def check_reference_stderr(self): if os.path.isfile(self.expected_stderr_file): expected = genio.read_file(self.expected_stderr_file) actual = genio.read_file(self.stderr_file) msg = ('Actual test sdterr differs from expected one:\n' 'Actual:\n%s\nExpected:\n%s' % (actual, expected)) self.assertEqual(expected, actual, msg)
def get_slot_from_sysfs(full_pci_address): """ Gets the PCI slot of given address. :note: Specific for ppc64 processor. :param full_pci_address: Full PCI address including domain (0000:03:00.0) :return: Removed port related details using re, only returns till physical slot of the adapter. """ if not os.path.isfile( '/sys/bus/pci/devices/%s/devspec' % full_pci_address): return devspec = genio.read_file("/sys/bus/pci/devices/%s/devspec" % full_pci_address).strip() if not os.path.isfile("/proc/device-tree/%s/ibm,loc-code" % devspec): return slot = genio.read_file("/proc/device-tree/%s/ibm,loc-code" % devspec) slot_ibm = re.match(r'((\w+)[.])+(\w+)-[PC(\d+)-]*C(\d+)', slot) if slot_ibm: return slot_ibm.group() slot_openpower = re.match(r'(\w+)[\s]*(\w+)(\d*)', slot) if slot_openpower: return slot_openpower.group() raise ValueError("Failed to get slot from: '%s'" % slot)
def setUp(self): """ Gets the console and set-up the machine for test """ if 'ppc' not in distro.detect().arch: self.cancel("Processor is not ppc64") output = genio.read_file("/sys/kernel/debug/powerpc/eeh_enable")\ .strip() if output != '0x1': self.cancel("EEH is not enabled, please enable via FSP") self.max_freeze = int(self.params.get('max_freeze', default='1')) cmd = "echo %d > /sys/kernel/debug/powerpc/eeh_max_freezes"\ % self.max_freeze process.system(cmd, ignore_status=True, shell=True) self.function = str(self.params.get('function', default='4')) self.err = str(self.params.get('err')) self.pci_device = str(self.params.get('pci_device', default=' ')) self.phb = self.pci_device.split(":", 1)[0] self.addr = genio.read_file("/sys/bus/pci/devices/%s/" "eeh_pe_config_addr" % self.pci_device) self.addr = str(self.addr).rstrip() self.err = 0 for line in process.system_output('lspci -vs %s' % self.pci_device, ignore_status=True, shell=True).splitlines(): if 'Memory' in line and '64-bit, prefetchable' in line: self.err = 1 break self.mem_addr = pci.get_memory_address(self.pci_device) self.mask = pci.get_mask(self.pci_device) self.log.info("Test-----> %s", self.addr) self.log.info("===============Testing EEH Frozen PE==================")
def _check_reference(self, produced_file_path, reference_file_name, diff_file_name, child_log_name, name='Content'): ''' Compares the file produced by the test with the reference file :param produced_file_path: the location of the file that was produced by this test execution :type produced_file_path: str :param reference_file_name: the name of the file that will compared with the content produced by this test :type reference_file_name: str :param diff_file_name: in case of differences between the produced and reference file, a file with this name will be saved to the test results directory, with the differences in unified diff format :type diff_file_name: str :param child_log_name: the name of a logger, child of :data:`LOG_JOB`, to be used when logging the content differences :type child_log_name: str :param name: optional parameter for a descriptive name of the type of content being checked here :type name: str :returns: True if the check was performed (there was a reference file) and was successful, and False otherwise (there was no such reference file and thus no check was performed). :raises: :class:`exceptions.TestFail` when the check is performed and fails ''' reference_path = self.get_data(reference_file_name) if reference_path is not None: expected = genio.read_file(reference_path) actual = genio.read_file(produced_file_path) diff_path = os.path.join(self.logdir, diff_file_name) fmt = '%(message)s' formatter = logging.Formatter(fmt=fmt) log_diff = LOG_JOB.getChild(child_log_name) self._register_log_file_handler(log_diff, formatter, diff_path) diff = unified_diff(expected.splitlines(), actual.splitlines(), fromfile=reference_path, tofile=produced_file_path) diff_content = [] for diff_line in diff: diff_content.append(diff_line.rstrip('\n')) if diff_content: self.log.debug('%s Diff:', name) for line in diff_content: log_diff.debug(line) self.fail('Actual test %s differs from expected one' % name) else: return True return False
def test_event_w_chip_param(self): if self.cpu_family in ['power8', 'power9']: event_out = genio.read_file("%s/events/PM_PB_CYC" % self.event_sysfs).rstrip('\t\r\n\0') if self.cpu_family == 'power10': event_out = genio.read_file("%s/events/PM_PHB0_0_CYC" % self.event_sysfs).rstrip('\t\r\n\0') if "chip=?" in event_out: self.log.info('sysfs entry has chip entry') else: self.fail('sysfs does not have chip entry') if os.path.exists("%s/format/chip" % self.event_sysfs): self.log.info('chip file exists') else: self.fail('chip file does not exist')
def bond_fail(self, arg1): ''' bond fail ''' if len(self.host_interfaces) > 1: for interface in self.host_interfaces: self.log.info("Failing interface %s for mode %s", interface, arg1) cmd = "ip link set %s down" % interface if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("bonding not working when trying to down the\ interface %s " % interface) time.sleep(self.sleep_time) if self.ping_check(): self.log.info("Ping passed for Mode %s", arg1) else: error_str = "Ping fail in Mode %s when interface %s down"\ % (arg1, interface) self.log.debug(error_str) self.err.append(error_str) self.log.info(genio.read_file(self.bond_status)) cmd = "ip link set %s up" % interface time.sleep(self.sleep_time) if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("Not able to bring up the slave\ interface %s" % interface) time.sleep(self.sleep_time) else: self.log.debug("Need a min of 2 host interfaces to test\ slave failover in Bonding") self.log.info("\n----------------------------------------") self.log.info("Failing all interfaces for mode %s", arg1) self.log.info("----------------------------------------") for interface in self.host_interfaces: cmd = "ip link set %s down" % interface if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("Could not bring down the interface %s " % interface) time.sleep(self.sleep_time) if not self.ping_check(): self.log.info("Ping to Bond interface failed. This is expected") self.log.info(genio.read_file(self.bond_status)) for interface in self.host_interfaces: cmd = "ip link set %s up" % interface time.sleep(self.sleep_time) if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("Not able to bring up the slave\ interface %s" % interface) time.sleep(self.sleep_time)
def test_statistics(self): ''' Test Statistics ''' rx_file = "/sys/class/net/%s/statistics/rx_packets" % self.iface tx_file = "/sys/class/net/%s/statistics/tx_packets" % self.iface rx_before = genio.read_file(rx_file) tx_before = genio.read_file(tx_file) self.networkinterface.ping_check(self.peer, count=500000, options='-f') rx_after = genio.read_file(rx_file) tx_after = genio.read_file(tx_file) if (rx_after <= rx_before) or (tx_after <= tx_before): self.log.debug("Before\nrx: %s tx: %s" % (rx_before, tx_before)) self.log.debug("After\nrx: %s tx: %s" % (rx_after, tx_after)) self.fail("Statistics not incremented properly")
def test(self): self.log.info("===Checking for cpu VPA data and MaxMem==") cpu_count = len(os.listdir('/sys/kernel/debug/powerpc/vpa')) output = genio.read_file('/proc/powerpc/lparcfg').rstrip('\t\r\n\0') for line in output.splitlines(): if 'MaxMem=' in line: maxmem = line.split('=')[1].strip() output = process.system_output('lscpu', shell=True, ignore_status=True) for line in output.decode().splitlines(): if line.startswith('CPU'): total_cpus = line.split(':')[1].strip() output = process.system_output('lparstat -i', shell=True, ignore_status=True) for line in output.decode().splitlines(): if 'Maximum Memory' in line: lmaxmem = line.split(':')[1].strip() if ((cpu_count == int(total_cpus)) and (maxmem == lmaxmem)): self.log.info( "Files are generated for all cpu's and maxmem values are same") else: self.fail( "Files are not generated for all cpu's and maxmem values are not same" )
def test_dry_run(self): cmd = ( "%s run --disable-sysinfo --dry-run --dry-run-no-cleanup --json - " "--test-runner=runner " "--mux-inject foo:1 bar:2 baz:3 foo:foo:a " "foo:bar:b foo:baz:c bar:bar:bar " "-- examples/tests/passtest.py " "examples/tests/failtest.py " "examples/tests/gendata.py " % AVOCADO) number_of_tests = 3 result = json.loads(process.run(cmd).stdout_text) log = '' for test in result['tests']: debuglog = test['logfile'] log += genio.read_file(debuglog) # Remove the result dir shutil.rmtree(os.path.dirname(os.path.dirname(debuglog))) self.assertIn(tempfile.gettempdir(), debuglog) # Use tmp dir, not default location self.assertEqual(result['job_id'], u'0' * 40) # Check if all tests were skipped self.assertEqual(result['cancel'], number_of_tests) for i in range(number_of_tests): test = result['tests'][i] self.assertEqual(test['fail_reason'], u'Test cancelled due to --dry-run') # Check if all params are listed # The "/:bar ==> 2 is in the tree, but not in any leave so inaccessible # from test. for line in ("/:foo ==> 1", "/:baz ==> 3", "/foo:foo ==> a", "/foo:bar ==> b", "/foo:baz ==> c", "/bar:bar ==> bar"): self.assertEqual( log.count(line), number_of_tests, "Avocado log count for param '%s' not as expected:\n%s" % (line, log))
def setUp(self): """ Install necessary packages to build the linux module """ if 'power' not in cpu.get_family(): self.cancel('Test Only supported on Power') pkgs = ['gcc', 'make', 'kernel-devel'] smm = SoftwareManager() for package in pkgs: if not smm.check_installed(package) and not smm.install(package): self.cancel('%s is needed for the test to be run' % package) tarball = self.fetch_asset("ipistorm.zip", locations=[ "https://github.com/antonblanchard/ipistorm" "/archive/master.zip"], expire='7d') archive.extract(tarball, self.teststmpdir) teststmpdir = os.path.join(self.teststmpdir, "ipistorm-master") os.chdir(teststmpdir) kernel_version = platform.uname()[2] if not os.path.exists(os.path.join("/lib/modules", kernel_version)): self.cancel( "Modules of running kernel missing to build ipistorm module") build.make(teststmpdir) if not os.path.isfile(os.path.join(teststmpdir, 'ipistorm.ko')): self.fail("No ipistorm.ko found, module build failed") int_op = genio.read_file("/proc/interrupts") if "XIVE" not in int_op: self.cancel("Test is supported only with XIVE")
def setUp(self): """ Gets the console and set-up the machine for test """ if 'ppc' not in distro.detect().arch: self.cancel("Processor is not ppc64") if 'PowerNV' in genio.read_file("/proc/cpuinfo").strip(): self.cancel("Test not supported on bare-metal") if '0x1' not in genio.read_file("/sys/kernel/debug/powerpc/eeh_enable").strip(): self.cancel("EEH is not enabled, please enable via FSP") self.max_freeze = self.params.get('max_freeze', default=1) cmd = "echo %d > /sys/kernel/debug/powerpc/eeh_max_freezes"\ % self.max_freeze process.system(cmd, ignore_status=True, shell=True) self.function = str(self.params.get('function')).split(" ") self.log.info("===============Testing EEH Frozen PE==================")
def test_mux_inject(self): cmd = ("%s run --disable-sysinfo --json - " "--mux-inject foo:1 bar:2 baz:3 foo:foo:a " "foo:bar:b foo:baz:c bar:bar:bar " "-- examples/tests/params.py " "examples/tests/params.py " "examples/tests/params.py " % AVOCADO) number_of_tests = 3 result = json.loads(process.run(cmd).stdout_text) log = '' for test in result['tests']: debuglog = test['logfile'] log += genio.read_file(debuglog) # Remove the result dir shutil.rmtree(os.path.dirname(os.path.dirname(debuglog))) self.assertIn(tempfile.gettempdir(), log) # Use tmp dir, not default location # Check if all params are listed # The "/:bar ==> 2 is in the tree, but not in any leave so inaccessible # from test. for line in ("/:foo ==> 1", "/:baz ==> 3", "/foo:foo ==> a", "/foo:bar ==> b", "/foo:baz ==> c", "/bar:bar ==> bar"): self.assertEqual( log.count(line), number_of_tests, "Avocado log count for param '%s' not as expected:\n%s" % (line, log))
def test(self): """ Test run is a One way throughput test. In this test, we have one host transmitting (or receiving) data from a client. This transmit large messages using multiple threads or processes. """ speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) cmd = "h=%s proto=tcp ./src/uperf -m manual/throughput.xml -a" \ % self.peer_ip result = process.run(cmd, shell=True, ignore_status=True) if result.exit_status: self.fail("FAIL: Uperf Run failed") for line in result.stdout.decode("utf-8").splitlines(): if self.peer_ip in line: if 'Mb/s' in line: tput = int(line.split()[3].split('.')[0]) else: # Converting the throughput calculated in Gb to Mb tput = int(line.split()[3].split('.')[0]) * 1000 if tput < (int(self.expected_tp) * speed) / 100: self.fail("FAIL: Throughput Actual - %s%%, Expected - %s%%" ", Throughput Actual value - %s " % ((tput*100)/speed, self.expected_tp, str(tput)+'Mb/sec')) if 'WARNING' in result.stdout.decode("utf-8"): self.log.warn('Test completed with warning')
def setUp(self): """ Verifies if powerpc-utils is installed, and gets current SMT value. """ if 'ppc' not in distro.detect().arch: self.cancel("Processor is not ppc64") if SoftwareManager().check_installed("powerpc-utils") is False: if SoftwareManager().install("powerpc-utils") is False: self.cancel("powerpc-utils is not installing") self.smt_str = "ppc64_cpu --smt" smt_op = process.system_output(self.smt_str, shell=True) if "is not SMT capable" in smt_op: self.cancel("Machine is not SMT capable") if "Inconsistent state" in smt_op: self.cancel("Machine has mix of ST and SMT cores") self.curr_smt = smt_op.strip().split("=")[-1].split()[-1] self.smt_subcores = 0 if os.path.exists("/sys/devices/system/cpu/subcores_per_core"): self.smt_subcores = 1 self.failures = 0 self.failure_message = "\n" self.smt_values = {1: "off"} self.key = 0 self.value = "" self.max_smt_value = 4 if cpu.get_cpu_arch().lower() == 'power9': if 'Hash' in genio.read_file('/proc/cpuinfo').rstrip('\t\r\n\0'): self.max_smt_value = 8 if cpu.get_cpu_arch().lower() == 'power8': self.max_smt_value = 8 if cpu.get_cpu_arch().lower() == 'power6': self.max_smt_value = 2
def test(self): """ netperf test """ if self.netperf_run == '1': tmp = "chmod 777 /tmp/%s/src" % self.version cmd = "ssh %s@%s \"%s\"" % (self.peer_user, self.peer_ip, tmp) if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("test failed because netserver not available") cmd = "ssh %s@%s \"/tmp/%s/src/netserver\"" % ( self.peer_user, self.peer_ip, self.version) if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("test failed because netserver not available") speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) self.expected_tp = int(self.expected_tp) * speed / 100 cmd = "timeout %s %s -H %s" % (self.timeout, self.perf, self.peer_ip) if self.option != "": cmd = "%s -t %s" % (cmd, self.option) cmd = "%s -l %s -i %s,%s" % (cmd, self.duration, self.max, self.min) result = process.run(cmd, shell=True, ignore_status=True) if result.exit_status != 0: self.fail("FAIL: Run failed") for line in result.stdout.splitlines(): if line and 'Throughput' in line.split()[-1]: tput = int(result.stdout.split()[-1].split('.')[0]) if tput < self.expected_tp: self.fail("FAIL: Throughput Actual - %d, Expected - %d" % (tput, self.expected_tp)) if 'WARNING' in result.stdout: self.log.warn('Test completed with warning')
def test_statistics(self): ''' Test Statistics ''' rx_file = "/sys/class/net/%s/statistics/rx_packets" % self.iface tx_file = "/sys/class/net/%s/statistics/tx_packets" % self.iface rx_before = genio.read_file(rx_file) tx_before = genio.read_file(tx_file) configure_network.ping_check(self.iface, self.peer, "500000", flood=True) rx_after = genio.read_file(rx_file) tx_after = genio.read_file(tx_file) if (rx_after <= rx_before) or (tx_after <= tx_before): self.log.debug("Before\nrx: %s tx: %s" % (rx_before, tx_before)) self.log.debug("After\nrx: %s tx: %s" % (rx_after, tx_after)) self.fail("Statistics not incremented properly")
def _check_test(self, test, expected): klass_method = test["id"].split(":")[1] self.assertEqual( expected[0], test["status"], (f"Status error: '{expected[0]}' != " f"'{test['status']}' ({klass_method})"), ) debug_log = genio.read_file(test["logfile"]) for msg in expected[1]: self.assertIn( msg, debug_log, (f"Message '{msg}' should be in the log " f"({klass_method})." f"\nJSON results:\n{test}" f"\nDebug Log:\n{debug_log}"), ) for msg in set(ALL_MESSAGES) - set(expected[1]): self.assertNotIn( msg, debug_log, (f"Message '{msg}' should not be in the log " "({klass_method})" f"\nJSON results:\n{test}" f"\nDebug Log:\n{debug_log}"), )
def test(self): """ netperf test """ if self.netperf_run == '1': tmp = "chmod 777 /tmp/%s/src" % self.version cmd = "ssh %s@%s \"%s\"" % (self.peer_user, self.peer_ip, tmp) if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("test failed because netserver not available") cmd = "ssh %s@%s \"/tmp/%s/src/netserver\"" % (self.peer_user, self.peer_ip, self.version) if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("test failed because netserver not available") speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) self.expected_tp = int(self.expected_tp) * speed / 100 cmd = "timeout %s %s -H %s" % (self.timeout, self.perf, self.peer_ip) if self.option != "": cmd = "%s -t %s" % (cmd, self.option) cmd = "%s -l %s -i %s,%s" % (cmd, self.duration, self.max, self.min) result = process.run(cmd, shell=True, ignore_status=True) if result.exit_status != 0: self.fail("FAIL: Run failed") for line in result.stdout.splitlines(): if line and 'Throughput' in line.split()[-1]: tput = int(result.stdout.split()[-1].split('.')[0]) if tput < self.expected_tp: self.fail("FAIL: Throughput Actual - %d, Expected - %d" % (tput, self.expected_tp)) if 'WARNING' in result.stdout: self.log.warn('Test completed with warning')
def dlpar_cpu_hotplug(self): if 'PowerNV' not in \ genio.read_file('/proc/cpuinfo').rstrip('\t\r\n\0'): if "cpu_dlpar=yes" in process.system_output("drmgr -C", ignore_status=True, shell=True): self.log.info("\nDLPAR remove cpu operation\n") for _ in range(self.dlpar_loop): process.run("drmgr -c cpu -r -q %s -w 5 -d 1" % self.cpu_unit, shell=True, ignore_status=True, sudo=True) self.log.info("\nDLPAR add cpu operation\n") for _ in range(self.dlpar_loop): process.run("drmgr -c cpu -a -q %s -w 5 -d 1" % self.cpu_unit, shell=True, ignore_status=True, sudo=True) else: self.log.info('UNSUPPORTED: dlpar not configured..') else: self.log.info("UNSUPPORTED: Test not supported on this platform")
def test(self): """ netperf test """ if self.netperf_run == '1': cmd = "chmod 777 /tmp/%s/src" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("test failed because netserver not available") cmd = "/tmp/%s/src/netserver" % self.version output = self.session.cmd(cmd) if not output.exit_status == 0: self.fail("test failed because netserver not available") speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) cmd = "timeout %s %s -H %s" % (self.timeout, self.perf, self.peer_ip) if self.option != "": cmd = "%s -t %s" % (cmd, self.option) cmd = "%s -l %s -i %s,%s" % (cmd, self.duration, self.max, self.min) result = process.run(cmd, shell=True, ignore_status=True) if result.exit_status != 0: self.fail("FAIL: Run failed") for line in result.stdout.decode("utf-8").splitlines(): if line and 'Throughput' in line.split()[-1]: tput = int( result.stdout.decode("utf-8").split()[-1].split('.')[0]) if tput < (int(self.expected_tp) * speed) / 100: self.fail("FAIL: Throughput Actual - %s%%, Expected - %s%%" ", Throughput Actual value - %s " % ((tput * 100) / speed, self.expected_tp, str(tput) + 'Mb/sec')) if 'WARNING' in result.stdout.decode("utf-8"): self.log.warn('Test completed with warning')
def is_baremetal(): """ to check system is bare-metal or not """ if 'PowerNV' in genio.read_file("/proc/cpuinfo").strip(): return True return False
def test(self): """ netperf test """ if self.netperf_run == 0: tmp = "chmod 777 /tmp/%s/src" % self.version cmd = "ssh %s@%s \"%s\"" % (self.peer_user, self.peer_ip, tmp) if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("test failed because netserver not available") cmd = "ssh %s@%s \"/tmp/%s/src/netserver\"" % (self.peer_user, self.peer_ip, self.version) if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("test failed because netserver not available") else: self.netperf_run = 1 for option in ["", "UDP_STREAM -- -m 63000", "TCP_RR", "UDP_RR"]: cmd = "timeout %s %s -H %s" % (self.timeout, self.perf, self.peer_ip) if option != "": cmd = "%s -t %s" % (cmd, option) result = process.run(cmd, shell=True, ignore_status=True) if result.exit_status != 0: self.fail("test failed when run with %s" % option) speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) if 'Throughput' in result.stdout: throughput = int(result.stdout.split()[-1].split('.')[0]) if throughput * 100 < self.expected_tp * speed: self.fail("Throughput %d is lower than expected %d" % (throughput, self.expected_tp * speed / 100))
def test_run_mplex_params(self): for variant_msg in (('/run/short', 'A'), ('/run/medium', 'ASDFASDF'), ('/run/long', 'This is very long\nmultiline\ntext.')): variant, msg = variant_msg cmd_line = ( '%s run --job-results-dir %s --disable-sysinfo ' 'examples/tests/custom_env_variable.sh ' '-m examples/tests/custom_env_variable.sh.data/variants.yaml ' '--mux-filter-only %s' % (AVOCADO, self.tmpdir.name, variant)) expected_rc = exit_codes.AVOCADO_ALL_OK result = self.run_and_check(cmd_line, expected_rc) log_files = glob.glob( os.path.join(self.tmpdir.name, 'latest', 'test-results', '*', 'debug.log')) result = '' for log_file in log_files: result += genio.read_file(log_file) msg_lines = msg.splitlines() msg_header = '[stdout] Custom variable: %s' % msg_lines[0] self.assertIn( msg_header, result, "Multiplexed variable should produce:" "\n %s\nwhich is not present in the output:\n %s" % (msg_header, "\n ".join(result.splitlines()))) for msg_remain in msg_lines[1:]: self.assertIn( '[stdout] %s' % msg_remain, result, "Multiplexed variable should produce:" "\n %s\nwhich is not present in the output:\n %s" % (msg_remain, "\n ".join(result.splitlines())))
def mount_point(mount_dir): lines = genio.read_file('/proc/mounts').rstrip('\t\r\0').splitlines() for substr in lines: mop = substr.split(" ")[1] if mop == mount_dir: return True return False
def test(self): """ Test run is a One way throughput test. In this test, we have one host transmitting (or receiving) data from a client. This transmit large messages using multiple threads or processes. """ speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) os.chdir(self.iperf) cmd = "./iperf -c %s" % self.peer_ip result = process.run(cmd, shell=True, ignore_status=True) nping_result = self.nping() if result.exit_status: self.fail("FAIL: Iperf Run failed") for line in result.stdout.decode("utf-8").splitlines(): if 'local {}'.format(self.ipaddr) in line: id = line[3] for line in result.stdout.decode("utf-8").splitlines(): if id in line and 'Mbits/sec' in line: tput = int(line.split()[6]) elif id in line and 'Gbits/sec' in line: tput = int(float(line.split()[6])) * 1000 if tput < (int(self.expected_tp) * speed) / 100: self.fail( "FAIL: Throughput Actual - %s%%, Expected - %s%%" ", Throughput Actual value - %s " % ((tput * 100) / speed, self.expected_tp, str(tput) + 'Mb/sec')) for line in nping_result.stdout.decode("utf-8").splitlines(): if 'Raw packets' in line: lost = int(line.split("|")[2].split(" ")[2]) * 10 if lost > 60: self.fail("FAIL: Ping fails after iperf test")
def cpu_freq_path(self, file): """ get cpu_freq values :param: file: is filename for which data needs to be fetched """ f_name = "/sys/devices/system/cpu/cpu%s/cpufreq/%s" % ( self.cpu_num, file) return genio.read_file(f_name).rstrip('\n').strip(' ')
def memtotal_sys(): """ Reports actual memory size according to online-memory blocks available via "/sys" :return: system memory in Kb as float """ sys_mempath = "/sys/devices/system/memory" no_memblocks = 0 for directory in os.listdir(sys_mempath): if directory.startswith("memory"): path = os.path.join(sys_mempath, directory, "online") if genio.read_file(path).strip() == "1": no_memblocks += 1 path = os.path.join(sys_mempath, "block_size_bytes") block_size = int(genio.read_file(path).strip(), 16) return (no_memblocks * block_size) / 1024.0
def cpu_freq_path(self, file): """ get cpu_freq values :param: file: is filename for which data needs to be fetched """ f_name = "/sys/devices/system/cpu/cpu%s/cpufreq/%s" % (self.cpu_num, file) return genio.read_file(f_name).rstrip('\n').strip(' ')
def setUp(self): """ Gets the console and set-up the machine for test """ if 'ppc' not in distro.detect().arch: self.cancel("Processor is not ppc64") if 'PowerNV' in genio.read_file("/proc/cpuinfo").strip(): self.cancel("Test not supported on bare-metal") if '0x1' not in genio.read_file( "/sys/kernel/debug/powerpc/eeh_enable").strip(): self.cancel("EEH is not enabled, please enable via FSP") self.max_freeze = self.params.get('max_freeze', default=1) cmd = "echo %d > /sys/kernel/debug/powerpc/eeh_max_freezes"\ % self.max_freeze process.system(cmd, ignore_status=True, shell=True) self.function = str(self.params.get('function')).split(" ") self.log.info("===============Testing EEH Frozen PE==================")
def read_from_meminfo(key): """ Retrieve key from meminfo. :param key: Key name, such as ``MemTotal``. """ for line in genio.read_file("/proc/meminfo").splitlines(): if key in line: return int(re.search(r"(\d+)\s*(?:kB)?$", line).group(1))
def subcore(self): """ Tests the subcores in ppc64_cpu command. """ op1 = process.system_output("ppc64_cpu --subcores-per-core", shell=True).strip().split()[-1] op2 = genio.read_file( "/sys/devices/system/cpu/subcores_per_core").strip() self.equality_check("Subcore", op1, op2)
def dscr(self): """ Tests the dscr in ppc64_cpu command. """ op1 = process.system_output( "ppc64_cpu --dscr", shell=True).decode("utf-8").strip().split()[-1] op2 = int(genio.read_file( "/sys/devices/system/cpu/dscr_default").strip(), 16) self.equality_check("DSCR", op1, op2)
def get_size_alignval(): """ Return the size align restriction based on platform """ if 'Hash' in genio.read_file('/proc/cpuinfo').rstrip('\t\r\n\0'): def_align = 16 * 1024 * 1024 else: def_align = 2 * 1024 * 1024 return def_align
def subcore(self): """ Tests the subcores in ppc64_cpu command. """ op1 = process.system_output( "ppc64_cpu --subcores-per-core", shell=True).strip().split()[-1] op2 = genio.read_file( "/sys/devices/system/cpu/subcores_per_core").strip() self.equality_check("Subcore", op1, op2)
def dscr(self): """ Tests the dscr in ppc64_cpu command. """ op1 = process.system_output( "ppc64_cpu --dscr", shell=True).strip().split()[-1] op2 = int(genio.read_file( "/sys/devices/system/cpu/dscr_default").strip(), 16) self.equality_check("DSCR", op1, op2)
def check_output_files(self, debug_log): base_dir = os.path.dirname(debug_log) json_output_path = os.path.join(base_dir, 'results.json') self.assertTrue(os.path.isfile(json_output_path)) with open(json_output_path, 'r') as fp: json.load(fp) xunit_output_path = os.path.join(base_dir, 'results.xml') self.assertTrue(os.path.isfile(json_output_path)) try: minidom.parse(xunit_output_path) except Exception as details: xunit_output_content = genio.read_file(xunit_output_path) raise AssertionError("Unable to parse xunit output: %s\n\n%s" % (details, xunit_output_content)) tap_output = os.path.join(base_dir, "results.tap") self.assertTrue(os.path.isfile(tap_output)) tap = genio.read_file(tap_output) self.assertIn("..", tap) self.assertIn("\n# debug.log of ", tap)
def _check_timeout_msg(self, idx): res_dir = os.path.join(self.tmpdir, "latest", "test-results") debug_log_paths = glob.glob(os.path.join(res_dir, "%s-*" % idx, "debug.log")) debug_log = genio.read_file(debug_log_paths[0]) self.assertIn("Runner error occurred: Timeout reached", debug_log, "Runner error occurred: Timeout reached message not " "in the %sst test's debug.log:\n%s" % (idx, debug_log)) self.assertIn("Traceback (most recent call last)", debug_log, "Traceback not present in the %sst test's debug.log:\n%s" % (idx, debug_log))
def setUp(self): """ Setup the device. """ cmd = "uname -p" if 'ppc' not in process.system_output(cmd, ignore_status=True): self.cancel("Processor is not ppc64") cmd = "cat /proc/cpuinfo" if cpu._list_matches(open('/proc/cpuinfo').readlines(), 'platform\t: pSeries\n'): PowerVM = True for mdl in ['rpaphp', 'rpadlpar_io']: if not linux_modules.module_is_loaded(mdl): linux_modules.load_module(mdl) elif cpu._list_matches(open('/proc/cpuinfo').readlines(), 'platform\t: PowerNV\n'): PowerVM = False if not linux_modules.module_is_loaded("pnv_php"): linux_modules.load_module("pnv_php") self.return_code = 0 self.device = self.params.get('pci_device', default=' ') self.num_of_hotplug = int(self.params.get('num_of_hotplug', default='1')) if not os.path.isdir('/sys/bus/pci/devices/%s' % self.device): self.cancel("PCI device given does not exist") if PowerVM: devspec = genio.read_file("/sys/bus/pci/devices/%s/devspec" % self.device) self.slot = genio.read_file("/proc/device-tree/%s/ibm,loc-code" % devspec) self.slot = re.match(r'((\w+)[\.])+(\w+)-P(\d+)-C(\d+)|Slot(\d+)', self.slot).group() else: self.slot = pci.get_pci_prop(self.device, "PhySlot") if not os.path.isdir('/sys/bus/pci/slots/%s' % self.slot): self.cancel("%s Slot not available" % self.slot) if not os.path.exists('/sys/bus/pci/slots/%s/power' % self.slot): self.cancel("%s Slot does not support hotplug" % self.slot)
def setUp(self): """ To check and install dependencies for the test """ smm = SoftwareManager() detected_distro = distro.detect() pkgs = ["gcc", "autoconf", "perl", "m4", "git-core"] if detected_distro.name == "Ubuntu": pkgs.extend(["libsctp1", "libsctp-dev", "lksctp-tools"]) else: pkgs.extend(["lksctp-tools", "lksctp-tools-devel"]) for pkg in pkgs: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) interfaces = netifaces.interfaces() self.iface = self.params.get("interface", default="") self.peer_ip = self.params.get("peer_ip", default="") if self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.peer_user = self.params.get("peer_user_name", default="root") uperf_download = self.params.get("uperf_download", default="https:" "//github.com/uperf/uperf/" "archive/master.zip") tarball = self.fetch_asset("uperf.zip", locations=[uperf_download], expire='7d') archive.extract(tarball, self.teststmpdir) self.uperf_dir = os.path.join(self.teststmpdir, "uperf-master") cmd = "scp -r %s %s@%s:/tmp" % (self.uperf_dir, self.peer_user, self.peer_ip) if process.system(cmd, shell=True, ignore_status=True) != 0: self.cancel("unable to copy the uperf into peer machine") cmd = "ssh %s@%s \"cd /tmp/uperf-master;autoreconf -fi;./configure " \ "ppc64le;make\"" % (self.peer_user, self.peer_ip) if process.system(cmd, ignore_status=True, shell=True, sudo=True): self.cancel("Unable to compile Uperf into peer machine") self.uperf_run = str(self.params.get("UPERF_SERVER_RUN", default=0)) if self.uperf_run == '1': cmd = "ssh %s@%s \"cd /tmp/uperf-master/src;./uperf -s\""\ % (self.peer_user, self.peer_ip) obj = process.SubProcess(cmd, verbose=False, shell=True) obj.start() os.chdir(self.uperf_dir) process.system('autoreconf -fi', shell=True) process.system('./configure ppc64le', shell=True) build.make(self.uperf_dir) self.expected_tp = self.params.get("EXPECTED_THROUGHPUT", default="85") speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) self.expected_tp = int(self.expected_tp) * speed / 100
def setUp(self): """ Gets the console and set-up the machine for test """ if 'ppc' not in distro.detect().arch: self.cancel("Processor is not ppc64") output = genio.read_file("/sys/kernel/debug/powerpc/eeh_enable")\ .strip() if output != '0x1': self.cancel("EEH is not enabled, please enable via FSP") self.max_freeze = int(self.params.get('max_freeze', default='1')) cmd = "echo %d > /sys/kernel/debug/powerpc/eeh_max_freezes"\ % self.max_freeze process.system(cmd, ignore_status=True, shell=True) self.function = str(self.params.get('function')) self.err = str(self.params.get('err')) self.pci_device = str(self.params.get('pci_device', default=' ')) self.phb = self.pci_device.split(":", 1)[0] self.addr = genio.read_file("/sys/bus/pci/devices/%s/" "eeh_pe_config_addr" % self.pci_device) self.addr = str(self.addr).rstrip() self.log.info("Test-----> %s", self.addr) self.log.info("===============Testing EEH Frozen PE==================")
def quad_to_cpu_mapping(self): """ Get the total quad and cpus list belonging to each quad. """ self.nums = range(0, self.cpus) for cpu in self.nums: phy_id = genio.read_file( '/sys/devices/system/cpu/cpu%s/physical_id' % cpu).rstrip("\n") quad_id = int(phy_id) >> 4 & 0x7 chip_id = int(phy_id) >> 8 & 0x7F if chip_id not in self.quad_dict.keys(): self.quad_dict[chip_id] = {} if quad_id not in self.quad_dict[chip_id].keys(): self.quad_dict[chip_id][quad_id] = [] self.quad_dict[chip_id][quad_id].append(cpu)
def test_prod_id_serial(self): """ Test verifies the product id and serial number in lshw output. """ self.log.info("===============Validating product id and serial number" "===========") self.is_fail = 0 if 'KVM' in self.run_cmd_out("pseries_platform"): product_path = '/proc/device-tree/host-model' serial_path = '/proc/device-tree/host-serial' else: product_path = '/proc/device-tree/model' serial_path = '/proc/device-tree/system-id' product_name = genio.read_file(product_path).rstrip(' \t\r\n\0') serial_num = genio.read_file(serial_path).rstrip(' \t\r\n\0') if product_name\ not in self.run_cmd_out("lshw | grep product | head -1"): self.is_fail += 1 if serial_num not in self.run_cmd_out("lshw | grep serial | head -1"): self.is_fail += 1 if self.is_fail >= 1: self.fail("%s command(s) failed to execute " % self.fail_cmd)
def setUp(self): smm = SoftwareManager() dist = distro.detect() memsize = int(memory.freememtotal() * 1024 * 0.2) self.nr_pages = self.params.get( 'nr_pages', default=memsize / memory.get_page_size()) self.map_type = self.params.get('map_type', default='private') self.hpage = self.params.get('h_page', default=False) nodes = memory.numa_nodes_with_memory() if len(nodes) < 2: self.cancel('Test requires two numa nodes to run.' 'Node list with memory: %s' % nodes) pkgs = ['gcc', 'make'] hp_check = 0 if self.hpage: hp_size = memory.get_huge_page_size() for node in nodes: genio.write_file('/sys/devices/system/node/node%s/hugepages/hu' 'gepages-%skB/nr_hugepages' % (node, str(hp_size)), str(self.nr_pages)) for node in nodes: hp_check += int(genio.read_file( '/sys/devices/system/node/node%s/hugepages/hugepages-%skB' '/nr_hugepages' % (node, str(hp_size))).strip()) if hp_check < self.nr_pages: self.cancel('Not enough pages to be configured on nodes') if dist.name == "Ubuntu": pkgs.extend(['libpthread-stubs0-dev', 'libnuma-dev', 'libhugetlbfs-dev']) elif dist.name in ["centos", "rhel", "fedora"]: pkgs.extend(['numactl-devel', 'libhugetlbfs-devel']) elif dist.name == "SuSE": pkgs.extend(['libnuma-devel']) if dist.version >= 15: pkgs.extend(['libhugetlbfs-devel']) else: pkgs.extend(['libhugetlbfs-libhugetlb-devel']) for package in pkgs: if not smm.check_installed(package) and not smm.install(package): self.cancel('%s is needed for the test to be run' % package) for file_name in ['util.c', 'numa_test.c', 'Makefile']: self.copyutil(file_name) build.make(self.teststmpdir)
def smt_snoozedelay(self): """ Tests the smt snooze delay in ppc64_cpu command. """ snz_content = set() op1 = process.system_output( "ppc64_cpu --smt-snooze-delay", shell=True).strip().split()[-1] snz_delay = "cpu*/smt_snooze_delay" if os.path.isdir("/sys/bus/cpu/devices"): snz_delay = "/sys/bus/cpu/devices/%s" % snz_delay else: snz_delay = "/sys/devices/system/cpu/%s" % snz_delay for filename in glob.glob(snz_delay): snz_content.add(genio.read_file(filename).strip()) op2 = list(snz_content)[0] self.equality_check("SMT snooze delay", op1, op2)
def test_setup(self): ''' bonding the interfaces work for multiple interfaces on both host and peer ''' msg = "[ -d %s ]" % self.bond_dir cmd = "ssh %s@%s %s" % (self.user, self.peer_first_ipinterface, msg) if process.system(cmd, shell=True, ignore_status=True) == 0: self.fail("bond name already exists on peer machine") if os.path.isdir(self.bond_dir): self.fail("bond name already exists on local machine") if self.peer_bond_needed: self.bond_setup("peer", "") self.bond_setup("local", self.mode) self.log.info(genio.read_file(self.bond_status)) self.ping_check() self.error_check()
def test_uprobe(self): output = self.cmd_verify('%s /usr/bin/perf main' % self.cmdProbe) if 'Added new event' not in output.stderr: self.fail("perf: probe of perf main failed") output = self.cmd_verify('perf probe -l') if 'probe_perf:main' not in output.stdout: self.fail("perf: probe of 'perf main' not found in list") sysfsfile = '/sys/kernel/debug/tracing/uprobe_events' if 'probe_perf' not in genio.read_file( '/sys/kernel/debug/tracing/uprobe_events' ).rstrip('\t\r\n\0'): self.fail("perf: sysfs file didn't reflect uprobe events") output = self.cmd_verify('perf record -o %s -e probe_perf:main -- ' 'perf list' % self.temp_file) if 'samples' not in output.stderr: self.fail("perf: perf.data file not created") output = self.cmd_verify(self.report)
def setUp(self): """ Gets the console and set-up the machine for test """ if 'ppc' not in distro.detect().arch: self.cancel("Processor is not ppc64") output = genio.read_file("/sys/kernel/debug/powerpc/eeh_enable")\ .strip() if output != '0x1': self.cancel("EEH is not enabled, please enable via FSP") sys.exit(1) self.max_freeze = int(self.params.get('max_freeze', default='1')) cmd = "echo %d > /sys/kernel/debug/powerpc/eeh_max_freezes"\ % self.max_freeze process.system(cmd, ignore_status=True, shell=True) self.function = str(self.params.get('function')).split(" ") self.log.info("===============Testing EEH Frozen PE==================")
def setUp(self): """ To check and install dependencies for the test """ smm = SoftwareManager() for pkg in ["gcc", "autoconf", "perl", "m4"]: if not smm.check_installed(pkg) and not smm.install(pkg): self.cancel("%s package is need to test" % pkg) interfaces = netifaces.interfaces() self.iface = self.params.get("interface", default="") self.peer_ip = self.params.get("peer_ip", default="") if self.iface not in interfaces: self.cancel("%s interface is not available" % self.iface) if self.peer_ip == "": self.cancel("%s peer machine is not available" % self.peer_ip) self.peer_user = self.params.get("peer_user_name", default="root") iperf_download = self.params.get("iperf_download", default="https:" "//github.com/esnet/" "iperf/archive/master.zip") tarball = self.fetch_asset("iperf.zip", locations=[iperf_download], expire='7d') archive.extract(tarball, self.teststmpdir) self.iperf_dir = os.path.join(self.teststmpdir, "iperf-master") cmd = "scp -r %s %s@%s:/tmp" % (self.iperf_dir, self.peer_user, self.peer_ip) if process.system(cmd, shell=True, ignore_status=True) != 0: self.cancel("unable to copy the iperf into peer machine") cmd = "ssh %s@%s \"cd /tmp/iperf-master;./bootstrap.sh;./configure;" \ "make\"" % (self.peer_user, self.peer_ip) if process.system(cmd, ignore_status=True, shell=True, sudo=True): self.cancel("Unable to compile Iperf into peer machine") self.iperf_run = str(self.params.get("IPERF_SERVER_RUN", default=0)) if self.iperf_run == '1': cmd = "ssh %s@%s \"cd /tmp/iperf-master/src/;./iperf3 -s\""\ % (self.peer_user, self.peer_ip) obj = process.SubProcess(cmd, verbose=False, shell=True) obj.start() os.chdir(self.iperf_dir) process.system('./bootstrap.sh', shell=True) process.system('./configure', shell=True) build.make(self.iperf_dir) self.iperf = os.path.join(self.iperf_dir, 'src') self.expected_tp = self.params.get("EXPECTED_THROUGHPUT", default="85") speed = int(read_file("/sys/class/net/%s/speed" % self.iface)) self.expected_tp = int(self.expected_tp) * speed / 100
def _check_test(self, test, expected): klass_method = test['id'].split(':')[1] self.assertEqual(expected[0], test['status'], "Status error: '%s' != '%s' (%s)" % (expected[0], test['status'], klass_method)) debug_log = genio.read_file(test['logfile']) for msg in expected[1]: self.assertIn(msg, debug_log, "Message '%s' should be in the log (%s)." "\nJSON results:\n%s" "\nDebug Log:\n%s" % (msg, klass_method, test, debug_log)) for msg in set(ALL_MESSAGES) - set(expected[1]): self.assertNotIn(msg, debug_log, "Message '%s' should not be in the log (%s)" "\nJSON results:\n%s" "\nDebug Log:\n%s" % (msg, klass_method, test, debug_log))
def test_skip_decorators(self): os.chdir(BASEDIR) cmd_line = [AVOCADO, 'run', '--sysinfo=off', '--job-results-dir', '%s' % self.tmpdir, '%s' % self.test_module, '--json -'] result = process.run(' '.join(cmd_line), ignore_status=True) json_results = json.loads(result.stdout_text) debuglog = json_results['debuglog'] self.assertEqual(result.exit_status, exit_codes.AVOCADO_ALL_OK) self.assertEqual(json_results['skip'], 3) debuglog_contents = genio.read_file(debuglog) self.assertFalse('setup executed' in debuglog_contents) self.assertFalse('test executed' in debuglog_contents) self.assertFalse('teardown executed' in debuglog_contents)
def test(self): """ Test disk devices with different operations of creating filesystem and mount it on a directory and verify it with certain parameters name, size, UUID and IO sizes etc """ msg = [] disk = (self.disk.split("/dev/"))[1] if process.system("ls /dev/disk/by-id -l| grep -i %s" % disk, ignore_status=True, shell=True, sudo=True) != 0: msg.append("Given disk %s is not present in /dev/disk/by-id", disk) if process.system("ls /dev/disk/by-path -l| grep -i %s" % disk, ignore_status=True, shell=True, sudo=True) != 0: msg.append("Given disk %s is not present in /dev/disk/by-path", disk) # Verify disk listed in all tools cmd_list = ["fdisk -l ", "parted -l", "lsblk ", "lshw -c disk "] if self.distro == 'Ubuntu': cmd_list.append("hwinfo --short --block") for cmd in cmd_list: cmd = cmd + " | grep -i %s" % disk if process.system(cmd, ignore_status=True, shell=True, sudo=True) != 0: msg.append("Given disk %s is not present in %s" % (disk, cmd)) # Get the size and UUID of the disk cmd = "lsblk -l %s --output SIZE -b |sed -n 2p" % self.disk output = process.system_output(cmd, ignore_status=True, shell=True, sudo=True) self.size_bytes = (output.strip("\n"))[0] self.log.info("Disk: %s Size: %s", self.disk, self.size_bytes) # Get the physical/logical and minimal/optimal sector sizes pbs_sysfs = "/sys/block/%s/queue/physical_block_size" % disk pbs = genio.read_file(pbs_sysfs).rstrip("\n") lbs_sysfs = "/sys/block/%s/queue/logical_block_size" % disk lbs = genio.read_file(lbs_sysfs).rstrip("\n") mis_sysfs = "/sys/block/%s/queue/minimum_io_size" % disk mis = genio.read_file(mis_sysfs).rstrip("\n") ois_sysfs = "/sys/block/%s/queue/optimal_io_size" % disk ois = genio.read_file(ois_sysfs).rstrip("\n") self.log.info("pbs: %s, lbs: %s, mis: %s, ois: %s", pbs, lbs, mis, ois) # Verify sector sizes sector_string = "Sector size (logical/physical): %s " \ "bytes / %s bytes" % (lbs, pbs) output = process.system_output("fdisk -l %s" % self.disk, ignore_status=True, shell=True, sudo=True) if sector_string not in output: msg.append("Mismatch in sector sizes of lbs,pbs in " "fdisk o/p w.r.t sysfs paths") io_size_string = "I/O size (minimum/optimal): %s " \ "bytes / %s bytes" % (mis, mis) if io_size_string not in output: msg.append("Mismatch in IO sizes of mis and ois" " in fdisk o/p w.r.t sysfs paths") # Verify disk size in other tools cmd = "fdisk -l %s | grep -i %s" % (self.disk, self.disk) if self.size_bytes not in process.system_output(cmd, ignore_status=True, shell=True, sudo=True): msg.append("Size of disk %s mismatch in fdisk o/p" % self.disk) cmd = "sfdisk -l %s | grep -i %s" % (self.disk, self.disk) if self.size_bytes not in process.system_output(cmd, ignore_status=True, shell=True, sudo=True): msg.append("Size of disk %s mismatch in sfdisk o/p" % self.disk) # Mount self.part_obj = Partition(self.disk, mountpoint=self.dir) self.log.info("Unmounting disk/dir before creating file system") self.part_obj.unmount() self.log.info("creating file system") self.part_obj.mkfs(self.fstype) self.log.info("Mounting disk %s on directory %s", self.disk, self.dir) try: self.part_obj.mount() except PartitionError: msg.append("failed to mount %s fs on %s to %s" % (self.fstype, self.disk, self.dir)) # Get UUID of the disk for each filesystem mount cmd = "blkid %s | cut -d '=' -f 2" % self.disk output = process.system_output(cmd, ignore_status=True, shell=True, sudo=True) self.uuid = output.split('"')[1] self.log.info("Disk: %s UUID: %s", self.disk, self.uuid) # Verify mount point, filesystem type and UUID for each test variant output = process.system_output("lsblk -l %s" % self.disk, ignore_status=True, shell=True, sudo=True) if self.dir in output: self.log.info("Mount point %s for disk %s updated in lsblk o/p", self.dir, self.disk) output = process.system_output("df %s" % self.disk, ignore_status=True, shell=True, sudo=True) if self.dir in output: self.log.info("Mount point %s for disk %s updated in df o/p", self.dir, self.disk) if process.system("ls /dev/disk/by-uuid -l| grep -i %s" % disk, ignore_status=True, shell=True, sudo=True) != 0: msg.append("Given disk %s not having uuid" % disk) output = process.system_output("blkid %s" % self.disk, ignore_status=True, shell=True, sudo=True) if (self.disk in output and self.fstype in output and self.uuid in output): self.log.info("Disk %s of file system %s and " "uuid %s is updated in blkid o/p", self.disk, self.fstype, self.uuid) if process.system("grub2-probe %s" % self.dir, ignore_status=True): msg.append("Given disk %s's fs not detected by grub2" % disk) # Un-mount the directory self.log.info("Unmounting directory %s", self.dir) self.part_obj.unmount() cmd = 'lshw -c disk | grep -n "%s" | cut -d ":" -f 1' % self.disk middle = process.system_output(cmd, ignore_status=True, shell=True, sudo=True) if middle: cmd = r'lshw -c disk | grep -n "\-disk" | cut -d ":" -f 1' total = process.system_output(cmd, ignore_status=True, shell=True, sudo=True) lst = total.splitlines() + middle.splitlines() lst.sort() index = lst.index(middle.splitlines()[0]) low = lst[index-1] high = lst[index+1] cmd = "lshw -c disk |sed -n '%s, %sp'" % (low, high) disk_details = process.system_output(cmd, ignore_status=True, shell=True, sudo=True) ls_string = "logicalsectorsize=%s sectorsize=%s" % (lbs, pbs) if ls_string not in disk_details: msg.append("Mismatch in sector sizes of lbs,pbs" " in lshw o/p w.r.t sysfs paths") if msg: self.fail("Some tests failed. Details below:\n%s" % "\n".join(msg))
def bond_setup(self, arg1, arg2): ''' bond setup ''' if arg1 == "local": self.log.info("Configuring Bonding on Local machine") self.log.info("--------------------------------------") for ifs in self.host_interfaces: cmd = "ip addr flush dev %s" % ifs process.system(cmd, shell=True, ignore_status=True) for ifs in self.host_interfaces: cmd = "ip link set %s down" % ifs process.system(cmd, shell=True, ignore_status=True) linux_modules.load_module("bonding") genio.write_file(self.bonding_masters_file, "+%s" % self.bond_name) genio.write_file("%s/bonding/mode" % self.bond_dir, arg2) genio.write_file("%s/bonding/miimon" % self.bond_dir, "100") genio.write_file("%s/bonding/fail_over_mac" % self.bond_dir, "2") for val in self.host_interfaces: genio.write_file(self.bonding_slave_file, "+%s" % val) time.sleep(2) bond_name_val = '' for line in genio.read_file(self.bond_status).splitlines(): if 'Bonding Mode' in line: bond_name_val = line.split(':')[1] self.log.info("Trying bond mode %s [ %s ]", arg2, bond_name_val) for ifs in self.host_interfaces: cmd = "ip link set %s up" % ifs if process.system(cmd, shell=True, ignore_status=True) != 0: self.fail("unable to interface up") cmd = "ip addr add %s/%s dev %s;ip link set %s up"\ % (self.local_ip, self.net_mask[0], self.bond_name, self.bond_name) process.system(cmd, shell=True, ignore_status=True) for _ in range(0, 600, 60): if 'state UP' in process.system_output("ip link \ show %s" % self.bond_name, shell=True): self.log.info("Bonding setup is successful on\ local machine") break time.sleep(60) else: self.fail("Bonding setup on local machine has failed") if self.gateway: cmd = 'ip route add default via %s dev %s' % \ (self.gateway, self.bond_name) process.system(cmd, shell=True, ignore_status=True) else: self.log.info("Configuring Bonding on Peer machine") self.log.info("------------------------------------------") cmd = '' for val in self.peer_interfaces: cmd += 'ip addr flush dev %s;' % val for val in self.peer_interfaces: cmd += 'ip link set %s down;' % val cmd += 'modprobe bonding;' cmd += 'echo +%s > %s;'\ % (self.bond_name, self.bonding_masters_file) cmd += 'echo 0 > %s/bonding/mode;'\ % self.bond_dir cmd += 'echo 100 > %s/bonding/miimon;'\ % self.bond_dir cmd += 'echo 2 > %s/bonding/fail_over_mac;'\ % self.bond_dir for val in self.peer_interfaces: cmd += 'echo "+%s" > %s;' % (val, self.bonding_slave_file) for val in self.peer_interfaces: cmd += 'ip link set %s up;' % val cmd += 'ip addr add %s/%s dev %s;ip link set %s up;sleep 5;'\ % (self.peer_first_ipinterface, self.net_mask[0], self.bond_name, self.bond_name) peer_cmd = "timeout %s ssh %s@%s \"%s\""\ % (self.peer_wait_time, self.user, self.peer_first_ipinterface, cmd) if process.system(peer_cmd, shell=True, ignore_status=True) != 0: self.fail("bond setup command failed in peer machine")
def setUp(self): # Check for basic utilities sm = SoftwareManager() detected_distro = distro.detect() deps = ['gcc', 'make', 'patch'] if detected_distro.name == "Ubuntu": deps += ['libpthread-stubs0-dev', 'git'] elif detected_distro.name == "SuSE": deps += ['glibc-devel-static', 'git-core'] else: deps += ['glibc-static', 'git'] for package in deps: if not sm.check_installed(package) and not sm.install(package): self.cancel(' %s is needed for the test to be run' % package) kernel.check_version("2.6.16") if detected_distro.name == "Ubuntu": op = glob.glob("/usr/lib/*/libpthread.a") else: op = glob.glob("/usr/lib*/libpthread.a") if not op: self.cancel("libpthread.a is required!!!" "\nTry installing glibc-static") # Get arguments: self.hugetlbfs_dir = self.params.get('hugetlbfs_dir', default=None) pages_requested = self.params.get('pages_requested', default=20) # Check hugepages: pages_available = 0 if os.path.exists('/proc/sys/vm/nr_hugepages'): Hugepages_support = genio.read_file("/proc/meminfo").rstrip("\n") if 'HugePages_' not in Hugepages_support: self.cancel("No Hugepages Configured") memory.set_num_huge_pages(pages_requested) pages_available = memory.get_num_huge_pages() else: self.cancel("Kernel does not support hugepages") # Check no of hugepages : if pages_available < pages_requested: self.cancel('%d pages available, < %d pages requested' % (pages_available, pages_requested)) # Check if hugetlbfs is mounted cmd_result = process.run( 'grep hugetlbfs /proc/mounts', verbose=False, sudo=True) if not cmd_result: if not self.hugetlbfs_dir: self.hugetlbfs_dir = os.path.join(self.tmpdir, 'hugetlbfs') os.makedirs(self.hugetlbfs_dir) if process.system('mount -t hugetlbfs none %s' % self.hugetlbfs_dir, sudo=True, ignore_status=True): self.cancel("hugetlbfs mount failed") git.get_repo('https://github.com/libhugetlbfs/libhugetlbfs.git', destination_dir=self.workdir) os.chdir(self.workdir) patch = self.params.get('patch', default='elflink.patch') process.run('patch -p1 < %s' % self.get_data(patch), shell=True) build.make(self.workdir, extra_args='BUILDTYPE=NATIVEONLY')
def get_proc_content(rel_path): try: return genio.read_file(os.path.join(p_dir, rel_path)).strip() except: return "<NOT AVAILABLE>"
except path.CmdNotFoundError: apidoc = False # Documentation sections. Key is the name of the section, followed by: # Second level module name (after avocado), Module description, # Output directory, List of directory to exclude from API generation, # list of (duplicated) generated reST files to remove (and avoid warnings) API_SECTIONS = {"Test APIs": (None, "This is the bare mininum set of APIs that users " "should use, and can rely on, while writing tests.", "test", ("core", "utils", "plugins"), ("modules.rst", )), "Utilities APIs": ("utils", genio.read_file("api_utils_heading"), "utils", ("core", "plugins"), ("avocado.rst", "modules.rst")), "Internal (Core) APIs": ("core", "Internal APIs that may be of interest to " "Avocado hackers.", "core", ("utils", "plugins"), ("avocado.rst", "modules.rst")), "Extension (plugin) APIs": ("plugins", "Extension APIs that may be of interest to " "plugin writers.", "plugins",