示例#1
0
    def run(self, args):
        if len(args) == 0:
            self.parser.error('Less arguments: ' + ' '.join(args))

        if self.options.debug:
            print args

        target_dir = args[0]

        parent_path = os.path.dirname(target_dir)
        new = os.path.basename(target_dir)
        if self.options.parents and not os.path.exists(parent_path):
            self.parser.error('%s not found' % parent_path)

        parent = cgroup.get_cgroup(parent_path)

        if not self.options.apply_all:
            parent.mkdir(new)
        else:
            status = cgroup.SubsystemStatus()
            enabled = status.get_enabled()
            enabled = [
                s for s in enabled if not (s == 'perf_event' or s == 'debug')
            ]

            parents = []
            for name in enabled:
                mount_point = status.get_path(name)
                path = os.path.join(mount_point, parent.fullname.lstrip('/'))
                parents.append(cgroup.get_cgroup(path))

            # Check directory existence first
            to_be_created = []
            for _parent in parents:
                new_path = os.path.join(_parent.fullpath, new)
                if self.options.debug:
                    print(new_path)
                if os.path.exists(new_path):
                    if not self.options.parents:
                        print("%s exists" % new_path)
                        sys.exit(1)
                    else:
                        to_be_created.append(_parent)
                else:
                    to_be_created.append(_parent)

            if self.options.debug:
                print(to_be_created)

            for _parent in to_be_created:
                if self.options.debug:
                    new_path = os.path.join(_parent.fullpath, new)
                    print("mkdir %s" % new_path)
                new_path = os.path.join(_parent.fullpath, new)
                if os.path.exists(new_path):
                    # XXX: this may happen when systemd creates
                    # a cpuacct,cpu group and links cpu and cpuacct
                    # to it.
                    continue
                _parent.mkdir(new)
示例#2
0
    def run(self, args):
        if len(args) == 0:
            self.parser.error('Less arguments: ' + ' '.join(args))

        if self.options.debug:
            print args

        target_dir = args[0]

        if not self.options.apply_all:
            if not os.path.exists(target_dir):
                print("Error: %s not found" % target_dir)
                sys.exit(1)

            if not os.path.isdir(target_dir):
                print("Error: %s is not a directory" % target_dir)
                sys.exit(1)

            cg = cgroup.get_cgroup(target_dir)

            if cg.depth == 0:
                print("Error: %s is a root cgroup" % target_dir)
                sys.exit(1)

            cg.rmdir()
        else:
            target = cgroup.get_cgroup(target_dir)

            status = cgroup.SubsystemStatus()
            enabled = status.get_enabled()
            enabled = [s for s in enabled if not (s == 'perf_event' or s == 'debug')]

            targets = []
            for name in enabled:
                mount_point = status.get_path(name)
                path = os.path.join(mount_point, target.fullname.lstrip('/'))
                targets.append(cgroup.get_cgroup(path))

            # Check directory existence first
            for _target in targets:
                if self.options.debug:
                    print(_target.fullpath)
                if not os.path.exists(_target.fullpath):
                    print("Error: %s not found" % _target.fullpath)
                    sys.exit(1)
                if not os.path.isdir(_target.fullpath):
                    print("Error: %s is not a directory" % _target.fullpath)
                    sys.exit(1)

            for _target in targets:
                if self.options.debug:
                    print("rmdir %s" % _target.fullpath)
                if not os.path.exists(_target.fullpath):
                    # XXX: this may happen when systemd creates
                    # a cpuacct,cpu group and links cpu and cpuacct
                    # to it.
                    continue
                _target.rmdir()
示例#3
0
            elif cmd == 'pgrep':
                opts.append('sh')
            elif cmd == 'tree' and '-a' in opts and subsys != 'cpu':
                # In the case, tree always fails
                continue
            if options.debug:
                print(opts)
            allok &= test(cmdline, opts)
    return allok


commands = cgutils.commands.__all__
# FIXME: there is no way to test automatically these commands ;-/
commands = [c for c in commands if c not in ['event', 'mkdir', 'rmdir']]

status = cgroup.SubsystemStatus()
subsystems = status.get_enabled()
subsystems = [
    s for s in subsystems
    if s != 'debug' and s != 'perf_event' and 'name=' not in s
]

for cmd in commands:
    print("#### Testing %s" % cmd)
    cmdline = '/usr/bin/python ./bin/cgutil %s %%s' % cmd
    output = execute(cmdline % '--help')
    _options = parse_help(output)
    if options.debug:
        print(output)
        print(cmd, _options)
    if not _options: