cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tall...@apache.org
Subject [09/18] Marvin + test changes from master Signed-off-by: SrikanteswaraRao Talluri <talluri@apache.org>
Date Mon, 28 Apr 2014 11:00:10 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/test/integration/smoke/test_vm_iam.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_vm_iam.py b/test/integration/smoke/test_vm_iam.py
index 80c049b..be75a79 100644
--- a/test/integration/smoke/test_vm_iam.py
+++ b/test/integration/smoke/test_vm_iam.py
@@ -20,9 +20,10 @@
 import marvin
 from marvin.cloudstackTestCase import *
 from marvin.cloudstackAPI import *
-from marvin.integration.lib.utils import *
-from marvin.integration.lib.base import *
-from marvin.integration.lib.common import *
+from marvin.lib.utils import *
+from marvin.lib.base import *
+from marvin.lib.common import *
+from marvin.codes import FAILED
 from nose.plugins.attrib import attr
 #Import System modules
 import time
@@ -103,7 +104,8 @@ class TestVMIam(cloudstackTestCase):
 
     @classmethod
     def setUpClass(self):
-        self.apiclient = super(TestVMIam, self).getClsTestClient().getApiClient()
+        testClient = super(TestVMIam, self).getClsTestClient()
+        self.apiclient = testClient.getApiClient()
         self.services = Services().services
         
         # backup default apikey and secretkey
@@ -191,7 +193,7 @@ class TestVMIam(cloudstackTestCase):
                                 self.services["service_offering"]["small"]
                                 )
         
