cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gir...@apache.org
Subject git commit: updated refs/heads/4.2 to 631743b
Date Thu, 21 Nov 2013 05:30:29 GMT
Updated Branches:
  refs/heads/4.2 b2b4b45ae -> 631743b44


CLOUDSTACK-5215: Correcting and refactoring code related to
 getting free vlan


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/631743b4
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/631743b4
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/631743b4

Branch: refs/heads/4.2
Commit: 631743b44a3cd5e69ff5c1ef6844950bb1074c5c
Parents: b2b4b45
Author: Gaurav Aradhye <gaurav.aradhye@clogeny.com>
Authored: Thu Nov 21 10:53:27 2013 +0530
Committer: Girish Shilamkar <girish@clogeny.com>
Committed: Thu Nov 21 11:00:15 2013 +0530

----------------------------------------------------------------------
 .../component/test_shared_networks.py           | 78 ++++++++++----------
 .../component/test_vpc_vm_life_cycle.py         | 32 +-------
 .../component/test_vpc_vms_deployment.py        | 39 ++--------
 tools/marvin/marvin/integration/lib/common.py   | 48 ++++++++++++
 4 files changed, 99 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/631743b4/test/integration/component/test_shared_networks.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_shared_networks.py b/test/integration/component/test_shared_networks.py
index 28468c9..9b76702 100644
--- a/test/integration/component/test_shared_networks.py
+++ b/test/integration/component/test_shared_networks.py
@@ -36,7 +36,8 @@ from marvin.integration.lib.utils import (cleanup_resources,
 from marvin.integration.lib.common import (get_domain,
                                            get_zone,
                                            get_template,
-                                           wait_for_cleanup)
+                                           wait_for_cleanup,
+                                           get_free_vlan)
 import random
 
 import netaddr
@@ -259,33 +260,6 @@ class TestSharedNetworks(cloudstackTestCase):
 
         return
 
-    def getFreeVlan(self, apiclient, zoneid):
-        """
-        Find an unallocated VLAN outside the range allocated to the physical network.
-
-        @note: This does not guarantee that the VLAN is available for use in
-        the deployment's network gear
-        @return: physical_network, shared_vlan_tag
-        """
-        list_physical_networks_response = PhysicalNetwork.list(
-            apiclient,
-            zoneid=zoneid
-        )
-        assert isinstance(list_physical_networks_response, list)
-        assert len(list_physical_networks_response) > 0, "No physical networks found in
zone %s" % zoneid
-
-        physical_network = list_physical_networks_response[0]
-        vlans = xsplit(physical_network.vlan, ['-', ','])
-
-        assert len(vlans) > 0
-        assert int(vlans[0]) < int(vlans[-1]), "VLAN range  %s was improperly split" %
physical_network.vlan
-        shared_ntwk_vlan = int(vlans[-1]) + random.randrange(1, 20)
-        if shared_ntwk_vlan > 4095:
-            shared_ntwk_vlan = int(vlans[0]) - random.randrange(1, 20)
-            assert shared_ntwk_vlan > 0, "VLAN chosen %s is invalid < 0" % shared_ntwk_vlan
-        self.debug("Attempting free VLAN %s for shared network creation" % shared_ntwk_vlan)
-        return physical_network, shared_ntwk_vlan
-
     @attr(tags=["advanced", "advancedns"])
     def test_sharedNetworkOffering_01(self):
         """  Test shared network Offering 01 """
@@ -703,7 +677,9 @@ class TestSharedNetworks(cloudstackTestCase):
 
         self.debug("User type account created: %s" % self.user_account.name)
 
-        physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         self.debug("Physical network found: %s" % physical_network.id)
 
@@ -972,7 +948,9 @@ class TestSharedNetworks(cloudstackTestCase):
 
         self.debug("User type account created: %s" % self.user_account.name)
 
-        physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         self.debug("Physical Network found: %s" % physical_network.id)
 
@@ -1281,7 +1259,9 @@ class TestSharedNetworks(cloudstackTestCase):
 
         self.debug("Domain user account created: %s" % self.domain_user_account.id)
 
-        physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         self.debug("Physical Network found: %s" % physical_network.id)
 
@@ -1588,7 +1568,9 @@ class TestSharedNetworks(cloudstackTestCase):
 
         self.debug("Project2 created: %s" % self.project2.id)
 
-        physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         self.debug("Physical Network found: %s" % physical_network.id)
 
@@ -1792,7 +1774,9 @@ class TestSharedNetworks(cloudstackTestCase):
 
         self.debug("Domain admin account created: %s" % self.admin_account.id)
 
-        physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         self.services["network_offering"]["specifyVlan"] = "True"
         self.services["network_offering"]["specifyIpRanges"] = "True"
@@ -1935,7 +1919,9 @@ class TestSharedNetworks(cloudstackTestCase):
 
         self.debug("Admin account created: %s" % self.admin_account.id)
 
