cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject [1/2] git commit: updated refs/heads/http_post to 9adbb62
Date Wed, 24 Apr 2013 08:12:10 GMT
Updated Branches:
  refs/heads/http_post c983174bc -> 9adbb622f


Additional test for sending userdata through GET

Userdata tests - send >2k data via GET and POST. Changes to
marvin_request to accomadate POST requests.

Signed-off-by: Prasanna Santhanam <tsp@apache.org>


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

Branch: refs/heads/http_post
Commit: 9b89a58bb48f8dfc690f1d1310fa9e79ffb5fad7
Parents: c983174
Author: Prasanna Santhanam <tsp@apache.org>
Authored: Wed Apr 24 13:36:27 2013 +0530
Committer: Prasanna Santhanam <tsp@apache.org>
Committed: Wed Apr 24 13:37:20 2013 +0530

----------------------------------------------------------------------
 .../component/test_deploy_vm_with_userdata.py      |   97 -----------
 .../smoke/test_deploy_vm_with_userdata.py          |  129 +++++++++++++++
 tools/marvin/marvin/cloudstackConnection.py        |   34 ++---
 tools/marvin/marvin/codegenerator.py               |    4 +-
 tools/marvin/marvin/integration/lib/base.py        |   11 +-
 5 files changed, 148 insertions(+), 127 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9b89a58b/test/integration/component/test_deploy_vm_with_userdata.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_deploy_vm_with_userdata.py b/test/integration/component/test_deploy_vm_with_userdata.py
