예제 #1
0
 def _init_test_depenent(self):
     uid = False
     uids = []
     for line in self.parent_subtest.stuff['passwd'].splitlines():
         line = line.strip()
         try:
             uids.append(int(line.split(':', 3)[2]))
         except (IndexError, TypeError):
             pass
     for i in xrange(1, 2147483647):
         if i not in uids:
             uid = i
             break
     if uid is False:
         msg = ("This container's image passwd occupies all uids. Unable to"
                " execute this test\n%s" %
                self.parent_subtest.stuff['passwd'])
         raise xceptions.DockerTestNAError(msg)
     self.sub_stuff['execution_failure'] = False
     self.sub_stuff['uid_check'] = "UIDCHECK: %s:" % uid
     self.sub_stuff['whoami_check'] = ("whoami: cannot find name for user "
                                       "ID %s" % uid)
     self.sub_stuff['subargs'] = [
         '--rm', '--interactive',
         '--user=%s' % uid
     ]
예제 #2
0
 def init_test_container(self, name):
     self.sub_stuff["subargs"].insert(0, "--name=\"%s\"" % name)
     dkrcmd = DockerCmd(self, 'run', self.sub_stuff['subargs'],
                        timeout=self.config['docker_timeout'])
     dkrcmd.verbose = True
     cmdresult = dkrcmd.execute()
     if cmdresult.exit_status != 0:
         xceptions.DockerTestNAError("Unable to prepare env for test: %s" %
                                     (cmdresult))
     cid = self.sub_stuff["cont"].list_containers_with_name(name)
     self.failif(cid == [],
                 "Unable to search container with name %s: details :%s" %
                 (name, cmdresult))
예제 #3
0
    def create_image(self, old_name, new_name, cmd):
        prep_changes = DockerCmd(self, "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, "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)
예제 #4
0
    def initialize(self):
        super(restart_base, self).initialize()
        config.none_if_empty(self.config)
        self.sub_stuff['container_id'] = None
        self.sub_stuff['restart_cmd'] = None
        self.sub_stuff['stop_cmd'] = None
        self.sub_stuff['restart_result'] = None
        self.sub_stuff['stop_result'] = None

        containers = DockerContainers(self)

        # Container
        if self.config.get('run_options_csv'):
            subargs = [
                arg for arg in self.config['run_options_csv'].split(',')
            ]
        else:
            subargs = []
        image = DockerImage.full_name_from_defaults(self.config)
        subargs.append(image)
        subargs.append("bash")
        subargs.append("-c")
        subargs.append(self.config['exec_cmd'])
        container = DockerCmd(self, 'run', subargs, timeout=240)
        cont_id = mustpass(container.execute()).stdout.strip()
        self.sub_stuff['container_id'] = cont_id
        container = containers.list_containers_with_cid(cont_id)
        if container == []:
            raise xceptions.DockerTestNAError(
                "Fail to get docker with id: %s" % cont_id)

        # Prepare the "restart" command
        if self.config.get('restart_options_csv'):
            subargs = [
                arg for arg in self.config['restart_options_csv'].split(',')
            ]
        else:
            subargs = []
        subargs.append(cont_id)
        self.sub_stuff['restart_cmd'] = DockerCmd(self, 'restart', subargs)

        # Prepare the "stop" command
        if self.config.get('stop_options_csv'):
            subargs = [
                arg for arg in self.config['stop_options_csv'].split(',')
            ]
        else:
            subargs = []
        subargs.append(cont_id)
        self.sub_stuff['stop_cmd'] = DockerCmd(self, 'stop', subargs)
예제 #5
0
 def initialize(self):
     """
     Runs one container
     """
     super(selinux_base, self).initialize()
     if utils.run("selinuxenabled", 10, True).exit_status:
         raise xceptions.DockerTestNAError("Selinux not enabled on this "
                                           "machine.")
     # Substuff
     config.none_if_empty(self.config)
     self.sub_stuff['dc'] = DockerContainers(self)
     self.sub_stuff['containers'] = []
     self.sub_stuff['volumes'] = set()
     self.sub_stuff['fds'] = []
예제 #6
0
    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
예제 #7
0
 def init_subcntrs(self):
     # Called from init_substitutions
     cntr = dockercmd.AsyncDockerCmd(
         self, 'run', ['--detach', self.sub_stuff['FQIN'], 'sleep 5m'])
     cntr.execute()
     # cntr.stdout is a property
     if output.wait_for_output(lambda: cntr.stdout, r'^\w{64}$'):
         self.sub_stuff['RUNCNTR'] = cntr.stdout.splitlines()[-1].strip()
     else:
         raise xceptions.DockerTestNAError("Failed to initialize %s" %
                                           self.config_section)
     # Throw away cntr, all we need is the CID
     result = mustpass(
         dockercmd.DockerCmd(
             self, 'run',
             ['--detach', self.sub_stuff['FQIN'], 'true']).execute())
     # Only the CID is needed
     self.sub_stuff['STPCNTR'] = result.stdout.splitlines()[-1].strip()
예제 #8
0
 def _init_test_depenent(self):
     user = None
     for line in self.parent_subtest.stuff['passwd'].splitlines():
         line = line.strip()
         if not line or line.startswith('root') or line.startswith('#'):
             continue
         user, _, uid, _ = line.split(':', 3)
         break
     if not user:
         msg = ("This container's image doesn't contain passwd with "
                "multiple users, unable to execute this test\n%s" %
                self.parent_subtest.stuff['passwd'])
         raise xceptions.DockerTestNAError(msg)
     self.sub_stuff['execution_failure'] = False
     self.sub_stuff['uid_check'] = "UIDCHECK: %s:" % uid
     self.sub_stuff['whoami_check'] = "WHOAMICHECK: %s" % user
     self.sub_stuff['subargs'] = [
         '--rm', '--interactive',
         '--user=%s' % uid
     ]
예제 #9
0
    def initialize(self):
        super(commit_base, self).initialize()
        config.none_if_empty(self.config)
        di = DockerImages(self)
        new_img_name = di.get_unique_name()
        self.sub_stuff["new_image_name"] = new_img_name

        self.sub_stuff['rand_data'] = utils.generate_random_string(8)
        cmd_with_rand = (self.config['docker_data_prepare_cmd'] %
                         self.sub_stuff['rand_data'])

        fqin = DockerImage.full_name_from_defaults(self.config)
        prep_changes = DockerCmd(self, "run",
                                 ["--detach", fqin, cmd_with_rand],
                                 self.config['docker_commit_timeout'])

        results = prep_changes.execute()
        if results.exit_status:
            raise xceptions.DockerTestNAError(
                "Problems during "
                "initialization of"
                " test: %s", results)
        else:
            self.sub_stuff["container"] = results.stdout.strip()