コード例 #1
0
    def config(self):
        # map our UID and GID to the same UID/GID in the container
        cmd = ('printf "uid {} 1000\ngid {} 1000" | sudo lxc config set '
               '{} raw.idmap -'
               ''.format(os.getuid(), os.getgid(), self.name))
        Run.run(cmd, shell_bool=True)

        # add the libcgroup root directory (where we did the build) into
        # the container
        cmd2 = list()
        if self.privileged:
            cmd2.append('sudo')
        cmd2.append('lxc')
        cmd2.append('config')
        cmd2.append('device')
        cmd2.append('add')
        cmd2.append(self.name)
        cmd2.append('libcgsrc')  # arbitrary name of device
        cmd2.append('disk')
        # to appease gcov, mount the libcgroup source at the same path as we
        # built it.  This can be worked around someday by using
        # GCOV_PREFIX_STRIP, but that was more difficult to setup than just
        # doing this initially
        cmd2.append('source={}'.format(self.libcg_dir))
        cmd2.append('path={}'.format(self.libcg_dir))

        return Run.run(cmd2)
コード例 #2
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def delete(config, controller_list, cgname, recursive=False):
        if isinstance(controller_list, str):
            controller_list = [controller_list]

        cmd = list()

        if not config.args.container:
            cmd.append('sudo')
        cmd.append(Cgroup.build_cmd_path('cgdelete'))

        if recursive:
            cmd.append('-r')

        if controller_list:
            controllers_and_path = '{}:{}'.format(','.join(controller_list),
                                                  cgname)
        else:
            controllers_and_path = ':{}'.format(cgname)

        cmd.append('-g')
        cmd.append(controllers_and_path)

        if config.args.container:
            config.container.run(cmd)
        else:
            Run.run(cmd)
コード例 #3
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def snapshot(config, controller=None):
        cmd = list()
        cmd.append(Cgroup.build_cmd_path('cgsnapshot'))
        if controller is not None:
            cmd.append(controller)

        # ensure the deny list file exists
        if config.args.container:
            try:
                config.container.run(
                    ['sudo', 'touch', '/etc/cgsnapshot_blacklist.conf'])
            except RunError as re:
                if re.ret == 0 and 'unable to resolve host' in re.stderr:
                    pass
        else:
            Run.run(['sudo', 'touch', '/etc/cgsnapshot_blacklist.conf'])

        try:
            if config.args.container:
                res = config.container.run(cmd)
            else:
                res = Run.run(cmd)
        except RunError as re:
            if re.ret == 0 and \
               'neither blacklisted nor whitelisted' in re.stderr:
                res = re.stdout
            else:
                raise (re)

        # convert the cgsnapshot stdout to a dict of cgroup objects
        return Cgroup.snapshot_to_dict(res)
コード例 #4
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def classify(config,
                 controller,
                 cgname,
                 pid_list,
                 sticky=False,
                 cancel_sticky=False):
        cmd = list()

        if not config.args.container:
            cmd.append('sudo')
        cmd.append(Cgroup.build_cmd_path('cgclassify'))
        cmd.append('-g')
        cmd.append('{}:{}'.format(controller, cgname))

        if isinstance(pid_list, str):
            cmd.append(pid_list)
        elif isinstance(pid_list, int):
            cmd.append(str(pid_list))
        elif isinstance(pid_list, list):
            for pid in pid_list:
                cmd.append(pid)

        if config.args.container:
            config.container.run(cmd)
        else:
            Run.run(cmd)
コード例 #5
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def init_cgrules(config):
        cmd = list()

        cmd.append('sudo')
        cmd.append('mkdir')
        cmd.append('-p')
        cmd.append('/etc/cgconfig.d')

        try:
            if config.args.container:
                config.container.run(cmd, shell_bool=True)
            else:
                Run.run(cmd, shell_bool=True)
        except RunError as re:
            raise re

        cmd2 = list()

        cmd2.append('sudo')
        cmd2.append('touch')
        cmd2.append('/etc/cgconfig.conf')

        if config.args.container:
            config.container.run(cmd2, shell_bool=True)
        else:
            Run.run(cmd2, shell_bool=True)
