mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* Fix #26755 by ensuring that the first nic in the nic list has primary set to True, and all other nics have primary set to False. * Fix sanity issues and add test for two nics * Fix typo in test * fix nic list * Ensure the niclist variable is used rather than a niclist string * Add tests just for dual nic, reverting changes to single nic VM creation tests * Correct idempotency test
This commit is contained in:
parent
32d786af65
commit
08f071eb7a
2 changed files with 92 additions and 10 deletions
|
@ -819,7 +819,8 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
if set(current_nics) != set(network_interfaces):
|
if set(current_nics) != set(network_interfaces):
|
||||||
self.log('CHANGED: virtual machine {0} - network interfaces are different.'.format(self.name))
|
self.log('CHANGED: virtual machine {0} - network interfaces are different.'.format(self.name))
|
||||||
differences.append('Network Interfaces')
|
differences.append('Network Interfaces')
|
||||||
updated_nics = [dict(id=id) for id in network_interfaces]
|
updated_nics = [dict(id=id, primary=(i is 0))
|
||||||
|
for i, id in enumerate(network_interfaces)]
|
||||||
vm_dict['properties']['networkProfile']['networkInterfaces'] = updated_nics
|
vm_dict['properties']['networkProfile']['networkInterfaces'] = updated_nics
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
@ -928,7 +929,8 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
if not self.short_hostname:
|
if not self.short_hostname:
|
||||||
self.short_hostname = self.name
|
self.short_hostname = self.name
|
||||||
|
|
||||||
nics = [self.compute_models.NetworkInterfaceReference(id=id) for id in network_interfaces]
|
nics = [self.compute_models.NetworkInterfaceReference(id=id, primary=(i is 0))
|
||||||
|
for i, id in enumerate(network_interfaces)]
|
||||||
|
|
||||||
# os disk
|
# os disk
|
||||||
if self.managed_disk_type:
|
if self.managed_disk_type:
|
||||||
|
@ -1057,9 +1059,8 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
|
|
||||||
self.log("Update virtual machine {0}".format(self.name))
|
self.log("Update virtual machine {0}".format(self.name))
|
||||||
self.results['actions'].append('Updated VM {0}'.format(self.name))
|
self.results['actions'].append('Updated VM {0}'.format(self.name))
|
||||||
|
nics = [self.compute_models.NetworkInterfaceReference(id=interface['id'], primary=(i is 0))
|
||||||
nics = [self.compute_models.NetworkInterfaceReference(id=interface['id'])
|
for i, interface in enumerate(vm_dict['properties']['networkProfile']['networkInterfaces'])]
|
||||||
for interface in vm_dict['properties']['networkProfile']['networkInterfaces']]
|
|
||||||
|
|
||||||
# os disk
|
# os disk
|
||||||
if not vm_dict['properties']['storageProfile']['osDisk'].get('managedDisk'):
|
if not vm_dict['properties']['storageProfile']['osDisk'].get('managedDisk'):
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
- name: Delete virtual machine
|
- name: Delete virtual machines
|
||||||
azure_rm_virtualmachine:
|
azure_rm_virtualmachine:
|
||||||
resource_group: "{{ resource_group }}"
|
resource_group: "{{ resource_group }}"
|
||||||
name: testvm002
|
name: "{{ vms }}"
|
||||||
state: absent
|
state: absent
|
||||||
vm_size: Standard_A0
|
vm_size: Standard_A0
|
||||||
|
loop:
|
||||||
|
- testvm002
|
||||||
|
- testvm003
|
||||||
|
loop_control:
|
||||||
|
loop_var: vms
|
||||||
register: output
|
register: output
|
||||||
|
|
||||||
- name: Create storage account name
|
- name: Create storage account name
|
||||||
|
@ -59,7 +64,7 @@
|
||||||
priority: 110
|
priority: 110
|
||||||
direction: Inbound
|
direction: Inbound
|
||||||
|
|
||||||
- name: Create NIC
|
- name: Create NIC for single nic VM
|
||||||
azure_rm_networkinterface:
|
azure_rm_networkinterface:
|
||||||
resource_group: "{{ resource_group }}"
|
resource_group: "{{ resource_group }}"
|
||||||
name: testvm001
|
name: testvm001
|
||||||
|
@ -68,7 +73,7 @@
|
||||||
public_ip_name: testvm001
|
public_ip_name: testvm001
|
||||||
security_group: testvm001
|
security_group: testvm001
|
||||||
|
|
||||||
- name: Create virtual machine
|
- name: Create virtual machine with a single NIC
|
||||||
register: output
|
register: output
|
||||||
azure_rm_virtualmachine:
|
azure_rm_virtualmachine:
|
||||||
resource_group: "{{ resource_group }}"
|
resource_group: "{{ resource_group }}"
|
||||||
|
@ -173,7 +178,7 @@
|
||||||
- "azure_vm.powerstate in ['starting', 'running']"
|
- "azure_vm.powerstate in ['starting', 'running']"
|
||||||
- output.changed
|
- output.changed
|
||||||
|
|
||||||
- name: Should be idempotent
|
- name: Should be idempotent with a single NIC
|
||||||
azure_rm_virtualmachine:
|
azure_rm_virtualmachine:
|
||||||
resource_group: "{{ resource_group }}"
|
resource_group: "{{ resource_group }}"
|
||||||
name: testvm002
|
name: testvm002
|
||||||
|
@ -251,6 +256,82 @@
|
||||||
state: absent
|
state: absent
|
||||||
vm_size: Standard_A0
|
vm_size: Standard_A0
|
||||||
|
|
||||||
|
- name: Create NICs for dual nic VM
|
||||||
|
azure_rm_networkinterface:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: "{{ item }}"
|
||||||
|
virtual_network: testvm001
|
||||||
|
subnet: testvm001
|
||||||
|
security_group: testvm001
|
||||||
|
loop:
|
||||||
|
- testvm011
|
||||||
|
- testvm012
|
||||||
|
|
||||||
|
- name: Create virtual machine with two NICs
|
||||||
|
register: output
|
||||||
|
vars:
|
||||||
|
niclist:
|
||||||
|
- testvm011
|
||||||
|
- testvm012
|
||||||
|
azure_rm_virtualmachine:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: testvm003
|
||||||
|
vm_size: Standard_A0
|
||||||
|
storage_account: "{{ storage_account }}"
|
||||||
|
storage_container: testvm001
|
||||||
|
storage_blob: testvm003.vhd
|
||||||
|
admin_username: adminuser
|
||||||
|
admin_password: Password123!
|
||||||
|
short_hostname: testvm
|
||||||
|
os_type: Linux
|
||||||
|
network_interfaces: "{{ niclist }}"
|
||||||
|
availability_set: "avbs{{ resource_group | hash('md5') | truncate(7, True, '') }}"
|
||||||
|
image:
|
||||||
|
offer: UbuntuServer
|
||||||
|
publisher: Canonical
|
||||||
|
sku: 16.04-LTS
|
||||||
|
version: latest
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- azure_vm.properties.availabilitySet.id
|
||||||
|
|
||||||
|
- name: Should be idempotent with a dual NICs
|
||||||
|
vars:
|
||||||
|
niclist:
|
||||||
|
- testvm011
|
||||||
|
- testvm012
|
||||||
|
azure_rm_virtualmachine:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: testvm003
|
||||||
|
vm_size: Standard_A0
|
||||||
|
storage_account: "{{ storage_account }}"
|
||||||
|
storage_container: testvm001
|
||||||
|
storage_blob: testvm003.vhd
|
||||||
|
admin_username: adminuser
|
||||||
|
admin_password: Password123!
|
||||||
|
short_hostname: testvm
|
||||||
|
os_type: Linux
|
||||||
|
network_interfaces: "{{ niclist }}"
|
||||||
|
availability_set: "avbs{{ resource_group | hash('md5') | truncate(7, True, '') }}"
|
||||||
|
image:
|
||||||
|
offer: UbuntuServer
|
||||||
|
publisher: Canonical
|
||||||
|
sku: 16.04-LTS
|
||||||
|
version: latest
|
||||||
|
register: output
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that: not output.changed
|
||||||
|
|
||||||
|
- name: Delete dual NIC VM
|
||||||
|
azure_rm_virtualmachine:
|
||||||
|
resource_group: "{{ resource_group }}"
|
||||||
|
name: testvm003
|
||||||
|
state: absent
|
||||||
|
vm_size: Standard_A0
|
||||||
|
register: output
|
||||||
|
|
||||||
# TODO: Until we have a module to create/delete images this is the best tests
|
# TODO: Until we have a module to create/delete images this is the best tests
|
||||||
# I can do
|
# I can do
|
||||||
- name: assert error thrown with invalid image dict
|
- name: assert error thrown with invalid image dict
|
||||||
|
|
Loading…
Reference in a new issue