本文整理汇总了Python中dockertest.images.DockerImages类的典型用法代码示例。如果您正苦于以下问题:Python DockerImages类的具体用法?Python DockerImages怎么用?Python DockerImages使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DockerImages类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cleanup
def cleanup(self):
super(run_base, self).cleanup()
if self.config['remove_after_test']:
dc = DockerContainers(self)
dc.clean_all(self.sub_stuff.get("containers"))
di = DockerImages(self)
di.clean_all(self.sub_stuff.get("images"))
示例2: cleanup
def cleanup(self):
super(commit_base, self).cleanup()
# Auto-converts "yes/no" to a boolean
if (self.config['remove_after_test'] and
'image_list' in self.sub_stuff):
dkrcmd = DockerCmd(self.parent_subtest, "rm",
['--volumes', '--force',
self.sub_stuff["container"]])
cmdresult = dkrcmd.execute()
msg = (" removed test container: %s" % self.sub_stuff["container"])
if cmdresult.exit_status == 0:
self.loginfo("Successfully" + msg)
else:
self.logwarning("Failed" + msg)
for image in self.sub_stuff["image_list"]:
try:
di = DockerImages(self.parent_subtest)
self.logdebug("Removing image %s", image.full_name)
di.remove_image_by_image_obj(image)
self.loginfo("Successfully removed test image: %s",
image.full_name)
except error.CmdError, e:
error_text = "tagged in multiple repositories"
if not error_text in e.result_obj.stderr:
raise
示例3: initialize
def initialize(self):
super(commit_base, self).initialize()
config.none_if_empty(self.config)
di = DockerImages(self.parent_subtest)
name_prefix = self.config["commit_repo_name_prefix"]
new_img_name = di.get_unique_name(name_prefix)
self.sub_stuff["new_image_name"] = new_img_name
self.sub_stuff['rand_data'] = utils.generate_random_string(8)
cmd_with_rand = (self.config['docker_data_prepare_cmd']
% self.sub_stuff['rand_data'])
fqin = DockerImage.full_name_from_defaults(self.config)
prep_changes = DockerCmd(self.parent_subtest, "run",
["--detach",
fqin,
cmd_with_rand],
self.config['docker_commit_timeout'])
results = prep_changes.execute()
if results.exit_status:
raise xceptions.DockerTestNAError("Problems during "
"initialization of"
" test: %s", results)
else:
self.sub_stuff["container"] = results.stdout.strip()
示例4: initialize
def initialize(self):
super(history_base, self).initialize()
config.none_if_empty(self.config)
dimgs = DockerImages(self.parent_subtest)
self.sub_stuff["containers"] = []
self.sub_stuff["images"] = []
new_img_name = dimgs.get_unique_name('1')
self.sub_stuff["new_image_name"] = new_img_name
new_img_name2 = dimgs.get_unique_name('2')
self.sub_stuff["new_image_name2"] = new_img_name2
self.sub_stuff['rand_data'] = utils.generate_random_string(8)
cmd_with_rand = (self.config['docker_data_prepare_cmd']
% self.sub_stuff['rand_data'])
fqin = DockerImage.full_name_from_defaults(self.config)
# create new image in history
self.create_image(fqin, new_img_name, cmd_with_rand)
self.sub_stuff["images"].append(new_img_name)
# create new image in history
self.create_image(new_img_name, new_img_name2, cmd_with_rand)
self.sub_stuff["images"].append(new_img_name2)
示例5: initialize
def initialize(self):
super(tag_base, self).initialize()
config.none_if_empty(self.config)
di = DockerImages(self.parent_subtest)
di.gen_lower_only = self.config['gen_lower_only']
name_prefix = self.config["tag_repo_name_prefix"]
new_img_name = di.get_unique_name(name_prefix)
while self.check_image_exists(new_img_name):
new_img_name = "%s_%s" % (name_prefix,
utils.generate_random_string(8))
self.sub_stuff["image"] = new_img_name
base_image = DockerImage.full_name_from_defaults(self.config)
prep_changes = DockerCmd(self.parent_subtest, "tag",
[base_image,
self.sub_stuff["image"]],
self.config['docker_tag_timeout'])
results = prep_changes.execute()
if results.exit_status:
raise xceptions.DockerTestNAError("Problems during "
"initialization of"
" test: %s", results)
im = self.check_image_exists(self.sub_stuff["image"])
self.sub_stuff['image_list'] = im
示例6: postprocess
def postprocess(self):
super(info, self).postprocess()
info_table = self.stuff['dockerinfo']
# We support multiple storage drivers. Each one has a different
# set of key/value settings under 'info'; so each one has a
# dedicated helper method for validating.
driver_name = info_table.get('storage_driver')
self.failif(not driver_name, "'docker info' did not return"
" a value for 'Storage Driver'")
self.loginfo("Storage Driver = %s", driver_name)
try:
handler = getattr(self, '_postprocess_' + driver_name.lower())
except AttributeError:
raise DockerTestFail("Unknown storage driver: %s" % driver_name)
handler(info_table.get('storage_driver', {}))
# Count 'docker images', compare to the 'Images' info key.
# Yes, that's unreliable on a busy system. We're not on a busy system.
di = DockerImages(self)
di.images_args = "%s --all" % di.images_args
img_set = set(di.list_imgs_ids()) # don't count multi-tags
img_cnt = int(info_table.get('images'))
self.failif_ne(len(img_set), img_cnt,
"count of 'docker images' vs 'docker info'->Images")
示例7: cleanup
def cleanup(self):
super(import_export_base, self).cleanup()
# Auto-converts "yes/no" to a boolean
if self.config['remove_after_test']:
for cont in self.sub_stuff["containers"]:
dkrcmd = DockerCmd(self, "rm", ['--volumes', '--force', cont])
cmdresult = dkrcmd.execute()
msg = (" removed test container: %s" % cont)
if cmdresult.exit_status == 0:
self.logdebug("Successfully" + msg)
else:
self.logwarning("Failed" + msg)
for image in self.sub_stuff["images"]:
try:
di = DockerImages(self.parent_subtest)
self.logdebug("Removing image %s", image)
di.remove_image_by_full_name(image)
self.logdebug("Successfully removed test image: %s",
image)
except xceptions.DockerCommandError, e:
error_text = "tagged in multiple repositories"
if error_text not in e.result_obj.stderr:
raise
except xceptions.DockerTestError:
pass # best effort removal, maybe image wasn't there
示例8: postprocess
def postprocess(self):
# Raise exception on Go Panic or usage help message
outputgood = OutputGood(self.stuff['cmdresult'])
info_map = self._build_table(outputgood.stdout_strip)
# Verify some individual items
self.failif_ne(info_map['Storage Driver'].lower(), 'devicemapper',
'Storage Driver')
self.failif_ne(info_map['Data file'].lower(), '',
'Data file')
self.failif_ne(info_map['Metadata file'].lower(), '',
'Metadata file')
di = DockerImages(self)
# Make sure nothing is 'hidden'
di.images_args = "%s --all" % di.images_args
# Possible race-condition here...
img_set = set(di.list_imgs_ids()) # don't count multi-tags
# ...with this
img_cnt = int(info_map['Images'].lower())
self.failif_ne(len(img_set), img_cnt,
"More/less images %d than info reported %d"
% (len(img_set), img_cnt))
# verify value of elements
self.verify_pool_name(info_map['Pool Name'])
data_name = 'Data loop file'
metadata_name = 'Metadata loop file'
if data_name in info_map:
self.verify_sizes(info_map[data_name],
info_map['Data Space Used'],
info_map['Data Space Total'],
info_map[metadata_name],
info_map['Metadata Space Used'],
info_map['Metadata Space Total'])
else:
data_name = 'Data file'
metadata_name = 'Metadata file'
示例9: cleanup
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)
示例10: gen_tag
def gen_tag(self):
reponame = self.config['image_repo_name']
postfix = self.config['image_tag_postfix']
di = DockerImages(self)
tag = '%s:%s' % (reponame, di.get_unique_name(suffix=postfix))
tag = tag.lower()
self.stuff['names'].append(tag)
return tag
示例11: initialize
def initialize(self):
super(empty, self).initialize()
di = DockerImages(self.parent_subtest)
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.sub_stuff['image_name_tag'] = image_name_tag
self.sub_stuff['image_name'] = image_name
self.sub_stuff['image_tag'] = image_tag
示例12: initialize
def initialize(self):
super(empty, self).initialize()
di = DockerImages(self)
suffix = self.config.get("image_name_postfix")
image_name_tag = di.get_unique_name(suffix=suffix)
image_name, image_tag = image_name_tag.split(":", 1)
self.sub_stuff["image_name_tag"] = image_name_tag
self.sub_stuff["image_name"] = image_name
self.sub_stuff["image_tag"] = image_tag
示例13: lookup_image_id
def lookup_image_id(self, image_name, image_tag):
di = DockerImages(self.parent_subtest)
fqin = DockerImage.full_name_from_component(image_name, image_tag)
imglst = di.list_imgs_with_full_name(fqin)
try:
# Don't care about duplicate ID's
return imglst[0].long_id
except IndexError:
return None # expected by some sub-subtests
示例14: cleanup
def cleanup(self):
super(build, self).cleanup()
# Auto-converts "yes/no" to a boolean
if (self.config['try_remove_after_test'] and
self.stuff.has_key('image_id')):
di = DockerImages(self)
di.remove_image_by_id(self.stuff['image_id'])
di.remove_image_by_full_name("empty_base_image")
self.loginfo("Successfully removed test images")
else:
self.loginfo("NOT removing image")
示例15: cleanup
def cleanup(self):
super(rmi_base, self).cleanup()
di = DockerImages(self)
# Auto-converts "yes/no" to a boolean
if self.config['remove_after_test']:
dc = DockerContainers(self)
dc.clean_all(self.sub_stuff.get("containers"))
di = DockerImages(self)
imgs = [img.full_name
for img in self.sub_stuff.get("image_list", [])]
di.clean_all(imgs)