Skip to content

Commit

Permalink
test: find cockpit test group dynamically
Browse files Browse the repository at this point in the history
https://cockpit-project.org/blog/cockpit-317.html changed the user/group name from
cockpit-ws to cockpit-wsinstance which causes tests to fail.

Instead, add a task file tests/tasks/get_cockpit_group.yml to determine which group
name to use.

Signed-off-by: Rich Megginson <[email protected]>
  • Loading branch information
richm committed Jun 13, 2024
1 parent 83d0b37 commit 6ed3e15
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ This example also installs Cockpit with an IdM-issued web server certificate.
- name: /etc/cockpit/ws-certs.d/monger-cockpit
dns: ['localhost', 'www.example.com']
ca: ipa
group: cockpit-ws
group: cockpit-ws # or cockpit-wsinstance on newer cockpit versions
```

NOTE: The `certificate` role, unless using IPA and joining the systems to an IPA domain,
Expand Down
13 changes: 13 additions & 0 deletions tests/tasks/get_cockpit_group.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: MIT
---
- name: Get name of cockpit group for tests
getent:
database: group
key: cockpit-wsinstance
fail_key: false

- name: Set __cockpit_test_group
set_fact:
__cockpit_test_group: "{{ 'cockpit-wsinstance'
if 'cockpit-wsinstance' in ansible_facts['getent_group']
else 'cockpit-ws' }}"
6 changes: 5 additions & 1 deletion tests/tests_certificate_external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
setype: cert_t
mode: "0755"
# returns global variable __cockpit_test_group
- name: Get name of cockpit group to use
include_tasks: tasks/get_cockpit_group.yml

# has to be done dynamically, as the first step checks it out
- name: Generate certificate with certificate system role
include_role:
Expand All @@ -35,7 +39,7 @@
- name: /etc/cockpit/ws-certs.d/monger-cockpit
dns: ['localhost', 'www.example.com']
ca: self-sign
group: cockpit-ws
group: "{{ __cockpit_test_group }}"

# ostree cannot remove packages and cannot cleanup properly
# this works around that issue
Expand Down
14 changes: 13 additions & 1 deletion tests/tests_certificate_internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@
- name: >-
Install cockpit using the certificate role to create a certificate
block:
# install cockpit package to get group
- name: Include role
include_role:
name: linux-system-roles.cockpit
public: true
vars:
cockpit_packages: minimal
# returns global variable __cockpit_test_group
- name: Get name of cockpit group to use
include_tasks: tasks/get_cockpit_group.yml
- name: Install cockpit with cockpit_certificates request
vars:
cockpit_packages: minimal
cockpit_certificates:
- name: "{{ cert_name }}"
dns: ['localhost', 'www.example.com']
ca: self-sign
group: cockpit-ws
group: "{{ __cockpit_test_group }}"
include_role:
name: linux-system-roles.cockpit
public: true
Expand Down
8 changes: 6 additions & 2 deletions tests/tests_certificate_runafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
setype: cert_t
mode: "0755"

# returns global variable __cockpit_test_group
- name: Get name of cockpit group to use
include_tasks: tasks/get_cockpit_group.yml

# has to be done dynamically, as the first step checks it out
- name: Generate certificate with certificate system role
include_role:
Expand All @@ -34,7 +38,7 @@
- name: monger-cockpit
dns: ['localhost', 'www.example.com']
ca: local
group: cockpit-ws
group: "{{ __cockpit_test_group }}"
# ideally we'd put the cert directly into /etc/cockpit/ws-certs.d;
# however, cockpit in RHEL/CentOS 7 does not yet support a separate
# key file, and lsr.certificate sets wrong permissions
Expand All @@ -44,7 +48,7 @@
cat {{ __certificate_default_directory }}/certs/monger-cockpit.crt \
{{ __certificate_default_directory }}/private/monger-cockpit.key > $DEST
chmod 640 $DEST
chown root:cockpit-ws $DEST
chown root:{{ __cockpit_test_group }} $DEST
- name: Validate installation
block:
Expand Down

0 comments on commit 6ed3e15

Please sign in to comment.