def nfs_disconnected(params): """ Drop nfs connection by iptables """ service_mgr = avocado_service.ServiceManager() service_mgr.start('iptables') Iptables.setup_or_cleanup_iptables_rules([params.get("iptable_rule")])
def nfs_disconnected(params): """ Drop nfs connection by iptables """ service_mgr = avocado_service.ServiceManager() service_mgr.start('iptables') Iptables.setup_or_cleanup_iptables_rules([params.get("iptable_rule")])
def recover(self, params=None): """ Recover env """ Iptables.setup_or_cleanup_iptables_rules([self.iptable_rule], cleanup=True) if self.vm.is_alive(): self.vm.destroy() self.vmxml_backup.sync() utils_test.libvirt.setup_or_cleanup_nfs( is_setup=False, is_mount=False, restore_selinux=self.nfs_res["selinux_status_bak"]) process.run("dmesg -c")
def recover(self, params=None): """ Recover env """ Iptables.setup_or_cleanup_iptables_rules([self.iptable_rule], cleanup=True) if self.vm.is_alive(): self.vm.destroy() self.vmxml_backup.sync() utils_test.libvirt.setup_or_cleanup_nfs( is_setup=False, is_mount=False, restore_selinux=self.nfs_res["selinux_status_bak"]) process.run("dmesg -c")
def result_confirm(self, params): """ Confirm the sign of nfs not response in dmesg, thread finished before timeout """ self.td.join() def check_nfs_response(): """ Check if there is 'nfs not responding' in dmesg. """ response = self.nfs_no_response_sign in process.run('dmesg').stdout_text if response: logging.debug(self.nfs_no_response_sign) return response Iptables.setup_or_cleanup_iptables_rules([self.iptable_rule], cleanup=True) if self.operation == "save": if not check_nfs_response(): self.test.fail("No nfs not response sign in dmesg")
def result_confirm(self, params): """ Confirm the sign of nfs not response in dmesg, thread finished before timeout """ self.td.join() def check_nfs_response(): """ Check if there is 'nfs not responding' in dmesg. """ response = self.nfs_no_response_sign in process.run('dmesg').stdout if response: logging.debug(self.nfs_no_response_sign) return response Iptables.setup_or_cleanup_iptables_rules([self.iptable_rule], cleanup=True) if self.operation == "save": if not check_nfs_response(): self.test.fail("No nfs not response sign in dmesg")
def firewall_to_permit_nfs(self): """ Method to configure firewall to permit NFS to be mounted from remote host """ # Check firewall in host permit nfs service to mount from remote server try: firewalld = service.Factory.create_service("firewalld") if not firewalld.status(): firewalld.start() firewall_cmd = "firewall-cmd --list-all | grep services:" try: ret = process.run(firewall_cmd, shell=True) if not ret.exit_status: firewall_services = ret.stdout_text.split( ':')[1].strip().split(' ') if 'nfs' not in firewall_services: service_cmd = "firewall-cmd --permanent --zone=public " service_cmd += "--add-service=nfs" ret = process.run(service_cmd, shell=True) if ret.exit_status: logging.error( "nfs service not added in firewall: " "%s", ret.stdout_text) else: logging.debug("nfs service added to firewall " "sucessfully") firewalld.restart() else: logging.debug( "nfs service already permitted by firewall") except process.CmdError: # For RHEL 6 based system firewall-cmd is not available logging.debug("Using iptables to permit NFS service") nfs_ports = [] rule_list = [] nfsd = service.Factory.create_service("nfs") rpcd = service.Factory.create_service("rpcbind") iptables = service.Factory.create_service("iptables") nfs_sysconfig = self.params.get("nfs_sysconfig_path", "/etc/sysconfig/nfs") tcp_port = self.params.get("nfs_tcp_port", "32803") udp_port = self.params.get("nfs_udp_port", "32769") mountd_port = self.params.get("nfs_mountd_port", "892") subnet_mask = self.params.get("priv_subnet", "192.168.2.0/24") nfs_ports.append("LOCKD_TCPPORT=%s" % tcp_port) nfs_ports.append("LOCKD_UDPPORT=%s" % udp_port) nfs_ports.append("MOUNTD_PORT=%s" % mountd_port) cmd_output = process.run("cat %s" % nfs_sysconfig, shell=True).stdout_text exist_ports = cmd_output.strip().split('\n') # check if the ports are already configured, if not then add it for each_port in nfs_ports: if each_port not in exist_ports: process.run("echo '%s' >> %s" % (each_port, nfs_sysconfig), shell=True) rpcd.restart() nfsd.restart() rule_temp = "INPUT -m state --state NEW -p %s -m multiport " rule_temp += "--dport 111,892,2049,%s -s %s -j ACCEPT" rule = rule_temp % ("tcp", tcp_port, subnet_mask) rule_list.append(rule) rule = rule_temp % ("udp", udp_port, subnet_mask) rule_list.append(rule) Iptables.setup_or_cleanup_iptables_rules(rule_list) iptables.restart() except Exception as info: logging.error("Firewall setting to add nfs service " "failed: %s", info)
def firewall_to_permit_nfs(self): """ Method to configure firewall to permit NFS to be mounted from remote host """ # Check firewall in host permit nfs service to mount from remote server try: firewalld = service.Factory.create_service("firewalld") if not firewalld.status(): firewalld.start() firewall_cmd = "firewall-cmd --list-all | grep services:" try: ret = process.run(firewall_cmd, shell=True) if not ret.exit_status: firewall_services = results_stdout_52lts(ret).split(':')[1].strip().split(' ') if 'nfs' not in firewall_services: service_cmd = "firewall-cmd --permanent --zone=public " service_cmd += "--add-service=nfs" ret = process.run(service_cmd, shell=True) if ret.exit_status: logging.error("nfs service not added in firewall: " "%s", results_stdout_52lts(ret)) else: logging.debug("nfs service added to firewall " "sucessfully") firewalld.restart() else: logging.debug("nfs service already permitted by firewall") except process.CmdError: # For RHEL 6 based system firewall-cmd is not available logging.debug("Using iptables to permit NFS service") nfs_ports = [] rule_list = [] nfsd = service.Factory.create_service("nfs") rpcd = service.Factory.create_service("rpcbind") iptables = service.Factory.create_service("iptables") nfs_sysconfig = self.params.get("nfs_sysconfig_path", "/etc/sysconfig/nfs") tcp_port = self.params.get("nfs_tcp_port", "32803") udp_port = self.params.get("nfs_udp_port", "32769") mountd_port = self.params.get("nfs_mountd_port", "892") subnet_mask = self.params.get("priv_subnet", "192.168.2.0/24") nfs_ports.append("LOCKD_TCPPORT=%s" % tcp_port) nfs_ports.append("LOCKD_UDPPORT=%s" % udp_port) nfs_ports.append("MOUNTD_PORT=%s" % mountd_port) cmd_output = decode_to_text(process.system_output( "cat %s" % nfs_sysconfig, shell=True)) exist_ports = cmd_output.strip().split('\n') # check if the ports are already configured, if not then add it for each_port in nfs_ports: if each_port not in exist_ports: process.run("echo '%s' >> %s" % (each_port, nfs_sysconfig), shell=True) rpcd.restart() nfsd.restart() rule_temp = "INPUT -m state --state NEW -p %s -m multiport " rule_temp += "--dport 111,892,2049,%s -s %s -j ACCEPT" rule = rule_temp % ("tcp", tcp_port, subnet_mask) rule_list.append(rule) rule = rule_temp % ("udp", udp_port, subnet_mask) rule_list.append(rule) Iptables.setup_or_cleanup_iptables_rules(rule_list) iptables.restart() except Exception as info: logging.error("Firewall setting to add nfs service " "failed: %s", info)
def run(test, params, env): """ :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. The test will 1. Create 'n' uperf server-client pairs, 2. Configure iptables in guest and install uperf 3. Kick start uperf run, wait for duration [customized given in uperf profile] 4. After run, test will check for errors and make sure all guests are reachable. 5. Cleanup temp files and iptable rules added before """ stress_duration = int(params.get("stress_duration", "20")) ip_rule = params.get("ip_rule", "") stress_type = params.get("stress_type", "") need_profile = int(params.get("need_profile", 0)) server_cmd = params.get("%s_server_cmd" % stress_type) client_cmd = params.get("%s_client_cmd" % stress_type) client_vms = [] server_vms = [] error = 0 vms = env.get_all_vms() if (need_profile): profile = params.get("client_profile_%s" % stress_type) profile = os.path.join(data_dir.get_root_dir(), profile) profile_pattren = params.get("profile_pattren", "").split() for index, vm in enumerate(vms): if index % 2 != 0: # Process for client client_vms.append(vm) else: # Process for server server_vms.append(vm) pair_vms = zip(server_vms, client_vms) if len(server_vms) != len(client_vms): test.cancel("This test requires server and client vms in 1:1 ratio") if stress_type == "uperf": protocol = params.get("%s_protocol" % stress_type, "tcp") nthreads = params.get("nthreads", "32") client_cmd = client_cmd % os.path.basename(profile) if not profile.endswith(".xml"): logging.debug("Error: profile should be an xml: %s", profile) test.cancel("%s profile not valid", stress_type) profile_values = [nthreads, str(stress_duration), protocol] if len(profile_pattren) != len(profile_values): test.cancel("Profile pattrens not matching values passed: fix the cfg file with right pattren") profile_pattren.append('serverip') pat_repl = dict(zip(profile_pattren, profile_values)) elif stress_type == "netperf": ports = params.get("ports", "16604") test_protocol = params.get("test_protocols", "TCP_STREAM") server_cmd = server_cmd.format(ports) client_cmd = client_cmd.format("{0}", ports, stress_duration, test_protocol) else: raise NotImplementedError for server_vm, client_vm in pair_vms: try: params['stress_cmds_%s' % stress_type] = server_cmd stress_server = utils_test.VMStress(server_vm, stress_type, params) params['server_pwd'] = params.get("password") # wait so that guests get ip address, else get_address will fail client_vm.wait_for_login().close() if ip_rule: for vm_ip in [server_vm.get_address(), client_vm.get_address()]: params['server_ip'] = vm_ip Iptables.setup_or_cleanup_iptables_rules( [ip_rule], params=params, cleanup=False) stress_server.load_stress_tool() if need_profile: profile_backup = profile + '.backup' shutil.copy(profile, profile_backup) pat_repl.update({"serverip": str(server_vm.get_address())}) utils_test.prepare_profile(test, profile, pat_repl) client_vm.copy_files_to(profile, "/home", timeout=60) shutil.copy(profile_backup, profile) os.remove(profile_backup) else: client_cmd = client_cmd.format(str(server_vm.get_address())) params['stress_cmds_%s' % stress_type] = client_cmd stress_client = utils_test.VMStress(client_vm, stress_type, params) stress_client.load_stress_tool() except exceptions.TestError as err_msg: error = 1 logging.error(err_msg) if stress_duration and not error: time.sleep(stress_duration) for vm in vms: try: s_ping, o_ping = utils_test.ping(vm.get_address(), count=10, timeout=20) logging.info(o_ping) if s_ping != 0: error = 1 logging.error("%s seem to have gone out of network", vm.name) else: stress = utils_test.VMStress(vm, stress_type, params) stress.unload_stress() if ip_rule: params['server_ip'] = vm.get_address() Iptables.setup_or_cleanup_iptables_rules([ip_rule], params=params, cleanup=True) stress.clean() vm.verify_dmesg() except exceptions.TestError as err_msg: error = 1 logging.error(err_msg) finally: if vm.exists() and vm.is_persistent(): vm.undefine() if error: test.fail("%s run failed: see error messages above" % stress_type)
def run(test, params, env): """ :param test: kvm test object :param params: Dictionary with the test parameters :param env: Dictionary with test environment. The test will 1. Create 'n' uperf server-client pairs, 2. Configure iptables in guest and install uperf 3. Kick start uperf run, wait for duration [customized given in uperf profile] 4. After run, test will check for errors and make sure all guests are reachable. 5. Cleanup temp files and iptable rules added before """ stress_duration = int(params.get("stress_duration", "20")) ip_rule = params.get("ip_rule", "") stress_type = params.get("stress_type", "") need_profile = int(params.get("need_profile", 0)) server_cmd = params.get("%s_server_cmd" % stress_type) client_cmd = params.get("%s_client_cmd" % stress_type) client_vms = [] server_vms = [] error = 0 vms = env.get_all_vms() if (need_profile): profile = params.get("client_profile_%s" % stress_type) profile = os.path.join(data_dir.get_root_dir(), profile) profile_pattren = params.get("profile_pattren", "").split() for index, vm in enumerate(vms): if index % 2 != 0: # Process for client client_vms.append(vm) else: # Process for server server_vms.append(vm) pair_vms = zip(server_vms, client_vms) if len(server_vms) != len(client_vms): test.cancel("This test requires server and client vms in 1:1 ratio") if stress_type == "uperf": protocol = params.get("%s_protocol" % stress_type, "tcp") nthreads = params.get("nthreads", "32") client_cmd = client_cmd % os.path.basename(profile) if not profile.endswith(".xml"): logging.debug("Error: profile should be an xml: %s", profile) test.cancel("%s profile not valid", stress_type) profile_values = [nthreads, str(stress_duration), protocol] if len(profile_pattren) != len(profile_values): test.cancel( "Profile pattrens not matching values passed: fix the cfg file with right pattren" ) profile_pattren.append('serverip') pat_repl = dict(zip(profile_pattren, profile_values)) elif stress_type == "netperf": ports = params.get("ports", "16604") test_protocol = params.get("test_protocols", "TCP_STREAM") server_cmd = server_cmd.format(ports) client_cmd = client_cmd.format("{0}", ports, stress_duration, test_protocol) else: raise NotImplementedError for server_vm, client_vm in pair_vms: try: params['stress_cmds_%s' % stress_type] = server_cmd stress_server = utils_test.VMStress(server_vm, stress_type, params) params['server_pwd'] = params.get("password") # wait so that guests get ip address, else get_address will fail client_vm.wait_for_login().close() if ip_rule: for vm_ip in [ server_vm.get_address(), client_vm.get_address() ]: params['server_ip'] = vm_ip Iptables.setup_or_cleanup_iptables_rules([ip_rule], params=params, cleanup=False) stress_server.load_stress_tool() if need_profile: profile_backup = profile + '.backup' shutil.copy(profile, profile_backup) pat_repl.update({"serverip": str(server_vm.get_address())}) utils_test.prepare_profile(test, profile, pat_repl) client_vm.copy_files_to(profile, "/home", timeout=60) shutil.copy(profile_backup, profile) os.remove(profile_backup) else: client_cmd = client_cmd.format(str(server_vm.get_address())) params['stress_cmds_%s' % stress_type] = client_cmd stress_client = utils_test.VMStress(client_vm, stress_type, params) stress_client.load_stress_tool() except exceptions.TestError as err_msg: error = 1 logging.error(err_msg) if stress_duration and not error: time.sleep(stress_duration) for vm in vms: try: s_ping, o_ping = utils_test.ping(vm.get_address(), count=10, timeout=20) logging.info(o_ping) if s_ping != 0: error = 1 logging.error("%s seem to have gone out of network", vm.name) else: stress = utils_test.VMStress(vm, stress_type, params) stress.unload_stress() if ip_rule: params['server_ip'] = vm.get_address() Iptables.setup_or_cleanup_iptables_rules([ip_rule], params=params, cleanup=True) stress.clean() vm.verify_dmesg() except exceptions.TestError as err_msg: error = 1 logging.error(err_msg) finally: if vm.exists() and vm.is_persistent(): vm.undefine() if error: test.fail("%s run failed: see error messages above" % stress_type)