Updated Branches: refs/heads/http_post 495a72928 -> c983174bc
Fix Vijay's test to use the marvin integratin libararies Allow VirtualMachine object to take in POST headers for userdata. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c983174b Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c983174b Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c983174b Branch: refs/heads/http_post Commit: c983174bc9751a23fdb5717cec80830774e3dc14 Parents: 495a729 Author: Prasanna Santhanam <[email protected]> Authored: Wed Apr 24 00:06:44 2013 +0530 Committer: Prasanna Santhanam <[email protected]> Committed: Wed Apr 24 00:06:44 2013 +0530 ---------------------------------------------------------------------- .../component/test_deploy_vm_with_userdata.py | 163 +++++++-------- tools/marvin/marvin/cloudstackConnection.py | 2 +- tools/marvin/marvin/integration/lib/base.py | 10 +- 3 files changed, 83 insertions(+), 92 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c983174b/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 index d9808a9..66afe2a 100644 --- a/test/integration/component/test_deploy_vm_with_userdata.py +++ b/test/integration/component/test_deploy_vm_with_userdata.py @@ -1,110 +1,97 @@ #!/usr/bin/env python -import marvin -from marvin import cloudstackTestCase -from marvin.cloudstackTestCase import * +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 unittest -import hashlib import random -import os import string +class Services: + def __init__(self): + self.services = { + "account": { + "email": "[email protected]", + "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): - """ - This test deploys a virtual machine into a user account - using the small service offering and builtin template + """Test Deploy VM with UserData > 2k """ def setUp(self): - password = "password" - - self.apiClient = self.testClient.getApiClient() #Get ourselves an API client - - self.acct = createAccount.createAccountCmd() #The createAccount command - self.acct.accounttype = 0 #We need a regular user. admins have accounttype=1 - self.acct.firstname = 'firstname' - self.acct.lastname = 'lastname' - self.acct.password = password - self.acct.username = 'user1' - self.acct.email = '[email protected]' - self.acct.account = 'user1' - self.acct.domainid = 1 #The default ROOT domain - self.acctResponse = self.apiClient.createAccount(self.acct) - - self.debug("Successfully created account: %s, user: %s, id: \ - %s"%(self.acctResponse.account.account, \ - self.acctResponse.account.username, \ - self.acctResponse.account.id)) + 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 - self.virtual_machine = { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'VMware', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - } - #self.virtual_machine["userdata"] = base64.b64encode(user_data) - self.virtual_machine["userdata"] = user_data - - def test_DeployVm(self): - """ - Let's start by defining the attributes of our VM that we will be - deploying on CloudStack. We will be assuming a single zone is available - and is configured and all templates are Ready - """ - deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() - deployVmCmd.zoneid = 1 - deployVmCmd.account = self.acct.account - deployVmCmd.domainid = self.acct.domainid - deployVmCmd.templateid = 7 - deployVmCmd.serviceofferingid = 1 - + 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.acct.account, - domainid=self.acct.domainid, - serviceofferingid=deployVmCmd.serviceofferingid, - templateid=deployVmCmd.templateid, - zoneid=deployVmCmd.zoneid + 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 ) - - # At this point our VM is expected to be Running. Let's find out what - # listVirtualMachines tells us about VMs in this account - - listVmCmd = listVirtualMachines.listVirtualMachinesCmd() - listVmCmd.id = deployVmResponse.id - listVmResponse = self.apiClient.listVirtualMachines(listVmCmd) - - self.assertNotEqual(len(listVmResponse), 0, "Check if the list API \ - returns a non-empty response") - - vm = listVmResponse[0] - - self.assertEqual(vm.id, deployVmResponse.id, "Check if the VM returned \ - is the same as the one we deployed") - - - self.assertEqual(vm.state, "Running", "Check if VM has reached \ - a state of running") + 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): - """ - Delete the account created. This will clear the VM belonging to that account as well. - """ - deleteAcct = deleteAccount.deleteAccountCmd() - deleteAcct.id = self.acctResponse.account.id - self.apiClient.deleteAccount(deleteAcct) - - + 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/c983174b/tools/marvin/marvin/cloudstackConnection.py ---------------------------------------------------------------------- diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py index 214a878..70d6a43 100644 --- a/tools/marvin/marvin/cloudstackConnection.py +++ b/tools/marvin/marvin/cloudstackConnection.py @@ -132,7 +132,7 @@ class cloudConnection(object): try: if data: - response = requests.get(self.baseurl, params=payload, + response = requests.post(self.baseurl, params=payload, data=data) else: response = requests.get(self.baseurl, params=payload) http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c983174b/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 92cdf81..b0ec88b 100755 --- a/tools/marvin/marvin/integration/lib/base.py +++ b/tools/marvin/marvin/integration/lib/base.py @@ -220,7 +220,7 @@ class VirtualMachine: def create(cls, apiclient, services, templateid=None, accountid=None, domainid=None, zoneid=None, networkids=None, serviceofferingid=None, securitygroupids=None, projectid=None, startvm=None, - diskofferingid=None, affinitygroupnames=None, hostid=None, mode='basic'): + diskofferingid=None, affinitygroupnames=None, hostid=None, mode='basic', method='GET'): """Create the instance""" cmd = deployVirtualMachine.deployVirtualMachineCmd() @@ -262,8 +262,6 @@ class VirtualMachine: if securitygroupids: cmd.securitygroupids = [str(sg_id) for sg_id in securitygroupids] - if "userdata" in services: - cmd.userdata = base64.b64encode(services["userdata"]) if "affinitygroupnames" in services: cmd.affinitygroupnames = services["affinitygroupnames"] @@ -279,6 +277,12 @@ class VirtualMachine: if hostid: 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) # VM should be in Running state after deploy
