当前位置: 首页>>代码示例>>Python>>正文


Python NoFailDockerCmd.execute方法代码示例

本文整理汇总了Python中dockertest.dockercmd.NoFailDockerCmd.execute方法的典型用法代码示例。如果您正苦于以下问题:Python NoFailDockerCmd.execute方法的具体用法?Python NoFailDockerCmd.execute怎么用?Python NoFailDockerCmd.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dockertest.dockercmd.NoFailDockerCmd的用法示例。


在下文中一共展示了NoFailDockerCmd.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _init_container

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
    def _init_container(self):
        """ Create, store in self.stuff and execute container """
        try:
            fin = DockerImage.full_name_from_defaults(self.config)
        except ValueError:
            raise DockerTestNAError("Empty test image name configured,"
                                    "did you set one for this test?")

        docker_containers = DockerContainers(self)
        name = docker_containers.get_unique_name()
        self.stuff['container_name'] = name
        if self.config.get('run_options_csv'):
            subargs = [arg for arg in
                       self.config['run_options_csv'].split(',')]
        else:
            subargs = []
        subargs.append("--name %s" % name)

        subargs.append(fin)
        subargs.append("bash")
        container = NoFailDockerCmd(self, 'run', subargs)
        self.stuff['container_cmd'] = container
        container.execute()

        if self.config.get('attach_options_csv'):
            subargs = [arg for arg in
                       self.config['attach_options_csv'].split(',')]
        else:
            subargs = []
        subargs.append(name)
        container = AsyncDockerCmd(self, 'attach', subargs)
        self.stuff['container_cmd'] = container  # overwrites finished cmd
        stdin = os.pipe()
        self.stuff['container_stdin'] = stdin[1]
        container.execute(stdin[0])
开发者ID:ldoktor,项目名称:autotest-docker,代码行数:37,代码来源:top.py

示例2: run_once

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def run_once(self):
     super(events, self).run_once()
     dc = self.stuff['dc']
     # Start listening
     self.stuff['events_cmd'].execute()
     # Do something to make new events
     cmdresult = self.stuff['nfdc'].execute()
     cid = self.stuff['nfdc_cid'] = cmdresult.stdout.strip()
     while True:
         _json = dc.json_by_long_id(cid)
         if len(_json) > 0 and _json[0]["State"]["Running"]:
             self.loginfo("Waiting for test container to exit...")
             time.sleep(3)
         else:
             break
     if self.config['rm_after_run']:
         self.loginfo("Removing test container...")
         try:
             dc.kill_container_by_long_id(cid)
         except ValueError:
             pass  # container isn't running, this is fine.
         dcmd = NoFailDockerCmd(self, 'rm', ['--force', '--volumes', cid])
         dcmd.execute()
     # No way to know how long async events take to pass through :S
     self.loginfo("Sleeping %s seconds for events to catch up",
                  self.config['wait_stop'])
     time.sleep(self.config['wait_stop'])
     # Kill off docker events after 1 second
     events_cmd = self.stuff['events_cmd']
     self.stuff['events_cmdresult'] = events_cmd.wait(timeout=1)
开发者ID:sibiaoluo,项目名称:autotest-docker,代码行数:32,代码来源:events.py

示例3: _init_container

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
    def _init_container(self):
        """ Create, store in self.stuff and execute container """
        docker_containers = DockerContainers(self)
        prefix = self.config["container_name_prefix"]
        name = docker_containers.get_unique_name(prefix, length=4)
        self.stuff['container_name'] = name
        if self.config.get('run_options_csv'):
            subargs = [arg for arg in
                       self.config['run_options_csv'].split(',')]
        else:
            subargs = []
        subargs.append("--name %s" % name)
        fin = DockerImage.full_name_from_defaults(self.config)
        subargs.append(fin)
        subargs.append("bash")
        container = NoFailDockerCmd(self, 'run', subargs)
        self.stuff['container_cmd'] = container
        container.execute()

        if self.config.get('attach_options_csv'):
            subargs = [arg for arg in
                       self.config['attach_options_csv'].split(',')]
        else:
            subargs = []
        subargs.append(name)
        container = AsyncDockerCmd(self, 'attach', subargs)
        self.stuff['container_cmd'] = container  # overwrites finished cmd
        stdin = os.pipe()
        self.stuff['container_stdin'] = stdin[1]
        container.execute(stdin[0])
