Example #1
0
    def test_progress_estimate_with_size(self):
        '''Test progress estimate value when size is pre-calculated  exists
        '''
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc")
        path = Dir(src_path)
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = ["./"]
        size_to_transfer = dir_size(src_path)
        self.tr_node.size = str(size_to_transfer)

        progress_estimate = self.tr_cpio.get_progress_estimate()
        expect_estimate = \
            int((float(size_to_transfer / 1024) / self.tr_cpio.DEFAULT_SIZE) \
                * self.tr_cpio.DEFAULT_PROG_EST)

        self.assertEqual(progress_estimate, expect_estimate)
    def test_cpio_non_default_args_set(self):
        '''Test copying a list of directories and files succeeds'''
        # Copy all the directories and files from /etc/X11 and /etc/zones
        # to /rpool/cpio_test_dir using a list for the contents

        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        args = Args({"cpio_args": "-n -d -pdum"})
        self.tr_node.insert_children([args])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        self.TEST_CONTENTS_LIST.append("bin/xclock")
        self.TEST_CONTENTS_LIST.append("bin/pv.sh")

        # The CPIO values that are specified
        self.TEST_CONTENTS_LIST.append("etc/X11")
        self.TEST_CONTENTS_LIST.append("etc/zones")
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_CONTENTS_LIST

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #3
0
    def test_media_transform(self):
        '''Test media transform functionality'''
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11")
        path = Dir(src_path)
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "transform"
        self.tr_node.contents = self.TEST_MEDIA_TRANSFORM
        with open(self.TEST_MEDIA_TRANSFORM, 'w') as filehandle:
            filehandle.write("#!/usr/bin/python\n")
            filehandle.write("import os\n")
            mkdir_cmd = "os.mkdir('" + self.TEST_DST_DIR + "')"
            filehandle.write(mkdir_cmd + "\n")
            mkdir_cmd = "os.mkdir('" + os.path.join(self.TEST_DST_DIR,
                                                    "media") + "')"
            filehandle.write(mkdir_cmd)
        os.chmod(self.TEST_MEDIA_TRANSFORM, 0777)
        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
    def test_cpio_w_file_list(self):
        '''Test copy from a list succeeds'''
        # Copy /bin/xclock and /bin/pv.sh to /rpool/cpio_test_dir
        # using a file list as the contents source

        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.TEST_CONTENTS_LIST.append("bin/xclock")
        self.TEST_CONTENTS_LIST.append("bin/pv.sh")

        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_CONTENTS_LIST

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
    def test_cpio_w_dir_list_file(self):
        '''Test directory cpio copy succeeds'''
        # Copy all the directories and files from /etc/X11 and /etc/zones
        # to /rpool/cpio_test_dir using a file for the contents

        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_DIR_LIST_FILE
        with open(self.TEST_DIR_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/X11" + "\n")
            filehandle.write("etc/zones" + "\n")

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
    def test_cpio_w_file_list_file(self):
        '''Test copy of a file list file succeeds'''
        # Copy /bin/xclock and /bin/pv.sh to /rpool/cpio_test_dir
        # using a file list file as the contents souce

        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_FILE_LIST_FILE
        with open(self.TEST_FILE_LIST_FILE, 'w') as filehandle:
            filehandle.write("bin/xclock" + "\n")
            filehandle.write("bin/pv.sh" + "\n")

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
    def test_cleanup_temp_files(self):
        '''Test the cleanup of the temporary files'''
        # Set up the source
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11")
        path = Dir(src_path)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = ["./"]

        self.tr_cpio._parse_input()
        try:
            self.tr_cpio._cleanup_tmp_files()
        except Exception as err:
            self.fail(str(err))
    def test_source_replacement(self):
        '''Test that replacing a source succeeds'''
        # Setup an IPS image
        src = Source()
        pub = Publisher("opensolaris.org")
        origin = Origin("http://ipkg.sfbay.sun.com/release/")
        pub2 = Publisher("extra")
        origin2 = Origin("http://ipkg.sfbay.sun.com/extra/")
        pub2.insert_children([origin2])
        pub.insert_children([origin])
        src.insert_children([pub, pub2])
        self.soft_node.insert_children([src])
        try:
            self.tr_ips.execute(dry_run=DRY_RUN)
        except Exception as err:
            self.fail(str(err))

        # Create a new transaction with a differnt publisher/origin.
        # Specify to update the image created above.
        self.soft_node = Software("IPS post install")
        self.doc.insert_children([self.soft_node])
        src = Source()
        pub = Publisher("opensolaris.org")
        origin = Origin("http://ipkg.sfbay.sun.com/dev/")
        pub.insert_children([origin])
        src.insert_children([pub])
        dst = Destination()
        self.ips_image = Image(self.IPS_IMG_DIR, "update")
        dst.insert_children([self.ips_image])
        self.soft_node.insert_children([dst, src])
        try:
            self.tr_ips.execute(dry_run=DRY_RUN)
        except Exception as err:
            self.fail(str(err))
Example #9
0
 def test_get_size(self):
     '''Test that get_size returns an error when no source is set'''
     dst = Destination()
     path = Dir(self.TEST_DST_DIR)
     dst.insert_children([path])
     self.soft_node.insert_children([dst])
     self.assertRaises(IndexError, self.tr_cpio.get_size)
Example #10
0
    def test_cpio_w_dir_list_file(self):
        '''Test directory cpio copy succeeds'''
        # Copy all the directories and files from /etc/X11 and /etc/zones
        # to /rpool/cpio_test_dir using a file for the contents

        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_DIR_LIST_FILE
        with open(self.TEST_DIR_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/X11" + "\n")
            filehandle.write("etc/zones" + "\n")

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #11
0
    def test_install_uninstall_dry_run(self):
        '''Test an install followed by an uninstall'''
        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1", "SUNWpkg2", "SUNWpkg3"]
        args = Args({"svr4_args": "-n -R %s" % (self.TEST_DST_DIR)})
        self.tr_node.insert_children([args])
        self.tr_node2 = SVR4Spec()
        self.tr_node2.action = "uninstall"
        self.tr_node2.contents = ["SUNWpkg2"]
        self.soft_node.insert_children([self.tr_node2])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])

        try:
            self.tr_svr4.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
    def test_media_transform(self):
        '''Test media transform functionality'''
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11")
        path = Dir(src_path)
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "transform"
        self.tr_node.contents = self.TEST_MEDIA_TRANSFORM
        with open(self.TEST_MEDIA_TRANSFORM, 'w') as filehandle:
            filehandle.write("#!/usr/bin/python\n")
            filehandle.write("import os\n")
            mkdir_cmd = "os.mkdir('" + self.TEST_DST_DIR + "')"
            filehandle.write(mkdir_cmd + "\n")
            mkdir_cmd = "os.mkdir('" + os.path.join(self.TEST_DST_DIR,
                                                    "media") + "')"
            filehandle.write(mkdir_cmd)
        os.chmod(self.TEST_MEDIA_TRANSFORM, 0777)
        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
    def test_progress_estimate_with_size(self):
        '''Test progress estimate value when size is pre-calculated  exists
        '''
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc")
        path = Dir(src_path)
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = ["./"]
        size_to_transfer = dir_size(src_path)
        self.tr_node.size = str(size_to_transfer)

        progress_estimate = self.tr_cpio.get_progress_estimate()
        expect_estimate = \
            int((float(size_to_transfer/1024) / self.tr_cpio.DEFAULT_SIZE) * \
                self.tr_cpio.DEFAULT_PROG_EST)

        self.assertEqual(progress_estimate, expect_estimate)
 def test_get_size(self):
     '''Test that get_size returns an error when no source is set'''
     dst = Destination()
     path = Dir(self.TEST_DST_DIR)
     dst.insert_children([path])
     self.soft_node.insert_children([dst])
     self.assertRaises(IndexError, self.tr_cpio.get_size)
