From d70b326063607741ef5da7f330ebcd4877bddb4f Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Tue, 29 Nov 2011 23:01:53 +0530 Subject: [PATCH] - some quick environment configuration files - adding service providers for zone configuration - getting the python framework working with providers (cherry picked from commit e0dd12619cc2dc32d23cc1f6cd82f01cd9f80b87) --- tools/testClient/configGenerator.py | 30 +- tools/testClient/deployDataCenter.py | 56 ++- tools/testClient/jsonHelper.py | 7 +- .../sandbox/advanced/advanced_env.py | 121 ++++++ .../sandbox/advanced/kvm.properties | 37 ++ .../sandbox/advanced/sandbox.kvm.cfg | 140 +++++++ .../sandbox/advanced/sandbox.xen.cfg | 141 +++++++ .../sandbox/advanced/setup.properties | 36 ++ .../sandbox/advanced/tests/test_scenarios.py | 126 +++++++ .../sandbox/advanced/xen.properties | 36 ++ tools/testClient/sandbox/basic/basic_env.py | 0 tools/testClient/sandbox/kvm/sandbox.kvm.cfg | 137 +++++++ tools/testClient/sandbox/kvm/setup.py | 134 +++++++ .../sandbox/kvm/tests/testProvision.py | 125 +++++++ .../sandbox/kvm/tests/testScratch.py | 125 +++++++ .../testClient/sandbox/simulator/sandbox.cfg | 346 ++++++++++++++++++ tools/testClient/sandbox/simulator/setup.py | 134 +++++++ .../sandbox/simulator/tests/testProvision.py | 124 +++++++ tools/testClient/sandbox/xen/sandbox.xen.cfg | 146 ++++++++ tools/testClient/sandbox/xen/setup.py | 136 +++++++ .../sandbox/xen/tests/testProvision.py | 123 +++++++ .../sandbox/xen/tests/testScratch.py | 125 +++++++ tools/testClient/unitTest/test_advanced.py | 2 +- 23 files changed, 2375 insertions(+), 12 deletions(-) create mode 100644 tools/testClient/sandbox/advanced/advanced_env.py create mode 100644 tools/testClient/sandbox/advanced/kvm.properties create mode 100644 tools/testClient/sandbox/advanced/sandbox.kvm.cfg create mode 100644 tools/testClient/sandbox/advanced/sandbox.xen.cfg create mode 100644 tools/testClient/sandbox/advanced/setup.properties create mode 100644 tools/testClient/sandbox/advanced/tests/test_scenarios.py create mode 100644 tools/testClient/sandbox/advanced/xen.properties create mode 100644 tools/testClient/sandbox/basic/basic_env.py create mode 100644 tools/testClient/sandbox/kvm/sandbox.kvm.cfg create mode 100644 tools/testClient/sandbox/kvm/setup.py create mode 100644 tools/testClient/sandbox/kvm/tests/testProvision.py create mode 100644 tools/testClient/sandbox/kvm/tests/testScratch.py create mode 100644 tools/testClient/sandbox/simulator/sandbox.cfg create mode 100644 tools/testClient/sandbox/simulator/setup.py create mode 100644 tools/testClient/sandbox/simulator/tests/testProvision.py create mode 100644 tools/testClient/sandbox/xen/sandbox.xen.cfg create mode 100644 tools/testClient/sandbox/xen/setup.py create mode 100644 tools/testClient/sandbox/xen/tests/testProvision.py create mode 100644 tools/testClient/sandbox/xen/tests/testScratch.py diff --git a/tools/testClient/configGenerator.py b/tools/testClient/configGenerator.py index 4d99ddff666..da03f5e48e8 100644 --- a/tools/testClient/configGenerator.py +++ b/tools/testClient/configGenerator.py @@ -2,6 +2,7 @@ import json import os from optparse import OptionParser import jsonHelper + class managementServer(): def __init__(self): self.mgtSvrIp = None @@ -21,6 +22,7 @@ class configuration(): def __init__(self): self.name = None self.value = None + class logger(): def __init__(self): '''TestCase/TestClient''' @@ -46,15 +48,37 @@ class zone(): self.guestcidraddress = None self.internaldns2 = None self.securitygroupenabled = None - '''guest vlan: e.g. 100-200, used in advanced mode''' - self.vlan = None '''default public network, in advanced mode''' self.ipranges = [] '''tagged network, in advanced mode''' self.networks = [] + self.providers = [] self.pods = [] self.secondaryStorages = [] +class provider(): + def __init__(self): + self.name = None + self.state = None + self.broadcastdomainrange = 'ZONE' + ''' Guest Vlan range''' + self.vlan = None + self.zoneid = None + self.servicelist = [] + + #self.vpn_service_provided = None + #self.dhcp_service_provided = None + #self.dns_service_provided = None + #self.gateway_service_provided = None + #self.firewall_service_provided = None + #self.source_nat_service_provided = None + #self.load_balance_service_provided = None + #self.static_nat_service_provided = None + #self.port_forwarding_service_provided = None + #self.user_data_service_provided = None + #self.security_group_service_provided = None + + class pod(): def __init__(self): self.gateway = None @@ -112,11 +136,11 @@ class network(): class iprange(): def __init__(self): '''tagged/untagged''' - self.vlan = None self.gateway = None self.netmask = None self.startip = None self.endip = None + self.vlan = None '''for account specific ''' self.account = None self.domain = None diff --git a/tools/testClient/deployDataCenter.py b/tools/testClient/deployDataCenter.py index 891d7f31b1e..7f2d3b7cbed 100644 --- a/tools/testClient/deployDataCenter.py +++ b/tools/testClient/deployDataCenter.py @@ -6,6 +6,7 @@ import sys import logging from cloudstackAPI import * from optparse import OptionParser + class deployDataCenters(): def __init__(self, cfgFile): self.configFile = cfgFile @@ -49,6 +50,7 @@ class deployDataCenters(): self.addHosts(cluster.hosts, zoneId, podId, clusterId, cluster.hypervisor) self.createPrimaryStorages(cluster.primaryStorages, zoneId, podId, clusterId) + def createPrimaryStorages(self, primaryStorages, zoneId, podId, clusterId): if primaryStorages is None: return @@ -78,12 +80,12 @@ class deployDataCenters(): podId = createpodResponse.id if pod.guestIpRanges is not None: - self.createipRanges("Basic", pod.guestIpRanges, zoneId, podId) + self.createVlanIpRanges("Basic", pod.guestIpRanges, zoneId, podId) self.createClusters(pod.clusters, zoneId, podId) - def createipRanges(self, mode, ipranges, zoneId, podId=None, networkId=None): + def createVlanIpRanges(self, mode, ipranges, zoneId, podId=None, networkId=None): if ipranges is None: return for iprange in ipranges: @@ -96,8 +98,8 @@ class deployDataCenters(): vlanipcmd.networkid = networkId vlanipcmd.podid = podId vlanipcmd.startip = iprange.startip - vlanipcmd.vlan = iprange.vlan vlanipcmd.zoneid = zoneId + vlanipcmd.vlan = iprange.vlan if mode == "Basic": vlanipcmd.forvirtualnetwork = "false" else: @@ -137,7 +139,45 @@ class deployDataCenters(): networkcmdresponse = self.apiClient.createNetwork(networkcmd) networkId = networkcmdresponse.id - self.createipRanges("Advanced", ipranges, zoneId, networkId=networkId) + self.createVlanIpRanges("Advanced", ipranges, zoneId, networkId=networkId) + + def configureProviders(self, providers, zoneid): + for prov in providers: + pnets = listPhysicalNetworks.listPhysicalNetworksCmd() + pnets.zoneid = zoneid + pnets.state = 'Disabled' + pnetsresponse = self.apiClient.listPhysicalNetworks(pnets) + pnetid = pnetsresponse[0].id + + upnet = updatePhysicalNetwork.updatePhysicalNetworkCmd() + upnet.state = 'Enabled' + upnet.id = pnetid + upnet.vlan = prov.vlan + upnetresponse = self.apiClient.updatePhysicalNetwork(upnet) + + pnetprov = listNetworkServiceProviders.listNetworkServiceProvidersCmd() + pnetprov.physicalnetworkid = pnetid + pnetprov.state = 'Disabled' + pnetprovresponse = self.apiClient.listNetworkServiceProviders(pnetprov) + pnetprovid = pnetprovresponse[0].id + + #TODO: Only enables default - should also update service list - VPN/LB/DNS/DHCP/FW + upnetprov = updateNetworkServiceProvider.updateNetworkServiceProviderCmd() + upnetprov.id = pnetprovid + upnetprov.state = 'Enabled' + upnetprovresponse = self.apiClient.updateNetworkServiceProvider(upnetprov) + + vrprov = listVirtualRouterElements.listVirtualRouterElementsCmd() + vrprov.nspid = pnetprovid + vrprovresponse = self.apiClient.listVirtualRouterElements(vrprov) + vrprovid = vrprovresponse[0].id + + vrconfig = configureVirtualRouterElement.configureVirtualRouterElementCmd() + vrconfig.enabled = 'true' + vrconfig.id = vrprovid + vrconfigresponse = self.apiClient.configureVirtualRouterElement(vrconfig) + + def createZones(self, zones): for zone in zones: '''create a zone''' @@ -150,17 +190,19 @@ class deployDataCenters(): createzone.name = zone.name createzone.securitygroupenabled = zone.securitygroupenabled createzone.networktype = zone.networktype - createzone.vlan = zone.vlan zoneresponse = self.apiClient.createZone(createzone) zoneId = zoneresponse.id + + '''enable physical networks and providers''' + self.configureProviders(zone.providers, zoneId) '''create pods''' self.createpods(zone.pods, zone, zoneId) if zone.networktype == "Advanced": '''create pubic network''' - self.createipRanges(zone.networktype, zone.ipranges, zoneId) + self.createVlanIpRanges(zone.networktype, zone.ipranges, zoneId) self.createnetworks(zone.networks, zoneId) '''create secondary storage''' @@ -263,4 +305,4 @@ if __name__ == "__main__": deploy = deployDataCenters("./datacenterCfg") deploy.loadCfg() deploy.apiClient.createStoragePool(create) - ''' \ No newline at end of file + ''' diff --git a/tools/testClient/jsonHelper.py b/tools/testClient/jsonHelper.py index 9c692159df9..6bf6d056f1f 100644 --- a/tools/testClient/jsonHelper.py +++ b/tools/testClient/jsonHelper.py @@ -2,6 +2,8 @@ import cloudstackException import json import inspect from cloudstackAPI import * +import pdb + class jsonLoader: '''The recursive class for building and representing objects with.''' def __init__(self, obj): @@ -120,6 +122,9 @@ def getResultObj(returnObj, responsecls=None): return finalizeResultObj(result, responseName, responsecls) if __name__ == "__main__": + + result = '{ "listnetworkserviceprovidersresponse" : { "count":1 ,"networkserviceprovider" : [ {"name":"VirtualRouter","physicalnetworkid":"ad2948fc-1054-46c7-b1c7-61d990b86710","destinationphysicalnetworkid":"0","state":"Disabled","id":"d827cae4-4998-4037-95a2-55b92b6318b1","servicelist":["Vpn","Dhcp","Dns","Gateway","Firewall","Lb","SourceNat","StaticNat","PortForwarding","UserData"]} ] } }' + nsp = getResultObj(result) result = '{ "listzonesresponse" : { "count":1 ,"zone" : [ {"id":1,"name":"test0","dns1":"8.8.8.8","dns2":"4.4.4.4","internaldns1":"192.168.110.254","internaldns2":"192.168.110.253","networktype":"Basic","securitygroupsenabled":true,"allocationstate":"Enabled","zonetoken":"5e818a11-6b00-3429-9a07-e27511d3169a","dhcpprovider":"DhcpServer"} ] } }' zones = getResultObj(result) @@ -166,4 +171,4 @@ if __name__ == "__main__": cmd = deployVirtualMachine.deployVirtualMachineCmd() responsename = cmd.__class__.__name__.replace("Cmd", "Response") response = getclassFromName(cmd, responsename) - print response.id \ No newline at end of file + print response.id diff --git a/tools/testClient/sandbox/advanced/advanced_env.py b/tools/testClient/sandbox/advanced/advanced_env.py new file mode 100644 index 00000000000..3dda7d62a3b --- /dev/null +++ b/tools/testClient/sandbox/advanced/advanced_env.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python + +''' +############################################################ +# Experimental state of scripts +# * Need to be reviewed +# * Only a sandbox +############################################################ +''' + +from ConfigParser import SafeConfigParser +from optparse import OptionParser +from configGenerator import * +import random + + +def getGlobalSettings(config): + for k, v in dict(config.items('globals')).iteritems(): + cfg = configuration() + cfg.name = k + cfg.value = v + yield cfg + + +def describeResources(config): + zs = cloudstackConfiguration() + + z = zone() + z.dns1 = config.get('environment', 'dns') + z.internaldns1 = config.get('environment', 'dns') + z.name = 'Sandbox-%s'%(config.get('environment', 'hypervisor')) + z.networktype = 'Advanced' + z.guestcidraddress = '10.1.1.0/24' + + prov = provider() + prov.vlan = config.get('cloudstack','guest.vlan') + z.providers.append(prov) + + p = pod() + p.name = 'POD0' + p.gateway = config.get('cloudstack', 'private.gateway') + p.startip = config.get('cloudstack', 'private.pod.startip') + p.endip = config.get('cloudstack', 'private.pod.endip') + p.netmask = '255.255.255.0' + + v = iprange() + v.gateway = config.get('cloudstack', 'public.gateway') + v.startip = config.get('cloudstack', 'public.vlan.startip') + v.endip = config.get('cloudstack', 'public.vlan.endip') + v.netmask = '255.255.255.0' + v.vlan = config.get('cloudstack', 'public.vlan') + z.ipranges.append(v) + + c = cluster() + c.clustername = 'C0' + c.hypervisor = config.get('environment', 'hypervisor') + c.clustertype = 'CloudManaged' + + h = host() + h.username = 'root' + h.password = 'password' + h.url = 'http://%s'%(config.get('cloudstack', 'host')) + c.hosts.append(h) + + ps = primaryStorage() + ps.name = 'PS0' + ps.url = config.get('cloudstack', 'pool') + c.primaryStorages.append(ps) + + p.clusters.append(c) + z.pods.append(p) + + secondary = secondaryStorage() + secondary.url = config.get('cloudstack', 'secondary') + z.secondaryStorages.append(secondary) + + '''Add zone''' + zs.zones.append(z) + + '''Add mgt server''' + mgt = managementServer() + mgt.mgtSvrIp = config.get('environment', 'mshost') + zs.mgtSvr.append(mgt) + + '''Add a database''' + db = dbServer() + db.dbSvr = config.get('environment', 'database') + zs.dbSvr = db + + '''Add some configuration''' + [zs.globalConfig.append(cfg) for cfg in getGlobalSettings(config)] + + ''''add loggers''' + testClientLogger = logger() + testClientLogger.name = 'TestClient' + testClientLogger.file = '/var/log/testclient.log' + + testCaseLogger = logger() + testCaseLogger.name = 'TestCase' + testCaseLogger.file = '/var/log/testcase.log' + + zs.logger.append(testClientLogger) + zs.logger.append(testCaseLogger) + return zs + + +if __name__ == '__main__': + parser = OptionParser() + parser.add_option('-i', '--input', action='store', default='setup.properties', \ + dest='input', help='file containing environment setup information') + parser.add_option('-o', '--output', action='store', default='./sandbox.cfg', \ + dest='output', help='path where environment json will be generated') + + + (opts, args) = parser.parse_args() + + cfg_parser = SafeConfigParser() + cfg_parser.read(opts.input) + + cfg = describeResources(cfg_parser) + generate_setup_config(cfg, opts.output) diff --git a/tools/testClient/sandbox/advanced/kvm.properties b/tools/testClient/sandbox/advanced/kvm.properties new file mode 100644 index 00000000000..a34da935760 --- /dev/null +++ b/tools/testClient/sandbox/advanced/kvm.properties @@ -0,0 +1,37 @@ +[globals] +expunge.delay=60 +expunge.interval=60 +storage.cleanup.interval=300 +account.cleanup.interval=600 +expunge.workers=3 +workers=10 +use.user.concentrated.pod.allocation=false +vm.allocation.algorithm=random +vm.op.wait.interval=5 +guest.domain.suffix=sandbox.kvm +instance.name=QA +direct.agent.load.size=1000 +default.page.size=10000 +check.pod.cidrs=true +secstorage.allowed.internal.sites=10.147.28.0/24 +[environment] +dns=10.147.28.6 +mshost=10.147.29.111 +database=10.147.29.111 +hypervisor=kvm +[cloudstack] +zone.vlan=675-679 +#pod configuration +private.gateway=10.147.29.1 +private.pod.startip=10.147.29.150 +private.pod.endip=10.147.29.159 +#public vlan range +public.gateway=10.147.31.1 +public.vlan=31 +public.vlan.startip=10.147.31.150 +public.vlan.endip=10.147.31.159 +#hosts +host=10.147.29.58 +#pools +pool=nfs://10.147.28.6:/export/home/prasanna/kamakura +secondary=nfs://10.147.28.6:/export/home/prasanna/sstor diff --git a/tools/testClient/sandbox/advanced/sandbox.kvm.cfg b/tools/testClient/sandbox/advanced/sandbox.kvm.cfg new file mode 100644 index 00000000000..7515dd82e58 --- /dev/null +++ b/tools/testClient/sandbox/advanced/sandbox.kvm.cfg @@ -0,0 +1,140 @@ +{ + "zones": [ + { + "name": "Sandbox-kvm", + "guestcidraddress": "10.1.1.0/24", + "dns1": "10.147.28.6", + "vlan": "675-679", + "ipranges": [ + { + "startip": "10.147.31.150", + "endip": "10.147.31.159", + "netmask": "255.255.255.0", + "vlan": "31", + "gateway": "10.147.31.1" + } + ], + "networktype": "Advanced", + "pods": [ + { + "endip": "10.147.29.159", + "name": "POD1", + "startip": "10.147.29.150", + "netmask": "255.255.255.0", + "clusters": [ + { + "clustername": "C0", + "hypervisor": "kvm", + "hosts": [ + { + "username": "root", + "url": "http://10.147.29.58", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://10.147.28.6:/export/home/prasanna/kamakura", + "name": "PS0" + } + ] + } + ], + "gateway": "10.147.29.1" + } + ], + "internaldns1": "10.147.28.6", + "secondaryStorages": [ + { + "url": "nfs://10.147.28.6:/export/home/prasanna/sstor" + } + ] + } + ], + "dbSvr": { + "dbSvr": "10.147.29.111", + "passwd": "cloud", + "db": "cloud", + "port": 3306, + "user": "cloud" + }, + "logger": [ + { + "name": "TestClient", + "file": "/var/log/testclient.log" + }, + { + "name": "TestCase", + "file": "/var/log/testcase.log" + } + ], + "globalConfig": [ + { + "name": "storage.cleanup.interval", + "value": "300" + }, + { + "name": "use.user.concentrated.pod.allocation", + "value": "false" + }, + { + "name": "vm.op.wait.interval", + "value": "5" + }, + { + "name": "default.page.size", + "value": "10000" + }, + { + "name": "instance.name", + "value": "QA" + }, + { + "name": "workers", + "value": "10" + }, + { + "name": "direct.agent.load.size", + "value": "1000" + }, + { + "name": "account.cleanup.interval", + "value": "600" + }, + { + "name": "guest.domain.suffix", + "value": "sandbox.kvm" + }, + { + "name": "expunge.delay", + "value": "60" + }, + { + "name": "vm.allocation.algorithm", + "value": "random" + }, + { + "name": "expunge.interval", + "value": "60" + }, + { + "name": "expunge.workers", + "value": "3" + }, + { + "name": "secstorage.allowed.internal.sites", + "value": "10.147.28.0/24" + }, + { + "name": "check.pod.cidrs", + "value": "true" + } + ], + "mgtSvr": [ + { + "mgtSvrIp": "10.147.29.111", + "port": 8096 + } + ] +} \ No newline at end of file diff --git a/tools/testClient/sandbox/advanced/sandbox.xen.cfg b/tools/testClient/sandbox/advanced/sandbox.xen.cfg new file mode 100644 index 00000000000..c6a49cd7bad --- /dev/null +++ b/tools/testClient/sandbox/advanced/sandbox.xen.cfg @@ -0,0 +1,141 @@ +{ + "zones": [ + { + "name": "Sandbox-XenServer", + "guestcidraddress": "10.1.1.0/24", + "providers": [ + { + "broadcastdomainrange": "ZONE", + "vlan": "675-679" + } + ], + "dns1": "10.147.28.6", + "ipranges": [ + { + "startip": "10.147.31.150", + "endip": "10.147.31.159", + "netmask": "255.255.255.0", + "vlan": "31", + "gateway": "10.147.31.1" + } + ], + "networktype": "Advanced", + "pods": [ + { + "endip": "10.147.29.159", + "name": "POD0", + "startip": "10.147.29.150", + "netmask": "255.255.255.0", + "clusters": [ + { + "clustername": "C0", + "hypervisor": "XenServer", + "hosts": [ + { + "username": "root", + "url": "http://10.147.29.57", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://10.147.28.6:/export/home/prasanna/budhgaya", + "name": "PS0" + } + ] + } + ], + "gateway": "10.147.29.1" + } + ], + "internaldns1": "10.147.28.6", + "secondaryStorages": [ + { + "url": "nfs://10.147.28.6:/export/home/prasanna/sstor" + } + ] + } + ], + "dbSvr": { + "dbSvr": "localhost", + "passwd": "cloud", + "db": "cloud", + "port": 3306, + "user": "cloud" + }, + "logger": [ + { + "name": "TestClient", + "file": "/var/log/testclient.log" + }, + { + "name": "TestCase", + "file": "/var/log/testcase.log" + } + ], + "globalConfig": [ + { + "name": "storage.cleanup.interval", + "value": "300" + }, + { + "name": "vm.op.wait.interval", + "value": "5" + }, + { + "name": "default.page.size", + "value": "10000" + }, + { + "name": "instance.name", + "value": "QA" + }, + { + "name": "workers", + "value": "10" + }, + { + "name": "direct.agent.load.size", + "value": "1000" + }, + { + "name": "account.cleanup.interval", + "value": "600" + }, + { + "name": "guest.domain.suffix", + "value": "sandbox.xen" + }, + { + "name": "expunge.delay", + "value": "60" + }, + { + "name": "vm.allocation.algorithm", + "value": "userdispersing" + }, + { + "name": "expunge.interval", + "value": "60" + }, + { + "name": "expunge.workers", + "value": "3" + }, + { + "name": "secstorage.allowed.internal.sites", + "value": "10.147.28.0/24" + }, + { + "name": "check.pod.cidrs", + "value": "true" + } + ], + "mgtSvr": [ + { + "mgtSvrIp": "localhost", + "port": 8096 + } + ] +} \ No newline at end of file diff --git a/tools/testClient/sandbox/advanced/setup.properties b/tools/testClient/sandbox/advanced/setup.properties new file mode 100644 index 00000000000..a90630c13f8 --- /dev/null +++ b/tools/testClient/sandbox/advanced/setup.properties @@ -0,0 +1,36 @@ +[globals] +expunge.delay=60 +expunge.interval=60 +storage.cleanup.interval=300 +account.cleanup.interval=600 +expunge.workers=3 +workers=10 +use.user.concentrated.pod.allocation=false +vm.allocation.algorithm=random +vm.op.wait.interval=5 +guest.domain.suffix=sandbox.kvm +instance.name=QA +direct.agent.load.size=1000 +default.page.size=10000 +check.pod.cidrs=true +secstorage.allowed.internal.sites=10.147.28.0/24 +[environment] +dns=10.147.28.6 +mshost=10.147.29.111 +database=10.147.29.111 +[cloudstack] +zone.vlan=675-679 +#pod configuration +private.gateway=10.147.29.1 +private.pod.startip=10.147.29.150 +private.pod.endip=10.147.29.159 +#public vlan range +public.gateway=10.147.31.1 +public.vlan=31 +public.vlan.startip=10.147.31.150 +public.vlan.endip=10.147.31.159 +#hosts +host=10.147.29.58 +#pools +pool=nfs://10.147.28.6:/export/home/prasanna/kamakura +secondary=nfs://10.147.28.6:/export/home/prasanna/sstor diff --git a/tools/testClient/sandbox/advanced/tests/test_scenarios.py b/tools/testClient/sandbox/advanced/tests/test_scenarios.py new file mode 100644 index 00000000000..bae181ca693 --- /dev/null +++ b/tools/testClient/sandbox/advanced/tests/test_scenarios.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python +try: + import unittest2 as unittest +except ImportError: + import unittest + +import random +import hashlib +from cloudstackTestCase import * +import remoteSSHClient + +class SampleScenarios(cloudstackTestCase): + ''' + ''' + def setUp(self): + pass + + + def tearDown(self): + pass + + + def test_1_createAccounts(self, numberOfAccounts=2): + ''' + Create a bunch of user accounts + ''' + mdf = hashlib.md5() + mdf.update('password') + mdf_pass = mdf.hexdigest() + api = self.testClient.getApiClient() + for i in range(1, numberOfAccounts + 1): + acct = createAccount.createAccountCmd() + acct.accounttype = 0 + acct.firstname = 'user' + str(i) + acct.lastname = 'user' + str(i) + acct.password = mdf_pass + acct.username = 'user' + str(i) + acct.email = 'user@example.com' + acct.account = 'user' + str(i) + acct.domainid = 1 + acctResponse = api.createAccount(acct) + self.debug("successfully created account: %s, user: %s, id: %s"%(acctResponse.account, acctResponse.username, acctResponse.id)) + + + def test_2_createServiceOffering(self): + apiClient = self.testClient.getApiClient() + createSOcmd=createServiceOffering.createServiceOfferingCmd() + createSOcmd.name='Sample SO' + createSOcmd.displaytext='Sample SO' + createSOcmd.storagetype='shared' + createSOcmd.cpunumber=1 + createSOcmd.cpuspeed=100 + createSOcmd.memory=128 + createSOcmd.offerha='false' + createSOresponse = apiClient.createServiceOffering(createSOcmd) + return createSOresponse.id + + def deployCmd(self, account, service): + deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() + deployVmCmd.zoneid = 1 + deployVmCmd.account=account + deployVmCmd.domainid=1 + deployVmCmd.templateid=2 + deployVmCmd.serviceofferingid=service + return deployVmCmd + + def listVmsInAccountCmd(self, acct): + api = self.testClient.getApiClient() + listVmCmd = listVirtualMachines.listVirtualMachinesCmd() + listVmCmd.account = acct + listVmCmd.zoneid = 1 + listVmCmd.domainid = 1 + listVmResponse = api.listVirtualMachines(listVmCmd) + return listVmResponse + + + def destroyVmCmd(self, key): + api = self.testClient.getApiClient() + destroyVmCmd = destroyVirtualMachine.destroyVirtualMachineCmd() + destroyVmCmd.id = key + api.destroyVirtualMachine(destroyVmCmd) + + + def test_3_stressDeploy(self): + ''' + Deploy 5 Vms in each account + ''' + service_id = self.test_2_createServiceOffering() + api = self.testClient.getApiClient() + for acct in range(1, 5): + [api.deployVirtualMachine(self.deployCmd('user'+str(acct), service_id)) for x in range(0,5)] + + @unittest.skip("skipping destroys") + def test_4_stressDestroy(self): + ''' + Cleanup all Vms in every account + ''' + api = self.testClient.getApiClient() + for acct in range(1, 6): + for vm in self.listVmsInAccountCmd('user'+str(acct)): + if vm is not None: + self.destroyVmCmd(vm.id) + + @unittest.skip("skipping destroys") + def test_5_combineStress(self): + for i in range(0, 5): + self.test_3_stressDeploy() + self.test_4_stressDestroy() + + 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 + ''' + cmds = [] + + if batchsize == 0: + self.testClient.submitCmdsAndWait(cmds) + else: + while len(z) > 0: + try: + newbatch = [cmds.pop() for b in range(batchsize)] #pop batchsize items + self.testClient.submitCmdsAndWait(newbatch) + except IndexError: + break diff --git a/tools/testClient/sandbox/advanced/xen.properties b/tools/testClient/sandbox/advanced/xen.properties new file mode 100644 index 00000000000..4d44e07e067 --- /dev/null +++ b/tools/testClient/sandbox/advanced/xen.properties @@ -0,0 +1,36 @@ +[globals] +expunge.delay=60 +expunge.interval=60 +storage.cleanup.interval=300 +account.cleanup.interval=600 +expunge.workers=3 +workers=10 +vm.allocation.algorithm=userdispersing +vm.op.wait.interval=5 +guest.domain.suffix=sandbox.xen +instance.name=QA +direct.agent.load.size=1000 +default.page.size=10000 +check.pod.cidrs=true +secstorage.allowed.internal.sites=10.147.28.0/24 +[environment] +dns=10.147.28.6 +mshost=localhost +database=localhost +hypervisor=XenServer +[cloudstack] +guest.vlan=675-679 +#pod configuration +private.gateway=10.147.29.1 +private.pod.startip=10.147.29.150 +private.pod.endip=10.147.29.159 +#public vlan range +public.gateway=10.147.31.1 +public.vlan=31 +public.vlan.startip=10.147.31.150 +public.vlan.endip=10.147.31.159 +#hosts +host=10.147.29.57 +#pools +pool=nfs://10.147.28.6:/export/home/prasanna/budhgaya +secondary=nfs://10.147.28.6:/export/home/prasanna/sstor diff --git a/tools/testClient/sandbox/basic/basic_env.py b/tools/testClient/sandbox/basic/basic_env.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tools/testClient/sandbox/kvm/sandbox.kvm.cfg b/tools/testClient/sandbox/kvm/sandbox.kvm.cfg new file mode 100644 index 00000000000..5771dbfd8ee --- /dev/null +++ b/tools/testClient/sandbox/kvm/sandbox.kvm.cfg @@ -0,0 +1,137 @@ +{ + "zones": [ + { + "name": "Sandbox-KVM", + "guestcidraddress": "10.1.1.0/24", + "dns2": "10.223.110.254", + "dns1": "10.147.28.6", + "vlan": "660-669", + "ipranges": [ + { + "startip": "10.147.32.105", + "endip": "10.147.32.109", + "netmask": "255.255.255.0", + "gateway": "10.147.32.1" + } + ], + "networktype": "Advanced", + "pods": [ + { + "endip": "10.147.31.109", + "name": "POD1", + "startip": "10.147.31.105", + "netmask": "255.255.255.0", + "clusters": [ + { + "clustername": "KVM0", + "hypervisor": "KVM", + "hosts": [ + { + "username": "root", + "url": "http://10.147.31.40", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://10.147.28.6/export/home/prasanna/kamakura", + "name": "PS0" + } + ] + } + ], + "gateway": "10.147.31.1" + } + ], + "internaldns1": "10.147.28.6", + "internaldns2": "10.223.110.254", + "secondaryStorages": [ + { + "url": "nfs://10.147.28.6/export/home/prasanna/secondary" + } + ] + } + ], + "dbSvr": { + "dbSvr": "10.147.28.75", + "passwd": "cloud", + "db": "cloud", + "port": 3306, + "user": "cloud" + }, + "logger": [ + { + "name": "TestClient", + "file": "/var/log/testclient.log" + }, + { + "name": "TestCase", + "file": "/var/log/testcase.log" + } + ], + "globalConfig": [ + { + "name": "use.user.concentrated.pod.allocation", + "value": "false" + }, + { + "name": "default.page.size", + "value": "10000" + }, + { + "name": "direct.agent.load.size", + "value": "1000" + }, + { + "name": "expunge.delay", + "value": "60" + }, + { + "name": "vm.allocation.algorithm", + "value": "random" + }, + { + "name": "check.pod.cidrs", + "value": "true" + }, + { + "name": "instance.name", + "value": "KVMQA" + }, + { + "name": "workers", + "value": "10" + }, + { + "name": "vm.op.wait.interval", + "value": "5" + }, + { + "name": "guest.domain.suffix", + "value": "sandbox.kvm" + }, + { + "name": "expunge.interval", + "value": "60" + }, + { + "name": "linkLocalIp.nums", + "value": "10" + }, + { + "name": "expunge.workers", + "value": "3" + }, + { + "name": "secstorage.allowed.internal.sites", + "value": "10.147.28.0/24" + } + ], + "mgtSvr": [ + { + "mgtSvrIp": "10.147.28.76", + "port": 8096 + } + ] +} \ No newline at end of file diff --git a/tools/testClient/sandbox/kvm/setup.py b/tools/testClient/sandbox/kvm/setup.py new file mode 100644 index 00000000000..b19575dc4ca --- /dev/null +++ b/tools/testClient/sandbox/kvm/setup.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python + +''' +############################################################ +# Experimental state of scripts +# * Need to be reviewed +# * Only a sandbox +# * DNS settings are internal +# * VLAN settings are internal +# * IP Ranges are internal +# * Storage share is internal +############################################################ +''' + +from optparse import OptionParser +from configGenerator import * +import random + + +def getGlobalSettings(): + global_settings = {'expunge.delay': '60', + 'expunge.interval': '60', + 'expunge.workers': '3', + 'workers': '10', + 'use.user.concentrated.pod.allocation': 'false', + 'vm.allocation.algorithm': 'random', + 'vm.op.wait.interval': '5', + 'guest.domain.suffix': 'sandbox.kvm', + 'instance.name': 'KVMQA', + 'direct.agent.load.size': '1000', + 'default.page.size': '10000', + 'linkLocalIp.nums': '10', + 'check.pod.cidrs': 'true', + 'secstorage.allowed.internal.sites': '10.147.28.0/24', + } + for k, v in global_settings.iteritems(): + cfg = configuration() + cfg.name = k + cfg.value = v + yield cfg + + +def describeResources(dbnode='localhost', mshost='localhost', kvmhost='localhost'): + zs = cloudstackConfiguration() + numberofpods = 1 + + clustersPerPod = 1 + hostsPerCluster = 2 + + z = zone() + z.dns1 = '10.147.28.6' + z.dns2 = '10.223.110.254' + z.internaldns1 = '10.147.28.6' + z.internaldns2 = '10.223.110.254' + z.name = 'Sandbox-KVM' + z.networktype = 'Advanced' + z.guestcidraddress = '10.1.1.0/24' + z.vlan='660-669' + + p = pod() + p.name = 'POD1' + p.gateway = '10.147.31.1' + p.startip = '10.147.31.105' + p.endip = '10.147.31.109' + p.netmask = '255.255.255.0' + + v = iprange() + v.gateway = '10.147.32.1' + v.startip = '10.147.32.105' + v.endip = '10.147.32.109' + v.netmask = '255.255.255.0' + + c = cluster() + c.clustername = 'KVM0' + c.hypervisor = 'KVM' + c.clustertype = 'CloudManaged' + + h = host() + h.username = 'root' + h.password = 'password' + h.url = 'http://%s'%(kvmhost) + c.hosts.append(h) + + ps = primaryStorage() + ps.name = 'PS0' + ps.url = 'nfs://10.147.28.6/export/home/prasanna/kamakura' ## TODO: Make this configurable + c.primaryStorages.append(ps) + p.clusters.append(c) + + secondary = secondaryStorage() + secondary.url = 'nfs://10.147.28.6/export/home/prasanna/secondary' ## TODO: Make this configurable + + z.pods.append(p) + z.ipranges.append(v) + z.secondaryStorages.append(secondary) + zs.zones.append(z) + + '''Add mgt server''' + mgt = managementServer() + mgt.mgtSvrIp = mshost + zs.mgtSvr.append(mgt) + + '''Add a database''' + db = dbServer() + db.dbSvr = opts.dbnode + zs.dbSvr = db + + '''Add some configuration''' + [zs.globalConfig.append(cfg) for cfg in getGlobalSettings()] + + ''''add loggers''' + testClientLogger = logger() + testClientLogger.name = 'TestClient' + testClientLogger.file = '/var/log/testclient.log' + + testCaseLogger = logger() + testCaseLogger.name = 'TestCase' + testCaseLogger.file = '/var/log/testcase.log' + + zs.logger.append(testClientLogger) + zs.logger.append(testCaseLogger) + return zs + + +if __name__ == '__main__': + parser = OptionParser() + parser.add_option('-o', '--output', action='store', default='./sandbox.kvm.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('-k', '--hypervisor', dest='hypervisor', help='hostname/ip of hypervisor server', action='store') + + (opts, args) = parser.parse_args() + cfg = describeResources(opts.dbnode, opts.mshost, opts.hypervisor) + generate_setup_config(cfg, opts.output) diff --git a/tools/testClient/sandbox/kvm/tests/testProvision.py b/tools/testClient/sandbox/kvm/tests/testProvision.py new file mode 100644 index 00000000000..04331fc96f4 --- /dev/null +++ b/tools/testClient/sandbox/kvm/tests/testProvision.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +try: + import unittest2 as unittest +except ImportError: + import unittest + +import random +import hashlib +from cloudstackTestCase import * + +class Provision(cloudstackTestCase): + ''' + ''' + def setUp(self): + pass + + + def tearDown(self): + pass + + + def test_1_createAccounts(self, numberOfAccounts=5): + ''' + Create a bunch of user accounts + ''' + mdf = hashlib.md5() + mdf.update('password') + mdf_pass = mdf.hexdigest() + api = self.testClient.getApiClient() + for i in range(1, numberOfAccounts + 1): + acct = createAccount.createAccountCmd() + acct.accounttype = 0 + acct.firstname = 'user' + str(i) + acct.lastname = 'user' + str(i) + acct.password = mdf_pass + acct.username = 'user' + str(i) + acct.email = 'user@example.com' + acct.account = 'user' + str(i) + acct.domainid = 1 + acctResponse = api.createAccount(acct) + self.debug("successfully created account: %s, user: %s, id: %s"%(acctResponse.account, acctResponse.username, acctResponse.id)) + + + def test_2_createServiceOffering(self): + apiClient = self.testClient.getApiClient() + createSOcmd=createServiceOffering.createServiceOfferingCmd() + createSOcmd.name='Sample SO' + createSOcmd.displaytext='Sample SO' + createSOcmd.storagetype='shared' + createSOcmd.cpunumber=1 + createSOcmd.cpuspeed=100 + createSOcmd.memory=128 + createSOcmd.offerha='false' + createSOresponse = apiClient.createServiceOffering(createSOcmd) + return createSOresponse.id + + def deployCmd(self, account, service): + deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() + deployVmCmd.zoneid = 1 + deployVmCmd.account=account + deployVmCmd.domainid=1 + deployVmCmd.templateid=4 #CentOS Default Builtin + deployVmCmd.serviceofferingid=service + return deployVmCmd + + def listVmsInAccountCmd(self, acct): + api = self.testClient.getApiClient() + listVmCmd = listVirtualMachines.listVirtualMachinesCmd() + listVmCmd.account = acct + listVmCmd.zoneid = 1 + listVmCmd.domainid = 1 + listVmResponse = api.listVirtualMachines(listVmCmd) + return listVmResponse + + + def destroyVmCmd(self, key): + api = self.testClient.getApiClient() + destroyVmCmd = destroyVirtualMachine.destroyVirtualMachineCmd() + destroyVmCmd.id = key + api.destroyVirtualMachine(destroyVmCmd) + + + def test_3_stressDeploy(self): + ''' + Deploy 20 Vms in each account + ''' + service_id = self.test_2_createServiceOffering() + api = self.testClient.getApiClient() + for acct in range(1, 5): + [api.deployVirtualMachine(self.deployCmd('user'+str(acct), service_id)) for x in range(0,20)] + + @unittest.skip("testing") + def test_4_stressDestroy(self): + ''' + Cleanup all Vms in every account + ''' + api = self.testClient.getApiClient() + for acct in range(1, 6): + for vm in self.listVmsInAccountCmd('user'+str(acct)): + if vm is not None: + self.destroyVmCmd(vm.id) + + @unittest.skip("testing") + def test_5_combineStress(self): + for i in range(0, 5): + self.test_3_stressDeploy() + self.test_4_stressDestroy() + + 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 + ''' + cmds = [] + + if batchsize == 0: + self.testClient.submitCmdsAndWait(cmds) + else: + while len(z) > 0: + try: + newbatch = [cmds.pop() for b in range(batchsize)] #pop batchsize items + self.testClient.submitCmdsAndWait(newbatch) + except IndexError: + break diff --git a/tools/testClient/sandbox/kvm/tests/testScratch.py b/tools/testClient/sandbox/kvm/tests/testScratch.py new file mode 100644 index 00000000000..4b3ceb316b1 --- /dev/null +++ b/tools/testClient/sandbox/kvm/tests/testScratch.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +try: + import unittest2 as unittest +except ImportError: + import unittest + +import random +import hashlib +from cloudstackTestCase import * + +class Provision(cloudstackTestCase): + ''' + ''' + def setUp(self): + pass + + + def tearDown(self): + pass + + + def test_1_createAccounts(self, numberOfAccounts=5): + ''' + Create a bunch of user accounts + ''' + mdf = hashlib.md5() + mdf.update('password') + mdf_pass = mdf.hexdigest() + api = self.testClient.getApiClient() + for i in range(1, numberOfAccounts + 1): + acct = createAccount.createAccountCmd() + acct.accounttype = 0 + acct.firstname = 'user' + str(i) + acct.lastname = 'user' + str(i) + acct.password = mdf_pass + acct.username = 'user' + str(i) + acct.email = 'user@example.com' + acct.account = 'user' + str(i) + acct.domainid = 1 + acctResponse = api.createAccount(acct) + self.debug("successfully created account: %s, user: %s, id: %s"%(acctResponse.account, acctResponse.username, acctResponse.id)) + + + def test_2_createServiceOffering(self): + apiClient = self.testClient.getApiClient() + createSOcmd=createServiceOffering.createServiceOfferingCmd() + createSOcmd.name='Sample SO' + createSOcmd.displaytext='Sample SO' + createSOcmd.storagetype='shared' + createSOcmd.cpunumber=1 + createSOcmd.cpuspeed=100 + createSOcmd.memory=128 + createSOcmd.offerha='false' + createSOresponse = apiClient.createServiceOffering(createSOcmd) + return createSOresponse.id + + def deployCmd(self, account, service): + deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() + deployVmCmd.zoneid = 1 + deployVmCmd.account=account + deployVmCmd.domainid=1 + deployVmCmd.templateid=4 #CentOS Default Builtin + deployVmCmd.serviceofferingid=service + deployVmCmd.diskofferingid=3 #standard 5 GB disk + return deployVmCmd + + def listVmsInAccountCmd(self, acct): + api = self.testClient.getApiClient() + listVmCmd = listVirtualMachines.listVirtualMachinesCmd() + listVmCmd.account = acct + listVmCmd.zoneid = 1 + listVmCmd.domainid = 1 + listVmResponse = api.listVirtualMachines(listVmCmd) + return listVmResponse + + + def destroyVmCmd(self, key): + api = self.testClient.getApiClient() + destroyVmCmd = destroyVirtualMachine.destroyVirtualMachineCmd() + destroyVmCmd.id = key + api.destroyVirtualMachine(destroyVmCmd) + + + def test_3_stressDeploy(self): + ''' + Deploy 20 Vms in each account + ''' + service_id = self.test_2_createServiceOffering() + api = self.testClient.getApiClient() + for acct in range(1, 5): + [api.deployVirtualMachine(self.deployCmd('user'+str(acct), service_id)) for x in range(0,20)] + + def test_4_stressDestroy(self): + ''' + Cleanup all Vms in every account + ''' + api = self.testClient.getApiClient() + for acct in range(1, 6): + for vm in self.listVmsInAccountCmd('user'+str(acct)): + if vm is not None: + self.destroyVmCmd(vm.id) + + @unittest.skip("testing") + def test_5_combineStress(self): + for i in range(0, 5): + self.test_3_stressDeploy() + self.test_4_stressDestroy() + + 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 + ''' + cmds = [] + + if batchsize == 0: + self.testClient.submitCmdsAndWait(cmds) + else: + while len(z) > 0: + try: + newbatch = [cmds.pop() for b in range(batchsize)] #pop batchsize items + self.testClient.submitCmdsAndWait(newbatch) + except IndexError: + break diff --git a/tools/testClient/sandbox/simulator/sandbox.cfg b/tools/testClient/sandbox/simulator/sandbox.cfg new file mode 100644 index 00000000000..049787524af --- /dev/null +++ b/tools/testClient/sandbox/simulator/sandbox.cfg @@ -0,0 +1,346 @@ +{ + "zones": [ + { + "name": "Sandbox-Simulator", + "guestcidraddress": "10.1.1.0/24", + "dns2": "10.223.110.254", + "dns1": "4.2.2.2", + "vlan": "100-300", + "ipranges": [ + { + "startip": "172.1.2.2", + "endip": "172.1.2.200", + "netmask": "255.255.255.0", + "vlan": "30", + "gateway": "172.1.2.1" + } + ], + "networktype": "Advanced", + "pods": [ + { + "endip": "172.1.1.200", + "name": "POD0", + "startip": "172.1.1.2", + "netmask": "255.255.255.0", + "clusters": [ + { + "clustername": "POD1-CLUSTER1", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-1", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-2", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/1", + "name": "spool1" + } + ] + }, + { + "clustername": "POD1-CLUSTER2", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-3", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-4", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/2", + "name": "spool2" + } + ] + }, + { + "clustername": "POD1-CLUSTER3", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-5", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-6", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/3", + "name": "spool3" + } + ] + }, + { + "clustername": "POD1-CLUSTER4", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-7", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-8", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/4", + "name": "spool4" + } + ] + }, + { + "clustername": "POD1-CLUSTER5", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-9", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-10", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/5", + "name": "spool5" + } + ] + }, + { + "clustername": "POD1-CLUSTER6", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-11", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-12", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/6", + "name": "spool6" + } + ] + }, + { + "clustername": "POD1-CLUSTER7", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-13", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-14", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/7", + "name": "spool7" + } + ] + }, + { + "clustername": "POD1-CLUSTER8", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-15", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-16", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/8", + "name": "spool8" + } + ] + }, + { + "clustername": "POD1-CLUSTER9", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-17", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-18", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/9", + "name": "spool9" + } + ] + }, + { + "clustername": "POD1-CLUSTER10", + "hypervisor": "Simulator", + "hosts": [ + { + "username": "root", + "url": "http://sim/test-19", + "password": "password" + }, + { + "username": "root", + "url": "http://sim/test-20", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://172.16.24.32/export/path/10", + "name": "spool10" + } + ] + } + ], + "gateway": "172.1.1.1" + } + ], + "internaldns1": "10.147.28.6", + "internaldns2": "10.223.110.254", + "secondaryStorages": [ + { + "url": "nfs://172.16.25.32/secondary/path" + } + ] + } + ], + "dbSvr": { + "dbSvr": "10.147.28.40", + "passwd": "cloud", + "db": "cloud", + "port": 3306, + "user": "cloud" + }, + "logger": [ + { + "name": "TestClient", + "file": "/var/log/testclient.log" + }, + { + "name": "TestCase", + "file": "/var/log/testcase.log" + } + ], + "globalConfig": [ + { + "name": "use.user.concentrated.pod.allocation", + "value": "false" + }, + { + "name": "default.page.size", + "value": "10000" + }, + { + "name": "direct.agent.load.size", + "value": "1000" + }, + { + "name": "expunge.delay", + "value": "60" + }, + { + "name": "vm.allocation.algorithm", + "value": "random" + }, + { + "name": "check.pod.cidrs", + "value": "false" + }, + { + "name": "instance.name", + "value": "SIMQA" + }, + { + "name": "workers", + "value": "10" + }, + { + "name": "vm.op.wait.interval", + "value": "5" + }, + { + "name": "guest.domain.suffix", + "value": "sandbox.simulator" + }, + { + "name": "expunge.interval", + "value": "60" + }, + { + "name": "linkLocalIp.nums", + "value": "10" + }, + { + "name": "expunge.workers", + "value": "3" + } + ], + "mgtSvr": [ + { + "mgtSvrIp": "10.147.28.40", + "port": 8096 + } + ] +} \ No newline at end of file diff --git a/tools/testClient/sandbox/simulator/setup.py b/tools/testClient/sandbox/simulator/setup.py new file mode 100644 index 00000000000..194e8f716ea --- /dev/null +++ b/tools/testClient/sandbox/simulator/setup.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python + +''' +############################################################ +# Experimental state of scripts +# * Need to be reviewed +# * Only a sandbox +############################################################ +''' + +from optparse import OptionParser +from configGenerator import * +import random + + +def getGlobalSettings(): + global_settings = {'expunge.delay': '60', + 'expunge.interval': '60', + 'expunge.workers': '3', + 'workers': '10', + 'use.user.concentrated.pod.allocation': 'false', + 'vm.allocation.algorithm': 'random', + 'vm.op.wait.interval': '5', + 'guest.domain.suffix': 'sandbox.simulator', + 'instance.name': 'SIMQA', + 'direct.agent.load.size': '1000', + 'default.page.size': '10000', + 'linkLocalIp.nums': '10', + 'check.pod.cidrs': 'false', + } + for k, v in global_settings.iteritems(): + cfg = configuration() + cfg.name = k + cfg.value = v + yield cfg + + +def describeResources(dbnode='localhost', mshost='localhost'): + zs = cloudstackConfiguration() + numberofpods = 1 + + clustersPerPod = 10 + hostsPerCluster = 2 + + z = zone() + z.dns1 = '4.2.2.2' + z.dns2 = '10.223.110.254' + z.internaldns1 = '10.147.28.6' + z.internaldns2 = '10.223.110.254' + z.name = 'Sandbox-Simulator' + z.networktype = 'Advanced' + z.guestcidraddress = '10.1.1.0/24' + z.vlan='100-300' + + p = pod() + p.name = 'POD0' + p.gateway = '172.1.1.1' + p.startip = '172.1.1.2' + p.endip = '172.1.1.200' + p.netmask = '255.255.255.0' + + v = iprange() + v.vlan = '30' + v.gateway = '172.1.2.1' + v.startip = '172.1.2.2' + v.endip = '172.1.2.200' + v.netmask = '255.255.255.0' + + curhost = 1 + for i in range(1, clustersPerPod + 1): + c = cluster() + c.clustername = 'POD1-CLUSTER' + str(i) + c.hypervisor = 'Simulator' + c.clustertype = 'CloudManaged' + + for j in range(1, hostsPerCluster + 1): + h = host() + h.username = 'root' + h.password = 'password' + h.url = 'http://sim/test-%d'%(curhost) + c.hosts.append(h) + curhost = curhost + 1 + + ps = primaryStorage() + ps.name = 'spool'+str(i) + ps.url = 'nfs://172.16.24.32/export/path/'+str(i) + c.primaryStorages.append(ps) + p.clusters.append(c) + + + secondary = secondaryStorage() + secondary.url = 'nfs://172.16.25.32/secondary/path' + + z.pods.append(p) + z.ipranges.append(v) + z.secondaryStorages.append(secondary) + zs.zones.append(z) + + '''Add mgt server''' + mgt = managementServer() + mgt.mgtSvrIp = mshost + zs.mgtSvr.append(mgt) + + '''Add a database''' + db = dbServer() + db.dbSvr = opts.dbnode + zs.dbSvr = db + + '''Add some configuration''' + [zs.globalConfig.append(cfg) for cfg in getGlobalSettings()] + + ''''add loggers''' + testClientLogger = logger() + testClientLogger.name = 'TestClient' + testClientLogger.file = '/var/log/testclient.log' + + testCaseLogger = logger() + testCaseLogger.name = 'TestCase' + testCaseLogger.file = '/var/log/testcase.log' + + zs.logger.append(testClientLogger) + zs.logger.append(testCaseLogger) + return zs + + +if __name__ == '__main__': + parser = OptionParser() + parser.add_option('-o', '--output', action='store', default='./sandbox.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') + + (opts, args) = parser.parse_args() + cfg = describeResources(opts.dbnode, opts.mshost) + generate_setup_config(cfg, opts.output) diff --git a/tools/testClient/sandbox/simulator/tests/testProvision.py b/tools/testClient/sandbox/simulator/tests/testProvision.py new file mode 100644 index 00000000000..5388d1041ec --- /dev/null +++ b/tools/testClient/sandbox/simulator/tests/testProvision.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +try: + import unittest2 as unittest +except ImportError: + import unittest + +import random +import hashlib +from cloudstackTestCase import * + +class Provision(cloudstackTestCase): + ''' + ''' + def setUp(self): + pass + + + def tearDown(self): + pass + + + def test_1_createAccounts(self, numberOfAccounts=5): + ''' + Create a bunch of user accounts + ''' + mdf = hashlib.md5() + mdf.update('password') + mdf_pass = mdf.hexdigest() + api = self.testClient.getApiClient() + for i in range(1, numberOfAccounts + 1): + acct = createAccount.createAccountCmd() + acct.accounttype = 0 + acct.firstname = 'user' + str(i) + acct.lastname = 'user' + str(i) + acct.password = mdf_pass + acct.username = 'user' + str(i) + acct.email = 'user@example.com' + acct.account = 'user' + str(i) + acct.domainid = 1 + acctResponse = api.createAccount(acct) + self.debug("successfully created account: %s, user: %s, id: %s"%(acctResponse.account, acctResponse.username, acctResponse.id)) + + + def test_2_createServiceOffering(self): + apiClient = self.testClient.getApiClient() + createSOcmd=createServiceOffering.createServiceOfferingCmd() + createSOcmd.name='Sample SO' + createSOcmd.displaytext='Sample SO' + createSOcmd.storagetype='shared' + createSOcmd.cpunumber=1 + createSOcmd.cpuspeed=100 + createSOcmd.memory=128 + createSOcmd.offerha='false' + createSOresponse = apiClient.createServiceOffering(createSOcmd) + return createSOresponse.id + + def deployCmd(self, account, service): + deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() + deployVmCmd.zoneid = 1 + deployVmCmd.hypervisor='Simulator' + deployVmCmd.account=account + deployVmCmd.domainid=1 + deployVmCmd.templateid=10 + deployVmCmd.serviceofferingid=service + return deployVmCmd + + def listVmsInAccountCmd(self, acct): + api = self.testClient.getApiClient() + listVmCmd = listVirtualMachines.listVirtualMachinesCmd() + listVmCmd.account = acct + listVmCmd.zoneid = 1 + listVmCmd.domainid = 1 + listVmResponse = api.listVirtualMachines(listVmCmd) + return listVmResponse + + + def destroyVmCmd(self, key): + api = self.testClient.getApiClient() + destroyVmCmd = destroyVirtualMachine.destroyVirtualMachineCmd() + destroyVmCmd.id = key + api.destroyVirtualMachine(destroyVmCmd) + + + def test_3_stressDeploy(self): + ''' + Deploy 20 Vms in each account + ''' + service_id = self.test_2_createServiceOffering() + api = self.testClient.getApiClient() + for acct in range(1, 5): + [api.deployVirtualMachine(self.deployCmd('user'+str(acct), service_id)) for x in range(0,20)] + + def test_4_stressDestroy(self): + ''' + Cleanup all Vms in every account + ''' + api = self.testClient.getApiClient() + for acct in range(1, 6): + for vm in self.listVmsInAccountCmd('user'+str(acct)): + if vm is not None: + self.destroyVmCmd(vm.id) + + def test_5_combineStress(self): + for i in range(0, 5): + self.test_3_stressDeploy() + self.test_4_stressDestroy() + + 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 + ''' + cmds = [] + + if batchsize == 0: + self.testClient.submitCmdsAndWait(cmds) + else: + while len(z) > 0: + try: + newbatch = [cmds.pop() for b in range(batchsize)] #pop batchsize items + self.testClient.submitCmdsAndWait(newbatch) + except IndexError: + break diff --git a/tools/testClient/sandbox/xen/sandbox.xen.cfg b/tools/testClient/sandbox/xen/sandbox.xen.cfg new file mode 100644 index 00000000000..aea32504c8b --- /dev/null +++ b/tools/testClient/sandbox/xen/sandbox.xen.cfg @@ -0,0 +1,146 @@ +{ + "zones": [ + { + "name": "Sandbox-XEN", + "guestcidraddress": "10.1.1.0/24", + "dns2": "10.223.110.254", + "dns1": "10.147.28.6", + "vlan": "665-669", + "ipranges": [ + { + "startip": "10.147.32.110", + "endip": "10.147.32.114", + "netmask": "255.255.255.0", + "vlan": "32", + "gateway": "10.147.32.1" + } + ], + "networktype": "Advanced", + "pods": [ + { + "endip": "10.147.31.114", + "name": "POD1", + "startip": "10.147.31.110", + "netmask": "255.255.255.0", + "clusters": [ + { + "clustername": "XEN0", + "hypervisor": "XenServer", + "hosts": [ + { + "username": "root", + "url": "http://None", + "password": "password" + } + ], + "clustertype": "CloudManaged", + "primaryStorages": [ + { + "url": "nfs://10.147.28.6/export/home/prasanna/taxila", + "name": "PS0" + } + ] + } + ], + "gateway": "10.147.31.1" + } + ], + "internaldns1": "10.147.28.6", + "internaldns2": "10.223.110.254", + "secondaryStorages": [ + { + "url": "nfs://10.147.28.6/export/home/prasanna/secondary" + } + ] + } + ], + "dbSvr": { + "dbSvr": "10.147.32.113", + "passwd": "cloud", + "db": "cloud", + "port": 3306, + "user": "cloud" + }, + "logger": [ + { + "name": "TestClient", + "file": "/var/log/testclient.log" + }, + { + "name": "TestCase", + "file": "/var/log/testcase.log" + } + ], + "globalConfig": [ + { + "name": "storage.cleanup.interval", + "value": "300" + }, + { + "name": "vm.op.wait.interval", + "value": "5" + }, + { + "name": "default.page.size", + "value": "10000" + }, + { + "name": "instance.name", + "value": "XENQA" + }, + { + "name": "workers", + "value": "10" + }, + { + "name": "use.user.concentrated.pod.allocation", + "value": "false" + }, + { + "name": "account.cleanup.interval", + "value": "600" + }, + { + "name": "guest.domain.suffix", + "value": "sandbox.xen" + }, + { + "name": "expunge.delay", + "value": "60" + }, + { + "name": "vm.allocation.algorithm", + "value": "random" + }, + { + "name": "expunge.interval", + "value": "60" + }, + { + "name": "linkLocalIp.nums", + "value": "10" + }, + { + "name": "expunge.workers", + "value": "3" + }, + { + "name": "check.pod.cidrs", + "value": "true" + }, + { + "name": "secstorage.allowed.internal.sites", + "value": "10.147.28.0/24" + }, + { + "name": "direct.agent.load.size", + "value": "1000" + } + ], + "mgtSvr": [ + { + "mgtSvrIp": "10.147.32.113", + "port": 8096 + } + ] +} \ No newline at end of file diff --git a/tools/testClient/sandbox/xen/setup.py b/tools/testClient/sandbox/xen/setup.py new file mode 100644 index 00000000000..a427caa603c --- /dev/null +++ b/tools/testClient/sandbox/xen/setup.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python + +''' +############################################################ +# Experimental state of scripts +# * Need to be reviewed +# * Only a sandbox +# * DNS settings are internal +# * VLAN settings are internal +# * IP Ranges are internal +# * Storage share is internal +############################################################ +''' + +from optparse import OptionParser +from configGenerator import * +import random + + +def getGlobalSettings(): + global_settings = {'expunge.delay': '60', + 'expunge.interval': '60', + 'storage.cleanup.interval': '300', + 'account.cleanup.interval': '600', + 'expunge.workers': '3', + 'workers': '10', + 'use.user.concentrated.pod.allocation': 'false', + 'vm.allocation.algorithm': 'random', + 'vm.op.wait.interval': '5', + 'guest.domain.suffix': 'sandbox.xen', + 'instance.name': 'XENQA', + 'direct.agent.load.size': '1000', + 'default.page.size': '10000', + 'linkLocalIp.nums': '10', + 'check.pod.cidrs': 'true', + 'secstorage.allowed.internal.sites': '10.147.28.0/24', + } + for k, v in global_settings.iteritems(): + cfg = configuration() + cfg.name = k + cfg.value = v + yield cfg + + +def describeResources(dbnode='localhost', mshost='localhost', xenhost='localhost'): + zs = cloudstackConfiguration() + numberofpods = 1 + + clustersPerPod = 1 + + z = zone() + z.dns1 = '10.147.28.6' + z.dns2 = '10.223.110.254' + z.internaldns1 = '10.147.28.6' + z.internaldns2 = '10.223.110.254' + z.name = 'Sandbox-XEN' + z.networktype = 'Advanced' + z.guestcidraddress = '10.1.1.0/24' + z.vlan='665-669' + + p = pod() + p.name = 'POD1' + p.gateway = '10.147.31.1' + p.startip = '10.147.31.110' + p.endip = '10.147.31.114' + p.netmask = '255.255.255.0' + + v = iprange() + v.vlan = '32' + v.gateway = '10.147.32.1' + v.startip = '10.147.32.110' + v.endip = '10.147.32.114' + v.netmask = '255.255.255.0' + + c = cluster() + c.clustername = 'XEN0' + c.hypervisor = 'XenServer' + c.clustertype = 'CloudManaged' + + h = host() + h.username = 'root' + h.password = 'password' + h.url = 'http://%s'%(xenhost) + c.hosts.append(h) + + ps = primaryStorage() + ps.name = 'PS0' + ps.url = 'nfs://10.147.28.6/export/home/prasanna/taxila' ## TODO: Make this configurable + c.primaryStorages.append(ps) + p.clusters.append(c) + + secondary = secondaryStorage() + secondary.url = 'nfs://10.147.28.6/export/home/prasanna/secondary' ## TODO: Make this configurable + + z.pods.append(p) + z.ipranges.append(v) + z.secondaryStorages.append(secondary) + zs.zones.append(z) + + '''Add mgt server''' + mgt = managementServer() + mgt.mgtSvrIp = mshost + zs.mgtSvr.append(mgt) + + '''Add a database''' + db = dbServer() + db.dbSvr = opts.dbnode + zs.dbSvr = db + + '''Add some configuration''' + [zs.globalConfig.append(cfg) for cfg in getGlobalSettings()] + + ''''add loggers''' + testClientLogger = logger() + testClientLogger.name = 'TestClient' + testClientLogger.file = '/var/log/testclient.log' + + testCaseLogger = logger() + testCaseLogger.name = 'TestCase' + testCaseLogger.file = '/var/log/testcase.log' + + zs.logger.append(testClientLogger) + zs.logger.append(testCaseLogger) + return zs + + +if __name__ == '__main__': + parser = OptionParser() + parser.add_option('-o', '--output', action='store', default='./sandbox.xen.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('-k', '--hypervisor', dest='hypervisor', help='hostname/ip of hypervisor server', action='store') + + (opts, args) = parser.parse_args() + cfg = describeResources(opts.dbnode, opts.mshost, opts.hypervisor) + generate_setup_config(cfg, opts.output) diff --git a/tools/testClient/sandbox/xen/tests/testProvision.py b/tools/testClient/sandbox/xen/tests/testProvision.py new file mode 100644 index 00000000000..16610d16209 --- /dev/null +++ b/tools/testClient/sandbox/xen/tests/testProvision.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python +try: + import unittest2 as unittest +except ImportError: + import unittest + +import random +import hashlib +from cloudstackTestCase import * + +class Provision(cloudstackTestCase): + ''' + ''' + def setUp(self): + pass + + + def tearDown(self): + pass + + + def test_1_createAccounts(self, numberOfAccounts=5): + ''' + Create a bunch of user accounts + ''' + mdf = hashlib.md5() + mdf.update('password') + mdf_pass = mdf.hexdigest() + api = self.testClient.getApiClient() + for i in range(1, numberOfAccounts + 1): + acct = createAccount.createAccountCmd() + acct.accounttype = 0 + acct.firstname = 'user' + str(i) + acct.lastname = 'user' + str(i) + acct.password = mdf_pass + acct.username = 'user' + str(i) + acct.email = 'user@example.com' + acct.account = 'user' + str(i) + acct.domainid = 1 + acctResponse = api.createAccount(acct) + self.debug("successfully created account: %s, user: %s, id: %s"%(acctResponse.account, acctResponse.username, acctResponse.id)) + + + def test_2_createServiceOffering(self): + apiClient = self.testClient.getApiClient() + createSOcmd=createServiceOffering.createServiceOfferingCmd() + createSOcmd.name='Sample SO' + createSOcmd.displaytext='Sample SO' + createSOcmd.storagetype='shared' + createSOcmd.cpunumber=1 + createSOcmd.cpuspeed=100 + createSOcmd.memory=128 + createSOcmd.offerha='false' + createSOresponse = apiClient.createServiceOffering(createSOcmd) + return createSOresponse.id + + def deployCmd(self, account, service): + deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() + deployVmCmd.zoneid = 1 + deployVmCmd.account=account + deployVmCmd.domainid=1 + deployVmCmd.templateid=2 + deployVmCmd.serviceofferingid=service + return deployVmCmd + + def listVmsInAccountCmd(self, acct): + api = self.testClient.getApiClient() + listVmCmd = listVirtualMachines.listVirtualMachinesCmd() + listVmCmd.account = acct + listVmCmd.zoneid = 1 + listVmCmd.domainid = 1 + listVmResponse = api.listVirtualMachines(listVmCmd) + return listVmResponse + + + def destroyVmCmd(self, key): + api = self.testClient.getApiClient() + destroyVmCmd = destroyVirtualMachine.destroyVirtualMachineCmd() + destroyVmCmd.id = key + api.destroyVirtualMachine(destroyVmCmd) + + + def test_3_stressDeploy(self): + ''' + Deploy 20 Vms in each account + ''' + service_id = self.test_2_createServiceOffering() + api = self.testClient.getApiClient() + for acct in range(1, 5): + [api.deployVirtualMachine(self.deployCmd('user'+str(acct), service_id)) for x in range(0,20)] + + def test_4_stressDestroy(self): + ''' + Cleanup all Vms in every account + ''' + api = self.testClient.getApiClient() + for acct in range(1, 6): + for vm in self.listVmsInAccountCmd('user'+str(acct)): + if vm is not None: + self.destroyVmCmd(vm.id) + + def test_5_combineStress(self): + for i in range(0, 5): + self.test_3_stressDeploy() + self.test_4_stressDestroy() + + 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 + ''' + cmds = [] + + if batchsize == 0: + self.testClient.submitCmdsAndWait(cmds) + else: + while len(z) > 0: + try: + newbatch = [cmds.pop() for b in range(batchsize)] #pop batchsize items + self.testClient.submitCmdsAndWait(newbatch) + except IndexError: + break diff --git a/tools/testClient/sandbox/xen/tests/testScratch.py b/tools/testClient/sandbox/xen/tests/testScratch.py new file mode 100644 index 00000000000..9461bb3d55c --- /dev/null +++ b/tools/testClient/sandbox/xen/tests/testScratch.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +try: + import unittest2 as unittest +except ImportError: + import unittest + +import random +import hashlib +from cloudstackTestCase import * + +class Provision(cloudstackTestCase): + ''' + ''' + def setUp(self): + pass + + + def tearDown(self): + pass + + + def test_1_createAccounts(self, numberOfAccounts=5): + ''' + Create a bunch of user accounts + ''' + mdf = hashlib.md5() + mdf.update('password') + mdf_pass = mdf.hexdigest() + api = self.testClient.getApiClient() + for i in range(1, numberOfAccounts + 1): + acct = createAccount.createAccountCmd() + acct.accounttype = 0 + acct.firstname = 'user' + str(i) + acct.lastname = 'user' + str(i) + acct.password = mdf_pass + acct.username = 'user' + str(i) + acct.email = 'user@example.com' + acct.account = 'user' + str(i) + acct.domainid = 1 + acctResponse = api.createAccount(acct) + self.debug("successfully created account: %s, user: %s, id: %s"%(acctResponse.account, acctResponse.username, acctResponse.id)) + + + def test_2_createServiceOffering(self): + apiClient = self.testClient.getApiClient() + createSOcmd=createServiceOffering.createServiceOfferingCmd() + createSOcmd.name='Sample SO' + createSOcmd.displaytext='Sample SO' + createSOcmd.storagetype='shared' + createSOcmd.cpunumber=1 + createSOcmd.cpuspeed=100 + createSOcmd.memory=128 + createSOcmd.offerha='false' + createSOresponse = apiClient.createServiceOffering(createSOcmd) + return createSOresponse.id + + def deployCmd(self, account, service): + deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() + deployVmCmd.zoneid = 1 + deployVmCmd.account=account + deployVmCmd.domainid=1 + deployVmCmd.templateid=2 #CentOS Default Builtin + deployVmCmd.serviceofferingid=service + deployVmCmd.diskofferingid=3 #standard 5 GB disk + return deployVmCmd + + def listVmsInAccountCmd(self, acct): + api = self.testClient.getApiClient() + listVmCmd = listVirtualMachines.listVirtualMachinesCmd() + listVmCmd.account = acct + listVmCmd.zoneid = 1 + listVmCmd.domainid = 1 + listVmResponse = api.listVirtualMachines(listVmCmd) + return listVmResponse + + + def destroyVmCmd(self, key): + api = self.testClient.getApiClient() + destroyVmCmd = destroyVirtualMachine.destroyVirtualMachineCmd() + destroyVmCmd.id = key + api.destroyVirtualMachine(destroyVmCmd) + + + def test_3_stressDeploy(self): + ''' + Deploy 20 Vms in each account + ''' + service_id = self.test_2_createServiceOffering() + api = self.testClient.getApiClient() + for acct in range(1, 5): + [api.deployVirtualMachine(self.deployCmd('user'+str(acct), service_id)) for x in range(0,2)] + + def test_4_stressDestroy(self): + ''' + Cleanup all Vms in every account + ''' + api = self.testClient.getApiClient() + for acct in range(1, 5): + for vm in self.listVmsInAccountCmd('user'+str(acct)): + if vm is not None: + self.destroyVmCmd(vm.id) + + @unittest.skip("testing") + def test_5_combineStress(self): + for i in range(0, 5): + self.test_3_stressDeploy() + self.test_4_stressDestroy() + + 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 + ''' + cmds = [] + + if batchsize == 0: + self.testClient.submitCmdsAndWait(cmds) + else: + while len(z) > 0: + try: + newbatch = [cmds.pop() for b in range(batchsize)] #pop batchsize items + self.testClient.submitCmdsAndWait(newbatch) + except IndexError: + break diff --git a/tools/testClient/unitTest/test_advanced.py b/tools/testClient/unitTest/test_advanced.py index c8992bbe893..9cbd94f5050 100644 --- a/tools/testClient/unitTest/test_advanced.py +++ b/tools/testClient/unitTest/test_advanced.py @@ -92,4 +92,4 @@ if __name__ == "__main__": cmd.templateid = listtmresponse[0].id res = api.deployVirtualMachine(cmd) - vmId.append(res.id) \ No newline at end of file + vmId.append(res.id)