本文整理汇总了Python中dockertest.images.DockerImages.get_unique_name方法的典型用法代码示例。如果您正苦于以下问题:Python DockerImages.get_unique_name方法的具体用法?Python DockerImages.get_unique_name怎么用?Python DockerImages.get_unique_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dockertest.images.DockerImages
的用法示例。
在下文中一共展示了DockerImages.get_unique_name方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
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)
示例2: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
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
示例3: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
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: gen_tag
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
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
示例5: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
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
示例6: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
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
示例7: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
def initialize(self):
super(with_blocking_container_by_tag, self).initialize()
rand_data = utils.generate_random_string(5)
self.sub_stuff["rand_data"] = rand_data
di = DockerImages(self.parent_subtest)
name_prefix = self.config["rmi_repo_tag_name_prefix"]
self.sub_stuff["image_name"] = di.get_unique_name(name_prefix)
cmd_with_rand = self.config['docker_data_prepare_cmd'] % (rand_data)
prep_changes = DockerCmd(self, "run",
["-d",
self.parent_subtest.stuff['base_image'],
cmd_with_rand],
self.config['docker_commit_timeout'])
results = prep_changes.execute()
dnamsg = ("Problems during initialization of"
" test: %s", results)
if results.exit_status:
raise DockerTestNAError(dnamsg)
else:
self.sub_stuff["container"] = results.stdout.strip()
self.sub_stuff["containers"].append(self.sub_stuff["container"])
# Private to this instance, outside of __init__
dkrcmd = DockerCmd(self, 'commit',
self.complete_commit_command_line(),
self.config['docker_commit_timeout'])
results = dkrcmd.execute()
if results.exit_status:
raise DockerTestNAError(dnamsg)
prep_changes = DockerCmd(self, "run",
["-d",
self.sub_stuff["image_name"],
cmd_with_rand],
self.config['docker_commit_timeout'])
results = prep_changes.execute()
if results.exit_status:
raise DockerTestNAError(dnamsg)
else:
self.sub_stuff["containers"].append(results.stdout.strip())
im = self.check_image_exists(self.sub_stuff["image_name"])
self.sub_stuff['image_list'] = im
示例8: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
def initialize(self):
super(simple, self).initialize()
# Test container setup
dc = DockerContainers(self)
c_name = dc.get_unique_name()
self.sub_stuff["containers"].append(c_name)
self.init_test_container(c_name)
# export/import command setup
di = DockerImages(self)
i_name = di.get_unique_name(c_name) # easier debugging
self.sub_stuff["images"].append(i_name)
subdct = {"container": c_name, "image": i_name}
export_cmd_args = self.config['export_cmd_args'].strip() % subdct
import_cmd_args = self.config['import_cmd_args'].strip() % subdct
self.init_ei_dockercmd(export_cmd_args, import_cmd_args)
示例9: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [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)
示例10: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
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))
if self.config['gen_lower_only']:
new_img_name = new_img_name.lower()
else:
new_img_name += '_UP' # guarantee some upper-case
self.sub_stuff["image"] = new_img_name
base_image = DockerImage.full_name_from_defaults(self.config)
self.prep_image(base_image)
示例11: initialize
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
def initialize(self):
super(commit_base, self).initialize()
config.none_if_empty(self.config)
di = DockerImages(self)
new_img_name = di.get_unique_name()
cname = DockerContainers(self).get_unique_name()
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, "run", ["--name=%s" % cname, 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)
self.sub_stuff["container"] = cname
示例12: tag_base
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
class tag_base(SubSubtest):
""" tag base class """
def __init__(self, *args, **kwargs):
super(tag_base, self).__init__(*args, **kwargs)
self.dkrimg = DockerImages(self.parent_subtest)
self.sub_stuff['tmp_image_list'] = set()
def get_images_by_name(self, full_name):
""" :return: List of images with given name """
return self.dkrimg.list_imgs_with_full_name(full_name)
def prep_image(self, base_image):
""" Tag the dockertest image to this test name """
NoFailDockerCmd(self, "pull", [base_image], verbose=False).execute()
subargs = [base_image, self.sub_stuff["image"]]
tag_results = DockerCmd(self, "tag", subargs, verbose=False).execute()
if tag_results.exit_status:
raise xceptions.DockerTestNAError("Problems during "
"initialization of"
" test: %s", tag_results)
img = self.get_images_by_name(self.sub_stuff["image"])
self.failif(not img, "Image %s was not created."
% self.sub_stuff["image"])
self.sub_stuff['image_list'] = img
def initialize(self):
super(tag_base, self).initialize()
config.none_if_empty(self.config)
self.dkrimg.gen_lower_only = self.config['gen_lower_only']
new_img_name = self.dkrimg.get_unique_name()
self.sub_stuff["image"] = new_img_name
base_image = DockerImage.full_name_from_defaults(self.config)
self.prep_image(base_image)
def complete_docker_command_line(self):
""" :return: tag subargs using new_image_name """
force = self.config["tag_force"]
cmd = []
if force:
cmd.append("-f")
cmd.append(self.sub_stuff["image"])
cmd.append(self.sub_stuff["new_image_name"])
self.sub_stuff["tag_cmd"] = cmd
return cmd
def run_once(self):
super(tag_base, self).run_once()
subargs = self.complete_docker_command_line()
self.sub_stuff["cmdresult"] = DockerCmd(self, 'tag', subargs).execute()
def postprocess(self):
super(tag_base, self).postprocess()
if self.config["docker_expected_result"] == "PASS":
# Raise exception if problems found
OutputGood(self.sub_stuff['cmdresult'])
self.failif(self.sub_stuff['cmdresult'].exit_status != 0,
"Non-zero tag exit status: %s"
% self.sub_stuff['cmdresult'])
img = self.get_images_by_name(self.sub_stuff["new_image_name"])
# Needed for cleanup
self.sub_stuff['image_list'] += img
self.failif(len(img) < 1,
"Failed to look up tagted image ")
elif self.config["docker_expected_result"] == "FAIL":
chck = OutputGood(self.sub_stuff['cmdresult'], ignore_error=True)
exit_code = self.sub_stuff['cmdresult'].exit_status
self.failif(not chck or not exit_code,
"Zero tag exit status: Command should fail due to"
" wrong command arguments.")
else:
self.failif(True, "Improper 'docker_expected_result' value %s"
% self.config["docker_expected_result"])
def cleanup(self):
super(tag_base, self).cleanup()
# Auto-converts "yes/no" to a boolean
if self.config['remove_after_test'] and 'image_list' in self.sub_stuff:
for image in self.sub_stuff["image_list"]:
self.logdebug("Removing image %s", image.full_name)
try:
self.dkrimg.remove_image_by_full_name(image.full_name)
except error.CmdError, exc:
err = exc.result_obj.stderr
if "tagged in multiple repositories" not in err:
raise
self.loginfo("Successfully removed test image: %s",
image.full_name)
for image in self.sub_stuff['tmp_image_list']:
image = self.get_images_by_name(image)
if image:
self.logdebug("Removing image %s", image[0].full_name)
self.dkrimg.remove_image_by_full_name(image[0].full_name)
self.loginfo("Successfully removed test image: %s",
#.........这里部分代码省略.........
示例13: tag_base
# 需要导入模块: from dockertest.images import DockerImages [as 别名]
# 或者: from dockertest.images.DockerImages import get_unique_name [as 别名]
class tag_base(SubSubtest):
""" tag base class """
def __init__(self, *args, **kwargs):
super(tag_base, self).__init__(*args, **kwargs)
self.dkrimg = DockerImages(self)
self.sub_stuff['tmp_image_list'] = set()
self._expect_pass = True
def expect_pass(self, set_to=None):
"""
Most of the time we expect our 'docker tag' command to succeed.
This method can be used (as a setter) to set an explicit expectation
or (as a getter) when checking results.
"""
if set_to is not None:
self._expect_pass = set_to
return self._expect_pass
def get_images_by_name(self, full_name):
""" :return: List of images with given name """
return self.dkrimg.list_imgs_with_full_name(full_name)
def prep_image(self, base_image):
""" Tag the dockertest image to this test name """
mustpass(DockerCmd(self, "pull", [base_image]).execute())
subargs = [base_image, self.sub_stuff["image"]]
tag_results = DockerCmd(self, "tag", subargs).execute()
if tag_results.exit_status:
raise xceptions.DockerTestNAError("Problems during "
"initialization of"
" test: %s", tag_results)
img = self.get_images_by_name(self.sub_stuff["image"])
self.failif(not img, "Image %s was not created."
% self.sub_stuff["image"])
self.sub_stuff['image_list'] = img
def initialize(self):
super(tag_base, self).initialize()
config.none_if_empty(self.config)
self.dkrimg.gen_lower_only = self.config['gen_lower_only']
new_img_name = self.dkrimg.get_unique_name()
self.sub_stuff["image"] = new_img_name
base_image = DockerImage.full_name_from_defaults(self.config)
self.prep_image(base_image)
def complete_docker_command_line(self):
""" :return: tag subargs using new_image_name """
cmd = []
if 'force_tag' in self.sub_stuff and self.sub_stuff['force_tag']:
cmd.append("-f")
cmd.append(self.sub_stuff["image"])
cmd.append(self.sub_stuff["new_image_name"])
self.sub_stuff["tag_cmd"] = cmd
return cmd
def run_once(self):
super(tag_base, self).run_once()
subargs = self.complete_docker_command_line()
self.sub_stuff["cmdresult"] = DockerCmd(self, 'tag', subargs).execute()
def postprocess(self):
super(tag_base, self).postprocess()
expect_pass = self.expect_pass()
OutputGood(self.sub_stuff['cmdresult'], ignore_error=not expect_pass)
if expect_pass:
# Raise exception if problems found
self.failif_ne(self.sub_stuff['cmdresult'].exit_status, 0,
"Non-zero tag exit status: %s"
% self.sub_stuff['cmdresult'])
img = self.get_images_by_name(self.sub_stuff["new_image_name"])
# Needed for cleanup
self.sub_stuff['image_list'] += img
self.failif(len(img) < 1,
"Failed to look up tagged image ")
else:
self.failif(self.sub_stuff['cmdresult'].exit_status == 0,
"Was expecting tag command to fail, but it exited OK")
def cleanup(self):
super(tag_base, self).cleanup()
# Auto-converts "yes/no" to a boolean
if self.config['remove_after_test'] and 'image_list' in self.sub_stuff:
for image in self.sub_stuff["image_list"]:
self.logdebug("Removing image %s", image.full_name)
try:
self.dkrimg.remove_image_by_full_name(image.full_name)
except error.CmdError, exc:
err = exc.result_obj.stderr
if "tagged in multiple repositories" not in err:
raise
self.loginfo("Successfully removed test image: %s",
image.full_name)
for image_name in self.sub_stuff['tmp_image_list']:
image = self.get_images_by_name(image_name)
#.........这里部分代码省略.........