Beispiel #1
0
 def cleanup(self):
     # Cannot predict what images/containers will be created
     # clean everything not existing in initialize()
     super(negativeusage, self).cleanup()
     if not self.config['remove_after_test']:
         return
     preserve_fqins = config.get_as_list(self.config['preserve_fqins'])
     preserve_cnames = config.get_as_list(self.config['preserve_cnames'])
     # this can happen if initialize() fails early
     if 'dc' not in self.stuff:
         return
     dc = self.stuff['dc']
     ecs = self.stuff['existing_containers'] + preserve_cnames
     di = self.stuff['di']
     eis = self.stuff['existing_images'] + [di.default_image]
     eis += preserve_fqins
     for cid in dc.list_container_ids():
         if cid not in ecs:
             # Sub-subtests should have cleaned up for themselves
             self.logwarning("Removing container %s", cid)
             dockercmd.DockerCmd(self, 'rm', ['--force', cid]).execute()
     # Don't clean default image
     for full_name in di.list_imgs_full_name():
         if full_name not in eis:
             # Sub-subtests should have cleaned up for themselves
             self.logwarning("Removing image: %s", full_name)
             di.remove_image_by_full_name(full_name)
             dockercmd.DockerCmd(self, 'rmi',
                                 ['--force', full_name]).execute()
Beispiel #2
0
    def initialize(self):
        super(icc, self).initialize()

        fin = DockerImage.full_name_from_defaults(self.config)
        conts = self.sub_stuff['conts']
        self.sub_stuff["cont1_name"] = conts.get_unique_name("server")
        self.sub_stuff["containers"].append(self.sub_stuff["cont1_name"])
        args1 = get_as_list(self.config["docker_cmd1_args"])
        args1.append("--name=%s" % (self.sub_stuff["cont1_name"]))
        args1.append(fin)
        adcsp = AsyncDockerCmdSpec.PIPE
        self.sub_stuff["bash1"] = self.dkr_cmd.async("run", args1 + ["sh"],
                                                     stdin_r=adcsp)

        self.sub_stuff["cont2_name"] = conts.get_unique_name("client")
        self.sub_stuff["containers"].append(self.sub_stuff["cont2_name"])
        args2 = get_as_list(self.config["docker_cmd2_args"])
        args2.append("--name=%s" % (self.sub_stuff["cont2_name"]))
        args2.append(fin)
        adcsp = AsyncDockerCmdSpec.PIPE
        self.sub_stuff["bash2"] = self.dkr_cmd.async("run", args2 + ["sh"],
                                                     stdin_r=adcsp)

        ip = self.get_container_ip(self.sub_stuff["cont1_name"])
        if ip is None:
            raise DockerTestNAError("Problems during initialization of"
                                    " test: Cannot get container IP addr.")
        self.sub_stuff["ip1"] = ip
Beispiel #3
0
 def start_server(self):
     params = self.sub_stuff['params']
     subargs = get_as_list(self.config['server_options'])
     subargs += ['--publish %s' % params['port'],
                 '-e ENV_VARIABLE=%s' % self.sub_stuff['server_env']]
     cmd = 'python ' + ' '.join(get_as_list(self.config['python_options']))
     servercmd, server = self.init_container('server', subargs, cmd)
     self.sub_stuff['server_name'] = server
     servercmd.execute()
     return servercmd
Beispiel #4
0
 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()
Beispiel #5
0
 def cleanup(self):
     super(base, self).cleanup()
     if self.config['remove_after_test']:
         preserve_fqins = get_as_list(self.config['preserve_fqins'])
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         if self.sub_stuff['import_repo'] not in preserve_fqins:
             DockerCmd(self, 'rmi',
                       [self.sub_stuff['import_repo']]).execute()
         if self.sub_stuff['run_name'] not in preserve_cnames:
             DockerCmd(self, 'rm', [self.sub_stuff['run_name']]).execute()
