def teardown(config):
    ver1 = CgroupVersion.get_version(CONTROLLER1)
    ver2 = CgroupVersion.get_version(CONTROLLER2)

    if ver1 == CgroupVersion.CGROUP_V2 and \
       ver2 == CgroupVersion.CGROUP_V2:
        # If both controllers are cgroup v2, then we only need to delete
        # one cgroup.  The path will be the same for both
        Cgroup.delete(config, [CONTROLLER1, CONTROLLER2], CGNAME)
    else:
        Cgroup.delete(config, CONTROLLER1, CGNAME)
        Cgroup.delete(config, CONTROLLER2, CGNAME)
def prereqs(config):
    result = consts.TEST_PASSED
    cause = None

    if CgroupVersion.get_version('cpu') != CgroupVersion.CGROUP_V1:
        result = consts.TEST_SKIPPED
        cause = 'This test requires the cgroup v1 cpu controller'
        return result, cause

    if CgroupVersion.get_version('memory') != CgroupVersion.CGROUP_V1:
        result = consts.TEST_SKIPPED
        cause = 'This test requires the cgroup v1 memory controller'
        return result, cause

    return result, cause
Beispiel #3
0
def test(config):
    result = consts.TEST_PASSED
    cause = None

    version = CgroupVersion.get_version(CONTROLLER)

    if version == CgroupVersion.CGROUP_V1:
        setting = SETTING_V1
        expected_out = EXPECTED_OUT_V1
    elif version == CgroupVersion.CGROUP_V2:
        setting = SETTING_V2
        expected_out = EXPECTED_OUT_V2

    out = Cgroup.get(config,
                     controller=None,
                     cgname=[CGNAME1, CGNAME2],
                     setting=setting)

    for line_num, line in enumerate(out.splitlines()):
        if line.strip() != expected_out.splitlines()[line_num].strip():
            result = consts.TEST_FAILED
            cause = ('Expected line:\n\t{}\nbut received line:\n\t{}'
                     ''.format(expected_out.splitlines()[line_num].strip(),
                               line.strip()))
            return result, cause

    return result, cause
def prereqs(config):
    result = consts.TEST_PASSED
    cause = None

    if CgroupVersion.get_version('cpu') != CgroupVersion.CGROUP_V1:
        result = consts.TEST_SKIPPED
        cause = 'This test requires the cgroup v1 cpu controller'

    # cpuacct controller is only available on cgroup v1, if an exception
    # gets raised, then no cgroup v1 controllers mounted.
    try:
        CgroupVersion.get_version('cpuacct')
    except IndexError:
        result = consts.TEST_SKIPPED
        cause = 'This test requires the cgroup v1 cpuacct controller'

    return result, cause
Beispiel #5
0
def prereqs(config):
    result = consts.TEST_PASSED
    cause = None

    if CgroupVersion.get_version('cpuset') != CgroupVersion.CGROUP_V2:
        result = consts.TEST_SKIPPED
        cause = 'This test requires the cgroup v2 cpuset controller'

    return result, cause
Beispiel #6
0
def prereqs(config):
    result = consts.TEST_PASSED
    cause = None

    if CgroupVersion.get_version(CONTROLLER) != CgroupVersion.CGROUP_V2:
        result = consts.TEST_SKIPPED
        cause = 'This test requires cgroup v2'

    return result, cause
Beispiel #7
0
    def get_cgroup(config, pid, controller):
        version = CgroupVersion.get_version(controller)

        if version == CgroupVersion.CGROUP_V1:
            return Process.__get_cgroup_v1(config, pid, controller)
        elif version == CgroupVersion.CGROUP_V2:
            return Process.__get_cgroup_v2(config, pid, controller)

        raise ValueError("get_cgroup() shouldn't reach this point")
Beispiel #8
0
def setup(config):
    Cgroup.create(config, CONTROLLER, CGNAME1)
    Cgroup.create(config, CONTROLLER, CGNAME2)

    version = CgroupVersion.get_version(CONTROLLER)

    if version == CgroupVersion.CGROUP_V1:
        Cgroup.set(config, CGNAME1, SETTING_V1, VALUE)
        Cgroup.set(config, CGNAME2, SETTING_V1, VALUE)
    elif version == CgroupVersion.CGROUP_V2:
        Cgroup.set(config, CGNAME1, SETTING_V2, VALUE)
        Cgroup.set(config, CGNAME2, SETTING_V2, VALUE)
