def main_section(): vulcanfuncs.generate_pid_file(common_config.LOGDIR) (ch, fh) = vulcanlog.setup_default_logging(common_config.LOGDIR + "tcfat.log") if common_config.VERBOSE > 0: vulcanlog.adjust_logging_level("debug", ch, fh) if common_config.QUIET > 0: vulcanlog.adjust_logging_level("quiet", ch, fh) number_of_tokens = 10000 token_id_list = [] total_launch_time = 0 tenant = "anne" username = "******" password = "******" tenant_id, auth_token = keystone_login(tenant, username, password) # creating multiple tokens LOG.info("Number of tokens to be creaeted is %d", number_of_tokens) for i in range(1, (number_of_tokens + 1)): initial_time = time.time() tenant_id, auth_token = keystone_login(tenant, username, password) token_id_list.append(auth_token) final_time = time.time() if i is 1: first_launch_time = final_time - initial_time else: total_launch_time += (final_time - initial_time) print "Get token ", auth_token, "in", \ (final_time - initial_time), "secs" # Deleting all tokens for token_id in token_id_list: delete_token(token_id) if number_of_tokens > 1: average_time = total_launch_time / (number_of_tokens - 1) print "First token created in", first_launch_time print "Avg time to create rest of the logins is", average_time else: average_time = total_launch_time print "First token created in", first_launch_time print "Avg time to create rest of the logins is", first_launch_time if average_time < first_launch_time: sys.exit(0) else: print( "Time taken for creating first token was less than the " "average time taken for rest of the tokens.") sys.exit(2)
def main_section(): vulcanfuncs.generate_pid_file(common_config.LOGDIR) (ch, fh) = vulcanlog.setup_default_logging( common_config.LOGDIR + "test.log") if common_config.VERBOSE > 0: vulcanlog.adjust_logging_level("debug", ch, fh) if common_config.QUIET > 0: vulcanlog.adjust_logging_level("quiet", ch, fh)
def main_section(): vulcanfuncs.generate_pid_file(common_config.LOGDIR) (ch, fh) = vulcanlog.setup_default_logging( common_config.LOGDIR + "tcbcdvm.log") if common_config.VERBOSE > 0: vulcanlog.adjust_logging_level("debug", ch, fh) if common_config.QUIET > 0: vulcanlog.adjust_logging_level("quiet", ch, fh) number_of_instances = 2000 flavor_id = 1 timeout = 5 instance_id_list = [] total_launch_time = 0 tenant = "anne" username = "******" password = "******" image_name = 'ubuntu' image_ref = "" tenant_id, auth_token = keystone_login(tenant, username, password) if image_ref == '': image_ref = find_image(image_name, tenant_id, auth_token) images = list_image_details(tenant_id, auth_token) LOG.info(images) # Launching multiple instances print "Number of instances to be launched is", number_of_instances for i in range(1, (number_of_instances + 1)): initial_time = time.time() instance_id = create_instance("useradmin_instance", image_ref, flavor_id, tenant_id, auth_token) # instance_status, instance_ip_address = get_instance_ip_address(instance_id, tenant_id, auth_token) instance_id_list.append(instance_id) while True: try: if is_instance_active(instance_id, tenant_id, auth_token): break except httplib.BadStatusLine as exn: print "Warning: got BadStatusLine" time.sleep(timeout) final_time = time.time() if i is 1: first_launch_time = final_time - initial_time else: total_launch_time += (final_time - initial_time) print "Launched instance", instance_id, "in", \ (final_time - initial_time), "secs" # Measuring the difference between the time taken to launch an instance # for the first time and the average of the time taken to launch # the rest of the instances average_time = total_launch_time / (number_of_instances - 1) print "First instance launched in", first_launch_time print "Avg time to launch rest of the instances is", average_time if average_time < first_launch_time: sys.exit(0) else: print ("Time taken for launching first instance was less than the " "average time taken for rest of the instances.") sys.exit(2)
def main_section(): vulcanfuncs.generate_pid_file(common_config.LOGDIR) (ch, fh) = vulcanlog.setup_default_logging( common_config.LOGDIR + "tcbcu.log") if common_config.VERBOSE > 0: vulcanlog.adjust_logging_level("debug", ch, fh) if common_config.QUIET > 0: vulcanlog.adjust_logging_level("quiet", ch, fh) number_of_users = 200 user_id_list = [] total_launch_time = 0 tenant = "anne" username = "******" password = "******" timeout = 5 tenant_id, auth_token = keystone_login( tenant, username, password, keystone_auth_url) users_list = keystone_user_list(auth_token) # check if original yser and tenant in users list assert username, tenant_id in users_list gen_new_username = gen_rnd_string(5) # Creating users print "Number of user accounts to be created is", number_of_users for i in range(1, (number_of_users + 1)): initial_time = time.time() new_username = gen_new_username + "_" + str(i) email = gen_new_username + "@hp.com" new_password = "******" user_id, response = createUser( auth_token, new_username, email, new_password) if int(response['status']) != 200: raise AssertionError("status is not 200: " + response['status']) user_id_list.append(user_id) final_time = time.time() if i is 1: first_launch_time = final_time - initial_time else: total_launch_time += (final_time - initial_time) # verify new user again users_list = keystone_user_list(auth_token) assert new_username, email in users_list # To do: delete users average_time = total_launch_time / (number_of_users - 1) print "First user created in", first_launch_time print "Avg time to launch rest of the users is", average_time if average_time < first_launch_time: sys.exit(0) else: print ("Time taken for creating first user was less than the " "average time taken for rest of the users.") sys.exit(2)
class main_section(unittest.TestCase): vulcanfuncs.generate_pid_file(common_config.LOGDIR) (ch, fh) = vulcanlog.setup_default_logging( common_config.LOGDIR + "test.log") if common_config.VERBOSE > 0: vulcanlog.adjust_logging_level("debug", ch, fh) if common_config.QUIET > 0: vulcanlog.adjust_logging_level("quiet", ch, fh) instance_id_list = [] def setUp(self): self.log = logging.getLogger("TestCase") self.tenant = common_config.TENANT_NAME self.username = common_config.USER_NAME self.password = common_config.PASS_WORD self.image_name = common_config.image_name self.kvm_host = common_config.kvm_host self.kvm_user = common_config.kvm_user self.kvm_pass = common_config.kvm_pass self.cmd = common_config.cmd self.tenant_id, self.token_id = keystone_login( self.tenant, self.username, self.password) self.flavor_id = int( find_flavor( common_config.flavor_name, self.tenant_id, self.token_id)) '''Create VM Instance and stop the libvirt services on the KVM Host''' def test_01_create_server(self): # sshcon(self.kvm_host,self.kvm_user,self.kvm_pass,self.cmd) # time.sleep(10) image_ref = find_image(self.image_name, self.tenant_id, self.token_id) instance_id = create_instance( "newimage", image_ref, self.flavor_id, self.tenant_id, self.token_id) self.instance_id_list.append(instance_id) # time.sleep(240) print "Token_id:", self.token_id self.log.info("test_01_Create_Server completed") '''Verify the VM Status after the libvirt services are stopped''' def test_02_vmstatus(self): while True: try: if(is_instance_active(self.instance_id_list[0], self.tenant_id, self.token_id)): # '5b5cf1d5-4fe9-4c68-8b81-6362dd345a94'" print "VM is ACTIVE" break elif(is_instance_active(self.instance_id_list[0], self.tenant_id, self.token_id) is False): print "VM is in inactive state" break self.log.info("test_02_Create_Server: Test Completed") except: self.log.error( "test_02_Create_Server: VM went into Error state") raise Exception("VM went into Error state") '''Verify the Healthnmon API(vmdetails) when libvirt services are stopped''' def test_03_vmDetails(self): try: content = get_vm_details( self.instance_id_list[0], self.tenant_id, self.token_id) content1 = get_instance_details( self.instance_id_list[0], self.tenant_id, self.token_id) print "------------------------------------------" print " Instance Attributes " print "------------------------------------------" print "Instance Name:", content['Vm']['name'] print "Connection State:", content['Vm']['connectionState'] print "Instance Power State:", content['Vm']['powerState'] print "Memory Size:", content['Vm']['memorySize'] print "Host ID:", content1['server']['hostId'] print "\n" self.log.info("test_03_VM Details: Test Completed") # print content except: self.log.error( "test_03_vmDetails: VM went into ERROR state,Could not fetch VM details") raise Exception("Could not fetch VM details")
def main_section(): vulcanfuncs.generate_pid_file(common_config.LOGDIR) (ch, fh) = vulcanlog.setup_default_logging(common_config.LOGDIR + "test.log") if common_config.VERBOSE > 0: vulcanlog.adjust_logging_level("debug", ch, fh) if common_config.QUIET > 0: vulcanlog.adjust_logging_level("quiet", ch, fh) class Test_RebootISC(unittest.TestCase): """ Procedure: Reboot isc - check services are up and running before and after reboot, create few instances before reboot, check the number of vms associated with the hosts are equal before and after reboot Expected result: Services should be up and running after reboot, number of vms associated with the hosts are equal before and after reboot """ # ====================================================================== # CHECK SERVICES ARE UP AND RUNNING # ====================================================================== def test_1check_services(self): LOG.info("check services are up and running") conn = ssh.Client(common_config.ISC_APPLIANCE_IP, common_config.ssh_username, common_config.ssh_password) servicelist = [ "openstack-nova-scheduler", "openstack-nova-cert", "healthnmon", "openstack-glance-api", "openstack-glance-registry", "openstack-keystone" ] for service in servicelist: output = conn.exec_command("service " + service + " status") try: self.assertEquals("running", output[-11:-4], "%s is not running" % service) LOG.error("%s is running" % service) except Exception as e: LOG.error("%s is not running" % service) # raise e # ====================================================================== # GET DETAILS AND COUNT OF INSTANCES # ====================================================================== def get_servers_details_count(self): LOG.info("get details and count of instances") tenant_id, auth_token = utils.keystone_login( common_config.TENANT_NAME, common_config.USER_NAME, common_config.PASS_WORD) details = utils.list_server_details(tenant_id, auth_token) servers_count = len(details["servers"]) return details, servers_count # ====================================================================== # CREATE INSTANCES,CHECK TOTAL COUNT BEFORE AND AFTER CREATING INSTANCES # ====================================================================== def test_2create_instance(self): LOG.info( "create instances, check total count before and after creating instances" ) tenant_id, auth_token = utils.keystone_login( common_config.TENANT_NAME, common_config.USER_NAME, common_config.PASS_WORD) details, servers_count_before = self.get_servers_details_count() for vm_name, image, flavor in common_config.vm_name_image_flavor: image_id = utils.find_image(image, tenant_id, auth_token) instance_id = utils.create_instance(vm_name, image_id, flavor, tenant_id, auth_token) time.sleep(120) inst_active = utils.is_instance_active(instance_id, tenant_id, auth_token) try: self.assertEquals("True", inst_active, "%s is not active" % vm_name) LOG.info("%s is active" % vm_name) except Exception as e: LOG.error("%s is not active" % vm_name) # raise e details, servers_count_now = self.get_servers_details_count() global servers_count_global servers_count_global = servers_count_now try: self.assertEquals((servers_count_before + len(common_config.vm_name_image_flavor)), servers_count_now, "instance count does not match") LOG.info("instance count matches") except Exception as e: LOG.error("instance count does not match") # raise e # ====================================================================== # GET COUNT OF VMs UNDER EACH HOST # ====================================================================== def test_3vm_count_with_host(self): LOG.info("Count of VMs under each host") tenant_id, auth_token = utils.keystone_login( common_config.TENANT_NAME, common_config.USER_NAME, common_config.PASS_WORD) server_details, total_server_count = self.get_servers_details_count( ) vm_hosts = utils.list_host(tenant_id, auth_token) vm_count_with_hosts_dict = {} for host in range(len(vm_hosts["vmhosts"])): vm_count_with_hosts_dict[vm_hosts["vmhosts"][host]["name"]] = 0 for server in range(total_server_count): for host in vm_count_with_hosts_dict.keys(): if server_details["servers"][server][ 'OS-EXT-SRV-ATTR:host'] == host: vm_count_with_hosts_dict[ host] = vm_count_with_hosts_dict[host] + 1 break global vm_count_with_hosts_global vm_count_with_hosts_global = vm_count_with_hosts_dict return vm_count_with_hosts_dict # ====================================================================== # REBOOT ISC APPLIANCE # ====================================================================== def test_4reboot_ISC(self): LOG.info("Reboot ISC appliance") conn = ssh.Client(common_config.ISC_APPLIANCE_IP, common_config.ssh_username, common_config.ssh_password) output = conn.exec_command("reboot") time.sleep(950) # ====================================================================== # PING APPLIANCE,CHECK SERVICES,SERVER COUNTS # AND NUMBER OF VMS ASSOCIATED WITH EACH HOST ARE EQUAL BEFORE AND AFTER REBOOT # ====================================================================== def test_5after_reboot(self): LOG.info( "check ISC appliance is pinging,check services, server counts and number of vms associated with hosts before and after reboot are equal" ) servers_count_before_reboot = servers_count_global vm_count_with_hosts_before_reboot = vm_count_with_hosts_global ping_time = pinger.ping(common_config.ISC_APPLIANCE_IP) LOG.info("pinging system") if ping_time is None: LOG.info("Appliance not reachable") else: self.test_1check_services() details, servers_count_after_reboot = self.get_servers_details_count( ) vm_count_with_hosts_after_reboot = self.test_3vm_count_with_host( ) try: self.assertEquals(servers_count_before_reboot, servers_count_after_reboot) LOG.info("number of servers before and after reboot are equal") except Exception as e: LOG.error( "number of servers before and after reboot are not equal") # raise e finally: try: self.assertEquals( vm_count_with_hosts_before_reboot, vm_count_with_hosts_after_reboot, "number of vms associted with hosts before and after reboot are not equal" ) LOG.info( "number of vms associted with hosts before and after reboot are equal" ) except Exception as e: LOG.error( "number of vms associted with hosts before and after reboot are not equal" ) # raise e # ================================================================== # CLEANUP # ================================================================== def test_cleanup(self): tenant_id, auth_token = utils.keystone_login( common_config.TENANT_NAME, common_config.USER_NAME, common_config.PASS_WORD) for vm_name, image, flavor in common_config.vm_name_image_flavor: instance_id = utils.find_server_id(vm_name, tenant_id, auth_token) utils.delete_instance(instance_id, tenant_id, auth_token) content = utils.list_server(tenant_id, auth_token) if content["servers"] == []: LOG.info("Deleted all instances") else: LOG.error("Instances are not deleted successfully") suite = unittest.TestLoader().loadTestsFromTestCase(Test_RebootISC) testResult = unittest.TextTestRunner(verbosity=2).run(suite) errors = testResult.errors failures = testResult.failures return errors, failures