开发者ID:Lorquas,项目名称:autotest-docker,代码行数:32,代码来源:top.py

示例4: _init_container_attached

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
    def _init_container_attached(self, name):
        """
        Starts detached container and attaches it using docker attach
        """
        if self.config.get('run_options_csv'):
            subargs = [arg for arg in
                       self.config['run_options_csv'].split(',')]
        else:
            subargs = []
        subargs.append("--name %s" % name)
        fin = DockerImage.full_name_from_defaults(self.config)
        subargs.append(fin)
        subargs.append("bash")
        subargs.append("-c")
        subargs.append(self.config['exec_cmd'])
        container = NoFailDockerCmd(self, 'run', subargs, verbose=False)
        self.sub_stuff['container_cmd'] = container
        container.execute()

        if self.config.get('attach_options_csv'):
            subargs = [arg for arg in
                       self.config['attach_options_csv'].split(',')]
        else:
            subargs = []
        subargs.append(name)
        container = AsyncDockerCmd(self, 'attach', subargs, verbose=False)
        self.sub_stuff['container_cmd'] = container  # overwrites finished cmd
        container.execute()
开发者ID:Acidburn0zzz,项目名称:autotest-docker,代码行数:30,代码来源:kill.py

示例5: initialize

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def initialize(self):
     super(diff_base, self).initialize()
     dc = DockerContainers(self.parent_subtest)
     name = self.sub_stuff['name'] = dc.get_unique_name()
     fin = DockerImage.full_name_from_defaults(self.config)
     subargs = ['--name=%s' % (name), fin]
     subargs = subargs + self.config['command'].split(',')
     nfdc = NoFailDockerCmd(self, 'run', subargs)
     nfdc.execute()
开发者ID:ldoktor,项目名称:autotest-docker,代码行数:11,代码来源:diff.py

示例6: cleanup

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def cleanup(self):
     super(psa, self).cleanup()
     cid = self.stuff.get('container_id')
     if self.config['remove_after_test'] and cid is not None:
         self.logdebug("Cleaning container %s", cid)
         # We need to know about this breaking anyway, let it raise!
         nfdc = NoFailDockerCmd(self, "rm", ['--force',
                                             '--volumes', cid])
         nfdc.execute()
开发者ID:sibiaoluo,项目名称:autotest-docker,代码行数:11,代码来源:psa.py

示例7: run_once

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def run_once(self):
     super(help_base, self).run_once()  # Prints out basic info
     for option in self.sub_stuff['success_option_list']:
         # No successful command should throw an exception
         dkrcmd = NoFailDockerCmd(self.parent_subtest, option)
         self.sub_stuff["success_cmdresults"].append(dkrcmd.execute())
     for option in self.sub_stuff['failure_option_list']:
         # These are likely to return non-zero
         dkrcmd = DockerCmd(self.parent_subtest, option)
         self.sub_stuff['failure_cmdresults'].append(dkrcmd.execute())
开发者ID:ldoktor,项目名称:autotest-docker,代码行数:12,代码来源:dockerhelp.py

示例8: cleanup

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def cleanup(self):
     super(psa, self).cleanup()
     # Auto-converts "yes/no" to a boolean
     if ( (self.config['remove_after_test']) and
          (self.stuff.get('container_id') is not None) ):
         long_id = self.stuff['container_id']
         # We need to know about this breaking anyway, let it raise!
         nfdc = NoFailDockerCmd(self, "rm", ['--force',
                                             '--volumes', long_id])
         nfdc.execute()
开发者ID:xiaoqing-wei,项目名称:autotest-docker,代码行数:12,代码来源:psa.py