deleted file mode 100644
index 66afe2a..0000000
--- a/test/integration/component/test_deploy_vm_with_userdata.py
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/env python
-
-from marvin.cloudstackTestCase import cloudstackTestCase
-from marvin.integration.lib.base import *
-from marvin.integration.lib.common import get_template, get_zone, list_virtual_machines,
cleanup_resources
-
-import random
-import string
-
-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,
-            },
-        }
-
-
-class TestDeployVmWithUserData(cloudstackTestCase):
-    """Test Deploy VM with UserData > 2k
-    """
-    def setUp(self):
-        self.apiClient = self.testClient.getApiClient()
-        self.services = Services().services
-        self.service_offering = ServiceOffering.create(
-            self.apiClient,
-            self.services["service_offering"]
-        )
-        self.account = Account.create(self.apiClient, services=self.services["account"])
-        self.zone = get_zone(self.apiClient, self.services)
-        self.template = get_template(
-            self.apiClient,
-            self.zone.id,
-            self.services["ostype"]
-        )
-        self.debug("Successfully created account: %s, id: \
-                   %s" % (self.account.name,\
-                          self.account.id))
-        self.cleanup = [self.account]
-
-        # Generate userdata of 2500 bytes. This is larger than the 2048 bytes limit.
-        # CS however allows for upto 4K bytes in the code. So this must succeed.
-        # Overall, the query length must not exceed 4K, for then the json decoder
-        # will fail this operation at the marvin client side itself.
-        user_data = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in
range(2500))
-        self.services["virtual_machine"]["userdata"] = user_data
-
-    def test_deployvm_userdata(self):
-        # Userdata is passed in the virtual_machine dictionary.
-        VirtualMachine.create(self.apiClient, self.services["virtual_machine"], method='POST')
-        deployVmResponse = VirtualMachine.create(
-            self.apiClient,
-            self.virtual_machine,
-            accountid=self.account.name,
-            domainid=self.account.domainid,
-            serviceofferingid=self.service_offering.id,
-            templateid=self.template.id,
-            zoneid=self.zone.id
-        )
-        vms = list_virtual_machines(
-            self.apiClient,
-            account=self.account.name,
-            domainid=self.account.domainid
-        )
-        self.assert_(len(vms) > 0, "There are no Vms deployed in the account %s" % self.account.name)
-        vm = vms[0].id
-        self.assertEqual(vm.id, deployVmResponse.id, "Vm deployed is different from the test")
-        self.assertEqual(vm.state, "Running", "VM is not in Running state")
-
-    def tearDown(self):
-        try:
-            #Cleanup resources used
-            cleanup_resources(self.apiClient, self.cleanup)
-        except Exception as e:
-            raise Exception("Warning: Exception during cleanup : %s" % e)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9b89a58b/test/integration/smoke/test_deploy_vm_with_userdata.py
----------------------------------------------------------------------
diff --git a/test/integration/smoke/test_deploy_vm_with_userdata.py b/test/integration/smoke/test_deploy_vm_with_userdata.py
new file mode 100644
index 0000000..c6e23bb
--- /dev/null
+++ b/test/integration/smoke/test_deploy_vm_with_userdata.py
@@ -0,0 +1,129 @@
+#!/usr/bin/env python
+
+from marvin.cloudstackTestCase import cloudstackTestCase
+from marvin.integration.lib.base import *
+from marvin.integration.lib.common import get_template, get_zone, list_virtual_machines,
cleanup_resources
+from nose.plugins.attrib import attr
+
+import random
+import string
+
+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,
+            },
+        }
+
+
+class TestDeployVmWithUserData(cloudstackTestCase):
+    """Tests for UserData
+    """
+
+    @classmethod
+    def setUpClass(cls):
+        cls.apiClient = super(TestDeployVmWithUserData, cls).getClsTestClient().getApiClient()
+        cls.services = Services().services
+        cls.zone = get_zone(cls.apiClient, cls.services)
+        if cls.zone.localstorageenabled:
+            #For devcloud since localstroage is enabled
+            cls.services["service_offering"]["storagetype"] = "local"
+        cls.service_offering = ServiceOffering.create(
+            cls.apiClient,
+            cls.services["service_offering"]
+        )
+        cls.account = Account.create(cls.apiClient, services=cls.services["account"])
+        cls.template = get_template(
+            cls.apiClient,
+            cls.zone.id,
+            cls.services["ostype"]
+        )
+        cls.debug("Successfully created account: %s, id: \
+                   %s" % (cls.account.name,\
+                          cls.account.id))
+        cls.cleanup = [cls.account]
+
+        # Generate userdata of 2500 bytes. This is larger than the 2048 bytes limit.
+        # CS however allows for upto 4K bytes in the code. So this must succeed.
+        # Overall, the query length must not exceed 4K, for then the json decoder
+        # will fail this operation at the marvin client side itcls.
+        user_data = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in
range(2500))
+        cls.services["virtual_machine"]["userdata"] = user_data
+
+    @attr(tags=["simulator", "devcloud", "basic", "advanced"])
+    def test_deployvm_userdata_post(self):
+        """Test userdata as POST, size > 2k
+        """
+        deployVmResponse = VirtualMachine.create(
+            self.apiClient,
+            services=self.services["virtual_machine"],
+            accountid=self.account.name,
+            domainid=self.account.domainid,
+            serviceofferingid=self.service_offering.id,
+            templateid=self.template.id,
+            zoneid=self.zone.id,
+            method='POST'
+        )
+        vms = list_virtual_machines(
+            self.apiClient,
+            account=self.account.name,
+            domainid=self.account.domainid
+        )
+        self.assert_(len(vms) > 0, "There are no Vms deployed in the account %s" % self.account.name)
+        vm = vms[0]
+        self.assert_(vm.id == str(deployVmResponse.id), "Vm deployed is different from the
test")
+        self.assert_(vm.state == "Running", "VM is not in Running state")
+
+    @attr(tags=["simulator", "devcloud", "basic", "advanced"])
+    def test_deployvm_userdata(self):
+        """Test userdata as GET, size > 2k
+        """
+        deployVmResponse = VirtualMachine.create(
+            self.apiClient,
+            services=self.services["virtual_machine"],
+            accountid=self.account.name,
+            domainid=self.account.domainid,
+            serviceofferingid=self.service_offering.id,
+            templateid=self.template.id,
+            zoneid=self.zone.id
+        )
+        vms = list_virtual_machines(
+            self.apiClient,
+            account=self.account.name,
+            domainid=self.account.domainid
+        )
+        self.assert_(len(vms) > 0, "There are no Vms deployed in the account %s" % self.account.name)
+        vm = vms[0]
+        self.assert_(vm.id == str(deployVmResponse.id), "Vm deployed is different from the
test")
+        self.assert_(vm.state == "Running", "VM is not in Running state")
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            #Cleanup resources used
+            cleanup_resources(cls.apiClient, cls.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9b89a58b/tools/marvin/marvin/cloudstackConnection.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py
index 70d6a43..5d30803 100644
--- a/tools/marvin/marvin/cloudstackConnection.py
+++ b/tools/marvin/marvin/cloudstackConnection.py
@@ -110,16 +110,15 @@ class cloudConnection(object):
         self.logging.info("Computed Signature by Marvin: %s" % signature)
         return signature
 
-    def request(self, command, auth=True, payload={}, data={}):
+    def request(self, command, auth=True, payload={}, method='GET'):
         """
         Makes requests using auth or over integration port
         @param command: cloudstack API command name
                     eg: deployVirtualMachineCommand
         @param auth: Authentication (apikey,secretKey) => True
                      else False for integration.api.port
-        @param payload: GET param data composed as a dictionary
-                        of key,value pairs
-        @param data: POST data as a dictionary
+        @param payload: request data composed as a dictionary
+        @param method: GET/POST via HTTP
         @return:
         """
         payload["command"] = command
@@ -131,9 +130,8 @@ class cloudConnection(object):
             payload["signature"] = signature
 
         try:
-            if data:
-                response = requests.post(self.baseurl, params=payload,
-                                        data=data)
+            if method == 'POST':
+                response = requests.post(self.baseurl, params=payload)
             else:
                 response = requests.get(self.baseurl, params=payload)
         except ConnectionError, c:
@@ -161,7 +159,7 @@ class cloudConnection(object):
         requests = {}
         required = []
         for attribute in dir(cmd):
-            if attribute != "__doc__" and attribute != "__init__" and \
+            if attribute != "__doc__" and attribute != "__init__" and\
                attribute != "__module__":
                 if attribute == "isAsync":
                     isAsync = getattr(cmd, attribute)
@@ -193,26 +191,20 @@ class cloudConnection(object):
                             i = i + 1
         return cmdname, isAsync, requests
 
-    def marvin_request(self, cmd, data={}, response_type=None):
+    def marvin_request(self, cmd, response_type=None, method='GET'):
         """
         Requester for marvin command objects
         @param cmd: marvin's command from cloudstackAPI
-        @param data: any data to be sent in as POST
         @param response_type: response type of the command in cmd
-        @param raw:
+        @param method: HTTP GET/POST, defaults to GET
         @return:
         """
         cmdname, isAsync, payload = self.sanitize_command(cmd)
-        self.logging.info("sending command: %s %s" % (cmdname, str(payload)))
-        if self.auth:
-            response = self.request(
-                cmdname, auth=True, payload=payload, data=data)
-        else:
-            response = self.request(
-                cmdname, auth=False, payload=payload, data=data)
-
-        self.logging.info("Request: %s Response: %s" %
-                          (response.url, response.text))
+        self.logging.debug("sending %s request: %s %s" % (method, cmdname, str(payload)))
+        response = self.request(
+            cmdname, self.auth, payload=payload, method=method)
+        self.logging.debug("Request: %s Response: %s" %
+                           (response.url, response.text))
         response = jsonHelper.getResultObj(response.json(), response_type)
 
         if isAsync == "false":

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9b89a58b/tools/marvin/marvin/codegenerator.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/codegenerator.py b/tools/marvin/marvin/codegenerator.py
index b3b2a86..36ba180 100644
--- a/tools/marvin/marvin/codegenerator.py
+++ b/tools/marvin/marvin/codegenerator.py
@@ -184,9 +184,9 @@ class codeGenerator:
         body += "\n"
 
         for cmdName in self.cmdsName:
-            body += self.space + 'def %s(self, command, postdata={}):\n'%cmdName
+            body += self.space + 'def %s(self, command, method="GET"):\n'%cmdName
             body += self.space + self.space + 'response = %sResponse()\n'%cmdName
-            body += self.space + self.space + 'response = self.connection.marvin_request(command,
data=postdata, response_type=response)\n'
+            body += self.space + self.space + 'response = self.connection.marvin_request(command,
response_type=response, method=method)\n'
             body += self.space + self.space + 'return response\n'
             body += '\n'
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9b89a58b/tools/marvin/marvin/integration/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py
index b0ec88b..6c28523 100755
--- a/tools/marvin/marvin/integration/lib/base.py
+++ b/tools/marvin/marvin/integration/lib/base.py
@@ -102,7 +102,7 @@ class Account:
     def delete(self, apiclient):
         """Delete an account"""
         cmd = deleteAccount.deleteAccountCmd()
-        cmd.id = self.account.id
+        cmd.id = self.id
         apiclient.deleteAccount(cmd)
 
     @classmethod
@@ -278,12 +278,9 @@ class VirtualMachine:
             cmd.hostid = hostid
 
         if "userdata" in services:
-            if method == 'POST':
-                postdata = base64.b64encode(services["userdata"])
-                virtual_machine = apiclient.deployVirtualMachine(cmd, postdata = {'userdata'
: postdata})
-            else:
-                cmd.userdata = base64.b64encode(services["userdata"])
-        virtual_machine = apiclient.deployVirtualMachine(cmd)
+            cmd.userdata = base64.b64encode(services["userdata"])
+
+        virtual_machine = apiclient.deployVirtualMachine(cmd, method=method)
 
         # VM should be in Running state after deploy
         timeout = 10


Mime
View raw message