From 830f917e2d06d9c2463263ecef18cd11c5b93a7d Mon Sep 17 00:00:00 2001 From: aubin bikouo Date: Fri, 11 Apr 2025 17:01:13 +0200 Subject: [PATCH] connection/aws_ssm - fix windows tests --- .gitignore | 1 + .../connection_aws_ssm_windows/aliases | 1 - .../connection_aws_ssm_windows/runme.sh | 6 +- .../connection_aws_ssm_windows/test.yml | 102 ++++++++++++++++++ .../setup_connection_aws_ssm/tasks/main.yml | 5 - .../templates/boto_config.j2 | 2 +- 6 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 tests/integration/targets/connection_aws_ssm_windows/test.yml diff --git a/.gitignore b/.gitignore index fe23d61c263..f70678bd809 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ tests/integration/targets/connection_aws_ssm_*/instance_vars_to_delete.yml tests/integration/targets/connection_aws_ssm_*/s3_vars_to_delete.yml tests/integration/targets/connection_aws_ssm_*/ssm_inventory tests/integration/targets/connection_aws_ssm_*/ssm_vars_to_delete.yml +tests/integration/targets/connection_aws_ssm_*/aws-env-vars.sh ### dotenv ### .env diff --git a/tests/integration/targets/connection_aws_ssm_windows/aliases b/tests/integration/targets/connection_aws_ssm_windows/aliases index 6fec5723b7d..c854f815b1b 100644 --- a/tests/integration/targets/connection_aws_ssm_windows/aliases +++ b/tests/integration/targets/connection_aws_ssm_windows/aliases @@ -3,4 +3,3 @@ time=12m cloud/aws connection_aws_ssm -unstable diff --git a/tests/integration/targets/connection_aws_ssm_windows/runme.sh b/tests/integration/targets/connection_aws_ssm_windows/runme.sh index c99b3b0663b..f7fb503bc2f 100755 --- a/tests/integration/targets/connection_aws_ssm_windows/runme.sh +++ b/tests/integration/targets/connection_aws_ssm_windows/runme.sh @@ -23,9 +23,5 @@ set +x . ./aws-env-vars.sh set -x -cd ../connection - # Execute Integration tests -INVENTORY="${PLAYBOOK_DIR}/ssm_inventory" ./test.sh \ - -e target_hosts=aws_ssm \ - "$@" +ansible-playbook ./test.yml -i "${PLAYBOOK_DIR}/ssm_inventory" "$@" diff --git a/tests/integration/targets/connection_aws_ssm_windows/test.yml b/tests/integration/targets/connection_aws_ssm_windows/test.yml new file mode 100644 index 00000000000..9cd28cd2d9d --- /dev/null +++ b/tests/integration/targets/connection_aws_ssm_windows/test.yml @@ -0,0 +1,102 @@ +- name: Run connection/aws_ssm tests on Windows managed node. + hosts: aws_ssm_windows + gather_facts: false + + vars: + local_dir: '{{ local_tmp }}-{{ inventory_hostname }}-汉语' + local_file: '{{ local_dir }}/汉语.txt' + remote_dir: '{{ remote_tmp }}-汉语' + remote_file: '{{ remote_dir }}/汉语.txt' + remote_empty_file: '{{ remote_dir }}/empty.txt' + + tasks: + - name: Wait for connection + ansible.builtin.wait_for_connection: + timeout: 1000 + sleep: 10 + + - name: Gather facts + ansible.builtin.setup: + + ### raw with unicode arg and output + + - name: Raw with unicode arg and output + ansible.builtin.raw: echo 汉语 + register: command + + - name: Check output of raw with unicode arg and output + ansible.builtin.assert: + that: + - "'汉语' in command.stdout" + - command is changed # as of 2.2, raw should default to changed: true for consistency w/ shell/command/script modules + + ### copy local file with unicode filename and content + + - name: Create local file with unicode filename and content + ansible.builtin.lineinfile: + dest: "{{ local_file }}" + create: true + line: 汉语 + mode: "0755" + delegate_to: localhost + + - name: Remove remote file with unicode filename and content + ansible.windows.win_file: + path: "{{ remote_file }}" + state: absent + + - name: Create remote directory with unicode name + ansible.windows.win_file: + path: "{{ remote_dir }}" + state: directory + + - name: Copy local file with unicode filename and content + ansible.windows.win_copy: + src: "{{ local_file }}" + dest: "{{ remote_file }}" + + ### fetch remote file with unicode filename and content + + - name: Remove local file with unicode filename and content + ansible.builtin.file: + path: "{{ local_file }}" + state: absent + delegate_to: localhost + + - name: Fetch remote file with unicode filename and content + ansible.builtin.fetch: + src: "{{ remote_file }}" + dest: "{{ local_file }}" + fail_on_missing: true + validate_checksum: true + flat: true + + ### remove local and remote temp files + + - name: Remove local temp file + ansible.builtin.file: + path: "{{ local_file }}" + state: absent + delegate_to: localhost + + - name: Remove remote temp file + ansible.windows.win_file: + path: "{{ remote_file }}" + state: absent + + ### copy an empty file + - name: Copy an empty file + ansible.windows.win_copy: + content: '' + dest: "{{ remote_empty_file }}" + + - name: Stat empty file + ansible.windows.win_stat: + path: "{{ remote_empty_file }}" + register: stat_empty_file_cmd + + - name: Check that empty file exists + ansible.builtin.assert: + that: + - stat_empty_file_cmd.stat.isreg # it is a regular file + - stat_empty_file_cmd.stat.size == 0 diff --git a/tests/integration/targets/setup_connection_aws_ssm/tasks/main.yml b/tests/integration/targets/setup_connection_aws_ssm/tasks/main.yml index b9d1735ddf1..a6bc600e835 100644 --- a/tests/integration/targets/setup_connection_aws_ssm/tasks/main.yml +++ b/tests/integration/targets/setup_connection_aws_ssm/tasks/main.yml @@ -10,11 +10,6 @@ session_token: '{{ security_token | default(omit) }}' region: '{{ aws_region }}' block: - - - name: get ARN of calling user - amazon.aws.aws_caller_info: - register: aws_caller_info - - name: setup connection argments fact ansible.builtin.include_tasks: 'connection_args.yml' diff --git a/tests/integration/targets/setup_connection_aws_ssm/templates/boto_config.j2 b/tests/integration/targets/setup_connection_aws_ssm/templates/boto_config.j2 index acc077c094d..0ee1ee3c147 100644 --- a/tests/integration/targets/setup_connection_aws_ssm/templates/boto_config.j2 +++ b/tests/integration/targets/setup_connection_aws_ssm/templates/boto_config.j2 @@ -4,4 +4,4 @@ aws_access_key_id = {{ session_access_key | default(aws_access_key) }} aws_secret_access_key = {{ session_secret_key | default(aws_secret_key) }} {% if security_token is defined or session_security_token is defined %} aws_security_token = {{ session_security_token | default(security_token) }} -{% endif %} \ No newline at end of file +{% endif %}