def getloopdev(fstype, imgname):
    run_cmd('dd if=/dev/zero of=/%s bs=1024 count=5000' % imgname)
    ldev = run_cmd('losetup -f')
    if not ldev:
        log.error('FAIL: No unused loop device!')
        return ''
    if not run_cmd('losetup %s /%s' % (ldev, imgname)):
        log.error('FAIL: associate %s with %s' % (ldev, imgname))
        return ''
    if not run_cmd('mkfs -t %s %s' % (fstype, ldev)):
        log.error('FAIL: create %s on %s' % (fstype, ldev))
        return ''
    return ldev
def exportfs_nfs_server(dname):
    run_cmd('mv /etc/exports /etc/exports.org', check_rc=False)
    fd = open("/etc/exports", "w")
    data = "%s *(rw,sync,no_root_squash,no_subtree_check,no_all_squash)\n" \
           % dname
    fd.write(data)
    fd.close()
    if not run_cmd('exportfs -ra'):
        log.error('FAIL: export NFS server')
        return False
    out = run_cmd('exportfs')
    if not verify_output(out, '%s.*world.*' % dname):
        log.error('FAIL: export NFS server')
        return False
    log.info('PASS: %s - NFS server exported' % dname)
    return True
def file_read_write_mntpnt(mntpnt, fname):
    fd = open('%s/%s' % (mntpnt, fname), "w")
    data = 'test read write on nfs client'
    fd.write(data)
    fd.close()
    out = run_cmd('cat %s/%s' % (mntpnt, fname))
    if not verify_output(out, data):
        log.error('FAIL: read/write on %s/%s' (mntpnt, fname))
        return False
    log.info('PASS: read/write on %s/%s' % (mntpnt, fname))
    return True
Beispiel #4
0
def test_ltp(ltp_command):
    """
    Running ltp
    """
    if ltp_command == 'memcg_stress':
        pytest.skip('memcg_stress is skipped')
    else:
        assert run_cmd("sync; export PATH=%stestcases/bin:$PATH;"
                       "export LTPROOT=%s ; export TMPDIR=/tmp;"
                       " %s" % (ltpdir, ltpdir, ltp_command),
                       wdir=ltpdir)
def update_test_mapfile(mapfile, mntpnt, opts, location):
    # Updating auto.test
    fd = open(mapfile, "w")
    data = mntpnt + ' ' + opts + ' ' + location + '\n'
    fd.write(data)
    fd.close()
    out = run_cmd('cat %s' % mapfile)
    if not verify_output(out, '.*%s.*%s' % (mntpnt, location)):
        log.error('FAIL: update %s\n%s' % (mapfile, out))
        return False
    log.info('PASS: %s updated\n%s' % (mapfile, out))
    return True
def update_master_mapfile(mntpnt, mapfile, opts):
    # Updating auto.master
    fd = open('/etc/auto.master', "w")
    data = mntpnt + ' ' + mapfile + ' ' + opts + '\n'
    fd.write(data)
    fd.close()
    out = run_cmd('cat /etc/auto.master')
    if not verify_output(out, '.*%s.*%s' % (mntpnt, mapfile)):
        log.error('FAIL: /etc/auto.master update\n%s' % out)
        return False
    log.info('PASS: /etc/auto.master updated\n%s' % out)
    return True
Beispiel #7
0
def setup_ltp():
    chk_ltp = run_cmd("ls %s/runltp 2>/dev/null" % ltpdir)
    assert chk_ltp
    testnames = []
    commands = []
    files = [line.rstrip('\n') for line in open(default_scen)]
    open("testfilecmds", "w+")
    for tests in files:
        fin = open(ltpdir + "runtest/" + tests, "r")
        data2 = fin.read()
        fout = open("testfilecmds", "a")
        fout.write(data2)
        fout.close()
    f = open('testfilecmds', 'r')
    for line in f:
        if line.strip():
            if not line.lstrip().startswith('#'):
                testnames.append(line.split(None, 1)[0])
                commands.append(line.split(None, 1)[1])
    commands = map(lambda s: s.strip(), commands)
    run_cmd("rm -rf testfilecmds")
    return testnames, commands