示例9: run_once

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def run_once(self):
     super(cp, self).run_once()
     #build arg list and execute command
     subargs = [self.stuff['container_name'] + ":" + self.stuff['cpfile']]
     subargs.append(self.tmpdir)
     nfdc = NoFailDockerCmd(self, "cp", subargs,
                            timeout=self.config['docker_timeout'])
     nfdc.execute()
     copied_path = "%s/%s" % (self.tmpdir,
                                self.stuff['cpfile'].split('/')[-1])
     self.stuff['copied_path'] = copied_path
开发者ID:Lorquas,项目名称:autotest-docker,代码行数:13,代码来源:cp.py

示例10: create_simple_container

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def create_simple_container(subtest):
     fin = DockerImage.full_name_from_defaults(subtest.config)
     name = utils.generate_random_string(12)
     subargs = ["--name=%s" % (name),
                fin,
                "/bin/bash",
                "-c",
                "'/bin/true'"]
     nfdc = NoFailDockerCmd(subtest.parent_subtest, 'run', subargs)
     nfdc.execute()
     if not subtest.sub_stuff or not subtest.sub_stuff['containers']:
         subtest.sub_stuff['containers'] = [name]
     else:
         subtest.sub_stuff['containers'] += [name]
     return name
开发者ID:Lorquas,项目名称:autotest-docker,代码行数:17,代码来源:dockerinspect.py

示例11: initialize

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def initialize(self):
     super(build, self).initialize()
     condition = self.config['build_timeout_seconds'] >= 10
     self.failif(not condition, "Config option build_timeout_seconds "
                                "is probably too short")
     di = DockerImages(self)
     image_name_tag = di.get_unique_name(self.config['image_name_prefix'],
                                         self.config['image_name_postfix'])
     image_name, image_tag = image_name_tag.split(':', 1)
     self.stuff['image_name_tag'] = image_name_tag
     self.stuff['image_name'] = image_name
     self.stuff['image_tag'] = image_tag
     # Must build from a base-image, import an empty one
     tarball = open(os.path.join(self.bindir, 'empty_base_image.tar'), 'rb')
     dc = NoFailDockerCmd(self, 'import', ["-", "empty_base_image"])
     dc.execute(stdin=tarball)
开发者ID:Acidburn0zzz,项目名称:autotest-docker,代码行数:18,代码来源:build.py

示例12: run_once

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
    def run_once(self):
        super(memory_base, self).run_once()

        for subargs in self.sub_stuff['subargs']:
            if self.config['expect_success'] == "PASS":
                memory_container = NoFailDockerCmd(self,
                                                   'run -d -t',
                                                   subargs).execute()
                long_id = self.container_json(str(subargs[0]).split('=')[1],
                                              'Id')
                memory_arg = self.get_value_from_arg(
                    self.get_arg_from_arglist(subargs, '-m'), ' ', 1)
                memory = self.split_unit(memory_arg)
                memory_value = memory[0]
                memory_unit = memory[1]

                cgpath = self.config['cgroup_path']
                cgvalue = self.config['cgroup_key_value']
                cgroup_memory = self.read_cgroup(long_id, cgpath, cgvalue)
                self.sub_stuff['result'].append(self.check_memory(
                    memory_value, cgroup_memory, memory_unit))
            else:
                memory_container = MustFailDockerCmd(self,
                                                     'run',
                                                     subargs)
                # throws exception if exit_status == 0
                self.sub_stuff['result'] = memory_container.execute()
开发者ID:Acidburn0zzz,项目名称:autotest-docker,代码行数:29,代码来源:memory.py

