vmware: refactoring of vmware test roles -- part6

Refactoring of the following roles to make use of the new
`prepare_vmware_tests` role.

- `vmware_inventory`
- `vmware_local_role_facts`
- `vmware_local_role_manager`
- `vmware_local_user_facts`
- `vmware_local_user_manager`
- `vmware_maintenancemode`
- `vmware_portgroup_facts`
- `vmware_resource_pool`
- `vmware_resource_pool_facts`

This patch depends on: https://github.com/ansible/ansible/pull/55719

Original PR: https://github.com/ansible/ansible/pull/54882
This commit is contained in:
Gonéri Le Bouder 2019-04-24 15:11:47 -04:00
parent b108d01b0f
commit 39d1794ed9
17 changed files with 172 additions and 463 deletions

View file

@ -4,3 +4,4 @@ skip/python3
destructive destructive
needs/file/contrib/inventory/vmware_inventory.py needs/file/contrib/inventory/vmware_inventory.py
needs/file/contrib/inventory/vmware_inventory.ini needs/file/contrib/inventory/vmware_inventory.ini
needs/target/prepare_vmware_tests

View file

@ -1,2 +1,3 @@
shippable/vcenter/group1 shippable/vcenter/group1
cloud/vcenter cloud/vcenter
needs/target/prepare_vmware_tests

View file

@ -2,6 +2,9 @@
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com> # Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- import_role:
name: prepare_vmware_tests
- name: Set list of Roles in fact - name: Set list of Roles in fact
set_fact: set_fact:
role_list: role_list:
@ -11,56 +14,26 @@
- Anonymous - Anonymous
- ReadOnly - ReadOnly
- name: Wait for Flask controller to come up online - &role_data
wait_for: name: Gather Role facts
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?esx=1
register: vcsim_instance
- name: Wait for Flask controller to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- debug: var=vcsim_instance
- name: Gather Role facts
vmware_local_role_facts: vmware_local_role_facts:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
validate_certs: no validate_certs: no
register: role_details register: role_details
- name: Test if role id is present for role - &role_test
name: Test if role id is present for role
assert: assert:
that: "{{ role_details.local_role_facts | json_query(s_query) != [] }}" that: "{{ role_details.local_role_facts | json_query(s_query) != [] }}"
vars: vars:
s_query: "[?role_name == '{{ item }}'].role_id" s_query: "[?role_name == '{{ item }}'].role_id"
with_items: "{{ role_list }}" with_items: "{{ role_list }}"
- name: Gather Role facts in check mode - <<: *role_data
vmware_local_role_facts: name: Gather Role facts in check mode
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
validate_certs: no
register: role_details
check_mode: yes check_mode: yes
- name: Test if role id is present for role - <<: *role_test
assert: name: Test if role id is present for role in check mode
that: "{{ role_details.local_role_facts | json_query(s_query) != [] }}"
vars:
s_query: "[?role_name == '{{ item }}'].role_id"
with_items: "{{ role_list }}"

View file

@ -1,2 +1,3 @@
shippable/vcenter/group1 shippable/vcenter/group1
cloud/vcenter cloud/vcenter
needs/target/prepare_vmware_tests

View file