def setup(config):
    user_name = Run.run('whoami', shell_bool=True)
    group_name = Run.run('groups', shell_bool=True).split(' ')[0]

    CgroupCli.create(config,
                     controller_list=CONTROLLER,
                     cgname=PARENT_NAME,
                     user_name=user_name,
                     group_name=group_name)
コード例 #7
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def create(config,
               controller_list,
               cgname,
               user_name=None,
               group_name=None,
               dperm=None,
               fperm=None,
               tperm=None,
               tasks_user_name=None,
               tasks_group_name=None,
               cghelp=False):
        if isinstance(controller_list, str):
            controller_list = [controller_list]

        cmd = list()

        if not config.args.container:
            cmd.append('sudo')
        cmd.append(Cgroup.build_cmd_path('cgcreate'))

        if user_name is not None and group_name is not None:
            cmd.append('-a')
            cmd.append('{}:{}'.format(user_name, group_name))

        if dperm is not None:
            cmd.append('-d')
            cmd.append(dperm)

        if fperm is not None:
            cmd.append('-f')
            cmd.append(fperm)

        if tperm is not None:
            cmd.append('-s')
            cmd.append(tperm)

        if tasks_user_name is not None and tasks_group_name is not None:
            cmd.append('-t')
            cmd.append('{}:{}'.format(tasks_user_name, tasks_group_name))

        if cghelp:
            cmd.append('-h')

        if controller_list:
            controllers_and_path = '{}:{}'.format(','.join(controller_list),
                                                  cgname)
        else:
            controllers_and_path = ':{}'.format(cgname)

        cmd.append('-g')
        cmd.append(controllers_and_path)

        if config.args.container:
            config.container.run(cmd)
        else:
            Run.run(cmd)
コード例 #8
0
def teardown(config):
    pids = Cgroup.get_pids_in_cgroup(config, CGNAME, CONTROLLER)
    if pids:
        for p in pids.splitlines():
            if config.args.container:
                config.container.run(['kill', '-9', p])
            else:
                Run.run(['sudo', 'kill', '-9', p])

    Cgroup.delete(config, CONTROLLER, CGNAME)
コード例 #9
0
def setup(config):
    f = open(CONFIG_FILE_NAME, 'w')
    f.write(CONFIG_FILE)
    f.close()

    if config.args.container:
        config.container.run(['useradd', '-p', 'Test019#1', USER])
        config.container.run(['groupadd', GROUP])
    else:
        Run.run(['sudo', 'useradd', '-p', 'Test019#1', USER])
        Run.run(['sudo', 'groupadd', GROUP])
コード例 #10
0
ファイル: controller.py プロジェクト: FriedSock/MLO-1
    def start_run(self, name, fitness, configuration):
        if not name:
            name = 'Default Run'
        run = Run(name, fitness, configuration, self)

        # Special case when we are restarting a previously crashed run
        if self.restart:
            run.restart()
            return run

        run.run()
        return run
コード例 #11
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def __run_cgrules(config):
        cmd = list()

        cmd.append('sudo')
        cmd.append(Cgroup.build_daemon_path('cgrulesengd'))
        cmd.append('-d')
        cmd.append('-n')

        if config.args.container:
            raise ValueError('Running cgrules within a container is not '
                             'supported')
        else:
            Run.run(cmd, shell_bool=True)
コード例 #12
0
def teardown(config):
    os.remove(CONFIG_FILE_NAME)

    try:
        if config.args.container:
            config.container.run(['userdel', USER])
            config.container.run(['groupdel', GROUP])
        else:
            Run.run(['sudo', 'userdel', USER])
            Run.run(['sudo', 'groupdel', GROUP])
    except (ContainerError, RunError, ValueError):
        pass

    Cgroup.delete(config, CONTROLLER, CGNAME)
コード例 #13
0
    def join_children(self, config):
        for child in self.children:
            child.join(1)

        for child in self.children_pids:
            try:
                if config.args.container:
                    config.container.run(['kill', str(child)])
                else:
                    Run.run(['kill', str(child)])
            except (RunError, ContainerError):
                # ignore any errors during the kill command.  this is belt
                # and suspenders code
                pass