def setup_test():
    run_cmd('/etc/init.d/autofs stop', check_rc=False)
    run_cmd('mkdir /autofsmntpnt', check_rc=False)
    run_cmd('mv /etc/auto.master /etc/auto.master.org', check_rc=False)
    run_cmd('mv /etc/exports /etc/exports.org', check_rc=False)
    log.info('test setup completed')
Beispiel #9
0
def test_run_cmd():
    """
    This is a sample test to test run_cmd() API.
    """
    out = run_cmd('uname -a')
    assert 'Linux' in out
Beispiel #10
0
def test_platform_is_ppc():
    """
    This is a sample negative test to show failure.
    """
    out = run_cmd('uname -a')
    assert 'ppc' in out
def create_file_nfs_server(dname, fname):
    return run_cmd('touch %s/%s' % (dname, fname))
def is_autofs_mounted(mapfile):
    return run_cmd('mount | grep %s | grep autofs' % mapfile)
def file_on_mntpnt(mntpnt, fname, rc=True):
    return run_cmd('ls %s/%s' % (mntpnt, fname), check_rc=rc)
def mount_nfs_server(dname, devname):
    run_cmd('mkdir %s' % dname, check_rc=False)
    if not run_cmd('mount -t ext3 %s %s' % (devname, dname)):
        log.error('FAIL: mount %s on %s' % (devname, dname))
        return False
    return True
def stop_autofs():
    log.info('stopping autofs service')
    return run_cmd('/etc/init.d/autofs stop')
