Skip to content

Commit 2cd4ad2

Browse files
Gaurav AradhyeSrikanteswaraRao Talluri
authored andcommitted
CLOUDSTACK-7800: Correcting code related to unplug NIC on VMware
Signed-off-by: SrikanteswaraRao Talluri <[email protected]>
1 parent c3e5964 commit 2cd4ad2

1 file changed

Lines changed: 30 additions & 60 deletions

File tree

test/integration/smoke/test_nic.py

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from marvin.lib.common import (get_zone,
2525
get_template,
2626
get_domain)
27+
from marvin.lib.utils import validateList
28+
from marvin.codes import PASS
2729
from nose.plugins.attrib import attr
2830

2931
import signal
@@ -149,7 +151,6 @@ def test_01_nic(self):
149151

150152
hypervisorIsVmware = False
151153
isVmwareToolInstalled = False
152-
assertForExceptionForNicOperations = False
153154
if self.hypervisor.lower() == "vmware":
154155
hypervisorIsVmware = True
155156

@@ -163,59 +164,18 @@ def test_01_nic(self):
163164
mode=self.zone.networktype if hypervisorIsVmware else "default"
164165
)
165166

166-
# If hypervisor is Vmware, then check if
167-
# the vmware tools are installed and the process is running
168-
# Vmware tools are necessary for add and remove nic operations
169-
if hypervisorIsVmware:
170-
sshClient = self.virtual_machine.get_ssh_client()
171-
result = str(
172-
sshClient.execute("service vmware-tools status")).lower()
173-
self.debug("and result is: %s" % result)
174-
if "running" in result:
175-
isVmwareToolInstalled = True
176-
177-
# If Vmware tools are not installed in case of vmware hypervisor
178-
# then check for exception while performing add and remove nic
179-
# operations
180-
if hypervisorIsVmware and not isVmwareToolInstalled:
181-
assertForExceptionForNicOperations = True
182-
183167
self.cleanup.insert(0, self.virtual_machine)
184-
list_vm_response = VirtualMachine.list(
168+
vms = VirtualMachine.list(
185169
self.apiclient,
186170
id=self.virtual_machine.id
187171
)
188172

189-
self.debug(
190-
"Verify listVirtualMachines response for virtual machine: %s"
191-
% self.virtual_machine.id
192-
)
193-
194-
self.assertEqual(
195-
isinstance(list_vm_response, list),
196-
True,
197-
"Check list response returns a valid list"
198-
)
199-
200-
self.assertNotEqual(
201-
len(list_vm_response),
202-
0,
203-
"Check VM available in List Virtual Machines"
204-
)
205-
vm_response = list_vm_response[0]
206-
207173
self.assertEqual(
174+
validateList(vms)[0],
175+
PASS,
176+
"vms list validation failed")
208177

209-
vm_response.id,
210-
self.virtual_machine.id,
211-
"Check virtual machine id in listVirtualMachines"
212-
)
213-
214-
self.assertEqual(
215-
vm_response.name,
216-
self.virtual_machine.name,
217-
"Check virtual machine name in listVirtualMachines"
218-
)
178+
vm_response = vms[0]
219179

220180
self.assertEqual(
221181
len(vm_response.nic),
@@ -231,30 +191,40 @@ def test_01_nic(self):
231191
existing_nic_ip = vm_response.nic[0].ipaddress
232192
existing_nic_id = vm_response.nic[0].id
233193

234-
if assertForExceptionForNicOperations:
235-
with self.assertRaises(Exception):
236-
self.virtual_machine.add_nic(
194+
self.virtual_machine.add_nic(
237195
self.apiclient,
238196
self.test_network2.id)
239-
240-
else:
241-
# 1. add a nic
242-
self.virtual_machine.add_nic(self.apiclient, self.test_network2.id)
243-
244-
time.sleep(5)
245-
# now go get the vm list?
246-
247-
list_vm_response = VirtualMachine.list(
197+
list_vm_response = VirtualMachine.list(
248198
self.apiclient,
249199
id=self.virtual_machine.id
250200
)
251201

252-
self.assertEqual(
202+
self.assertEqual(
253203
len(list_vm_response[0].nic),
254204
2,
255205
"Verify we have 2 NIC's now"
256206
)
257207

208+
# If hypervisor is Vmware, then check if
209+
# the vmware tools are installed and the process is running
210+
# Vmware tools are necessary for remove nic operations (vmware 5.5+)
211+
if hypervisorIsVmware:
212+
sshClient = self.virtual_machine.get_ssh_client()
213+
result = str(
214+
sshClient.execute("service vmware-tools status")).lower()
215+
self.debug("and result is: %s" % result)
216+
if "running" in result:
217+
isVmwareToolInstalled = True
218+
219+
goForUnplugOperation = True
220+
# If Vmware tools are not installed in case of vmware hypervisor
221+
# then don't go further for unplug operation (remove nic) as it won't
222+
# be supported
223+
if hypervisorIsVmware and not isVmwareToolInstalled:
224+
goForUnplugOperation = False
225+
226+
227+
if goForUnplugOperation:
258228
new_nic_id = ""
259229
for nc in list_vm_response[0].nic:
260230
if nc.ipaddress != existing_nic_ip:

0 commit comments

Comments
 (0)