From 259ae4831e37198c9c2230196e1be88242291cd4 Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Thu, 25 Aug 2011 18:25:39 +0530 Subject: [PATCH 1/2] correcting indentation problems with python --- agent-simulator/scripts/zucchini/setup.py | 60 +++++++++---------- .../scripts/zucchini/tests/testProvision.py | 4 +- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/agent-simulator/scripts/zucchini/setup.py b/agent-simulator/scripts/zucchini/setup.py index 8fb5f911b72..bd2b92265d1 100644 --- a/agent-simulator/scripts/zucchini/setup.py +++ b/agent-simulator/scripts/zucchini/setup.py @@ -58,7 +58,7 @@ def getGlobalSettings(): 'systemvm.use.local.storage':'true', 'use.local.storage':'true', 'check.pod.cidrs':'false', - } + } for k,v in global_settings.iteritems(): cfg=configuration() cfg.name=k @@ -69,33 +69,31 @@ def podIpRangeGenerator(): x=1 y=2 while 1: - if y == 256: + if y == 255: x=x+1 - if x == 256: + if x == 255: + x=1 break y=1 y=y+1 #pod mangement network - yield ('172.'+str(x)+'.'+str(y)+'.129', - '172.'+str(x)+'.'+str(y)+'.130', - '172.'+str(x)+'.'+str(y)+'.189') + yield ('172.'+str(x)+'.'+str(y)+'.129', '172.'+str(x)+'.'+str(y)+'.130', '172.'+str(x)+'.'+str(y)+'.189') def vlanIpRangeGenerator(): x=1 y=2 while 1: - if y == 256: + if y == 255: x=x+1 - if x==256: + if x==255: + x=1 break y=1 y=y+1 #vlan ip range - yield ('172.'+str(x)+'.'+str(y)+'.129', - '172.'+str(x)+'.'+str(y)+'.190', - '172.'+str(x)+'.'+str(y)+'.249') - + yield ('172.'+str(x)+'.'+str(y)+'.129', '172.'+str(x)+'.'+str(y)+'.190', '172.'+str(x)+'.'+str(y)+'.249') + def describeZyngaResources(numberOfAgents=1300, dbnode='localhost', mshost='localhost', randomize=False): zs=cloudstackConfiguration() @@ -106,7 +104,7 @@ def describeZyngaResources(numberOfAgents=1300, dbnode='localhost', mshost='loca clustersPerPod=10 hostsPerPod=10 - + z = zone() z.dns1 = '4.2.2.2' z.dns2 = '192.168.110.254' @@ -114,12 +112,13 @@ def describeZyngaResources(numberOfAgents=1300, dbnode='localhost', mshost='loca z.internaldns2 = '192.168.110.254' z.name = 'Zynga' z.networktype = 'Basic' - + hosttags=['TAG1' for x in range(tagOneHosts)] + ['TAG2' for x in range(tagTwoHosts)] + ['TAG3' for x in range(tagThreeHosts)] if randomize: - random.shuffle(hosttags) #randomize the host distribution - curhost=0 - curpod=0 + random.shuffle(hosttags) #randomize the host distribution + curhost=0 + curpod=0 + for podRange,vlanRange in zip(podIpRangeGenerator(), vlanIpRangeGenerator()): p = pod() curpod=curpod+1 @@ -141,12 +140,12 @@ def describeZyngaResources(numberOfAgents=1300, dbnode='localhost', mshost='loca c.clustername = 'POD'+str(curpod)+'-CLUSTER'+str(i) c.hypervisor = 'Simulator' c.clustertype = 'CloudManaged' - + try: h = host() h.username = 'root' h.password = 'password' - h.url = "http://sim/%d/cpucore=4&cpuspeed=8000&memory=%d&localstorage=%d"%(i,8*1024*1024*1024,1*1024*1024*1024*1024) + h.url = "http://sim/test-%d"%(curhost) h.hosttags = hosttags.pop() c.hosts.append(h) curhost=curhost+1 @@ -162,47 +161,48 @@ def describeZyngaResources(numberOfAgents=1300, dbnode='localhost', mshost='loca secondary.url = 'nfs://172.16.25.32/secondary/path' z.secondaryStorages.append(secondary) zs.zones.append(z) - + '''Add mgt server''' mgt = managementServer() mgt.mgtSvrIp = mshost #could be the LB balancing the cluster of management server as well 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('-h','--host',dest='host',help='location of management server(s) or load-balancer') + # 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('-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'] for m in mandatories: - if not opts.__dict__[m]: - print "mandatory option missing" + if not opts.__dict__[m]: + print "mandatory option missing" + cfg = describeZyngaResources(int(opts.agents), opts.dbnode, opts.mshost, opts.randomize) generate_setup_config(cfg, opts.output) diff --git a/agent-simulator/scripts/zucchini/tests/testProvision.py b/agent-simulator/scripts/zucchini/tests/testProvision.py index 21acb6e33df..49b696d361e 100644 --- a/agent-simulator/scripts/zucchini/tests/testProvision.py +++ b/agent-simulator/scripts/zucchini/tests/testProvision.py @@ -59,7 +59,7 @@ class Provision(unittest.case.TestCase): deployVmCmd.serviceofferingid=solist[tag] deployVmCmd.account='admin' deployVmCmd.domainid=1 - deployVmCmd.templateid=2 + deployVmCmd.templateid=10 return deployVmCmd def deployN(self,nargs=300,batchsize=0): @@ -90,7 +90,7 @@ class Provision(unittest.case.TestCase): def test_bulkDeploy(self): deployN(130,0) - deployN(nargs=3000,batchsize=100) + deployN(nargs=9000,batchsize=100) From 345f28f9e4e20e9f546099991e5e15a2860b4f64 Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Thu, 25 Aug 2011 19:48:04 +0530 Subject: [PATCH 2/2] a. Test Discovery is only found in python 2.7+. unittest2 makes it backwards compatible for python 2.4-2.6 b. Adding traceback from pymysql to debug problems in connecting with database --- tools/testClient/TestCaseExecuteEngine.py | 8 ++++++-- tools/testClient/dbConnection.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/testClient/TestCaseExecuteEngine.py b/tools/testClient/TestCaseExecuteEngine.py index 522c52417ba..059e7556637 100644 --- a/tools/testClient/TestCaseExecuteEngine.py +++ b/tools/testClient/TestCaseExecuteEngine.py @@ -1,4 +1,8 @@ -import unittest +try: + import unittest2 as unittest +except ImportError: + import unittest + from functools import partial import os import sys @@ -37,4 +41,4 @@ class TestCaseExecuteEngine(object): unittest.TextTestRunner(stream=self.testResultLogFile, verbosity=2).run(suite) - \ No newline at end of file + diff --git a/tools/testClient/dbConnection.py b/tools/testClient/dbConnection.py index f4748f3c909..e6135edf00f 100644 --- a/tools/testClient/dbConnection.py +++ b/tools/testClient/dbConnection.py @@ -2,6 +2,7 @@ import pymysql import cloudstackException import sys import os +import traceback class dbConnection(object): def __init__(self, host="localhost", port=3306, user='cloud', passwd='cloud', db='cloud'): self.host = host @@ -13,6 +14,7 @@ class dbConnection(object): try: self.db = pymysql.Connect(host=host, port=port, user=user, passwd=passwd, db=db) except: + traceback.print_exc() raise cloudstackException.InvalidParameterException(sys.exc_info()) def __copy__(self): @@ -73,4 +75,4 @@ if __name__ == "__main__": for i in range(10): result = db.execute("select job_status, created, last_updated from async_job where id=%d"%i) print result - \ No newline at end of file +