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 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)
Exemple #3
0
    def add_root_transfer_to_doc(self):
        """ Adds the list of files of directories to be transferred
            to the DOC
        """
        if self.doc is None:
            self.doc = InstallEngine.get_instance().data_object_cache

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

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

        dot_node = CPIOSpec()
        dot_node.action = CPIOSpec.INSTALL
        dot_node.size = str(dir_size(os.path.join(self.ba_build, "")))
        dot_node.contents = ["."]

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

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

        software_node = Software(TRANSFER_ROOT, type="CPIO")
        software_node.insert_children([src, dst, dot_node, usr_node, dev_node])

        self.doc.persistent.insert_children(software_node)

        self.logger.debug(str(self.doc.persistent))
    def add_root_transfer_to_doc(self):
        """ Adds the list of files of directories to be transferred
            to the DOC
        """
        if self.doc is None:
            self.doc = InstallEngine.get_instance().data_object_cache

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

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

        dot_node = CPIOSpec()
        dot_node.action = CPIOSpec.INSTALL
        dot_node.size = str(dir_size(os.path.join(self.ba_build, "")))
        dot_node.contents = ["."]

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

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

        software_node = Software(TRANSFER_ROOT, type="CPIO")
        software_node.insert_children([src, dst, dot_node, usr_node, dev_node])

        self.doc.persistent.insert_children(software_node)

        self.logger.debug(str(self.doc.persistent))
Exemple #5
0
    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)
Exemple #6
0
    def configure_system(self):
        """ class method for the execution of various, isolated shell commands
        needed to configure the boot archive.
        """
        self.logger.info("preparing boot archive")

        # configure devices
        cmd = [cli.DEVFSADM, "-r", self.ba_build]
        run(cmd)

        # etc/dev/.devfsadm_dev.lock gets created every time
        # devfsadm is run. remove it since there's no point
        # in carrying it forward through to the image
        lockfile = os.path.join(self.ba_build, "etc/dev/.devfsadm_dev.lock")
        if os.path.exists(lockfile):
            self.logger.debug("removing devfsadm lock file")
            os.remove(lockfile)

        # Set a marker so that every boot is a reconfiguration boot
        cmd = [cli.TOUCH, os.path.join(self.ba_build, "reconfigure")]
        run(cmd)

        # Set up /etc/rtc_config
        cmd = [
            cli.CP,
            os.path.join(self.file_defaults, "rtc_config.default"),
            os.path.join(self.ba_build, "etc/rtc_config")
        ]
        run(cmd)

        # go to the ba_build
        self.logger.debug("creating symlinks and mountpoints")
        os.chdir(self.ba_build)

        # create ./tmp.  mkdir and chmod have to be done seperately
        self.logger.debug("creating tmp dir and setting it to 01777")
        os.mkdir("tmp")
        os.chmod("tmp", 01777)

        # create ./proc
        self.logger.debug("creating proc directory")
        os.mkdir("proc")

        # create ./mnt
        self.logger.debug("creating mnt directory")
        os.mkdir("mnt")

        # create bin symlink to /usr/bin if needed
        self.logger.debug("checking for symlink of bin -> usr/bin")
        if not os.path.islink("bin"):
            os.symlink("usr/bin", "bin")

        # create mountpoints for misc and pkg zlibs
        self.logger.debug("creating mnt/misc and mnt/pkg mountpoints")
        os.mkdir("mnt/misc", 0755)
        os.mkdir("mnt/pkg", 0755)

        # create volume set id file, use system name + date for uniqueness
        with open(".volsetid", "w") as v:
            volsetid = os.uname()[1] + '-' + \
                       datetime.datetime.now().isoformat()
            self.logger.debug("setting .volsetid to %s" % volsetid)
            v.write(volsetid)

        # chmod it to 444 and set the ownership to root:root (0:0)
        os.chmod(".volsetid", 0444)
        os.chown(".volsetid", 0, 0)

        # create the file marking the image type (e.g. .autoinstall or
        # .livecd)
        self.logger.debug("creating image_type file")
        with open(self.image_type, "w"):
            pass

        # create .cdrom directory
        self.logger.debug("creating .cdrom directory")
        os.mkdir(".cdrom", 0755)

        # create opt symlink to mnt/misc/opt if needed
        self.logger.debug("checking for symlink of opt -> mnt/misc/opt")
        if not os.path.islink("opt"):
            os.symlink("mnt/misc/opt", "opt")

        tr_uninstall = CPIOSpec()
        tr_uninstall.action = CPIOSpec.UNINSTALL
        tr_uninstall.contents = ["opt"]

        root_tr_software_node = self.doc.persistent.get_descendants(
            name=TRANSFER_ROOT, class_type=Software, not_found_is_err=True)[0]
        root_tr_software_node.insert_children(tr_uninstall)

        # copy the SMF repository from pkg_image_path to ba_build
        pkg_img_path_repo = os.path.join(self.pkg_img_path,
                                         "etc/svc/repository.db")
        ba_build_repo = os.path.join(self.ba_build, "etc/svc/repository.db")
        shutil.copy2(pkg_img_path_repo, ba_build_repo)
