From 2f12de8e3536a28fd7c1888e22cbc0c5e9add972 Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Mon, 12 Sep 2011 17:05:03 +0530 Subject: [PATCH] * Ordering the test cases as they are interdependent right now. * Enabling security groups for zucchini zones * Timing listVM with timeit --- agent-simulator/scripts/zucchini/setup.py | 17 +- .../scripts/zucchini/tests/testListVm.py | 21 +-- .../scripts/zucchini/tests/testProvision.py | 150 +++++++++++------- 3 files changed, 116 insertions(+), 72 deletions(-) diff --git a/agent-simulator/scripts/zucchini/setup.py b/agent-simulator/scripts/zucchini/setup.py index 65d48cec39e..98217ddb44f 100644 --- a/agent-simulator/scripts/zucchini/setup.py +++ b/agent-simulator/scripts/zucchini/setup.py @@ -95,7 +95,7 @@ def vlanIpRangeGenerator(): yield ('172.'+str(x)+'.'+str(y)+'.129', '172.'+str(x)+'.'+str(y)+'.190', '172.'+str(x)+'.'+str(y)+'.249') -def describeZucchiniResources(numberOfAgents=1300, dbnode='localhost', mshost='localhost', randomize=False): +def describeZucchiniResources(numberOfAgents=1300, dbnode='localhost', mshost='localhost', randomize=False, sgenabled=False): zs=cloudstackConfiguration() numberofpods=numberOfAgents/10 tagOneHosts = numberOfAgents*5/13 @@ -112,12 +112,13 @@ def describeZucchiniResources(numberOfAgents=1300, dbnode='localhost', mshost='l z.internaldns2 = '192.168.110.254' z.name = 'Zucchini' z.networktype = 'Basic' + z.securitygroupenabled = sgenabled hosttags=['TAG1' for x in range(tagOneHosts)] + ['TAG2' for x in range(tagTwoHosts)] + ['TAG3' for x in range(tagThreeHosts)] + curhost=0 + curpod=0 if randomize: random.shuffle(hosttags) #randomize the host distribution - curhost=0 - curpod=0 for podRange,vlanRange in zip(podIpRangeGenerator(), vlanIpRangeGenerator()): p = pod() @@ -193,16 +194,16 @@ if __name__=="__main__": # parser.add_option('-h','--host',dest='host',help='location of management server(s) or load-balancer') parser.add_option('-n', '--number-of-agents', action='store', dest='agents', help='number of agents in the deployment') parser.add_option('-g', '--enable-security-groups', dest='sgenabled', help='specify if security groups are to be enabled', default=False, action='store_true') - parser.add_option('-o', '--output', action='store', default='./zucchiniCfg', dest='output', help='the path where the json config file generated') + parser.add_option('-o', '--output', action='store', default='./z.cfg', dest='output', help='the path where the json config file generated') parser.add_option('-d', '--dbnode', dest='dbnode', help='hostname/ip of the database node', action='store') parser.add_option('-m', '--mshost', dest='mshost', help='hostname/ip of management server', action='store') parser.add_option('-r', '--randomize', dest='randomize', help='randomize the distribution of tags (hetergenous clusters)', action='store_true', default=False) (opts, args) = parser.parse_args() - mandatories = ['mshost', 'dbnode', 'agents'] + mandatories = ['agents'] for m in mandatories: if not opts.__dict__[m]: - print "mandatory option missing" + print 'mandatory option missing' - cfg = describeZucchiniResources(int(opts.agents), opts.dbnode, opts.mshost, opts.randomize) - generate_setup_config(cfg, opts.output) + cfg = describeZucchiniResources(int(opts.agents), opts.dbnode, opts.mshost, opts.randomize, opts.sgenabled) + generate_setup_config(cfg, opts.output) diff --git a/agent-simulator/scripts/zucchini/tests/testListVm.py b/agent-simulator/scripts/zucchini/tests/testListVm.py index 12fdb869eb6..33a8db2be60 100644 --- a/agent-simulator/scripts/zucchini/tests/testListVm.py +++ b/agent-simulator/scripts/zucchini/tests/testListVm.py @@ -21,14 +21,15 @@ class ListVmTests(cloudstackTestCase): def test_listAllVm(self): numVms = 0 - def time_listAllVm(): - api = self.testClient.getApiClient() - listVmCmd = listVirtualMachines.listVirtualMachinesCmd() - listVmCmd.account = 'admin' - listVmCmd.zoneid = 1 - listVmCmd.domainid = 1 - numVms = len(api.listVirtualMachines(listVmCmd)) + api = self.testClient.getApiClient() + listVmCmd = listVirtualMachines.listVirtualMachinesCmd() + listVmCmd.account = 'admin' + listVmCmd.zoneid = 1 + listVmCmd.domainid = 1 + listVmResponse = api.listVirtualMachines(listVmCmd) + if listVmResponse is not None: + numVms = len() - t = timeit.Timer(time_listAllVm) - l = t.repeat(5, 5) - self.debug("Number of VMs: " + str(len(numVms)) + ", time for last 5 listVM calls : " + str(l)) + t = timeit.Timer(test_listAllVm) + l = t.repeat(5, 5) + self.debug("Number of VMs: " + str(len(numVms)) + ", time for last 5 listVM calls : " + str(l)) diff --git a/agent-simulator/scripts/zucchini/tests/testProvision.py b/agent-simulator/scripts/zucchini/tests/testProvision.py index 49b696d361e..5f4421080e2 100644 --- a/agent-simulator/scripts/zucchini/tests/testProvision.py +++ b/agent-simulator/scripts/zucchini/tests/testProvision.py @@ -1,101 +1,143 @@ #!/usr/bin/env python -''' -Deploy Virtual Machine tests -''' -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest import random from cloudstackAPI import * +from cloudstackTestCase import * -class Provision(unittest.case.TestCase): +class Provision(cloudstackTestCase): ''' - This should test basic provisioning of virtual machines - 1. Deploy a no-frills VM - 2. Deploy with tags - hosttags - 3. Deploy with/without security groups + This should test basic provisioning of virtual machines + 1. Deploy a no-frills VM + 2. Deploy with tags - hosttags + 3. Deploy with/without security groups ''' - api = self.testClient.getApiClient() solist = {} + sgid = 1 def setUp(self): - '''setup service offerings with tags''' + pass + + + def tearDown(self): + pass + + + def test_0_createServiceOfferings(self): for tag in ['TAG1', 'TAG2', 'TAG3']: csocmd = createServiceOffering.createServiceOfferingCmd() csocmd.cpunumber = 1 csocmd.cpuspeed = 2048 - csocmd.displayText = tag + csocmd.displaytext = tag csocmd.memory = 7168 csocmd.name = tag csocmd.hosttags = tag csocmd.storagetype = 'local' - csoresponse = self.api.createServiceOffering(csocmd) - self.debug("Created Service Offering: %s", tag) - solist[tag]=csoresponse.id - - - def tearDown(self): - ''' Any cleanup post tests ''' - - def test_DeployVMWithHostTags(self): + csoresponse = self.testClient.getApiClient().createServiceOffering(csocmd) + self.debug("Created Service Offering: %s" %tag) + self.solist[tag]=csoresponse.id + + + def test_1_createSecurityGroupAndRules(self): + apiClient = self.testClient.getApiClient() + sgCmd=createSecurityGroup.createSecurityGroupCmd() + sgCmd.description='default-zzzz' + sgCmd.name='default-zzzz' + sgCmd.account='admin' + sgCmd.domainid='1' + sgRes = apiClient.createSecurityGroup(sgCmd) + + ruleCmd=authorizeSecurityGroupIngress.authorizeSecurityGroupIngressCmd() + ruleCmd.cidrlist = '172.16.0.0/12' + ruleCmd.startport = '1' + ruleCmd.endport = '65535' + ruleCmd.protocol = 'TCP' + ruleCmd.securitygroupid = sgRes.id + ruleCmd.account='admin' + ruleCmd.domainid='1' + sgIngressresponse=apiClient.authorizeSecurityGroupIngress(ruleCmd) + + ruleCmd=authorizeSecurityGroupIngress.authorizeSecurityGroupIngressCmd() + ruleCmd.cidrlist = '10.0.0.0/8' + ruleCmd.startport = '22' + ruleCmd.endport = '22' + ruleCmd.protocol = 'TCP' + ruleCmd.securitygroupid = sgRes.id + ruleCmd.account='admin' + ruleCmd.domainid='1' + sgIngressresponse=apiClient.authorizeSecurityGroupIngress(ruleCmd) + + ruleCmd=authorizeSecurityGroupIngress.authorizeSecurityGroupIngressCmd() + ruleCmd.cidrlist = '10.0.0.0/8' + ruleCmd.startport = '80' + ruleCmd.endport = '80' + ruleCmd.protocol = 'TCP' + ruleCmd.securitygroupid = sgRes.id + ruleCmd.account='admin' + ruleCmd.domainid='1' + sgIngressresponse=apiClient.authorizeSecurityGroupIngress(ruleCmd) + + self.sgid = sgRes.id + + + + def test_2_DeployVMWithHostTags(self): ''' - Deploy 3 virtual machines one with each hosttag + Deploy 3 virtual machines one with each hosttag ''' - for k,v in solist: + for k,v in self.solist: deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() deployVmCmd.zoneid = 1 deployVmCmd.hypervisor='Simulator' deployVmCmd.serviceofferingid=v deployVmCmd.account='admin' deployVmCmd.domainid=1 - deployVmCmd.templateid=2 - deployVmResponse = self.api.deployVirtualMachine(deployVmCmd) - self.debug("Deployed VM :%d in job: %d",deployVmResponse.id, deployVmResponse.jobid) + deployVmCmd.templateid=10 + deployVmResponse = self.testClient.getApiClient().deployVirtualMachine(deployVmCmd) + self.debug("Deployed VM :%d in job: %d"%(deployVmResponse[0].id, deployVmResponse[0].jobid)) def deployCmd(self, tag): - deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() - deployVmCmd.zoneid = 1 - deployVmCmd.hypervisor='Simulator' - deployVmCmd.serviceofferingid=solist[tag] - deployVmCmd.account='admin' - deployVmCmd.domainid=1 - deployVmCmd.templateid=10 - return deployVmCmd - + deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() + deployVmCmd.zoneid = 1 + deployVmCmd.hypervisor='Simulator' + deployVmCmd.serviceofferingid=self.solist[tag] + deployVmCmd.account='admin' + deployVmCmd.domainid=1 + deployVmCmd.templateid=10 + deployVmCmd.securitygroupids=self.sgid + return deployVmCmd + def deployN(self,nargs=300,batchsize=0): ''' - Deploy Nargs number of VMs concurrently in batches of size {batchsize}. - When batchsize is 0 all Vms are deployed in one batch - VMs will be deployed in 5:2:6 ratio + Deploy Nargs number of VMs concurrently in batches of size {batchsize}. + When batchsize is 0 all Vms are deployed in one batch + VMs will be deployed in 5:2:6 ratio ''' tag1=nargs*5/13 tag2=nargs*2/13 tag3=nargs-tag1-tag2 - + cmds = [] - [cmds.append(deployCmd('TAG1')) for i in range(tag1)] - [cmds.append(deployCmd('TAG2')) for i in range(tag2)] - [cmds.append(deployCmd('TAG3')) for i in range(tag3)] + [cmds.append(self.deployCmd('TAG1')) for i in range(tag1)] + [cmds.append(self.deployCmd('TAG2')) for i in range(tag2)] + [cmds.append(self.deployCmd('TAG3')) for i in range(tag3)] random.shuffle(cmds) #with mix-and-match of Tags - + if batchsize == 0: self.testClient.submitCmdsAndWait(cmds) else: - while len(z) > 0: + while len(cmds) > 0: try: newbatch = [cmds.pop() for b in range(batchsize)] #pop batchsize items self.testClient.submitCmdsAndWait(newbatch) except IndexError: break - def test_bulkDeploy(self): - deployN(130,0) - deployN(nargs=9000,batchsize=100) - - - - - - - + def test_3_bulkDeploy(self): + self.deployN(130,0) + self.deployN(nargs=9000,batchsize=100)