mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-09-30 05:23:29 -07:00
Rework gcp_compute_instance integration tests
Also adding the test cases for new attachDisk feature
This commit is contained in:
parent
a05a7be02a
commit
a65d6ebfa5
3 changed files with 120 additions and 8 deletions
|
@ -0,0 +1,104 @@
|
||||||
|
---
|
||||||
|
- block:
|
||||||
|
- name: Create instance
|
||||||
|
google.cloud.gcp_compute_instance:
|
||||||
|
name: "{{ resource_name }}-attach-vm"
|
||||||
|
machine_type: n1-standard-1
|
||||||
|
state: present
|
||||||
|
disks:
|
||||||
|
- auto_delete: true
|
||||||
|
boot: true
|
||||||
|
initialize_params:
|
||||||
|
source_image: "{{ gcp_disk_image }}"
|
||||||
|
disk_type: pd-standard
|
||||||
|
network_interfaces:
|
||||||
|
- network: "{{ _network }}"
|
||||||
|
zone: "{{ gcp_zone }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
register: _result1
|
||||||
|
|
||||||
|
- name: Verify instance info post-create
|
||||||
|
google.cloud.gcp_compute_instance_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ _result1.name }}
|
||||||
|
zone: "{{ gcp_zone }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: _info1
|
||||||
|
|
||||||
|
- name: Create extra disk
|
||||||
|
google.cloud.gcp_compute_disk:
|
||||||
|
name: "{{ resource_name }}-extra"
|
||||||
|
state: present
|
||||||
|
zone: "{{ gcp_zone }}"
|
||||||
|
size_gb: 20
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
register: _disk
|
||||||
|
|
||||||
|
- name: Attach extra disk to instance
|
||||||
|
google.cloud.gcp_compute_instance:
|
||||||
|
name: "{{ resource_name }}-attach-vm"
|
||||||
|
machine_type: n1-standard-1
|
||||||
|
state: present
|
||||||
|
disks:
|
||||||
|
- auto_delete: true
|
||||||
|
boot: true
|
||||||
|
initialize_params:
|
||||||
|
source_image: "{{ gcp_disk_image }}"
|
||||||
|
disk_type: pd-standard
|
||||||
|
- source: "{{ _disk }}"
|
||||||
|
network_interfaces:
|
||||||
|
- network: "{{ _network }}"
|
||||||
|
zone: "{{ gcp_zone }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
register: _result2
|
||||||
|
|
||||||
|
- name: Verify instance info post-change
|
||||||
|
google.cloud.gcp_compute_instance_info:
|
||||||
|
filters:
|
||||||
|
- name = {{ _result2.name }}
|
||||||
|
zone: "{{ gcp_zone }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
scopes:
|
||||||
|
- https://www.googleapis.com/auth/compute
|
||||||
|
register: _info2
|
||||||
|
|
||||||
|
- name: Run assertions
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- _info1.resources | length > 0
|
||||||
|
- _info1.resources[0].disks | length == 1
|
||||||
|
- _info2.resources | length > 0
|
||||||
|
- _info2.resources[0].disks | length == 2
|
||||||
|
|
||||||
|
always:
|
||||||
|
# teardown
|
||||||
|
- name: Destroy instance
|
||||||
|
google.cloud.gcp_compute_instance:
|
||||||
|
name: "{{ resource_name }}-attach-vm"
|
||||||
|
state: absent
|
||||||
|
machine_type: n1-standard-1
|
||||||
|
zone: "{{ gcp_zone }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
|
||||||
|
- name: Destroy extra disk
|
||||||
|
google.cloud.gcp_compute_disk:
|
||||||
|
name: "{{ resource_name }}-extra"
|
||||||
|
state: absent
|
||||||
|
zone: "{{ gcp_zone }}"
|
||||||
|
project: "{{ gcp_project }}"
|
||||||
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
|
@ -9,8 +9,8 @@
|
||||||
google.cloud.gcp_compute_disk:
|
google.cloud.gcp_compute_disk:
|
||||||
name: "{{ resource_prefix }}-{{ item.key }}"
|
name: "{{ resource_prefix }}-{{ item.key }}"
|
||||||
size_gb: 50
|
size_gb: 50
|
||||||
source_image: projects/rhel-cloud/global/images/rhel-9-v20250513
|
source_image: "{{ gcp_disk_image }}"
|
||||||
zone: us-central1-a
|
zone: "{{ gcp_zone }}"
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
network_interfaces:
|
network_interfaces:
|
||||||
- network: "{{ _network }}"
|
- network: "{{ _network }}"
|
||||||
nic_type: "{{ item.value if item.value != 'default' else omit }}"
|
nic_type: "{{ item.value if item.value != 'default' else omit }}"
|
||||||
zone: us-central1-a
|
zone: "{{ gcp_zone }}"
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
google.cloud.gcp_compute_instance_info:
|
google.cloud.gcp_compute_instance_info:
|
||||||
filters:
|
filters:
|
||||||
- name = {{ resource_name }}-{{ item.key }}
|
- name = {{ resource_name }}-{{ item.key }}
|
||||||
zone: us-central1-a
|
zone: "{{ gcp_zone }}"
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
google.cloud.gcp_compute_instance:
|
google.cloud.gcp_compute_instance:
|
||||||
name: "{{ resource_name }}-{{ item.key }}"
|
name: "{{ resource_name }}-{{ item.key }}"
|
||||||
machine_type: n1-standard-1
|
machine_type: n1-standard-1
|
||||||
zone: us-central1-a
|
zone: "{{ gcp_zone }}"
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
- name: Delete disk
|
- name: Delete disk
|
||||||
google.cloud.gcp_compute_disk:
|
google.cloud.gcp_compute_disk:
|
||||||
name: "{{ resource_prefix }}-{{ item.key }}"
|
name: "{{ resource_prefix }}-{{ item.key }}"
|
||||||
zone: us-central1-a
|
zone: "{{ gcp_zone }}"
|
||||||
project: "{{ gcp_project }}"
|
project: "{{ gcp_project }}"
|
||||||
auth_kind: "{{ gcp_cred_kind }}"
|
auth_kind: "{{ gcp_cred_kind }}"
|
||||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
- name: Generated tests
|
- name: Generated tests
|
||||||
ansible.builtin.include_tasks: autogen.yml
|
ansible.builtin.include_tasks: autogen.yml
|
||||||
|
|
||||||
- name: Test nic_type scenarios
|
- name: Extra non-autogen tests
|
||||||
block:
|
block:
|
||||||
- name: Create network
|
- name: Create network
|
||||||
google.cloud.gcp_compute_network:
|
google.cloud.gcp_compute_network:
|
||||||
|
@ -14,15 +14,23 @@
|
||||||
state: present
|
state: present
|
||||||
register: _network
|
register: _network
|
||||||
|
|
||||||
- name: Loop over testcase
|
- name: Test GVNIC test cases
|
||||||
ansible.builtin.include_tasks: gvnic.yml
|
ansible.builtin.include_tasks: gvnic.yml
|
||||||
loop: "{{ testcases | dict2items }}"
|
loop: "{{ testcases | dict2items }}"
|
||||||
vars:
|
vars:
|
||||||
|
gcp_disk_image: projects/centos-cloud/global/images/family/centos-stream-9
|
||||||
|
gcp_zone: us-central1-a
|
||||||
testcases:
|
testcases:
|
||||||
gvnic: GVNIC
|
gvnic: GVNIC
|
||||||
virtio: VIRTIO_NET
|
virtio: VIRTIO_NET
|
||||||
default: default
|
default: default
|
||||||
|
|
||||||
|
- name: Test attach disks
|
||||||
|
ansible.builtin.include_tasks: attach-disks.yml
|
||||||
|
vars:
|
||||||
|
gcp_disk_image: projects/centos-cloud/global/images/family/centos-stream-9
|
||||||
|
gcp_zone: us-central1-a
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Delete network
|
- name: Delete network
|
||||||
google.cloud.gcp_compute_network:
|
google.cloud.gcp_compute_network:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue