def test_create_volume_type(self): try: volume = Base() except Exception as e: LOG.warning( _LW('Init test env failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) raise exceptions.InitFailed try: volume_type_created = \ volume.create_test_volume_type() LOG.debug(_LI("The new volume_type is %s"), volume_type_created) except Exception as e: LOG.warning( _LW('Create volume type failed, ' 'msg: %(msg)s, traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) raise finally: volume.delete_all()
def run_test(self, testcase=None, cycle=1): if testcase is None: return run_times = cycle if cycle > 0 else self._LONG_RUN_TIMES if isinstance(run_times, basestring): run_times = int(run_times) path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) python_path = os.environ.get("PYTHONPATH") if not python_path: python_path = path else: python_path += ';' + path os.environ['PYTHONPATH'] = python_path while run_times > 0: try: cmd = "python " + testcase LOG.info(('TESTCASE begin to run: %s'), testcase) ret = os.system(cmd) if ret == 0: LOG.info(_LI('TESTCASE run successfully: %s'), testcase) else: raise except Exception: LOG.error(('TESTCASE failed: %s'), testcase) run_times = run_times - 1
def run_all_tests(self, cycle=1): testcases = self.load_tests() run_times = cycle if cycle > 0 else self._LONG_RUN_TIMES if isinstance(run_times, basestring): run_times = int(run_times) path = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) python_path = os.environ.get("PYTHONPATH") if not python_path: python_path = path else: python_path += ';' + path os.environ['PYTHONPATH'] = python_path while run_times > 0: total_cases_num = len(testcases) failed_cases_num = 0 failed_cases = [] for case in testcases: try: cmd = "python " + case LOG.info(_LI('TESTCASE begin to run: %s') % case) ret = os.system(cmd) if ret == 0: LOG.info(('TESTCASE run successfully: %s'), case) else: raise except Exception: LOG.error(_LE('TESTCASE failed: %s'), case) failed_cases.append(case) failed_cases_num += 1 LOG.info(_LI('RUN ALL CASES Total: %(total)s Fail: %(fail)s'), { 'total': total_cases_num, 'fail': failed_cases_num }) for case in failed_cases: LOG.info(_LI('RUN ALL CASES FAILED: %s'), case) run_times -= 1
def live_migration_test(self): try: compute = Base() except Exception as err: LOG.error(_LE('init env failed for %s'), str(err)) raise exceptions.ServerFault try: instance = compute.create_server() compute.show_server(instance['id']) orig_host = compute.get_server_host(instance['id']) # when migrate, the status transfer from MIGRATING # TO ACTIVE # do not use block migration and no host is assigned self.manager.servers_client.live_migrate_server( instance['id'], None, False) compute._check_server_status_interval(instance['id'], 'ACTIVE', interval=10, timeout=60) # check the host attributes curr_host = compute.get_server_host(instance['id']) LOG.debug(('the origin host %(orig)s the current host' ' %(curr)s'), {'orig': orig_host, 'curr': curr_host}) if curr_host is not None and orig_host == curr_host: raise exceptions.ServerMigrateFailed() LOG.info(_LI('live migrate of %s successful'), instance['id']) except Exception as err: LOG.error(_LE('migrate server failed for %s'), str(err)) compute.delete_all() raise exceptions.ServerMigrateFailed() finally: compute.delete_all()
def test_multipleVM(self): try: network = self.create_network() subnet = self.create_subnet(network.get('id')) router = self.create_router() self.router_set_external_gw(router.get('id')) self.router_add_subnet(router.get('id'), subnet.get('id')) sg = self.create_security_group() self.create_security_group_rule(sg.get('id'), 'IPv4', 'ingress', '0.0.0.0/0', 'ICMP') except Exception as e: LOG.warning( _LW('Create network env failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) self.delete_all() raise e try: success_count = 0 vm_count = random.randint(1, 10) for i in range(vm_count): try: LOG.info( _LI('Create and delete %(i)d of %(vm_count)d vm' ' start'), { 'i': i + 1, 'vm_count': vm_count }) vm_name = "server-" + str(uuid.uuid4())[:5] server = self.compute.\ create_server(name=vm_name, network_id=network.get('id'), sec_grp_id=sg.get('id')) interfaces = self.compute.\ show_server_interfaces(server['id']) interfaces = interfaces.get('interfaceAttachments', []) if not interfaces: LOG.warning( _LW('During network test server ' 'has no port!')) raise port_id = interfaces[0]['port_id'] floatingip = self.create_floating_ip(port_id) floatingip_addr = floatingip['floating_ip_address'] self.test_ping_floatingip(floatingip_addr) success_count += 1 LOG.info( _LI('Create and delete %(i)d of %(vm_count)d vm' ' success'), { 'i': i + 1, 'vm_count': vm_count }) except Exception as e: LOG.warning( _LW('Create and delete %(i)d of %(vm_count)d ' 'vm failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'i': i + 1, 'vm_count': vm_count, 'msg': e, 'tb': traceback.format_exc() }) LOG.info( _LI(' %(success_count)d success of %(vm_count)d round ' 'total'), { 'success_count': success_count, 'vm_count': vm_count }) except Exception as e: LOG.warning( _LW('Test multiple vm failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) finally: is_successfully_deleted = True try: self.compute.delete_all() except Exception as e: LOG.warning( _LW('Clear compute resource failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) is_successfully_deleted = False try: self.delete_all() except Exception as e: LOG.warning( _LW('Clear network resource failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) is_successfully_deleted = False if not is_successfully_deleted: raise exceptions.DeleteException
def test_security_group(self): try: network = self.create_network() subnet = self.create_subnet(network.get('id')) router = self.create_router() self.router_set_external_gw(router.get('id')) self.router_add_subnet(router.get('id'), subnet.get('id')) sg = self.create_security_group(self.sec_group_name) sg_rule = self.create_security_group_rule(sg.get('id'), 'IPv4', 'ingress', '0.0.0.0/0', 'ICMP') except Exception as e: LOG.warning( _LW('Create network env failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) self.delete_all() raise e try: self.create_security_group() vm_name = "server-" + str(uuid.uuid4())[:5] server = self.compute.create_server(name=vm_name, network_id=network.get('id'), sec_grp_id=sg.get('id')) interfaces = self.compute.show_server_interfaces(server['id']) interfaces = interfaces.get('interfaceAttachments', []) if not interfaces: LOG.warning(_LW('During network test server has no port!')) raise port_id = interfaces[0]['port_id'] floatingip = self.create_floating_ip(port_id) floatingip_addr = floatingip['floating_ip_address'] self.test_ping_floatingip(floatingip_addr) # negative test self.delete_sec_group_rule(sg_rule['id']) try: time.sleep(20) self.test_ping_floatingip(floatingip_addr, 10, 30) except exceptions.TimeoutException: LOG.info( _LI('Congratulations! Security group test ' 'successfully!')) else: raise exceptions.SecurityGroupException except Exception as e: LOG.warning( _LW('Test security group failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) finally: is_successfully_deleted = True try: self.compute.delete_all() except Exception as e: LOG.warning( _LW('Clear compute resource failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) is_successfully_deleted = False try: self.delete_all() except Exception as e: LOG.warning( _LW('Clear network resource failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) is_successfully_deleted = False if not is_successfully_deleted: raise exceptions.DeleteException
def test_create_volume_with_qos(self): try: volume = Base() except Exception as e: LOG.warning( _LW('Init test env failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) raise exceptions.InitFailed ''' try: compute = compute_base() except Exception as e: LOG.warning(_LW('Init test env failed, msg: %(msg)s, ' 'traceback: %(tb)s.'), {'msg': e, 'tb': traceback.format_exc()}) raise exceptions.ServerFault ''' try: volume_type = volume.create_test_volume_type() except Exception as e: LOG.warning( _LW('Create volume_type before create volume failed, ' 'msg: %(msg)s, traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) volume.delete_all() raise # raise exceptions.VolumeBuildErrorException() try: volumetype_randname, fixedname = volume_type['name'].split('-') LOG.info(_LI("Volume_type fixedname is %s"), fixedname) qos_name = volumetype_randname + '-Qos' qos_type = volume.create_test_qos_specs(qos_name, **self.__disk_qos_low) except Exception as e: LOG.warning( _LW('Create qos_type before create volume failed, ' 'msg: %(msg)s, traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) volume.delete_all() raise try: volume.associate_volumetype_with_qos(qos_type['id'], volume_type['id']) except Exception as e: LOG.warning( _LW('Associate qos_type with volume_type failed, ' 'msg: %(msg)s, traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) volume.delete_all() raise try: volume_name = str(uuid.uuid4()) params = {'volume_type': volume_type['id'], 'name': volume_name} single_volume = volume.create_volume(**params) LOG.debug("current test volume is %s", single_volume) # volume.check_volume_status_interval(single_volume['id'], # 'available') except Exception as e: LOG.warning( _LW('Create volume before snapshot failed, ' 'msg: %(msg)s, traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) volume.delete_all() raise finally: volume.delete_all() '''
def test_update_vm_password(self): try: instance = self.create_server() admin_pass = "******" self.manager.servers_client.change_password( instance['id'], admin_pass) waiters.wait_for_server_status(self.manager.servers_client, instance['id'], 'ACTIVE') server_detail = self.manager.servers_client.\ show_server(instance['id']) vm_name = server_detail.get("name") fp_body = self.manager.floating_ips_client.\ create_floating_ip('external') floating_ip_id_allocated = fp_body['id'] floating_ip_ip_allocated = fp_body['ip'] self.manager.floating_ips_client.\ associate_floating_ip_to_server(floating_ip_ip_allocated, instance['id']) self.manager.servers_client.\ add_security_group(instance['id'], CONF.compute.security_group) cmd = "hostname" f = open('/root/.ssh/known_hosts', 'w') f.truncate() ret = self._check_server_start_status_interval( floating_ip_ip_allocated, admin_pass, cmd) if vm_name not in str(ret): raise exceptions.PasswordNotCorrectlyUpdated else: LOG.info( _LI("Congratulations! VM password was successfully " "updated!")) except Exception as e: LOG.warning( _LW('Update vm password failed, ' 'msg: %(msg)s, traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) raise e finally: try: self.manager.floating_ips_client.\ disassociate_floating_ip_from_server( floating_ip_ip_allocated, instance['id']) except Exception as e: LOG.warning( _LW('Disassociate floating ip failed, ' 'msg: %(msg)s, traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) try: self.manager.floating_ips_client.\ delete_floating_ip(floating_ip_id_allocated) except Exception as e: LOG.warning( _LW('Delete floating ip failed, ' 'msg: %(msg)s, traceback: %(tb)s.'), { 'msg': e, 'tb': traceback.format_exc() }) self.delete_all()