本文整理汇总了Python中dockertest.containers.DockerContainers.list_containers方法的典型用法代码示例。如果您正苦于以下问题:Python DockerContainers.list_containers方法的具体用法?Python DockerContainers.list_containers怎么用?Python DockerContainers.list_containers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dockertest.containers.DockerContainers
的用法示例。
在下文中一共展示了DockerContainers.list_containers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: postprocess
# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import list_containers [as 别名]
def postprocess(self):
self.loginfo("postprocess()")
# Raise exception if problems found
OutputGood(self.sub_stuff["cmdresult"])
self.failif_ne(
self.sub_stuff["cmdresult"].exit_status, 0, "Non-zero commit exit status: %s" % self.sub_stuff["cmdresult"]
)
im = self.check_image_exists(self.sub_stuff["new_image_name"])
# Needed for cleanup
self.sub_stuff["image_list"] = im
self.failif(len(im) < 1, "Failed to look up committed image ")
self.check_file_in_image()
# Check if is possible start image with default command.
dc = DockerCmd(
self, "run", ["--rm", self.sub_stuff["image_list"][0].long_id], timeout=self.config["docker_timeout"]
)
results = dc.execute()
dct = DockerContainers(self)
cnts = dct.list_containers()
for cont in cnts:
if cont.image_name == self.sub_stuff["image_list"][0].full_name:
try:
dct.kill_container_by_long_id(cont.long_id)
except ValueError:
pass
dc = DockerCmd(self, "rm", ["-f", cont.long_id])
rm_results = dc.execute()
self.failif_ne(rm_results.exit_status, 0, "Non-zero commit exit status: %s" % rm_results)
self.failif_ne(results.exit_status, 0, "Non-zero commit exit status: %s" % results)
self.failif(not self.sub_stuff["rand_data"] in results.stdout, "Unexpected command result: %s" % results.stdout)
示例2: cleanup
# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import list_containers [as 别名]
def cleanup(self):
super(run, self).cleanup()
# Clean up all containers
dc = DockerContainers(self)
for cobj in dc.list_containers():
self.logwarning("Found leftover container: %s", cobj.container_name)
try:
dc.kill_container_by_obj(cobj)
except ValueError:
pass # already dead
else:
self.logdebug("Killed container %s, waiting up to %d seconds "
"for it to exit", cobj.container_name,
dc.timeout)
dc.wait_by_obj(cobj)
self.logdebug("Removing container %s", cobj.container_name)
dc.remove_by_obj(cobj)
# Clean up all non-default images
fqin = DockerImage.full_name_from_defaults(self.config)
di = DockerImages(self)
def_img_obj = di.list_imgs_with_full_name(fqin)[0]
for img_obj in di.list_imgs():
if img_obj.full_name != def_img_obj.full_name:
self.logwarning("Found leftover image: %s", img_obj)
di.remove_image_by_image_obj(img_obj)
else:
self.logdebug("Not removing default image: %s", def_img_obj)
示例3: init_use_names
# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import list_containers [as 别名]
def init_use_names(self, use_names=False):
if use_names:
conts = self.sub_stuff['containers']
containers = DockerContainers(self.parent_subtest)
containers = containers.list_containers()
cont_ids = [cont['id'] for cont in conts]
for cont in containers:
if cont.long_id in cont_ids:
if use_names is not True and random.choice((True, False)):
continue # 50% chance of using id vs. name
# replace the id with name
cont_idx = cont_ids.index(cont.long_id)
conts[cont_idx]['id'] = cont.container_name
示例4: postprocess
# 需要导入模块: from dockertest.containers import DockerContainers [as 别名]
# 或者: from dockertest.containers.DockerContainers import list_containers [as 别名]
def postprocess(self):
super(commit_base, self).postprocess()
# Raise exception if problems found
OutputGood(self.sub_stuff['cmdresult'])
self.failif(self.sub_stuff['cmdresult'].exit_status != 0,
"Non-zero commit exit status: %s"
% self.sub_stuff['cmdresult'])
im = self.check_image_exists(self.sub_stuff["new_image_name"])
# Needed for cleanup
self.sub_stuff['image_list'] = im
self.failif(len(im) < 1,
"Failed to look up committed image ")
self.check_file_in_image()
# Check if is possible start image with default command.
dc = DockerCmd(self.parent_subtest, "run",
[self.sub_stuff['image_list'][0].long_id],
timeout=self.config['docker_timeout'])
results = dc.execute()
dct = DockerContainers(self.parent_subtest)
cnts = dct.list_containers()
for cont in cnts:
if cont.image_name == self.sub_stuff['image_list'][0].full_name:
try:
dct.kill_container_by_long_id(cont.long_id)
except ValueError:
pass
dc = DockerCmd(self.parent_subtest, "rm", ["-f", cont.long_id])
rm_results = dc.execute()
self.failif(rm_results.exit_status != 0,
"Non-zero commit exit status: %s"
% rm_results)
self.failif(results.exit_status != 0,
"Non-zero commit exit status: %s"
% results)
self.failif(not self.config['check_results_contain'] in results.stdout,
"Unable to start image with default command: %s"
% results)