Skip to content

Commit 5d03fa8

Browse files
Gaurav AradhyeGirish Shilamkar
authored andcommitted
CLOUDSTACK-5518: Fixing non contiguous vlan test case
1 parent cca60cd commit 5d03fa8

1 file changed

Lines changed: 32 additions & 86 deletions

File tree

test/integration/component/test_non_contiguous_vlan.py

Lines changed: 32 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,21 @@
2525
"""
2626

2727
#Import local modules
28-
from marvin.cloudstackTestCase import *
29-
from marvin.cloudstackAPI import *
30-
from marvin.cloudstackTestCase import cloudstackTestCase
31-
from marvin.integration.lib.base import Account
32-
from marvin.integration.lib.base import PhysicalNetwork
33-
from marvin.integration.lib.common import *
28+
29+
30+
from marvin.cloudstackTestCase import (cloudstackTestCase,unittest)
31+
from marvin.integration.lib.base import (Account,
32+
ServiceOffering,
33+
PhysicalNetwork,
34+
VirtualMachine,
35+
)
36+
from marvin.integration.lib.common import (get_zone,
37+
get_pod,
38+
get_domain,
39+
get_template)
40+
from marvin.integration.lib.utils import (cleanup_resources,
41+
xsplit)
42+
3443
from nose.plugins.attrib import attr
3544

3645
class Services():
@@ -330,12 +339,9 @@ def test_04_remove_unused_range(self):
330339
vlan1 = self.existingvlan+","+self.vlan["partial_range"][0]
331340
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = vlan1)
332341

333-
vlan2 = vlan1+","+self.vlan["partial_range"][1]
334-
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = vlan2)
342+
self.debug("Removing vlan : %s" % self.vlan["partial_range"][0])
335343

336-
self.debug("Removing vlan : %s" % self.vlan["partial_range"][1])
337-
338-
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = vlan1)
344+
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.existingvlan)
339345

340346
physicalnetworks = PhysicalNetwork.list(self.apiclient, id=self.physicalnetworkid)
341347

@@ -346,7 +352,7 @@ def test_04_remove_unused_range(self):
346352

347353
vlanranges= physicalnetworks[0].vlan
348354

349-
self.assert_(vlanranges.find(self.vlan["partial_range"][1]) == -1, "vlan range is not removed")
355+
self.assert_(vlanranges.find(self.vlan["partial_range"][0]) == -1, "vlan range is not removed")
350356

351357
return
352358

@@ -355,92 +361,32 @@ def test_05_remove_used_range(self):
355361
"""
356362
Test removing used vlan range
357363
"""
358-
# 1. If vlan id from existing range is in use, try to delete this range and add different range,
359-
# this operation should fail
360-
# 2. If any of existing vlan id is not in use, delete this range and add new vlan range
361-
# 3. Use a vlan id from this new range by deploying an instance which
364+
# 1. Use a vlan id from existing range by deploying an instance which
362365
# will create a network with vlan id from this range
363366
# 4. Now try to remove this vlan range
364367
# 5. Vlan range should not get removed, should throw error
365368

366-
vlans = xsplit(self.existingvlan, ['-', ','])
367-
vlanstartid = int(vlans[0])
368-
vlanendid = int(vlans[1])
369-
370-
networks = list_networks(self.apiclient)
371-
existingvlaninuse = False
372-
373-
374-
# Check if any of the vlan id from existing range is in use
375-
if isinstance(networks,list) and len(networks) > 0:
376-
377-
self.debug("networks: %s" % networks)
378-
379-
vlansinuse = [network for network in networks if network.vlan and (vlanstartid <= int(network.vlan) <= vlanendid)]
380-
381-
self.debug("Total no. of vlans in use : %s" % len(vlansinuse))
382-
383-
if len(vlansinuse) > 0:
384-
existingvlaninuse = True
385-
else:
386-
existingvlaninuse = False
387-
388-
vlan1 = self.vlan["partial_range"][0]
389-
390-
# If existing vlan id is in use, then try to delete this range, the operation should fail
391-
# This serves the test case purpose, hence test case has completed successfully
392-
if existingvlaninuse:
393-
self.debug("Trying to remove existing vlan in use, This should fail")
394-
with self.assertRaises(Exception) as e:
395-
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = vlan1)
396-
397-
self.debug("operation failed with exception: %s" % e.exception)
398-
399-
# If any of the existing vlan id is not in use, then add new range and deploy an instance which
400-
# will create a network using vlan id from this new range, hence now the new range is in use
401-
# Now try to delete this new range and add another range, operation should fail
402-
# This serves the test case purpose, hence test case has completed successfully
403-
else:
404-
405-
self.debug("No vlan in use, hence adding a new vlan and using it by deploying an instance")
406-
407-
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = vlan1)
408-
409-
self.debug("Verifying the VLAN of the updated physical network: %s, It should match with \
410-
the passed vlan: %s" % (self.physicalnetworkid,vlan1))
411-
412-
self.validatePhysicalNetworkVlan(self.physicalnetworkid, vlan1)
413-
414-
account = Account.create(
415-
self.apiclient,
416-
self.services["account"],
417-
domainid=self.domain.id
418-
)
419-
420-
self.debug("Deploying instance in the account: %s" %
421-
account.name)
422-
423-
self.virtual_machine = VirtualMachine.create(
424-
self.apiclient,
425-
self.services["virtual_machine"],
426-
accountid=account.name,
427-
domainid=account.domainid,
428-
serviceofferingid=self.service_offering.id,
429-
mode=self.zone.networktype
430-
)
431-
432-
self.debug("Deployed instance in account: %s" %
433-
account.name)
369+
account = Account.create(self.apiclient,self.services["account"],
370+
domainid=self.domain.id)
434371

372+
self.debug("Deploying instance in the account: %s" % account.name)
435373

374+
try:
436375

376+
self.virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
377+
accountid=account.name,domainid=account.domainid,
378+
serviceofferingid=self.service_offering.id,
379+
mode=self.zone.networktype)
380+
self.debug("Deployed instance in account: %s" % account.name)
437381
self.debug("Trying to remove vlan range : %s , This should fail" % self.vlan["partial_range"][0])
438382

439383
with self.assertRaises(Exception) as e:
440-
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.existingvlan)
384+
self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.vlan["partial_range"][0])
441385

442386
self.debug("operation failed with exception: %s" % e.exception)
443-
444387
account.delete(self.apiclient)
445388

389+
except Exception as e:
390+
self.fail("Exception in test case: %s" % e)
391+
446392
return

0 commit comments

Comments
 (0)