Skip to content

Commit 28b289d

Browse files
sanjeevneelarapusanju1010
authored andcommitted
New test to validate starting vm after nic removal and attach Bug-Id: CLOUDSTACK-9219
Incorporated review comments from GabrielBrascher
1 parent 419f8fb commit 28b289d

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

test/integration/component/test_add_remove_network.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,103 @@ def test_29_remove_nic_CS22503(self):
10211021
self.fail("Failed to delete the nic from vm")
10221022
return
10231023

1024+
@attr(tags=["advanced"], required_hardware="true")
1025+
def test_30_remove_nic_reattach(self):
1026+
"""
1027+
Test to verify vm start after NIC removal and reattach
1028+
1029+
# 1.Create vm which has 3 nics(e.g. #0,#1,#2)
1030+
# 2.Stop the vm
1031+
# 3.Remove second nic(#1)
1032+
# 4.Add/Reattach same network(#1)
1033+
# 5.Start the instance
1034+
"""
1035+
self.ntwk2 = Network.create(
1036+
self.apiclient,
1037+
self.services["isolated_network"],
1038+
self.account.name,
1039+
self.account.domainid,
1040+
networkofferingid=self.isolated_network_offering.id
1041+
)
1042+
self.ntwk3 = Network.create(
1043+
self.apiclient,
1044+
self.services["isolated_network"],
1045+
self.account.name,
1046+
self.account.domainid,
1047+
networkofferingid=self.isolated_network_offering.id
1048+
)
1049+
self.test_vm = VirtualMachine.create(
1050+
self.apiclient,
1051+
self.services["virtual_machine"],
1052+
accountid=self.account.name,
1053+
domainid=self.account.domainid,
1054+
serviceofferingid=self.service_offering.id,
1055+
mode=self.zone.networktype,
1056+
networkids=[self.isolated_network.id, self.ntwk2.id, self.ntwk3.id]
1057+
)
1058+
self.assertIsNotNone(self.test_vm, "Failed to create vm with 3 nics")
1059+
map(lambda x: self.cleanup.append(x), [self.test_vm, self.ntwk2, self.ntwk3])
1060+
vm_res = VirtualMachine.list(
1061+
self.apiclient,
1062+
id=self.test_vm.id
1063+
)
1064+
self.assertEqual(validateList(vm_res)[0], PASS, "Invalid list vm response")
1065+
self.nics = vm_res[0].nic
1066+
self.assertEqual(
1067+
validateList(self.nics)[0],
1068+
PASS,
1069+
"vm response does not contain nics info"
1070+
)
1071+
self.assertEqual(len(self.nics), 3, "Not all nics found in vm response")
1072+
self.test_vm.stop(self.apiclient)
1073+
vm_res2 = VirtualMachine.list(
1074+
self.apiclient,
1075+
id=self.test_vm.id
1076+
)
1077+
self.assertEqual(validateList(vm_res2)[0], PASS, "Invalid response")
1078+
self.assertEqual(
1079+
vm_res2[0].state,
1080+
"Stopped",
1081+
"VM did not stop properly"
1082+
)
1083+
1084+
"""
1085+
get the network id of the nic which we are remove from the nic, so that we can
1086+
use that network id for reattach
1087+
"""
1088+
nic_to_attach = [x for x in [self.isolated_network, self.ntwk2, self.ntwk3]\
1089+
if x.id == self.nics[1].networkid]
1090+
self.assertEqual(validateList(nic_to_attach)[0], PASS, "No matching nics")
1091+
self.assertEqual(len(nic_to_attach), 1, "More than one nic in same network")
1092+
try:
1093+
self.test_vm.remove_nic(self.apiclient, nicId=self.nics[1].id)
1094+
self.test_vm.add_nic(
1095+
self.apiclient,
1096+
nic_to_attach[0].id
1097+
)
1098+
self.test_vm.start(self.apiclient)
1099+
except Exception as e:
1100+
self.fail("Failed to start vm after nic removal and attachment")
1101+
vm_res3 = VirtualMachine.list(self.apiclient, id=self.test_vm.id)
1102+
self.assertEqual(
1103+
validateList(vm_res3)[0],
1104+
PASS,
1105+
"Invalid listvm response after nic detach and attach"
1106+
)
1107+
self.assertEqual(
1108+
vm_res3[0].state,
1109+
"Running",
1110+
"VM didn't come to running state after nic detach and attach"
1111+
)
1112+
vm_nics = vm_res3[0].nic
1113+
self.assertEqual(validateList(vm_nics)[0], PASS, "Invalid nics after vm stop/start")
1114+
self.assertEqual(
1115+
len(vm_nics),
1116+
3,
1117+
"Nic is not attached/detected"
1118+
)
1119+
return
1120+
10241121
class TestUpdateVirtualMachineNIC(cloudstackTestCase):
10251122

10261123
@classmethod

0 commit comments

Comments
 (0)