-        physical_network, shared_ntwk_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         self.debug("Physical Network found: %s" % physical_network.id)
 
@@ -2104,7 +2090,9 @@ class TestSharedNetworks(cloudstackTestCase):
 
         self.debug("Admin account created: %s" % self.admin_account.id)
 
-        physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         self.debug("Physical Network found: %s" % physical_network.id)
 
@@ -2211,7 +2199,12 @@ class TestSharedNetworks(cloudstackTestCase):
         self.services["network1"]["acltype"] = "domain"
         self.services["network1"]["networkofferingid"] = self.shared_network_offering.id
         self.services["network1"]["physicalnetworkid"] = physical_network.id
-        self.services["network1"]["vlan"] = self.getFreeVlan(self.api_client, self.zone.id)[1]
#vlan id is second return value of function
+
+        shared_vlan = get_free_vlan(self.api_client, self.zone.id)[1]
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
+
+        self.services["network1"]["vlan"] = shared_vlan
 
         self.network1 = Network.create(
                          self.api_client,
@@ -2452,7 +2445,10 @@ class TestSharedNetworks(cloudstackTestCase):
             )
 
         self.debug("Isolated Network Offering created: %s" % self.isolated_network_offering.id)
-        physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         #create network using the shared network offering created
         self.services["network"]["acltype"] = "domain"
@@ -2678,7 +2674,9 @@ class TestSharedNetworks(cloudstackTestCase):
 
         self.debug("Admin type account created: %s" % self.admin_account.id)
 
-        physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         self.debug("Physical Network found: %s" % physical_network.id)
 
@@ -2807,7 +2805,9 @@ class TestSharedNetworks(cloudstackTestCase):
 
         self.debug("Admin type account created: %s" % self.admin_account.id)
 
-        physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id)
+        if shared_vlan is None:
+            self.fail("Failed to get free vlan id for shared network")
 
         self.debug("Physical Network found: %s" % physical_network.id)
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/631743b4/test/integration/component/test_vpc_vm_life_cycle.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_vpc_vm_life_cycle.py b/test/integration/component/test_vpc_vm_life_cycle.py
index beb5b99..5e2e7a7 100644
--- a/test/integration/component/test_vpc_vm_life_cycle.py
+++ b/test/integration/component/test_vpc_vm_life_cycle.py
@@ -863,33 +863,6 @@ class TestVMLifeCycleVPC(cloudstackTestCase):
 class TestVMLifeCycleSharedNwVPC(cloudstackTestCase):
 
     @classmethod
