diff --git a/tripleo_ansible/roles/tripleo_transfer/molecule/default/cleanup.yml b/tripleo_ansible/roles/tripleo_transfer/molecule/default/cleanup.yml new file mode 100644 index 000000000..5242a1059 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_transfer/molecule/default/cleanup.yml @@ -0,0 +1,29 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Cleanup + hosts: localhost + connection: local + gather_facts: false + any_errors_fatal: true + tasks: + - name: Remove test files + file: + state: absent + path: "{{ item }}" + loop: + - "{{ test_src_dir }}" + - "{{ test_dst_dir }}" diff --git a/tripleo_ansible/roles/tripleo_transfer/molecule/default/converge.yml b/tripleo_ansible/roles/tripleo_transfer/molecule/default/converge.yml index 758e9aff3..fd6047e5a 100644 --- a/tripleo_ansible/roles/tripleo_transfer/molecule/default/converge.yml +++ b/tripleo_ansible/roles/tripleo_transfer/molecule/default/converge.yml @@ -27,9 +27,39 @@ hosts: localhost connection: local any_errors_fatal: true - roles: - - role: "tripleo_transfer" - tripleo_transfer_src_host: controller2 - tripleo_transfer_src_dir: /etc - tripleo_transfer_dest_host: controller1 - tripleo_transfer_dest_dir: /opt/etc-target + tasks: + - name: Install openssl for file creation + package: + name: openssl + state: present + become: true + + - name: Create test directories + file: + state: directory + path: "{{ item }}" + loop: + - "{{ test_src_dir }}" + - "{{ test_dst_dir }}" + + - name: Create 1GB src test files with random content + shell: >- + openssl rand -out {{ item }} -base64 $(( 2**30 * 3/4 )) + args: + chdir: "{{ test_src_dir }}" + creates: "{{ item }}" + loop: "{{ test_src_files }}" + + - name: Create empty dst test files with random content + file: + path: "{{ test_dst_dir }}/{{ item }}" + state: touch + loop: "{{ test_dst_files }}" + + - include_role: + name: "tripleo_transfer" + vars: + tripleo_transfer_src_host: controller2 + tripleo_transfer_src_dir: "{{ test_src_dir }}" + tripleo_transfer_dest_host: controller1 + tripleo_transfer_dest_dir: "{{ test_dst_dir }}" diff --git a/tripleo_ansible/roles/tripleo_transfer/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo_transfer/molecule/default/molecule.yml index 589349cd1..6c9fb2df7 100644 --- a/tripleo_ansible/roles/tripleo_transfer/molecule/default/molecule.yml +++ b/tripleo_ansible/roles/tripleo_transfer/molecule/default/molecule.yml @@ -36,13 +36,27 @@ provisioner: ansible_host: 127.0.0.2 controller2: ansible_host: 127.0.0.3 + vars: + test_src_dir: "/tmp/src_files" + test_src_files: + - testfile1 + - testfile2 + - testfile3 + test_dst_dir: "/tmp/dst_files" + test_dst_files: + - testfile4 + - testfile5 + - testfile6 log: true env: ANSIBLE_STDOUT_CALLBACK: yaml scenario: test_sequence: + - cleanup - converge + - verify + - cleanup verifier: - name: testinfra + name: ansible diff --git a/tripleo_ansible/roles/tripleo_transfer/molecule/default/verify.yml b/tripleo_ansible/roles/tripleo_transfer/molecule/default/verify.yml new file mode 100644 index 000000000..ee50f57e9 --- /dev/null +++ b/tripleo_ansible/roles/tripleo_transfer/molecule/default/verify.yml @@ -0,0 +1,47 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Verify + hosts: localhost + connection: local + any_errors_fatal: true + tasks: + - name: Collect file system data + find: + paths: + - "{{ test_src_dir }}" + - "{{ test_dst_dir }}" + get_checksum: true + recurse: true + register: _fs_data + + - name: Verify that the src files copied to the dst + assert: + that: + - _fs_data | json_query(srcfilequery) == _fs_data | json_query(dstfilequery) + vars: + srcfilequery: files[?path =='{{ test_src_dir }}/{{ item }}'].checksum + dstfilequery: files[?path =='{{ test_dst_dir }}/{{ item }}'].checksum + loop: "{{ test_src_files }}" + + - set_fact: + result_file_list: "{{ _fs_data | json_query('files[*].path') }}" + test_dst_files: "{{ test_dst_files | map('regex_replace', '(.*)', test_dst_dir ~ '/\\1') }}" + + - name: Verify that the dst file are not there any more + assert: + that: + - test_dst_files is not subset(result_file_list)