def create_cntnr(self, command, args='', execute=True, cls=DockerCmd): """ Return possibly executed DockerCmd instance :param name: Name for container :param command: Command argument for container :param args: Complete, space-separated argument list for container :param execute: If true, execute() will be called on instance :param cls: A DockerCmdBase subclass to use for instance :return: A new DockerCmd instance """ fqin = DockerImage.full_name_from_defaults(self.config) name = self.sub_stuff['dc'].get_unique_name() # scrape_names (above) depends on separate name argument from --name subargs = ['--name', name] subargs += get_as_list(self.config['extra_create_args']) subargs += [fqin, command] subargs += args.strip().split() dockercmd = cls(self, 'create', subargs) dockercmd.quiet = True if execute: dockercmd.execute() mustpass(dockercmd.cmdresult) self.sub_stuff['cntnr_names'].append(name) return dockercmd
def initialize(self): super(login_base, self).initialize() # We need to create cert and htpasswd files for bind-mounting in # the registry container; do so in a safe temporary workdir. os.chdir(self.tmpdir) # Creates domain.crt and domain.key files self._create_certs() # Credentials: fixed username with pseudorandom password self._create_htpasswd() self._preserve_docker_auth_file() # Now run the registry itself, leave it running for the login test c_name = DockerContainers(self).get_unique_name() subargs = ['-d', '-p', '{port}:{port}'.format(**self.sub_stuff), '--name', c_name, '-v', '{}:/auth:Z'.format(self.tmpdir), '-e', 'REGISTRY_HTTP_TLS_CERTIFICATE=/auth/domain.crt', '-e', 'REGISTRY_HTTP_TLS_KEY=/auth/domain.key', '-e', 'REGISTRY_AUTH=htpasswd', '-e', 'REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm"', '-e', 'REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd', self.config['registry_fqin']] self.sub_stuff['my_containers'] = [c_name] self.sub_stuff['my_images'] = [] mustpass(DockerCmd(self, 'run', subargs).execute()) self._wait_for_registry_ready()
def run_once(self): super(basic, self).run_once() containers = [] cidfile = self._nonexisting_path(self.tmpdir, "cidfile-") subargs = self.config.get('run_options_csv').split(',') containers.append(self._init_container(subargs, cidfile, 'sh', None, InteractiveAsyncDockerCmd)) name = self.sub_stuff['containers'][0] self.failif(utils.wait_for(lambda: os.path.isfile(cidfile), 9) is None, "cidfile didn't appear in 9s after container execution") cont = self._get_container_by_name(name) long_id = cont.long_id self._check_cidfile(long_id, cidfile) # cidfile already exists (running container) containers.append(self._init_container(subargs, cidfile, 'true', lambda x: mustfail(x, 125))) self._check_failure_cidfile_present(containers[-1]) # cidfile already exists (exited container) # FIXME: this occasionally throws SIGPIPE, presumably because # container isn't fully ready. This is a tough one to solve. containers[0].stdin("exit\n") containers[0].wait(10) containers[0].close() containers.append(self._init_container(subargs, cidfile, 'true', lambda x: mustfail(x, 125))) self._check_failure_cidfile_present(containers[-1]) # restart container with cidfile mustpass(dockercmd.DockerCmd(self, 'start', [name]).execute()) is_alive = lambda: 'Up' in self._get_container_by_name(name).status self.failif(utils.wait_for(is_alive, 10) is None, "Container %s " "was not restarted in 10 seconds." % name) self._check_cidfile(long_id, cidfile) self.sub_stuff['dc'].kill_container_by_name(name) self._check_cidfile(long_id, cidfile)
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 _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) 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 _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) 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) c_attach = AsyncDockerCmd(self, 'attach', subargs) self.sub_stuff['container_cmd'] = c_attach # overwrites finished cmd c_attach.execute()
def run_once(self): super(iptable_base, self).run_once() subargs = self.sub_stuff['subargs'] mustpass(DockerCmd(self, 'run -d', subargs, verbose=True).execute()) self.sub_stuff['rules_during'] = self.read_iptable_rules(None) self.logdebug("Rules during:\n%s", '\n'.join(self.sub_stuff['rules_during']))
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(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 run_once(self): super(cp_symlink, self).run_once() self.sub_stuff['cname'] = DockerContainers(self).get_unique_name() # Run a container. It will wait for the presence of a signal file, # then check for presence of the xfer file and compare its contents # to the expected value. Different exit codes (tested in postprocess) # mean different errors. destdir = self.config['destdir'] command = ('\'ln -s /tmp /mylink; echo READY; while [ ! -f /stop ]; do sleep 0.2s; done; xfer_file=%s/%s; test -f $xfer_file || exit 4; actual=$(< $xfer_file); expect="%s"; test "$actual" = "$expect" && exit 0; echo $xfer_file: bad content "$actual" - expected "$expect";exit 5\'' % (destdir, self.sub_stuff['xfer_file'], self.sub_stuff['xfer_content'])) subargs = [ '--name=%s' % self.sub_stuff['cname'], DockerImage.full_name_from_defaults(self.config), '/bin/bash', '-c', command] self.sub_stuff['dkrcmd'] = AsyncDockerCmd(self, 'run', subargs) self.sub_stuff['dkrcmd'].execute() self.sub_stuff['dkrcmd'].wait_for_ready() # First: copy the desired destination file cp_dest = self.config['cp_dest'] if '%' in cp_dest: cp_dest = cp_dest % self.sub_stuff['xfer_file'] subargs = [ self.sub_stuff['xfer_file_local'], "%s:%s" % (self.sub_stuff['cname'], cp_dest) ] mustpass(DockerCmd(self, 'cp', subargs).execute()) # Second: create the signal file that tells the container to stop. # We don't use the content file as signal, first, because we # don't know if docker-cp is atomic, i.e. if we can have a race # condition where the destfile exists but does not have content; # and second, because there are situations in which docker-cp # to / (root) works but /tmp or /mylink->/tmp does not. subargs[1] = '%s:/stop' % self.sub_stuff['cname'] mustpass(DockerCmd(self, 'cp', subargs).execute())
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 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 init_save_images(self): # If images w/ same id as remote image already exist, save then remove di = self.sub_stuff['img'] imgs = di.list_imgs_with_full_name(self.config["remote_image_fqin"]) if imgs: long_id = imgs[0].long_id existing_images = di.list_imgs_with_image_id(long_id) self.sub_stuff['saved_images'] = os.path.join(self.tmpdir, str(long_id)) subargs = ['--output', self.sub_stuff['saved_images']] for img in existing_images: self.loginfo("Going to save image %s" % img.full_name) subargs.append(img.full_name) self.loginfo("Saving images...") mustpass(DockerCmd(self, 'save', subargs).execute()) self.loginfo("Removing images...") subargs = ['--force'] subargs += [img.full_name for img in existing_images] mustpass(DockerCmd(self, 'rmi', subargs, verbose=True).execute()) # Wait for images to actually go away _fn = lambda: self.long_id_in_images(long_id) gone = utils.wait_for(_fn, 60, step=1, text="Waiting for image removal") self.logdebug("Current images: %s", di.list_imgs()) if not gone: raise DockerTestFail("Timeout waiting for removal of %s" % long_id)
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 init_save_images(self): # If images w/ same id as remote image already exist, save then remove di = self.sub_stuff['img'] imgs = di.list_imgs_with_full_name(self.config["remote_image_fqin"]) if imgs: long_id = imgs[0].long_id existing_images = di.list_imgs_with_image_id(long_id) self.sub_stuff['saved_images'] = os.path.join(self.tmpdir, str(long_id)) subargs = ['--output', self.sub_stuff['saved_images']] for img in existing_images: self.loginfo("Going to save image %s" % img.full_name) subargs.append(img.full_name) self.loginfo("Saving images...") mustpass(DockerCmd(self, 'save', subargs).execute()) self.loginfo("Removing images...") subargs = ['--force'] subargs += [img.full_name for img in existing_images] mustpass(DockerCmd(self, 'rmi', subargs).execute()) # Wait for images to actually go away _fn = lambda: self.long_id_in_images(long_id) gone = utils.wait_for(_fn, 60, step=1, text="Waiting for image removal") self.logdebug("Current images: %s", di.list_imgs()) if not gone: raise DockerTestFail("Timeout waiting for removal of %s" % long_id)
def initialize(self): super(login_base, self).initialize() # We need to create cert and htpasswd files for bind-mounting in # the registry container; do so in a safe temporary workdir. os.chdir(self.tmpdir) # Creates domain.crt and domain.key files self._create_certs() # Credentials: fixed username with pseudorandom password self._create_htpasswd() self._preserve_docker_auth_file() # Now run the registry itself, leave it running for the login test c_name = DockerContainers(self).get_unique_name() subargs = [ '-d', '-p', '{port}:{port}'.format(**self.sub_stuff), '--name', c_name, '-v', '{}:/auth:Z'.format(self.tmpdir), '-e', 'REGISTRY_HTTP_TLS_CERTIFICATE=/auth/domain.crt', '-e', 'REGISTRY_HTTP_TLS_KEY=/auth/domain.key', '-e', 'REGISTRY_AUTH=htpasswd', '-e', 'REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm"', '-e', 'REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd', self.config['registry_fqin'] ] self.sub_stuff['my_containers'] = [c_name] self.sub_stuff['my_images'] = [] mustpass(DockerCmd(self, 'run', subargs).execute()) self._wait_for_registry_ready()
def postprocess(self): super(login_ok, self).postprocess() cmdresult = self.sub_stuff['cmdresult'] OutputGood(cmdresult) mustpass(cmdresult) self.failif_not_in("Login Succeeded", cmdresult.stdout, "stdout from docker login") self._check_credentials()
def postprocess(self): super(exec_base, self).postprocess() # Prints out basic info os.write(self.sub_stuff['dkrcmd_stdin'], 'exit\t') time.sleep(1) mustpass(DockerCmd(self, 'kill', [self.sub_stuff['run_name']]).execute()) # It may have been killed, but exec is what we care about OutputNotBad(self.sub_stuff['dkrcmd'].cmdresult)
def postprocess(self): dkrcmd_exec = self.sub_stuff['dkrcmd_exec'] mustpass(dkrcmd_exec.cmdresult) OutputGood(dkrcmd_exec.cmdresult) pids = dkrcmd_exec.stdout.strip().splitlines() expected = self.config["pid_count"] self.failif_ne(len(pids), expected, "Number of pids: %s" % pids) super(exec_pid_count, self).postprocess()
def initialize(self): super(double_tag, self).initialize() # Tag it for the first time. This should pass... self.sub_stuff['tmp_image_list'].add(self.sub_stuff["new_image_name"]) mustpass(DockerCmd(self, 'tag', self.complete_docker_command_line(), verbose=True).execute()) # ...but the actual (second) tag incantation in run_once() should fail. self.expect_pass(False)
def initialize(self): super(diff_base, self).initialize() dc = DockerContainers(self) name = self.sub_stuff['name'] = dc.get_unique_name() fin = DockerImage.full_name_from_defaults(self.config) subargs = ['--name=%s' % (name), fin] subargs = subargs + self.config['command'].split(',') nfdc = DockerCmd(self, 'run', subargs) mustpass(nfdc.execute())
def postprocess(self): super(push_ok, self).postprocess() cmdresult = self.sub_stuff['pushresult'] OutputGood(cmdresult) mustpass(cmdresult) self.failif_not_in(": Pushed", cmdresult.stdout, "stdout from docker push") self.failif_not_in("tag_ok: digest:", cmdresult.stdout, "stdout from docker push")
def run_once(self): super(simple, self).run_once() dd_cmd = self.config["dd_cmd"] for size in (int(size) for size in self.config["dd_sizes"].split()): self.loginfo("Testing %d megabytes", size) segment = "1M" self.sub_stuff["sizes"].append(size) dkrcmd = self._init_container([], dd_cmd % (segment, size)) mustpass(dkrcmd.execute())
def initialize(self): super(double_tag, self).initialize() # Tag it for the first time self.sub_stuff['tmp_image_list'].add(self.sub_stuff["new_image_name"]) mustpass( DockerCmd(self, 'tag', self.complete_docker_command_line(), verbose=False).execute())
def run_once(self): super(simple, self).run_once() dd_cmd = self.config['dd_cmd'] for size in (int(size) for size in self.config['dd_sizes'].split()): self.loginfo("Testing %d megabytes", size) segment = "1M" self.sub_stuff['sizes'].append(size) dkrcmd = self._init_container([], dd_cmd % (segment, size)) mustpass(dkrcmd.execute())
def run_once(self): super(simple, self).run_once() # build arg list and execute command subargs = ["%s:%s" % (self.sub_stuff["container_name"], self.sub_stuff["cpfile"])] subargs.append(self.tmpdir) nfdc = DockerCmd(self, "cp", subargs, timeout=self.config["docker_timeout"]) mustpass(nfdc.execute()) copied_path = "%s/%s" % (self.tmpdir, self.sub_stuff["cpfile"].split("/")[-1]) self.sub_stuff["copied_path"] = copied_path
def postprocess(self): super(sigproxy_base, self).postprocess() self._check_results() # stop the container container_name = self.sub_stuff['container_name'] mustpass(DockerCmd(self, "kill", [container_name]).execute()) container = self.sub_stuff['container_cmd'] if not utils.wait_for(lambda: container.done, 5, step=0.1): raise DockerTestFail("Unable to kill container after test...")
def postprocess(self): super(run_attach_stdout, self).postprocess() attach_cmdresult = self.sub_stuff['attachcmd'].cmdresult OutputGood(attach_cmdresult) mustpass(attach_cmdresult) secret_sauce = self.config['secret_sauce'] secret_present = attach_cmdresult.stdout.find(secret_sauce) != -1 self.failif(not secret_present, "Test data not found from attach command output: %s" % attach_cmdresult)
def postprocess(self): super(load, self).postprocess() OutputGood(self.stuff['dkrcmd'].cmdresult) mustpass(self.stuff['dkrcmd']) img_id = self._test_id img_name = self.config['test_fqin'] di = self.stuff['di'] self.failif(img_id not in di.list_imgs_ids(), "Failed to remove test image with id %s" % img_id) self.failif(img_name not in di.list_imgs_full_name(), "Failed to remove test image with name %s" % img_name)
def create_simple_container(subtest): fin = DockerImage.full_name_from_defaults(subtest.config) name = utils.generate_random_string(12) subargs = ["--name=%s" % (name), fin, "/bin/bash", "-c", "'/bin/true'"] nfdc = DockerCmd(subtest, 'run', subargs) mustpass(nfdc.execute()) if not subtest.sub_stuff or not subtest.sub_stuff['containers']: subtest.sub_stuff['containers'] = [name] else: subtest.sub_stuff['containers'] += [name] return name
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() if self.config['expect_success'] == 'PASS': mustpass(dkrcmd) else: mustfail(dkrcmd, 125) memory_containers.append(dkrcmd)
def postprocess(self): super(simple, self).postprocess() name = self.sub_stuff['container_name'] logs = AsyncDockerCmd(self, "logs", ['-f', name]) logs.execute() utils.wait_for(lambda: logs.stdout.count("\n") == 2, 5, step=0.1) out = logs.stdout self.failif(out.count("\n") != 2, "The container was executed twice, " "there should be 2 lines with start dates, but is " "%s.\nContainer output:\n%s" % (out.count("\n"), out)) mustpass(DockerCmd(self, "kill", [name]).execute())
def create_simple_container(subtest): fin = DockerImage.full_name_from_defaults(subtest.config) name = utils.generate_random_string(12) subargs = ["--name=%s" % (name), fin, "/bin/bash", "-c", "'/bin/true'"] nfdc = DockerCmd(subtest, "run", subargs) mustpass(nfdc.execute()) if not subtest.sub_stuff or not subtest.sub_stuff["containers"]: subtest.sub_stuff["containers"] = [name] else: subtest.sub_stuff["containers"] += [name] return name
def postprocess(self): super(run_attach_stdout, self).postprocess() attach_cmdresult = self.sub_stuff['attachcmd'].cmdresult OutputGood(attach_cmdresult) mustpass(attach_cmdresult) secret_sauce = self.config['secret_sauce'] secret_present = attach_cmdresult.stdout.find(secret_sauce) != -1 self.failif( not secret_present, "Test data not found from attach command output: %s" % attach_cmdresult)
def postprocess(self): super(simple, self).postprocess() name = self.sub_stuff['container_name'] def started_twice(): result = mustpass(DockerCmd(self, "logs", [name]).execute()) return result.stdout.count("STARTED") == 2 ok = utils.wait_for(started_twice, 10, step=0.5) self.failif(not ok, "Timed out waiting for second STARTED message.\n") mustpass(DockerCmd(self, "kill", [name]).execute())
def run_once(self): super(simple, self).run_once() # build arg list and execute command subargs = ["%s:%s" % (self.sub_stuff['container_name'], self.sub_stuff['cpfile'])] subargs.append(self.tmpdir) nfdc = DockerCmd(self, "cp", subargs, timeout=self.config['docker_timeout']) mustpass(nfdc.execute()) copied_path = "%s/%s" % (self.tmpdir, self.sub_stuff['cpfile'].split('/')[-1]) self.sub_stuff['copied_path'] = copied_path
def initialize(self): super(double_tag, self).initialize() # Tag it for the first time. This should pass... self.sub_stuff['tmp_image_list'].add(self.sub_stuff["new_image_name"]) mustpass(DockerCmd(self, 'tag', self.complete_docker_command_line()).execute()) # On docker 1.10, the second tag should pass. On < 1.10, fail. try: DockerVersion().require_server("1.10") self.expect_pass(True) except xceptions.DockerTestNAError: self.expect_pass(False)
def postprocess(self): super(create_base, self).postprocess() # Prints out basic info # Fail test if bad command or other stdout/stderr problems detected dkrcmd = self.sub_stuff['dkrcmd'] OutputGood(dkrcmd.cmdresult) expected = 0 # always self.failif(dkrcmd.exit_status != expected, "Exit status non-zero command %s" % dkrcmd.cmdresult) # cid must be printed on stdout, always cid = self.get_cid() # non-forced removal must succeed, rely on rm test to verify. mustpass(DockerCmd(self, 'rm', [cid]).execute())
def postprocess(self): super(create_base, self).postprocess() # Prints out basic info # Fail test if bad command or other stdout/stderr problems detected dkrcmd = self.sub_stuff['dkrcmd'] OutputGood(dkrcmd.cmdresult) expected = self.config['exit_status'] self.failif_ne(dkrcmd.exit_status, expected, "Exit status non-zero command %s" % dkrcmd.cmdresult) # cid must be printed on stdout, always cid = self.get_cid() # non-forced removal must succeed, rely on rm test to verify. mustpass(DockerCmd(self, 'rm', [cid]).execute())
def run_once(self): super(simple, self).run_once() dd_cmd = self.config['dd_cmd'] for size in (int(size) for size in self.config['dd_sizes'].split()): if size >= 1000: segment = '1G' size = size / 1000 self.sub_stuff['sizes'].append(size * 1000) else: segment = "1M" self.sub_stuff['sizes'].append(size) dkrcmd = self._init_container([], dd_cmd % (segment, size)) mustpass(dkrcmd.execute())
def initialize(self): super(double_tag, self).initialize() # Tag it for the first time. This should pass... self.sub_stuff['tmp_image_list'].add(self.sub_stuff["new_image_name"]) mustpass( DockerCmd(self, 'tag', self.complete_docker_command_line()).execute()) # On docker 1.10, the second tag should pass. On < 1.10, fail. try: DockerVersion().require_server("1.10") self.expect_pass(True) except xceptions.DockerTestNAError: self.expect_pass(False)
def _init_container(self, prefix, fin, subargs, cmd): """ Prepares dkrcmd and stores the name in self.sub_stuff['containers'] :return: name """ if fin is None: fin = DockerImage.full_name_from_defaults(self.config) name = self.sub_stuff['dc'].get_unique_name(prefix) subargs.append("--name %s" % name) self.sub_stuff['containers'].append(name) subargs.append(fin) subargs.append(cmd) mustpass(DockerCmd(self, 'run', subargs).execute()) return 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