Example #15
0
    def test_cpio_non_default_args_set(self):
        '''Test copying a list of directories and files succeeds'''
        # Copy all the directories and files from /etc/X11 and /etc/zones
        # to /rpool/cpio_test_dir using a list for the contents

        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        args = Args({"cpio_args": "-n -d -pdum"})
        self.tr_node.insert_children([args])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        self.TEST_CONTENTS_LIST.append("bin/xclock")
        self.TEST_CONTENTS_LIST.append("bin/pv.sh")

        # The CPIO values that are specified
        self.TEST_CONTENTS_LIST.append("etc/X11")
        self.TEST_CONTENTS_LIST.append("etc/zones")
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_CONTENTS_LIST

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #16
0
    def test_single_args_instance(self):
        '''Test pass when single instance of args provided
        '''
        mysrc = "srcdir"
        mydest = "destfile"
        args = Args({"svr4_args": "-n -d %s -R %s" % (mysrc, mydest)})
        self.tr_node.insert_children([args])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])
        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1"]

        try:
            self.tr_svr4.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
    def test_single_args_instance(self):
        '''Test pass when single instance of args provided
        '''
        mysrc = "srcdir"
        mydest = "destfile"
        args = Args({"svr4_args": "-n -d %s -R %s" % (mysrc, mydest)})
        self.tr_node.insert_children([args])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])
        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1"]

        try:
            self.tr_svr4.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #18
