Skip to content

Commit b544669

Browse files
author
Girish Shilamkar
committed
CLOUDSTACK-5497: Fix test_guest_vlan_range.py to get free vlan range
1 parent 914bc46 commit b544669

3 files changed

Lines changed: 96 additions & 106 deletions

File tree

test/integration/component/test_non_contiguous_vlan.py

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
from marvin.integration.lib.common import (get_zone,
3737
get_pod,
3838
get_domain,
39-
get_template)
39+
get_template,
40+
setNonContiguousVlanIds)
4041
from marvin.integration.lib.utils import (cleanup_resources,
4142
xsplit)
4243

@@ -125,8 +126,14 @@ def setUp(self):
125126
self.vlan = self.services["vlan"]
126127
self.apiClient = self.testClient.getApiClient()
127128

128-
self.setNonContiguousVlanIds(self.apiclient, self.zone.id)
129+
self.physicalnetwork, self.vlan = setNonContiguousVlanIds(self.apiclient, self.zone.id)
129130

131+
self.physicalnetworkid = self.physicalnetwork.id
132+
self.existingvlan = self.physicalnetwork.vlan
133+
134+
if self.vlan == None:
135+
self.fail("Failed to set non contiguous vlan ids to test. Free some ids from \
136+
from existing physical networks at extreme ends")
130137
self.cleanup = []
131138

132139
def tearDown(self):
@@ -141,78 +148,6 @@ def tearDown(self):
141148
except Exception as e:
142149
raise Exception("Warning: Exception during cleanup : %s" % e)
143150

144-
def setNonContiguousVlanIds(self, apiclient, zoneid):
145-
"""
146-
Form the non contiguous ranges based on currently assigned range in physical network
147-
"""
148-
149-
NonContigVlanIdsAcquired = False
150-
151-
list_physical_networks_response = PhysicalNetwork.list(
152-
apiclient,
153-
zoneid=zoneid
154-
)
155-
assert isinstance(list_physical_networks_response, list)
156-
assert len(list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid
157-
158-
for physical_network in list_physical_networks_response:
159-
160-
self.physicalnetwork = physical_network
161-
self.physicalnetworkid = physical_network.id
162-
self.existingvlan = physical_network.vlan
163-
164-
vlans = xsplit(self.existingvlan, ['-', ','])
165-
166-
assert len(vlans) > 0
167-
assert int(vlans[0]) < int(vlans[-1]), "VLAN range %s was improperly split" % self.existingvlan
168-
169-
# Keep some gap between existing vlan and the new vlans which we are going to add
170-
# So that they are non contiguous
171-
172-
non_contig_end_vlan_id = int(vlans[-1]) + 6
173-
non_contig_start_vlan_id = int(vlans[0]) - 6
174-
175-
# Form ranges which are consecutive to existing ranges but not immediately contiguous
176-
# There should be gap in between existing range and new non contiguous ranage
177-
178-
# If you can't add range after existing range, because it's crossing 4095, then
179-
# select VLAN ids before the existing range such that they are greater than 0, and
180-
# then add this non contiguoud range
181-
182-
if non_contig_end_vlan_id < 4095:
183-
184-
self.vlan["partial_range"][0] = str(non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id - 3)
185-
self.vlan["partial_range"][1] = str(non_contig_end_vlan_id - 1) + '-' + str(non_contig_end_vlan_id)
186-
self.vlan["full_range"] = str(non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id)
187-
NonContigVlanIdsAcquired = True
188-
189-
elif non_contig_start_vlan_id > 0:
190-
191-
self.vlan["partial_range"][0] = str(non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 1)
192-
self.vlan["partial_range"][1] = str(non_contig_start_vlan_id + 3) + '-' + str(non_contig_start_vlan_id + 4)
193-
self.vlan["full_range"] = str(non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 4)
194-
NonContigVlanIdsAcquired = True
195-
196-
else:
197-
NonContigVlanIdsAcquired = False
198-
199-
# If failed to get relevant vlan ids, continue to next physical network
200-
# else break from loop as we have hot the non contiguous vlan ids for the test purpose
201-
202-
if not NonContigVlanIdsAcquired:
203-
continue
204-
else:
205-
break
206-
207-
# If even through looping from all existing physical networks, failed to get relevant non
208-
# contiguous vlan ids, then fail the test case
209-
210-
if not NonContigVlanIdsAcquired:
211-
self.fail("Failed to set non contiguous vlan ids to test. Free some ids from \
212-
from existing physical networks at extreme ends")
213-
214-
return
215-
216151
def validatePhysicalNetworkVlan(self, physicalNetworkId, vlan):
217152
"""Validate whether the physical network has the updated vlan
218153

test/integration/smoke/test_guest_vlan_range.py

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,34 @@ class TestDedicateGuestVlanRange(cloudstackTestCase):
5353

5454
@classmethod
5555
def setUpClass(cls):
56-
cls.api_client = super(TestDedicateGuestVlanRange, cls).getClsTestClient().getApiClient()
56+
cls.apiclient = super(TestDedicateGuestVlanRange, cls).getClsTestClient().getApiClient()
5757
cls.services = Services().services
5858
# Get Zone, Domain
59-
cls.domain = get_domain(cls.api_client, cls.services)
60-
cls.zone = get_zone(cls.api_client, cls.services)
59+
cls.domain = get_domain(cls.apiclient, cls.services)
60+
cls.zone = get_zone(cls.apiclient, cls.services)
6161

6262
# Create Account
6363
cls.account = Account.create(
64-
cls.api_client,
64+
cls.apiclient,
6565
cls.services["account"],
6666
domainid=cls.domain.id
6767
)
6868
cls._cleanup = [
6969
cls.account,
7070
]
7171

72-
phy_networks = PhysicalNetwork.list(
73-
cls.api_client
74-
)
75-
cls.existed_vlan = phy_networks[0].vlan
72+
cls.physical_network, cls.free_vlan = setNonContiguousVlanIds(cls.apiclient, cls.zone.id)
7673
return
7774

7875
@classmethod
7976
def tearDownClass(cls):
8077
try:
8178
# Cleanup resources used
82-
list_physical_network_response = PhysicalNetwork.list(cls.api_client)
83-
if list_physical_network_response is not None and len(list_physical_network_response) > 0:
84-
physical_network = list_physical_network_response[0]
85-
removeGuestVlanRangeResponse = \
86-
physical_network.update(cls.api_client,
87-
id=physical_network.id,
88-
vlan=cls.existed_vlan)
89-
cleanup_resources(cls.api_client, cls._cleanup)
79+
removeGuestVlanRangeResponse = \
80+
cls.physical_network.update(cls.apiclient,
81+
id=cls.physical_network.id,
82+
vlan=cls.physical_network.vlan)
83+
cleanup_resources(cls.apiclient, cls._cleanup)
9084
except Exception as e:
9185
raise Exception("Warning: Exception during cleanup : %s" % e)
9286
return
@@ -121,28 +115,23 @@ def test_dedicateGuestVlanRange(self):
121115
# 6. Verify guest vlan range has been released, verify with listDedicatedGuestVlanRanges
122116
# 7. Remove the added guest vlan range using UpdatePhysicalNetwork
123117

124-
self.debug("Listing available physical network")
125-
list_physical_network_response = PhysicalNetwork.list(
126-
self.apiclient
127-
)
128-
self.assertEqual(
129-
isinstance(list_physical_network_response, list),
130-
True,
131-
"Check for list guest vlan range response"
132-
)
133-
physical_network_response = list_physical_network_response[0]
134-
135118
self.debug("Adding guest vlan range")
136119

137-
new_vlan = self.existed_vlan + "," + self.services["vlan"]
138-
addGuestVlanRangeResponse = physical_network_response.update(self.apiclient,
139-
id=physical_network_response.id, vlan=new_vlan)
120+
121+
print "existing vlna = %s" %self.physical_network.vlan
122+
print "free vlan = %s" %self.free_vlan
123+
new_vlan = self.physical_network.vlan + "," + self.free_vlan["partial_range"][0]
124+
print "new vlan = %s" % new_vlan
125+
#new_vlan = self.free_vlan["partial_range"][0]
126+
addGuestVlanRangeResponse = self.physical_network.update(self.apiclient,
127+
id=self.physical_network.id, vlan=new_vlan)
128+
#id=self.physical_network.id, vlan=self.free_vlan["partial_range"][0])
140129

141130
self.debug("Dedicating guest vlan range");
142131
dedicate_guest_vlan_range_response = PhysicalNetwork.dedicate(
143132
self.apiclient,
144-
self.services["vlan"],
145-
physicalnetworkid=physical_network_response.id,
133+
self.free_vlan["partial_range"][0],
134+
physicalnetworkid=self.physical_network.id,
146135
account=self.account.name,
147136
domainid=self.account.domainid
148137
)

tools/marvin/marvin/integration/lib/common.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,69 @@ def get_free_vlan(apiclient, zoneid):
830830
break
831831

832832
return physical_network, shared_ntwk_vlan
833+
834+
def setNonContiguousVlanIds(apiclient, zoneid):
835+
"""
836+
Form the non contiguous ranges based on currently assigned range in physical network
837+
"""
838+
839+
NonContigVlanIdsAcquired = False
840+
841+
list_physical_networks_response = PhysicalNetwork.list(
842+
apiclient,
843+
zoneid=zoneid
844+
)
845+
assert isinstance(list_physical_networks_response, list)
846+
assert len(list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid
847+
848+
for physical_network in list_physical_networks_response:
849+
850+
vlans = xsplit(physical_network.vlan, ['-', ','])
851+
852+
assert len(vlans) > 0
853+
assert int(vlans[0]) < int(vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan
854+
855+
# Keep some gap between existing vlan and the new vlans which we are going to add
856+
# So that they are non contiguous
857+
858+
non_contig_end_vlan_id = int(vlans[-1]) + 6
859+
non_contig_start_vlan_id = int(vlans[0]) - 6
860+
861+
# Form ranges which are consecutive to existing ranges but not immediately contiguous
862+
# There should be gap in between existing range and new non contiguous ranage
863+
864+
# If you can't add range after existing range, because it's crossing 4095, then
865+
# select VLAN ids before the existing range such that they are greater than 0, and
866+
# then add this non contiguoud range
867+
vlan = { "partial_range": ["",""], "full_range": ""}
868+
869+
if non_contig_end_vlan_id < 4095:
870+
vlan["partial_range"][0] = str(non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id - 3)
871+
vlan["partial_range"][1] = str(non_contig_end_vlan_id - 1) + '-' + str(non_contig_end_vlan_id)
872+
vlan["full_range"] = str(non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id)
873+
NonContigVlanIdsAcquired = True
874+
875+
elif non_contig_start_vlan_id > 0:
876+
vlan["partial_range"][0] = str(non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 1)
877+
vlan["partial_range"][1] = str(non_contig_start_vlan_id + 3) + '-' + str(non_contig_start_vlan_id + 4)
878+
vlan["full_range"] = str(non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 4)
879+
NonContigVlanIdsAcquired = True
880+
881+
else:
882+
NonContigVlanIdsAcquired = False
883+
884+
# If failed to get relevant vlan ids, continue to next physical network
885+
# else break from loop as we have hot the non contiguous vlan ids for the test purpose
886+
887+
if not NonContigVlanIdsAcquired:
888+
continue
889+
else:
890+
break
891+
892+
# If even through looping from all existing physical networks, failed to get relevant non
893+
# contiguous vlan ids, then fail the test case
894+
895+
if not NonContigVlanIdsAcquired:
896+
return None, None
897+
898+
return physical_network, vlan

0 commit comments

Comments
 (0)