@ -2,34 +2,14 @@
# Copyright: (c) 2017-2018, Abhijeet Kasurde <akasurde@redhat.com> # Copyright: (c) 2017-2018, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Wait for Flask controller to come up online - import_role:
wait_for: name: prepare_vmware_tests
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?esx=1
register: vcsim_instance
- name: Wait for Flask controller to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- debug: var=vcsim_instance
- name: Create a role without privileges in check mode - name: Create a role without privileges in check mode
vmware_local_role_manager: vmware_local_role_manager:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
local_role_name: SampleRole_0001 local_role_name: SampleRole_0001
validate_certs: no validate_certs: no
state: present state: present
@ -41,11 +21,12 @@
that: that:
- role_creation.changed - role_creation.changed
- name: Create a role without privileges - &create_role_data
name: Create a role without privileges
vmware_local_role_manager: vmware_local_role_manager:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
local_role_name: SampleRole_0001 local_role_name: SampleRole_0001
validate_certs: no validate_certs: no
state: present state: present
@ -56,26 +37,20 @@
that: that:
- role_creation_0001.changed - role_creation_0001.changed
- name: Again create a role without privileges - <<: *create_role_data
vmware_local_role_manager: name: Again create a role without privileges
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
local_role_name: SampleRole_0001
validate_certs: no
state: present
register: role_creation_0001
- name: verify if role is not created again - name: verify if role is not created again
assert: assert:
that: that:
- not role_creation_0001.changed - not role_creation_0001.changed
- name: Delete a role - &delete_role_data
name: Delete a role
vmware_local_role_manager: vmware_local_role_manager:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
local_role_name: SampleRole_0001 local_role_name: SampleRole_0001
validate_certs: no validate_certs: no
state: absent state: absent
@ -86,15 +61,8 @@
that: that:
- role_creation_0001.changed - role_creation_0001.changed
- name: Delete role again - <<: *delete_role_data
vmware_local_role_manager: name: Delete role again
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
local_role_name: SampleRole_0001
validate_certs: no
state: absent
register: role_creation_0001
- name: Verify if role is absent again - name: Verify if role is absent again
assert: assert:
@ -103,9 +71,9 @@
- name: Create a role with privileges - name: Create a role with privileges
vmware_local_role_manager: vmware_local_role_manager:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
local_role_name: SampleRole_0001 local_role_name: SampleRole_0001
validate_certs: no validate_certs: no
local_privilege_ids: ['VirtualMachine.State.RenameSnapshot'] local_privilege_ids: ['VirtualMachine.State.RenameSnapshot']
@ -117,11 +85,12 @@
that: that:
- role_creation_0001.changed - role_creation_0001.changed
- name: Add a privilege to existing privileges - &exist_role_data
name: Add a privilege to existing privileges
vmware_local_role_manager: vmware_local_role_manager:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
local_role_name: SampleRole_0001 local_role_name: SampleRole_0001
validate_certs: no validate_certs: no
local_privilege_ids: ['Folder.Create'] local_privilege_ids: ['Folder.Create']
@ -134,28 +103,20 @@
that: that:
- role_add.changed - role_add.changed
- name: Again add a privilege to existing privileges - <<: *exist_role_data
vmware_local_role_manager: name: Again add a privilege to existing privileges
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
local_role_name: SampleRole_0001
validate_certs: no
local_privilege_ids: ['Folder.Create']
action: add
state: present
register: role_add_0002
- name: Verify if role is not updated - name: Verify if role is not updated
assert: assert:
that: that:
- not role_add_0002.changed - not role_add.changed
- name: Remove a privilege from existing privileges - &remove_role_data
name: Remove a privilege from existing privileges
vmware_local_role_manager: vmware_local_role_manager:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
local_role_name: SampleRole_0001 local_role_name: SampleRole_0001
validate_certs: no validate_certs: no
local_privilege_ids: ['Folder.Create'] local_privilege_ids: ['Folder.Create']
@ -167,27 +128,20 @@
that: that:
- role_remove.changed - role_remove.changed
- name: Again remove a privilege from existing privileges - <<: *remove_role_data
vmware_local_role_manager: name: Again remove a privilege from existing privileges
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
local_role_name: SampleRole_0001
validate_certs: no
local_privilege_ids: ['Folder.Create']
action: remove
register: role_remove_0002
- name: Verify if role is not updated - name: Verify if role is not updated
assert: assert:
that: that:
- not role_remove_0002.changed - not role_remove.changed
- name: Set a privilege to an existing role - &set_priv_role_data
name: Set a privilege to an existing role
vmware_local_role_manager: vmware_local_role_manager:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
local_role_name: SampleRole_0001 local_role_name: SampleRole_0001
validate_certs: no validate_certs: no
local_privilege_ids: ['Folder.Create'] local_privilege_ids: ['Folder.Create']
@ -199,18 +153,10 @@
that: that:
- role_set.changed - role_set.changed
- name: Again set a privilege to an existing role - <<: *set_priv_role_data
vmware_local_role_manager: name: Again set a privilege to an existing role
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
local_role_name: SampleRole_0001
validate_certs: no
local_privilege_ids: ['Folder.Create']
action: set
register: role_set_0002
- name: verify if role is not updated - name: verify if role is not updated
assert: assert:
that: that:
- not role_set_0002.changed - not role_set.changed

View file

@ -1,2 +1,3 @@
cloud/vcenter cloud/vcenter
unsupported shippable/vcenter/group1
needs/target/prepare_vmware_tests

View file

