def initialize(self): super(psa, self).initialize() dc = self.stuff['dc'] = DockerContainers(self) dc.verify_output = True # test subject, do extra checking name = self.stuff['container_name'] = dc.get_unique_name() cidfile = os.path.join(self.tmpdir, 'cidfile') self.stuff['cidfile'] = cidfile subargs = ['--cidfile', cidfile, '--name=%s' % name] fin = images.DockerImage.full_name_from_defaults(self.config) subargs.append(fin) subargs.append('/bin/bash') subargs.append('-c') # Write to a file when signal received # Loop forever until marker-file exists command = ("\"" "echo 'foobar' > stop && " "rm -f stop && trap '/usr/bin/date +%%s> stop' USR1 && " "while ! [ -f stop ]; do /usr/bin/sleep 0.1s; done" "\"") subargs.append(command) self.stuff['cl0'] = dc.list_containers() dkrcmd = AsyncDockerCmd(self, 'run', subargs) self.stuff['dkrcmd'] = dkrcmd if os.path.isfile(cidfile): os.unlink(cidfile)
def cleanup(self): """ Cleanup the containers defined in self.sub_stuff['containers'] """ if self.config['remove_after_test']: dc = DockerContainers(self) dc.clean_all(self.sub_stuff.get("containers"))
def initialize(self): super(stop_base, self).initialize() # Prepare a container docker_containers = DockerContainers(self) name = docker_containers.get_unique_name() self.sub_stuff['container_name'] = name config.none_if_empty(self.config) if self.config.get('run_options_csv'): subargs = [ arg for arg in self.config['run_options_csv'].split(',') ] 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 = AsyncDockerCmd(self, 'run', subargs) self.sub_stuff['container_cmd'] = container container.execute() container.wait_for_ready() # Prepare the "stop" command if self.config.get('stop_options_csv'): subargs = [ arg for arg in self.config['stop_options_csv'].split(',') ] subargs.append(name) self.sub_stuff['stop_cmd'] = DockerCmd(self, 'stop', subargs)
def initialize(self): super(simple, self).initialize() config.none_if_empty(self.config) # Get free name docker_containers = DockerContainers(self) name = docker_containers.get_unique_name() self.sub_stuff['container_name'] = name
def initialize(self): """ Execute 6 variants of the same 'docker run -a' command and store the results. variants: - tty - nontty variants: - stdin (execute bash, put 'ls /\n exit\n' on stdin) - stdout (execute ls /) - stderr (execute ls /nonexisting/directory/...) """ super(run_attach_base, self).initialize() # Prepare a container config.none_if_empty(self.config) self.sub_stuff['dc'] = DockerContainers(self) self.sub_stuff['containers'] = [] self._init_test_dependent() # TODO: Test w/ tty=True when some DockerCmd class supports pty # for tty in (True, False): # generate matrix of tested variants tty = False # interactive container cont = self._init_container(tty, 'bash', 'ls /\nexit\n') self.sub_stuff['res_stdin_%s' % tty] = cont # stdout container cont = self._init_container(tty, 'ls /') self.sub_stuff['res_stdout_%s' % tty] = cont # stderr container cont = self._init_container( tty, 'ls /I/hope/this/does/not/exist/%s' % utils.generate_random_string(6)) self.sub_stuff['res_stderr_%s' % tty] = cont
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 initialize(self): super(liverestore, self).initialize() # Skip test if live-restore is not enabled try: lr_enabled = DockerInfo().get('Live Restore Enabled') self.failif_ne(lr_enabled, 'true', "Live Restore Enabled field from 'docker info'", DockerTestNAError) except KeyError: # docker 1.12 doesn't include this in 'docker info'. Try looking # at command line. This won't work with containerized docker # because it uses /etc/docker/*.json docker_cmdline = docker_daemon.cmdline() self.failif_not_in("--live-restore", docker_cmdline, "docker daemon command-line options", DockerTestNAError) # rhbz1424709#c40 : live-restore fails unless KillMode=process killmode = docker_daemon.systemd_show('KillMode') if killmode != 'process': self.logwarning("systemd KillMode is '%s' (expected 'process')." " This test will probably fail." % killmode) self.stuff['dc'] = DockerContainers(self)
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 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(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 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 cleanup(self): """ Cleanup the container """ super(run_user, self).cleanup() if self.config['remove_after_test']: dc = DockerContainers(self) dc.clean_all([self.stuff.get("container")])
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 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 postprocess(self): super(iptable_base, self).postprocess() name = self.sub_stuff['name'] DockerContainers(self).wait_by_name(name) self.sub_stuff['rules_after'] = self.read_iptable_rules(None) self.logdebug("Rules after:\n%s", '\n'.join(self.sub_stuff['rules_after']))
def initialize(self): super(import_export_base, self).initialize() self.sub_stuff['subargs'] = self.config['run_options_csv'].split(',') fin = DockerImage.full_name_from_defaults(self.config) self.sub_stuff['subargs'].append(fin) self.sub_stuff['subargs'].append(self.config['docker_data_prep_cmd']) self.sub_stuff["containers"] = [] self.sub_stuff["images"] = [] self.sub_stuff["cont"] = DockerContainers(self)
def initialize(self): super(start_base, self).initialize() config.none_if_empty(self.config) self.sub_stuff["conts_obj"] = DockerContainers(self) self.sub_stuff["con_ro_obj"] = DockerContainersRunOnly(self) self.sub_stuff["image_name"] = None self.sub_stuff["container"] = None self.sub_stuff["containers"] = []
def initialize(self): super(flag, self).initialize() self.stuff["containter_name"] = [] self.stuff["subargs"] = [] self.stuff["cmdresult"] = [] docker_containers = DockerContainers(self) self.logdebug("Generating ramdom name will take 1 minute") cname = docker_containers.get_unique_name() self.stuff["containter_name"] = cname
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 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 initialize(self): """ Runs one container """ super(basic, self).initialize() config.none_if_empty(self.config) self.sub_stuff['dc'] = DockerContainers(self) self.sub_stuff['containers'] = [] self.sub_stuff['cidfiles'] = set()
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 initialize(self): """ Runs one container """ super(run_user_base, self).initialize() # Prepare a container config.none_if_empty(self.config) self.sub_stuff['dc'] = DockerContainers(self) self._init_test_depenent() self._init_container(self.sub_stuff['subargs'], self.config['exec_cmd'])
def initialize(self): super(attach_base, self).initialize() self.sub_stuff['subargs'] = self.config['run_options_csv'].split(',') fin = DockerImage.full_name_from_defaults(self.config) if self.image_exist(fin) == []: self.pull_image(fin) self.sub_stuff['subargs'].append(fin) self.sub_stuff['subargs'] += ['bash', '-c', self.config['cmd']] self.sub_stuff["containers"] = [] self.sub_stuff["images"] = [] self.sub_stuff["cont"] = DockerContainers(self) self.sub_stuff["file_desc"] = []
def initialize(self): super(deferred_deletion, self).initialize() docker_cmdline = dockertest.docker_daemon.cmdline() self.failif_not_in("dm.use_deferred_deletion=true", str(docker_cmdline), "docker daemon command-line options", DockerTestNAError) self._rhel72_bug_workaround() self.stuff['dc'] = DockerContainers(self)
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 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 initialize(self): """ Runs one container """ super(kill_bad_base, self).initialize() config.none_if_empty(self.config) # Prepare a container docker_containers = DockerContainers(self) name = docker_containers.get_unique_name() self.sub_stuff['container_name'] = name self._init_container(name) time.sleep(self.config.get('wait_start', 3))
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 initialize(self): self.sub_stuff['dc'] = DockerContainers(self) fqin = DockerImage.full_name_from_defaults(self.config) self.sub_stuff['fqin'] = fqin self.sub_stuff['run_options'] = (get_as_list( self.config['run_options_csv'])) self.sub_stuff['run_options'] += ['--name', self.get_run_name()] self.sub_stuff['top_options'] = (get_as_list( self.config['top_options_csv'])) self.sub_stuff['containers'] = [] self.sub_stuff['run_dkrcmd'] = self.init_run_dkrcmd() self.sub_stuff['top_dkrcmd'] = self.init_top_dkrcmd()