-        self.zone = get_zone(self.apiclient, self.services)
+        self.zone = get_zone(self.apiclient, testClient.getZoneForTests())
         self.services['mode'] = self.zone.networktype
         self.template = get_template(self.apiclient, self.zone.id, self.services["ostype"])
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/test/integration/smoke/test_vm_life_cycle.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py
index 7d47f70..f114ec9 100644
--- a/test/integration/smoke/test_vm_life_cycle.py
+++ b/test/integration/smoke/test_vm_life_cycle.py
@@ -18,138 +18,28 @@
 """
 #Import Local Modules
 from marvin.cloudstackTestCase import cloudstackTestCase
-from marvin.cloudstackAPI import (detachIso,
-                                  attachIso,
-                                  recoverVirtualMachine,
-                                  destroyVirtualMachine)
-from marvin.integration.lib.utils import (cleanup_resources,
-                                           validateList,
-                                           get_hypervisor_type)
-from marvin.integration.lib.base import (Account,
-                                         ServiceOffering,
-                                         VirtualMachine,
-                                         Iso,
-                                         Host)
-from marvin.integration.lib.common import (get_domain,
-                                           get_zone,
-                                           get_template,
-                                           list_virtual_machines,
-                                           list_configurations,
-                                           list_routers,
-                                           list_isos)
-from marvin.codes import PASS
+from marvin.codes import FAILED
+from marvin.cloudstackTestCase import *
+from marvin.cloudstackAPI import *
+from marvin.lib.utils import *
+from marvin.lib.base import *
+from marvin.lib.common import *
 from nose.plugins.attrib import attr
 #Import System modules
 import time
 
 _multiprocess_shared_ = True
-class Services:
-    """Test VM Life Cycle Services
-    """
-
-    def __init__(self):
-        self.services = {
-                "disk_offering":{
-                    "displaytext": "Small",
-                    "name": "Small",
-                    "disksize": 1
-                },
-                "account": {
-                    "email": "test@test.com",
-                    "firstname": "Test",
-                    "lastname": "User",
-                    "username": "test",
-                    # Random characters are appended in create account to
-                    # ensure unique username generated each time
-                    "password": "password",
-                },
-                "small":
-                # Create a small virtual machine instance with disk offering
-                {
-                    "displayname": "testserver",
-                    "username": "root", # VM creds for SSH
-                    "password": "password",
-                    "ssh_port": 22,
-                    "hypervisor": 'XenServer',
-                    "privateport": 22,
-                    "publicport": 22,
-                    "protocol": 'TCP',
-                },
-                "medium":   # Create a medium virtual machine instance
-                {
-                    "displayname": "testserver",
-                    "username": "root",
-                    "password": "password",
-                    "ssh_port": 22,
-                    "hypervisor": 'XenServer',
-                    "privateport": 22,
-                    "publicport": 22,
-                    "protocol": 'TCP',
-                },
-                "service_offerings":
-                {
-                 "tiny":
-                   {
-                        "name": "Tiny Instance",
-                        "displaytext": "Tiny Instance",
-                        "cpunumber": 1,
-                        "cpuspeed": 100, # in MHz
-                        "memory": 128, # In MBs
-                    },
-                 "small":
-                    {
-                     # Small service offering ID to for change VM
-                     # service offering from medium to small
-                        "name": "Small Instance",
-                        "displaytext": "Small Instance",
-                        "cpunumber": 1,
-                        "cpuspeed": 100,
-                        "memory": 256,
-                    },
-                "medium":
-                    {
-                    # Medium service offering ID to for
-                    # change VM service offering from small to medium
-                        "name": "Medium Instance",
-                        "displaytext": "Medium Instance",
-                        "cpunumber": 1,
-                        "cpuspeed": 100,
-                        "memory": 256,
-                    }
-                },
-                "iso":  # ISO settings for Attach/Detach ISO tests
-                {
-                    "displaytext": "Test ISO",
-                    "name": "testISO",
-                    "url": "http://people.apache.org/~tsp/dummy.iso",
-                     # Source URL where ISO is located
-                    "ostype": 'CentOS 5.3 (64-bit)',
-                    "mode": 'HTTP_DOWNLOAD', # Downloading existing ISO
-                },
-                "template": {
-                    "displaytext": "Cent OS Template",
-                    "name": "Cent OS Template",
-                    "passwordenabled": True,
-                },
-            "diskdevice": ['/dev/vdc',  '/dev/vdb', '/dev/hdb', '/dev/hdc', '/dev/xvdd', '/dev/cdrom', '/dev/sr0', '/dev/cdrom1' ],
-            # Disk device where ISO is attached to instance
-            "mount_dir": "/mnt/tmp",
-            "sleep": 60,
-            "timeout": 10,
-            #Migrate VM to hostid
-            "ostype": 'CentOS 5.3 (64-bit)',
-            # CentOS 5.3 (64-bit)
-        }
-
 class TestDeployVM(cloudstackTestCase):
 
     @classmethod
     def setUpClass(cls):
-        cls.services = Services().services
-        cls.apiclient = super(TestDeployVM, cls).getClsTestClient().getApiClient()
+        testClient = super(TestDeployVM, cls).getClsTestClient()
+        cls.apiclient = testClient.getApiClient()
+        cls.services = testClient.getParsedTestDataConfig()
+
         # Get Zone, Domain and templates
-        domain = get_domain(cls.apiclient, cls.services)
-        cls.zone = get_zone(cls.apiclient, cls.services)
+        domain = get_domain(cls.apiclient)
+        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
         cls.services['mode'] = cls.zone.networktype
 
         #If local storage is enabled, alter the offerings to use localstorage
@@ -164,13 +54,16 @@ class TestDeployVM(cloudstackTestCase):
             cls.zone.id,
             cls.services["ostype"]
         )
+        if template == FAILED:
+            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
+
         # Set Zones and disk offerings
         cls.services["small"]["zoneid"] = cls.zone.id
         cls.services["small"]["template"] = template.id
 
         cls.services["medium"]["zoneid"] = cls.zone.id
         cls.services["medium"]["template"] = template.id
-        cls.services["iso"]["zoneid"] = cls.zone.id
+        cls.services["iso1"]["zoneid"] = cls.zone.id
 
         cls.account = Account.create(
             cls.apiclient,
@@ -303,12 +196,13 @@ class TestVMLifeCycle(cloudstackTestCase):
 
     @classmethod
     def setUpClass(cls):
-        cls.api_client = super(TestVMLifeCycle, cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
+        testClient = super(TestVMLifeCycle, cls).getClsTestClient()
+        cls.apiclient = testClient.getApiClient()
+        cls.services = testClient.getParsedTestDataConfig()
 
         # Get Zone, Domain and templates
-        domain = get_domain(cls.api_client, cls.services)
-        cls.zone = get_zone(cls.api_client, cls.services)
+        domain = get_domain(cls.apiclient)
+        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
         cls.services['mode'] = cls.zone.networktype
 
         #if local storage is enabled, alter the offerings to use localstorage
@@ -319,37 +213,40 @@ class TestVMLifeCycle(cloudstackTestCase):
             cls.services["service_offerings"]["medium"]["storagetype"] = 'local'
 
         template = get_template(
-                            cls.api_client,
+                            cls.apiclient,
                             cls.zone.id,
                             cls.services["ostype"]
                             )
+        if template == FAILED:
+            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
+
         # Set Zones and disk offerings
         cls.services["small"]["zoneid"] = cls.zone.id
         cls.services["small"]["template"] = template.id
 
         cls.services["medium"]["zoneid"] = cls.zone.id
         cls.services["medium"]["template"] = template.id
-        cls.services["iso"]["zoneid"] = cls.zone.id
+        cls.services["iso1"]["zoneid"] = cls.zone.id
 
         # Create VMs, NAT Rules etc
         cls.account = Account.create(
-                            cls.api_client,
+                            cls.apiclient,
                             cls.services["account"],
                             domainid=domain.id
                             )
 
         cls.small_offering = ServiceOffering.create(
-                                    cls.api_client,
+                                    cls.apiclient,
                                     cls.services["service_offerings"]["small"]
                                     )
 
         cls.medium_offering = ServiceOffering.create(
-                                    cls.api_client,
+                                    cls.apiclient,
                                     cls.services["service_offerings"]["medium"]
                                     )
         #create small and large virtual machines
         cls.small_virtual_machine = VirtualMachine.create(
-                                        cls.api_client,
+                                        cls.apiclient,
                                         cls.services["small"],
                                         accountid=cls.account.name,
                                         domainid=cls.account.domainid,
@@ -357,7 +254,7 @@ class TestVMLifeCycle(cloudstackTestCase):
                                         mode=cls.services["mode"]
                                         )
         cls.medium_virtual_machine = VirtualMachine.create(
-                                       cls.api_client,
+                                       cls.apiclient,
                                        cls.services["medium"],
                                        accountid=cls.account.name,
                                        domainid=cls.account.domainid,
@@ -365,7 +262,7 @@ class TestVMLifeCycle(cloudstackTestCase):
                                        mode=cls.services["mode"]
                                     )
         cls.virtual_machine = VirtualMachine.create(
-                                        cls.api_client,
+                                        cls.apiclient,
                                         cls.services["small"],
                                         accountid=cls.account.name,
                                         domainid=cls.account.domainid,
@@ -380,8 +277,8 @@ class TestVMLifeCycle(cloudstackTestCase):
 
     @classmethod
     def tearDownClass(cls):
-        cls.api_client = super(TestVMLifeCycle, cls).getClsTestClient().getApiClient()
-        cleanup_resources(cls.api_client, cls._cleanup)
+        cls.apiclient = super(TestVMLifeCycle, cls).getClsTestClient().getApiClient()
+        cleanup_resources(cls.apiclient, cls._cleanup)
         return
 
     def setUp(self):
@@ -628,7 +525,7 @@ class TestVMLifeCycle(cloudstackTestCase):
 
         #deploy VM on target host
         self.vm_to_migrate = VirtualMachine.create(
-            self.api_client,
+            self.apiclient,
             self.services["small"],
             accountid=self.account.name,
             domainid=self.account.domainid,
@@ -641,7 +538,7 @@ class TestVMLifeCycle(cloudstackTestCase):
                                         migrate_host.id
                                         ))
 
-        self.vm_to_migrate.migrate(self.api_client, migrate_host.id)
+        self.vm_to_migrate.migrate(self.apiclient, migrate_host.id)
 
         list_vm_response = list_virtual_machines(
                                             self.apiclient,
@@ -733,7 +630,7 @@ class TestVMLifeCycle(cloudstackTestCase):
 
         iso = Iso.create(
                          self.apiclient,
-                         self.services["iso"],
+                         self.services["iso1"],
                          account=self.account.name,
                          domainid=self.account.domainid
                          )
@@ -760,12 +657,13 @@ class TestVMLifeCycle(cloudstackTestCase):
         except Exception as e:
             self.fail("SSH failed for virtual machine: %s - %s" %
                                 (self.virtual_machine.ipaddress, e))
-
-        cmds = "mkdir -p %s" % self.services["mount_dir"]
+        
+        mount_dir = "/mnt/tmp"
+        cmds = "mkdir -p %s" % mount_dir
         self.assert_(ssh_client.execute(cmds) == [], "mkdir failed within guest")
 
         for diskdevice in self.services["diskdevice"]:
-            res = ssh_client.execute("mount -rt iso9660 {} {}".format(diskdevice, self.services["mount_dir"]))
+            res = ssh_client.execute("mount -rt iso9660 {} {}".format(diskdevice, mount_dir))
             if res == []:
                 self.services["mount"] = diskdevice
                 break
@@ -790,7 +688,7 @@ class TestVMLifeCycle(cloudstackTestCase):
 
         try:
             #Unmount ISO
-            command = "umount %s" % self.services["mount_dir"]
+            command = "umount %s" % mount_dir
             ssh_client.execute(command)
         except Exception as e:
             self.fail("SSH failed for virtual machine: %s - %s" %

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/test/integration/smoke/test_vm_snapshots.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_vm_snapshots.py b/test/integration/smoke/test_vm_snapshots.py
index 65a5acb..e884d42 100644
--- a/test/integration/smoke/test_vm_snapshots.py
+++ b/test/integration/smoke/test_vm_snapshots.py
@@ -16,83 +16,33 @@
 # under the License.
 
 # Import Local Modules
-import marvin
+from marvin.codes import FAILED
 from nose.plugins.attrib import attr
 from marvin.cloudstackTestCase import *
 from marvin.cloudstackAPI import *
-from marvin.integration.lib.utils import *
-from marvin.integration.lib.base import *
-from marvin.integration.lib.common import *
-
-class Services:
-    """Test Snapshots Services
-    """
-
-    def __init__(self):
-        self.services = {
-            "account": {
-                "email": "test@test.com",
-                "firstname": "Test",
-                "lastname": "User",
-                "username": "test",
-                # Random characters are appended for unique
-                # username
-                "password": "password",
-            },
-            "service_offering": {
-                "name": "Tiny Instance",
-                "displaytext": "Tiny Instance",
-                "cpunumber": 1,
-                "cpuspeed": 200, # in MHz
-                "memory": 256, # In MBs
-            },
-            "server": {
-                "displayname": "TestVM",
-                "username": "root",
-                "password": "password",
-                "ssh_port": 22,
-                "hypervisor": 'XenServer',
-                "privateport": 22,
-                "publicport": 22,
-                "protocol": 'TCP',
-            },
-            "mgmt_server": {
-                "ipaddress": '1.2.2.152',
-                "username": "root",
-                "password": "password",
-                "port": 22,
-            },
-            "templates": {
-                "displaytext": 'Template',
-                "name": 'Template',
-                "ostype": "CentOS 5.3 (64-bit)",
-                "templatefilter": 'self',
-            },
-            "test_dir": "/tmp",
-            "random_data": "random.data",
-            "snapshot_name": "TestSnapshot",
-            "snapshot_displaytext": "Test",
-            "ostype": "CentOS 5.3 (64-bit)",
-            "sleep": 60,
-            "timeout": 10,
-            "mode": 'advanced', # Networking mode: Advanced, Basic
-        }
+from marvin.lib.utils import *
+from marvin.lib.base import *
+from marvin.lib.common import *
 
 class TestVmSnapshot(cloudstackTestCase):
 
     @classmethod
     def setUpClass(cls):
-        cls.api_client = super(TestVmSnapshot, cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
+	testClient = super(TestVmSnapshot, cls).getClsTestClient()
+        cls.apiclient = testClient.getApiClient()
+        cls.services = testClient.getParsedTestDataConfig()
         # Get Zone, Domain and templates
-        cls.domain = get_domain(cls.api_client, cls.services)
-        cls.zone = get_zone(cls.api_client, cls.services)
+        cls.domain = get_domain(cls.apiclient)
+        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
 
         template = get_template(
-                    cls.api_client,
+                    cls.apiclient,
                     cls.zone.id,
                     cls.services["ostype"]
                     )
+        if template == FAILED:
+            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
+
         cls.services["domainid"] = cls.domain.id
         cls.services["server"]["zoneid"] = cls.zone.id
         cls.services["templates"]["ostypeid"] = template.ostypeid
@@ -100,27 +50,27 @@ class TestVmSnapshot(cloudstackTestCase):
 
         # Create VMs, NAT Rules etc
         cls.account = Account.create(
-                    cls.api_client,
+                    cls.apiclient,
                     cls.services["account"],
                     domainid=cls.domain.id
                     )
 
-        cls.services["account"] = cls.account.name
-
         cls.service_offering = ServiceOffering.create(
-                            cls.api_client,
-                            cls.services["service_offering"]
+                            cls.apiclient,
+                            cls.services["service_offerings"]
                             )
         cls.virtual_machine = VirtualMachine.create(
-                    cls.api_client,
+                    cls.apiclient,
                     cls.services["server"],
                     templateid=template.id,
                     accountid=cls.account.name,
                     domainid=cls.account.domainid,
                     serviceofferingid=cls.service_offering.id,
-                    mode=cls.services["mode"]
+                    mode=cls.zone.networktype
                     )
         cls.random_data_0 = random_gen(size=100)
+        cls.test_dir = "/tmp"
+        cls.random_data = "random.data"
         cls._cleanup = [
                 cls.service_offering,
                 cls.account,
@@ -131,7 +81,7 @@ class TestVmSnapshot(cloudstackTestCase):
     def tearDownClass(cls):
         try:
             # Cleanup resources used
-            cleanup_resources(cls.api_client, cls._cleanup)
+            cleanup_resources(cls.apiclient, cls._cleanup)
         except Exception as e:
             raise Exception("Warning: Exception during cleanup : %s" % e)
         return
@@ -160,8 +110,8 @@ class TestVmSnapshot(cloudstackTestCase):
             ssh_client = self.virtual_machine.get_ssh_client()
 
             cmds = [
-                "echo %s > %s/%s" % (self.random_data_0, self.services["test_dir"], self.services["random_data"]),
-                "cat %s/%s" % (self.services["test_dir"], self.services["random_data"])
+                "echo %s > %s/%s" % (self.random_data_0, self.test_dir, self.random_data),
+                "cat %s/%s" % (self.test_dir, self.random_data)
             ]
 
             for c in cmds:
@@ -184,8 +134,8 @@ class TestVmSnapshot(cloudstackTestCase):
             self.apiclient,
             self.virtual_machine.id,
             "false",
-            self.services["snapshot_name"],
-            self.services["snapshot_displaytext"]
+            "TestSnapshot",
+            "Dsiplay Text"
         )
         self.assertEqual(
             vm_snapshot.state,
@@ -203,8 +153,8 @@ class TestVmSnapshot(cloudstackTestCase):
             ssh_client = self.virtual_machine.get_ssh_client()
 
             cmds = [
-                "rm -rf %s/%s" % (self.services["test_dir"], self.services["random_data"]),
-                "ls %s/%s" % (self.services["test_dir"], self.services["random_data"])
+                "rm -rf %s/%s" % (self.test_dir, self.random_data),
+                "ls %s/%s" % (self.test_dir, self.random_data)
             ]
 
             for c in cmds:
@@ -263,7 +213,7 @@ class TestVmSnapshot(cloudstackTestCase):
             ssh_client = self.virtual_machine.get_ssh_client(reconnect=True)
 
             cmds = [
-                "cat %s/%s" % (self.services["test_dir"], self.services["random_data"])
+                "cat %s/%s" % (self.test_dir, self.random_data)
             ]
 
             for c in cmds:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/test/integration/smoke/test_volumes.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py
index 411ecf1..7f5c4f3 100644
--- a/test/integration/smoke/test_volumes.py
+++ b/test/integration/smoke/test_volumes.py
@@ -17,14 +17,15 @@
 """ BVT tests for Volumes
 """
 #Import Local Modules
-import marvin
 from marvin.cloudstackTestCase import *
 from marvin.cloudstackException import *
 from marvin.cloudstackAPI import *
 from marvin.sshClient import SshClient
-from marvin.integration.lib.utils import *
-from marvin.integration.lib.base import *
-from marvin.integration.lib.common import *
+from marvin.lib.utils import *
+from marvin.lib.base import *
+from marvin.lib.common import *
+from marvin.lib.utils import checkVolumeSize
+from marvin.codes import SUCCESS
 from nose.plugins.attrib import attr
 #Import System modules
 import os
@@ -34,103 +35,55 @@ import tempfile
 
 _multiprocess_shared_ = True
 
-class Services:
-    """Test Volume Services
-    """
-
-    def __init__(self):
-        self.services = {
-                         "account": {
-                                    "email": "test@test.com",
-                                    "firstname": "Test",
-                                    "lastname": "User",
-                                    "username": "test",
-                                    # Random characters are appended for unique
-                                    # username
-                                    "password": "password",
-                         },
-                         "service_offering": {
-                                    "name": "Tiny Instance",
-                                    "displaytext": "Tiny Instance",
-                                    "cpunumber": 1,
-                                    "cpuspeed": 100,    # in MHz
-                                    "memory": 260       # In MBs
-
-                        },
-                        "disk_offering": {
-                                    "displaytext": "Small",
-                                    "name": "Small",
-                                    "disksize": 1
-                        },
-                        'resized_disk_offering': {
-                                    "displaytext": "Resized",
-                                    "name": "Resized",
-                                    "disksize": 3
-                        },
-                        "volume_offerings": {
-                            0: {
-                                "diskname": "TestDiskServ",
-                            },
-                        },
-                        "customdisksize": 1,    # GBs
-                        "username": "root",     # Creds for SSH to VM
-                        "password": "password",
-                        "ssh_port": 22,
-                        "diskname": "TestDiskServ",
-                        "hypervisor": 'KVM',
-                        "privateport": 22,
-                        "publicport": 22,
-                        "protocol": 'TCP',
-                        "ostype": 'CentOS 5.5 (64-bit)',
-                        "sleep": 10,
-                        "timeout": 600,
-                    }
-
-
 class TestCreateVolume(cloudstackTestCase):
 
     @classmethod
     def setUpClass(cls):
-        cls.api_client = super(TestCreateVolume, cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
-
+        testClient = super(TestCreateVolume, cls).getClsTestClient()
+        cls.apiclient = testClient.getApiClient()
+        cls.services = testClient.getParsedTestDataConfig()
         # Get Zone, Domain and templates
-        cls.domain = get_domain(cls.api_client, cls.services)
-        cls.zone = get_zone(cls.api_client, cls.services)
+        cls.domain = get_domain(cls.apiclient)
+        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
         cls.services['mode'] = cls.zone.networktype
         cls.disk_offering = DiskOffering.create(
-                                    cls.api_client,
+                                    cls.apiclient,
                                     cls.services["disk_offering"]
                                     )
+        cls.sparse_disk_offering = DiskOffering.create(
+                                    cls.apiclient,
+                                    cls.services["sparse_disk_offering"]
+                                    )
         cls.custom_disk_offering = DiskOffering.create(
-                                    cls.api_client,
+                                    cls.apiclient,
                                     cls.services["disk_offering"],
                                     custom=True
                                     )
         template = get_template(
-                            cls.api_client,
+                            cls.apiclient,
                             cls.zone.id,
                             cls.services["ostype"]
                             )
+        if template == FAILED:
+            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
+
         cls.services["domainid"] = cls.domain.id
         cls.services["zoneid"] = cls.zone.id
         cls.services["template"] = template.id
         cls.services["customdiskofferingid"] = cls.custom_disk_offering.id
-
+        cls.services["diskname"] = cls.services["volume"]["diskname"]
         # Create VMs, NAT Rules etc
         cls.account = Account.create(
-                            cls.api_client,
+                            cls.apiclient,
                             cls.services["account"],
                             domainid=cls.domain.id
                             )
-
-        cls.services["account"] = cls.account.name
         cls.service_offering = ServiceOffering.create(
-                                            cls.api_client,
-                                            cls.services["service_offering"]
+                                            cls.apiclient,
+                                            cls.services["service_offerings"]
                                             )
         cls.virtual_machine = VirtualMachine.create(
-                                    cls.api_client,
+                                    cls.apiclient,
                                     cls.services,
                                     accountid=cls.account.name,
                                     domainid=cls.account.domainid,
@@ -172,6 +125,18 @@ class TestCreateVolume(cloudstackTestCase):
             self.debug("Created a volume with ID: %s" % volume.id)
             self.volumes.append(volume)
 
+        if self.virtual_machine.hypervisor == "KVM":
+            sparse_volume = Volume.create(
+                                        self.apiClient,
+                                        self.services,
+                                        zoneid=self.zone.id,
+                                        account=self.account.name,
+                                        domainid=self.account.domainid,
+                                        diskofferingid=self.sparse_disk_offering.id
+                                        )
+            self.debug("Created a sparse volume: %s" % sparse_volume.id)
+            self.volumes.append(sparse_volume)
+
         volume = Volume.create_custom_disk(
                                     self.apiClient,
                                     self.services,
@@ -227,7 +192,6 @@ class TestCreateVolume(cloudstackTestCase):
                                             )
 
                 if isinstance(list_vm_response, list):
-
                     vm = list_vm_response[0]
                     if vm.state == 'Running':
                         self.debug("VM state: %s" % vm.state)
@@ -236,31 +200,17 @@ class TestCreateVolume(cloudstackTestCase):
                 if timeout == 0:
                     raise Exception(
                         "Failed to start VM (ID: %s) " % vm.id)
-
                 timeout = timeout - 1
 
-            try:
-                ssh = self.virtual_machine.get_ssh_client(
+            vol_sz = str(list_volume_response[0].size)
+            ssh = self.virtual_machine.get_ssh_client(
                                                       reconnect=True
                                                       )
-                c = "/sbin/fdisk -l"
-                res = ssh.execute(c)
-
-            except Exception as e:
-                self.fail("SSH access failed for VM: %s - %s" %
-                                (self.virtual_machine.ipaddress, e))
-
-            # Disk /dev/sda doesn't contain a valid partition table
-            # Disk /dev/sda: 21.5 GB, 21474836480 bytes
-            result = str(res)
-            self.debug("fdisk result: %s" % result)
-
-            self.assertEqual(
-                             str(list_volume_response[0].size) in result,
-                             True,
-                             "Check if promised disk size actually available"
-                             )
+            ret = checkVolumeSize(ssh_handle=ssh,size_to_verify=vol_sz)
+            self.debug(" Volume Size Expected %s  Actual :%s" %(vol_sz,ret[1]))
             self.virtual_machine.detach_volume(self.apiClient, volume)
+            self.assertEqual(ret[0],SUCCESS,"Check if promised disk size actually available")
+            time.sleep(self.services["sleep"])
 
     def tearDown(self):
         #Clean up, terminate the created volumes
@@ -270,8 +220,8 @@ class TestCreateVolume(cloudstackTestCase):
     @classmethod
     def tearDownClass(cls):
         try:
-            cls.api_client = super(TestCreateVolume, cls).getClsTestClient().getApiClient()
-            cleanup_resources(cls.api_client, cls._cleanup)
+            cls.apiclient = super(TestCreateVolume, cls).getClsTestClient().getApiClient()
+            cleanup_resources(cls.apiclient, cls._cleanup)
         except Exception as e:
             raise Exception("Warning: Exception during cleanup : %s" % e)
 
@@ -280,31 +230,36 @@ class TestVolumes(cloudstackTestCase):
 
     @classmethod
     def setUpClass(cls):
-        cls.api_client = super(TestVolumes, cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
+        testClient = super(TestVolumes, cls).getClsTestClient()
+        cls.apiclient = testClient.getApiClient()
+        cls.services = testClient.getParsedTestDataConfig()
+
         # Get Zone, Domain and templates
-        cls.domain = get_domain(cls.api_client, cls.services)
-        cls.zone = get_zone(cls.api_client, cls.services)
+        cls.domain = get_domain(cls.apiclient)
+        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
         cls.services['mode'] = cls.zone.networktype
         cls.disk_offering = DiskOffering.create(
-                                    cls.api_client,
+                                    cls.apiclient,
                                     cls.services["disk_offering"]
                                     )
         cls.resized_disk_offering = DiskOffering.create(
-                                    cls.api_client,
+                                    cls.apiclient,
                                     cls.services["resized_disk_offering"]
                                     )
         cls.custom_resized_disk_offering = DiskOffering.create(
-                                    cls.api_client,
+                                    cls.apiclient,
                                     cls.services["resized_disk_offering"],
                                     custom=True
                                     )
 
         template = get_template(
-                            cls.api_client,
+                            cls.apiclient,
                             cls.zone.id,
                             cls.services["ostype"]
                             )
+        if template == FAILED:
+            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
+
         cls.services["domainid"] = cls.domain.id
         cls.services["zoneid"] = cls.zone.id
         cls.services["template"] = template.id
@@ -314,18 +269,16 @@ class TestVolumes(cloudstackTestCase):
 
         # Create VMs, VMs etc
         cls.account = Account.create(
-                            cls.api_client,
+                            cls.apiclient,
                             cls.services["account"],
                             domainid=cls.domain.id
                             )
-
-        cls.services["account"] = cls.account.name
         cls.service_offering = ServiceOffering.create(
-                                            cls.api_client,
-                                            cls.services["service_offering"]
+                                            cls.apiclient,
+                                            cls.services["service_offerings"]
                                         )
         cls.virtual_machine = VirtualMachine.create(
-                                    cls.api_client,
+                                    cls.apiclient,
                                     cls.services,
                                     accountid=cls.account.name,
                                     domainid=cls.account.domainid,
@@ -334,7 +287,7 @@ class TestVolumes(cloudstackTestCase):
                                 )
 
         cls.volume = Volume.create(
-                                   cls.api_client,
+                                   cls.apiclient,
                                    cls.services,
                                    account=cls.account.name,
                                    domainid=cls.account.domainid
@@ -351,7 +304,7 @@ class TestVolumes(cloudstackTestCase):
     @classmethod
     def tearDownClass(cls):
         try:
-            cleanup_resources(cls.api_client, cls._cleanup)
+            cleanup_resources(cls.apiclient, cls._cleanup)
         except Exception as e:
             raise Exception("Warning: Exception during cleanup : %s" % e)
 
@@ -766,7 +719,7 @@ class TestVolumes(cloudstackTestCase):
         self.debug("Delete Volume ID: %s" % self.volume.id)
 
         self.volume_1 = Volume.create(
-                                   self.api_client,
+                                   self.apiclient,
                                    self.services,
                                    account=self.account.name,
                                    domainid=self.account.domainid

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/test/integration/smoke/test_vpc_vpn.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_vpc_vpn.py b/test/integration/smoke/test_vpc_vpn.py
index 0e94e25..03826e9 100644
--- a/test/integration/smoke/test_vpc_vpn.py
+++ b/test/integration/smoke/test_vpc_vpn.py
@@ -17,105 +17,29 @@
 """ Tests for VPN in VPC
 """
 #Import Local Modules
+from marvin.codes import FAILED
 from marvin.cloudstackTestCase import *
 from marvin.cloudstackAPI import *
-from marvin.integration.lib.utils import *
-from marvin.integration.lib.base import *
-from marvin.integration.lib.common import *
+from marvin.lib.utils import *
+from marvin.lib.base import *
+from marvin.lib.common import *
 from nose.plugins.attrib import attr
 
 import time
 
-class Services:
-    def __init__(self):
-        self.services = {
-            "account": {
-                "email": "test@test.com",
-                "firstname": "Test",
-                "lastname": "User",
-                "username": "test",
-                "password": "password",
-            },
-            "virtual_machine": {
-                "displayname": "Test VM",
-                "username": "root",
-                "password": "password",
-                "ssh_port": 22,
-                "hypervisor": 'XenServer',
-                "privateport": 22,
-                "publicport": 22,
-                "protocol": 'TCP',
-            },
-            "ostype": 'CentOS 5.3 (64-bit)',
-            "service_offering": {
-                "name": "Tiny Instance",
-                "displaytext": "Tiny Instance",
-                "cpunumber": 1,
-                "cpuspeed": 100,
-                "memory": 256,
-            },
-            "network_offering": {
-                "name": "Network offering for internal vpc",
-                "displaytext": "Network offering for internal vpc",
-                "guestiptype": "Isolated",
-                "traffictype": "Guest",
-                "supportedservices": "Vpn,Dhcp,Dns,Lb,UserData,SourceNat,StaticNat,PortForwarding,NetworkACL",
-                "serviceProviderList": {
-                    "Dhcp": "VpcVirtualRouter",
-                    "Dns": "VpcVirtualRouter",
-                    "Vpn": "VpcVirtualRouter",
-                    "UserData": "VpcVirtualRouter",
-                    "Lb": "InternalLbVM",
-                    "SourceNat": "VpcVirtualRouter",
-                    "StaticNat": "VpcVirtualRouter",
-                    "PortForwarding": "VpcVirtualRouter",
-                    "NetworkACL": "VpcVirtualRouter",
-                },
-                "serviceCapabilityList": {
-                    "SourceNat": {"SupportedSourceNatTypes": "peraccount"},
-                    "Lb": {"lbSchemes": "internal", "SupportedLbIsolation": "dedicated"}
-                }
-            },
-            "vpn_user": {
-                "username": "test",
-                "password": "password",
-            },
-            "vpc": {
-                "name": "vpc_vpn",
-                "displaytext": "vpc-vpn",
-                "cidr": "10.1.1.0/24"
-            },
-            "ntwk": {
-                "name": "tier1",
-                "displaytext": "vpc-tier1",
-                "gateway" : "10.1.1.1",
-                "netmask" : "255.255.255.192"
-            },
-            "vpc2": {
-                "name": "vpc2_vpn",
-                "displaytext": "vpc2-vpn",
-                "cidr": "10.2.1.0/24"
-            },
-            "ntwk2": {
-                "name": "tier2",
-                "displaytext": "vpc-tier2",
-                "gateway" : "10.2.1.1",
-                "netmask" : "255.255.255.192"
-            }
-        }
-
-
 class TestVpcRemoteAccessVpn(cloudstackTestCase):
 
     @classmethod
     def setUpClass(cls):
-        cls.apiclient = super(TestVpcRemoteAccessVpn, cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
-        cls.zone = get_zone(cls.apiclient, cls.services)
+        testClient = super(TestVpcRemoteAccessVpn, cls).getClsTestClient()
+        cls.apiclient = testClient.getApiClient()
+        cls.services = testClient.getParsedTestDataConfig()
+
+        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
         cls.domain = get_domain(cls.apiclient)
         cls.service_offering = ServiceOffering.create(
             cls.apiclient,
-            cls.services["service_offering"]
+            cls.services["service_offerings"]
         )
         cls.account = Account.create(cls.apiclient, services=cls.services["account"])
         cls.template = get_template(
@@ -123,6 +47,9 @@ class TestVpcRemoteAccessVpn(cloudstackTestCase):
             cls.zone.id,
             cls.services["ostype"]
         )
+        if cls.template == FAILED:
+            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
+
         cls.cleanup = [cls.account]
 
     @attr(tags=["advanced", "selfservice"])
@@ -211,13 +138,15 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
 
     @classmethod
     def setUpClass(cls):
-        cls.apiclient = super(TestVpcSite2SiteVpn, cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
-        cls.zone = get_zone(cls.apiclient, cls.services)
+        testClient = super(TestVpcSite2SiteVpn, cls).getClsTestClient()
+        cls.apiclient = testClient.getApiClient()
+        cls.services = testClient.getParsedTestDataConfig()
+
+        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
         cls.domain = get_domain(cls.apiclient)
         cls.service_offering = ServiceOffering.create(
             cls.apiclient,
-            cls.services["service_offering"]
+            cls.services["service_offerings"]
         )
         cls.account = Account.create(cls.apiclient, services=cls.services["account"])
         cls.template = get_template(
@@ -225,6 +154,9 @@ class TestVpcSite2SiteVpn(cloudstackTestCase):
             cls.zone.id,
             cls.services["ostype"]
         )
+        if cls.template == FAILED:
+            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
+
         cls.cleanup = [cls.account]
 
     @attr(tags=["advanced", "selfservice"])

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/tools/marvin/marvin/__init__.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/__init__.py b/tools/marvin/marvin/__init__.py
index 7af168e..7102e3f 100644
--- a/tools/marvin/marvin/__init__.py
+++ b/tools/marvin/marvin/__init__.py
@@ -15,4 +15,4 @@
 # specific language governing permissions and limitations
 # under the License.
 
-#Marvin - The cloudstack test client
+# Marvin - The cloudstack test client

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/tools/marvin/marvin/asyncJobMgr.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/asyncJobMgr.py b/tools/marvin/marvin/asyncJobMgr.py
index e24170e..00e8c19 100644
--- a/tools/marvin/marvin/asyncJobMgr.py
+++ b/tools/marvin/marvin/asyncJobMgr.py
@@ -16,7 +16,7 @@
 # under the License.
 
 import threading
-import cloudstackException
+from marvin import cloudstackException
 import time
 import Queue
 import copy
@@ -26,12 +26,14 @@ import datetime
 
 
 class job(object):
+
     def __init__(self):
         self.id = None
         self.cmd = None
 
 
 class jobStatus(object):
+
     def __init__(self):
         self.result = None
         self.status = None
@@ -47,6 +49,7 @@ class jobStatus(object):
 
 
 class workThread(threading.Thread):
+
     def __init__(self, in_queue, outqueue, apiClient, db=None, lock=None):
         threading.Thread.__init__(self)
         self.inqueue = in_queue
@@ -62,7 +65,7 @@ class workThread(threading.Thread):
         try:
             self.lock.acquire()
             result = self.connection.poll(job.jobId, job.responsecls).jobresult
-        except cloudstackException.cloudstackAPIException, e:
+        except cloudstackException.CloudstackAPIException as e:
             result = str(e)
         finally:
             self.lock.release()
@@ -102,7 +105,7 @@ class workThread(threading.Thread):
                     except:
                         pass
                     jobstatus.status = True
-        except cloudstackException.cloudstackAPIException, e:
+        except cloudstackException.CloudstackAPIException as e:
             jobstatus.result = str(e)
             jobstatus.status = False
         except:
@@ -129,6 +132,7 @@ class workThread(threading.Thread):
 
 
 class jobThread(threading.Thread):
+
     def __init__(self, inqueue, interval):
         threading.Thread.__init__(self)
         self.inqueue = inqueue
@@ -149,12 +153,14 @@ class jobThread(threading.Thread):
 
 
 class outputDict(object):
+
     def __init__(self):
         self.lock = threading.Condition()
         self.dict = {}
 
 
 class asyncJobMgr(object):
+
     def __init__(self, apiClient, db):
         self.inqueue = Queue.Queue()
         self.output = outputDict()

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/tools/marvin/marvin/cloudstackConnection.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py
index fb03e3b..d006002 100644
--- a/tools/marvin/marvin/cloudstackConnection.py
+++ b/tools/marvin/marvin/cloudstackConnection.py
@@ -21,21 +21,35 @@ import base64
 import hmac
 import hashlib
 import time
-import cloudstackException
 from cloudstackAPI import *
 import jsonHelper
+from marvin.codes import (
+    FAILED,
+    INVALID_RESPONSE,
+    INVALID_INPUT,
+    JOB_FAILED,
+    JOB_INPROGRESS,
+    JOB_CANCELLED,
+    JOB_SUCCEEDED
+)
 from requests import (
     ConnectionError,
     HTTPError,
     Timeout,
     RequestException
-    )
+)
+from marvin.cloudstackException import GetDetailExceptionInfo
 
 
-class cloudConnection(object):
+class CSConnection(object):
+
+    '''
+    @Desc: Connection Class to make API\Command calls to the
+           CloudStack Management Server
+           Sends the GET\POST requests to CS based upon the
+           information provided and retrieves the parsed response.
+    '''
 
-    """ Connections to make API calls to the cloudstack management server
-    """
     def __init__(self, mgmtDet, asyncTimeout=3600, logger=None,
                  path='client/api'):
         self.apiKey = mgmtDet.apiKey
@@ -44,68 +58,93 @@ class cloudConnection(object):
         self.port = mgmtDet.port
         self.user = mgmtDet.user
         self.passwd = mgmtDet.passwd
-        self.certCAPath = mgmtDet.certCAPath
-        self.certPath = mgmtDet.certPath
+        self.certPath = ()
+        if mgmtDet.certCAPath != "NA" and mgmtDet.certPath != "NA":
+            self.certPath = (mgmtDet.certCAPath, mgmtDet.certPath)
         self.logger = logger
         self.path = path
         self.retries = 5
+        self.__lastError = ''
         self.mgtDetails = mgmtDet
-        self.protocol = "http"
         self.asyncTimeout = asyncTimeout
         self.auth = True
         if self.port == 8096 or \
            (self.apiKey is None and self.securityKey is None):
             self.auth = False
-        if mgmtDet.useHttps == "True":
-            self.protocol = "https"
-        self.baseurl = "%s://%s:%d/%s"\
+        self.protocol = "https" if mgmtDet.useHttps == "True" else "http"
+        self.httpsFlag = True if self.protocol == "https" else False
+        self.baseUrl = "%s://%s:%d/%s"\
                        % (self.protocol, self.mgtSvr, self.port, self.path)
 
     def __copy__(self):
-        return cloudConnection(self.mgtDetails,
-                               self.asyncTimeout,
-                               self.logger,
-                               self.path)
-
-    def poll(self, jobid, response):
-        """
-        polls the completion of a given jobid
-        @param jobid:
-        @param response:
-        @return:
-        """
-        cmd = queryAsyncJobResult.queryAsyncJobResultCmd()
-        cmd.jobid = jobid
-        timeout = self.asyncTimeout
-
-        while timeout > 0:
-            asyncResonse = self.marvinRequest(cmd, response_type=response)
+        return CSConnection(self.mgtDetails,
+                            self.asyncTimeout,
+                            self.logger,
+                            self.path)
 
-            if asyncResonse.jobstatus == 2:
-                raise cloudstackException.cloudstackAPIException(
-                    "asyncquery", asyncResonse.jobresult)
-            elif asyncResonse.jobstatus == 1:
-                return asyncResonse
-
-            time.sleep(5)
-            if self.logger is not None:
-                self.logger.debug("job: %s still processing,"
-                                  "will timeout in %ds" % (jobid, timeout))
-            timeout = timeout - 5
+    def __poll(self, jobid, response_cmd):
+        '''
+        @Name : __poll
+        @Desc: polls for the completion of a given jobid
+        @Input 1. jobid: Monitor the Jobid for CS
+               2. response_cmd:response command for request cmd
+        @return: FAILED if jobid is cancelled,failed
+                 Else return async_response
+        '''
+        try:
+            cmd = queryAsyncJobResult.queryAsyncJobResultCmd()
+            cmd.jobid = jobid
+            timeout = self.asyncTimeout
+            start_time = time.time()
+            end_time = time.time()
+            async_response = FAILED
+            self.logger.debug("=== Jobid: %s Started ===" % (str(jobid)))
+            while timeout > 0:
+                async_response = self.\
+                    marvinRequest(cmd, response_type=response_cmd)
+                if async_response != FAILED:
+                    job_status = async_response.jobstatus
+                    if job_status in [JOB_FAILED,
+                                      JOB_CANCELLED,
+                                      JOB_SUCCEEDED]:
+                        break
+                time.sleep(5)
+                timeout -= 5
+                self.logger.debug("=== JobId:%s is Still Processing, "
+                                  "Will TimeOut in:%s ====" % (str(jobid),
+                                                               str(timeout)))
+            end_time = time.time()
+            tot_time = int(start_time - end_time)
+            self.logger.debug(
+                "===Jobid:%s ; StartTime:%s ; EndTime:%s ; "
+                "TotalTime:%s===" %
+                (str(jobid), str(time.ctime(start_time)),
+                 str(time.ctime(end_time)), str(tot_time)))
+            return async_response
+        except Exception as e:
+            self.__lastError = e
+            self.logger.exception("==== __poll: Exception Occurred :%s ====" %
+                                  str(self.__lastError))
+            return FAILED
 
-        raise cloudstackException.cloudstackAPIException(
-            "asyncquery", "Async job timeout %s" % jobid)
+    def getLastError(self):
+        '''
+        @Name : getLastError
+        @Desc : Returns the last error from marvinRequest
+        '''
+        return self.__lastError
 
-    def sign(self, payload):
+    def __sign(self, payload):
         """