0
    def test_source_replacement(self):
        '''Test that replacing a source succeeds'''
        # Setup an IPS image
        src = Source()
        pub = Publisher("opensolaris.org")
        origin = Origin("http://ipkg.sfbay.sun.com/release/")
        pub2 = Publisher("extra")
        origin2 = Origin("http://ipkg.sfbay.sun.com/extra/")
        pub2.insert_children([origin2])
        pub.insert_children([origin])
        src.insert_children([pub, pub2])
        self.soft_node.insert_children([src])
        try:
            self.tr_ips.execute(dry_run=DRY_RUN)
        except Exception as err:
            self.fail(str(err))

        # Create a new transaction with a differnt publisher/origin.
        # Specify to update the image created above.
        self.soft_node = Software("IPS post install")
        self.doc.insert_children([self.soft_node])
        src = Source()
        pub = Publisher("opensolaris.org")
        origin = Origin("http://ipkg.sfbay.sun.com/dev/")
        pub.insert_children([origin])
        src.insert_children([pub])
        dst = Destination()
        self.ips_image = Image(self.IPS_IMG_DIR, "update")
        dst.insert_children([self.ips_image])
        self.soft_node.insert_children([dst, src])
        try:
            self.tr_ips.execute(dry_run=DRY_RUN)
        except Exception as err:
            self.fail(str(err))
Example #19
0
    def test_valid_transfer_action(self):
        '''Test valid input with dry run.
        '''
        self.tr_node2 = SVR4Spec()
        self.tr_node2.action = "uninstall"
        self.tr_node2.contents = ["SUNWpkg1", "SUNWpkg2"]
        self.soft_node.insert_children([self.tr_node2])
        args2 = Args({"svr4_args": "-n -R %s" % (self.TEST_DST_DIR)})
        self.tr_node2.insert_children([args2])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])

        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1", "SUNWpkg2"]

        self.tr_node3 = SVR4Spec()
        self.tr_node3.action = "transform"
        self.tr_node3.contents = ["SUNWpkg1", "SUNWpkg2"]
        self.soft_node.insert_children([self.tr_node3])

        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
