You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by gi...@apache.org on 2013/11/21 06:29:51 UTC

git commit: updated refs/heads/4.3 to 0253fe5

Updated Branches:
  refs/heads/4.3 ff24ed0c8 -> 0253fe5d3


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/0253fe5d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0253fe5d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0253fe5d

Branch: refs/heads/4.3
Commit: 0253fe5d3bcaebfd7d23da5404a071588235b8d4
Parents: ff24ed0
Author: Gaurav Aradhye <ga...@clogeny.com>
Authored: Thu Nov 21 10:53:27 2013 +0530
Committer: Girish Shilamkar <gi...@clogeny.com>
Committed: Thu Nov 21 10:59:35 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/0253fe5d/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/0253fe5d/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 bcd37e7..32288a4 100644
--- a/test/integration/component/test_vpc_vm_life_cycle.py
+++ b/test/integration/component/test_vpc_vm_life_cycle.py
@@ -864,33 +864,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,
@@ -969,7 +942,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/0253fe5d/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 ebf3b31..af9d310 100644
--- a/test/integration/component/test_vpc_vms_deployment.py
+++ b/test/integration/component/test_vpc_vms_deployment.py
@@ -272,34 +272,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
@@ -2023,8 +1995,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(
@@ -2181,7 +2155,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/0253fe5d/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