-        signs a given request URL when the apiKey and secretKey are known
-
-        @param payload: dict of GET params to be signed
-        @return: the signature of the payload
+        @Name : __sign
+        @Desc:signs a given request URL when the apiKey and
+              secretKey are known
+        @Input: payload: dictionary of params be signed
+        @Output: the signature of the payload
         """
         params = zip(payload.keys(), payload.values())
         params.sort(key=lambda k: str.lower(k[0]))
-        hashStr = "&".join(
+        hash_str = "&".join(
             ["=".join(
                 [str.lower(r[0]),
                  str.lower(
@@ -114,168 +153,219 @@ class cloudConnection(object):
             ) for r in params]
         )
         signature = base64.encodestring(hmac.new(
-            self.securityKey, hashStr, hashlib.sha1).digest()).strip()
-        self.logger.debug("Computed Signature by Marvin: %s" % signature)
+            self.securityKey, hash_str, hashlib.sha1).digest()).strip()
         return signature
 
-    def request(self, command, auth=True, payload={}, method='GET'):
+    def __sendPostReqToCS(self, url, payload):
+        '''
+        @Name : __sendPostReqToCS
+        @Desc : Sends the POST Request to CS
+        @Input : url: URL to send post req
+                 payload:Payload information as part of request
+        @Output: Returns response from POST output
+                 else FAILED
+        '''
+        try:
+            response = requests.post(url,
+                                     params=payload,
+                                     cert=self.certPath,
+                                     verify=self.httpsFlag)
+            return response
+        except Exception as e:
+            self.__lastError = e
+            self.logger.\
+                exception("__sendPostReqToCS : Exception "
+                          "Occurred: %s" % str(self.__lastError))
+            return FAILED
+
+    def __sendGetReqToCS(self, url, payload):
+        '''
+        @Name : __sendGetReqToCS
+        @Desc : Sends the GET Request to CS
+        @Input : url: URL to send post req
+                 payload:Payload information as part of request
+        @Output: Returns response from GET output
+                 else FAILED
+        '''
+        try:
+            response = requests.get(url,
+                                    params=payload,
+                                    cert=self.certPath,
+                                    verify=self.httpsFlag)
+            return response
+        except Exception as e:
+            self.__lastError = e
+            self.logger.exception("__sendGetReqToCS : Exception Occurred: %s" %
+                                  str(self.__lastError))
+            return FAILED
+
+    def __sendCmdToCS(self, command, auth=True, payload={}, method='GET'):
         """