@ -4,41 +4,34 @@
# Commenting local user testcases as older vcsim docker image # Commenting local user testcases as older vcsim docker image
# does not support this. # does not support this.
- when: vcsim is not defined
block:
- import_role:
name: prepare_vmware_tests
vars:
setup_esxi_instance: true
- name: Wait for Flask controller to come up online # Local user manager works only with standalone ESXi server
wait_for: - &user_fact_data
host: "{{ vcsim }}" name: Gather facts about users
port: 5000
state: started
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
# Local user manager works only with standalone ESXi server
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?esx=1
register: vcsim_instance
- debug:
var: vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- name: Gather facts about users
vmware_local_user_facts: vmware_local_user_facts:
hostname: "{{ vcsim }}" hostname: "{{ hostvars[esxi1].ansible_host }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ hostvars[esxi1].ansible_user }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ hostvars[esxi1].ansible_password }}"
validate_certs: False validate_certs: False
register: all_user_facts register: all_user_facts
- name: ensure user facts are gathered - name: ensure user facts are gathered
assert:
that:
- not all_user_facts.changed
- all_user_facts.local_user_facts is defined
- <<: *user_fact_data
name: Gather facts about users in check mode
check_mode: yes
- name: ensure user facts are gathered
assert: assert:
that: that:
- not all_user_facts.changed - not all_user_facts.changed

View file

@ -1,2 +1,3 @@
cloud/vcenter cloud/vcenter
unsupported shippable/vcenter/group1
needs/target/prepare_vmware_tests

View file

@ -1,94 +1,12 @@
# Test code for the vmware_local_user_manager module. - import_role:
# Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com> name: prepare_vmware_tests
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Commenting local user testcases as older vcsim docker image
# does not support this.
- name: Wait for Flask controller to come up online
wait_for:
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
# Local user manager works only with standalone ESXi server
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?esx=1
register: vcsim_instance
- debug:
var: vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
# Testcase 0001: Add Local user in ESXi server
- name: add local user
vmware_local_user_manager:
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance.json.username }}"
password: "{{ vcsim_instance.json.password }}"
validate_certs: no
local_user_name: testuser_0001
local_user_password: "SamplePassword!"
state: present
register: user_add_0001
- name: ensure user is created
assert:
that:
- user_add_0001.changed == true
# Testcase 0002: Delete Local user in ESXi server
- name: Delete local user
vmware_local_user_manager:
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance.json.username }}"
password: "{{ vcsim_instance.json.password }}"
validate_certs: no
local_user_name: testuser_0001
state: absent
register: user_delete_0002
- name: ensure user is deleted
assert:
that:
- user_delete_0002.changed == true
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
# Local user manager works only with standalone ESXi server not with vCenter
# So testcase should check failures
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?cluster=2
register: vcsim_instance
- debug:
var: vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
# Testcase 0003: Add Local user in vCenter server # Testcase 0003: Add Local user in vCenter server
- name: add local user - name: add local user
vmware_local_user_manager: vmware_local_user_manager:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
validate_certs: no validate_certs: no
local_user_name: testuser_0003 local_user_name: testuser_0003
local_user_password: "SamplePassword!" local_user_password: "SamplePassword!"
@ -105,9 +23,9 @@
# Testcase 0003: Delete Local user in vCenter server # Testcase 0003: Delete Local user in vCenter server
- name: Delete local user - name: Delete local user
vmware_local_user_manager: vmware_local_user_manager:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
validate_certs: no validate_certs: no
local_user_name: testuser_0003 local_user_name: testuser_0003
state: absent state: absent

View file

@ -1,2 +1,3 @@
shippable/vcenter/group1 shippable/vcenter/group1
cloud/vcenter cloud/vcenter
needs/target/prepare_vmware_tests

View file