Beispiel #6
0
 def start_client(self):
     server_name = self.sub_stuff['server_name']
     subargs = get_as_list(self.config['client_options'])
     subargs += ['--link %s:server' % server_name,
                 '--env ENV_VARIABLE=%s' % self.sub_stuff['client_env']]
     cmd = 'python ' + ' '.join(get_as_list(self.config['python_options']))
     clientcmd, client = self.init_container('client', subargs, cmd)
     self.sub_stuff['client_name'] = client
     clientcmd.execute()
     return clientcmd
 def cleanup(self):
     super(base, self).cleanup()
     if self.config['remove_after_test']:
         preserve_fqins = get_as_list(self.config['preserve_fqins'])
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         if self.sub_stuff['import_repo'] not in preserve_fqins:
             DockerCmd(self, 'rmi',
                       [self.sub_stuff['import_repo']]).execute()
         if self.sub_stuff['run_name'] not in preserve_cnames:
             DockerCmd(self, 'rm',
                       [self.sub_stuff['run_name']]).execute()
Beispiel #8
0
 def initialize(self):
     super(volumes_rw, self).initialize()
     host_paths = get_as_list(self.config['host_paths'], omit_empty=True)
     cntr_paths = get_as_list(self.config['cntr_paths'], omit_empty=True)
     # list of substitution dictionaries for each container
     path_info = self.sub_stuff['path_info'] = []
     self.init_path_info(path_info, host_paths, cntr_paths, self.tmpdir)
     dockercmds = self.sub_stuff['dockercmds'] = []
     self.sub_stuff['cmdresults'] = []
     # Does not execute()
     self.init_dkrcmds(self, path_info, dockercmds)
Beispiel #9
0
 def initialize(self):
     super(volumes_rw, self).initialize()
     host_paths = get_as_list(self.config['host_paths'], omit_empty=True)
     cntr_paths = get_as_list(self.config['cntr_paths'], omit_empty=True)
     # list of substitution dictionaries for each container
     path_info = self.sub_stuff['path_info'] = []
     self.init_path_info(path_info, host_paths, cntr_paths, self.tmpdir)
     dockercmds = self.sub_stuff['dockercmds'] = []
     self.sub_stuff['cmdresults'] = []
     # Does not execute()
     self.init_dkrcmds(self, path_info, dockercmds)
Beispiel #10
0
 def start_client(self):
     server_name = self.sub_stuff['server_name']
     subargs = get_as_list(self.config['client_options'])
     subargs += [
         '--link %s:server' % server_name,
         '--env ENV_VARIABLE=%s' % self.sub_stuff['client_env']
     ]
     cmd = 'python ' + ' '.join(get_as_list(self.config['python_options']))
     clientcmd, client = self.init_container('client', subargs, cmd)
     self.sub_stuff['client_name'] = client
     clientcmd.execute()
     return clientcmd
Beispiel #11
0
 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()
Beispiel #12
0
 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()
Beispiel #13
0
 def start_server(self):
     params = self.sub_stuff['params']
     subargs = get_as_list(self.config['server_options'])
     subargs += [
         '--publish %s' % params['port'],
         '-e ENV_VARIABLE=%s' % self.sub_stuff['server_env']
     ]
     cmd = 'python ' + ' '.join(get_as_list(self.config['python_options']))
     servercmd, server = self.init_container('server', subargs, cmd)
     self.sub_stuff['server_name'] = server
     servercmd.execute()
     return servercmd
Beispiel #14
0
 def init_subargs(self):
     subargs = self.sub_stuff['subargs']
     subargs += get_as_list(self.config['run_options_csv'])
     if self.config['run_append_name'] is True:
         dc = self.sub_stuff["cont"]
         name = dc.get_unique_name()
         self.sub_stuff['name'] = name
         self.sub_stuff['containers'].append(name)
         subargs.append('--name')
         subargs.append(name)
     fqin = self.sub_stuff['fqin']
     subargs.append(fqin)
     subargs += get_as_list(self.config['bash_cmd'])
     subargs.append(self.config['cmd'])
Beispiel #15
0
    def initialize(self):
        super(restart_base, self).initialize()
        none_if_empty(self.config)

        bind_addr = self.config["docker_daemon_bind"]

        self.conts = DockerContainersE(self.parent_subtest)
        self.conts.interface.docker_daemon_bind = bind_addr

        self.dkr_cmd = DkrcmdFactory(self, dkrcmd_class=AsyncDockerCmdSpec)
        self.sub_stuff["image_name"] = None
        self.sub_stuff["container"] = None
        self.sub_stuff["containers"] = []

        # Necessary for avoid conflict with service manager. [docker.socket]
        docker_args = []
        docker_args += get_as_list(self.config["docker_daemon_args"])
        docker_args.append("-H %s" % bind_addr)
        if self.config.get("new_docker_graph_path"):
            self.sub_stuff["graph_path"] = os.path.join(self.tmpdir, "graph")
            docker_args.append("-g %s" % self.sub_stuff["graph_path"])

        self.sub_stuff["dd_args"] = docker_args

        self.loginfo("Starting %s %s", self.config["docker_path"], docker_args)
        dd = docker_daemon.start(self.config["docker_path"],
                                 docker_args)
        if not docker_daemon.output_match(dd):
            raise DockerTestNAError("Unable to start docker daemon:"
                                    "\n**STDOUT**:\n%s\n**STDERR**:\n%s" %
                                    (dd.get_stdout(), dd.get_stderr()))
        self.sub_stuff["docker_daemon"] = dd
