def ovs_2468_verify_no_mds_files_left_after_remove_vpool_test(): """ Verify MDS presence after vpool removal """ vpools = GeneralVPool.get_vpools() vpool_names = [vpool.name for vpool in vpools] command = "find /mnt -name '*mds*'" mdsvpoolnames = [] out = General.execute_command(command + " | wc -l") if not out == '0': mdsvpoolnames = [line.split('/')[-1] for line in General.execute_command(command)[0].splitlines()] mds_files_still_in_filesystem = "" for mdsvpoolname in mdsvpoolnames: if mdsvpoolname.split('_')[1] not in vpool_names: mds_files_still_in_filesystem += mdsvpoolname + "\n" assert len(mds_files_still_in_filesystem) == 0,\ "MDS files still present in filesystem after remove vpool test:\n %s" % mds_files_still_in_filesystem
def cleanup(): """ Do some cleanup actions :return: None """ from ci.tests.general.general_pmachine import GeneralPMachine from ci.tests.general.general_vdisk import GeneralVDisk from ci.tests.general.general_vmachine import GeneralVMachine def _get_remote_ssh_connection(ip_address, username, password): import paramiko ssh_connection = paramiko.SSHClient() ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_connection.connect(ip_address, username=username, password=password, timeout=2) sftp = ssh_connection.open_sftp() return ssh_connection, sftp # @TODO: Split this cleanup function up in relevant parts and put them in the correct general files machine_name = "AT_" from ci.tests.general import general_hypervisor from ci.tests.general.general_vpool import GeneralVPool for vpool in GeneralVPool.get_vpools(): if vpool: hpv = general_hypervisor.Hypervisor.get(vpool) vm_names = [vm.name for vm in GeneralVMachine.get_vmachines()] for name in vm_names: vm = GeneralVMachine.get_vmachine_by_name(name) if not vm: continue vm = vm[0] if not vm.name.startswith(machine_name): continue if vm.is_vtemplate: hpv.delete_clones(vm) logging.log(1, "Deleting {0} on hypervisor".format(vm.name)) hpv.poweroff(vm.name) hpv.delete(vm.name) env_macs = General.execute_command("""ip a | awk '/link\/ether/ {gsub(":","",$2);print $2;}'""")[0].splitlines() if vpool.storagedrivers: mountpoint = vpool.storagedrivers[0].mountpoint if os.path.exists(mountpoint): for d in os.listdir(mountpoint): if d.startswith(machine_name): p = '/'.join([mountpoint, d]) if os.path.isdir(p): logging.log(1, "removing tree: {0}".format(p)) shutil.rmtree(p) else: logging.log(1, "removing file: {0}".format(p)) if os.path.isfile(p): os.remove(p) for mac in env_macs: mac_path = '/'.join([mountpoint, mac]) if os.path.exists(mac_path): for f in os.listdir(mac_path): logging.log(1, "removing file: {0}".format(f)) os.remove('/'.join([mac_path, f])) # remove existing disks vdisks = GeneralVDisk.get_vdisks() for vdisk in vdisks: if vdisk: for junction in vdisk.mds_services: if junction: junction.delete() vdisk.delete() logging.log(1, 'WARNING: Removed leftover disk: {0}'.format(vdisk.name)) GeneralVPool.remove_vpool(vpool) if GeneralPMachine.get_hypervisor_type() == 'VMWARE': from ci.tests.general.general_hypervisor import GeneralHypervisor hypervisor_info = GeneralHypervisor.get_hypervisor_info() ssh_con = _get_remote_ssh_connection(*hypervisor_info)[0] cmd = "esxcli storage nfs remove -v {0}".format(vpool.name) ssh_con.exec_command(cmd) vmachines = GeneralVMachine.get_vmachines() for vmachine in vmachines: logging.log(1, 'WARNING: Removing leftover vmachine: {0}'.format(vmachine.name)) vmachine.delete()