Skip to content

Commit 3d7e88e

Browse files
authored
Merge pull request #528 from henrywang/no_key
test: remove ssh key files and generate them on the fly
2 parents c17b09d + a0c60ad commit 3d7e88e

6 files changed

Lines changed: 202 additions & 60 deletions

File tree

test/ansible.cfg

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[defaults]
2+
timeout = 30
3+
# human-readable stdout/stderr results display
4+
stdout_callback = yaml
5+
6+
[ssh_connection]
7+
scp_if_ssh=True
8+
pipelining=False

test/check-ostree.yaml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
---
2+
- hosts: ostree_guest
3+
become: no
4+
vars:
5+
total_counter: "0"
6+
failed_counter: "0"
7+
8+
tasks:
9+
10+
# current target host's IP address
11+
- debug: var=ansible_all_ipv4_addresses
12+
- debug: var=ansible_facts['distribution_version']
13+
- debug: var=ansible_facts['distribution']
14+
- debug: var=ansible_facts['architecture']
15+
16+
# check BIOS or UEFI
17+
- name: check bios or uefi
18+
stat:
19+
path: /sys/firmware/efi
20+
21+
# check secure boot status if it's enabled
22+
- name: check secure boot status
23+
command: mokutil --sb-state
24+
ignore_errors: yes
25+
26+
# check tpm device
27+
- name: check tpm device
28+
stat:
29+
path: /dev/tpm0
30+
ignore_errors: yes
31+
32+
- name: check partition size
33+
command: df -h
34+
ignore_errors: yes
35+
become: yes
36+
37+
- name: check disk partition table
38+
command: fdisk -l
39+
ignore_errors: yes
40+
become: yes
41+
42+
- name: check rpm-ostree status
43+
command: rpm-ostree status
44+
ignore_errors: yes
45+
46+
- name: check installed kernel
47+
command: uname -r
48+
49+
# first installed or upgraded
50+
- name: determine which stage the checking is running on
51+
shell: rpm-ostree status --json | jq '.deployments | length'
52+
register: result_stage
53+
54+
- set_fact:
55+
checking_stage: "{{ result_stage.stdout }}"
56+
57+
# case: check fdo onboarding status
58+
# after fdo onboarding finished, /boot/device-credentials will be moved to /etc/device-credentials
59+
- name: check if fdo onboarding completed successfully
60+
block:
61+
- name: wait until the file /etc/device-credentials is present before continuing
62+
wait_for:
63+
path: /etc/device-credentials
64+
always:
65+
- set_fact:
66+
total_counter: "{{ total_counter | int + 1 }}"
67+
rescue:
68+
- name: failed count + 1
69+
set_fact:
70+
failed_counter: "{{ failed_counter | int + 1 }}"
71+
72+
# case: check ostree commit correctly updated
73+
- name: get deployed ostree commit
74+
shell: rpm-ostree status --json | jq -r '.deployments[0].checksum'
75+
register: result_commit
76+
77+
- name: make a json result
78+
set_fact:
79+
deploy_commit: "{{ result_commit.stdout }}"
80+
81+
- name: check commit deployed and built
82+
block:
83+
- assert:
84+
that:
85+
- deploy_commit == ostree_commit
86+
fail_msg: "deployed ostree commit is not commit built by osbuild-composer"
87+
success_msg: "successful building and deployment"
88+
always:
89+
- set_fact:
90+
total_counter: "{{ total_counter | int + 1 }}"
91+
rescue:
92+
- name: failed count + 1
93+
set_fact:
94+
failed_counter: "{{ failed_counter | int + 1 }}"
95+
96+
# case: check ostree ref
97+
- name: check ostree ref
98+
shell: rpm-ostree status --json | jq -r '.deployments[0].origin'
99+
register: result_ref
100+
101+
- name: check ostree ref deployed
102+
block:
103+
- assert:
104+
that:
105+
- result_ref.stdout == ostree_ref
106+
fail_msg: "deployed ostree ref failed"
107+
success_msg: "ostree ref successful building and deployment"
108+
always:
109+
- set_fact:
110+
total_counter: "{{ total_counter | int + 1 }}"
111+
rescue:
112+
- name: failed count + 1
113+
set_fact:
114+
failed_counter: "{{ failed_counter | int + 1 }}"
115+
116+
# case: check wget installed after upgrade
117+
- name: check installed package
118+
shell: rpm -qa | sort
119+
register: result_packages
120+
121+
- name: check wget installed
122+
block:
123+
- assert:
124+
that:
125+
- "'wget' in result_packages.stdout"
126+
fail_msg: "wget not installed, ostree upgrade might be failed"
127+
success_msg: "wget installed in ostree upgrade"
128+
always:
129+
- set_fact:
130+
total_counter: "{{ total_counter | int + 1 }}"
131+
rescue:
132+
- name: failed count + 1
133+
set_fact:
134+
failed_counter: "{{ failed_counter | int + 1 }}"
135+
when: checking_stage == "2"
136+
137+
- name: check dmesg output
138+
command: dmesg
139+
140+
# Check FDO status and task status
141+
- name: check fdo-client-linuxapp logs
142+
command: journalctl -u fdo-client-linuxapp
143+
become: yes
144+
145+
# Check re-encryption status on x86_64
146+
- name: wait for FDO re-encryption
147+
block:
148+
- shell: cryptsetup luksDump /dev/vda4
149+
register: result
150+
until: not result.stdout_lines is search("cipher_null-ecb")
151+
retries: 30
152+
delay: 60
153+
always:
154+
- set_fact:
155+
total_counter: "{{ total_counter | int + 1 }}"
156+
rescue:
157+
- name: failed count + 1
158+
set_fact:
159+
failed_counter: "{{ failed_counter | int + 1 }}"
160+
161+
# Check FDO status and task status
162+
- name: check fdo-client-linuxapp logs
163+
command: journalctl -u fdo-client-linuxapp
164+
become: yes
165+
166+
- assert:
167+
that:
168+
- failed_counter == "0"
169+
fail_msg: "Run {{ total_counter }} tests, but {{ failed_counter }} of them failed"
170+
success_msg: "Totally {{ total_counter }} test passed"

