diff --git a/.github/workflows/integ-test.yml b/.github/workflows/integ-test.yml index 3c209ac07..1c454069e 100644 --- a/.github/workflows/integ-test.yml +++ b/.github/workflows/integ-test.yml @@ -54,7 +54,7 @@ jobs: - run: apt install -y jq - run: mkdir -p $WORKDIR - run: cp -a ./ $WORKDIR - - run: ansible-galaxy collection install community.general + - run: ansible-galaxy collection install community.crypto community.general - run: | cd $WORKDIR echo "${{ vars.CI_CONFIG_HC_IP50 }}" > tests/integration/integration_config.yml @@ -65,6 +65,7 @@ jobs: ls -al tests/integration/integration_config.yml - run: cd $WORKDIR && ansible-playbook tests/integration/prepare/prepare_iso.yml - run: cd $WORKDIR && ansible-playbook tests/integration/prepare/prepare_vm.yml + - run: cd $WORKDIR && ansible-playbook tests/integration/prepare/prepare_examples.yml if: "${{ github.event.inputs.integ_tests_include || github.event.schedule }}" integ-matrix: @@ -165,7 +166,7 @@ jobs: eval export SC_USERNAME=$(cat tests/integration/integration_config.yml | yq '.sc_username') eval export SC_PASSWORD=$(cat tests/integration/integration_config.yml | yq '.sc_password') eval export SC_TIMEOUT=$(cat tests/integration/integration_config.yml | yq '.sc_timeout') - ansible-playbook --check examples/${{ matrix.example_name }} + ansible-playbook -i localhost, -e hypercore_example_check_mode=true examples/${{ matrix.example_name }} integ: needs: diff --git a/examples/certificate_signing_example.yml b/examples/certificate_signing_example.yml index 95862d8b3..5dc0e4856 100644 --- a/examples/certificate_signing_example.yml +++ b/examples/certificate_signing_example.yml @@ -3,6 +3,8 @@ hosts: localhost connection: local gather_facts: false + vars: + hypercore_example_check_mode: "{{ ansible_check_mode }}" tasks: # More info about openssl_privatekey module @@ -40,6 +42,8 @@ private_key: "{{ lookup('file', 'private_key_example.pem') }}" certificate: "{{ lookup('file', 'certificate_example.crt') }}" register: certificate_info + # This is problematic, it would restart API server + check_mode: "{{ hypercore_example_check_mode }}" - name: Show uploaded certificate info debug: diff --git a/examples/dns_config.yml b/examples/dns_config.yml index b527e48b4..6ee183721 100644 --- a/examples/dns_config.yml +++ b/examples/dns_config.yml @@ -15,13 +15,14 @@ dns_servers: - 1.2.3.4 - 5.6.7.8 - state: set + state: after # or before + # ------------------------------------------------------ + # Configure system with valid DNS resolvers - name: Modify existing DNS config configurations scale_computing.hypercore.dns_config: - search_domains: - - example.domain.com + search_domains: [] dns_servers: - - 0.0.0.1 - - 0.0.1.0 - state: before # or after + - 1.1.1.1 + - 1.0.0.1 + state: set diff --git a/examples/email_alert.yml b/examples/email_alert.yml index eacd32505..4b17aded9 100644 --- a/examples/email_alert.yml +++ b/examples/email_alert.yml @@ -6,6 +6,7 @@ vars: email: example@example.com email_new: new@example.com + hypercore_example_check_mode: "{{ ansible_check_mode }}" tasks: - name: Create Email alert recipient @@ -17,6 +18,8 @@ scale_computing.hypercore.email_alert: email: "{{ email }}" state: test + # Sending test can fail (invalid email, or invalid SMTP server). + check_mode: "{{ hypercore_example_check_mode }}" - name: Modify previously created Email alert recipient scale_computing.hypercore.email_alert: diff --git a/examples/list_vms_with_ide_disk.yml b/examples/list_vms_with_ide_disk.yml index 28b287778..6e85e7323 100644 --- a/examples/list_vms_with_ide_disk.yml +++ b/examples/list_vms_with_ide_disk.yml @@ -36,7 +36,9 @@ break print(json.dumps(ide_vm_names)) args: - executable: /usr/bin/python3 + # /usr/bin/python3 - fedora + # /usr/local/bin/python - python:3.10-slim-buster docker image + executable: python3 stdin: "{{ all_vms.records | to_json }}" changed_when: false register: ide_vm_names_result @@ -53,3 +55,5 @@ ansible.builtin.fail: msg: Found {{ ide_vm_names | length }} VMs using IDE disk when: ide_vm_names | length > 0 + # VMs with IDE disks are created while testing. Ignore them if testing. + ignore_errors: "{{ hypercore_example_check_mode | default(false) }}" diff --git a/examples/smtp.yml b/examples/smtp.yml index a8607f18d..0611922df 100644 --- a/examples/smtp.yml +++ b/examples/smtp.yml @@ -3,6 +3,8 @@ hosts: localhost connection: local gather_facts: false + # Example is safe to run - if we do not modify from_address + check_mode: true vars: smtp_server: smtp-relay.gmail.com smtp_port: 25 diff --git a/examples/time_server.yml b/examples/time_server.yml index 880a69dc1..179656864 100644 --- a/examples/time_server.yml +++ b/examples/time_server.yml @@ -3,6 +3,8 @@ hosts: localhost connection: local gather_facts: false + # NTP is always a bit problemtic for reconfiguration + check_mode: true vars: source: pool.ntp.org diff --git a/examples/time_zone_info.yml b/examples/time_zone_info.yml index 0dd971930..16aac6a77 100644 --- a/examples/time_zone_info.yml +++ b/examples/time_zone_info.yml @@ -6,7 +6,7 @@ tasks: - name: List current Time Zone entries - - scale_computing.hypercore.time_zone_info: + scale_computing.hypercore.time_zone_info: register: time_zone_info - ansible.builtin.debug: msg: "{{ time_zone_info }}" diff --git a/examples/virtual_disk.yml b/examples/virtual_disk.yml index 824c39098..2fc08f01c 100644 --- a/examples/virtual_disk.yml +++ b/examples/virtual_disk.yml @@ -8,9 +8,6 @@ # image_url: https://github.com/ddemlow/RestAPIExamples/blob/master/ubuntu18_04-cloud-init/ubuntu18cloudimage.qcow2 image_filename: "{{ image_url | split('/') | last }}" image_remove_old: false - sc_host: https://10.100.20.38 # TODO - sc_username: admin - sc_password: admin tasks: # # ------------------------------------------------------ @@ -39,10 +36,6 @@ - name: Upload Virtual Disk {{ image_filename }} to HyperCore scale_computing.hypercore.api: action: put - cluster_instance: - host: "{{ sc_host }}" - username: "{{ sc_username }}" - password: "{{ sc_password }}" endpoint: /rest/v1/VirtualDisk/upload data: filename: "{{ image_filename }}" @@ -54,10 +47,6 @@ - name: Get Information About the uploaded Virtual Disk in HyperCore scale_computing.hypercore.api: action: get - cluster_instance: - host: "{{ sc_host }}" - username: "{{ sc_username }}" - password: "{{ sc_password }}" endpoint: /rest/v1/VirtualDisk/{{ uploadResult.record.createdUUID }} register: result diff --git a/tests/integration/prepare/prepare_examples.yml b/tests/integration/prepare/prepare_examples.yml new file mode 100644 index 000000000..cd91d7023 --- /dev/null +++ b/tests/integration/prepare/prepare_examples.yml @@ -0,0 +1,44 @@ +--- +- name: Create resources for testing examples + hosts: localhost + connection: local + vars: + cluster_instance: + host: "{{ sc_host }}" + username: "{{ sc_username }}" + password: "{{ sc_password }}" + timeout: "{{ sc_timeout }}" + vars_files: + - ../integration_config.yml + + tasks: + - name: Debug show SC_HOST + ansible.builtin.debug: + msg: SC_HOST={{ lookup('ansible.builtin.env', 'SC_HOST') }} sc_host={{ sc_host }} + + # For examples/vm_replication_info.yml + - name: Create VM demo-vm for examples/vm_replication_info.yml + scale_computing.hypercore.vm: + cluster_instance: "{{ cluster_instance }}" + vm_name: demo-vm + description: demo-vm + state: present + tags: + - Xlab + memory: "{{ '512 MB' | human_to_bytes }}" + vcpu: 1 + attach_guest_tools_iso: false + power_state: stop + disks: + - type: virtio_disk + disk_slot: 0 + size: "{{ '1.1 GB' | human_to_bytes }}" + nics: + - vlan: 1 + type: RTL8139 + boot_devices: + - type: virtio_disk + disk_slot: 0 + - type: nic + nic_vlan: 1 + machine_type: BIOS