Example #20
0
    def test_dry_run_transfer(self):
        '''Test with accurate input dry run succeeds
        '''
        self.tr_node2 = SVR4Spec()
        self.tr_node2.action = "install"
        self.tr_node2.contents = ["SUNWpkg1", "SUNWpkg2"]
        self.soft_node.insert_children([self.tr_node2])
        args2 = Args({"svr4_args": "-n -R %s" % (self.TEST_DST_DIR)})
        self.tr_node2.insert_children([args2])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])

        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1", "SUNWpkg2"]

        try:
            self.tr_svr4.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
    def add_content_list_to_doc(self, content_list):
        src_path = Dir(MEDIA_DIR_VAR)
        src = Source()
        src.insert_children(src_path)

        dst_path = Dir(INSTALL_TARGET_VAR)
        dst = Destination()
        dst.insert_children(dst_path)

        media_install = CPIOSpec()
        media_install.action = CPIOSpec.INSTALL
        media_install.contents = content_list
        total_size_byte = 0
        for content in content_list:
            content_path = os.path.join(self.pkg_img_path, content)
            # only want to calculate the size of files, since directories
            # are traversed and it's files are included in the list.
            if not os.path.isdir(content_path):
                total_size_byte += file_size(content_path)
        media_install.size = str(total_size_byte)

        media_soft_node = Software(TRANSFER_MEDIA, type="CPIO")
        media_soft_node.insert_children([src, dst, media_install])

        # Add that into the software transfer list.
        self.doc.persistent.insert_children(media_soft_node)

        # call manifest writer to write out the content of
        # the transfer manifest
        manifest_out = os.path.join(self.pkg_img_path, TRANSFER_MANIFEST_NAME)
        xslt_name = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 "xslt", "doc2_media_transfer.xslt")
        manifest_writer = ManifestWriter("manifest-writer",
                                         manifest_out, xslt_file=xslt_name)
        manifest_writer.write(self.doc)
    def test_valid_transfer_action(self):
        '''Test valid input with dry run.
        '''
        self.tr_node2 = SVR4Spec()
        self.tr_node2.action = "uninstall"
        self.tr_node2.contents = ["SUNWpkg1", "SUNWpkg2"]
        self.soft_node.insert_children([self.tr_node2])
        args2 = Args({"svr4_args": "-n -R %s" % (self.TEST_DST_DIR)})
        self.tr_node2.insert_children([args2])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])

        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1", "SUNWpkg2"]

        self.tr_node3 = SVR4Spec()
        self.tr_node3.action = "transform"
        self.tr_node3.contents = ["SUNWpkg1", "SUNWpkg2"]
        self.soft_node.insert_children([self.tr_node3])

        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
    def create_misc_archive(self):
        """ class method to create the /mnt/misc file system archive
        """
        os.chdir(self.pkg_img_path)

        self.logger.info("Generating /mnt/misc file system archive")

        os.mkdir("miscdirs")
        shutil.move("opt", "miscdirs")
        shutil.move("etc", "miscdirs")
        shutil.move("var", "miscdirs")

        # add Software node to install items from /mnt/misc

        src_path = Dir("/mnt/misc")
        src = Source()
        src.insert_children(src_path)

        dst_path = Dir(INSTALL_TARGET_VAR)
        dst = Destination()
        dst.insert_children(dst_path)

        tr_install_misc = CPIOSpec()
        tr_install_misc.action = CPIOSpec.INSTALL
        tr_install_misc.contents = ["."]
        tr_install_misc.size = str(dir_size(os.path.join(self.pkg_img_path,
                                                         "miscdirs")))

        misc_software_node = Software(TRANSFER_MISC, type="CPIO")
        misc_software_node.insert_children([src, dst, tr_install_misc])
        self.doc.persistent.insert_children(misc_software_node)

        cmd = [cli.MKISOFS, "-o", "solarismisc.zlib", "-N", "-l", "-R",
               "-U", "-allow-multidot", "-no-iso-translate", "-quiet",
               "-cache-inodes", "-d", "-D", "-V", "\"compress\"",
               "miscdirs"]
        run(cmd)

        self.logger.info("Compressing /mnt/misc file system archive " +
                         "using: " + self.compression_type)

        cmd = [cli.LOFIADM, "-C", self.compression_type,
               os.path.join(self.pkg_img_path, "solarismisc.zlib")]
        p = run(cmd, check_result=Popen.ANY)
        if p.returncode != 0:
            if "invalid algorithm name" in p.stderr:
                raise RuntimeError("Invalid compression algorithm " +
                    "specified for /mnt/misc archive: " +
                    self.compression_type)
            else:
                raise RuntimeError("Compression of /mnt/misc file system " +
                                   "failed:  " + os.strerror(p.returncode))

        # the removal of /usr must be deferred to until solarismisc.zlib has
        # been created because the contents of solarismisc.zlib actually come
        # from /usr
        shutil.rmtree(os.path.join(self.pkg_img_path, "miscdirs"),
                      ignore_errors=True)
        shutil.rmtree(os.path.join(self.pkg_img_path, "usr"),
                      ignore_errors=True)