コード例 #14
0
    def __infinite_loop(config, sleep_time=1):
        cmd = [
            "/usr/bin/perl", "-e",
            "'while(1){{sleep({})}};'".format(sleep_time)
        ]

        try:
            if config.args.container:
                config.container.run(cmd, shell_bool=True)
            else:
                Run.run(cmd, shell_bool=True)
        except RunError:
            # when the process is killed, a RunError will be thrown.  let's
            # catch and suppress it
            pass
コード例 #15
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def join_children(self, config):
        # todo - make this smarter.  this is ugly, but it works for now
        cmd = ['sudo', 'killall', 'cgrulesengd']
        try:
            if config.args.container:
                config.container.run(cmd, shell_bool=True)
            else:
                Run.run(cmd, shell_bool=True)
        except (RunError, ContainerError):
            # ignore any errors during the kill command.  this is belt
            # and suspenders code
            pass

        for child in self.children:
            child.join(1)
コード例 #16
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def cgexec(config,
               controller,
               cgname,
               cmdline,
               sticky=False,
               cghelp=False):
        """cgexec equivalent method
        """
        cmd = list()

        if not config.args.container:
            cmd.append('sudo')
        cmd.append(Cgroup.build_cmd_path('cgexec'))
        cmd.append('-g')
        cmd.append('{}:{}'.format(controller, cgname))

        if sticky:
            cmd.append('--sticky')

        if isinstance(cmdline, str):
            cmd.append(cmdline)
        elif isinstance(cmdline, list):
            for entry in cmdline:
                cmd.append(entry)

        if cghelp:
            cmd.append('-h')

        if config.args.container:
            return config.container.run(cmd, shell_bool=True)
        else:
            return Run.run(cmd, shell_bool=True)
コード例 #17
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def lssubsys(config,
                 ls_all=False,
                 cghelp=False,
                 hierarchies=False,
                 mount_points=False,
                 all_mount_points=False):
        cmd = list()

        cmd.append(Cgroup.build_cmd_path('lssubsys'))

        if ls_all:
            cmd.append('-a')

        if cghelp:
            cmd.append('-h')

        if hierarchies:
            cmd.append('-i')

        if mount_points:
            cmd.append('-m')

        if all_mount_points:
            cmd.append('-M')

        if config.args.container:
            ret = config.container.run(cmd)
        else:
            ret = Run.run(cmd)

        return ret
コード例 #18
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def lscgroup(config, cghelp=False, controller=None, path=None):
        cmd = list()

        cmd.append(Cgroup.build_cmd_path('lscgroup'))

        if cghelp:
            cmd.append('-h')

        if controller is not None and path is not None:
            if isinstance(controller, list):
                for idx, ctrl in enumerate(controller):
                    cmd.append('-g')
                    cmd.append('{}:{}'.format(ctrl, path[idx]))
            elif isinstance(controller, str):
                cmd.append('-g')
                cmd.append('{}:{}'.format(controller, path))
            else:
                raise ValueError('Unsupported controller value')

        if config.args.container:
            ret = config.container.run(cmd)
        else:
            ret = Run.run(cmd)

        return ret
コード例 #19
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def clear(config,
              empty=False,
              cghelp=False,
              load_file=None,
              load_dir=None):
        cmd = list()

        if not config.args.container:
            cmd.append('sudo')
        cmd.append(Cgroup.build_cmd_path('cgclear'))

        if empty:
            cmd.append('-e')

        if cghelp:
            cmd.append('-h')

        if load_file is not None:
            cmd.append('-l')
            cmd.append(load_file)

        if load_dir is not None:
            cmd.append('-L')
            cmd.append(load_dir)

        if config.args.container:
            return config.container.run(cmd)
        else:
            return Run.run(cmd)
コード例 #20
0
def setup(config):
    cmd = ['sudo', 'mkdir']

    cmd.append(MNT_POINT)

    for count in range(MNT_COUNT):
        cmd.append(cgroup_path(count))

    # execute mkdir top-level top-level/sub-directory* at once.
    Run.run(cmd)

    for count in range(MNT_COUNT):
        cmd = ['sudo', 'mount', '-t', 'cgroup', '-o']
        cmd.append('none,name=' + DIR_PREFIX + str(count))
        cmd.append('none')
        cmd.append(cgroup_path(count))
        Run.run(cmd)
