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/master to de99094
Date Mon, 19 May 2014 07:55:59 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 667c8e790 -> de9909403


CLOUDSTACK-6687: Fixed IP reservation test case failures with code re-factoring


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

Branch: refs/heads/master
Commit: de9909403eaaa01d5b6fb6df631aceb4651a5422
Parents: 667c8e7
Author: Gaurav Aradhye <gaurav.aradhye@clogeny.com>
Authored: Thu May 15 03:45:22 2014 -0400
Committer: Girish Shilamkar <girish@clogeny.com>
Committed: Sun May 18 21:04:31 2014 -0400

----------------------------------------------------------------------
 .../component/test_ip_reservation.py            | 125 ++++++++++++++-----
 tools/marvin/marvin/codes.py                    |   1 +
 tools/marvin/marvin/lib/common.py               |  22 +++-
 3 files changed, 109 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/de990940/test/integration/component/test_ip_reservation.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_ip_reservation.py b/test/integration/component/test_ip_reservation.py
index bfb0da1..69d0b89 100644
--- a/test/integration/component/test_ip_reservation.py
+++ b/test/integration/component/test_ip_reservation.py
@@ -23,10 +23,22 @@
     Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/FS+-+IP+Range+Reservation+within+a+Network
 """
 from marvin.cloudstackTestCase import cloudstackTestCase, unittest
-from marvin.cloudstackException import CloudstackAPIException
-from marvin.lib.utils import *
-from marvin.lib.base import *
-from marvin.lib.common import *
+from marvin.lib.utils import validateList, cleanup_resources, verifyRouterState
+from marvin.lib.base import (Account,
+                             Network,
+                             VirtualMachine,
+                             Router,
+                             ServiceOffering,
+                             NetworkOffering)
+from marvin.lib.common import (get_zone,
+                               get_template,
+                               get_domain,
+                               wait_for_cleanup,
+                               createEnabledNetworkOffering,
+                               createNetworkRulesForVM,
+                               verifyNetworkState)
+from marvin.codes import (PASS, FAIL, FAILED, UNKNOWN, FAULT, MASTER,
+                          NAT_RULE, STATIC_NAT_RULE, ERROR_CODE_530)
 import netaddr
 
 import random
@@ -1056,19 +1068,6 @@ class TestFailureScnarios(cloudstackTestCase):
             raise Exception("Warning: Exception during cleanup : %s" % e)
         return
 
-    def create_virtual_machine(self, network_id=None, ip_address=None):
-        virtual_machine = VirtualMachine.create(self.apiclient,
-                                                          self.services["virtual_machine"],
-                                                          networkids=network_id,
-                                                          serviceofferingid=self.service_offering.id,
-                                                          accountid=self.account.name,
-                                                          domainid=self.domain.id,
-                                                          ipaddress=ip_address
-                                                          )
-        self.debug("Virtual Machine is created: " + virtual_machine.id)
-        self.cleanup.append(virtual_machine)
-        return virtual_machine
-
     @attr(tags=["advanced", "selfservice"])
     def test_network_not_implemented(self):
         # steps
@@ -1076,6 +1075,7 @@ class TestFailureScnarios(cloudstackTestCase):
         #
         # validation
         # should throw exception as network is not in implemented state as no vm is created
+
         networkOffering = self.isolated_network_offering
         resultSet = createIsolatedNetwork(self, networkOffering.id)
         if resultSet[0] == FAIL:
@@ -1100,14 +1100,31 @@ class TestFailureScnarios(cloudstackTestCase):
         # 1. guest vm cidr should be successfully updated with correct value
         # 2. existing guest vm ip should not be changed after reservation
         # 3. newly created VM should get ip in guestvmcidr
-        guest_vm_cidr = u"10.1.1.0/29"
+
+        networkOffering = self.isolated_persistent_network_offering
+        subnet = "10.1."+str(random.randrange(1,254))
+        gateway = subnet + ".1"
+        isolated_persistent_network = None
+        resultSet = createIsolatedNetwork(self, networkOffering.id, gateway=gateway)
+        if resultSet[0] == FAIL:
+            self.fail("Failed to create isolated network")
+        else:
+            isolated_persistent_network = resultSet[1]
+        guest_vm_cidr = subnet +".0/29"
         virtual_machine_1 = None
         try:
-            virtual_machine_1 = self.create_virtual_machine(network_id=self.isolated_persistent_network.id,
ip_address=u"10.1.1.3")
+            virtual_machine_1 = VirtualMachine.create(self.apiclient,
+                                                          self.testData["virtual_machine"],
+                                                          networkids=isolated_persistent_network.id,
+                                                          serviceofferingid=self.service_offering.id,
+                                                          accountid=self.account.name,
+                                                          domainid=self.domain.id,
+                                                          ipaddress=subnet+".3"
+                                                          )
         except Exception as e:
-            self.skipTest("VM creation fails in network ")
+            self.fail("VM creation fails in network: %s" % e)
 
-        update_response = Network.update(self.isolated_persistent_network, self.apiclient,
id=self.isolated_persistent_network.id, guestvmcidr=guest_vm_cidr)
+        update_response = Network.update(isolated_persistent_network, self.apiclient, id=isolated_persistent_network.id,
guestvmcidr=guest_vm_cidr)
         self.assertEqual(guest_vm_cidr, update_response.cidr, "cidr in response is not as
expected")
         vm_list = VirtualMachine.list(self.apiclient,
                                        id=virtual_machine_1.id)
@@ -1118,11 +1135,18 @@ class TestFailureScnarios(cloudstackTestCase):
                           virtual_machine_1.ipaddress,
                            "VM IP should not change after reservation")
         try:
-            virtual_machine_2 = self.create_virtual_machine(network_id=self.isolated_persistent_network.id)
+            virtual_machine_2 = VirtualMachine.create(self.apiclient,
+                                                          self.testData["virtual_machine"],
+                                                          networkids=isolated_persistent_network.id,
+                                                          serviceofferingid=self.service_offering.id,
+                                                          accountid=self.account.name,
+                                                          domainid=self.domain.id
+                                                          )
             if netaddr.IPAddress(virtual_machine_2.ipaddress) not in netaddr.IPNetwork(guest_vm_cidr):
                 self.fail("Newly created VM doesn't get IP from reserverd CIDR")
         except Exception as e:
-            self.skipTest("VM creation fails, cannot validate the condition")
+            self.skipTest("VM creation fails, cannot validate the condition: %s" % e)
+        return
 
     @attr(tags=["advanced", "selfservice"])
     def test_reservation_after_router_restart(self):
@@ -1133,13 +1157,31 @@ class TestFailureScnarios(cloudstackTestCase):
         # validation
         # 1. guest vm cidr should be successfully updated with correct value
         # 2. network cidr should remain same after router restart
-        guest_vm_cidr = u"10.1.1.0/29"
+        networkOffering = self.isolated_persistent_network_offering
+        subnet = "10.1."+str(random.randrange(1,254))
+        gateway = subnet + ".1"
+        isolated_persistent_network = None
+        resultSet = createIsolatedNetwork(self, networkOffering.id, gateway=gateway)
+        if resultSet[0] == FAIL:
+            self.fail("Failed to create isolated network")
+        else:
+            isolated_persistent_network = resultSet[1]
 
-        update_response = Network.update(self.isolated_persistent_network, self.apiclient,
id=self.isolated_persistent_network.id, guestvmcidr=guest_vm_cidr)
+        response = verifyNetworkState(self.apiclient, isolated_persistent_network.id,\
+                        "implemented")
+        exceptionOccured = response[0]
+        isNetworkInDesiredState = response[1]
+        exceptionMessage = response[2]
+
+        if (exceptionOccured or (not isNetworkInDesiredState)):
+            self.fail(exceptionMessage)
+        guest_vm_cidr = subnet +".0/29"
+
+        update_response = Network.update(isolated_persistent_network, self.apiclient, id=isolated_persistent_network.id,
guestvmcidr=guest_vm_cidr)
         self.assertEqual(guest_vm_cidr, update_response.cidr, "cidr in response is not as
expected")
 
         routers = Router.list(self.apiclient,
-                             networkid=self.isolated_persistent_network.id,
+                             networkid=isolated_persistent_network.id,
                              listall=True)
         self.assertEqual(
                     isinstance(routers, list),
@@ -1150,13 +1192,14 @@ class TestFailureScnarios(cloudstackTestCase):
             self.skipTest("Router list should not be empty, skipping test")
 
         Router.reboot(self.apiclient, routers[0].id)
-        networks = Network.list(self.apiclient, id=self.isolated_persistent_network.id)
+        networks = Network.list(self.apiclient, id=isolated_persistent_network.id)
         self.assertEqual(
                     isinstance(networks, list),
                     True,
                     "list Networks should return valid response"
                     )
         self.assertEqual(networks[0].cidr, guest_vm_cidr, "guestvmcidr should match after
router reboot")
+        return
 
     @attr(tags=["advanced", "selfservice"])
     def test_vm_create_outside_cidr_after_reservation(self):
@@ -1167,11 +1210,25 @@ class TestFailureScnarios(cloudstackTestCase):
         # validation
         # 1. guest vm cidr should be successfully updated with correct value
         # 2  newly created VM should not be created and result in exception
-        guest_vm_cidr = u"10.1.1.0/29"
-        update_response = Network.update(self.isolated_persistent_network, self.apiclient,
id=self.isolated_persistent_network.id, guestvmcidr=guest_vm_cidr)
+        networkOffering = self.isolated_persistent_network_offering
+        subnet = "10.1."+str(random.randrange(1,254))
+        gateway = subnet + ".1"
+        isolated_persistent_network = None
+        resultSet = createIsolatedNetwork(self, networkOffering.id, gateway=gateway)
+        if resultSet[0] == FAIL:
+            self.fail("Failed to create isolated network")
+        else:
+            isolated_persistent_network = resultSet[1]
+        guest_vm_cidr = subnet +".0/29"
+        update_response = Network.update(isolated_persistent_network, self.apiclient, id=isolated_persistent_network.id,
guestvmcidr=guest_vm_cidr)
         self.assertEqual(guest_vm_cidr, update_response.cidr, "cidr in response is not as
expected")
-        try:
-            self.create_virtual_machine(network_id=self.isolated_persistent_network.id, ip_address=u"10.1.1.9")
-            self.fail("vm should not be created ")
-        except Exception as e:
-            self.debug("exception as IP is outside of guestvmcidr")
+        with self.assertRaises(Exception):
+            VirtualMachine.create(self.apiclient,
+                                  self.testData["virtual_machine"],
+                                  networkids=isolated_persistent_network.id,
+                                  serviceofferingid=self.service_offering.id,
+                                  accountid=self.account.name,
+                                  domainid=self.domain.id,
+                                  ipaddress="10.1.1.9"
+                                  )
+        return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/de990940/tools/marvin/marvin/codes.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/codes.py b/tools/marvin/marvin/codes.py
index ef49c0c..c72a6bd 100644
--- a/tools/marvin/marvin/codes.py
+++ b/tools/marvin/marvin/codes.py
@@ -60,6 +60,7 @@ JOB_INPROGRESS = 0
 JOB_SUCCEEDED = 1
 JOB_FAILED = 2
 JOB_CANCELLED = 3
+ERROR_CODE_530 = 530
 '''
 User Related Codes
 '''

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/de990940/tools/marvin/marvin/lib/common.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/lib/common.py b/tools/marvin/marvin/lib/common.py
index 4a41abc..8b170da 100644
--- a/tools/marvin/marvin/lib/common.py
+++ b/tools/marvin/marvin/lib/common.py
@@ -1083,13 +1083,25 @@ def shouldTestBeSkipped(networkType, zoneType):
 
 def verifyNetworkState(apiclient, networkid, state):
     """List networks and check if the network state matches the given state"""
+    retriesCount = 10
+    isNetworkInDesiredState = False
+    exceptionOccured = False
+    exceptionMessage = ""
     try:
-        networks = Network.list(apiclient, id=networkid)
+        while retriesCount >= 0:
+            networks = Network.list(apiclient, id=networkid)
+            assert validateList(
+                networks)[0] == PASS, "Networks list validation failed"
+            if str(networks[0].state).lower() == state:
+                isNetworkInDesiredState = True
+                break
+            retriesCount -= 1
+            time.sleep(60)
     except Exception as e:
-        raise Exception("Failed while fetching network list with error: %s" % e)
-    assert validateList(networks)[0] == PASS, "Networks list validation failed, list is %s"
% networks
-    assert str(networks[0].state).lower() == state, "network state should be %s, it is %s"
% (state, networks[0].state)
-    return
+        exceptionOccured = True
+        exceptionMessage = e
+        return [exceptionOccured, isNetworkInDesiredState, exceptionMessage]
+    return [exceptionOccured, isNetworkInDesiredState, exceptionMessage]
 
 def verifyComputeOfferingCreation(apiclient, computeofferingid):
     """List Compute offerings by ID and verify that the offering exists"""


Mime
View raw message