|
| 1 | +#!/usr/bin/env python |
| 2 | +try: |
| 3 | + import unittest2 as unittest |
| 4 | +except ImportError: |
| 5 | + import unittest |
| 6 | + |
| 7 | +import random |
| 8 | +import hashlib |
| 9 | +from cloudstackTestCase import * |
| 10 | + |
| 11 | +class Provision(cloudstackTestCase): |
| 12 | + ''' |
| 13 | + ''' |
| 14 | + def setUp(self): |
| 15 | + pass |
| 16 | + |
| 17 | + |
| 18 | + def tearDown(self): |
| 19 | + pass |
| 20 | + |
| 21 | + |
| 22 | + def test_createAccounts(self, numberOfAccounts=5): |
| 23 | + ''' |
| 24 | + Create a bunch of user accounts |
| 25 | + ''' |
| 26 | + mdf = hashlib.md5() |
| 27 | + mdf.update('password') |
| 28 | + mdf_pass = mdf.hexdigest() |
| 29 | + api = self.testClient.getApiClient() |
| 30 | + for i in range(1, numberOfAccounts + 1): |
| 31 | + acct = createAccount.createAccountCmd() |
| 32 | + acct.accounttype = 0 |
| 33 | + acct.firstname = 'user' + str(i) |
| 34 | + acct.lastname = 'user' + str(i) |
| 35 | + acct.password = mdf_pass |
| 36 | + acct.username = 'user' + str(i) |
| 37 | + acct.email = 'user@example.com' |
| 38 | + acct.account = 'user' + str(i) |
| 39 | + acct.domainid = 1 |
| 40 | + acctResponse = api.createAccount(acct) |
| 41 | + self.debug("successfully created account: %s, user: %s, id: %s"%(acctResponse.account, acctResponse.username, acctResponse.id)) |
| 42 | + |
| 43 | + |
| 44 | + def deployCmd(self, account): |
| 45 | + deployVmCmd = deployVirtualMachine.deployVirtualMachineCmd() |
| 46 | + deployVmCmd.zoneid = 1 |
| 47 | + deployVmCmd.hypervisor='Simulator' |
| 48 | + deployVmCmd.account=account |
| 49 | + deployVmCmd.domainid=1 |
| 50 | + deployVmCmd.templateid=10 |
| 51 | + deployVmCmd.serviceofferingid=7 |
| 52 | + return deployVmCmd |
| 53 | + |
| 54 | + |
| 55 | + def listVmsInAccountCmd(self, acct): |
| 56 | + api = self.testClient.getApiClient() |
| 57 | + listVmCmd = listVirtualMachines.listVirtualMachinesCmd() |
| 58 | + listVmCmd.account = acct |
| 59 | + listVmCmd.zoneid = 1 |
| 60 | + listVmCmd.domainid = 1 |
| 61 | + listVmResponse = api.listVirtualMachines(listVmCmd) |
| 62 | + self.debug(listVmResponse) |
| 63 | + return listVmResponse |
| 64 | + |
| 65 | + |
| 66 | + def destroyVmCmd(self, key): |
| 67 | + api = self.testClient.getApiClient() |
| 68 | + destroyVmCmd = destroyVirtualMachine.destroyVirtualMachineCmd() |
| 69 | + destroyVmCmd.id = key |
| 70 | + api.destroyVirtualMachine(destroyVmCmd) |
| 71 | + |
| 72 | + |
| 73 | + def test_stressDeploy(self): |
| 74 | + ''' |
| 75 | + Deploy 20 Vms in each account |
| 76 | + ''' |
| 77 | + api = self.testClient.getApiClient() |
| 78 | + for acct in range(1, 5): |
| 79 | + [api.deployVirtualMachine(self.deployCmd('user'+str(acct))) for x in range(0,20)] |
| 80 | + |
| 81 | + def test_stressDestroy(self): |
| 82 | + ''' |
| 83 | + Cleanup all Vms in every account |
| 84 | + ''' |
| 85 | + api = self.testClient.getApiClient() |
| 86 | + for acct in range(1, 6): |
| 87 | + for vm in self.listVmsInAccountCmd('user'+str(acct)): |
| 88 | + self.destroyVmCmd(vm.id) |
| 89 | + |
| 90 | + def test_combineStress(self): |
| 91 | + for i in range(0, 5): |
| 92 | + self.test_stressDestroy() |
| 93 | + self.test_stressDeploy() |
| 94 | + |
| 95 | + def deployN(self,nargs=300,batchsize=0): |
| 96 | + ''' |
| 97 | + Deploy Nargs number of VMs concurrently in batches of size {batchsize}. |
| 98 | + When batchsize is 0 all Vms are deployed in one batch |
| 99 | + VMs will be deployed in 5:2:6 ratio |
| 100 | + ''' |
| 101 | + cmds = [] |
| 102 | + |
| 103 | + if batchsize == 0: |
| 104 | + self.testClient.submitCmdsAndWait(cmds) |
| 105 | + else: |
| 106 | + while len(z) > 0: |
| 107 | + try: |
| 108 | + newbatch = [cmds.pop() for b in range(batchsize)] #pop batchsize items |
| 109 | + self.testClient.submitCmdsAndWait(newbatch) |
| 110 | + except IndexError: |
| 111 | + break |
| 112 | + |
0 commit comments