Beispiel #16
0
    def run_once(self):
        super(tls_verify_all_base, self).run_once()
        # start new docker daemon
        docker_args = []
        docker_args += get_as_list(self.config["docker_daemon_args"])
        docker_args.append("-H %s" % self.config["docker_daemon_bind"])
        dd = docker_daemon.start(self.config["docker_path"], docker_args)
        ret = docker_daemon.output_match(dd)
        if not ret:
            raise DockerTestNAError("Unable to start docker daemon:"
                                    "\n**STDOUT**:\n%s\n**STDERR**:\n%s" %
                                    (dd.get_stdout(), dd.get_stderr()))
        self.sub_stuff["docker_daemon"] = dd

        if self.sub_stuff["check_container_name"]:
            self.sub_stuff["cont1_name"] = self.conts.get_unique_name("test")
            self.sub_stuff["containers"].append(self.sub_stuff["cont1_name"])
        else:
            # Try to generate name without check using docker.
            rand = utils.generate_random_string(30)
            self.sub_stuff["cont1_name"] = "test" + rand
            self.sub_stuff["containers"].append(self.sub_stuff["cont1_name"])

        # start docker client command
        fin = DockerImage.full_name_from_defaults(self.config)
        args1 = ["--name=%s" % (self.sub_stuff["cont1_name"])]
        args1.append(fin)
        args1 += ["ls", "/"]
        adc_p = AsyncDockerCmdSpec.PIPE
        self.sub_stuff["bash1"] = self.dkr_cmd.async("run", args1,
                                                     stdin_r=adc_p)
        # 1. Run with no options
        self.sub_stuff["bash1"].wait(120)
Beispiel #17
0
 def cleanup(self):
     super(flag, self).cleanup()
     if self.config["remove_after_test"]:
         preserve_cnames = get_as_list(self.config["preserve_cnames"])
         cntnr = self.stuff["containter_name"]
         if cntnr not in preserve_cnames:
             DockerCmd(self, "rm", ["--force", "--volumes", cntnr]).execute()
 def postprocess(self):
     # File in top-level 'results/default/sysinfo' directory
     with open(os.path.join(self.job.sysinfo.sysinfodir,
                            'docker_images'), 'wb') as info_file:
         for img in self.stuff['di'].list_imgs():
             info_file.write("%s\n" % str(img))
             self.loginfo(str(img))
     # Hopefully not a TOCTOU race with initialize()
     if self.stuff['update'] and self.stuff['fqins']:
         # These /are/ the customized defaults, don't re-default them
         cfgsec = ConfigSection(dict(), 'DEFAULTS')
         # config.merge_write() can't work with DEFAULTS
         for key, value in Config.defaults_.items():
             cfgsec.set(key, value)
         # This may not exist
         if cfgsec.has_option('preserve_fqins'):
             preserve_fqins = set(get_as_list(cfgsec.get('preserve_fqins')))
         else:
             preserve_fqins = set([])
         self.logdebug("Old preserve_fqins: %s", preserve_fqins)
         # Update the existing list
         preserve_fqins |= set(self.stuff['fqins'])
         # Convert back to CSV, value still in memory only
         cfgsec.set('preserve_fqins', ",".join(preserve_fqins))
         self.loginfo("Updated preserve_fqins: %s",
                      cfgsec.get('preserve_fqins'))
         # This will get picked up when next test executes
         cfgsec.write(open(self.stuff['defaults_ini'], 'wb'))
         # Be kind to anyone debugging the contents
         msg = "\n# preserve_fqins modified by %s\n" % self.config_section
         open(self.stuff['defaults_ini'], 'ab').write(msg)
     super(docker_test_images, self).postprocess()