示例13: lookup_image_id

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def lookup_image_id(self, image_name, image_tag):
     # FIXME: We need a standard way to do this
     image_id = None
     # Any API failures must not be fatal
     if DOCKERAPI:
         client = docker.Client()
         results = client.images(name=image_name)
         image = None
         if len(results) == 1:
             image = results[0]
             # Could be unicode strings
             if ((str(image['Repository']) == image_name) and
                 (str(image['Tag']) == image_tag)):
                 image_id = image.get('Id')
         if ((image_id is None) or (len(image_id) < 12)):
             logging.error("Could not lookup image %s:%s Id using "
                           "docker python API Data: '%s'",
                           image_name, image_tag, str(image))
             image_id = None
     # Don't have DOCKERAPI or API failed (still need image ID)
     if image_id is None:
         subargs = ['--quiet', image_name]
         dkrcmd = NoFailDockerCmd(self.parent_subtest, 'images', subargs)
         # fail -> raise exception
         cmdresult = dkrcmd.execute()
         stdout_strip = cmdresult.stdout.strip()
         # TODO: Better image ID validity check?
         if len(stdout_strip) == 12:
             image_id = stdout_strip
         else:
             self.loginfo("Error retrieving image id, unexpected length")
     if image_id is not None:
         self.loginfo("Found image Id '%s'", image_id)
     return image_id
开发者ID:xiaoqing-wei,项目名称:autotest-docker,代码行数:36,代码来源:empty.py

示例14: _gather_processes

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
    def _gather_processes(self, last_idx=0, fail=False):
        """
        Gathers `docker top` and in-container `ps` output and stores it in
        `self.stuff`.
        """
        if not fail:
            cmd = NoFailDockerCmd(self, "top", [self.stuff['container_name'],
                                                'all'])
            out = cmd.execute().stdout.splitlines()
            self.stuff['docker_top'].append(out)
        else:
            cmd = MustFailDockerCmd(self, "top", [self.stuff['container_name'],
                                                  'all'])
            out = cmd.execute()
            self.stuff['docker_top'].append(out)
            return

        cont_cmd = self.stuff['container_cmd']
        os.write(self.stuff['container_stdin'], "ps all\n")

        new_idx = last_idx
        endtime = time.time() + 5
        while time.time() < endtime:
            out = cont_cmd.stdout.splitlines()
            if len(out) <= last_idx:
                continue
            i = last_idx
            for i in xrange(last_idx, len(out)):
                if "ps all" in out[i]:    # wait for the command to appear
                    break
            else:   # "ps all" not in output, wait a bit longer
                continue
            if new_idx == len(out):    # wait twice for the same output
                out = out[i + 1:]   # cut everything before this cmd execution
                # cut the last line (bash prompt)
                if out and not self.__re_top_all.match(out[-1]):
                    out = out[:-1]
                break
            new_idx = len(out)
            time.sleep(0.05)
        else:
            raise xceptions.DockerTestFail("No new output after 'ps' command "
                                           "executed in the container.")
        self.stuff['container_ps'].append(out)
        return new_idx
开发者ID:Acidburn0zzz,项目名称:autotest-docker,代码行数:47,代码来源:top.py

示例15: initialize

# 需要导入模块: from dockertest.dockercmd import NoFailDockerCmd [as 别名]
# 或者: from dockertest.dockercmd.NoFailDockerCmd import execute [as 别名]
 def initialize(self):
     super(build, self).initialize()
     condition = self.config['build_timeout_seconds'] >= 10
     self.failif(not condition, "Config option build_timeout_seconds "
                                "is probably too short")
     # FIXME: Need a standard way to do this
     image_name_tag = ("%s%s%s"
                       % (self.config['image_name_prefix'],
                          utils.generate_random_string(4),
                          self.config['image_name_postfix']))
     image_name, image_tag = image_name_tag.split(':', 1)
     self.stuff['image_name_tag'] = image_name_tag
     self.stuff['image_name'] = image_name
     self.stuff['image_tag'] = image_tag
     # Must build from a base-image, import an empty one
     tarball = open(os.path.join(self.bindir, 'empty_base_image.tar'), 'rb')
     dc = NoFailDockerCmd(self, 'import', ["-", "empty_base_image"])
     dc.execute(stdin=tarball)
开发者ID:xiaoqing-wei,项目名称:autotest-docker,代码行数:20,代码来源:build.py


注:本文中的dockertest.dockercmd.NoFailDockerCmd.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。