Example #24
0
    def test_cleanup_temp_files(self):
        '''Test the cleanup of the temporary files'''
        # Set up the source
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11")
        path = Dir(src_path)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = ["./"]

        self.tr_cpio._parse_input()
        try:
            self.tr_cpio._cleanup_tmp_files()
        except Exception as err:
            self.fail(str(err))
    def test_install_uninstall_dry_run(self):
        '''Test an install followed by an uninstall'''
        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1", "SUNWpkg2", "SUNWpkg3"]
        args = Args({"svr4_args": "-n -R %s" % (self.TEST_DST_DIR)})
        self.tr_node.insert_children([args])
        self.tr_node2 = SVR4Spec()
        self.tr_node2.action = "uninstall"
        self.tr_node2.contents = ["SUNWpkg2"]
        self.soft_node.insert_children([self.tr_node2])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])

        try:
            self.tr_svr4.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
    def test_dry_run_transfer(self):
        '''Test with accurate input dry run succeeds
        '''
        self.tr_node2 = SVR4Spec()
        self.tr_node2.action = "install"
        self.tr_node2.contents = ["SUNWpkg1", "SUNWpkg2"]
        self.soft_node.insert_children([self.tr_node2])
        args2 = Args({"svr4_args": "-n -R %s" % (self.TEST_DST_DIR)})
        self.tr_node2.insert_children([args2])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])

        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1", "SUNWpkg2"]

        try:
            self.tr_svr4.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #27
0
    def test_cpio_w_file_list_file(self):
        '''Test copy of a file list file succeeds'''
        # Copy /bin/xclock and /bin/pv.sh to /rpool/cpio_test_dir
        # using a file list file as the contents souce

        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_FILE_LIST_FILE
        with open(self.TEST_FILE_LIST_FILE, 'w') as filehandle:
            filehandle.write("bin/xclock" + "\n")
            filehandle.write("bin/pv.sh" + "\n")

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #28
0
    def test_cpio_w_file_list(self):
        '''Test copy from a list succeeds'''
        # Copy /bin/xclock and /bin/pv.sh to /rpool/cpio_test_dir
        # using a file list as the contents source

        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.TEST_CONTENTS_LIST.append("bin/xclock")
        self.TEST_CONTENTS_LIST.append("bin/pv.sh")

        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_CONTENTS_LIST

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #29
0
    def test_src_not_specified(self):
        ''' Test that an error is raised when src is not specified'''
        # Test that an error is raised.
        dst = Destination()
        dst_path = self.TEST_DST_DIR
        path = Dir(dst_path)
        dst.insert_children([path])

        self.soft_node.insert_children([dst])
        self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
    def test_src_not_specified(self):
        '''Test error when src is not specified
        '''
        dst = Destination()
        dst_path = self.TEST_DST_DIR
        path = Dir(dst_path)
        dst.insert_children([path])

        self.soft_node.insert_children([dst])
        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
 def setUp(self):
     InstallEngine._instance = None
     InstallEngine()
     self.engine = InstallEngine.get_instance()
     self.doc = self.engine.data_object_cache.volatile
     self.soft_node = Software("P5I transfer")
     self.tr_node = P5ISpec()
     dst = Destination()
     self.ips_image = Image(IPS_IMG_DIR, "create")
     dst.insert_children([self.ips_image])
     self.soft_node.insert_children([self.tr_node, dst])
     self.doc.insert_children([self.soft_node])
Example #32
0
 def setUp(self):
     InstallEngine._instance = None
     InstallEngine()
     self.engine = InstallEngine.get_instance()
     self.doc = self.engine.data_object_cache.volatile
     self.soft_node = Software("P5I transfer")
     self.tr_node = P5ISpec()
     dst = Destination()
     self.ips_image = Image(IPS_IMG_DIR, "create")
     dst.insert_children([self.ips_image])
     self.soft_node.insert_children([self.tr_node, dst])
     self.doc.insert_children([self.soft_node])
    def test_src_not_exist(self):
        ''' Test that an error is raised when src doesn't exist.'''

        #Set up the source
        src = Source()
        path = Dir("/hello")
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])
        self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
    def test_src_not_exist(self):
        '''Test that an error is raised when the source doesn't exist'''
        src = Source()
        pub = Publisher()
        origin = Origin("/doesnt_exist")
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])
        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
Example #35
0
    def test_src_not_exist(self):
        '''Test that an error is raised when the source doesn't exist'''
        src = Source()
        pub = Publisher()
        origin = Origin("/doesnt_exist")
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])
        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