Beispiel #19
0
 def init_container(self, volume=None, volumes_from=None):
     """
     Starts container
     """
     subargs = config.get_as_list(self.config['run_options_csv'])
     if volume:
         subargs.append("--volume %s" % volume)
     if volumes_from:
         subargs.append("--volumes-from %s" % volumes_from)
     name = self.sub_stuff['dc'].get_unique_name()
     self.sub_stuff['containers'].append(name)
     subargs.append("--name %s" % name)
     fin = DockerImage.full_name_from_defaults(self.config)
     subargs.append(fin)
     subargs.append("sh")
     read_fd, write_fd = os.pipe()
     self.sub_stuff['fds'].append(write_fd)
     self.sub_stuff['fds'].append(read_fd)
     dkrcmd = dockercmd.AsyncDockerCmd(self, 'run', subargs)
     # TODO: Fix use of dkrcmd.stdin when appropriate class mech. available
     dkrcmd.execute(read_fd)
     dkrcmd.stdin = write_fd
     os.close(read_fd)  # no longer needed
     os.write(write_fd, 'echo "Started"\n')
     self.failif(
         not wait_for_output(lambda: dkrcmd.stdout, 'Started', timeout=20),
         "Error starting container %s: %s" % (name, dkrcmd))
     return dkrcmd
Beispiel #20
0
 def cleanup(self):
     super(cgroups_base, self).cleanup()
     if self.config["remove_after_test"]:
         preserve_cnames = get_as_list(self.config["preserve_cnames"])
         for name in self.sub_stuff.get("name", []):
             if name not in preserve_cnames:
                 DockerCmd(self, "rm", ["--force", name]).execute()
 def postprocess(self):
     super(docker_test_images, self).postprocess()
     # File in top-level 'results/default/sysinfo' directory
     with open(os.path.join(self.job.sysinfo.sysinfodir, 'docker_images'),
               'wb') as info_file:
         for img in self.stuff['di'].list_imgs():
             info_file.write("%s\n" % str(img))
             self.loginfo(str(img))
     # Hopefully not a TOCTOU race with initialize()
     if self.stuff['update'] and self.stuff['fqins']:
         # These /are/ the customized defaults, don't re-default them
         cfgsec = ConfigSection(dict(), 'DEFAULTS')
         # This may not exist
         if cfgsec.has_option('preserve_fqins'):
             preserve_fqins = get_as_list(cfgsec.get('preserve_fqins'))
         else:
             preserve_fqins = []
         self.logdebug("Old preserve_fqins: %s", preserve_fqins)
         # Update the existing list
         preserve_fqins += self.stuff['fqins']
         # Convert back to CSV, value still in memory only
         cfgsec.set('preserve_fqins', ",".join(preserve_fqins))
         # This will get picked up when next test executes
         cfgsec.merge_write(open(self.stuff['defaults_ini'], 'wb'))
         self.loginfo("Updated preserve_fqins: %s",
                      cfgsec.get('preserve_fqins'))
Beispiel #22
0
    def initialize(self):
        super(network_base, self).initialize()
        none_if_empty(self.config)

        bind_addr = self.config["docker_daemon_bind"]

        conts = DockerContainersE(self.parent_subtest)
        self.sub_stuff['conts'] = conts
        conts.interface.docker_daemon_bind = bind_addr
        self.dkr_cmd = DkrcmdFactory(self.parent_subtest,
                                     dkrcmd_class=AsyncDockerCmdSpec)
        self.sub_stuff["image_name"] = None
        self.sub_stuff["container"] = None
        self.sub_stuff["containers"] = []

        docker_args = []
        docker_args += get_as_list(self.config["docker_daemon_args"])
        docker_args.append("-H %s" % bind_addr)
        self.loginfo("Starting %s %s", self.config["docker_path"], docker_args)
        dd = docker_daemon.start(self.config["docker_path"],
                                 docker_args)
        if not docker_daemon.output_match(dd):
            raise DockerTestNAError("Unable to start docker daemon:"
                                    "\n**STDOUT**:\n%s\n**STDERR**:\n%s" %
                                    (dd.get_stdout(), dd.get_stderr()))
        self.sub_stuff["docker_daemon"] = dd
Beispiel #23
0
 def initialize(self):
     super(create_base, self).initialize()
     self.sub_stuff['dkrcmd'] = None
     self.init_utilities()
     self.sub_stuff['subargs'] = get_as_list(self.config['run_options_csv'])
     self.init_name()
     self.init_subargs_imgcmd()
