def test_05_stop_start_vm_with_multiple_nic(self): """ Stop and Start a VM with Multple NIC Steps: # 1) Create a Vm with multiple NIC's # 2) Configure secondary IP's on the VM # 3) Try to stop/start the VM # 4) Ping the IP's of the vm # 5) Remove Secondary IP from one of the NIC :return: """ ipaddress1 = NIC.addIp(self.apiclient, id=self.virtual_machine2.nic[0].id) ipaddress2 = NIC.addIp(self.apiclient, id=self.virtual_machine2.nic[1].id) # Stop the VM with multiple NIC's self.virtual_machine2.stop(self.apiclient) virtual_machine = VirtualMachine.list(self.apiclient, id=self.virtual_machine2.id) self.assertEqual(virtual_machine[0]['state'], 'Stopped', "Could not stop the VM with multiple NIC's") if virtual_machine[0]['state'] == 'Stopped': # If stopped then try to start the VM self.virtual_machine2.start(self.apiclient) virtual_machine = VirtualMachine.list(self.apiclient, id=self.virtual_machine2.id) self.assertEqual(virtual_machine[0]['state'], 'Running', "Could not start the VM with multiple NIC's") self.verify_network_rules(self.virtual_machine2.id)
def test_07_remove_secondary_ip_from_nic(self): """ Remove secondary IP from any NIC Steps: # 1) Navigate to Instances # 2) Select any vm # 3) NIC's ->Edit secondary IP's->Release IP # 4) The secondary IP should be successfully removed """ virtual_machine = VirtualMachine.list( self.apiclient, id=self.virtual_machine2.id) # Check which NIC is having secondary IP secondary_ips = virtual_machine[0].nic[1].secondaryip for secondary_ip in secondary_ips: NIC.removeIp(self.apiclient, ipaddressid=secondary_ip['id']) virtual_machine = VirtualMachine.list( self.apiclient, id=self.virtual_machine2.id ) self.assertFalse( virtual_machine[0].nic[1].secondaryip, 'Failed to remove secondary IP') self.verify_network_rules(self.virtual_machine2.id)
def test_04_add_ip_to_remaining_nics(self): """ Add secondary IP's to remaining NIC's Steps: # 1) Create a VM with more than 1 NIC # 2)Navigate to Instances-NIC's->Edit Secondary IP's # ->Acquire new Secondary IP # 3) Add secondary IP to all the NIC's of the VM # 4) Confiugre the secondary IP's by referring to "Configure the # secondary IP's" in the "Action Item" section :return: """ self.virtual_machine1.add_nic(self.apiclient, self.network3.id) vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine1.id) self.assertIsNotNone(vms[0].nic[2], "Third NIC is not added successfully to the VM") vms1_nic1_id = vms[0].nic[1]['id'] vms1_nic2_id = vms[0].nic[2]['id'] ipaddress21 = NIC.addIp(self.apiclient, id=vms1_nic1_id) ipaddress22 = NIC.addIp(self.apiclient, id=vms1_nic1_id) self.assertIsNotNone( ipaddress21, "Unable to add first secondary IP to the second nic") self.assertIsNotNone( ipaddress22, "Unable to add second secondary IP to second NIC") ipaddress31 = NIC.addIp(self.apiclient, id=vms1_nic2_id) ipaddress32 = NIC.addIp(self.apiclient, id=vms1_nic2_id) self.assertIsNotNone(ipaddress31, "Unable to add first secondary IP to third NIC") self.assertIsNotNone(ipaddress32, "Unable to add second secondary IP to third NIC") self.verify_network_rules(self.virtual_machine1.id)
def test_validateState_succeeds_before_retry_limit(self): retries = 2 timeout = 3 api_client = MockApiClient(retries, 'initial state', 'final state') vm = VirtualMachine( { 'id': 'vm_id', 'nic': [NIC({'ipaddress': '192.168.0.100'})] }, {}) state = vm.validateState(api_client, 'final state', timeout=timeout, interval=1) self.assertEqual(state, [PASS, None]) self.assertEqual(retries, api_client.retry_counter)
def test_03_add_ip_to_default_nic(self): """ Add secondary IP's to the VM Steps: # 1. Create a VM with more than 1 NIC # 2) Navigate to Instances->NIC->Edit Secondary IP's # ->Aquire new Secondary IP" # 3) Add as many secondary Ip as possible to the VM # 4) Configure the secondary IP's by referring to "Configure # the secondary IP's" in the "Action Item" section :return: """ ipaddress = NIC.addIp(self.apiclient, id=self.virtual_machine2.nic[0].id) self.assertIsNotNone(ipaddress, "Unable to add secondary IP to the default NIC") self.verify_network_rules(self.virtual_machine2.id)
def test_validateState_fails_after_retry_limit(self): retries = 3 timeout = 2 api_client = MockApiClient(retries, 'initial state', 'final state') vm = VirtualMachine( { 'id': 'vm_id', 'nic': [NIC({'ipaddress': '192.168.0.100'})] }, {}) state = vm.validateState(api_client, 'final state', timeout=timeout, interval=1) self.assertEqual(state, [ FAIL, 'VirtualMachine state not trasited to final state, operation timed out' ]) self.assertEqual(retries, api_client.retry_counter)
def checkIpv6NetworkVm(self): self.debug("Listing NICS for VM %s in network: %s" % (self.virtual_machine.name, self.network.name)) nics = NIC.list( self.apiclient, virtualmachineid=self.virtual_machine.id, networkid=self.network.id ) self.assertEqual( len(nics), 1, "Router for the network isn't found" ) nic = nics[0] self.assertNotEqual(nic.ip6address, None, "IPv6 address for VM %s NIC is empty" % nic.traffictype) self.virtual_machine_ipv6_address = nic.ip6address self.assertNotEqual(nic.ip6cidr, None, "IPv6 CIDR for VM %s NIC is empty" % nic.traffictype) self.assertNotEqual(nic.ip6gateway, None, "IPv6 gateway for VM %s NIC is empty" % nic.traffictype)
def test_updating_nics_on_two_shared_networks(self): """ Test updating vm nics on two shared networks Works as follows: - Create two shared networks, with different IP ranges (eg network1, network2). - Create two VMs on each shared network (eg vm1 on network1, vm2 on network2) and stop them. - Add additional IP range to each shared network. The two additional IP ranges have same start IP and end IP, but different gateway and netmask (eg network1-iprange2, network2-iprange2). - Update IP address of the two vms, by specifying new IP address on additional IP ranges. The new gateway and netmask should be updated correctly (eg vm1 on network1-iprange2, vm2 on network2-iprange2). """ # - Create two shared networks, with different IP ranges (eg network1, network2). self.services["shared_network"]["netmask"] = "255.255.255.0" self.services["shared_network"]["gateway"] = "192.168.1.1" self.services["shared_network"]["startip"] = "192.168.1.2" self.services["shared_network"]["endip"] = "192.168.1.20" self.services["shared_network"]["vlan"] = "111" testnet = self.services["shared_network"] self.debug(f"========= network 1 : {testnet}") self.network1 = Network.create( self.apiclient, self.services["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) self._cleanup.append(self.network1) self.services["shared_network"]["netmask"] = "255.255.255.0" self.services["shared_network"]["gateway"] = "192.168.2.1" self.services["shared_network"]["startip"] = "192.168.2.2" self.services["shared_network"]["endip"] = "192.168.2.20" self.services["shared_network"]["vlan"] = "222" self.network2 = Network.create( self.apiclient, self.services["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) self._cleanup.append(self.network2) # - Create two VMs on each shared network (eg vm1 on network1, vm2 on network2) and stop them. vm_data = self.services["virtual_machine"] self.debug(f"============virtual machine data : {vm_data}") virtual_machine1 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, serviceofferingid=self.service_offering.id, networkids=[self.network1.id], zoneid=self.zone.id) self.cleanup.append(virtual_machine1) virtual_machine1.stop(self.apiclient) virtual_machine2 = VirtualMachine.create( self.apiclient, self.services["virtual_machine"], templateid=self.template.id, serviceofferingid=self.service_offering.id, networkids=[self.network2.id], zoneid=self.zone.id) self.cleanup.append(virtual_machine2) virtual_machine2.stop(self.apiclient) # - Add additional IP range to each shared network. The two additional IP ranges have same start IP and end IP, # but different gateway and netmask (eg network1-iprange2, network2-iprange2). self.services["vlan_ip_range"]["netmask"] = "255.255.255.224" self.services["vlan_ip_range"]["gateway"] = "192.168.3.1" self.services["vlan_ip_range"]["startip"] = "192.168.3.2" self.services["vlan_ip_range"]["endip"] = "192.168.3.20" self.services["vlan_ip_range"]["vlan"] = "111" range1 = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"], networkid=self.network1.id) self.debug(f"============range 1 : {range1}") self.services["vlan_ip_range"]["netmask"] = "255.255.255.192" self.services["vlan_ip_range"]["gateway"] = "192.168.3.21" self.services["vlan_ip_range"]["startip"] = "192.168.3.2" self.services["vlan_ip_range"]["endip"] = "192.168.3.20" self.services["vlan_ip_range"]["vlan"] = "222" range2 = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"], networkid=self.network2.id) # - Update IP address of the two vms, by specifying new IP address on additional IP ranges. The new gateway and # netmask should be updated correctly (eg vm1 on network1-iprange2, vm2 on network2-iprange2). nic1id = NIC.list(self.apiclient, virtualmachineid=virtual_machine1.id, networkid=self.network1.id)[0].id NIC.updateIp(self.apiclient, id=nic1id, ipaddress="192.168.3.2") nics = NIC.list(self.apiclient, virtualmachineid=virtual_machine1.id, networkid=self.network1.id) self.check_nic(nics, self.network1, range1) nic2id = NIC.list(self.apiclient, virtualmachineid=virtual_machine2.id, networkid=self.network2.id)[0].id NIC.updateIp(self.apiclient, id=nic2id, ipaddress="192.168.3.2") nics = NIC.list(self.apiclient, virtualmachineid=virtual_machine2.id, networkid=self.network2.id) self.check_nic(nics, self.network2, range2) return