Skip to content

Commit 41184f2

Browse files
test(tmachine): remove the Podman userns overrides block in default mode
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent b470b85 commit 41184f2

4 files changed

Lines changed: 32 additions & 6 deletions

File tree

‎TESTING.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ which takes a name and the tables to change, such as `[openshell.gateway]` or
615615
616616
The role writes each name as its own marked block in
617617
`/etc/openshell-test/gateway-overrides.toml`, so writers keep each other's
618-
settings. Two blocks must not declare the same table. Don't write the file
618+
settings, and `gateway_overrides_state: absent` removes a name's block.
619+
Two blocks must not declare the same table. Don't write the file
619620
directly. The file is not a complete configuration. Each installer applies it
620621
to the gateway's own file:
621622

‎tests/tmachine/ansible/playbooks/drivers/podman/userns.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# `podman_userns_mode` is default, auto, keep-id or private. Every mode except
77
# default adds its `[openshell.drivers.podman]` settings to the gateway
88
# overrides (the gateway_overrides role), which every installer applies to the
9-
# gateway's configuration. Default mode adds nothing, so userns, uidmap and
9+
# gateway's configuration. Default mode removes them, so userns, uidmap and
1010
# gidmap stay unset. The Podman support crate (tests/support/podman) reads the
1111
# published mode and runs Podman's own reference container in it.
1212
---
@@ -47,7 +47,7 @@
4747
vars:
4848
gateway_overrides_name: podman-userns
4949
gateway_overrides_content: "{{ podman_userns_settings[podman_userns_mode] }}"
50-
when: podman_userns_mode != "default"
50+
gateway_overrides_state: "{{ 'absent' if podman_userns_mode == 'default' else 'present' }}"
5151

5252
- name: Publish Podman user-namespace test variables
5353
ansible.builtin.include_tasks: ../../test-env.yaml

‎tests/tmachine/ansible/roles/gateway_overrides/defaults/main.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
---
55
gateway_overrides_path: /etc/openshell-test/gateway-overrides.toml
6+
gateway_overrides_state: present

‎tests/tmachine/ansible/roles/gateway_overrides/tasks/main.yaml‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# the same name again replaces its block
1212
# gateway_overrides_content whole TOML tables, such as
1313
# `[openshell.drivers.podman]`
14+
# gateway_overrides_state `absent` removes the name's block and keeps the
15+
# others; the default is `present`
1416
#
1517
# Each name gets its own marked block, so writers keep each other's settings
1618
# and may run in any order. Two blocks must not declare the same table: TOML
@@ -24,14 +26,19 @@
2426
that:
2527
- gateway_overrides_name is defined
2628
- gateway_overrides_name is match('^[a-z0-9][a-z0-9-]*$')
27-
- gateway_overrides_content is defined
28-
- gateway_overrides_content | trim | length > 0
29+
- gateway_overrides_state in ['present', 'absent']
30+
- >-
31+
gateway_overrides_state == 'absent' or
32+
(gateway_overrides_content is defined and
33+
gateway_overrides_content | trim | length > 0)
2934
fail_msg: >-
3035
gateway_overrides needs gateway_overrides_name (lowercase letters,
31-
digits and dashes) and non-empty gateway_overrides_content
36+
digits and dashes), gateway_overrides_state present or absent, and
37+
non-empty gateway_overrides_content unless the state is absent
3238
3339
- name: Create the test configuration directory
3440
become: true
41+
when: gateway_overrides_state == 'present'
3542
ansible.builtin.file:
3643
path: "{{ gateway_overrides_path | dirname }}"
3744
state: directory
@@ -49,3 +56,20 @@
4956
mode: "0644"
5057
marker: "# {mark} {{ gateway_overrides_name }}"
5158
block: "{{ gateway_overrides_content }}"
59+
when: gateway_overrides_state == 'present'
60+
61+
- name: Check for the gateway overrides file
62+
ansible.builtin.stat:
63+
path: "{{ gateway_overrides_path }}"
64+
register: gateway_overrides_file
65+
when: gateway_overrides_state == 'absent'
66+
67+
- name: Remove the {{ gateway_overrides_name }} gateway overrides
68+
become: true
69+
ansible.builtin.blockinfile:
70+
path: "{{ gateway_overrides_path }}"
71+
marker: "# {mark} {{ gateway_overrides_name }}"
72+
state: absent
73+
when:
74+
- gateway_overrides_state == 'absent'
75+
- gateway_overrides_file.stat.exists

0 commit comments

Comments
 (0)