本文整理汇总了Python中dockertest.containers.DockerContainers.list_containers_with_cid方法的典型用法代码示例。如果您正苦于以下问题:Python DockerContainers.list_containers_with_cid方法的具体用法?Python DockerContainers.list_containers_with_cid怎么用?Python DockerContainers.list_containers_with_cid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dockertest.containers.DockerContainers
的用法示例。
在下文中一共展示了DockerContainers.list_containers_with_cid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cleanup
# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import list_containers_with_cid [as 别名]
def cleanup(self):
# Removes the docker safely
super(restart_base, self).cleanup()
if self.sub_stuff.get('container_id') is None:
return # Docker was not created, we are clean
containers = DockerContainers(self.parent_subtest)
cont_id = self.sub_stuff['container_id']
conts = containers.list_containers_with_cid(cont_id)
if conts == []:
return # Container created, but doesn't exist. Desired end-state.
elif len(conts) > 1:
msg = ("Multiple containers matches id %s, not removing any of "
"them...", cont_id)
raise xceptions.DockerTestError(msg)
DockerCmd(self, 'rm', ['--force', '--volumes', cont_id]).execute()
示例2: initialize
# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import list_containers_with_cid [as 别名]
def initialize(self):
super(restart_base, self).initialize()
config.none_if_empty(self.config)
self.sub_stuff['container_id'] = None
self.sub_stuff['restart_cmd'] = None
self.sub_stuff['stop_cmd'] = None
self.sub_stuff['restart_result'] = None
self.sub_stuff['stop_result'] = None
containers = DockerContainers(self.parent_subtest)
# Container
if self.config.get('run_options_csv'):
subargs = [arg for arg in
self.config['run_options_csv'].split(',')]
else:
subargs = []
image = DockerImage.full_name_from_defaults(self.config)
subargs.append(image)
subargs.append("bash")
subargs.append("-c")
subargs.append(self.config['exec_cmd'])
container = NoFailDockerCmd(self, 'run', subargs)
cont_id = container.execute().stdout.strip()
self.sub_stuff['container_id'] = cont_id
container = containers.list_containers_with_cid(cont_id)
if container == []:
raise xceptions.DockerTestNAError("Fail to get docker with id: %s"
% cont_id)
# Prepare the "restart" command
if self.config.get('restart_options_csv'):
subargs = [arg for arg in
self.config['restart_options_csv'].split(',')]
else:
subargs = []
subargs.append(cont_id)
self.sub_stuff['restart_cmd'] = NoFailDockerCmd(self, 'restart',
subargs)
# Prepare the "stop" command
if self.config.get('stop_options_csv'):
subargs = [arg for arg in
self.config['stop_options_csv'].split(',')]
else:
subargs = []
subargs.append(cont_id)
self.sub_stuff['stop_cmd'] = NoFailDockerCmd(self, 'stop', subargs)