Skip to content

Commit 3267ddb

Browse files
committed
test: ensure integration and unit pytest work in collection mode
Refactor the common code in tests_unit.yml and the integration pytest into a single block of code. The tests/ directory has a library sub-directory with a symlink to the network_connections.py module. This was causing problems because the logic in get_modules_and_utils_paths.yml really wants the real files and directories, not the symlinks, and for some reason the bash `-f` test is returning `true` for the symlink. Instead, ensure that we do not use the link by using `-L` to screen it out. Also added the collection paths to the search. Make the path arrays have unique values. Use the `realpath` filter to see the full actual path. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent 0cd3b7a commit 3267ddb

4 files changed

Lines changed: 231 additions & 297 deletions

File tree

tests/playbooks/integration_pytest_python3.yml

Lines changed: 6 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -30,110 +30,16 @@
3030
tasks:
3131
- name: Run Pytest tests
3232
block:
33-
- name: Create tempdir for code to test
34-
tempfile:
35-
state: directory
36-
prefix: lsrtest_
37-
register: _rundir
38-
39-
- name: Get tempfile for tar
40-
tempfile:
41-
prefix: lsrtest_
42-
suffix: ".tar"
43-
register: temptar
44-
delegate_to: localhost
45-
46-
- name: Include the task '../tasks/get_modules_and_utils_paths.yml'
47-
include_tasks: ../tasks/get_modules_and_utils_paths.yml
48-
49-
- name: Get tests directory
50-
set_fact:
51-
tests_directory: "{{ lookup('first_found', params) }}"
52-
vars:
53-
params:
54-
files:
55-
- tests
56-
- network
57-
paths:
58-
- "../.."
59-
60-
# TODO: using tar and copying the file is a workaround for the
61-
# synchronize module that does not work in test-harness. Related issue:
62-
# https://github.com/linux-system-roles/test-harness/issues/102
63-
#
64-
- name: Create Tar file
65-
command: >
66-
tar -cvf {{ temptar.path }} --exclude "*.pyc"
67-
--exclude "__pycache__"
68-
-C {{ tests_directory | realpath | dirname }}
69-
{{ tests_directory | basename }}
70-
-C {{ modules_parent_and_dir.stdout_lines[0] }}
71-
{{ modules_parent_and_dir.stdout_lines[1] }}
72-
-C {{ module_utils_parent_and_dir.stdout_lines[0] }}
73-
{{ module_utils_parent_and_dir.stdout_lines[1] }}
74-
# noqa command-instead-of-module
75-
delegate_to: localhost
76-
changed_when: false
77-
78-
- name: Copy testrepo.tar to the remote system
79-
copy:
80-
src: "{{ temptar.path }}"
81-
dest: "{{ _rundir.path }}"
82-
mode: preserve
83-
84-
- name: Untar testrepo.tar
85-
unarchive:
86-
src: "{{ _rundir.path }}/{{ temptar.path | basename }}"
87-
dest: "{{ _rundir.path }}"
88-
remote_src: true
89-
90-
- name: "Create subdirectory './ansible' under '{{ _rundir.path }}'"
91-
file:
92-
state: directory
93-
path: "{{ _rundir.path }}/ansible"
94-
mode: "0755"
95-
96-
- name: Move module_utils to ansible directory
97-
shell: |
98-
if [ -d {{ _rundir.path }}/module_utils ]; then
99-
mv {{ _rundir.path }}/module_utils {{ _rundir.path }}/ansible
100-
fi
101-
changed_when: false
102-
103-
- name: Fake out python module directories, primarily for python2
104-
shell: |
105-
for dir in $(find {{ _rundir.path }} -type d -print); do
106-
if [ ! -f "$dir/__init__.py" ]; then
107-
touch "$dir/__init__.py"
108-
fi
109-
done
110-
changed_when: false
111-
112-
- name: Set _lsr_python_path
113-
set_fact:
114-
_lsr_python_path: "{{
115-
_rundir.path ~ '/' ~
116-
modules_parent_and_dir.stdout_lines[1] ~ ':' ~ _rundir.path
117-
}}"
118-
119-
- name: Show _lsr_python_path
120-
debug:
121-
msg: path {{ _lsr_python_path }}
122-
123-
- name: "List the files in {{ _rundir.path }}"
124-
command: ls -alrtFR {{ _rundir.path }}
125-
changed_when: false
33+
- name: Copy python files to the remote system
34+
include_tasks: ../tasks/setup_remote_pytest.yml
12635

12736
- name: Run pytest with nm provider
12837
block:
12938
- name: Run pytest with nm
130-
command: >
131-
pytest-3
132-
{{ _rundir.path }}/{{ tests_directory | basename }}/integration/
133-
--provider=nm
134-
register: playbook_run
39+
command: pytest-3 {{ _rundir.path }}/integration/ --provider=nm
13540
environment:
13641
PYTHONPATH: "{{ _lsr_python_path }}"
42+
register: playbook_run
13743
changed_when: false
13844
always:
13945
- name: Debug stdout_lines of the running playbook with nm
@@ -149,13 +55,10 @@
14955
use: "{{ (__network_is_ostree | d(false)) |
15056
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
15157
- name: Run pytest with initscripts
152-
command: >
153-
pytest-3
154-
{{ _rundir.path }}/{{ tests_directory | basename }}/integration/
155-
--provider=initscripts
156-
register: playbook_run
58+
command: pytest-3 {{ _rundir.path }}/integration/ --provider=initscripts
15759
environment:
15860
PYTHONPATH: "{{ _lsr_python_path }}"
61+
register: playbook_run
15962
changed_when: false
16063
always:
16164
- name: Debug stdout_lines of the running playbook with initscripts

tests/tasks/get_modules_and_utils_paths.yml

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

0 commit comments

Comments
 (0)