2012-04-03 04:50:05 -07:00

107 lines
3.8 KiB
Python
Executable File

# Copyright 2012 Citrix Systems, Inc. Licensed under the
# Apache License, Version 2.0 (the "License"); you may not use this
# file except in compliance with the License. Citrix Systems, Inc.
# reserves all rights not expressly granted by the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Automatically generated by addcopyright.py at 04/03/2012
'''
Created on Oct 18, 2011
@author: frank
'''
from cloudstackTestCase import *
from cloudstackAPI import *
import uuid
import threading
import random
import time
class Task(threading.Thread):
def __init__(self, func, param=None):
super(Task, self).__init__()
self.func = func
self.param = param
def run(self):
self.func(self.param)
def doTask(self):
self.start()
class TestDeploy100Hosts(cloudstackTestCase):
hosts = []
def deployHost(self, url):
apiClient = self.testClient.getApiClient()
addHostCmd = addHost.addHostCmd()
addHostCmd.hypervisor = "simulator"
addHostCmd.clusterid = 1
addHostCmd.zoneid = 1
addHostCmd.podid = 1
addHostCmd.url = "http://sim/%s"%url
addHostCmd.username = "placeholder"
addHostCmd.password = "placeholder"
addHostResponce = apiClient.addHost(addHostCmd)
return addHostResponce[0].id
def randomCancelMaintenance(self):
def run(param):
while(1):
try:
interval = random.randint(1, 2)
time.sleep(interval)
if len(self.hosts) == 0:
continue
index = random.randint(0, len(self.hosts)-1)
hostId = self.hosts[index]
apiClient = self.testClient.getApiClient()
cMaintainCmd = cancelHostMaintenance.cancelHostMaintenanceCmd()
cMaintainCmd.id = hostId
response = apiClient.cancelHostMaintenance(cMaintainCmd)
id = response.id
print "Host %s cancelled maintenance mode" % id
except Exception, e:
print e
t = Task(run)
t.doTask()
def randomEnterMaintenance(self):
def run(param):
while(1):
try:
interval = random.randint(1, 2)
time.sleep(interval)
if len(self.hosts) == 0:
continue
index = random.randint(0, len(self.hosts)-1)
hostId = self.hosts[index]
apiClient = self.testClient.getApiClient()
maintainCmd = prepareHostForMaintenance.prepareHostForMaintenanceCmd()
maintainCmd.id = hostId
response = apiClient.prepareHostForMaintenance(maintainCmd)
id = response.id
print "Host %s entered maintenance mode" % id
except Exception, e:
print e
t = Task(run)
t.doTask()
def test_deploy100Hosts(self):
#for i in range(200):
#self.hosts.append(self.deployHost(i))
for i in range(200):
self.hosts.append(i)
self.randomEnterMaintenance()
self.randomCancelMaintenance()
while(1): time.sleep(10000)