Beispiel #24
0
 def make_dockercmd(subtest, dockercmd_class, fqin,
                    run_template, cmd_tmplate, test_dict):
     # safe_substutute ignores unknown tokens
     subargs = get_as_list(str(run_template % test_dict), omit_empty=True)
     subargs.append(fqin)
     subargs.append(cmd_tmplate % test_dict)
     return dockercmd_class(subtest, 'run', subargs)
Beispiel #25
0
    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)
Beispiel #26
0
 def cleanup(self):
     super(diff_base, self).cleanup()
     if self.config['remove_after_test']:
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         if self.sub_stuff['name'] not in preserve_cnames:
             DockerCmd(self, 'rm', ['--force', '--volumes',
                                    self.sub_stuff['name']]).execute()
Beispiel #27
0
 def do_substitutions(self):
     # Some are CSV, some are regex, some are simple strings
     for key in ('subcmd', 'subarg', 'stderr', 'stdout'):
         # Ignore empty config values
         if self.config[key].strip() != '':
             # Catch misspellings / unsupported sutstitution keywords
             try:
                 value = self.config[key] % self.sub_stuff
             except KeyError as xcpt:
                 raise KeyError("Configuration error with option '%s' value"
                                "in sub-subtest %s: Invalid substitution "
                                "key '%s'" %
                                (key, self.config_section, xcpt.message))
         else:
             value = ''
         # pylint: disable=E0012,R0204
         if key == 'subarg':  # This is a CSV option
             if value.strip() == '':
                 value = []
             else:
                 value = config.get_as_list(value)
         elif key in ('stderr', 'stdout'):  # This is a regex
             if value.strip() == '':
                 value = None  # Signals bypass postprocess() check
             else:
                 value = re.compile(value.strip())
         # Record possibly modified value
         self.sub_stuff[key] = value
 def init_container(self, volume=None, volumes_from=None):
     """
     Starts container
     """
     subargs = config.get_as_list(self.config['run_options_csv'])
     if volume:
         subargs.append("--volume %s" % volume)
     if volumes_from:
         subargs.append("--volumes-from %s" % volumes_from)
     name = self.sub_stuff['dc'].get_unique_name()
     self.sub_stuff['containers'].append(name)
     subargs.append("--name %s" % name)
     fin = DockerImage.full_name_from_defaults(self.config)
     subargs.append(fin)
     subargs.append("sh")
     read_fd, write_fd = os.pipe()
     self.sub_stuff['fds'].append(write_fd)
     self.sub_stuff['fds'].append(read_fd)
     dkrcmd = dockercmd.AsyncDockerCmd(self, 'run', subargs)
     # TODO: Fix use of dkrcmd.stdin when appropriate class mech. available
     dkrcmd.execute(read_fd)
     dkrcmd.stdin = write_fd
     os.close(read_fd)  # no longer needed
     os.write(write_fd, 'echo "Started"\n')
     self.failif(not wait_for_output(lambda: dkrcmd.stdout,
                                     'Started',
                                     timeout=20),
                 "Error starting container %s: %s" % (name, dkrcmd))
     return dkrcmd
Beispiel #29
0
 def cleanup(self):
     super(cgroups_base, self).cleanup()
     if self.config['remove_after_test']:
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         for name in self.sub_stuff.get('name', []):
             if name not in preserve_cnames:
                 DockerCmd(self, 'rm', ['--force', name]).execute()
Beispiel #30
0
    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, verbose=False)
        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)
Beispiel #31
0
 def postprocess(self):
     # File in top-level 'results/default/sysinfo' directory
     with open(os.path.join(self.job.sysinfo.sysinfodir,
                            'docker_images'), 'w') as info_file:
         for img in self.stuff['di'].list_imgs():
             info_file.write("%s\n" % str(img))
             self.loginfo(str(img))
     # Hopefully not a TOCTOU race with initialize()
     if self.stuff['update'] and self.stuff['fqins']:
         # These /are/ the customized defaults, don't re-default them
         cfgsec = ConfigSection(dict(), 'DEFAULTS')
         # config.merge_write() can't work with DEFAULTS
         for key, value in list(Config.defaults_.items()):
             cfgsec.set(key, value)
         # This may not exist
         if cfgsec.has_option('preserve_fqins'):
             preserve_fqins = set(get_as_list(cfgsec.get('preserve_fqins')))
         else:
             preserve_fqins = set([])
         self.logdebug("Old preserve_fqins: %s", preserve_fqins)
         # Update the existing list
         preserve_fqins |= set(self.stuff['fqins'])
         # Convert back to CSV, value still in memory only
         cfgsec.set('preserve_fqins', ",".join(preserve_fqins))
         self.loginfo("Updated preserve_fqins: %s",
                      cfgsec.get('preserve_fqins'))
         # This will get picked up when next test executes
         cfgsec.write(open(self.stuff['defaults_ini'], 'w'))
         # Be kind to anyone debugging the contents
         msg = "\n# preserve_fqins modified by %s\n" % self.config_section
         open(self.stuff['defaults_ini'], 'a').write(msg)
     super(docker_test_images, self).postprocess()
