def initialize(self): """ 1) Generate list of random $names and $repeat_count number of `docker load` commands associated to them 2) Run container for each name which saves the $name to a file 3) Commit the container to $name image 4) Remove the container """ super(stressed_load, self).initialize() # Generate $count random unique nonexisting image names self.sub_stuff['load_cmds'] = [] # tuple(name, dkrcmd) self.sub_stuff['cmdresults_save'] = [] # results of dkr save self.sub_stuff['cmdresults_del'] = [] # resutls of dkr rmi self.sub_stuff['cmdresults_load'] = [] # tuple(name, dkr load result) rand_names = [] while len(rand_names) < self.config['image_count']: name = utils.generate_random_string(8).lower() if (name not in rand_names and not os.path.exists(os.path.join(self.tmpdir, name))): rand_names.append(name) subargs = [self.config['load_cmd'] % {"image": name, "tmpdir": self.tmpdir}] for _ in xrange(self.config['repeat_count']): load_cmd = DockerCmd(self, 'load', subargs) self.sub_stuff['load_cmds'].append((name, load_cmd)) random.shuffle(self.sub_stuff['load_cmds']) # randomize the order self.sub_stuff['rand_names'] = rand_names for rand_name in rand_names: self.sub_stuff['containers'].append(rand_name) self.sub_stuff["images"].append(rand_name) cmd = "sh -c 'echo TEST: %s > /test_file'" % rand_name dkrcmd, name = self._init_container(rand_name, cmd) self.sub_stuff['containers'].append(name) cmdresult = dkrcmd.execute() if cmdresult.exit_status != 0: error.TestNAError("Unable to prepare env for test: %s" % (cmdresult)) cid = self.sub_stuff["cont"].list_containers_with_name(rand_name) self.failif(cid == [], "Unable to search container with name %s: details :%s" % (rand_name, cmdresult)) dkrcmd = DockerCmd(self, 'commit', [rand_name, rand_name]) cmdresult = dkrcmd.execute() if cmdresult.exit_status != 0: error.TestNAError("Unable to prepare env for test: %s" % (cmdresult)) dkrcmd = DockerCmd(self, 'rm', [rand_name]) cmdresult = dkrcmd.execute() if cmdresult.exit_status != 0: error.TestNAError("Failed to cleanup env for test: %s" % (cmdresult))
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 _init_container_attached(self, name): if self.sub_stuff.get('run_options_csv'): subargs = [arg for arg in self.sub_stuff['run_options_csv'].split(',')] else: subargs = [] subargs.append("--name %s" % name) fin = DockerImage.full_name_from_defaults(self.config) subargs.append(fin) subargs.append("bash") subargs.append("-c") subargs.append(self.config['exec_cmd']) container = DockerCmd(self, 'run', subargs) self.sub_stuff['container_cmd'] = container mustpass(container.execute()) if self.sub_stuff.get('attach_options_csv'): subargs = [arg for arg in self.sub_stuff['attach_options_csv'].split(',')] else: subargs = [] subargs.append(name) c_attach = AsyncDockerCmd(self, 'attach', subargs) self.sub_stuff['container_cmd'] = c_attach # overwrites finished cmd c_attach.execute()
def run_once(self): super(events, self).run_once() dc = self.stuff['dc'] # Start listening self.stuff['events_cmd'].execute() # Do something to make new events cmdresult = mustpass(self.stuff['nfdc'].execute()) cid = self.stuff['nfdc_cid'] = cmdresult.stdout.strip() while True: _json = dc.json_by_long_id(cid) if len(_json) > 0 and _json[0]["State"]["Running"]: self.loginfo("Waiting for test container to exit...") time.sleep(3) else: break if self.config['rm_after_run']: self.loginfo("Removing test container...") try: dc.kill_container_by_long_id(cid) except ValueError: pass # container isn't running, this is fine. dcmd = DockerCmd(self, 'rm', ['--force', '--volumes', cid]) mustpass(dcmd.execute()) # No way to know how long async events take to pass through :S self.loginfo("Sleeping %s seconds for events to catch up", self.config['wait_stop']) time.sleep(self.config['wait_stop']) # Kill off docker events after 1 second events_cmd = self.stuff['events_cmd'] self.stuff['events_cmdresult'] = events_cmd.wait(timeout=1)
def initialize(self): super(long_term_app, self).initialize() kill_cmd = DockerCmd(self, "kill", [self.sub_stuff["container"].long_id], self.config["docker_run_timeout"]) results = kill_cmd.execute() if results.exit_status: raise error.TestNAError("Problems during initialization of" " test: %s", results)
def cleanup(self): super(run_memory_base, self).cleanup() if self.config['remove_after_test']: for name in self.sub_stuff.get('name', []): self.logdebug("Cleaning up %s", name) dcmd = DockerCmd(self, 'rm', ['--force', name]) dcmd.execute()
def initialize(self): super(simple, self).initialize() rand_name = utils.generate_random_string(8).lower() self.sub_stuff["rand_name"] = rand_name self.sub_stuff['containers'].append(rand_name) self.sub_stuff["images"].append(rand_name) dkrcmd = self._init_container(rand_name, self.config['docker_data_prep_cmd'])[0] cmdresult = dkrcmd.execute() if cmdresult.exit_status != 0: error.TestNAError("Unable to prepare env for test: %s" % (cmdresult)) rand_name = self.sub_stuff["rand_name"] cid = self.sub_stuff["cont"].list_containers_with_name(rand_name) self.failif(cid == [], "Unable to search container with name %s: details :%s" % (rand_name, cmdresult)) dkrcmd = DockerCmd(self, 'commit', [rand_name, rand_name]) cmdresult = dkrcmd.execute() if cmdresult.exit_status != 0: error.TestNAError("Unable to prepare env for test: %s" % (cmdresult)) dkrcmd = DockerCmd(self, 'rm', [rand_name]) cmdresult = dkrcmd.execute() if cmdresult.exit_status != 0: error.TestNAError("Failed to cleanup env for test: %s" % (cmdresult))
def _init_container_attached(self, name): """ Starts detached container and attaches it using docker attach """ if self.config.get('run_options_csv'): subargs = [arg for arg in self.config['run_options_csv'].split(',')] else: subargs = [] if self.tty: subargs.append('--tty=true') else: subargs.append('--tty=false') subargs.append("--name %s" % name) fin = DockerImage.full_name_from_defaults(self.config) subargs.append(fin) subargs.append("bash") subargs.append("-c") subargs.append(self.config['exec_cmd']) container = DockerCmd(self, 'run', subargs) self.sub_stuff['container_cmd'] = container mustpass(container.execute()) if self.config.get('attach_options_csv'): subargs = [arg for arg in self.config['attach_options_csv'].split(',')] else: subargs = [] subargs.append(name) container = AsyncDockerCmd(self, 'attach', subargs) self.sub_stuff['container_cmd'] = container # overwrites finished cmd container.execute()
def _init_container_attached(self, name): """ Starts detached container and attaches it using docker attach """ if self.config.get("run_options_csv"): subargs = [arg for arg in self.config["run_options_csv"].split(",")] else: subargs = [] if self.tty: subargs.append("--tty=true") else: subargs.append("--tty=false") subargs.append("--name %s" % name) fin = DockerImage.full_name_from_defaults(self.config) subargs.append(fin) subargs.append("bash") subargs.append("-c") subargs.append(self.config["exec_cmd"]) container = DockerCmd(self, "run", subargs, verbose=False) self.sub_stuff["container_cmd"] = container mustpass(container.execute()) if self.config.get("attach_options_csv"): subargs = [arg for arg in self.config["attach_options_csv"].split(",")] else: subargs = [] subargs.append(name) container = AsyncDockerCmd(self, "attach", subargs, verbose=False) self.sub_stuff["container_cmd"] = container # overwrites finished cmd container.execute()
def run_once(self): super(inspect_container_simple, self).run_once() subargs = [self.sub_stuff['name']] nfdc = DockerCmd(self, "inspect", subargs) self.sub_stuff['cmdresult'] = mustpass(nfdc.execute()) # Log details when command is successful self.logdebug(nfdc.cmdresult)
def run_once(self): super(memory_base, self).run_once() memory_containers = self.sub_stuff['memory_containers'] for subargs in self.sub_stuff['subargs']: dkrcmd = DockerCmd(self, 'run -d -i', subargs) dkrcmd.execute() memory_containers.append(dkrcmd)
def wait_for_container_death(self, container_obj): cont_id = container_obj.long_id prep_changes = DockerCmd(self, "wait", [cont_id], self.config['docker_run_timeout']) results = prep_changes.execute() return results.exit_status
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 run_once(self): super(every_last, self).run_once() total = len(self.sub_stuff["lastfiles"]) self.sub_stuff["expected_total"] = total self.failif( total < self.config["max_files"], "Max files number expected : %d," "exceeds container total has : %d" % (self.config["max_files"], total), ) self.loginfo("Testing copy of %d files from container" % total) self.sub_stuff["results"] = {} # cont_path -> cmdresult nfdc = DockerCmd(self, "cp") nfdc.quiet = True nfiles = 0 for index, srcfile in enumerate(self.sub_stuff["lastfiles"]): if index % 100 == 0: self.loginfo("Copied %d of %d", nfiles, total) cont_path = "%s:%s" % (self.sub_stuff["container_name"], srcfile) host_path = self.tmpdir host_fullpath = os.path.join(host_path, os.path.basename(srcfile)) nfdc.subargs = [cont_path, host_path] mustpass(nfdc.execute()) self.failif(not os.path.isfile(host_fullpath), "Not a file: '%s'" % host_fullpath) nfiles += 1 self.sub_stuff["nfiles"] = nfiles if nfiles >= self.config["max_files"]: self.loginfo("Configuration max %d, Copied %d of %d" % (self.config["max_files"], nfiles, total)) break
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(only_tag, self).initialize() name_prefix = self.config["rmi_repo_tag_name_prefix"] rand_data = utils.generate_random_string(5).lower() self.sub_stuff["rand_data"] = rand_data im_name = "%s_%s" % (name_prefix, rand_data) im = self.check_image_exists(im_name) while im != []: rand_data = utils.generate_random_string(5).lower() self.sub_stuff["rand_data"] = rand_data im_name = "%s_%s" % (name_prefix, rand_data) im = self.check_image_exists(im_name) self.sub_stuff["image_name"] = im_name # Private to this instance, outside of __init__ prep_changes = DockerCmd(self, "tag", [self.parent_subtest.stuff["base_image"], self.sub_stuff["image_name"]], self.config['docker_rmi_timeout']) results = prep_changes.execute() if results.exit_status: raise DockerTestNAError("Problems during initialization of" " test: %s", results)
def cleanup(self): super(inspect_base, self).cleanup() if self.config['remove_after_test'] and self.sub_stuff['containers']: dkrcmd = DockerCmd(self.parent_subtest, 'rm', self.sub_stuff['containers']) dkrcmd.execute()
def filedir_contents_postprocess(self, build_def, command, parameter): bad_command = [command.find('file_exist') < 0, command.find('dir_exist') < 0, command.find('rx_file') < 0] if all(bad_command): raise DockerTestError('Command error: %s' % command) positive = command[0] != '!' # Need a character unlikely in file name params = get_as_list(parameter, ':') path = params[0] try: regex = re.compile(''.join(params[1:])) except IndexError: # parameter not specified regex = None # Only cmd differs between all commands (file, dir, rx). if command.find('file') > -1: cmd = 'cat "%s"' % path else: cmd = 'ls -la "%s"' % path subargs = ['--rm', '--attach', 'stdout', build_def.image_name, cmd] dkrcmd = DockerCmd(self, 'run', subargs) dkrcmd.quiet = True dkrcmd.execute() exists = dkrcmd.exit_status == 0 self.logdebug('%s(%s) exists: %s', command, path, exists) if command.find('exist') > -1: return positive == exists if not exists: return False # guaranteed failure, don't bother searching contents = dkrcmd.stdout.strip() mobj = regex.search(contents) self.logdebug('%s(%s) matches: %s', command, regex.pattern, bool(mobj)) return positive == bool(mobj)
def cleanup(self): super(diff_base, self).cleanup() if self.config['remove_after_test']: dkrcmd = DockerCmd(self.parent_subtest, 'rm', [self.sub_stuff['name']]) dkrcmd.execute()
def initialize(self): super(commit_base, self).initialize() config.none_if_empty(self.config) name_prefix = self.config["commit_repo_name_prefix"] new_img_name = "%s_%s" % (name_prefix, utils.generate_random_string(8)) 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 initialize(self): super(short_term_app, self).initialize() docker_name = DockerImage.full_name_from_component( self.config["docker_repo_name"], self.config["docker_repo_tag"]) # Private to this instance, outside of __init__ prep_changes = DockerCmd(self, "run", ["-d", docker_name, self.config["run_cmd"]], self.config['docker_run_timeout']) results = prep_changes.execute() if results.exit_status: raise error.TestNAError("Problems during initialization of" " test: %s" % results) else: c_id = results.stdout.strip() cont = self.sub_stuff["conts_obj"].list_containers_with_cid(c_id) if cont == []: raise error.TestNAError("Problems during initialization of" " test: Failed to find container with" "id %s." % c_id) self.sub_stuff["container"] = cont[0] self.sub_stuff["containers"].append(self.sub_stuff["container"]) if self.check_if_cmd_finished: self.wait_for_container_death(cont[0])
def create_image(self, old_name, new_name, cmd): prep_changes = DockerCmd(self.parent_subtest, "run", ["--name=%s" % new_name, old_name, cmd], self.config['docker_history_timeout']) results = prep_changes.execute() if results.exit_status: raise xceptions.DockerTestNAError("Problems during " "initialization of" " test: %s", results) else: self.sub_stuff["containers"].append(new_name) prep_changes = DockerCmd(self.parent_subtest, "commit", [new_name, new_name], self.config['docker_history_timeout']) results = prep_changes.execute() if results.exit_status: raise xceptions.DockerTestNAError("Problems during " "initialization of" " test: %s", results)
def initialize(self): super(systemd, self).initialize() unit_file_srcpath = '{}{}'.format(self.bindir, '/p4321.service') shutil.copyfile(unit_file_srcpath, self.config['sysd_unitf_dest']) dkrcmd = DockerCmd(self, 'build', ['--force-rm -t', self.config['name'], self.bindir]) mustpass(dkrcmd.execute())
def run_command(self, cmd, subargs, cmd_name): dkrcmd = DockerCmd(self.parent_subtest, cmd, subargs, timeout=self.config['docker_timeout']) self.loginfo(dkrcmd.command) result = dkrcmd.execute() self.sub_stuff[cmd_name] = result self.logdebug("Command %s: %s" % (cmd_name, result))
def cleanup(self): super(empty, self).cleanup() if self.parent_subtest.config['try_remove_after_test']: dkrcmd = DockerCmd(self, 'rmi', [self.sub_stuff['image_name_tag']]) cmdresult = dkrcmd.execute() if cmdresult.exit_status != 0: self.logwarning("Cleanup command failed: %s" % cmdresult)
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)
def cleanup(self): # Call empty parent's cleanup, not empty's. super(empty, self).cleanup() # pylint: disable=E1003 # Fail test if **successful** image_name = self.sub_stuff['image_name'] # assume id lookup failed if self.parent_subtest.config['remove_after_test']: dkrcmd = DockerCmd(self, 'rmi', [image_name]) mustfail(dkrcmd.execute())
def cleanup(self): super(run_memory_base, self).cleanup() if self.config['expect_success'] == "PASS": if self.config['remove_after_test']: for name in self.sub_stuff['name']: dcmd = DockerCmd(self.parent_subtest, 'rm', ['--force', name]) dcmd.execute()
def remove_lock_container(self): prep_changes = DockerCmd(self, "rm", [self.sub_stuff["container"]], self.config['docker_rmi_timeout']) results = prep_changes.execute() if results.exit_status: raise DockerTestNAError("Problems during initialization of" " test: %s", results)
def run_once(self): super(syslog, self).run_once() subargs = [self.stuff['name'], self.stuff['params'], self.stuff['fin'], self.stuff['testcmds']] nfdc = DockerCmd(self, "run", subargs) self.stuff['cmdresults'] = mustpass(nfdc.execute())
def run_once(self): super(iptable_base, self).run_once() subargs = self.sub_stuff['subargs'] mustpass(DockerCmd(self, 'run -d', subargs).execute()) self.sub_stuff['rules_during'] = self.read_iptable_rules(None)
def init_run_dkrcmd(self): subargs = self.sub_stuff['run_options'] subargs += [self.sub_stuff['fqin'], self.COMMAND] return DockerCmd(self, 'run', subargs)
def cleanup(self): super(psa, self).cleanup() cid = self.stuff.get('container_id') if self.config['remove_after_test'] and cid is not None: self.logdebug("Cleaning container %s", cid) DockerCmd(self, "rm", ['--force', '--volumes', cid]).execute()
def run_once(self): super(md5sum, self).run_once() subargs = ['%s:%s' % (self.sub_stuff['run_name'], self.config['in_tar_file']), self.tmpdir] mustpass(DockerCmd(self, 'cp', subargs).execute())
def run_once(self): super(run_twice, self).run_once() nfdc = DockerCmd(self, 'run', self.stuff['subargs']) self.stuff['cmdresults'].append(mustpass(nfdc.execute())) dc = DockerCmd(self, 'run', self.stuff['subargs']) self.stuff['2nd_cmdresults'].append(dc.execute())
def run_once(self): super(inspect_container_simple, self).run_once() subargs = [self.sub_stuff['name']] nfdc = DockerCmd(self, "inspect", subargs) self.sub_stuff['cmdresult'] = mustpass(nfdc.execute())
def run_once(self): super(exec_false, self).run_once() subargs = self.sub_stuff['exec_args'] + ['/bin/false'] dkrcmd_exec = DockerCmd(self, 'exec', subargs, timeout=60) self.sub_stuff['dkrcmd_exec'] = dkrcmd_exec dkrcmd_exec.execute()
def init_dockercmd(self): dkrcmd = DockerCmd(self, 'run', self.sub_stuff['subargs']) self.sub_stuff['dkrcmd'] = dkrcmd
def run_once(self): super(create_base, self).run_once() # Prints out basic info dkrcmd = DockerCmd(self, 'create', self.sub_stuff['subargs']) self.sub_stuff['dkrcmd'] = dkrcmd dkrcmd.execute()
def initialize(self): super(systemd_run, self).initialize() # build image using edited Dockerfile in tmpdir dkrcmd = DockerCmd(self, 'build', [self.config['build_opt'], self.tmpdir]) mustpass(dkrcmd.execute())
def cleanup(self): super(rhel_push_plugin_base, self).cleanup() for k in 'image_name', 'dest_name', 'base_image': dcmd = DockerCmd(self, 'rmi', [self.sub_stuff[k]]) dcmd.execute()
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 inspect_and_parse(self, subargs): nfdc = DockerCmd(self, "inspect", subargs) cmdresult = mustpass(nfdc.execute()) # Log details when command is successful self.logdebug(nfdc.cmdresult) return self.parse_cli_output(cmdresult.stdout)
def cleanup(self): super(syslog, self).cleanup() if self.config['remove_after_test']: if 'container_name' in self.stuff: dkrcmd = DockerCmd(self, 'rm', [self.stuff['container_name']]) dkrcmd.execute()
def container_ports(self, name): port_dkrcmd = DockerCmd(self, 'port', [name]) port_dkrcmd.execute() mustpass(port_dkrcmd) return port_dkrcmd.stdout.strip()
def run_import(self): subargs = [ self.config['tar_url'].strip(), self.sub_stuff['import_repo'] ] cmdresult = mustpass(DockerCmd(self, 'import', subargs).execute()) self.sub_stuff['import_cmdresult'] = cmdresult
def verify_images(self, test_images): """ For each test_image from test_images verifies: 1. Presence in `docker images` 2. Presence in `docker images --all` 3. Presence of parent in `docker history` test_image compounded of [$long_id, $name, $exists, $tagged, $parents] exists, tagged are bools set by test developer parents is list of parent long_ids """ def format_err_str(test_images, images, imagesall): """ Format useful err info """ out = "Expected images:\n" out += "\n".join((str(_) for _ in test_images)) out += "\nImages:\n" out += "\n".join(("%s%s" % (_.repo, _.long_id) for _ in images)) out += "\nImages --all:\n" out += "\n".join(("%s (%s)" % (_.repo, _.long_id) for _ in imagesall)) return out def name_in(name, images): """ name (.repo) in list of images """ return name in (_.repo for _ in images) def id_in(long_id, images): """ id in list of images """ return long_id in (_.long_id for _ in images) images = self.sub_stuff['di'].list_imgs() imagesall = self.sub_stuff['dia'].list_imgs() err_str = lambda: format_err_str(test_images, images, imagesall) for image in test_images: if image[2:4] == [False, False]: # Non existing (nowhere) self.failif(id_in(image[0], imagesall), "Removed image id" " '%s' in images all:\n%s" % (image[0], err_str())) self.failif(name_in(image[1], imagesall), "Removed image " "named '%s' in images all:\n%s" % (image[1], err_str())) elif image[3] is False: # Untagged (id in images all) self.failif(name_in(image[1], imagesall), "Untagged name '%s'" " in images all:\n%s" % (image[1], err_str())) self.failif(id_in(image[0], images), "Untagged id '%s' in " "images:\n%s" % (image[0], err_str())) self.failif(not id_in(image[0], imagesall), "Untagged id '%s'" " used in another image not present in images all" ":\n%s" % (image[0], err_str())) else: # Tags and ids exist everywhere self.failif(not id_in(image[0], images), "Image id '%s' " "not found in images:\n%s" % (image[0], err_str())) self.failif(not id_in(image[0], imagesall), "Image id '%s'" " not found in images all:\n%s" % (image[0], err_str())) self.failif(not name_in(image[1], images), "Image named '%s' " "not found in images:\n%s" % (image[1], err_str())) self.failif(not name_in(image[1], imagesall), "Image named " "'%s' not found in images all:\n%s" % (image[1], err_str())) if image[3] and image[4] is not None: history = mustpass(DockerCmd(self, 'history', ['--no-trunc', '-q', image[0]]).execute()).stdout for parent in image[4]: self.failif(parent not in history, "Parent image '%s' of " "image '%s' was not found in `docker history`:" "\n%s\n%s" % (parent, image[0], history, err_str()))
def init_top_dkrcmd(self): subargs = [self.get_run_name()] subargs += self.sub_stuff['top_options'] return DockerCmd(self, 'top', subargs)
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 run_once(self): super(inspect_all, self).run_once() # find inputs to this subargs = [self.sub_stuff['name']] nfdc = DockerCmd(self, "inspect", subargs) self.sub_stuff['cmdresult'] = mustpass(nfdc.execute())
def run_once(self): super(info, self).run_once() # 1. Run with no options nfdc = DockerCmd(self, "info") self.stuff['cmdresult'] = mustpass(nfdc.execute())
def cleanup(self): super(events, self).cleanup() if self.config['remove_after_test']: cid = self.stuff['nfdc_cid'] DockerCmd(self, 'rm', ['--force', '--volumes', cid]).execute()
def run_once(self): super(diff_base, self).run_once() nfdc = DockerCmd(self, 'diff', [self.sub_stuff['name']]) self.sub_stuff['cmdresult'] = mustpass(nfdc.execute())
def run_once(self): super(logout_ok, self).run_once() logout = DockerCmd(self, 'logout', [self.sub_stuff['server']]) self.sub_stuff['cmdresult_logout'] = logout.execute()
def run_once(self): super(volume_mount, self).run_once() subargs = ['-a', self.sub_stuff['container2']] # This is the command that fails in broken docker-1.12 builds result = mustpass(DockerCmd(self, 'start', subargs).execute()) self.sub_stuff['start_result'] = result
def started_twice(): result = mustpass(DockerCmd(self, "logs", [name]).execute()) return result.stdout.count("STARTED") == 2
def postprocess(self): super(run_remote_tag, self).postprocess() # Prints out basic info # Fail test if image removal fails fqin = self.config["remote_image_fqin"] mustpass(DockerCmd(self, 'rmi', ['--force', fqin]).execute())
def remove_link(self, client_name, alias): return mustpass( DockerCmd( self, 'rm', ['--link=true', '%s/%s' % (client_name, alias)]).execute())
def run_once(self): super(docker_test_images, self).run_once() for fqin in self.stuff['fqins']: self.loginfo("Pulling %s", fqin) # TODO: Support pulling/verifying with atomic command DockerCmd(self, 'pull', [fqin]).execute()
def initialize(self): super(run_attach_stdout, self).initialize() attachcmd = DockerCmd(self, 'attach', [self.sub_stuff['name']]) self.sub_stuff['attachcmd'] = attachcmd