Exemple #7
0
    def configure_symlinks(self):
        """ class method for the configuration of symlinks needed in the boot
        archive.
        """
        self.logger.debug("Creating additional symlinks in ramdisk")

        self.logger.debug("creating set of files in pkg_img_path:  %s" % \
                          self.pkg_img_path)

        # change to the pkg_img_path directory
        os.chdir(self.pkg_img_path)

        # walk /etc and /var in pkg_img_path and create a list of
        # directories
        pkg_img_dirs = []
        for rootdir in ["etc", "var"]:
            for root, dirs, files in os.walk(rootdir):
                for d in dirs:
                    pkg_img_dirs.append(os.path.join(root, d))

        # change to the boot_archive directory
        os.chdir(self.ba_build)

        # walk the pkg_img_dirs list and create each directory that doesn't
        # already exist.  Also, copy the directory permissions and metadata
        # to the new directory
        for d in pkg_img_dirs:
            ba_path = os.path.join(self.ba_build, d)
            pkg_path = os.path.join(self.pkg_img_path, d)

            # split the directory on / to verify parent directories exist
            dir_list = d.split("/")

            # keep a 'path' string for verification
            path = ""
            for subdir in dir_list:
                # extend path
                path = os.path.join(path, subdir)
                full_path = os.path.join(self.ba_build, path)

                # check to see if it exists and is not already a symlink
                if not os.path.exists(full_path) and \
                    not os.path.islink(full_path):

                    # create the directory
                    os.mkdir(os.path.join(self.ba_build, path))

                    # copy the metadata from pkg_image to boot_archive
                    shutil.copystat(os.path.join(self.pkg_img_path, path),
                                    os.path.join(self.ba_build, path))

                    # copy the uid/gid as well
                    pkg_statinfo = os.stat(
                        os.path.join(self.pkg_img_path, path))

                    os.chown(os.path.join(self.ba_build, path),
                             pkg_statinfo.st_uid, pkg_statinfo.st_gid)

        # now that the directory structure is created, create symlinks for
        # all the missing files in the boot_archive

        # change to the pkg_img_path directory
        os.chdir(self.pkg_img_path)

        # keep track of all the symlinks created
        misc_symlinks = []
        for rootdir in ["etc", "var"]:
            for root, dirs, files in os.walk(rootdir):
                for f in files:
                    pkg_path = os.path.join(self.pkg_img_path, root, f)

                    # skip symlinks
                    if os.path.islink(pkg_path):
                        continue

                    ba_path = os.path.join(self.ba_build, root, f)
                    if not os.path.exists(ba_path):
                        # the file is missing from the boot_archive so
                        # create a symlink to /mnt/misc/file/path
                        misc_path = os.path.join("/mnt/misc", root, f)

                        # save the cwd
                        cwd = os.getcwd()

                        # changedir to the dirname of the file
                        os.chdir(os.path.dirname(ba_path))

                        # create the symlink
                        os.symlink(misc_path, f)

                        os.chdir(cwd)

                        misc_symlinks.append(os.path.join(root, f))

        tr_uninstall = CPIOSpec()
        tr_uninstall.action = CPIOSpec.UNINSTALL
        tr_uninstall.contents = misc_symlinks

        # Add that into the software transfer list.  The list of files to
        # uninstall MUST go before the contents to be installed from /mnt/misc
        root_tr_software_node = self.doc.persistent.get_descendants(
            name=TRANSFER_ROOT, class_type=Software, not_found_is_err=True)[0]

        root_tr_software_node.insert_children(tr_uninstall)

        self.logger.debug(str(self.doc.persistent))