コード例 #21
0
ファイル: worker.py プロジェクト: krivard/codalab-cli
 def _run(self, bundle, resources):
     if self.shared_file_system:
         bundle_path = bundle['location']
     else:
         bundle_path = self._dependency_manager.get_run_path(bundle['uuid'])
     run = Run(self._bundle_service, self._docker, self._image_manager,
               self, bundle, bundle_path, resources)
     if run.run():
         self._worker_state_manager.add_run(bundle['uuid'], run)
コード例 #22
0
ファイル: ftests.py プロジェクト: libcgroup/libcgroup-tests
def update_host_subgid():
    subgid_line1 = 'lxd:{}:1'.format(os.getgid())
    subgid_line2 = 'root:{}:1'.format(os.getgid())
    found_line1 = False
    found_line2 = False

    with open('/etc/subgid') as ufile:
        for line in ufile.readlines():
            if line.strip() == subgid_line1:
                found_line1 = True
            elif line.strip() == subgid_line2:
                found_line2 = True

    if not found_line1:
        Run.run('sudo sh -c "echo {} >> /etc/subgid"'.format(subgid_line1),
                shell_bool=True)
    if not found_line2:
        Run.run('sudo sh -c "echo {} >> /etc/subgid"'.format(subgid_line2),
                shell_bool=True)
コード例 #23
0
ファイル: worker.py プロジェクト: Akhila-Yerukola/codalab-cli
 def _run(self, bundle, resources):
     if self.shared_file_system:
         bundle_path = bundle['location']
     else:
         bundle_path = self._dependency_manager.get_run_path(bundle['uuid'])
     run = Run(self._bundle_service, self._docker, self._image_manager,
               self, bundle, bundle_path, resources)
     if run.run():
         with self._runs_lock:
             self._runs[bundle['uuid']] = run
コード例 #24
0
def teardown(config):
    result = consts.TEST_PASSED
    cause = None

    for count in range(MNT_COUNT):
        cmd = ['sudo', 'umount']
        cmd.append(cgroup_path(count))
        Run.run(cmd)

    cmd = ['sudo', 'rmdir']
    for count in range(MNT_COUNT):
        cmd.append(cgroup_path(count))

    cmd.append(MNT_POINT)

    # execute rmdir top-level top-level/sub-directory* at once.
    Run.run(cmd)

    return result, cause
コード例 #25
0
ファイル: cgroup.py プロジェクト: libcgroup/libcgroup-tests
    def set_cgrules_conf(config, line, append=True):
        cmd = list()

        cmd.append('sudo')
        cmd.append('su')
        cmd.append('-c')

        if append:
            redirect_str = '>>'
        else:
            redirect_str = '>'

        subcmd = '"echo {} {} {}"'.format(line, redirect_str,
                                          consts.CGRULES_FILE)
        cmd.append(subcmd)

        if config.args.container:
            config.container.run(cmd, shell_bool=True)
        else:
            Run.run(cmd, shell_bool=True)
コード例 #26
0
    def _init_container(self, q):
        cmd = list()

        if self.privileged:
            cmd.append('sudo')

        cmd.append('lxc')
        cmd.append('init')

        cmd.append('{}:{}'.format(self.distro, self.release))

        cmd.append(self.name)

        try:
            Run.run(cmd)
            q.put(True)
        except Exception:  # noqa: E722
            q.put(False)
        except BaseException:  # noqa: E722
            q.put(False)
コード例 #27
0
ファイル: utils.py プロジェクト: libcgroup/libcgroup-tests
def get_file_owner_group_name(config, filename):
    cmd = list()
    cmd.append('stat')
    cmd.append('-c')
    cmd.append("'%G'")
    cmd.append(filename)

    if config.args.container:
        return config.container.run(cmd, shell_bool=True)
    else:
        return Run.run(cmd, shell_bool=True)
コード例 #28
0
ファイル: utils.py プロジェクト: libcgroup/libcgroup-tests
def get_file_permissions(config, filename):
    cmd = list()
    cmd.append('stat')
    cmd.append('-c')
    cmd.append("'%a'")
    cmd.append(filename)

    if config.args.container:
        return config.container.run(cmd, shell_bool=True)
    else:
        return Run.run(cmd, shell_bool=True)
コード例 #29
0
    def delete(self):
        cmd = list()

        if self.privileged:
            cmd.append('sudo')

        cmd.append('lxc')
        cmd.append('delete')

        cmd.append(self.name)

        return Run.run(cmd)