-        Makes requests using auth or over integration port
-        @param command: cloudstack API command name
+        @Name : __sendCmdToCS
+        @Desc : Makes requests to CS using the Inputs provided
+        @Input: command: cloudstack API command name
                     eg: deployVirtualMachineCommand
-        @param auth: Authentication (apikey,secretKey) => True
+                auth: Authentication (apikey,secretKey) => True
                      else False for integration.api.port
-        @param payload: request data composed as a dictionary
-        @param method: GET/POST via HTTP
-        @return:
+                payload: request data composed as a dictionary
+                method: GET/POST via HTTP
+        @output: FAILED or else response from CS
         """
-        payload["command"] = command
-        payload["response"] = "json"
-
-        if auth:
-            payload["apiKey"] = self.apiKey
-            signature = self.sign(payload)
-            payload["signature"] = signature
-
         try:
-            #https_flag : Signifies whether to verify connection over \
-            #http or https, \
-            #initialized to False, will be set to true if user provided https
-            #connection
-            https_flag = False
-            cert_path = ()
-            if self.protocol == "https":
-                https_flag = True
-                if self.certCAPath != "NA" and self.certPath != "NA":
-                    cert_path = (self.certCAPath, self.certPath)
+            payload["command"] = command
+            payload["response"] = "json"
 
-            #Verify whether protocol is "http", then call the request over http
-            if self.protocol == "http":
+            if auth:
+                payload["apiKey"] = self.apiKey
+                payload["signature"] = self.__sign(payload)
+
+            # Verify whether protocol is "http" or "https", then send the
+            # request
+            if self.protocol in ["http", "https"]:
+                self.logger.debug("Payload: %s" % str(payload))
                 if method == 'POST':
-                    response = requests.post(self.baseurl, params=payload,
-                                             verify=https_flag)
-                else:
-                    response = requests.get(self.baseurl, params=payload,
-                                            verify=https_flag)
+                    self.logger.debug("=======Sending POST Cmd : %s======="
+                                      % str(command))
+                    return self.__sendPostReqToCS(self.baseUrl, payload)
+                if method == "GET":
+                    self.logger.debug("========Sending GET Cmd : %s======="
+                                      % str(command))
+                    return self.__sendGetReqToCS(self.baseUrl, payload)
             else:
-                '''
-                If protocol is https, then create the  connection url with \
-                user provided certificates \
-                provided as part of cert
-                '''
-                try:
-                    if method == 'POST':
-                        response = requests.post(self.baseurl,
-                                                 params=payload,
-                                                 cert=cert_path,
-                                                 verify=https_flag)
-                    else:
-                        response = requests.get(self.baseurl, params=payload,
-                                                cert=cert_path,
-                                                verify=https_flag)
-                except Exception, e:
-                    '''
-                    If an exception occurs with user provided CA certs, \
-                    then try with default certs, \
-                    we dont need to mention here the cert path
-                    '''
-                    self.logger.debug("Creating CS connection over https \
-                                        didnt worked with user provided certs \
-                                            , so trying with no certs %s" % e)
-                    if method == 'POST':
-                        response = requests.post(self.baseurl,
-                                                 params=payload,
-                                                 verify=https_flag)
-                    else:
-                        response = requests.get(self.baseurl,
-                                                params=payload,
-                                                verify=https_flag)
-        except ConnectionError, c:
-            self.logger.debug("Connection refused. Reason: %s : %s" %
-                              (self.baseurl, c))
-            raise c
-        except HTTPError, h:
-            self.logger.debug("Http Error.Server returned error code: %s" % h)
-            raise h
-        except Timeout, t:
-            self.logger.debug("Connection timed out with %s" % t)
-            raise t
-        except RequestException, r:
-            self.logger.debug("RequestException from server %s" % r)
-            raise r
-        except Exception, e:
-            self.logger.debug("Error returned by server %s" % r)
-            raise e
-        else:
-            return response
+                self.logger.exception("__sendCmdToCS: Invalid Protocol")
+                return FAILED
+        except Exception as e:
+            self.logger.exception("__sendCmdToCS: Exception:%s" %
+                                  GetDetailExceptionInfo(e))
+            return FAILED
 
-    def sanitizeCommand(self, cmd):
+    def __sanitizeCmd(self, cmd):
         """