Example #36
0
    def test_src_not_exist(self):
        ''' Test that an error is raised when src doesn't exist.'''

        #Set up the source
        src = Source()
        path = Dir("/hello")
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])
        self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
Example #37
0
 def setUp(self):
     InstallEngine._instance = None
     InstallEngine()
     self.engine = InstallEngine.get_instance()
     self.doc = self.engine.data_object_cache.volatile
     self.soft_node = Software("IPS transfer")
     self.tr_node = IPSSpec()
     dst = Destination()
     self.ips_image = Image(self.IPS_IMG_DIR, "create")
     ips_im_type = ImType("full")
     self.ips_image.insert_children([ips_im_type])
     dst.insert_children([self.ips_image])
     self.soft_node.insert_children([self.tr_node, dst])
     self.doc.insert_children([self.soft_node])
     self.tr_ips = TransferIPS("IPS transfer")
 def setUp(self):
     InstallEngine._instance = None
     InstallEngine()
     self.engine = InstallEngine.get_instance()
     self.doc = self.engine.data_object_cache.volatile
     self.soft_node = Software("IPS transfer")
     self.tr_node = IPSSpec()
     dst = Destination()
     self.ips_image = Image(self.IPS_IMG_DIR, "create")
     ips_im_type = ImType("full")
     self.ips_image.insert_children([ips_im_type])
     dst.insert_children([self.ips_image])
     self.soft_node.insert_children([self.tr_node, dst])
     self.doc.insert_children([self.soft_node])
     self.tr_ips = TransferIPS("IPS transfer")
    def test_dir_excl_list_not_valid(self):
        '''Test that an error is raised for invalid dir_excl_list'''
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11")
        path = Dir(src_path)
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "uninstall"
        self.tr_node.contents = "/tmp/invalid_dir_file"
        self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
Example #40
0
    def test_dir_excl_list_not_valid(self):
        '''Test that an error is raised for invalid dir_excl_list'''
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11")
        path = Dir(src_path)
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "uninstall"
        self.tr_node.contents = "/tmp/invalid_dir_file"
        self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
 def test_image_type(self):
     '''Test that image_type functionality succeeds'''
     self.tr_ips = TransferIPS("IPS transfer", {"zonename": "zonename"})
     self.ips_image.delete_children()
     ips_im_type = ImType("partial", zone=True)
     self.ips_image = Image(self.IPS_IMG_DIR, "create")
     self.ips_image.insert_children([ips_im_type])
     dst = Destination()
     dst.insert_children([self.ips_image])
     self.soft_node.delete_children()
     self.soft_node.insert_children([self.tr_node, dst])
     self.doc.delete_children()
     self.doc.insert_children([self.soft_node])
     try:
         self.tr_ips.execute(dry_run=DRY_RUN)
     except Exception as err:
         self.fail(str(err))
Example #42
0
 def test_image_type(self):
     '''Test that image_type functionality succeeds'''
     self.tr_ips = TransferIPS("IPS transfer", {"zonename": "zonename"})
     self.ips_image.delete_children()
     ips_im_type = ImType("partial", zone=True)
     self.ips_image = Image(self.IPS_IMG_DIR, "create")
     self.ips_image.insert_children([ips_im_type])
     dst = Destination()
     dst.insert_children([self.ips_image])
     self.soft_node.delete_children()
     self.soft_node.insert_children([self.tr_node, dst])
     self.doc.delete_children()
     self.doc.insert_children([self.soft_node])
     try:
         self.tr_ips.execute(dry_run=DRY_RUN)
     except Exception as err:
         self.fail(str(err))
    def test_transfer_fail_uninstall(self):
        '''Test that the transfer mechanism to uninstall
           fails with a non-existent package
        '''
        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])
        self.tr_node.action = 'uninstall'
        self.tr_node.contents = ["SUNWpkg0"]

        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=False)
    def test_uninstall_bad_args(self):
        '''Test transfer uninstall fails with bad args
        '''
        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])
        args = Args({"svr4_args": "-q -r -s -t"})
        self.tr_node.insert_children([args])
        self.tr_node.action = "uninstall"
        self.tr_node.contents = ["SUNWpkg1"]
        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=False)