Beispiel #32
0
    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
Beispiel #33
0
 def make_dockercmd(subtest, dockercmd_class, fqin, run_template,
                    cmd_tmplate, test_dict):
     # safe_substutute ignores unknown tokens
     subargs = get_as_list(str(run_template % test_dict), omit_empty=True)
     subargs.append(fqin)
     subargs.append(cmd_tmplate % test_dict)
     return dockercmd_class(subtest, 'run', subargs)
Beispiel #34
0
 def cleanup(self):
     super(create_base, self).cleanup()
     if self.config['remove_after_test']:
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         # One last cleanup try based on what is known
         if self.sub_stuff['name'] not in preserve_cnames:
             DockerCmd(self, 'rm', ['--force', '--volumes',
                                    self.sub_stuff['name']]).execute()
Beispiel #35
0
 def cleanup(self):
     super(Base, self).cleanup()
     if self.config['remove_after_test']:
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         for cntnr_name in self.sub_stuff['cntnr_names']:
             if cntnr_name in preserve_cnames:
                 continue
             DockerCmd(self, 'rm', ['--force', cntnr_name]).execute()
Beispiel #36
0
 def cleanup(self):
     super(run_twice, self).cleanup()
     if self.config['remove_after_test']:
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         cname = self.stuff['container_name']
         if cname not in preserve_cnames:
             DockerCmd(self, 'rm',
                       ['--force', '--volumes', cname]).execute()
Beispiel #37
0
 def docker_options(self):
     """
     String of docker args
     """
     # Defined in [DEFAULTS] guaranteed to exist
     opts = get_as_list(self.parent.config['docker_options_spec'])
     opts.append("-H %s" % self.parent.config['docker_client_bind'])
     return " ".join(opts)
Beispiel #38
0
 def cleanup(self):
     super(load, self).cleanup()
     if self.config['remove_after_test']:
         preserve_fqins = get_as_list(self.config['preserve_fqins'])
         test_fqin = self.config['test_fqin']
         if test_fqin in preserve_fqins:
             return
         DockerCmd(self, 'rmi', ['--force', test_fqin]).execute()
Beispiel #39
0
 def cleanup(self):
     super(run_twice, self).cleanup()
     if self.config['remove_after_test']:
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         cname = self.stuff['container_name']
         if cname not in preserve_cnames:
             DockerCmd(self, 'rm',
                       ['--force', '--volumes', cname]).execute()
Beispiel #40
0
 def cleanup(self):
     super(flag, self).cleanup()
     if self.config["remove_after_test"]:
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         cntnr = self.stuff["containter_name"]
         if cntnr not in preserve_cnames:
             DockerCmd(self, "rm",
                       ['--force', '--volumes', cntnr]).execute()
Beispiel #41
0
 def cleanup(self):
     super(load, self).cleanup()
     if self.config['remove_after_test']:
         preserve_fqins = get_as_list(self.config['preserve_fqins'])
         test_fqin = self.config['test_fqin']
         if test_fqin in preserve_fqins:
             return
         DockerCmd(self, 'rmi', ['--force', test_fqin]).execute()
 def init_subargs_imgcmd(self):
     if self.config["remote_image_fqin"] == "":
         raise error.TestNAError("Unable to prepare env for test:"
                                 "create_remote_tag/remote_image_fqin has "
                                 "to be set to functional repo address.")
     self.sub_stuff['subargs'].append(self.config["remote_image_fqin"])
     self.sub_stuff['subargs'] += get_as_list(self.config['bash_cmd'])
     self.sub_stuff['subargs'].append(self.config['cmd'])
