Esempio n. 1
0
 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
Esempio n. 2
0
 def cleanup(self):
     super(build, self).cleanup()
     # Auto-converts "yes/no" to a boolean
     if (self.config['try_remove_after_test'] and
                                          self.stuff.has_key('image_id')):
         di = DockerImages(self)
         di.remove_image_by_id(self.stuff['image_id'])
         di.remove_image_by_full_name("empty_base_image")
         self.loginfo("Successfully removed test images")
     else:
         self.loginfo("NOT removing image")
Esempio n. 3
0
 def cleanup(self):
     super(tag_base, self).cleanup()
     # Auto-converts "yes/no" to a boolean
     if self.config['remove_after_test'] and 'image_list' in self.sub_stuff:
         for image in self.sub_stuff["image_list"]:
             di = DockerImages(self.parent_subtest)
             self.logdebug("Removing image %s", image.full_name)
             try:
                 di.remove_image_by_full_name(image.full_name)
             except error.CmdError, e:
                 err = e.result_obj.stderr
                 if "tagged in multiple repositories" not in err:
                     raise
             self.loginfo("Successfully removed test image: %s",
                          image.full_name)
Esempio n. 4
0
 def cleanup(self):
     super(build, self).cleanup()
     # Auto-converts "yes/no" to a boolean
     if self.config['try_remove_after_test']:
         dc = DockerContainers(self)
         for cid in dc.list_container_ids():
             dcmd = DockerCmd(self, 'rm', ['--force', '--volumes', cid])
             dcmd.execute()
         di = DockerImages(self)
         if self.stuff.get('image_id') is not None:
             di.remove_image_by_id(self.stuff['image_id'])
         di.remove_image_by_full_name("empty_base_image")
         self.loginfo("Successfully removed test images")
     else:
         self.loginfo("NOT removing image")
Esempio n. 5
0
 def cleanup(self):
     super(rmi_base, self).cleanup()
     di = DockerImages(self.parent_subtest)
     # Auto-converts "yes/no" to a boolean
     if (self.config['remove_after_test'] and
             'image_list' in self.sub_stuff):
         for cont in self.sub_stuff["containers"]:
             clean_cont = NoFailDockerCmd(self, "rm",
                                          ['--force', cont],
                                          self.config['docker_rmi_timeout'])
             clean_cont.execute()
         for image in self.sub_stuff["image_list"]:
             # If removal by name fails, try id
             try:
                 try:
                     di.remove_image_by_full_name(image.full_name)
                 except DockerCommandError:
                     di.remove_image_by_id(image.long_id)
             except DockerCommandError:
                 self.logwarning("Image not exist or failed"
                                 " to remove image.")
             self.loginfo("Successfully removed test image")
Esempio n. 6
0
    def run_once(self):
        fqin = self.sub_stuff['fqin']
        di = DockerImages(self.parent_subtest)
        try:
            di.remove_image_by_full_name(fqin)
        except error.CmdError:
            pass  # removal was the goal
        images = di.list_imgs_with_full_name(fqin)
        if images != []:
            error.TestNAError("Unable to prepare env for test:"
                              " image %s already/still"
                              " exist in docker repository", fqin)

        self.logdebug("Existing images: %s", di.list_imgs_full_name())
        self.loginfo("Executing test commands")

        self.run_command('run', self.sub_stuff['subargs'],
                         'cmdresult_run1')

        self.run_command('rm', [self.sub_stuff["rand_name"]],
                         'cmdresult_rm')

        self.run_command('tag',
                         [fqin, self.sub_stuff["rand_name"].lower()],
                         'cmdresult_tag')

        self.run_command('rmi',
                         [fqin],
                         'cmdresult_rmi')

        self.run_command('run', self.sub_stuff['subargs'],
                         'cmdresult_run2')

        self.run_command('rm', [self.sub_stuff["rand_name"]],
                         'cmdresult_rm2')

        self.run_command('rmi',
                         [self.sub_stuff["rand_name"].lower()],
                         'cmdresult_rmi2')