Example #45
0
    def test_uninstall_bad_args(self):
        '''Test transfer uninstall fails with bad args
        '''
        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])
        args = Args({"svr4_args": "-q -r -s -t"})
        self.tr_node.insert_children([args])
        self.tr_node.action = "uninstall"
        self.tr_node.contents = ["SUNWpkg1"]
        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=False)
Example #46
0
    def test_transfer_fail_uninstall(self):
        '''Test that the transfer mechanism to uninstall
           fails with a non-existent package
        '''
        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])
        self.tr_node.action = 'uninstall'
        self.tr_node.contents = ["SUNWpkg0"]

        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=False)
Example #47
0
    def test_cpio_no_contents(self):
        ''' Test that an error is raised when no contents exist'''
        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified - no contents
        self.tr_node.action = "install"

        self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
    def test_bad_args_name(self):
        '''Test having invalid args key fails'''
        args = Args({"svr44444_args": "-n -d"})
        self.tr_node.insert_children([args])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])
        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1"]

        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
Example #49
0
    def test_bad_args_name(self):
        '''Test having invalid args key fails'''
        args = Args({"svr44444_args": "-n -d"})
        self.tr_node.insert_children([args])

        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])
        self.soft_node.insert_children([src, dst])
        self.tr_node.action = "install"
        self.tr_node.contents = ["SUNWpkg1"]

        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
    def test_cpio_no_contents(self):
        ''' Test that an error is raised when no contents exist'''
        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified - no contents
        self.tr_node.action = "install"

        self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
