def test_cpu_passthrough(self): ''' case_tag: CPU case_name: test_cpu_passthrough case_file: os_tests.tests.test_nutanix_vm.test_cpu_passthrough component: CPU bugzilla_id: N/A is_customer_case: False customer_case_id: N/A testplan: N/A maintainer: [email protected] description: Verify CPU passthrough features key_steps: | 1. Enable CPU passthrough, and check CPU info on RHEL guest OS 2. Disable CPU passthrough, and check CPU info on RHEL guest OS expect_result: CPU passthrough can be enable or disable and take effect on RHEL guest OS debug_want: N/A ''' pt_is_disabled = self.vm.get_cpu_passthrough(enabled=False) if pt_is_disabled: self.vm.set_cpu_passthrough(enabled=True) utils_lib.init_connection(self) self.assertTrue(self.vm.get_cpu_passthrough(enabled=True), "Test failed as setup CPU passthrough failed") else: self.fail( "Expecte CPU passthrough set as disabled by default, need more investigation here" ) cmd = "grep -i vmx /proc/cpuinfo" utils_lib.run_cmd( self, cmd, expect_ret=0, expect_kw="vmx", msg="Verify if cpu vmx has take effected on RHEL guest OS") self.log.info("Recover VM cpu passthrough") self.vm.set_cpu_passthrough(enabled=False) self.assertTrue(self.vm.get_cpu_passthrough(enabled=False), "Test failed as recover CPU passthrough failed") utils_lib.init_connection(self) utils_lib.run_cmd( self, cmd, expect_not_ret=0, expect_not_kw="vmx", msg="Verify if cpu vmx has disabled on RHEL guest OS")
def test_check_product_id(self): ''' bz: 1938930 issue: RHELPLAN-60817 check if product id matches /etc/redhat-release ''' check_cmd = "sudo cat /etc/redhat-release" output = utils_lib.run_cmd(self, check_cmd, expect_ret=0, cancel_not_kw='CentOS,Fedora', msg='check release name') product_id = re.findall('\d.\d', output)[0] self.log.info("Get product id: {}".format(product_id)) cmd = 'sudo rpm -qa|grep redhat-release' utils_lib.run_cmd(self, cmd, cancel_ret='0', msg='get redhat-release-server version') cmd = 'sudo rct cat-cert /etc/pki/product-default/*.pem' utils_lib.run_cmd(self, cmd, expect_ret=0, expect_kw="Version: {}".format(product_id), msg='check product certificate')
def test_check_sysfs_cpu_list(self): ''' case_name: test_check_sysfs_cpu_list case_priority: 1 component: kernel bugzilla_id: 1741462 polarion_id: n/a maintainer: [email protected] description: Check no crash when read "cpu_list" in /sys. key_steps: 1. # find -H /sys -name cpu_list -type f -perm -u=r -print -exec cat '{}' 2>&1 \; expected_result: No crash/panic happen ''' cmd = "find -H /sys -name cpu_list -type f -perm -u=r -print -exec cat '{}' 2>&1 \;" utils_lib.run_cmd( self, cmd, msg='Check no crash seen when read cpu_list if exists')
def test_check_dmidecode_dump_segfault(self): ''' case_name: test_check_dmidecode_dump_segfault case_priority: 2 component: dmidecode bugzilla_id: 1885823 customer_case_id: 02939365 polarion_id: n/a maintainer: [email protected] description: check there is no segmentation fault while run 'dmidecode --dump' key_steps: # dmidecode --dump |grep -i Segmentation expected_result: No segmentation fault found. ''' utils_lib.is_cmd_exist(self, cmd='dmidecode') cmd = "sudo dmidecode --dump" utils_lib.run_cmd(self, cmd, expect_ret=0, expect_not_kw='Segmentation')
def test_check_hosts(self): ''' des: localhost ipv6 and ipv4 should be set in /etc/hosts ''' expect_kws = '127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4,::1 localhost localhost.localdomain localhost6 localhost6.localdomain6' cmd = "sudo cat /etc/hosts" utils_lib.run_cmd(self, cmd, expect_ret=0, expect_kw=expect_kws, msg='check /etc/hosts')
def test_check_service(self): ''' case_name: test_check_service case_priority: 1 component: systemd bugzilla_id: 1740443 polarion_id: n/a maintainer: [email protected] description: Check no failed service in start up. key_steps: 1. # systemctl|grep failed expected_result: No failed service found. ''' cmd = 'systemctl' utils_lib.run_cmd(self, cmd, expect_ret=0) utils_lib.run_cmd(self, cmd, expect_ret=0, expect_not_kw='failed')
def test_check_available_clocksource(self): ''' polarion_id: bz: 1726487 ''' output = utils_lib.run_cmd(self, 'lscpu', expect_ret=0) if 'Xen' in output: expect_clocks = 'xen,tsc,hpet,acpi_pm' elif 'aarch64' in output: expect_clocks = 'arch_sys_counter' elif 'AuthenticAMD' in output and 'KVM' in output: expect_clocks = 'kvm-clock,tsc,acpi_pm' elif 'GenuineIntel' in output and 'KVM' in output: expect_clocks = 'kvm-clock,tsc,acpi_pm' else: expect_clocks = 'tsc,hpet,acpi_pm' cmd = 'sudo cat /sys/devices/system/clocksource/clocksource0/\ available_clocksource' utils_lib.run_cmd(self, cmd, expect_ret=0, expect_kw=expect_clocks, msg='Checking available clocksource')
def test_check_username(self): """ Check no old username in fresh image """ for user in ['cloud-user']: cmd = 'sudo cat /etc/passwd|grep {}'.format(user) utils_lib.run_cmd(self, cmd, expect_not_ret='0', msg='check no {} user in fresh image'.format(user))
def test_check_sysconfig_kernel(self): ''' des: UPDATEDEFAULT=yes and DEFAULTKERNEL=kernel should be set in /etc/sysconfig/kernel ''' expect_kws = 'UPDATEDEFAULT=yes,DEFAULTKERNEL=kernel-core' cmd = "sudo cat /etc/sysconfig/kernel" utils_lib.run_cmd(self, cmd, expect_ret=0, expect_kw=expect_kws, msg='check /etc/sysconfig/kernel')
def test_check_selinux_status(self): """ case_name: test_check_selinux_status component: rhel-guest-image bugzilla_id: N/A is_customer_case: False maintainer: [email protected] description: check selinux status is enforcing key_steps: 1. getenforce 2. cat /etc/selinux/config|grep SELINUX= expect_result: Enforcing/enforcing """ cmd = "getenforce" output = utils_lib.run_cmd(self, cmd, expect_ret=0, msg="getenforce") self.assertEqual(output.rstrip('\n'), "Enforcing", "SELinux is not enforcing") cmd = "cat /etc/selinux/config|grep SELINUX=" output = utils_lib.run_cmd(self, cmd, expect_ret=0, msg="get SELINUX in /etc/selinux/config") keyword = "" for line in output.splitlines(): if '#' not in line: keyword = line.split('=')[1] self.assertEqual(keyword, "enforcing", "SELinux is not enforcing")
def test_check_bash_history(self): ''' Verify no old .bash_history exists ''' for user in ['cloud-user', 'root']: cmd = 'sudo cat ~{}/.bash_history'.format(user) utils_lib.run_cmd(self, cmd, expect_not_ret='0', msg='check bash history does not exist in fresh image')
def test_dracut_f_v(self): ''' case_name: test_dracut_f_v case_priority: 1 component: kernel bugzilla_id: 1849082,1906301 customer_case_id: 02925130 polarion_id: n/a maintainer: [email protected] description: Test no failed items in generating an initramfs/initrd image. key_steps: 1. # dracut -f -v expected_result: No failed items found. ''' cmd = "sudo dracut -f -v" utils_lib.run_cmd(self, cmd, expect_ret=0, expect_not_kw='Failed,FAILED', timeout=120)
def test_fsadm_resize(self): """ case_name: test_fsadm_resize component: lvm2 bugzilla_id: 1905705 is_customer_case: True maintainer: [email protected] description: test if "fsdadm resize" can run normally key_steps: 1.check cmd fsadm 2.sudo fsadm resize $(findmnt -n -o source /) expect_result: fsadm does nothing since the filesystem is already at maximum size """ utils_lib.is_cmd_exist(self, 'fsadm') utils_lib.run_cmd(self, 'sudo fsadm resize $(findmnt -n -o source /)', expect_ret=0, expect_not_kw="unbound variable", msg="fsadm should not crash")
def tearDown(self): if 'test_boot_debugkernel' in self.id(): cmd = "sudo grubby --set-default-index=%s" % self.old_grub_index utils_lib.run_cmd(self, cmd, expect_ret=0, msg="restore default boot index to {}".format( self.old_grub_index)) if 'test_boot_hpet_mmap_enabled' in self.id(): cmd = 'sudo grubby --update-kernel=ALL --remove-args="hpet_mmap=1"' utils_lib.run_cmd(self, cmd, msg='Remove "hpet_mmap=1"') if 'test_boot_mitigations' in self.id(): cmd = 'sudo grubby --update-kernel=ALL --remove-args="mitigations=auto,nosmt"' utils_lib.run_cmd(self, cmd, msg='Remove "mitigations=auto,nosmt"') if 'test_boot_usbcore_quirks' in self.id(): cmd = 'sudo grubby --update-kernel=ALL --remove-args="usbcore.quirks=quirks=0781:5580:bk,0a5c:5834:gij"' utils_lib.run_cmd( self, cmd, msg='Remove "usbcore.quirks=quirks=0781:5580:bk,0a5c:5834:gij"' ) if 'test_kdump_no_specify_cpu' not in self.id(): utils_lib.run_cmd(self, 'sudo reboot', msg='reboot system under test') time.sleep(10) utils_lib.init_connection(self, timeout=800)
def test_change_clocksource(self): ''' :avocado: tags=test_change_clocksource,fast_check polarion_id: ''' output = utils_lib.run_cmd(self, 'lscpu', expect_ret=0) cmd = 'sudo cat /sys/devices/system/clocksource/clocksource0/\ current_clocksource' utils_lib.run_cmd(self, cmd, expect_ret=0, msg='Check current clock source') cmd = 'sudo cat /sys/devices/system/clocksource/clocksource0/\ available_clocksource' output = utils_lib.run_cmd(self, cmd, expect_ret=0) for clocksource in output.split(' '): cmd = 'sudo bash -c \'echo "%s" > /sys/devices/system/clocksource/clocksource0/\ current_clocksource\'' % clocksource utils_lib.run_cmd(self, cmd, expect_ret=0, msg='Change clocksource to %s' % clocksource) cmd = 'sudo cat /sys/devices/system/clocksource/clocksource0/\ current_clocksource' utils_lib.run_cmd(self, cmd, expect_kw=clocksource, msg='Check current clock source') utils_lib.run_cmd(self, 'dmesg|tail -30', expect_ret=0)
def test_boot_usbcore_quirks(self): ''' bz: 1809429 polarion_id: ''' utils_lib.run_cmd(self, r'sudo rm -rf /var/crash/*', expect_ret=0, msg='clean /var/crash firstly') option = 'usbcore.quirks=quirks=0781:5580:bk,0a5c:5834:gij' cmd = 'sudo grubby --update-kernel=ALL --args="{}"'.format(option) utils_lib.run_cmd(self, cmd, msg='Append {} to command line!'.format(option), timeout=600) utils_lib.run_cmd(self, 'sudo reboot', msg='reboot system under test') time.sleep(10) utils_lib.init_connection(self, timeout=800) utils_lib.run_cmd(self, 'cat /proc/cmdline', expect_kw=option) cmd = r'sudo cat /var/crash/*/vmcore-dmesg.txt|tail -50' utils_lib.run_cmd(self, cmd, expect_kw='No such file or directory', msg='make sure there is no core generated') utils_lib.check_log(self, "error,warn,fail,trace,Trace", skip_words='ftrace', rmt_redirect_stdout=True)
def test_check_root_is_locked(self): """ Root account should be locked """ self.log.info('RHEL AMI found') cmd = 'sudo passwd -S root | grep -q LK' utils_lib.run_cmd(self, cmd, expect_ret=0, msg='check root is locked')
def test_check_proc_self_status(self): ''' case_name: test_check_proc_self_status case_priority: 1 component: kernel bugzilla_id: 1773868 polarion_id: n/a maintainer: [email protected] description: Check no 'unknown' in /proc/self/status. key_steps: 1. # cat /proc/self/status expected_result: No 'unknown' in this file ''' utils_lib.run_cmd(self, 'cat /proc/self/status', expect_not_kw='unknown', msg='Check no unknown in "/proc/self/status"')
def test_check_journal_log(self): ''' Verify no traceback|ordering in journalctl -xl ''' ignore_list = [] utils_lib.run_cmd(self, 'sudo journalctl -xl > /tmp/journal.log') self._check_log('/tmp/journal.log', ignore_list, 'traceback|ordering')
def test_check_selinux(self): ''' SELinux should be in enforcing/targeted mode ''' out = utils_lib.run_cmd(self, 'uname -r', msg='get kernel version') utils_lib.run_cmd(self, 'sudo getenforce',expect_kw='Enforcing', msg='check selinux current mode is Enforcing') utils_lib.run_cmd(self, 'sudo cat /etc/sysconfig/selinux',expect_kw='SELINUX=enforcing,SELINUXTYPE=targeted', msg='check selinux current setting')
def test_check_authselect(self): ''' Check authselect current ''' if self.rhel_x_version < 8: self.skipTest("Only support in RHEL-8+") cmd = 'authselect current' utils_lib.run_cmd(self, cmd, expect_output="No existing configuration detected.", msg="Check authselect current")
def _update_kernel_args(self, boot_param_required): cmd = 'sudo grubby --update-kernel=ALL --args="{}"'.format(boot_param_required) utils_lib.run_cmd(self, cmd, msg="append {} to boot params".format(boot_param_required)) utils_lib.run_cmd(self, 'sudo reboot', msg='reboot system under test') time.sleep(10) utils_lib.init_connection(self, timeout=self.ssh_timeout) cat_proc_cmdline = utils_lib.run_cmd(self, 'cat /proc/cmdline') return cat_proc_cmdline
def test_check_chrony_conf(self): ''' Verify file /etc/chrony.conf is not changed ''' # filename = '/etc/chrony.conf' # self._check_file_content(filename.split('/')[-1], filename, project=self.rhel_x_version) # self._check_file_not_changed("chrony") utils_lib.run_cmd(self, "sudo cat /etc/chrony.conf", expect_ret=0, expect_kw='server metadata.google.internal iburst', msg='check chrony points to Google Time Sync service')
def test_check_ttyS0_conf(self): """ bz: 1103344 check no "/etc/init/ttyS0.conf" exists. check no "/dev/ttyS0: tcgetattr: Input/output error" in "/var/log/secure" """ utils_lib.run_cmd(self, 'sudo cat /etc/init/ttyS0.conf', expect_not_ret=0, msg='make sure no /etc/init/ttyS0.conf found') utils_lib.run_cmd(self, 'sudo cat /etc/init/ttyS0.bak', msg='ttyS0.bak may also not in RHEL nowadays')
def test_check_auditd(self): """ Check auditd: - service should be on - config files shoud have specified checksums """ utils_lib.run_cmd(self, 'sudo systemctl is-active auditd', expect_ret=0, msg="Ensure auditd service is active") utils_lib.run_cmd(self, 'sudo rpm -V audit', expect_ret=0, msg='Ensure /etc/auditd.conf is not changed')
def test_check_cpu_flags(self): ''' rhbz: 1061348 check various cpu flags ''' utils_lib.is_arch(self, arch='x86_64', action='cancel') cmd = "sudo cat /proc/cpuinfo" utils_lib.run_cmd(self, cmd, expect_ret=0, expect_kw='avx,xsave,pcid', msg='check avx,xsave,pcid flags')
def test_check_rhel_version(self): ''' check if rhel provider matches /etc/redhat-release ''' release_file = 'redhat-release' product_id = utils_lib.get_product_id(self) cmd = "echo $(sudo rpm -q --qf '%{VERSION}' --whatprovides " + release_file + ')' utils_lib.run_cmd(self,cmd, expect_kw=product_id, msg='check redhat-release version match')
def test_check_hostkey_permission(self): ''' bz: 2013644 Verify /etc/ssh/ssh_host_xxx_key permission are 600, group is root. ''' expected = "-rw-------.rootroot" cmd = "ls -l /etc/ssh/{ssh_host_ecdsa_key,ssh_host_ed25519_key,ssh_host_rsa_key}|awk '{print $1$3$4}'|uniq" utils_lib.run_cmd(self, cmd, expect_output=expected, msg="Verify /etc/ssh/ssh_host_xxx_key permission is 600, group is ssh_keys")
def test_check_metadata(self): ''' polarion_id: https://cloudinit.readthedocs.io/en/latest/topics/datasources/ec2.html ''' cmd = r"curl http://169.254.169.254/latest/meta-data/instance-type" utils_lib.run_cmd(self, cmd, expect_ret=0, expect_not_kw="Not Found")
def test_iostat_x(self): ''' case_name: test_iostat_x case_priority: 1 component: kernel bugzilla_id: 1661977 polarion_id: n/a maintainer: [email protected] description: Check "iostat -x" report and make sure there is no high utils when there is no obviously read/write operations. key_steps: 1. # iostat -x expected_result: No high utils reported when no obviously read/write operations. eg. # iostat -x Linux 4.18.0-236.el8.aarch64 (ip-xx-xxx-x-xxx.us-west-2.compute.internal) 09/28/2020 _aarch64_ (2 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 7.77 0.00 1.48 0.69 0.00 90.06 Device r/s w/s rkB/s wkB/s rrqm/s wrqm/s %rrqm %wrqm r_await w_await aqu-sz rareq-sz wareq-sz svctm %util nvme0n1 46.06 2.82 1587.81 274.62 0.00 0.23 0.00 7.52 0.50 1.32 0.00 34.47 97.31 0.86 4.19 nvme1n1 0.15 0.00 10.43 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 70.40 0.00 1.50 0.02 ''' expect_utils = self.params.get('disk_utils') self.log.info("Check no disk utils lager than %s" % expect_utils) utils_lib.is_cmd_exist(self, cmd='iostat') cmd = 'sudo iostat -x -o JSON' output = utils_lib.run_cmd(self, cmd) try: res_dict = json.loads(output) for x in res_dict["sysstat"]["hosts"][0]["statistics"][0]["disk"]: self.assertLessEqual( x["util"], expect_utils, msg="Utils more than %s without any large io! act: %s" % (expect_utils, x["util"])) except ValueError as err: self.log.info("cmd has no json support") cmd = "sudo iostat -x" utils_lib.run_cmd(self, cmd, expect_ret=0) cmd = "sudo iostat -x|awk -F' ' '{print $NF}'" output = utils_lib.run_cmd(self, cmd, expect_ret=0) compare = False for util in output.split('\n'): if 'util' in util: compare = True continue if compare and not util == '': if float(util) > expect_utils: self.fail("Some disk's utils %s is larger than %s" % (util, expect_utils))