コード例 #30
0
    def start(self):
        cmd = list()

        if self.privileged:
            cmd.append('sudo')

        cmd.append('lxc')
        cmd.append('start')

        cmd.append(self.name)

        return Run.run(cmd)
コード例 #31
0
ファイル: ftests.py プロジェクト: libcgroup/libcgroup-tests
def setup(config, do_teardown=True, record_time=False):
    global setup_time

    start_time = time.time()
    if do_teardown:
        # belt and suspenders here.  In case a previous run wasn't properly
        # cleaned up, let's try and clean it up here
        try:
            teardown(config)
        except Exception as e:
            # log but ignore all exceptions
            Log.log_debug(e)

    if config.args.container:
        # this command initializes the lxd storage, networking, etc.
        Run.run(['sudo', 'lxd', 'init', '--auto'])
        update_host_subuid()
        update_host_subgid()

        config.container.create()
        config.container.config()
        config.container.start()

        # LXC on Ubuntu 20.04 put sed in a different spot.  Add a symlink
        config.container.run(['ln', '-s', '/bin/sed', '/usr/bin/sed'])

        # add the libcgroup library to the container's ld
        libcgrp_lib_path = os.path.join(consts.LIBCG_MOUNT_POINT, 'src/.libs')
        echo_cmd = ([
            'bash', '-c', 'echo {} >> /etc/ld.so.conf.d/libcgroup.conf'
            ''.format(libcgrp_lib_path)
        ])
        config.container.run(echo_cmd)
        config.container.run('ldconfig')

    if record_time:
        setup_time = time.time() - start_time
コード例 #32
0
ファイル: gui.py プロジェクト: krekle/aiProg
    def play_level(self, level, str_level=None):


        # Set new run instance

        # Astar
        # Label for Algorithm
        astar_label = Label(master=self, text="Best First - Algorithm").grid(column=0, row=0, sticky=N+W, padx=20, pady=20)
        astar_generated = Label(master=self, textvariable=self.astar_stat).grid(column=0, row=2, sticky=N+W, padx=20, pady=20)

        astar_run = Run(self)
        self.astar_gui = Board(parent=self, stats_gui=self.astar_stat, run=astar_run, column=0, row=1, sq_size=self.sqsize, delay=self.delay, height=300, width=300)
        astar_run.gui = self.astar_gui


        # BFS
        # Label for Algorithm
        bfs_label = Label(master=self, text="BFS - Algorithm").grid(column=1, row=0, sticky=N+W, padx=20, pady=20)
        bfs_generated = Label(master=self, textvariable=self.bfs_stat).grid(column=1, row=2, sticky=N+W, padx=20, pady=20)

        bfs_run = Run(self)
        self.bfs_gui = Board(parent=self, stats_gui=self.bfs_stat, run=bfs_run, column=1, row=1, sq_size=self.sqsize, delay=self.delay, height=300, width=300)
        bfs_run.gui = self.bfs_gui

        # DFS
        # Label for Algorithm
        astar_label = Label(master=self, text="DFS - Algorithm").grid(column=2, row=0, sticky=N+W, padx=20, pady=20)
        dfs_generated = Label(master=self, textvariable=self.dfs_stat).grid(column=2, row=2, sticky=N+W, padx=20, pady=20)


        lifo_run = Run(self)
        self.lifo_gui = Board(parent=self, stats_gui=self.dfs_stat, run=lifo_run, column=2, row=1, sq_size=self.sqsize, delay=self.delay, height=300, width=300)
        lifo_run.gui = self.lifo_gui




        # Set the algorithm 0 = Astar, 1=BFS
        astar_run.set_algorithm(0)
        bfs_run.set_algorithm(1)
        lifo_run.set_algorithm(2)

        # Set the correct level in Run class
        if str_level:
            bfs_run.initialize(bfs_run.generate_board(str_level=str_level))
            astar_run.initialize((astar_run.generate_board(str_level=str_level)))
            lifo_run.initialize(lifo_run.generate_board(str_level=str_level))
        else:
            bfs_run.open_file(level)
            astar_run.open_file(level)
            lifo_run.open_file(level)

        # Run the solvers
        astar_run.run()
        bfs_run.run()
        lifo_run.run()