-        Removes None values, Validates all required params are present
-        @param cmd: Cmd object eg: createPhysicalNetwork
-        @return:
+        @Name : __sanitizeCmd
+        @Desc : Removes None values, Validates all required params are present
+        @Input: cmd: Cmd object eg: createPhysicalNetwork
+        @Output: Returns command name, asynchronous or not,request payload
+                 FAILED for failed cases
         """
-        requests = {}
-        required = []
-        for attribute in dir(cmd):
-            if not attribute.startswith('__'):
-                if attribute == "isAsync":
-                    isAsync = getattr(cmd, attribute)
-                elif attribute == "required":
-                    required = getattr(cmd, attribute)
-                else:
-                    requests[attribute] = getattr(cmd, attribute)
-
-        cmdname = cmd.__class__.__name__.replace("Cmd", "")
-        for requiredPara in required:
-            if requests[requiredPara] is None:
-                raise cloudstackException.cloudstackAPIException(
-                    cmdname, "%s is required" % requiredPara)
-        for param, value in requests.items():
-            if value is None:
-                requests.pop(param)
-            elif isinstance(value, list):
-                if len(value) == 0:
-                    requests.pop(param)
-                else:
-                    if not isinstance(value[0], dict):
-                        requests[param] = ",".join(value)
+        try:
+            cmd_name = ''
+            payload = {}
+            required = []
+            isAsync = "false"
+            for attribute in dir(cmd):
+                if not attribute.startswith('__'):
+                    if attribute == "isAsync":
+                        isAsync = getattr(cmd, attribute)
+                    elif attribute == "required":
+                        required = getattr(cmd, attribute)
                     else:
-                        requests.pop(param)
-                        i = 0
-                        for val in value:
-                            for k, v in val.iteritems():
-                                requests["%s[%d].%s" % (param, i, k)] = v
-                            i = i + 1
-        return cmdname.strip(), isAsync, requests
+                        payload[attribute] = getattr(cmd, attribute)
+            cmd_name = cmd.__class__.__name__.replace("Cmd", "")
+            for required_param in required:
+                if payload[required_param] is None:
+                    self.logger.debug("CmdName: %s Parameter : %s is Required"
+                                      % (cmd_name, required_param))
+                    return FAILED
+            for param, value in payload.items():
+                if value is None:
+                    payload.pop(param)
+                elif isinstance(value, list):
+                    if len(value) == 0:
+                        payload.pop(param)
+                    else:
+                        if not isinstance(value[0], dict):
+                            payload[param] = ",".join(value)
+                        else:
+                            payload.pop(param)
+                            i = 0
+                            for val in value:
+                                for k, v in val.iteritems():
+                                    payload["%s[%d].%s" % (param, i, k)] = v
+                                i += 1
+            return cmd_name.strip(), isAsync, payload
+        except Exception as e:
+            self.logger.\
+                exception("__sanitizeCmd: CmdName : "
+                          "%s : Exception:%s" % (cmd_name,
+                                                 GetDetailExceptionInfo(e)))
+            return FAILED
+
+    def __parseAndGetResponse(self, cmd_response, response_cls, is_async):
+        '''
+        @Name : __parseAndGetResponse
+        @Desc : Verifies the  Response(from CS) and returns an
+                appropriate json parsed Response
+        @Input: cmd_response: Command Response from cs
+                response_cls : Mapping class for this Response
+                is_async: Whether the cmd is async or not.
+        @Output:Response output from CS
+        '''
+        try:
+            ret = jsonHelper.getResultObj(cmd_response.json(), response_cls)
+        except TypeError:
+            ret = jsonHelper.getResultObj(cmd_response.json, response_cls)
+
+        '''
+        If the response is asynchronous, poll and return response
+        else return response as it is
+        '''
+        if is_async == "false":
+            self.logger.debug("Response : %s" % str(ret))
+            return ret
+        else:
+            response = self.__poll(ret.jobid, response_cls)
+            self.logger.debug("Response : %s" % str(response))
+            return response.jobresult if response != FAILED else FAILED
 
     def marvinRequest(self, cmd, response_type=None, method='GET', data=''):
         """
