Skip to content

Commit b251368

Browse files
authored
Fix unhandled exception when a running a command that does not exist (#83)
* Fix unhandled exception when a running a command that does not exist * Fixed lint issues * Python 3.13 now works with docker * Fixed lint issues * Fix to allow unit tests to run with docker * Updated version of coverage based on latest ansible requirements * Fixed unit test and lint issues * Refactored unit tests to comply with ansible 2.19 changes
1 parent 3cbaaaa commit b251368

24 files changed

Lines changed: 280 additions & 237 deletions

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
VERSION := 2.1.2-preview
22
TARBALL := skupper-v2-$(VERSION).tar.gz
33

4-
IMAGES = default fedora40 ubuntu2404
4+
IMAGES = default ubuntu2404
55
PYTHON ?= `python -c 'import platform; print(".".join(platform.python_version_tuple()[0:2]))'`
66
PYTHON_DOCKER = 3.12
77

@@ -51,7 +51,7 @@ sanity:
5151
.PHONY: unit
5252
unit:
5353
pip install -r ./tests/unit/requirements.txt -U
54-
ansible-test units --color --coverage --python $(PYTHON) -v
54+
ansible-test units --color --coverage --venv --python $(PYTHON) -v
5555

5656
.PHONY: unit-docker
5757
unit-docker: $(foreach img,$(IMAGES),unit-docker-$(img))

plugins/module_utils/command.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88

99
def run_command(module: AnsibleModule, command: list) -> t.Tuple[int, str, str]:
10-
module.debug("running command: %s" % (command))
11-
code, out, err = module.run_command(command)
12-
module.debug("code: %d" % (code))
13-
module.debug("stdout: %s" % (out))
14-
module.debug("stderr: %s" % (err))
15-
return code, out, err
10+
try:
11+
module.debug("running command: %s" % (command))
12+
code, out, err = module.run_command(command, handle_exceptions=False)
13+
module.debug("code: %d" % (code))
14+
module.debug("stdout: %s" % (out))
15+
module.debug("stderr: %s" % (err))
16+
return code, out, err
17+
except Exception as ex:
18+
module.debug("exception running command %s: %s" % (command, str(ex)))
19+
return 1, "", str(ex)

tests/integration/targets/delete_nonkube_namespace/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
- name: Setting namespace home directory (rootless)
33
ansible.builtin.set_fact:
4-
_namespace_home: "{{ lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' + namespace + '/' }}"
4+
_namespace_home: "{{ lookup('env', 'HOME') + '/.local/share/skupper/namespaces/' + namespace | string + '/' }}"
55
when: ansible_real_user_id != 0
66
- name: Setting namespace home directory (rootful)
77
ansible.builtin.set_fact:
8-
_namespace_home: "{{ '/var/lib/skupper/namespaces/' + namespace + '/' }}"
8+
_namespace_home: "{{ '/var/lib/skupper/namespaces/' + namespace | string + '/' }}"
99
when: ansible_real_user_id == 0
1010
- name: Removing namespace directory
1111
ansible.builtin.file:

tests/integration/targets/resource/tasks/kube/resource.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: Create Site A resources based on definition
33
skupper.v2.resource:
44
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
5-
namespace: "{{ namespace }}"
5+
namespace: "{{ namespace | string }}"
66
kubeconfig: "{{ kubeconfig }}"
77
register: _result
88
- name: Assert that resources have been created
@@ -19,7 +19,7 @@
1919
- name: Create Site A resources based on definition (no changes expected)
2020
skupper.v2.resource:
2121
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
22-
namespace: "{{ namespace }}"
22+
namespace: "{{ namespace | string }}"
2323
kubeconfig: "{{ kubeconfig }}"
2424
register: _result
2525
- name: Assert that resources have not been changed
@@ -30,7 +30,7 @@
3030
- name: Create Site A resources based on local path (no changes expected)
3131
skupper.v2.resource:
3232
path: "{{ role_path }}/files/site_a.yml"
33-
namespace: "{{ namespace }}"
33+
namespace: "{{ namespace | string }}"
3434
kubeconfig: "{{ kubeconfig }}"
3535
register: _result
3636
- name: Assert that resources have not been changed
@@ -41,7 +41,7 @@
4141
- name: Create Site A resources based on remote path (no changes expected)
4242
skupper.v2.resource:
4343
path: "{{ role_path }}/files/site_a.yml"
44-
namespace: "{{ namespace }}"
44+
namespace: "{{ namespace | string }}"
4545
remote: true
4646
kubeconfig: "{{ kubeconfig }}"
4747
register: _result
@@ -53,7 +53,7 @@
5353
- name: Override Site A resources based on local path
5454
skupper.v2.resource:
5555
path: "{{ role_path }}/files/site_a.yml"
56-
namespace: "{{ namespace }}"
56+
namespace: "{{ namespace | string }}"
5757
state: latest
5858
kubeconfig: "{{ kubeconfig }}"
5959
register: _result
@@ -65,7 +65,7 @@
6565
- name: Delete Site A resources based on remote path
6666
skupper.v2.resource:
6767
path: "{{ role_path }}/files/site_a.yml"
68-
namespace: "{{ namespace }}"
68+
namespace: "{{ namespace | string }}"
6969
state: absent
7070
kubeconfig: "{{ kubeconfig }}"
7171
register: _result

tests/integration/targets/resource/tasks/kube/resource_created.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
api_version: skupper.io/v2alpha1
55
kind: "{{ item.kind }}"
66
name: "{{ item.name }}"
7-
namespace: "{{ namespace }}"
7+
namespace: "{{ namespace | string }}"
88
kubeconfig: "{{ kubeconfig }}"
99
register: my_resource
1010
- name: Assert that the resource was successfully retrieved

tests/integration/targets/resource/tasks/kube/resource_deleted.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
api_version: skupper.io/v2alpha1
55
kind: "{{ item.kind }}"
66
name: "{{ item.name }}"
7-
namespace: "{{ namespace }}"
7+
namespace: "{{ namespace | string }}"
88
kubeconfig: "{{ kubeconfig }}"
99
register: _resource
1010
until: _resource.resources | length == 0

tests/integration/targets/resource/tasks/nonkube/invalid_resource.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: Create Site A resources based on definition
33
skupper.v2.resource:
44
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
5-
namespace: "{{ namespace }}"
5+
namespace: "{{ namespace | string }}"
66
platform: podman
77
register: _result
88
- name: Assert that resources have been created
@@ -19,7 +19,7 @@
1919
- name: Delete Site A resources based on remote path with invalid resources
2020
skupper.v2.resource:
2121
path: "{{ role_path }}/files/site_invalid.yml"
22-
namespace: "{{ namespace }}"
22+
namespace: "{{ namespace | string }}"
2323
state: absent
2424
platform: podman
2525
register: _result

tests/integration/targets/resource/tasks/nonkube/resource.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: Create Site A resources based on definition
33
skupper.v2.resource:
44
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
5-
namespace: "{{ namespace }}"
5+
namespace: "{{ namespace | string }}"
66
platform: podman
77
register: _result
88
- name: Assert that resources have been created
@@ -19,7 +19,7 @@
1919
- name: Create Site A resources based on definition (no changes expected)
2020
skupper.v2.resource:
2121
def: "{{ lookup('ansible.builtin.file', 'site_a.yml') }}"
22-
namespace: "{{ namespace }}"
22+
namespace: "{{ namespace | string }}"
2323
platform: podman
2424
register: _result
2525
- name: Assert that resources have not been changed
@@ -30,7 +30,7 @@
3030
- name: Create Site A resources based on local path (no changes expected)
3131
skupper.v2.resource:
3232
path: "{{ role_path }}/files/site_a.yml"
33-
namespace: "{{ namespace }}"
33+
namespace: "{{ namespace | string }}"
3434
platform: podman
3535
register: _result
3636
- name: Assert that resources have not been changed
@@ -41,7 +41,7 @@
4141
- name: Create Site A resources based on remote path (no changes expected)
4242
skupper.v2.resource:
4343
path: "{{ role_path }}/files/site_a.yml"
44-
namespace: "{{ namespace }}"
44+
namespace: "{{ namespace | string }}"
4545
remote: true
4646
platform: podman
4747
register: _result
@@ -53,7 +53,7 @@
5353
- name: Override Site A resources based on local path
5454
skupper.v2.resource:
5555
path: "{{ role_path }}/files/site_a.yml"
56-
namespace: "{{ namespace }}"
56+
namespace: "{{ namespace | string }}"
5757
state: latest
5858
platform: podman
5959
register: _result
@@ -65,7 +65,7 @@
6565
- name: Delete Site A resources based on remote path
6666
skupper.v2.resource:
6767
path: "{{ role_path }}/files/site_a.yml"
68-
namespace: "{{ namespace }}"
68+
namespace: "{{ namespace | string }}"
6969
state: absent
7070
platform: podman
7171
register: _result

tests/integration/targets/resource/tasks/nonkube/resource_deleted.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
when: ansible_real_user_id != 0
66
- name: Set the filename to be verified (rootful)
77
ansible.builtin.set_fact:
8-
_filename: "{{ '/var/lib/skupper/namespaces/' + namespace + '/input/resources/' + item.file }}"
8+
_filename: "{{ '/var/lib/skupper/namespaces/' + namespace | string + '/input/resources/' + item.file }}"
99
when: ansible_real_user_id == 0
1010
- name: Retrieve expected resource from the filesystem
1111
ansible.builtin.stat:

tests/integration/targets/system/tasks/action-reload.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
- name: Create Site A resources
33
skupper.v2.resource:
44
path: "{{ role_path }}/files/site_a.yml"
5-
namespace: "{{ namespace }}"
5+
namespace: "{{ namespace | string }}"
66
platform: podman
77
- name: Get skupper-site-ca key file hash
88
ansible.builtin.set_fact:
@@ -11,7 +11,7 @@
1111
- name: Run the reload action
1212
skupper.v2.system:
1313
action: reload
14-
namespace: "{{ namespace }}"
14+
namespace: "{{ namespace | string }}"
1515
image: "{{ system_image }}"
1616
register: _system
1717
environment:

0 commit comments

Comments
 (0)