@ -1,42 +1,20 @@
# Test code for the vmware_guest_maintenancemode module. # Test code for the vmware_guest_maintenancemode module.
# Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com> # Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- import_role:
name: prepare_vmware_tests
vars:
setup_attach_host: true
- name: Wait for Flask controller to come up online
wait_for:
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?datacenter=1&cluster=1&folder=0
register: vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- name: Get a list of host systems from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=H
register: hostsystems
- name: Enter maintenance mode - name: Enter maintenance mode
vmware_maintenancemode: vmware_maintenancemode:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
state: present state: present
esxi_hostname: "{{ item | basename }}" esxi_hostname: '{{ hostvars[esxi2].ansible_host }}'
validate_certs: no validate_certs: no
with_items: "{{ hostsystems['json'] }}"
register: test_result_0001 register: test_result_0001
- debug: var=test_result_0001 - debug: var=test_result_0001
@ -44,17 +22,16 @@
- name: assert that changes were made - name: assert that changes were made
assert: assert:
that: that:
- "test_result_0001.results|map(attribute='changed')|unique|list == [true]" - test_result_0001 is changed
- name: Enter maintenance mode again - name: Enter maintenance mode again
vmware_maintenancemode: vmware_maintenancemode:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
state: present state: present
esxi_hostname: "{{ item | basename }}" esxi_hostname: '{{ hostvars[esxi2].ansible_host }}'
validate_certs: no validate_certs: no
with_items: "{{ hostsystems['json'] }}"
register: test_result_0002 register: test_result_0002
- debug: var=test_result_0002 - debug: var=test_result_0002
@ -62,17 +39,16 @@
- name: assert that no changes were made - name: assert that no changes were made
assert: assert:
that: that:
- "test_result_0002.results|map(attribute='changed')|unique|list == [false]" - not (test_result_0002 is changed)
- name: Exit maintenance mode - name: Exit maintenance mode
vmware_maintenancemode: vmware_maintenancemode:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
state: absent state: absent
esxi_hostname: "{{ item | basename }}" esxi_hostname: '{{ hostvars[esxi2].ansible_host }}'
validate_certs: no validate_certs: no
with_items: "{{ hostsystems['json'] }}"
register: test_result_0003 register: test_result_0003
- debug: var=test_result_0003 - debug: var=test_result_0003
@ -80,17 +56,16 @@
- name: assert that changes were made - name: assert that changes were made
assert: assert:
that: that:
- "test_result_0003.results|map(attribute='changed')|unique|list == [true]" - test_result_0003 is changed
- name: Exit maintenance mode again - name: Exit maintenance mode again
vmware_maintenancemode: vmware_maintenancemode:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
state: absent state: absent
esxi_hostname: "{{ item | basename }}" esxi_hostname: '{{ hostvars[esxi2].ansible_host }}'
validate_certs: no validate_certs: no
with_items: "{{ hostsystems['json'] }}"
register: test_result_0004 register: test_result_0004
- debug: var=test_result_0004 - debug: var=test_result_0004
@ -98,4 +73,4 @@
- name: assert that no changes were made - name: assert that no changes were made
assert: assert:
that: that:
- "test_result_0004.results|map(attribute='changed')|unique|list == [false]" - not (test_result_0004 is changed)

View file

@ -1,3 +1,4 @@
shippable/vcenter/group1 shippable/vcenter/group1
cloud/vcenter cloud/vcenter
needs/target/prepare_vmware_tests

View file

@ -1,57 +1,17 @@
# Test code for the vmware_portgroup_facts module. # Test code for the vmware_portgroup_facts module.
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com> # Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- import_role:
name: prepare_vmware_tests
vars:
setup_attach_host: true
- name: Wait for Flask controller to come up online
wait_for:
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?cluster=2
register: vcsim_instance
- debug:
var: vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- name: get a list of Cluster from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=CCR
register: clusters
- name: get a cluster
set_fact:
ccr1: "{{ clusters.json[0] | basename }}"
- name: get a list of hosts from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=H
register: hosts
- name: get a host
set_fact:
host1: "{{ hosts.json[0] | basename }}"
- debug: var=ccr1
- debug: var=host1
- name: Gather portgroup facts for all ESXi host from given cluster - name: Gather portgroup facts for all ESXi host from given cluster
vmware_portgroup_facts: vmware_portgroup_facts:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
validate_certs: no validate_certs: no
cluster_name: "{{ ccr1 }}" cluster_name: "{{ ccr1 }}"
register: portgroup_0001_results register: portgroup_0001_results
@ -63,11 +23,11 @@
- name: Gather portgroup facts for an ESXi host - name: Gather portgroup facts for an ESXi host
vmware_portgroup_facts: vmware_portgroup_facts:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
validate_certs: no validate_certs: no
esxi_hostname: "{{ host1 }}" esxi_hostname: '{{ hostvars[esxi1].ansible_host }}'
register: portgroup_0002_results register: portgroup_0002_results
- assert: - assert:
@ -77,11 +37,11 @@
- name: Gather all portgroup facts for an ESXi host - name: Gather all portgroup facts for an ESXi host
vmware_portgroup_facts: vmware_portgroup_facts:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
validate_certs: no validate_certs: no
esxi_hostname: "{{ host1 }}" esxi_hostname: '{{ hostvars[esxi1].ansible_host }}'
policies: true policies: true
register: portgroup_0003_results register: portgroup_0003_results
@ -92,11 +52,11 @@
- name: Gather all portgroup facts for an ESXi host in check mode - name: Gather all portgroup facts for an ESXi host in check mode
vmware_portgroup_facts: vmware_portgroup_facts:
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance.json.username }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance.json.password }}" password: "{{ vcenter_password }}"
validate_certs: no validate_certs: no
esxi_hostname: "{{ host1 }}" esxi_hostname: '{{ hostvars[esxi1].ansible_host }}'
policies: true policies: true
register: portgroup_0004_results register: portgroup_0004_results
check_mode: yes check_mode: yes