Beispiel #43
0
 def init_targets(self):
     sss = self.sub_stuff
     target_setups = get_as_list(self.config['target_setups'])
     # Single values will auto-convert to int's, convert back to string
     target_waits = get_as_list(str(self.config['target_waits']))
     target_sleeps = get_as_list(str(self.config['target_sleeps']))
     fqin = sss['di'].full_name_from_defaults()
     for index, setup in enumerate(target_setups):
         name = sss['dc'].get_unique_name(setup)
         sleep = float(target_sleeps[index])
         wait_opr = target_waits[index].lower()
         wait_dkr = self.target_wait_dkrcmd(name, fqin,
                                            setup, wait_opr.lower(), sleep)
         target = Target(name=name, fqin=fqin,
                         setup=setup.lower(),
                         wait=wait_dkr, sleep=sleep)
         sss['targets'][target] = self.target_dkrcmd(target)
Beispiel #44
0
 def cleanup(self):
     super(diff_base, self).cleanup()
     if self.config['remove_after_test']:
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         if self.sub_stuff['name'] not in preserve_cnames:
             DockerCmd(self, 'rm',
                       ['--force', '--volumes', self.sub_stuff['name']
                        ]).execute()
 def init_subargs_imgcmd(self):
     if self.config["remote_image_fqin"] == "":
         raise error.TestNAError("Unable to prepare env for test:"
                                 "create_remote_tag/remote_image_fqin has "
                                 "to be set to functional repo address.")
     self.sub_stuff['subargs'].append(self.config["remote_image_fqin"])
     self.sub_stuff['subargs'] += get_as_list(self.config['bash_cmd'])
     self.sub_stuff['subargs'].append(self.config['cmd'])
Beispiel #46
0
 def initialize(self):
     self.record_iptables('initial')
     self.logdebug('Restarting docker daemon w/ --icc=false')
     daemon_options = get_as_list(self.config['daemon_options'])
     daemon_options.append('--icc=false')
     self.sub_stuff['dd'] = docker_daemon.start(self.config['docker_path'],
                                                daemon_options)
     self.failif(not docker_daemon.output_match(self.sub_stuff['dd']))
     super(rm_link, self).initialize()
Beispiel #47
0
 def initialize(self):
     self.record_iptables('initial')
     self.logdebug('Restarting docker daemon w/ --icc=false')
     daemon_options = get_as_list(self.config['daemon_options'])
     daemon_options.append('--icc=false')
     self.sub_stuff['dd'] = docker_daemon.start(self.config['docker_path'],
                                                daemon_options)
     self.failif(not docker_daemon.output_match(self.sub_stuff['dd']))
     super(rm_link, self).initialize()
Beispiel #48
0
 def cleanup(self):
     super(Base, self).cleanup()
     if self.config['remove_after_test']:
         preserve_cnames = get_as_list(self.config['preserve_cnames'])
         for cntnr_name in self.sub_stuff['cntnr_names']:
             if cntnr_name in preserve_cnames:
                 continue
             DockerCmd(self, 'rm',
                       ['--force', cntnr_name]).execute()
Beispiel #49
0
 def initialize(self):
     super(volumes_rw, self).initialize()
     host_paths = get_as_list(self.config['host_paths'])
     cntr_paths = get_as_list(self.config['cntr_paths'])
     if len(host_paths) != len(cntr_paths):
         raise DockerTestNAError("Configuration option host_paths CSV list "
                                 "must exactly match length of cntr_paths. "
                                 "'%s' != '%s'" % (host_paths, cntr_paths))
     if len(host_paths) < 1:
         raise DockerTestNAError("Configuration options host_paths and "
                                 "cntr_paths CSV lists are empty")
     # list of substitution dictionaries for each container
     path_info = self.sub_stuff['path_info'] = []
     # Throws DockerTestNAError if any host_paths is bad
     self.init_path_info(path_info, host_paths, cntr_paths, self.tmpdir)
     dockercmds = self.sub_stuff['dockercmds'] = []
     self.sub_stuff['cmdresults'] = []
     # Does not execute()
     self.init_dkrcmds(self, path_info, dockercmds)
Beispiel #50
0
    def cleanup(self):
        if "docker_options_spec_good" in self.config:
            dos = " ".join(get_as_list(self.config['docker_options_spec_good']))
            self.conts.interface.docker_options_spec = dos
        # Avoid warning about not exist container.
        c1 = self.conts.list_containers_with_name(self.sub_stuff["cont1_name"])
        if c1 != []:
            self.sub_stuff["containers"].remove(self.sub_stuff["cont1_name"])

        tls_verify_all_base.cleanup(self)