Esempio n. 7
0
 def cleanup(self):
     super(run_base, self).cleanup()
     # Auto-converts "yes/no" to a boolean
     if self.config['remove_after_test']:
         for cont in self.sub_stuff.get("containers", []):
             dkrcmd = DockerCmd(self.parent_subtest, "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.get("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 error.CmdError, e:
                 error_text = "tagged in multiple repositories"
                 if not error_text in e.result_obj.stderr:
                     raise
Esempio n. 8
0
class tag_base(SubSubtest):

    """ tag base class """

    def __init__(self, *args, **kwargs):
        super(tag_base, self).__init__(*args, **kwargs)
        self.dkrimg = DockerImages(self.parent_subtest)
        self.sub_stuff['tmp_image_list'] = set()

    def get_images_by_name(self, full_name):
        """ :return: List of images with given name """
        return self.dkrimg.list_imgs_with_full_name(full_name)

    def prep_image(self, base_image):
        """ Tag the dockertest image to this test name """
        NoFailDockerCmd(self, "pull", [base_image], verbose=False).execute()
        subargs = [base_image, self.sub_stuff["image"]]
        tag_results = DockerCmd(self, "tag", subargs, verbose=False).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

    def initialize(self):
        super(tag_base, self).initialize()
        config.none_if_empty(self.config)
        self.dkrimg.gen_lower_only = self.config['gen_lower_only']
        new_img_name = self.dkrimg.get_unique_name()
        self.sub_stuff["image"] = new_img_name
        base_image = DockerImage.full_name_from_defaults(self.config)
        self.prep_image(base_image)

    def complete_docker_command_line(self):
        """ :return: tag subargs using new_image_name """
        force = self.config["tag_force"]

        cmd = []
        if force:
            cmd.append("-f")

        cmd.append(self.sub_stuff["image"])
        cmd.append(self.sub_stuff["new_image_name"])
        self.sub_stuff["tag_cmd"] = cmd
        return cmd

    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 postprocess(self):
        super(tag_base, self).postprocess()
        if self.config["docker_expected_result"] == "PASS":
            # Raise exception if problems found
            OutputGood(self.sub_stuff['cmdresult'])
            self.failif(self.sub_stuff['cmdresult'].exit_status != 0,
                        "Non-zero tag exit status: %s"
                        % self.sub_stuff['cmdresult'])

            img = self.get_images_by_name(self.sub_stuff["new_image_name"])
            # Needed for cleanup
            self.sub_stuff['image_list'] += img
            self.failif(len(img) < 1,
                        "Failed to look up tagted image ")

        elif self.config["docker_expected_result"] == "FAIL":
            chck = OutputGood(self.sub_stuff['cmdresult'], ignore_error=True)
            exit_code = self.sub_stuff['cmdresult'].exit_status
            self.failif(not chck or not exit_code,
                        "Zero tag exit status: Command should fail due to"
                        " wrong command arguments.")
        else:
            self.failif(True, "Improper 'docker_expected_result' value %s"
                        % self.config["docker_expected_result"])

    def cleanup(self):
        super(tag_base, self).cleanup()
        # Auto-converts "yes/no" to a boolean
        if self.config['remove_after_test'] and 'image_list' in self.sub_stuff:
            for image in self.sub_stuff["image_list"]:
                self.logdebug("Removing image %s", image.full_name)
                try:
                    self.dkrimg.remove_image_by_full_name(image.full_name)
                except error.CmdError, exc:
                    err = exc.result_obj.stderr
                    if "tagged in multiple repositories" not in err:
                        raise
                self.loginfo("Successfully removed test image: %s",
                             image.full_name)
            for image in self.sub_stuff['tmp_image_list']:
                image = self.get_images_by_name(image)
                if image:
                    self.logdebug("Removing image %s", image[0].full_name)
                    self.dkrimg.remove_image_by_full_name(image[0].full_name)
                    self.loginfo("Successfully removed test image: %s",
                                 image[0].full_name)
Esempio n. 9
0
class tag_base(SubSubtest):

    """ tag base class """

    def __init__(self, *args, **kwargs):
        super(tag_base, self).__init__(*args, **kwargs)
        self.dkrimg = DockerImages(self)
        self.sub_stuff['tmp_image_list'] = set()
        self._expect_pass = True

    def expect_pass(self, set_to=None):
        """
         Most of the time we expect our 'docker tag' command to succeed.
         This method can be used (as a setter) to set an explicit expectation
         or (as a getter) when checking results.
        """
        if set_to is not None:
            self._expect_pass = set_to
        return self._expect_pass

    def get_images_by_name(self, full_name):
        """ :return: List of images with given name """
        return self.dkrimg.list_imgs_with_full_name(full_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

    def initialize(self):
        super(tag_base, self).initialize()
        config.none_if_empty(self.config)
        self.dkrimg.gen_lower_only = self.config['gen_lower_only']
        new_img_name = self.dkrimg.get_unique_name()
        self.sub_stuff["image"] = new_img_name
        base_image = DockerImage.full_name_from_defaults(self.config)
        self.prep_image(base_image)

    def complete_docker_command_line(self):
        """ :return: tag subargs using new_image_name """
        cmd = []
        if 'force_tag' in self.sub_stuff and self.sub_stuff['force_tag']:
            cmd.append("-f")

        cmd.append(self.sub_stuff["image"])
        cmd.append(self.sub_stuff["new_image_name"])
        self.sub_stuff["tag_cmd"] = cmd
        return cmd

    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 postprocess(self):
        super(tag_base, self).postprocess()
        expect_pass = self.expect_pass()
        OutputGood(self.sub_stuff['cmdresult'], ignore_error=not expect_pass)
        if expect_pass:
            # Raise exception if problems found
            self.failif_ne(self.sub_stuff['cmdresult'].exit_status, 0,
                           "Non-zero tag exit status: %s"
                           % self.sub_stuff['cmdresult'])

            img = self.get_images_by_name(self.sub_stuff["new_image_name"])
            # Needed for cleanup
            self.sub_stuff['image_list'] += img
            self.failif(len(img) < 1,
                        "Failed to look up tagged image ")

        else:
            self.failif(self.sub_stuff['cmdresult'].exit_status == 0,
                        "Was expecting tag command to fail, but it exited OK")

    def cleanup(self):
        super(tag_base, self).cleanup()
        # Auto-converts "yes/no" to a boolean
        if self.config['remove_after_test'] and 'image_list' in self.sub_stuff:
            for image in self.sub_stuff["image_list"]:
                self.logdebug("Removing image %s", image.full_name)
                try:
                    self.dkrimg.remove_image_by_full_name(image.full_name)
                except error.CmdError, exc:
                    err = exc.result_obj.stderr
                    if "tagged in multiple repositories" not in err:
                        raise
                self.loginfo("Successfully removed test image: %s",
                             image.full_name)
            for image_name in self.sub_stuff['tmp_image_list']:
                image = self.get_images_by_name(image_name)
                if image:
                    self.logdebug("Removing tmp image %s", image[0].full_name)
                    self.dkrimg.remove_image_by_full_name(image[0].full_name)
                    self.loginfo("Successfully removed test image: %s",
                                 image[0].full_name)
Esempio n. 10
0
class tag_base(SubSubtest):
    """ tag base class """
    def __init__(self, *args, **kwargs):
        super(tag_base, self).__init__(*args, **kwargs)
        self.dkrimg = DockerImages(self)
        self.sub_stuff['tmp_image_list'] = set()
        self._expect_pass = True

    def expect_pass(self, set_to=None):
        """
         Most of the time we expect our 'docker tag' command to succeed.
         This method can be used (as a setter) to set an explicit expectation
         or (as a getter) when checking results.
        """
        if set_to is not None:
            self._expect_pass = set_to
        return self._expect_pass

    def get_images_by_name(self, full_name):
        """ :return: List of images with given name """
        return self.dkrimg.list_imgs_with_full_name(full_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

    def initialize(self):
        super(tag_base, self).initialize()
        config.none_if_empty(self.config)
        self.dkrimg.gen_lower_only = self.config['gen_lower_only']
        new_img_name = self.dkrimg.get_unique_name()
        self.sub_stuff["image"] = new_img_name
        base_image = DockerImage.full_name_from_defaults(self.config)
        self.prep_image(base_image)

    def complete_docker_command_line(self):
        """ :return: tag subargs using new_image_name """
        cmd = []
        if 'force_tag' in self.sub_stuff and self.sub_stuff['force_tag']:
            cmd.append("-f")

        cmd.append(self.sub_stuff["image"])
        cmd.append(self.sub_stuff["new_image_name"])
        self.sub_stuff["tag_cmd"] = cmd
        return cmd

    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 postprocess(self):
        super(tag_base, self).postprocess()
        expect_pass = self.expect_pass()
        OutputGood(self.sub_stuff['cmdresult'], ignore_error=not expect_pass)
        if expect_pass:
            # Raise exception if problems found
            self.failif_ne(
                self.sub_stuff['cmdresult'].exit_status, 0,
                "Non-zero tag exit status: %s" % self.sub_stuff['cmdresult'])

            img = self.get_images_by_name(self.sub_stuff["new_image_name"])
            # Needed for cleanup
            self.sub_stuff['image_list'] += img
            self.failif(len(img) < 1, "Failed to look up tagged image ")

        else:
            self.failif(self.sub_stuff['cmdresult'].exit_status == 0,
                        "Was expecting tag command to fail, but it exited OK")

    def cleanup(self):
        super(tag_base, self).cleanup()
        # Auto-converts "yes/no" to a boolean
        if self.config['remove_after_test'] and 'image_list' in self.sub_stuff:
            for image in self.sub_stuff["image_list"]:
                self.logdebug("Removing image %s", image.full_name)
                try:
                    self.dkrimg.remove_image_by_full_name(image.full_name)
                except error.CmdError, exc:
                    err = exc.result_obj.stderr
                    if "tagged in multiple repositories" not in err:
                        raise
                self.loginfo("Successfully removed test image: %s",
                             image.full_name)
            for image_name in self.sub_stuff['tmp_image_list']:
                image = self.get_images_by_name(image_name)
                if image:
                    self.logdebug("Removing tmp image %s", image[0].full_name)
                    self.dkrimg.remove_image_by_full_name(image[0].full_name)
                    self.loginfo("Successfully removed test image: %s",
                                 image[0].full_name)
Esempio n. 11
0
class tag_base(SubSubtest):
    """ tag base class """
    def __init__(self, *args, **kwargs):
        super(tag_base, self).__init__(*args, **kwargs)
        self.dkrimg = DockerImages(self)
        self.sub_stuff['tmp_image_list'] = set()

    def get_images_by_name(self, full_name):
        """ :return: List of images with given name """
        return self.dkrimg.list_imgs_with_full_name(full_name)

    def prep_image(self, base_image):
        """ Tag the dockertest image to this test name """
        mustpass(
            DockerCmd(self, "pull", [base_image], verbose=False).execute())
        subargs = [base_image, self.sub_stuff["image"]]
        tag_results = DockerCmd(self, "tag", subargs, verbose=False).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

    def initialize(self):
        super(tag_base, self).initialize()
        config.none_if_empty(self.config)
        self.dkrimg.gen_lower_only = self.config['gen_lower_only']
        new_img_name = self.dkrimg.get_unique_name()
        self.sub_stuff["image"] = new_img_name
        base_image = DockerImage.full_name_from_defaults(self.config)
        self.prep_image(base_image)

    def complete_docker_command_line(self):
        """ :return: tag subargs using new_image_name """
        force = self.config["tag_force"]

        cmd = []
        if force:
            cmd.append("-f")

        cmd.append(self.sub_stuff["image"])
        cmd.append(self.sub_stuff["new_image_name"])
        self.sub_stuff["tag_cmd"] = cmd
        return cmd

    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 postprocess(self):
        super(tag_base, self).postprocess()
        if self.config["docker_expected_result"] == "PASS":
            # Raise exception if problems found
            OutputGood(self.sub_stuff['cmdresult'])
            self.failif(
                self.sub_stuff['cmdresult'].exit_status != 0,
                "Non-zero tag exit status: %s" % self.sub_stuff['cmdresult'])

            img = self.get_images_by_name(self.sub_stuff["new_image_name"])
            # Needed for cleanup
            self.sub_stuff['image_list'] += img
            self.failif(len(img) < 1, "Failed to look up tagted image ")

        elif self.config["docker_expected_result"] == "FAIL":
            chck = OutputGood(self.sub_stuff['cmdresult'], ignore_error=True)
            exit_code = self.sub_stuff['cmdresult'].exit_status
            self.failif(
                not chck or not exit_code,
                "Zero tag exit status: Command should fail due to"
                " wrong command arguments.")
        else:
            self.failif(
                True, "Improper 'docker_expected_result' value %s" %
                self.config["docker_expected_result"])

    def cleanup(self):
        super(tag_base, self).cleanup()
        # Auto-converts "yes/no" to a boolean
        if self.config['remove_after_test'] and 'image_list' in self.sub_stuff:
            for image in self.sub_stuff["image_list"]:
                self.logdebug("Removing image %s", image.full_name)
                try:
                    self.dkrimg.remove_image_by_full_name(image.full_name)
                except error.CmdError, exc:
                    err = exc.result_obj.stderr
                    if "tagged in multiple repositories" not in err:
                        raise
                self.loginfo("Successfully removed test image: %s",
                             image.full_name)
            for image in self.sub_stuff['tmp_image_list']:
                image = self.get_images_by_name(image)
                if image:
                    self.logdebug("Removing image %s", image[0].full_name)
                    self.dkrimg.remove_image_by_full_name(image[0].full_name)
                    self.loginfo("Successfully removed test image: %s",
                                 image[0].full_name)