Skip to content

Commit d26564b

Browse files
committed
debug vault daemon in CI
1 parent ba8a0dd commit d26564b

4 files changed

Lines changed: 201 additions & 18 deletions

File tree

.github/workflows/build_and_test.yaml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ jobs:
1919
include:
2020
- python-version-short: "3.9"
2121
python-version: 3.9.21
22+
consul-version: "1.22.7-1"
2223
vault-version: "2.0.0-1"
2324
hvac-gh-tag: "v2.4.0"
2425
- python-version-short: "3.10"
2526
python-version: 3.10.16
27+
consul-version: "1.22.7-1"
2628
vault-version: "2.0.0-1"
2729
hvac-gh-tag: "v2.4.0"
2830
- python-version-short: "3.11"
2931
python-version: 3.11.11
32+
consul-version: "1.22.7-1"
3033
vault-version: "2.0.0-1"
3134
hvac-gh-tag: "v2.4.0"
3235
steps:
@@ -59,22 +62,7 @@ jobs:
5962
working-directory: pack
6063
shell: bash
6164
run: |
62-
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/hashicorp.gpg
63-
echo "deb [arch=amd64, signed-by=/etc/apt/trusted.gpg.d/hashicorp.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" \
64-
| sudo tee /etc/apt/sources.list.d/hashicorp.list
65-
66-
sudo apt update \
67-
-o Dir::Etc::sourceparts="-" \
68-
-o APT::Get::List-Cleanup="0" \
69-
-o Dir::Etc::sourcelist="sources.list.d/hashicorp.list"
70-
71-
sudo apt install consul vault=${{ matrix.vault-version }}
72-
73-
# We disble cap_ipc_lock here as its generally incompatabile with GitHub
74-
# Actions' runtime environments.
75-
sudo setcap cap_ipc_lock= /usr/bin/vault
76-
sudo systemctl restart consul vault
77-
sudo systemctl status consul vault
65+
${ROOT_DIR}/tests/scripts/install_vault ${{ matrix.vault-version }} ${{ matrix.consul-version }}
7866
7967
- name: Setup hvac symlinks
8068
shell: bash

tests/scripts/install_consul

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: CI
2+
3+
on:
4+
workflow_call:
5+
pull_request:
6+
schedule:
7+
# NOTE: We run this weekly at 1 am UTC on every Saturday
8+
- cron: '0 1 * * 6'
9+
10+
jobs:
11+
# This is based on this workflow, with an additional test env setup method
12+
# StackStorm-Exchange/ci/.github/workflows/pack-build_and_test.yaml@master
13+
14+
build_and_test:
15+
runs-on: ubuntu-22.04
16+
name: 'Build and Test / Python ${{ matrix.python-version-short }}'
17+
strategy:
18+
matrix:
19+
include:
20+
- python-version-short: "3.9"
21+
python-version: 3.9.21
22+
consul-version: "1.22.7-1"
23+
vault-version: "2.0.0-1"
24+
hvac-gh-tag: "v2.4.0"
25+
- python-version-short: "3.10"
26+
python-version: 3.10.16
27+
consul-version: "1.22.7-1"
28+
vault-version: "2.0.0-1"
29+
hvac-gh-tag: "v2.4.0"
30+
- python-version-short: "3.11"
31+
python-version: 3.11.11
32+
consul-version: "1.22.7-1"
33+
vault-version: "2.0.0-1"
34+
hvac-gh-tag: "v2.4.0"
35+
steps:
36+
- name: Checkout Pack Repo and CI Repos
37+
uses: StackStorm-Exchange/ci/.github/actions/checkout@master
38+
39+
- name: Checkout github.com/hvac/hvac
40+
uses: actions/checkout@v2
41+
with:
42+
path: hvac
43+
repository: hvac/hvac
44+
# main = the release branch; devel = the active development branch
45+
ref: ${{ matrix.hvac-gh-tag }}
46+
fetch-depth: 0
47+
48+
- name: Install APT Dependencies
49+
uses: StackStorm-Exchange/ci/.github/actions/apt-dependencies@master
50+
with:
51+
cache-version: v0
52+
53+
- name: Install Python Dependencies
54+
uses: StackStorm-Exchange/ci/.github/actions/py-dependencies@master
55+
with:
56+
cache-version: v0
57+
python-version: ${{ matrix.python-version }}
58+
59+
# task copied (Apache 2.0 License) from
60+
# github.com/hvac/hvac .github/workflows/lint-and-test.yml
61+
- name: Install Vault and Consul (for integration tests)
62+
working-directory: pack
63+
shell: bash
64+
run: |
65+
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/hashicorp.gpg
66+
echo "deb [arch=amd64, signed-by=/etc/apt/trusted.gpg.d/hashicorp.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" \
67+
| sudo tee /etc/apt/sources.list.d/hashicorp.list
68+
69+
sudo apt update \
70+
-o Dir::Etc::sourceparts="-" \
71+
-o APT::Get::List-Cleanup="0" \
72+
-o Dir::Etc::sourcelist="sources.list.d/hashicorp.list"
73+
74+
sudo apt install consul=${{ matrix.consul-version }} vault=${{ matrix.vault-version }}
75+
76+
# We disble cap_ipc_lock here as its generally incompatabile with GitHub
77+
# Actions' runtime environments.
78+
sudo setcap cap_ipc_lock= /usr/bin/vault
79+
80+
# Consul needs to be explicitly configured to start in the CI/CD environment.
81+
sudo mkdir -p /srv/consul && sudo chown -R consul:consul /srv/consul
82+
sudo tee /etc/consul.d/consul.hcl >/dev/null <<EOF
83+
enable_debug = false
84+
datacenter = "cicd"
85+
data_dir = "/srv/consul"
86+
ui_config{
87+
enabled = false
88+
}
89+
server = true
90+
bind_addr = "127.0.0.1"
91+
client_addr = "127.0.0.1"
92+
advertise_addr = "127.0.0.1"
93+
retry_join = ["localhost"]
94+
bootstrap_expect = 0
95+
encrypt = "katpv2wgyY5Za8bGAHh7+URaeLJWh4g+gK0GBjmvQXA="
96+
EOF
97+
sudo systemctl restart consul
98+
sudo systemctl restart vault
99+
100+
- name: Setup hvac symlinks
101+
shell: bash
102+
env:
103+
HVAC_DIR: ${{ github.workspace }}/hvac
104+
run: |
105+
# using symlinks allows us to import tests.utils.* without adding
106+
# the rest of the hvac tests. tests.utils also uses config_files,
107+
# so make that available too.
108+
set -eux
109+
for x in utils config_files; do
110+
rm -f ${ROOT_DIR}/tests/${x}
111+
# relative (-r) allows the symlink to work in vagrant
112+
ln -rs ${HVAC_DIR}/tests/${x} ${ROOT_DIR}/tests/${x}
113+
ls -ld ${ROOT_DIR}/tests/${x}
114+
done
115+
116+
- name: Run pack tests
117+
uses: StackStorm-Exchange/ci/.github/actions/test@master
118+
with:
119+
enable-common-libs: false
120+
121+
services:
122+
mongo:
123+
image: mongo:7.0
124+
ports:
125+
- 27017:27017
126+
rabbitmq:
127+
image: rabbitmq:3
128+
ports:
129+
- 5672:5672
130+
#redis:
131+
# image: redis
132+
# ports:
133+
# - 6379:6379

