Skip to content

Commit

Permalink
Fix ansible-lint issues from prepare env files in tests. (#524)
Browse files Browse the repository at this point in the history
* Fix `schema[tasks]: $[0] 'block' is a required property` lint issue in prep env tasks

* Update ok to test command with dir structure changes

* Fix prep env sanity tests
  • Loading branch information
bhati-pradeep authored Dec 9, 2024
1 parent 2d2ad43 commit ddf9675
Show file tree
Hide file tree
Showing 20 changed files with 743 additions and 751 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ok-to-test-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ jobs:
echo '${{ secrets.FC_CONFIG }}' > tests/integration/targets/prepare_fc_env/vars/main.yml
echo '${{ secrets.PC_CONFIG }}' > tests/integration/targets/prepare_env/vars/main.yml
echo '${{ secrets.NDB_CONFIG }}' > tests/integration/targets/prepare_ndb_env/vars/main.yml
ansible-playbook tests/integration/targets/prepare_env/tasks/prepare_env.yml
ansible-playbook tests/integration/targets/prepare_ndb_env/tasks/prepare_env.yml
ansible-playbook tests/integration/targets/prepare_fc_env/tasks/prepare_fc_env.yml
ansible-playbook tests/integration/targets/prepare_foundation_env/tasks/prepare_foundation_env.yml
ansible-playbook tests/integration/targets/prepare_env/playbooks/prepare_env.yml
ansible-playbook tests/integration/targets/prepare_ndb_env/playbooks/prepare_env.yml
ansible-playbook tests/integration/targets/prepare_fc_env/playbooks/prepare_fc_env.yml
ansible-playbook tests/integration/targets/prepare_foundation_env/playbooks/prepare_foundation_env.yml
ansible-test integration --continue-on-error --python ${{ matrix.python-version }} --coverage $flag
ansible-test coverage report > coverage.txt
ansible-playbook tests/integration/targets/prepare_env/tasks/cleanup.yml
ansible-playbook tests/integration/targets/prepare_foundation_env/tasks/cleanup.yml
ansible-playbook tests/integration/targets/prepare_env/playbooks/cleanup.yml
ansible-playbook tests/integration/targets/prepare_foundation_env/playbooks/cleanup.yml
- name: Code Coverage Check
if: ${{ always() }}
Expand Down
67 changes: 67 additions & 0 deletions tests/integration/targets/prepare_env/playbooks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
- name: Clean up the environment
hosts: localhost
gather_facts: false
tasks:
- name: Include var file
ansible.builtin.include_vars: ../vars/main.yml
- name: Delete VM
ignore_errors: true
register: result
nutanix.ncp.ntnx_vms:
vm_uuid: "{{ vm.uuid }}"
state: absent
nutanix_host: "{{ ip }}"
nutanix_username: "{{ username }}"
nutanix_password: "{{ password }}"
validate_certs: false
# # - name: Delete DR VM
# # ntnx_vms:
# # vm_uuid: '{{dr_vm.uuid }}'
# # state: absent
# # nutanix_host: "{{ ip }}"
# # nutanix_username: "{{ username }}"
# # nutanix_password: "{{ password }}"
# # validate_certs: False
- name: Delete overlay
register: result
ignore_errors: true
nutanix.ncp.ntnx_subnets:
state: absent
nutanix_host: "{{ ip }}"
nutanix_username: "{{ username }}"
nutanix_password: "{{ password }}"
validate_certs: false
subnet_uuid: "{{ item }}"
loop:
- "{{ overlay.uuid }}"
- name: Delete vpc
register: result
ignore_errors: true
nutanix.ncp.ntnx_vpcs:
state: absent
nutanix_host: "{{ ip }}"
nutanix_username: "{{ username }}"
nutanix_password: "{{ password }}"
validate_certs: false
vpc_uuid: "{{ vpc.uuid }}"
- name: Delete subnets
ignore_errors: true
register: result
nutanix.ncp.ntnx_subnets:
state: absent
nutanix_host: "{{ ip }}"
nutanix_username: "{{ username }}"
nutanix_password: "{{ password }}"
validate_certs: false
subnet_uuid: "{{ item }}"
loop:
- "{{ external_nat_subnet.uuid }}"
- "{{ static.uuid }}"

- name: Delete downloaded disk file
ignore_errors: true
register: result
ansible.builtin.file:
path: "{{ disk_image.dest }}"
state: absent
212 changes: 212 additions & 0 deletions tests/integration/targets/prepare_env/playbooks/prepare_env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
---
- name: Prepare the environment
hosts: localhost
gather_facts: false

tasks:
- name: Include var file
ansible.builtin.include_vars: ../vars/main.yml
- name: Set environment variables
ansible.builtin.set_fact:
ip: "{{lookup('env', 'NUTANIX_HOST') }}"
username: "{{lookup('env', 'NUTANIX_USERNAME') }}"
password: "{{lookup('env', 'NUTANIX_PASSWORD') }}"
recovery_site_ip: "{{lookup('env', 'NUTANIX_DR_SITE')}}"
validate_certs: false
- name: Insert credentials block to vars
ansible.builtin.blockinfile:
path: ../vars/main.yml
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 0"
block: |
ip: "{{lookup('env', 'NUTANIX_HOST') }}"
username: "{{lookup('env', 'NUTANIX_USERNAME') }}"
password: "{{lookup('env', 'NUTANIX_PASSWORD') }}"
recovery_site_ip: "{{lookup('env', 'NUTANIX_DR_SITE') }}"
validate_certs: false
- name: Create external subnet with NAT
nutanix.ncp.ntnx_subnets:
state: present
nutanix_host: "{{ ip }}"
validate_certs: false
nutanix_username: "{{ username }}"
nutanix_password: "{{ password }}"
name: "{{external_nat_subnets[0].name}}"
external_subnet:
vlan_id: "{{external_nat_subnets[0].vlan_id}}"
enable_nat: true
cluster:
name: "{{ cluster.name }}"
ipam:
network_ip: "{{ external_nat_subnets[0].network_ip }}"
network_prefix: "{{ external_nat_subnets[0].network_prefix }}"
gateway_ip: "{{ external_nat_subnets[0].gateway_ip_address }}"
ip_pools:
- start_ip: "{{ external_nat_subnets[0].dhcp.start_address }}"
end_ip: "{{ external_nat_subnets[0].dhcp.end_address }}"
register: result
- name: Insert external subnet configuration block to vars
ansible.builtin.blockinfile:
path: ../vars/main.yml
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 1"
block: |
external_nat_subnet:
name: "{{external_nat_subnets[0].name}}"
uuid: "{{result.subnet_uuid}}"
- name: Create min VPC with external_subnet uuid
nutanix.ncp.ntnx_vpcs:
validate_certs: false
state: present
wait: true
nutanix_host: "{{ ip }}"
nutanix_username: "{{ username }}"
nutanix_password: "{{ password }}"
name: "{{vpc_name}}"
external_subnets:
- subnet_uuid: "{{ result.subnet_uuid }}"
register: result

- name: Insert VPC configuration block to vars
ansible.builtin.blockinfile:
path: ../vars/main.yml
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 2"
block: |
vpc:
name: "{{vpc_name}}"
uuid: "{{result.vpc_uuid}}"
- name: Create vlan subnet with IPAM
nutanix.ncp.ntnx_subnets:
state: present
nutanix_host: "{{ ip }}"
wait: true
validate_certs: false
nutanix_username: "{{ username }}"
nutanix_password: "{{ password }}"
name: "{{static_subnet_name}}"
vlan_subnet:
vlan_id: 373
virtual_switch:
name: vs0
cluster:
name: "{{ cluster.name }}"
ipam:
network_ip: 10.30.30.0
network_prefix: 24
gateway_ip: 10.30.30.254
ip_pools:
- start_ip: 10.30.30.10
end_ip: 10.30.30.90
register: result

- name: Insert vlan subnet configuration block to var file
ansible.builtin.blockinfile:
path: ../vars/main.yml
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 3"
block: |
static:
name: "{{static_subnet_name}}"
uuid: "{{result.subnet_uuid}}"
network_ip: 10.30.30.0
network_prefix: 24
gateway_ip: 10.30.30.254
- name: Include var file
ansible.builtin.include_vars: ../vars/main.yml
- name: Create overlay Subnet with minimum requirements
nutanix.ncp.ntnx_subnets:
state: present
nutanix_host: "{{ ip }}"
validate_certs: false
nutanix_username: "{{ username }}"
nutanix_password: "{{ password }}"
name: "{{overlay_subnet.name}}"
overlay_subnet:
vpc:
uuid: "{{ vpc.uuid }}"
ipam:
network_ip: "{{overlay_subnet.network_ip}}"
network_prefix: "{{overlay_subnet.network_prefix}}"
gateway_ip: "{{overlay_subnet.gateway_ip}}"
register: result

- name: Insert overlay subnet configuration block to var file
ansible.builtin.blockinfile:
path: ../vars/main.yml
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 4"
block: |
overlay:
name: "{{overlay_subnet.name}}"
uuid: "{{result.subnet_uuid}}"
- name: Create VM with overlay subnet
nutanix.ncp.ntnx_vms:
state: present
nutanix_host: "{{ ip }}"
nutanix_username: "{{ username }}"
nutanix_password: "{{ password }}"
validate_certs: false
name: "{{vm_name}}"
cluster:
uuid: "{{ cluster.uuid }}"
networks:
- is_connected: true
subnet:
name: "{{overlay_subnet.name}}"
private_ip: "{{overlay_subnet.private_ip}}"
register: result

- name: Insert vm configuration block to var file
ansible.builtin.blockinfile:
path: ../vars/main.yml
marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 5"
block: |
vm:
name: "{{vm_name}}"
uuid: "{{result.vm_uuid}}"
# - name: create VM with static subnet for dr tests
# nutanix.ncp.ntnx_vms:
# state: present
# nutanix_host: "{{ ip }}"
# nutanix_username: "{{ username }}"
# nutanix_password: "{{ password }}"
# validate_certs: false
# name: "{{dr_vm_name}}"
# categories:
# Environment:
# - Staging
# - Testing
# cluster:
# uuid: "{{ cluster.uuid }}"
# networks:
# - is_connected: true
# subnet:
# name: "{{static_subnet_name}}"
# vcpus: 1
# cores_per_vcpu: 1
# memory_gb: 1
# register: result

# - name: Insert vm configuration block to var file
# ansible.builtin.blockinfile:
# path: ../vars/main.yml
# marker: "# {mark} ANSIBLE MANAGED BLOCK insertion 6"
# block: |
# dr_vm:
# name: "{{dr_vm_name}}"
# uuid: "{{result.vm_uuid}}"

- name: Downloading disk image for image related tests
ansible.builtin.get_url:
mode: "0644"
url: "{{ disk_image.url }}"
dest: "{{ disk_image.dest }}"
# # - name: create address group for network security policy related tests
# # nutanix.ncp.ntnx_address_groups:
# # state: present
# # name: dest
# # desc: dest
# # subnets:
# # - network_ip: "10.1.1.0"
# # network_prefix: 24
65 changes: 0 additions & 65 deletions tests/integration/targets/prepare_env/tasks/cleanup.yml

This file was deleted.

1 change: 0 additions & 1 deletion tests/integration/targets/prepare_env/tasks/main.yml

This file was deleted.

Loading

0 comments on commit ddf9675

Please sign in to comment.