Beispiel #51
0
 def init_targets(self):
     sss = self.sub_stuff
     target_setups = get_as_list(self.config['target_setups'])
     # Single values will auto-convert to int's, convert back to string
     target_waits = get_as_list(str(self.config['target_waits']))
     target_sleeps = get_as_list(str(self.config['target_sleeps']))
     fqin = sss['di'].full_name_from_defaults()
     for index, setup in enumerate(target_setups):
         name = sss['dc'].get_unique_name(setup)
         sleep = float(target_sleeps[index])
         wait_opr = target_waits[index].lower()
         wait_dkr = self.target_wait_dkrcmd(name, fqin, setup,
                                            wait_opr.lower(), sleep)
         target = Target(name=name,
                         fqin=fqin,
                         setup=setup.lower(),
                         wait=wait_dkr,
                         sleep=sleep)
         sss['targets'][target] = self.target_dkrcmd(target)
 def initialize(self):
     super(volumes_rw, self).initialize()
     host_paths = get_as_list(self.config['host_paths'])
     cntr_paths = get_as_list(self.config['cntr_paths'])
     if len(host_paths) != len(cntr_paths):
         raise DockerTestNAError("Configuration option host_paths CSV list "
                                 "must exactly match length of cntr_paths. "
                                 "'%s' != '%s'" % (host_paths, cntr_paths))
     if len(host_paths) < 1:
         raise DockerTestNAError("Configuration options host_paths and "
                                 "cntr_paths CSV lists are empty")
     # list of substitution dictionaries for each container
     path_info = self.sub_stuff['path_info'] = []
     # Throws DockerTestNAError if any host_paths is bad
     self.init_path_info(path_info, host_paths, cntr_paths, self.tmpdir)
     dockercmds = self.sub_stuff['dockercmds'] = []
     self.sub_stuff['cmdresults'] = []
     # Does not execute()
     self.init_dkrcmds(self, path_info, dockercmds)
 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)
Beispiel #54
0
 def run_once(self):
     super(builder, self).run_once()
     if None in self.parent_subtest.stuff['build']:
         return
     subopts = get_as_list(self.config.get('build_opts_csv', []))
     stuff = self.parent_subtest.stuff
     # Someday we might support building more than one
     for name, dockerfile in list(stuff['build'].items()):
         this_subopts = subopts + ['-t', name, dockerfile]
         mustpass(DockerCmd(self, 'build', this_subopts).execute())
         stuff['fqins'] += list(stuff['build'].keys())
Beispiel #55
0
    def initialize(self):
        super(Base, self).initialize()
        self.step_log_msgs = {}
        self.sub_stuff['dc'] = DockerContainers(self)
        self.sub_stuff['di'] = di = DockerImages(self)
        di.DICLS = DockerImageIncomplete

        default_image = self.fuzzy_img(di.default_image)
        self.sub_stuff['default_image'] = default_image

        # Can't use set of DockerImageIncomplete -> it's mutable
        preserve_images = [default_image]
        for fqin_or_id in get_as_list(self.config['preserve_fqins']):
            preserve_images.append(self.fuzzy_img(fqin_or_id))
        self.sub_stuff['preserve_images'] = preserve_images

        preserve_cnames = set(get_as_list(self.config['preserve_cnames']))
        self.sub_stuff['preserve_cnames'] = preserve_cnames
        self.sub_stuff['fail_containers'] = False
        self.sub_stuff['fail_images'] = False
Beispiel #56
0
 def target_dkrcmd(self, target):
     # Validate setup command
     if target.setup == 'none':
         return None
     elif target.setup == 'run':
         command = 'run'
     elif target.setup == 'create':
         command = 'create'
     else:
         raise ValueError("Unsupported target setup string: "
                          "%s" % target.setup)
     subargs = get_as_list(self.config['target_run'])
     subargs.append('--name')
     subargs.append(target.name)
     subargs.append(target.fqin)
     target_cmd = self.config['target_cmd'].replace('@SLEEP@',
                                                    str(target.sleep))
     subargs += get_as_list(target_cmd)
     timeout = self.config['target_timeout']
     return DockerCmd(self, command, subargs, timeout=timeout)