def initialize(self): super(history_base, self).initialize() config.none_if_empty(self.config) dimgs = DockerImages(self) 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)
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
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)
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)
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")
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
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'
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"))
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
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()
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")
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'
def cleanup(self): super(history_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"))
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
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
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
def lookup_image_id(self, image_name, image_tag): di = DockerImages(self) 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
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
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
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)
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")
def cleanup(self): super(pull_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"]: try: di = DockerImages(self.parent_subtest) di.remove_image_by_image_obj(image) self.loginfo("Successfully removed test image") except error.CmdError: self.logwarning("Image not exist.")
def cleanup(self): super(exec_base, self).cleanup() for ifd in self.sub_stuff['fds']: try: os.close(ifd) except OSError: pass 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"))
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
def cleanup(self): super(build, self).cleanup() # Auto-converts "yes/no" to a boolean if self.config['try_remove_after_test']: dc = DockerContainers(self) for cid in dc.list_container_ids(): dcmd = DockerCmd(self, 'rm', ['--force', '--volumes', cid]) dcmd.execute() di = DockerImages(self) if self.stuff.get('image_id') is not None: 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")
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)
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"]: di = DockerImages(self.parent_subtest) self.logdebug("Removing image %s", image.full_name) try: di.remove_image_by_full_name(image.full_name) except error.CmdError, e: err = e.result_obj.stderr if "tagged in multiple repositories" not in err: raise self.loginfo("Successfully removed test image: %s", image.full_name)
def cleanup(self): super(login_base, self).cleanup() if 'my_containers' in self.sub_stuff: DockerContainers(self).clean_all(self.sub_stuff['my_containers']) if 'my_images' in self.sub_stuff: DockerImages(self).clean_all(self.sub_stuff['my_images']) self._restore_docker_auth_file()
def clean_all(self): di = self.sub_stuff['di'] flbc = di.filter_list_by_components image_list = flbc(di.list_imgs(), repo=self.config['docker_repo_name']) remove = [img.full_name for img in image_list] DockerImages(self).clean_all(remove)
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)
def initialize(self): super(build, self).initialize() self.stuff['dc'] = dcont = DockerContainers(self) self.stuff['existing_containers'] = dcont.list_container_ids() self.stuff['di'] = dimg = DockerImages(self) self.stuff['existing_images'] = ei = dimg.list_imgs() self.logdebug("Existing images: %s", ei)
def cleanup(self): super(attach_base, self).cleanup() if self.config['remove_after_test']: dc = self.sub_stuff["cont"] di = di = DockerImages(self) dc.clean_all(self.sub_stuff["containers"]) di.clean_all(self.sub_stuff["images"])
def postprocess(self): super(systemd_base, self).postprocess() image_name = self.config['image_name'] all_images = DockerImages(self).list_imgs() for img_obj in all_images: if img_obj.cmp_greedy(repo=image_name, tag="latest"): return
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) self.sub_stuff["image_name"] = di.get_unique_name(":tag") 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']) dnamsg = ("Problems during initialization of" " test: %s") prep_changes.execute() if prep_changes.cmdresult.exit_status: raise DockerTestNAError(dnamsg % prep_changes.cmdresult) else: self.sub_stuff["container"] = prep_changes.cmdresult.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']) dkrcmd.execute() if dkrcmd.cmdresult.exit_status: raise DockerTestNAError(dnamsg % dkrcmd.cmdresult) args = ["-d", self.sub_stuff["image_name"], cmd_with_rand] prep_changes = DockerCmd(self, "run", args, self.config['docker_commit_timeout']) prep_changes.execute() if prep_changes.cmdresult.exit_status: raise DockerTestNAError(dnamsg % dkrcmd.cmdresult) else: prep_stdout = prep_changes.cmdresult.stdout.strip() self.sub_stuff["containers"].append(prep_stdout) im = self.check_image_exists(self.sub_stuff["image_name"]) self.sub_stuff['image_list'] = im
def initialize(self): super(images_all_base, self).initialize() # Prepare a container config.none_if_empty(self.config) self.sub_stuff['dc'] = DockerContainers(self) self.sub_stuff['di'] = DockerImages(self) self.sub_stuff['containers'] = [] self.sub_stuff['images'] = []
def initialize_utils(self): # Get the latest container (remove all newly created in cleanup self.sub_stuff['dc'] = DockerContainers(self) self.sub_stuff['di'] = DockerImages(self) pec = self.parent_subtest.stuff['existing_containers'] self.sub_stuff['existing_containers'] = pec pei = self.parent_subtest.stuff['existing_images'] self.sub_stuff['existing_images'] = pei
def postprocess(self): super(build, self).postprocess() # Raise exception if problems found OutputGood(self.stuff['cmdresult']) self.failif(self.stuff['cmdresult'].exit_status != 0, "Non-zero build exit status: %s" % self.stuff['cmdresult']) image_name = self.stuff['image_name'] image_tag = self.stuff['image_tag'] di = DockerImages(self) imgs = di.list_imgs_with_full_name_components(repo=image_name, tag=image_tag) self.failif(len(imgs) < 1, "Test image build result was not found") self.stuff['image_id'] = imgs[0].long_id # assume first one is match self.failif(self.stuff['image_id'] is None, "Failed to look up image ID from build") self.loginfo("Found image: %s", imgs[0].full_name)
def initialize(self): super(delete_wrong_name, self).initialize() rand_data = utils.generate_random_string(5).lower() self.sub_stuff["rand_data"] = rand_data im_name = DockerImages(self).get_unique_name() self.sub_stuff["image_name"] = im_name
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)
def postprocess(self): super(systemd_base, self).postprocess() image_name = self.config['image_name'] all_images = DockerImages(self).list_imgs() for img_obj in all_images: if img_obj.cmp_greedy(repo=image_name, tag="latest"): return raise DockerTestError("Image %s:latest not found among %s" % (image_name, [i.full_name for i in all_images]))
def initialize(self): super(CpBase, self).initialize() set_selinux_context(self.tmpdir) dc = self.sub_stuff['dc'] = DockerContainers(self) self.sub_stuff['di'] = DockerImages(self) container_name = dc.get_unique_name() self.sub_stuff['container_name'] = container_name fqin = DockerImage.full_name_from_defaults(self.config) self.sub_stuff['fqin'] = fqin
def postprocess(self): super(pull_base, self).postprocess() self.outputcheck() if self.config["docker_expected_result"] == "PASS": self.failif(self.sub_stuff['cmdresult'].exit_status != 0, "Non-zero pull exit status: %s" % self.sub_stuff['cmdresult']) di = DockerImages(self.parent_subtest) image_list = di.list_imgs_with_full_name(self.sub_stuff["img_fn"]) self.sub_stuff['image_list'] = image_list self.failif(self.sub_stuff['image_list'] == [], "Failed to look up image ") elif self.config["docker_expected_result"] == "FAIL": self.failif(self.sub_stuff['cmdresult'].exit_status == 0, "Zero pull exit status: Command should fail due to" " wrong command arguments.")
def initialize(self): super(docker_test_images, self).initialize() self.stuff['di'] = di = DockerImages(self) extra_fqins_csv = self.config.get('extra_fqins_csv', '') update_defaults_ini = self.config.get('update_defaults_ini', False) self.stuff['defaults_ini'] = os.path.join(CONFIGCUSTOMS, 'defaults.ini') defaults_ini_exists = os.path.isfile(self.stuff['defaults_ini']) self.stuff['update'] = update_defaults_ini and defaults_ini_exists self.stuff['fqins'] = [di.default_image] + get_as_list(extra_fqins_csv)
def cleanup(self): super(systemd_base, self).cleanup() try: self.sysd_action('stop', self.config['sysd_unit_file']) except OSError: pass finally: unlink(self.sub_stuff['unitfile_dst']) self.sysd_action('daemon-reload') DockerImages(self).clean_all([self.config['image_name']])
def initialize(self): super(pull_base, self).initialize() self.sub_stuff['di'] = DockerImages(self) image_fn = self.init_image_fn() # set by run_once() self.sub_stuff['image_list'] = [] dkrcmd = AsyncDockerCmd(self, 'pull', [image_fn]) dkrcmd.quiet = False self.sub_stuff['dkrcmd'] = dkrcmd self.clean_all()
def initialize_cmdline(self): subargs = ['--rm', '-v', '%s:/x:Z' % self.tmpdir] for key, value in self.sub_stuff['envd'].items(): subargs.append("-e") subargs.append("%s=%s" % (key, value)) subargs.append(DockerImages(self).default_image) subargs.append("bash -c 'env > /x/env.output'") _ = DockerCmd(self, 'run', subargs) _.quiet = True self.sub_stuff['dkrcmd'] = _
def run_once(self): super(pull_base, self).run_once() dkrcmd = self.sub_stuff['dkrcmd'] self.loginfo("Executing background pull...") dkrcmd.execute() while not dkrcmd.done: self.loginfo("Pulling...") time.sleep(3) if dkrcmd.exit_status is not None: break self.sub_stuff['image_list'] = DockerImages(self).list_imgs()
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
def initialize(self): super(base, self).initialize() dc = self.sub_stuff['dc'] = DockerContainers(self) di = self.sub_stuff['di'] = DockerImages(self) import_repo = di.get_unique_name() run_name = dc.get_unique_name() self.sub_stuff['run_name'] = run_name self.sub_stuff['import_repo'] = import_repo self.sub_stuff['import_cmdresult'] = None self.run_import() self.sub_stuff['run_cid'] = None self.run_image()
def cleanup(self): super(commit_base, self).cleanup() if self.config['remove_after_test']: dc = DockerContainers(self) container = self.sub_stuff.get("container") if container: dc.clean_all([container]) di = di = DockerImages(self) images = [ img.full_name for img in self.sub_stuff.get("image_list", []) ] di.clean_all(images)
def run_once(self): fqin = self.sub_stuff['fqin'] di = DockerImages(self.parent_subtest) try: di.remove_image_by_full_name(fqin) except error.CmdError: pass # removal was the goal images = di.list_imgs_with_full_name(fqin) if images != []: error.TestNAError("Unable to prepare env for test:" " image %s already/still" " exist in docker repository", fqin) self.logdebug("Existing images: %s", di.list_imgs_full_name()) self.loginfo("Executing test commands") self.run_command('run', self.sub_stuff['subargs'], 'cmdresult_run1') self.run_command('rm', [self.sub_stuff["rand_name"]], 'cmdresult_rm') self.run_command('tag', [fqin, self.sub_stuff["rand_name"].lower()], 'cmdresult_tag') self.run_command('rmi', [fqin], 'cmdresult_rmi') self.run_command('run', self.sub_stuff['subargs'], 'cmdresult_run2') self.run_command('rm', [self.sub_stuff["rand_name"]], 'cmdresult_rm2') self.run_command('rmi', [self.sub_stuff["rand_name"].lower()], 'cmdresult_rmi2')
def cleanup(self): super(rmi_base, self).cleanup() di = DockerImages(self.parent_subtest) # Auto-converts "yes/no" to a boolean if (self.config['remove_after_test'] and 'image_list' in self.sub_stuff): for cont in self.sub_stuff["containers"]: clean_cont = NoFailDockerCmd(self, "rm", ['--force', cont], self.config['docker_rmi_timeout']) clean_cont.execute() for image in self.sub_stuff["image_list"]: # If removal by name fails, try id try: try: di.remove_image_by_full_name(image.full_name) except DockerCommandError: di.remove_image_by_id(image.long_id) except DockerCommandError: self.logwarning("Image not exist or failed" " to remove image.") self.loginfo("Successfully removed test image")
def initialize(self): super(run_base, self).initialize() self.sub_stuff['fqin'] = '' self.sub_stuff['dkrcmd'] = None self.sub_stuff['stdin'] = None self.sub_stuff['subargs'] = [] self.sub_stuff["containers"] = [] self.sub_stuff["images"] = [] self.sub_stuff["cont"] = DockerContainers(self) self.sub_stuff["img"] = DockerImages(self) self.init_image() self.init_subargs() self.init_dockercmd()
def initialize(self): super(docker_test_images, self).initialize() # Keep it simple, just use/store everything in this instance self.stuff['di'] = di = DockerImages(self) extra_fqins_csv = self.config.get('extra_fqins_csv', '') update_defaults_ini = self.config.get('update_defaults_ini', False) self.stuff['defaults_ini'] = os.path.join(CONFIGCUSTOMS, 'defaults.ini') defaults_ini_exists = os.path.isfile(self.stuff['defaults_ini']) self.stuff['update'] = update_defaults_ini and defaults_ini_exists self.stuff['fqins'] = [di.default_image] + get_as_list(extra_fqins_csv) # Optional, could be {None: None} self.stuff['build'] = {self.config.get('build_name'): self.config.get('build_dockerfile')}
def initialize(self): super(exec_base, self).initialize() self.sub_stuff['containers'] = [] self.sub_stuff['images'] = [] self.sub_stuff['cont'] = DockerContainers(self) self.sub_stuff['img'] = DockerImages(self) self.sub_stuff['fds'] = [] # every fd in here guarantee closed self.sub_stuff['dkrcmd_stdin'] = None # stdin fd for vvvvvvv self.sub_stuff['run_name'] = None # container name for vvvvvvv self.sub_stuff['run_args'] = [] # parameters for vvvvvv self.sub_stuff['dkrcmd'] = None # docker run ... container self.sub_stuff['exec_args'] = [] # parameters for vvvvvv self.sub_stuff['dkrcmd_exec'] = None # docker exec ... container self.init_subargs() self.start_base_container()
def initialize(self): super(commit_base, self).initialize() config.none_if_empty(self.config) di = DockerImages(self) new_img_name = di.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", ["--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()
def image_exist(self, image_name): di = DockerImages(self) image_list = di.get_dockerimages_list() exist_status = DockerImages.filter_list_full_name(image_list, image_name) return exist_status
def cleanup(self): super(with_blocking_container_by_id, self).cleanup() di = DockerImages(self) di.clean_all([self.sub_stuff["image_name"]])