test/fdo-container.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ COMPOSE_START=${TEMPDIR}/compose-start-${IMAGE_KEY}.json
3737
COMPOSE_INFO=${TEMPDIR}/compose-info-${IMAGE_KEY}.json
3838

3939
# SSH setup.
40+
SSH_KEY="${TEMPDIR}/id_rsa"
41+
ssh-keygen -f "${SSH_KEY}" -N "" -q -t rsa
4042
SSH_OPTIONS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5)
41-
SSH_KEY=key/ostree_key
4243
SSH_KEY_PUB=$(cat "${SSH_KEY}".pub)
43-
EDGE_USER_PASSWORD=foobar
44+
4445
FDO_USER=fdouser
45-
SYSROOT_RO="true"
4646

4747
# Colorful output.
4848
function greenprint {
@@ -215,10 +215,24 @@ DIUN_PUB_KEY_HASH=sha256:$(openssl x509 -fingerprint -sha256 -noout -in aio/keys
215215
greenprint "🔧 Prepare FDO key and configuration files for FDO containers"
216216
cp -r aio/keys fdo/
217217

218+
# Install python3-pip
219+
sudo dnf install -y python3-pip
220+
# Install yq to modify service api server config yaml file
221+
sudo pip3 install yq
222+
223+
# Configure disk encryption
224+
/usr/local/bin/yq -iy '.service_info.diskencryption_clevis |= [{disk_label: "/dev/vda4", reencrypt: true, binding: {pin: "tpm2", config: "{}"}}]' fdo/serviceinfo_api_server.yml
225+
# FDO user does not have password, use ssh key and no sudo password instead
226+
/usr/local/bin/yq -iy ".service_info.initial_user |= {username: \"fdouser\", sshkeys: [\"$SSH_KEY_PUB\"]}" fdo/serviceinfo-api-server.yml
218227
# No sudo password required by ansible
219228
tee /tmp/fdouser > /dev/null << EOF
220229
$FDO_USER ALL=(ALL) NOPASSWD: ALL
221230
EOF
231+
# Configure files
232+
/usr/local/bin/yq -iy '.service_info.files |= [{path: "/etc/sudoers.d/fdouser", source_path: "/etc/fdo/fdouser"}]' fdo/serviceinfo-api-server.yml
233+
234+
# Check fdo/serviceinfo_api_server.yml configuration
235+
cat fdo/serviceinfo_api_server.yml
222236

223237
greenprint "🔧 Starting fdo manufacture server"
224238
podman run -d \
@@ -440,11 +454,11 @@ ansible_private_key_file=${SSH_KEY}
440454
ansible_ssh_common_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
441455
ansible_become=yes
442456
ansible_become_method=sudo
443-
ansible_become_pass=${EDGE_USER_PASSWORD}
457+
ansible_become_pass=foobar
444458
EOF
445459

446460
# Test IoT/Edge OS
447-
sudo podman run -v "$(pwd)":/work:z -v "${TEMPDIR}":/tmp:z --rm quay.io/rhel-edge/ansible-runner:latest ansible-playbook -v -i /tmp/inventory -e os_name=redhat -e ostree_commit="${INSTALL_HASH}" -e ostree_ref="${REF_PREFIX}:${OSTREE_REF}" -e fdo_credential="true" -e sysroot_ro="$SYSROOT_RO" check-ostree.yaml || RESULTS=0
461+
sudo podman run -v "$(pwd)":/work:z -v "${TEMPDIR}":/tmp:z --rm quay.io/rhel-edge/ansible-runner:latest ansible-playbook -v -i /tmp/inventory -e ostree_commit="${INSTALL_HASH}" -e ostree_ref="${REF_PREFIX}:${OSTREE_REF}" check-ostree.yaml || RESULTS=0
448462
check_result
449463

450464
# Clean up BIOS VM
@@ -572,7 +586,7 @@ ansible_become_method=sudo
572586
EOF
573587

574588
# Test IoT/Edge OS
575-
sudo podman run -v "$(pwd)":/work:z -v "${TEMPDIR}":/tmp:z --rm quay.io/rhel-edge/ansible-runner:latest ansible-playbook -v -i /tmp/inventory -e os_name=redhat -e ostree_commit="${INSTALL_HASH}" -e ostree_ref="${REF_PREFIX}:${OSTREE_REF}" -e fdo_credential="true" -e sysroot_ro="$SYSROOT_RO" check-ostree.yaml || RESULTS=0
589+
sudo podman run -v "$(pwd)":/work:z -v "${TEMPDIR}":/tmp:z --rm quay.io/rhel-edge/ansible-runner:latest ansible-playbook -v -i /tmp/inventory -e ostree_commit="${INSTALL_HASH}" -e ostree_ref="${REF_PREFIX}:${OSTREE_REF}" check-ostree.yaml || RESULTS=0
576590
check_result
577591

578592
# Clean up VM
@@ -703,7 +717,7 @@ ansible_become_method=sudo
703717
EOF
704718

705719
# Test IoT/Edge OS
706-
sudo podman run -v "$(pwd)":/work:z -v "${TEMPDIR}":/tmp:z --rm quay.io/rhel-edge/ansible-runner:latest ansible-playbook -v -i /tmp/inventory -e os_name=redhat -e ostree_commit="${INSTALL_HASH}" -e ostree_ref="${REF_PREFIX}:${OSTREE_REF}" -e fdo_credential="true" -e sysroot_ro="$SYSROOT_RO" check-ostree.yaml || RESULTS=0
720+
sudo podman run -v "$(pwd)":/work:z -v "${TEMPDIR}":/tmp:z --rm quay.io/rhel-edge/ansible-runner:latest ansible-playbook -v -i /tmp/inventory -e ostree_commit="${INSTALL_HASH}" -e ostree_ref="${REF_PREFIX}:${OSTREE_REF}" check-ostree.yaml || RESULTS=0
707721
check_result
708722

709723
# Clean up VM

test/fdo/serviceinfo-api-server.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
---
22
service_info:
3-
initial_user:
4-
username: fdouser
5-
sshkeys:
6-
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCzxo5dEcS+LDK/OFAfHo6740EyoDM8aYaCkBala0FnWfMMTOq7PQe04ahB0eFLS3IlQtK5bpgzxBdFGVqF6uT5z4hhaPjQec0G3+BD5Pxo6V+SxShKZo+ZNGU3HVrF9p2V7QH0YFQj5B8F6AicA3fYh2BVUFECTPuMpy5A52ufWu0r4xOFmbU7SIhRQRAQz2u4yjXqBsrpYptAvyzzoN4gjUhNnwOHSPsvFpWoBFkWmqn0ytgHg3Vv9DlHW+45P02QH1UFedXR2MqLnwRI30qqtaOkVS+9rE/dhnR+XPpHHG+hv2TgMDAuQ3IK7Ab5m/yCbN73cxFifH4LST0vVG3Jx45xn+GTeHHhfkAfBSCtya6191jixbqyovpRunCBKexI5cfRPtWOitM3m7Mq26r7LpobMM+oOLUm4p0KKNIthWcmK9tYwXWSuGGfUQ+Y8gt7E0G06ZGbCPHOrxJ8lYQqXsif04piONPA/c9Hq43O99KPNGShONCS9oPFdOLRT3U=
7-
ostree-image-test
8-
files:
9-
- path: /etc/sudoers.d/fdouser
10-
source_path: /etc/fdo/fdouser
3+
initial_user: null
4+
files: null
115
commands: null
12-
diskencryption_clevis:
13-
- disk_label: /dev/vda4
14-
reencrypt: true
15-
binding:
16-
pin: tpm2
17-
config: '{}'
6+
diskencryption_clevis: null
187
additional_serviceinfo: null
198
bind: 0.0.0.0:8083
209
service_info_auth_token: 2IOtlXsSqfcGjnhBLZjPiHIteskzZEW3lncRzpEmgqI=

test/key/ostree_key

Lines changed: 0 additions & 38 deletions
This file was deleted.

test/key/ostree_key.pub

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)