tests/scripts/install_vault

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
3+
set -eux
4+
5+
# Installing consul and vault in the CI/CD environment is complex. That
6+
# complexity is now wrapped inside this shell script for a clearer CI/CD YAML.
7+
8+
VAULT_VERSION="$1"
9+
CONSUL_VERSION="$2"
10+
11+
# github group
12+
function ghg
13+
{
14+
test "$1" == "start" && echo "##[group]$2"
15+
test "$1" == "end" && echo "##[endgroup]"
16+
}
17+
18+
ghg start "Setup Hashicorp (IBM) APT repository source"
19+
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/hashicorp.gpg
20+
sudo tee /etc/apt/sources.list.d/hashicorp.list <<<"deb [arch=amd64, signed-by=/etc/apt/trusted.gpg.d/hashicorp.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
21+
ghg end
22+
23+
ghg start "Install consul=${CONSUL_VERSION} vault=${VAULT_VERSION}"
24+
sudo apt update -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" -o Dir::Etc::sourcelist="sources.list.d/hashicorp.list"
25+
sudo apt install consul=${CONSUL_VERSION} vault=${VAULT_VERSION}
26+
ghg end
27+
28+
# We disble cap_ipc_lock here as its generally incompatabile with GitHub
29+
# Actions' runtime environments.
30+
sudo setcap cap_ipc_lock= /usr/bin/vault
31+
32+
# Consul needs to be explicitly configured to start in the CI/CD environment.
33+
ghg start "Configure Consul"
34+
sudo mkdir -p /srv/consul && sudo chown -R consul:consul /srv/consul
35+
36+
sudo tee /etc/consul.d/consul.hcl >/dev/null <<EOF
37+
enable_debug = false
38+
datacenter = "cicd"
39+
data_dir = "/srv/consul"
40+
ui_config{
41+
enabled = false
42+
}
43+
server = true
44+
bind_addr = "127.0.0.1"
45+
client_addr = "127.0.0.1"
46+
advertise_addr = "127.0.0.1"
47+
retry_join = ["localhost"]
48+
bootstrap_expect = 0
49+
encrypt = "katpv2wgyY5Za8bGAHh7+URaeLJWh4g+gK0GBjmvQXA="
50+
EOF
51+
52+
sudo systemctl restart consul
53+
ghg end
54+
55+
ghg start "Configure Vault"
56+
sudo systemctl restart vault
57+
58+
# Initialise and unseal vault
59+
vault init
60+
ghg end

tests/vault_action_tests_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from st2tests.base import BaseActionTestCase
22

3-
from tests.utils import get_config_file_path
3+
# #from tests.utils import get_config_file_path
44
from tests.utils.hvac_integration_test_case import HvacIntegrationTestCase
55

66

@@ -59,7 +59,9 @@ def tearDown(self):
5959

6060
def build_dummy_pack_config(self, url="https://localhost:8200"):
6161
# based on create_client() in hvac/tests/utils/__init__.py
62-
server_cert_path = get_config_file_path("server-cert.pem")
62+
# CI/CD only has a self-signed cert.
63+
# #server_cert_path = get_config_file_path("server-cert.pem")
64+
server_cert_path = False
6365

6466
token_result = self.client.auth.token.create(ttl=self.default_token_lease)
6567
token = token_result["auth"]["client_token"]

0 commit comments

Comments
 (0)