def prereqs(config):
    result = consts.TEST_PASSED
    cause = None

    if config.args.container:
        result = consts.TEST_SKIPPED
        cause = 'This test cannot be run within a container'
        return result, cause

    if CgroupVersion.get_version(CONTROLLER) != CgroupVersion.CGROUP_V2:
        result = consts.TEST_SKIPPED
        cause = 'This test requires cgroup v2'

    return result, cause
def prereqs(config):
    result = consts.TEST_PASSED
    cause = None

    if CgroupVersion.get_version('memory') != CgroupVersion.CGROUP_V1:
        result = consts.TEST_SKIPPED
        cause = 'This test requires the cgroup v1 memory controller'
        return result, cause

    if not config.args.container:
        result = consts.TEST_SKIPPED
        cause = 'This test must be run within a container'
        return result, cause

    return result, cause
Beispiel #11
0
def setup(config):
    Cgroup.create(config, CONTROLLER, PARENT)
    Cgroup.create(config, CONTROLLER, os.path.join(PARENT, CHILD))
    Cgroup.create(config, CONTROLLER, os.path.join(PARENT, CHILD, GRANDCHILD))

    version = CgroupVersion.get_version(CONTROLLER)
    if version == CgroupVersion.CGROUP_V1:
        # cgdelete in a cgroup v1 controller should be able to move a process
        # from a child cgroup to its parent.
        #
        # Moving a process from a child cgroup to its parent isn't (easily)
        # supported in cgroup v2 because of cgroup v2's restriction that
        # processes only be located in leaf cgroups
        grandchild_cgrp_path = os.path.join(PARENT, CHILD, GRANDCHILD)
        config.process.create_process_in_cgroup(config, CONTROLLER,
                                                grandchild_cgrp_path)
Beispiel #12
0
def test(config):
    result = consts.TEST_PASSED
    cause = None

    out = Cgroup.get(config,
                     controller='{}:{}'.format(CONTROLLER, CGNAME),
                     print_headers=False)

    version = CgroupVersion.get_version(CONTROLLER)

    if version == CgroupVersion.CGROUP_V1:
        expected_out = EXPECTED_OUT_V1

        if len(out.splitlines()) != len(expected_out.splitlines()):
            expected_out = EXPECTED_OUT_V1_CFS_BANDWIDTH
    elif version == CgroupVersion.CGROUP_V2:
        expected_out = EXPECTED_OUT_V2

        if len(out.splitlines()) != len(expected_out.splitlines()):
            expected_out = EXPECTED_OUT_V2_PSI

            if len(out.splitlines()) != len(expected_out.splitlines()):
                expected_out = EXPECTED_OUT_V2_PSI_CFS_BANDWIDTH

    if len(out.splitlines()) != len(expected_out.splitlines()):
        result = consts.TEST_FAILED
        cause = ('Expected line count: {}, but received line count: {}'
                 ''.format(len(expected_out.splitlines()),
                           len(out.splitlines())))
        return result, cause

    if len(out.splitlines()) != len(expected_out.splitlines()):
        result = consts.TEST_FAILED
        cause = ('Expected {} lines but received {} lines'
                 ''.format(len(expected_out.splitlines()),
                           len(out.splitlines())))
        return result, cause

    for line_num, line in enumerate(out.splitlines()):
        if line.strip() != expected_out.splitlines()[line_num].strip():
            result = consts.TEST_FAILED
            cause = ('Expected line:\n\t{}\nbut received line:\n\t{}'
                     ''.format(expected_out.splitlines()[line_num].strip(),
                               line.strip()))
            return result, cause

    return result, cause
Beispiel #13
0
def test(config):
    result = consts.TEST_PASSED
    cause = None

    if CgroupVersion.get_version(CONTROLLER) == CgroupVersion.CGROUP_V1:
        # request the opposite version of what this system is running
        requested_ver = CgroupVersion.CGROUP_V2
    else:
        requested_ver = CgroupVersion.CGROUP_V1

    out = Cgroup.xget(config,
                      cgname=CGNAME,
                      setting=SETTING,
                      version=requested_ver,
                      print_headers=False,
                      ignore_unmappable=True)
    if len(out):
        result = consts.TEST_FAILED
        cause = 'Expected cgxget to return nothing.  Received {}'.format(out)

    return result, cause
Beispiel #14
0
def setup(config):
    CgroupCli.create(config, CONTROLLER, CGNAME)
    if CgroupVersion.get_version('cpu') == CgroupVersion.CGROUP_V1:
        CgroupCli.set(config, CGNAME, SETTING1, VALUE1)
    else:
        CgroupCli.set(config, CGNAME, SETTING2, VALUE2)