def test_autofs(request, check_kernconfigs, setup_test, fstype):
    """
    Tests for kernel-based automount utility for NFS and local FS based on
    ext3 & ext4. Also the timeout feature of autofs is also tested.
    """
    mapfile = '/auto.test'
    autofs_mntpnt = '/autofsmntpnt'
    master_opts = '--timeout=20'
    ltimeout = [10, 60, 300]

    def cleanup():
        imgs = ['nfsimg', 'ext3img', 'ext4img']
        for img in imgs:
            ldev = run_cmd("losetup -j /%s | cut -d ':' -f1" % img,
                           check_rc=False)
            if img == 'nfsimg':
                run_cmd('umount /nfs_server', check_rc=False)
                run_cmd('rm -rf /nfs_server', check_rc=False)
            if ldev:
                run_cmd('losetup -d %s' % ldev, check_rc=False)
            run_cmd('rm -rf /%s' % img, check_rc=False)
        run_cmd('mv /etc/auto.master.org /etc/auto.master',
                check_rc=False)
        run_cmd('mv /etc/exports.org /etc/exports',
                check_rc=False)
        run_cmd('exportfs -ra', check_rc=False)
        run_cmd('rm -rf %s' % autofs_mntpnt, check_rc=False)
        run_cmd('rm -rf %s' % mapfile, check_rc=False)
        run_cmd('/etc/init.d/autofs stop', check_rc=False)
    request.addfinalizer(cleanup)
    if 'nfs' in fstype:
        ser_dname = '/nfs_server'
        cli_dname = 'nfs_client'
        test_opts = '-fstype=nfs,nolock'
        location = '127.0.0.1:%s' % ser_dname
        ser_fname = 'server_file'
        nfs_cli_mntpnt = autofs_mntpnt + '/' + cli_dname
        ldev = getloopdev('ext3', 'nfsimg')
        assert ldev
        assert mount_nfs_server(ser_dname, ldev)
        assert exportfs_nfs_server(ser_dname)
        assert update_test_mapfile(mapfile, cli_dname, test_opts, location)
        assert update_master_mapfile(autofs_mntpnt, mapfile, master_opts)
        assert start_autofs()
        assert is_autofs_mounted(mapfile)
        log.info('PASS: %s mounted as type autofs' % mapfile)
        assert create_file_nfs_server(ser_dname, ser_fname)
        log.info('PASS: %s/%s created on NFS server'
                 % (ser_dname, ser_fname))
        if not file_on_mntpnt(nfs_cli_mntpnt, ser_fname):
            log.error('FAIL: %s/%s: no such file on NFS client.'
                      % (nfs_cli_mntpnt, ser_fname))
        log.info('PASS: %s/%s: exits on NFS client.'
                 % (nfs_cli_mntpnt, ser_fname))
        assert file_read_write_mntpnt(nfs_cli_mntpnt, 'tempfile')
        assert stop_autofs()
        if file_on_mntpnt(nfs_cli_mntpnt, ser_fname, rc=False):
            log.error('FAIL: %s still mounted after autofs stopped'
                      % nfs_cli_mntpnt)
            assert False
        log.info('PASS: %s: unmounted' % nfs_cli_mntpnt)
        log.info('*************************************')
        log.info('Testing for automount timeout feature')
        log.info('*************************************')
        for val in ltimeout:
            master_opts = '--timeout=%s' % val
            assert update_master_mapfile(autofs_mntpnt, mapfile, master_opts)
            assert start_autofs()
            log.info('sleeping for %d seconds' % val)
            time.sleep(val + 20)
            if run_cmd('ls %s | grep %s' % (autofs_mntpnt, cli_dname),
                       check_rc=False):
                log.error('FAIL: %s still mounted after timeout %s seconds'
                          % (nfs_cli_mntpnt, val))
                assert False
            log.info('PASS: %s: unmounted after timeout %s seconds'
                     % (nfs_cli_mntpnt, val))
    else:
        img = fstype + 'img'
        cli_dname = fstype + 'mnt'
        test_opts = '-fstype=%s' % fstype
        fs_mntpnt = autofs_mntpnt + '/' + cli_dname
        ldev = getloopdev(fstype, img)
        assert ldev
        location = ':%s' % ldev
        assert update_test_mapfile(mapfile, cli_dname, test_opts, location)
        assert update_master_mapfile(autofs_mntpnt, mapfile, master_opts)
        assert start_autofs()
        assert is_autofs_mounted(mapfile)
        log.info('PASS: %s mounted as type autofs' % mapfile)
        assert file_read_write_mntpnt(fs_mntpnt, 'tempfile')
        assert stop_autofs()
        if file_on_mntpnt(fs_mntpnt, 'tempfile', rc=False):
            log.error('FAIL: %s still mounted after autofs stopped'
                      % fs_mntpnt)
            assert False
        log.info('PASS: %s: unmounted' % fs_mntpnt)
        log.info('*************************************')
        log.info('Testing for automount timeout feature')
        log.info('*************************************')
        for val in ltimeout:
            master_opts = '--timeout=%s' % val
            assert update_master_mapfile(autofs_mntpnt, mapfile, master_opts)
            assert start_autofs()
            log.info('sleeping for %d seconds' % val)
            time.sleep(val + 20)
            if run_cmd('ls %s | grep %s' % (autofs_mntpnt, cli_dname),
                       check_rc=False):
                log.error('FAIL: %s still mounted after timeout %s seconds'
                          % (fs_mntpnt, val))
                assert False
            log.info('PASS: %s: unmounted after timeout %s seconds'
                     % (fs_mntpnt, val))
 def cleanup():
     imgs = ['nfsimg', 'ext3img', 'ext4img']
     for img in imgs:
         ldev = run_cmd("losetup -j /%s | cut -d ':' -f1" % img,
                        check_rc=False)
         if img == 'nfsimg':
             run_cmd('umount /nfs_server', check_rc=False)
             run_cmd('rm -rf /nfs_server', check_rc=False)
         if ldev:
             run_cmd('losetup -d %s' % ldev, check_rc=False)
         run_cmd('rm -rf /%s' % img, check_rc=False)
     run_cmd('mv /etc/auto.master.org /etc/auto.master',
             check_rc=False)
     run_cmd('mv /etc/exports.org /etc/exports',
             check_rc=False)
     run_cmd('exportfs -ra', check_rc=False)
     run_cmd('rm -rf %s' % autofs_mntpnt, check_rc=False)
     run_cmd('rm -rf %s' % mapfile, check_rc=False)
     run_cmd('/etc/init.d/autofs stop', check_rc=False)