View file

@ -1,2 +1,3 @@
shippable/vcenter/group1 shippable/vcenter/group1
cloud/vcenter cloud/vcenter
needs/target/prepare_vmware_tests

View file

@ -2,56 +2,19 @@
# Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com> # Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Wait for Flask controller to come up online - import_role:
wait_for: name: prepare_vmware_tests
host: "{{ vcsim }}" vars:
port: 5000 setup_attach_host: true
state: started setup_datastore: true
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?cluster=2
register: vcsim_instance
- debug: var=vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- name: get a list of Datacenters from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=DC
register: datacenters
- name: get a datacenter
set_fact: dc1="{{ datacenters['json'][0] | basename }}"
- debug: var=dc1
- name: get a list of Clusters from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=CCR
register: clusters
- name: get a cluster
set_fact: ccr1="{{ clusters['json'][0] | basename }}"
- debug: var=ccr1
# Testcase 0001: Add Resource pool # Testcase 0001: Add Resource pool
- name: add resource pool - name: add resource pool
vmware_resource_pool: vmware_resource_pool:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
datacenter: "{{ dc1 }}" datacenter: "{{ dc1 }}"
cluster: "{{ ccr1 }}" cluster: "{{ ccr1 }}"
resource_pool: test_resource_0001 resource_pool: test_resource_0001
@ -66,27 +29,19 @@
state: present state: present
register: resource_result_0001 register: resource_result_0001
- name: get a list of resources from vcsim after adding a resource pool
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=RP
register: new_rp_list
- set_fact: new_resource="{% for rp in new_rp_list['json'] %} {{ True if (rp | basename) == 'test_resource_0001' else False }} {% endfor %}"
- name: ensure a resource pool is present - name: ensure a resource pool is present
assert: assert:
that: that:
- "{{ resource_result_0001.changed == true }}" - "{{ resource_result_0001.changed == true }}"
- "{{ 'True' in new_resource }}"
# Testcase 0002: Add Resource pool again # Testcase 0002: Add Resource pool again
- name: add resource pool again - name: add resource pool again
vmware_resource_pool: vmware_resource_pool:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
datacenter: "{{ dc1 }}" datacenter: "{{ dc1 }}"
cluster: "{{ ccr1 }}" cluster: "{{ ccr1 }}"
resource_pool: test_resource_0001 resource_pool: test_resource_0001
@ -111,9 +66,9 @@
- name: add resource pool again - name: add resource pool again
vmware_resource_pool: vmware_resource_pool:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
datacenter: "{{ dc1 }}" datacenter: "{{ dc1 }}"
cluster: "{{ ccr1 }}" cluster: "{{ ccr1 }}"
resource_pool: test_resource_0001 resource_pool: test_resource_0001
@ -129,9 +84,9 @@
- name: add resource pool again - name: add resource pool again
vmware_resource_pool: vmware_resource_pool:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
datacenter: "{{ dc1 }}" datacenter: "{{ dc1 }}"
cluster: "{{ ccr1 }}" cluster: "{{ ccr1 }}"
resource_pool: test_resource_0001 resource_pool: test_resource_0001

View file

@ -1,2 +1,3 @@
shippable/vcenter/group1 shippable/vcenter/group1
cloud/vcenter cloud/vcenter
needs/target/prepare_vmware_tests

View file

@ -2,35 +2,15 @@
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com> # Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Wait for Flask controller to come up online - import_role:
wait_for: name: prepare_vmware_tests
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: start vcsim
uri:
url: http://{{ vcsim }}:5000/spawn?cluster=2
register: vcsim_instance
- debug: var=vcsim_instance
- name: Wait for vcsim server to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- name: Gather facts about resource pool - name: Gather facts about resource pool
vmware_resource_pool_facts: vmware_resource_pool_facts:
validate_certs: False validate_certs: False
hostname: "{{ vcsim }}" hostname: "{{ vcenter_hostname }}"
username: "{{ vcsim_instance['json']['username'] }}" username: "{{ vcenter_username }}"
password: "{{ vcsim_instance['json']['password'] }}" password: "{{ vcenter_password }}"
register: resource_result_0001 register: resource_result_0001
- name: ensure a resource pool is present - name: ensure a resource pool is present