Exemple #8
0
    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)
Exemple #9
0
    def test_info(self):
        '''Test that all the arguments get into the node correctly'''
        soft_node = Software("CPIO transfer test 1")
        cpio_node = CPIOSpec()

        dst = Destination()
        path = Dir("/a")
        dst.insert_children([path])

        src = Source()
        path = Dir("/bin")
        src.insert_children([path])

        # first check src and dst
        soft_node.insert_children([dst, src, cpio_node])
        self.doc.insert_children([soft_node])
        soft_list = self.doc.get_children("CPIO transfer test 1", Software)
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                try:
                    args = tr.get_children("args", Args)[0]
                except:
                    self.assertTrue(True)
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(tr.action, None)
                self.assertEqual(tr.contents, None)

        # set cpio args
        args = Args({"cpio_args": "-pdm"})
        cpio_node.insert_children([args])

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, None)
                self.assertEqual(tr.contents, None)

        # set file_list content
        cpio_node.action = "install"
        cpio_node.type = "FILE"
        cpio_node.contents = "/usr/share/tr_file_list"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "install")
                self.assertEqual(tr.contents, "/usr/share/tr_file_list")

        # set dir_list
        cpio_node.action = "install"
        cpio_node.type = "DIR"
        cpio_node.contents = "/usr/share/tr_dir_list"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "install")
                self.assertEqual(tr.contents, "/usr/share/tr_dir_list")

        # set skip_file_list
        cpio_node.action = "uninstall"
        cpio_node.type = "FILE"
        cpio_node.contents = "/usr/share/tr_skip_file_list"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "uninstall")
                self.assertEqual(tr.contents, "/usr/share/tr_skip_file_list")

        # set dir_excl_list
        cpio_node.action = "uninstall"
        cpio_node.type = "DIR"
        cpio_node.contents = "/usr/share/tr_dir_excl_list"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "uninstall")
                self.assertEqual(tr.contents, "/usr/share/tr_dir_excl_list")

        # set media transform
        cpio_node.action = "transform"
        cpio_node.type = "None"
        cpio_node.contents = "/usr/share/media_transform"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "transform")
                self.assertEqual(tr.contents, "/usr/share/media_transform")
    def test_info(self):
        '''Test that all the arguments get into the node correctly'''
        soft_node = Software("CPIO transfer test 1")
        cpio_node = CPIOSpec()

        dst = Destination()
        path = Dir("/a")
        dst.insert_children([path])

        src = Source()
        path = Dir("/bin")
        src.insert_children([path])

        # first check src and dst
        soft_node.insert_children([dst, src, cpio_node])
        self.doc.insert_children([soft_node])
        soft_list = self.doc.get_children("CPIO transfer test 1", Software)
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                try:
                    args = tr.get_children("args", Args)[0]
                except:
                    self.assertTrue(True)
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(tr.action, None)
                self.assertEqual(tr.contents, None)

        # set cpio args
        args = Args({"cpio_args": "-pdm"})
        cpio_node.insert_children([args])

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, None)
                self.assertEqual(tr.contents, None)

        # set file_list content
        cpio_node.action = "install"
        cpio_node.type = "FILE"
        cpio_node.contents = "/usr/share/tr_file_list"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "install")
                self.assertEqual(tr.contents, "/usr/share/tr_file_list")

        # set dir_list
        cpio_node.action = "install"
        cpio_node.type = "DIR"
        cpio_node.contents = "/usr/share/tr_dir_list"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "install")
                self.assertEqual(tr.contents, "/usr/share/tr_dir_list")

        # set skip_file_list
        cpio_node.action = "uninstall"
        cpio_node.type = "FILE"
        cpio_node.contents = "/usr/share/tr_skip_file_list"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "uninstall")
                self.assertEqual(tr.contents, "/usr/share/tr_skip_file_list")

        # set dir_excl_list
        cpio_node.action = "uninstall"
        cpio_node.type = "DIR"
        cpio_node.contents = "/usr/share/tr_dir_excl_list"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "uninstall")
                self.assertEqual(tr.contents, "/usr/share/tr_dir_excl_list")

        # set media transform
        cpio_node.action = "transform"
        cpio_node.type = "None"
        cpio_node.contents = "/usr/share/media_transform"

        # Check that we can read the attributes out correctly
        for soft in soft_list:
            src_list = soft.get_children("source", Source)
            self.assertEqual(len(src_list), 1)

            src_path = src_list[0].get_children("dir", Dir)
            self.assertEqual(len(src_path), 1)
            src = src_path[0].dir_path

            dst_list = soft.get_children("destination", Destination)
            self.assertEqual(len(dst_list), 1)

            dst_path = dst_list[0].get_children("dir", Dir)
            self.assertEqual(len(dst_path), 1)
            dst = dst_path[0].dir_path

            tr_list = soft.get_children("transfer", CPIOSpec)
            for tr in tr_list:
                args = tr.get_children("args", Args)[0]
                self.assertEqual(dst, "/a")
                self.assertEqual(src, "/bin")
                self.assertEqual(args.arg_dict["cpio_args"], "-pdm")
                self.assertEqual(tr.action, "transform")
                self.assertEqual(tr.contents, "/usr/share/media_transform")
    def configure_system(self):
        """ class method for the execution of various, isolated shell commands
        needed to configure the boot archive.
        """
        self.logger.info("preparing boot archive")

        # configure devices
        cmd = [cli.DEVFSADM, "-r", self.ba_build]
        run(cmd)

        # etc/dev/.devfsadm_dev.lock gets created every time
        # devfsadm is run. remove it since there's no point
        # in carrying it forward through to the image
        lockfile = os.path.join(self.ba_build, "etc/dev/.devfsadm_dev.lock")
        if os.path.exists(lockfile):
            self.logger.debug("removing devfsadm lock file")
            os.remove(lockfile)

        # Set a marker so that every boot is a reconfiguration boot
        cmd = [cli.TOUCH, os.path.join(self.ba_build, "reconfigure")]
        run(cmd)

        # Set up /etc/rtc_config
        cmd = [cli.CP, os.path.join(self.file_defaults, "rtc_config.default"),
               os.path.join(self.ba_build, "etc/rtc_config")]
        run(cmd)

        # go to the ba_build
        self.logger.debug("creating symlinks and mountpoints")
        os.chdir(self.ba_build)

        # create ./tmp.  mkdir and chmod have to be done seperately
        self.logger.debug("creating tmp dir and setting it to 01777")
        os.mkdir("tmp")
        os.chmod("tmp", 01777)

        # create ./proc
        self.logger.debug("creating proc directory")
        os.mkdir("proc")

        # create ./mnt
        self.logger.debug("creating mnt directory")
        os.mkdir("mnt")

        # create bin symlink to /usr/bin if needed
        self.logger.debug("checking for symlink of bin -> usr/bin")
        if not os.path.islink("bin"):
            os.symlink("usr/bin", "bin")

        # create mountpoints for misc and pkg zlibs
        self.logger.debug("creating mnt/misc and mnt/pkg mountpoints")
        os.mkdir("mnt/misc", 0755)
        os.mkdir("mnt/pkg", 0755)

        # create volume set id file, use system name + date for uniqueness
        with open(".volsetid", "w") as v:
            volsetid = os.uname()[1] + '-' + \
                       datetime.datetime.now().isoformat()
            self.logger.debug("setting .volsetid to %s" % volsetid)
            v.write(volsetid)

        # chmod it to 444 and set the ownership to root:root (0:0)
        os.chmod(".volsetid", 0444)
        os.chown(".volsetid", 0, 0)

        # create the file marking the image type (e.g. .autoinstall or
        # .livecd)
        self.logger.debug("creating image_type file")
        with open(self.image_type, "w"):
            pass

        # create .cdrom directory
        self.logger.debug("creating .cdrom directory")
        os.mkdir(".cdrom", 0755)

        # create opt symlink to mnt/misc/opt if needed
        self.logger.debug("checking for symlink of opt -> mnt/misc/opt")
        if not os.path.islink("opt"):
            os.symlink("mnt/misc/opt", "opt")

        tr_uninstall = CPIOSpec()
        tr_uninstall.action = CPIOSpec.UNINSTALL
        tr_uninstall.contents = ["opt"]

        root_tr_software_node = self.doc.persistent.get_descendants(
            name=TRANSFER_ROOT, class_type=Software, not_found_is_err=True)[0]
        root_tr_software_node.insert_children(tr_uninstall)

        # copy the SMF repository from pkg_image_path to ba_build
        pkg_img_path_repo = os.path.join(self.pkg_img_path,
                                         "etc/svc/repository.db")
        ba_build_repo = os.path.join(self.ba_build,
                                     "etc/svc/repository.db")
        shutil.copy2(pkg_img_path_repo, ba_build_repo)
    def configure_symlinks(self):
        """ class method for the configuration of symlinks needed in the boot
        archive.
        """
        self.logger.debug("Creating additional symlinks in ramdisk")

        self.logger.debug("creating set of files in pkg_img_path:  %s" % \
                          self.pkg_img_path)

        # change to the pkg_img_path directory
        os.chdir(self.pkg_img_path)

        # walk /etc and /var in pkg_img_path and create a list of
        # directories
        pkg_img_dirs = []
        for rootdir in ["etc", "var"]:
            for root, dirs, files in os.walk(rootdir):
                for d in dirs:
                    pkg_img_dirs.append(os.path.join(root, d))

        # change to the boot_archive directory
        os.chdir(self.ba_build)

        # walk the pkg_img_dirs list and create each directory that doesn't
        # already exist.  Also, copy the directory permissions and metadata
        # to the new directory
        for d in pkg_img_dirs:
            ba_path = os.path.join(self.ba_build, d)
            pkg_path = os.path.join(self.pkg_img_path, d)

            # split the directory on / to verify parent directories exist
            dir_list = d.split("/")

            # keep a 'path' string for verification
            path = ""
            for subdir in dir_list:
                # extend path
                path = os.path.join(path, subdir)
                full_path = os.path.join(self.ba_build, path)

                # check to see if it exists and is not already a symlink
                if not os.path.exists(full_path) and \
                    not os.path.islink(full_path):

                    # create the directory
                    os.mkdir(os.path.join(self.ba_build, path))

                    # copy the metadata from pkg_image to boot_archive
                    shutil.copystat(os.path.join(self.pkg_img_path, path),
                                    os.path.join(self.ba_build, path))

                    # copy the uid/gid as well
                    pkg_statinfo = os.stat(os.path.join(self.pkg_img_path,
                                                        path))

                    os.chown(os.path.join(self.ba_build, path),
                             pkg_statinfo.st_uid, pkg_statinfo.st_gid)

        # now that the directory structure is created, create symlinks for
        # all the missing files in the boot_archive

        # change to the pkg_img_path directory
        os.chdir(self.pkg_img_path)

        # keep track of all the symlinks created
        misc_symlinks = []
        for rootdir in ["etc", "var"]:
            for root, dirs, files in os.walk(rootdir):
                for f in files:
                    pkg_path = os.path.join(self.pkg_img_path, root, f)

                    # skip symlinks
                    if os.path.islink(pkg_path):
                        continue

                    ba_path = os.path.join(self.ba_build, root, f)
                    if not os.path.exists(ba_path):
                        # the file is missing from the boot_archive so
                        # create a symlink to /mnt/misc/file/path
                        misc_path = os.path.join("/mnt/misc", root, f)

                        # save the cwd
                        cwd = os.getcwd()

                        # changedir to the dirname of the file
                        os.chdir(os.path.dirname(ba_path))

                        # create the symlink
                        os.symlink(misc_path, f)

                        os.chdir(cwd)

                        misc_symlinks.append(os.path.join(root, f))

        tr_uninstall = CPIOSpec()
        tr_uninstall.action = CPIOSpec.UNINSTALL
        tr_uninstall.contents = misc_symlinks

        # Add that into the software transfer list.  The list of files to
        # uninstall MUST go before the contents to be installed from /mnt/misc
        root_tr_software_node = self.doc.persistent.get_descendants(
            name=TRANSFER_ROOT, class_type=Software, not_found_is_err=True)[0]

        root_tr_software_node.insert_children(tr_uninstall)

        self.logger.debug(str(self.doc.persistent))