Beispiel #18
0
def pytest_configure(config):
    """Provide additional environment details to pytest-html report"""
    # add environment details to the pytest-html plugin

    msd = 'Unknown'
    msd_version = 'Unknown'

    path = '/etc/mvl*/conf/local-content.conf'
    machine_file_list = glob.glob(path)

    if machine_file_list:

        machine_file = machine_file_list[0]

        machine_file_content = run_cmd('cat %s' % machine_file, check_rc=False)
        match = re.findall(r'''MACHINE.*["'](.*)["']''', machine_file_content,
                           re.M)
        if match:
            machine = match[0]
        else:
            machine = 'Unknown'

        uname_output = run_cmd('uname -r', check_rc=False)
        match = re.findall('(\d+.\d+).*', uname_output, re.M)
        if match:
            kernel_version = match[0]
        else:
            kernel_version = 'Unknown'

        mvl_ver_output = run_cmd('cat /etc/mvl-version', check_rc=False)
        match = re.findall('(\d+.\d+).\d', mvl_ver_output, re.M)
        if match:
            yocto_version = match[0]
            yocto_version = yocto_version.replace('7.0', '1.4')
        else:
            yocto_version = 'Unknown'

        msd = '-'.join([machine, kernel_version, yocto_version])

        match = re.findall(r'MSD.*VERSION="(.*)"', machine_file_content, re.M)
        if match:
            msd_version = match[0]

    if msd_version == 'Unknown':

        path = '/etc/mvlcgx*/conf/emitted.inc'
        msd_ver_file_list = glob.glob(path)

        if msd_ver_file_list:
            msd_ver_file = msd_ver_file_list[0]
            msd_ver_file_output = run_cmd('cat %s' % msd_ver_file,
                                          check_rc=False)
            match = re.findall(r'MSD.*VERSION="(.*)"', msd_ver_file_output,
                               re.M)
            if match:
                msd_version = match[0]

    config._metadata['MSD'] = msd
    config._metadata['MSD Version'] = msd_version

    msd_release = run_cmd('cat /etc/mvl-release', check_rc=False)
    if not msd_release:
        msd_release = 'Unknown'
    config._metadata['MSD Release'] = msd_release

    hostname = run_cmd('hostname', check_rc=False)
    if not hostname:
        hostname = 'Unknown'
    config._metadata['Target'] = hostname

    kernel_preemption = 'Unknown'
    if check_kernel_configs('PREEMPT_RT_FULL', logging=False):
        kernel_preemption = 'PREEMPT_RT_FULL'
    elif check_kernel_configs('PREEMPT_RT', logging=False):
        kernel_preemption = 'PREEMPT_RT'
    elif check_kernel_configs('PREEMPT__LL', logging=False):
        kernel_preemption = 'PREEMPT__LL'
    elif check_kernel_configs('PREEMPT_NONE', logging=False):
        kernel_preemption = 'PREEMPT_NONE'
    elif check_kernel_configs('PREEMPT_VOLUNTARY', logging=False):
        kernel_preemption = 'PREEMPT_VOLUNTARY'
    elif check_kernel_configs('PREEMPT', logging=False):
        kernel_preemption = 'PREEMPT'
    config._metadata['Kernel Preemption'] = kernel_preemption

    uname_output = run_cmd('uname -mr', check_rc=False)
    kernel_release = 'Unknown'
    arch = 'Unknown'
    if uname_output:
        kernel_release, arch = uname_output.split()
    config._metadata['Kernel Release'] = kernel_release
    config._metadata['Arch'] = arch
    parameters = sys.argv
    if not parameters:
        test_name = 'Unknown'
    else:
        test_name = re.sub(
            r'.*test_', '', ''.join(filter(lambda x: '.py' in x,
                                           parameters)).replace(".py", ""))
    if not test_name:
        test_name = 'Unknown'
    config._metadata['Test Name'] = test_name
def start_autofs():
    log.info('starting autofs service')
    return run_cmd('/etc/init.d/autofs start')