Example #51
0
    def test_more_than_one_dst(self):
        '''Test error with more than one dst directory
        '''
        dst = Destination()
        path = Dir("/hello")
        dst.insert_children([path])

        dst2 = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst2.insert_children([path])

        self.soft_node.insert_children([dst, dst2])
        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
    def test_dir_excl_list_file(self):
        '''Test the success of using directory exclusion'''
        # Copy all files/dirs from /etc/xdg except for anything under
        # /etc/xdg/menus to /rpool/cpio_test_dir using a file to
        # specify the contents

        # Set up the Source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_DIR_LIST_FILE

        # Populate the dir list file
        with open(self.TEST_DIR_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/xdg" + "\n")

        # Create and insert a node for the excluded files/dirs
        self.tr_node2 = CPIOSpec()
        self.tr_node2.action = "uninstall"
        self.tr_node2.contents = self.TEST_DIR_EXCL_LIST_FILE
        self.soft_node.insert_children([self.tr_node2])

        # Populate the excl file
        with open(self.TEST_DIR_EXCL_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/xdg/menus" + "\n")

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #53
0
    def test_dir_excl_list_file(self):
        '''Test the success of using directory exclusion'''
        # Copy all files/dirs from /etc/xdg except for anything under
        # /etc/xdg/menus to /rpool/cpio_test_dir using a file to
        # specify the contents

        # Set up the Source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_DIR_LIST_FILE

        # Populate the dir list file
        with open(self.TEST_DIR_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/xdg" + "\n")

        # Create and insert a node for the excluded files/dirs
        self.tr_node2 = CPIOSpec()
        self.tr_node2.action = "uninstall"
        self.tr_node2.contents = self.TEST_DIR_EXCL_LIST_FILE
        self.soft_node.insert_children([self.tr_node2])

        # Populate the excl file
        with open(self.TEST_DIR_EXCL_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/xdg/menus" + "\n")

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #54
0
    def test_cpio_no_contents(self):
        ''' Test that "no contents" scenario is handled'''
        # Set up the source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified - no contents
        self.tr_node.action = "install"

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #55
0
    def test_more_than_one_src(self):
        '''Test error when more than one src directory is added.
        '''
        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        dst_path = self.TEST_DST_DIR
        path = Dir(dst_path)
        dst.insert_children([path])

        src2 = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src2.insert_children([pub])

        self.soft_node.insert_children([dst, src, src2])
        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
    def test_more_than_one_src(self):
        '''Test error when more than one src directory is added.
        '''
        src = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src.insert_children([pub])

        dst = Destination()
        dst_path = self.TEST_DST_DIR
        path = Dir(dst_path)
        dst.insert_children([path])

        src2 = Source()
        pub = Publisher()
        origin = Origin(self.TEST_SRC_DIR)
        pub.insert_children([origin])
        src2.insert_children([pub])

        self.soft_node.insert_children([dst, src, src2])
        self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
    def test_skip_file_list_file(self):
        '''Test the success of using skip_file_list'''
        # Copy all the files/dirs from /etc except for /etc/name_to_major
        # to /rpool/cpio_test_dir using a file for the contents

        # Set up the Source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_DIR_LIST_FILE

        # Create and insert a node for the files to be uninstalled
        self.tr_node2 = CPIOSpec()
        self.tr_node2.action = "uninstall"
        self.tr_node2.contents = self.TEST_SKIP_FILE_LIST_FILE
        self.soft_node.insert_children([self.tr_node2])

        # Populate the files
        with open(self.TEST_DIR_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/dhcp" + "\n")
        with open(self.TEST_SKIP_FILE_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/dhcp/duid" + "\n")
            filehandle.write("etc/dhcp/iaid" + "\n")

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))
Example #58
0
    def test_progress_estimate(self):
        '''Test that the progress estimate is the value expected.'''
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11")
        path = Dir(src_path)
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = ["xinit"]

        try:
            progress_estimate = self.tr_cpio.get_progress_estimate()
        except Exception:
            self.assertTrue(False)
        size = 0

        size += file_size(os.path.join(src_path, "./"))
        for contents in self.tr_node.contents:
            size += file_size(os.path.join(src_path, contents))
            for root, subdirs, files in os.walk(
                    os.path.join(src_path, contents)):
                for subdir in subdirs:
                    size += file_size(os.path.join(root, subdir))
                for fname in files:
                    size += file_size(os.path.join(root, fname))

        # convert size to kilobytes
        size = size / 1024

        self.assertTrue(progress_estimate == \
                        int(float(size) / self.tr_cpio.DEFAULT_SIZE * \
                            self.tr_cpio.DEFAULT_PROG_EST))
    def test_progress_estimate(self):
        '''Test that the progress estimate is the value expected.'''
        src = Source()
        src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11")
        path = Dir(src_path)
        src.insert_children([path])

        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = ["xinit"]

        try:
            progress_estimate = self.tr_cpio.get_progress_estimate()
        except Exception:
            self.assertTrue(False)
        size = 0

        size += file_size(os.path.join(src_path, "./"))
        for contents in self.tr_node.contents:
            size += file_size(os.path.join(src_path, contents))
            for root, subdirs, files in os.walk(os.path.join(src_path,
                                                            contents)):
                for subdir in subdirs:
                    size += file_size(os.path.join(root, subdir))
                for fname in files:
                    size += file_size(os.path.join(root, fname))

        # convert size to kilobytes
        size = size / 1024

        self.assertTrue(progress_estimate == \
                        int(float(size) / self.tr_cpio.DEFAULT_SIZE * \
                            self.tr_cpio.DEFAULT_PROG_EST))
Example #60
0
    def test_skip_file_list_file(self):
        '''Test the success of using skip_file_list'''
        # Copy all the files/dirs from /etc except for /etc/name_to_major
        # to /rpool/cpio_test_dir using a file for the contents

        # Set up the Source
        src = Source()
        path = Dir(self.TEST_SRC_DIR)
        src.insert_children([path])

        # Set up the destination
        dst = Destination()
        path = Dir(self.TEST_DST_DIR)
        dst.insert_children([path])

        # Insert the source and dest into the Software node
        self.soft_node.insert_children([src, dst])

        # The CPIO values that are specified
        self.tr_node.action = "install"
        self.tr_node.contents = self.TEST_DIR_LIST_FILE

        # Create and insert a node for the files to be uninstalled
        self.tr_node2 = CPIOSpec()
        self.tr_node2.action = "uninstall"
        self.tr_node2.contents = self.TEST_SKIP_FILE_LIST_FILE
        self.soft_node.insert_children([self.tr_node2])

        # Populate the files
        with open(self.TEST_DIR_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/dhcp" + "\n")
        with open(self.TEST_SKIP_FILE_LIST_FILE, 'w') as filehandle:
            filehandle.write("etc/dhcp/duid" + "\n")
            filehandle.write("etc/dhcp/iaid" + "\n")

        try:
            self.tr_cpio.execute(dry_run=True)
        except Exception as err:
            self.fail(str(err))