-    def getFreeVlan(cls, apiclient, zoneid):
-        """
-        Find an unallocated VLAN outside the range allocated to the physical network.
-
-        @note: This does not guarantee that the VLAN is available for use in
-        the deployment's network gear
-        @return: physical_network, shared_vlan_tag
-        """
-        list_physical_networks_response = PhysicalNetwork.list(
-            apiclient,
-            zoneid=zoneid
-        )
-        assert isinstance(list_physical_networks_response, list)
-        assert len(list_physical_networks_response) > 0, "No physical networks found in
zone %s" % zoneid
-
-        physical_network = list_physical_networks_response[0]
-        vlans = xsplit(physical_network.vlan, ['-', ','])
-
-        assert len(vlans) > 0
-        assert int(vlans[0]) < int(vlans[-1]), "VLAN range  %s was improperly split" %
physical_network.vlan
-        shared_ntwk_vlan = int(vlans[-1]) + random.randrange(1, 20)
-        if shared_ntwk_vlan > 4095:
-            shared_ntwk_vlan = int(vlans[0]) - random.randrange(1, 20)
-            assert shared_ntwk_vlan > 0, "VLAN chosen %s is invalid < 0" % shared_ntwk_vlan
-        return physical_network, shared_ntwk_vlan
-
-    @classmethod
     def setUpClass(cls):
         cls.api_client = super(
                                TestVMLifeCycleSharedNwVPC,
@@ -968,7 +941,10 @@ class TestVMLifeCycleSharedNwVPC(cloudstackTestCase):
         cls.shared_nw_off.update(cls.api_client, state='Enabled')
 
 
-        physical_network, shared_vlan = cls.getFreeVlan(cls.api_client, cls.zone.id)
+        physical_network, shared_vlan = get_free_vlan(cls.api_client, cls.zone.id)
+        if shared_vlan is None:
+            assert False, "Failed to get free vlan id for shared network creation in the
zone"
+
         #create network using the shared network offering created
         cls.services["network"]["acltype"] = "Domain"
         cls.services["network"]["physicalnetworkid"] = physical_network.id

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/631743b4/test/integration/component/test_vpc_vms_deployment.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_vpc_vms_deployment.py b/test/integration/component/test_vpc_vms_deployment.py
index c4811ed..baefa55 100644
--- a/test/integration/component/test_vpc_vms_deployment.py
+++ b/test/integration/component/test_vpc_vms_deployment.py
@@ -271,34 +271,6 @@ class TestVMDeployVPC(cloudstackTestCase):
         self.debug("VPC network validated - %s" % network.name)
         return
 
-    def getFreeVlan(self, apiclient, zoneid):
-        """
-        Find an unallocated VLAN outside the range allocated to the physical network.
-
-        @note: This does not guarantee that the VLAN is available for use in
-        the deployment's network gear
-        @return: physical_network, shared_vlan_tag
-        """
-        list_physical_networks_response = PhysicalNetwork.list(
-            apiclient,
-            zoneid=zoneid
-        )
-        assert isinstance(list_physical_networks_response, list)
-        assert len(list_physical_networks_response) > 0, "No physical networks found in
zone %s" % zoneid
-
-        physical_network = list_physical_networks_response[0]
-        vlans = xsplit(physical_network.vlan, ['-', ','])
-
-        assert len(vlans) > 0
-        assert int(vlans[0]) < int(vlans[-1]), "VLAN range  %s was improperly split" %
physical_network.vlan
-        shared_ntwk_vlan = int(vlans[-1]) + random.randrange(1, 20)
-        if shared_ntwk_vlan > 4095:
-            shared_ntwk_vlan = int(vlans[0]) - random.randrange(1, 20)
-            assert shared_ntwk_vlan > 0, "VLAN chosen %s is invalid < 0" % shared_ntwk_vlan
-        self.debug("Attempting free VLAN %s for shared network creation" % shared_ntwk_vlan)
-        return shared_ntwk_vlan
-
-
     @attr(tags=["advanced", "intervlan"])
     def test_01_deploy_vms_in_network(self):
         """ Test deploy VMs in VPC networks
@@ -2022,8 +1994,10 @@ class TestVMDeployVPC(cloudstackTestCase):
                                 services=self.services["http_rule"],
                                 traffictype='Egress'
                                 )
-        
-        vlan = self.getFreeVlan(self.api_client, self.zone.id)
+
+        vlan = get_free_vlan(self.apiclient, self.zone.id)[1]
+        if vlan is None:
+            self.fail("Failed to get free vlan id in the zone")
 
         self.debug("Creating private gateway in VPC: %s" % vpc.name)
         private_gateway = PrivateGateway.create(
@@ -2180,7 +2154,10 @@ class TestVMDeployVPC(cloudstackTestCase):
                                 traffictype='Egress'
                                 )
 
-        vlan = self.getFreeVlan(self.api_client, self.zone.id)
+        vlan = get_free_vlan(self.api_client, self.zone.id)[1]
+        if vlan is None:
+            self.fail("Failed to get free vlan id in the zone")
+
         self.debug("Creating private gateway in VPC: %s" % vpc.name)
         private_gateway = PrivateGateway.create(
                                                 self.apiclient,

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/631743b4/tools/marvin/marvin/integration/lib/common.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/common.py b/tools/marvin/marvin/integration/lib/common.py
index 6c2bb2a..096b073 100644
--- a/tools/marvin/marvin/integration/lib/common.py
+++ b/tools/marvin/marvin/integration/lib/common.py
@@ -750,3 +750,51 @@ def get_portable_ip_range_services(config):
         services = None
 
     return services
+
+def get_free_vlan(apiclient, zoneid):
+    """
+    Find an unallocated VLAN outside the range allocated to the physical network.
+
+    @note: This does not guarantee that the VLAN is available for use in
+    the deployment's network gear
+    @return: physical_network, shared_vlan_tag
+    """
+    list_physical_networks_response = PhysicalNetwork.list(
+            apiclient,
+            zoneid=zoneid
+        )
+    assert isinstance(list_physical_networks_response, list)
+    assert len(list_physical_networks_response) > 0, "No physical networks found in zone
%s" % zoneid
+
+    physical_network = list_physical_networks_response[0]
+    vlans = xsplit(physical_network.vlan, ['-', ','])
+
+    assert len(vlans) > 0
+    assert int(vlans[0]) < int(vlans[-1]), "VLAN range  %s was improperly split" % physical_network.vlan
+
+    usedVlanIds = []
+    networks = list_networks(apiclient, zoneid= zoneid, type='Shared')
+    if isinstance(networks, list) and len(networks) > 0:
+        usedVlanIds = [int(nw.vlan) for nw in networks]
+
+    retriesCount = 20 #Assuming random function will give different integer each time
+
+    shared_ntwk_vlan = None
+
+    while True:
+
+        if retriesCount == 0:
+           break
+
+        free_vlan = int(vlans[-1]) + random.randrange(1, 20)
+
+        if free_vlan > 4095:
+            free_vlan = int(vlans[0]) - random.randrange(1, 20)
+        if free_vlan < 0 or (free_vlan in usedVlanIds):
+            retriesCount -= 1
+            continue
+        else:
+            shared_ntwk_vlan = free_vlan
+            break
+
+    return physical_network, shared_ntwk_vlan


Mime
View raw message