-        Requester for marvin command objects
-        @param cmd: marvin's command from cloudstackAPI
-        @param response_type: response type of the command in cmd
-        @param method: HTTP GET/POST, defaults to GET
-        @return:
+        @Name : marvinRequest
+        @Desc: Handles Marvin Requests
+        @Input  cmd: marvin's command from cloudstackAPI
+                response_type: response type of the command in cmd
+                method: HTTP GET/POST, defaults to GET
+        @Output: Response received from CS
+                 FAILED In case of Error\Exception
         """
-        cmdname, isAsync, payload = self.sanitizeCommand(cmd)
-        self.logger.debug("sending %s request: %s %s" % (method, cmdname,
-                                                         str(payload)))
-        response = self.request(cmdname,
-                                self.auth,
-                                payload=payload,
-                                method=method)
-        if response is None:
-            return None
-        self.logger.debug("Request: %s Response: %s" % (response.url,
-                                                        response.text))
         try:
-            response = jsonHelper.getResultObj(response.json(), response_type)
-        except TypeError:
-            response = jsonHelper.getResultObj(response.json, response_type)
+            '''
+            1. Verify the Inputs Provided
+            '''
+            if (cmd is None or cmd == '')or \
+                    (response_type is None or response_type == ''):
+                self.logger.exception("marvinRequest : Invalid Command Input")
+                return FAILED
 
-        if isAsync == "false":
-            return response
-        else:
-            asyncJobId = response.jobid
-            response = self.poll(asyncJobId, response_type)
-            return response.jobresult
+            '''
+            2. Sanitize the Command
+            '''
+            sanitize_cmd_out = self.__sanitizeCmd(cmd)
+
+            if sanitize_cmd_out == FAILED:
+                return FAILED
+
+            cmd_name, is_async, payload = sanitize_cmd_out
+            '''
+            3. Send Command to CS
+            '''
+            cmd_response = self.__sendCmdToCS(cmd_name,
+                                              self.auth,
+                                              payload=payload,
+                                              method=method)
+            if cmd_response == FAILED:
+                raise self.__lastError
+
+            '''
+            4. Check if the Command Response received above is valid or Not.
+               If not return Invalid Response
+            '''
+            ret = self.__parseAndGetResponse(cmd_response,
+                                             response_type,
+                                             is_async)
+            if ret == FAILED:
+                raise self.__lastError
+            return ret
+        except Exception as e:
+            self.logger.exception("marvinRequest : CmdName: %s Exception: %s" %
+                                  (str(cmd), GetDetailExceptionInfo(e)))
+            return FAILED

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/tools/marvin/marvin/cloudstackException.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackException.py b/tools/marvin/marvin/cloudstackException.py
index 6200003..c2eb57a 100644
--- a/tools/marvin/marvin/cloudstackException.py
+++ b/tools/marvin/marvin/cloudstackException.py
@@ -15,8 +15,13 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import sys
+import traceback
+from marvin.codes import (INVALID_INPUT, EXCEPTION_OCCURRED)
+
+
+class CloudstackAPIException(Exception):
 
-class cloudstackAPIException(Exception):
     def __init__(self, cmd="", result=""):
         self.errorMsg = "Execute cmd: %s failed, due to: %s" % (cmd, result)
 
@@ -25,6 +30,7 @@ class cloudstackAPIException(Exception):
 
 
 class InvalidParameterException(Exception):
+
     def __init__(self, msg=''):
         self.errorMsg = msg
 
@@ -33,6 +39,7 @@ class InvalidParameterException(Exception):
 
 
 class dbException(Exception):
+
     def __init__(self, msg=''):
         self.errorMsg = msg
 
@@ -41,8 +48,18 @@ class dbException(Exception):
 
 
 class internalError(Exception):
+
     def __init__(self, msg=''):
         self.errorMsg = msg
 
     def __str__(self):
         return self.errorMsg
+
+
+def GetDetailExceptionInfo(e):
+    if e is not None:
+        exc_type, exc_value, exc_traceback = sys.exc_info()
+        return str(repr(traceback.format_exception(
+            exc_type, exc_value, exc_traceback)))
+    else:
+        return EXCEPTION_OCCURRED

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/404ac549/tools/marvin/marvin/cloudstackTestCase.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py
index 6456bb1..5cb4a10 100644
--- a/tools/marvin/marvin/cloudstackTestCase.py
+++ b/tools/marvin/marvin/cloudstackTestCase.py
@@ -16,7 +16,7 @@
 # under the License.
 
 import unittest
-from marvin.integration.lib.utils import verifyElementInList
+from marvin.lib.utils import verifyElementInList
 from marvin.codes import PASS
 
 
@@ -37,7 +37,7 @@ def user(Name, DomainName, AcctType):
 class cloudstackTestCase(unittest.case.TestCase):
     clstestclient = None
 
-    def assertElementInList(inp, toverify, responsevar=None,  pos=0,
+    def assertElementInList(inp, toverify, responsevar=None, pos=0,
                             assertmsg="TC Failed for reason"):
         '''
         @Name: assertElementInList
@@ -46,7 +46,7 @@ class cloudstackTestCase(unittest.case.TestCase):
         Takes one additional argument of what message to assert with
         when failed
         '''
-        out = verifyElementInList(inp, toverify, responsevar,  pos)
+        out = verifyElementInList(inp, toverify, responsevar, pos)
         unittest.TestCase.assertEquals(out[0], PASS, "msg:%s" % out[1])
 
     @classmethod


Mime
View raw message