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)
def test_multiple_source_info(self): '''Test that specifying multiple sources succeeds.''' soft_node = Software("transfer test 2") src1 = Source() pub1 = Publisher("test1.org") origin1 = Origin("http://test1/dev") pub1.insert_children([origin1]) src1.insert_children([pub1]) src2 = Source() pub2 = Publisher("test2.org") origin2 = Origin("http://test2/dev") pub2.insert_children([origin2]) src2.insert_children([pub2]) tr_node = IPSSpec() soft_node.insert_children([src1, src2, tr_node]) self.doc.insert_children([soft_node]) soft_list = self.doc.get_children("transfer test 2", Software) for soft in soft_list: src_list = soft.get_children("source", Source) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(pub[0].publisher, "test1.org") self.assertEqual(origin[0].origin, "http://test1/dev") pub = src_list[1].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(pub[0].publisher, "test2.org") self.assertEqual(origin[0].origin, "http://test2/dev")
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_more_than_one_same_soft_node(self): '''Test error when multiple software nodes with same name ''' soft_node2 = Software("SVR4Transfer") self.doc.insert_children([soft_node2]) tr_node2 = SVR4Spec() soft_node2.insert_children([tr_node2]) self.doc.insert_children([soft_node2]) self.assertRaises(Exception, TransferSVR4, "SVR4Transfer")
def test_file_name(self): '''Test that Origin is set correctly in the node''' p5i_node = Software("transfer 1") src = Source() pub = Publisher() origin = Origin(self.DEF_P5I_FILE) pub.insert_children([origin]) src.insert_children([pub]) p5i_node.insert_children([src]) self.doc.insert_children([p5i_node]) soft_list = self.doc.get_children("transfer 1", Software) for soft in soft_list: src = soft.get_children("source", Source)[0] pub = src.get_children("publisher", Publisher)[0] origin = pub.get_children("origin", Origin)[0] self.assertTrue(origin.origin == self.DEF_P5I_FILE)
def test_args(self): '''Test that setting the ips arguments works''' soft_node = Software("transfer test 4") tr_node = IPSSpec() ips_args_node = Args({"force": True, "set-something": 12}) tr_node.insert_children([ips_args_node]) soft_node.insert_children([tr_node]) self.doc.insert_children([soft_node]) soft_list = self.doc.get_children("transfer test 4", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: ips_args = tr.get_children("args", Args) for args in ips_args: for key in args.arg_dict: if key is not "force" or key is not "set-something": self.assertTrue(True) if key is "force": self.assertEqual(args.arg_dict[key], True) if key is "set-something": self.assertEqual(args.arg_dict[key], 12)
def test_mirror_info(self): '''Test that writting to the mirror object works''' soft_node = Software("transfer test 1") src = Source() pub = Publisher("test.org") origin = Origin("http://test/dev") mirror = Mirror("http://mirror") pub.insert_children([origin, mirror]) src.insert_children([pub]) tr_node = IPSSpec() soft_node.insert_children([src, tr_node]) self.doc.insert_children([soft_node]) soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: src_list = soft.get_children("source", Source) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) mirror = pub[0].get_children("mirror", Mirror) self.assertEqual(pub[0].publisher, "test.org") self.assertEqual(origin[0].origin, "http://test/dev") self.assertEqual(mirror[0].mirror, "http://mirror")
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))
class TestP5IFunctions(unittest.TestCase): 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 tearDown(self): self.engine.data_object_cache.clear() InstallEngine._instance = None self.doc = None self.soft_node = None self.tr_node = None self.engine = None def test_install(self): '''Test that p5i install is successful''' src = Source() pub = Publisher("test") origin = Origin(PKG_FULL_P5I) pub.insert_children(origin) pub_prim = Publisher("test2") origin_prim = Origin(PKG_PUB_PATH) pub1 = Publisher(PKG_PUBLISHER) origin1 = Origin(PKG_PUB_PATH) pub_prim.insert_children(origin_prim) pub1.insert_children(origin1) src.insert_children([pub, pub_prim, pub1]) self.soft_node.insert_children(src) tr_p5i = TransferP5I("P5I transfer") try: tr_p5i.execute(DRY_RUN) except Exception as err: self.fail(str(err)) def test_src_not_specified(self): '''Test an error is raised when the source is not specified. ''' tr_p5i = TransferP5I("P5I transfer") self.assertRaises(Exception, tr_p5i.execute, DRY_RUN) def test_publisher_not_specified(self): '''Test an error is raised when the publisher is not specified. ''' src = Source() self.soft_node.insert_children([src]) tr_p5i = TransferP5I("P5I transfer") self.assertRaises(Exception, tr_p5i.execute, DRY_RUN) def test_origin_not_specified(self): '''Test an errer is raised when the origin is not specified. ''' src = Source() pub = Publisher() src.insert_children([pub]) self.soft_node.insert_children([src]) tr_p5i = TransferP5I("P5I transfer") self.assertRaises(ObjectNotFoundError, tr_p5i.execute, DRY_RUN) def test_bogus_p5i_file(self): '''Test that including a nonexistent origin fails. ''' src = Source() pub = Publisher() origin = Origin("/tmp/bogus") pub.insert_children([origin]) pub_prim = Publisher() origin_prim = Origin(PKG_PUB_PATH) pub1 = Publisher("contrib.opensolaris.org") origin1 = Origin("http://pkg.opensolaris.org/contrib") pub2 = Publisher("extra") origin2 = Origin("http://ipkg.sfbay/extra") pub_prim.insert_children([origin_prim]) pub1.insert_children([origin1]) pub2.insert_children([origin2]) src.insert_children([pub, pub_prim, pub1, pub2]) self.soft_node.insert_children([src]) tr_p5i = TransferP5I("P5I transfer") self.assertRaises(Exception, tr_p5i.execute, DRY_RUN)
def test_info(self): '''Test that all the arguments get into the node correctly''' soft_node = Software("SVR4 transfer test 1") svr4_node = SVR4Spec() 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, svr4_node]) self.doc.insert_children([soft_node]) soft_list = self.doc.get_children("SVR4 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", SVR4Spec) 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({"svr4_args": "-n -d"}) svr4_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", SVR4Spec) 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["svr4_args"], "-n -d") self.assertEqual(tr.action, None) self.assertEqual(tr.contents, None) # set install package content svr4_node.action = "install" svr4_node.contents = ["SUNWcsr", "SUNWcsu"] # 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", SVR4Spec) 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["svr4_args"], "-n -d") self.assertEqual(tr.action, "install") self.assertEqual(tr.contents, ["SUNWcsr", "SUNWcsu"]) # set uninstall package content svr4_node.action = "uninstall" svr4_node.contents = ["SUNWlxml", "SUNWzfs"] # 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", SVR4Spec) 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["svr4_args"], "-n -d") self.assertEqual(tr.action, "uninstall") self.assertEqual(tr.contents, ["SUNWlxml", "SUNWzfs"])
def do_ti_install(install_data, screen, update_status_func): '''Installation engine for text installer. Raises InstallationError for any error occurred during install. ''' sysconfig_profile = sysconfig.profile.from_engine() # # The following information is needed for installation. # Make sure they are provided before even starting # # timezone timezone = sysconfig_profile.system.tz_timezone LOGGER.debug("time zone: %s", timezone) # Validate the value specified for timezone if not tz_isvalid(timezone): LOGGER.error("Timezone value specified (%s) is not valid", timezone) raise ti_utils.InstallationError # Compute the time to set. install_time = datetime.datetime.now() + \ sysconfig_profile.system.time_offset # Set the system time to the time specified by the user. cmd = ["/usr/bin/date", install_time.strftime("%m%d%H%M%y")] Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE, logger=LOGGER) hostname = sysconfig_profile.system.hostname LOGGER.debug("hostname: " + hostname) engine = InstallEngine.get_instance() doc = engine.doc solaris_slice = get_solaris_slice(doc) if solaris_slice is None: raise ti_utils.InstallationError("Unable to find solaris slice") inst_device_size = solaris_slice.size LOGGER.info("Installation Device Size: %sMB", inst_device_size) minimum_size = screen.tc.minimum_target_size LOGGER.info("Minimum required size: %s", minimum_size) if (inst_device_size < minimum_size): LOGGER.error("Size of device specified for installation " "is too small") LOGGER.error("Size of install device: %s", inst_device_size) LOGGER.error("Minimum required size: %s", minimum_size) raise ti_utils.InstallationError recommended_size = screen.tc.recommended_target_size LOGGER.info("Recommended size: %s", recommended_size) if (inst_device_size < recommended_size): # Warn users that their install target size is not optimal # Just log the warning, but continue with the installation. LOGGER.warning("Size of device specified for installation is " "not optimal") LOGGER.warning("Size of install device: %s", inst_device_size) LOGGER.warning("Recommended size: %s", recommended_size) (swap_type, swap_size, dump_type, dump_size) = \ screen.tc.calc_swap_dump_size(minimum_size, inst_device_size, swap_included=True) desired_zpool = get_desired_target_zpool(doc) if (swap_type == TargetController.SWAP_DUMP_ZVOL): swap_zvol = desired_zpool.add_zvol("swap", \ swap_size.get(Size.mb_units), Size.mb_units, use="swap") if (dump_type == TargetController.SWAP_DUMP_ZVOL): dump_zvol = desired_zpool.add_zvol("dump", \ dump_size.get(Size.mb_units), Size.mb_units, use="dump", create_failure_ok=True) LOGGER.info("Swap type: %s", swap_type) LOGGER.info("Swap size: %s", swap_size) LOGGER.info("Dump type: %s", dump_type) LOGGER.info("Dump size: %s", dump_size) # Specify for the shared datasets <root_pool>/export and # <root_pool>/export/home be created. We will specify # a mountpoint for <root_pool>/export dataset. # We must not specify a mountpoint for <root_pool>/export/home. # It should inherit the mountpoint from <root_pool>/export. desired_zpool.add_filesystem("export", mountpoint="/export") desired_zpool.add_filesystem("export/home") # Add the list of packages to be removed after the install to the DOC pkg_remove_list = ['pkg:/system/install/media/internal', 'pkg:/system/install/text-install'] pkg_spec = IPSSpec(action=IPSSpec.UNINSTALL, contents=pkg_remove_list) pkg_rm_node = Software(CLEANUP_CPIO_INSTALL, type="IPS") pkg_rm_node.insert_children(pkg_spec) doc.volatile.insert_children(pkg_rm_node) # execute the prepare transfer checkpoint. This checkpoint must # be executed by itself, before executing any of the transfer # related checkpoints. The transfer checkpoints requires # data setup from the prepare transfer checkpoint. (status, failed_cp) = engine.execute_checkpoints( start_from=TRANSFER_PREP, pause_before=VAR_SHARED_DATASET) if status != InstallEngine.EXEC_SUCCESS: err_data = (errsvc.get_errors_by_mod_id(TRANSFER_PREP))[0] LOGGER.error("%s checkpoint failed" % TRANSFER_PREP) err = err_data.error_data[liberrsvc.ES_DATA_EXCEPTION] LOGGER.error(err) raise ti_utils.InstallationError("Failed to execute checkpoint " "%s", TRANSFER_PREP) global INSTALL_STATUS INSTALL_STATUS = InstallStatus(screen, update_status_func) LOGGER.debug("Executing rest of checkpoints") engine.execute_checkpoints(callback=exec_callback, \ dry_run=install_data.no_install_mode) INSTALL_STATUS.report_status() if INSTALL_STATUS.exec_status is InstallEngine.EXEC_CANCELED: raise ti_utils.InstallationCanceledError("User selected cancel.") if INSTALL_STATUS.exec_status is InstallEngine.EXEC_FAILED: raise ti_utils.InstallationError("Failed executing checkpoints") if install_data.no_install_mode: # all subsequent code depends on the install target being # setup, so, can not execute them. return new_be = get_desired_target_be(doc) install_mountpoint = new_be.mountpoint # If swap was created, add appropriate entry to <target>/etc/vfstab LOGGER.debug("install mountpoint: %s", install_mountpoint) LOGGER.debug("new_be: %s", new_be) screen.tc.setup_vfstab_for_swap(ROOT_POOL, install_mountpoint) # Fix up the timezone before we reboot default_init_loc = install_mountpoint + '/etc/default/init' tzfile = open(default_init_loc, 'w') tzfile.write('TZ="' + timezone + '"\nCMASK=022\n') tzfile.close() # Write out the selected hostname nodename_log = install_mountpoint + '/etc/nodename' nodefile = open(nodename_log, 'w') nodefile.write(hostname + '\n') nodefile.close() post_install_cleanup(install_data)
class TestCleanupCPIOInstall(unittest.TestCase): '''test the functionality for CleanupCPIOInstall Class''' def setUp(self): '''Setup for tests''' # Test Packages self.TEXT_PKG_REMOVE_LIST = ['pkg:/system/install/media/internal', 'pkg:/system/install/text-install'] # packages added to the cleanup list self.add_files = ['file1', 'file2', 'file3'] self.filesys_files = ['/var/tmp/test_dir/', '/var/tmp/file1', '/var/tmp/file2', '/mnt/test_dir/file1', '/mnt/file2', '/mnt/file3', '/save/etc/gconf/schemas/panel-default-setup.entries', '/save/etc/X11/gdm/custom.conf', '/save/etc/xdg/autostart/updatemanagernotifier.desktop', '/save/usr/share/dbus-1/services/gnome-power-manager.service', '/save/usr/share/gnome/autostart/gnome-keyring-daemon-wrapper.desktop', '.livecd', '.volsetid', '.textinstall', 'etc/sysconfig/language', '.liveusb', 'a', 'bootcd_microroot', 'var/user/jack', 'var/cache/gdm/jack/dmrc', 'var/cache/gdm/jack/', '/save/bogus'] self.test_target = create_filesystem(*self.filesys_files) # Create a data object to hold the required data self.simple = CreateSimpleDataObjectCache(test_target=self.test_target) def tearDown(self): '''Tear down for the tests''' reset_engine() self.simple.doc = None if os.path.exists(self.test_target): os.unlink(self.test_target) def test_live_cd_cleanup_dry(self): '''Test the dry run functionality for cleanup_livecd''' # Create an IPS node for packages to be removed self.soft_node = Software("cleanup_cpio_install") self.pkg_rm_node = IPSSpec() self.pkg_rm_node.action = "uninstall" self.pkg_rm_node.contents = self.TEXT_PKG_REMOVE_LIST self.soft_node.insert_children([self.pkg_rm_node]) self.simple.doc.persistent.insert_children([self.soft_node]) # Create a CPIO node for files to be removed self.add_cleanup_node = CPIOSpec() self.add_cleanup_node.action = "uninstall" self.add_cleanup_node.contents = self.add_files self.soft_node.insert_children([self.add_cleanup_node]) cleanup_list = ['.livecd', '.volsetid', '.textinstall', 'etc/sysconfig/language', '.liveusb', 'a', 'bootcd_microroot', 'var/user/jack', 'var/cache/gdm/jack/dmrc', 'var/cache/gdm/jack/', 'file1', 'file2', 'file3'] # Instantiate the checkpoint self.clean_lcd = CleanupCPIOInstall("cleanup_cpio_install") # Call the execute command for the checkpoint # with dry_run set to true. try: self.clean_lcd.execute(dry_run=True) except Exception as e: self.fail(str(e)) self.assertEquals(cleanup_list, self.clean_lcd.cleanup_list) def test_get_progress_estimate(self): '''Test get progress estimate return value''' self.clean_lcd = CleanupCPIOInstall("cleanup_cpio_install") # Check the return value for the progress estimate self.assertEquals(self.clean_lcd.get_progress_estimate(), 60)
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")
class TestTransferSVR4Functions(unittest.TestCase): '''Tests for the TransferSVR4 class''' TEST_SRC_DIR = ROOT + "/var/tmp" TEST_DST_DIR = ROOT + "/tmp" def setUp(self): InstallEngine._instance = None InstallEngine() self.engine = InstallEngine.get_instance() self.doc = self.engine.data_object_cache.volatile self.soft_node = Software("SVR4Transfer", "SVR4") self.tr_node = SVR4Spec() self.soft_node.insert_children([self.tr_node]) self.doc.insert_children([self.soft_node]) self.tr_svr4 = TransferSVR4("SVR4Transfer") self.make_dummy_pkg(self.TEST_SRC_DIR + "/SUNWpkg1") self.make_dummy_pkg(self.TEST_SRC_DIR + "/SUNWpkg2") self.make_dummy_pkg(self.TEST_SRC_DIR + "/SUNWpkg3") if not os.path.isdir(AbstractSVR4.ADMIN_FILE_DIR): os.makedirs(AbstractSVR4.ADMIN_FILE_DIR, 0755) def tearDown(self): self.engine.data_object_cache.clear() self.doc = None self.engine = None self.soft_node = None self.tr_node = None self.tr_svr4 = None InstallEngine._instance = None shutil.rmtree(self.TEST_SRC_DIR + "/SUNWpkg1") shutil.rmtree(self.TEST_SRC_DIR + "/SUNWpkg2") shutil.rmtree(self.TEST_SRC_DIR + "/SUNWpkg3") if os.path.isdir(AbstractSVR4.ADMIN_FILE_DIR): os.removedirs(AbstractSVR4.ADMIN_FILE_DIR) def make_dummy_pkg(self, where): os.makedirs(where) fd = open(where + "/pkgmap", "w") fd.close() fd = open(where + "/pkginfo", "w") fd.close() def test_software_type(self): self.assertTrue(self.soft_node.tran_type == "SVR4") def test_cancel(self): '''Test the cancel method''' try: self.tr_svr4.cancel() except Exception as err: self.fail(str(err)) def test_check_cancel_event(self): self.tr_svr4._cancel_event = True try: self.tr_svr4.check_cancel_event() except Exception as err: self.fail(str(err)) def test_validate_dst(self): '''Test error is raised when no destination is registered''' self.tr_svr4.dst = None self.assertRaises(Exception, self.tr_svr4._validate_input) def test_validate_src(self): '''Test error is raised when no source is registered''' self.tr_svr4.dst = "/mydest" self.tr_svr4.src = None self.assertRaises(Exception, self.tr_svr4._validate_input) def test_validate_no_transfer_list(self): '''Test error is raised when transfer list is empty''' self.tr_svr4.dst = "/mydest" self.tr_svr4._transfer_list = [] self.assertRaises(Exception, self.tr_svr4._validate_input) def test_validate_no_args(self): ''''Test error is raised when no args are provided''' self.tr_svr4.dst = "/mydest" self.tr_svr4.src = "/mysrc" self.tr_svr4._transfer_list = [{ 'action': 'install', 'contents': ['mypkg'] }, { 'action': 'uninstall', 'contents': ["myuninstallpkg"] }] self.assertRaises(Exception, self.tr_svr4._validate_input) 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) 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 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_dst_not_specified(self): '''Test error when dst is not specified ''' src = Source() pub = Publisher() origin = Origin(self.TEST_SRC_DIR) pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True) 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_more_than_one_same_soft_node(self): '''Test error when multiple software nodes with same name ''' soft_node2 = Software("SVR4Transfer") self.doc.insert_children([soft_node2]) tr_node2 = SVR4Spec() soft_node2.insert_children([tr_node2]) self.doc.insert_children([soft_node2]) self.assertRaises(Exception, TransferSVR4, "SVR4Transfer") def test_more_than_one_soft_node(self): '''Test checkpoint and software node match correctly ''' 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"] soft_node2 = Software("SVR4Transfer2") self.doc.insert_children([soft_node2]) try: self.tr_svr4.execute(dry_run=True) except Exception as err: self.fail(str(err)) def test_checkpoint_soft_node_mismatch(self): '''Test fail when checkpoint and software node don't match ''' self.assertRaises(Exception, TransferSVR4, "SVR4_Transfer") def test_multiple_args_declared(self): '''Test having multiple args fails''' args = Args({"svr4_args": "-n -d"}) self.tr_node.insert_children([args]) args2 = Args({"svr4_args": "-n -d, mi"}) self.tr_node.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"] self.assertRaises(Exception, self.tr_svr4.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) 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_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)) 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 test_transfer_fail_install(self): '''Test that the transfer mechanism to install 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 = "install" self.tr_node.contents = ["SUNWpkg0"] self.assertRaises(Exception, self.tr_svr4.execute, dry_run=False) 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_install_bad_args(self): '''Test that the transfer install fails with bad SVR4 package 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 = "install" self.tr_node.contents = ["SUNWpkg1"] 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)
def test_info(self): '''Test that the arguments get into the node correctly''' # just dst, need to check default repo soft_node = Software("transfer test 1") tr_node = IPSSpec() soft_node.insert_children([tr_node]) self.doc.insert_children([soft_node]) dst = Destination() ips_image = Image("/rpool/dc", "create") self.img_type = ImType("full") ips_image.insert_children([self.img_type]) dst.insert_children([ips_image]) src = Source() pub = Publisher() origin = Origin("http://pkg.syneto.eu") pub.insert_children([origin]) src.insert_children([pub]) # first check src and dst soft_node.insert_children([dst, src, soft_node]) soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.syneto.eu") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, False) self.assertEqual(tr.action, None) self.assertEqual(tr.contents, None) self.assertEqual(tr.app_callback, None) self.assertEqual(tr.purge_history, False) # pkg install list is set tr_node.action = "install" tr_node.contents = ["SUNWcs", "SUNWcsr"] soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.syneto.eu") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, False) self.assertEqual(tr.contents, ["SUNWcs", "SUNWcsr"]) self.assertEqual(tr.action, "install") self.assertEqual(tr.purge_history, False) self.assertEqual(tr.app_callback, None) # pkg uninstall list is set tr_node.action = "uninstall" tr_node.contents = ["SUNWcs"] soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.syneto.eu") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, False) self.assertEqual(tr.action, "uninstall") self.assertEqual(tr.contents, ["SUNWcs"]) self.assertEqual(tr.purge_history, False) self.assertEqual(tr.app_callback, None) # purge history is set to true tr_node.purge_history = True soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.syneto.eu") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, False) self.assertEqual(tr.action, "uninstall") self.assertEqual(tr.contents, ["SUNWcs"]) self.assertEqual(tr.purge_history, True) # is zone is set to True self.img_type.zone = True soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.syneto.eu") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, True) self.assertEqual(tr.action, "uninstall") self.assertEqual(tr.contents, ["SUNWcs"]) self.assertEqual(tr.purge_history, True) # completeness is set to IMG_TYPE_PARTIAL self.img_type.completeness = IMG_TYPE_PARTIAL soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.syneto.eu") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, IMG_TYPE_PARTIAL) self.assertEqual(img_type[0].zone, True) self.assertEqual(tr.action, "uninstall") self.assertEqual(tr.contents, ["SUNWcs"]) self.assertEqual(tr.purge_history, True)
class TestIPSFunctions(unittest.TestCase): IPS_IMG_DIR = "/rpool/test_ips" 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 tearDown(self): self.engine.data_object_cache.clear() InstallEngine._instance = None self.doc = None self.soft_node = None self.tr_node = None self.tr_ips = None self.engine = None def test_create(self): '''Test that the IPS Transfer object is created''' try: try_ips = TransferIPS("IPS transfer") except (TypeError, NameError): self.fail("Failed to create TransferIPS object") def test_install(self): '''Test that an IPS package can be installed''' self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs", "entire"] try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_uninstall(self): '''Test that an IPS package can be uninstalled''' self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs", "system/library/svm-rcm"] self.tr_node2 = IPSSpec() self.tr_node2.action = "uninstall" self.tr_node2.contents = ["system/library/svm-rcm"] self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_purge_history(self): '''Test that the history is purged''' self.tr_node.purge_history = True self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs"] try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) 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_image_args(self): '''Test that setting Args for the image works''' image_args = Args(arg_dict={"force": True}) self.ips_image.insert_children([image_args]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_ssl_key_in_image_args(self): '''Test that setting ssl_key in image_args produces an error''' image_args = Args(arg_dict={"ssl_key": "aaa"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) def test_ssl_cert_in_image_args(self): '''Test that setting ssl_cert in image_args produces an error''' image_args = Args(arg_dict={"ssl_cert": "aaa"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) def test_install_args(self): '''Test that setting Args for the install works''' install_args = Args(arg_dict={"refresh_catalogs": False}) self.tr_node.insert_children([install_args]) self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs"] try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_uninstall_args(self): '''Test that setting Args for the uninstall works''' uninstall_args = Args(arg_dict={"update_index": False}) self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs", "system/library/svm-rcm"] self.tr_node2 = IPSSpec() self.tr_node2.action = "uninstall" self.tr_node2.contents = ["system/library/svm-rcm"] self.tr_node2.insert_children([uninstall_args]) self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_default_publisher(self): '''Test that using the default publisher succeeds''' src = Source() pub = Publisher() origin = Origin("http://ipkg.sfbay.sun.com/release/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_multiple_sources(self): '''Test that setting multiple sources succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") pub2 = Publisher("contrib.opensolaris.org") origin2 = Origin("http://ipkg.sfbay.sun.com/contrib/") pub3 = Publisher("extra") origin3 = Origin("http://ipkg.sfbay.sun.com/extra/") pub.insert_children([origin]) pub2.insert_children([origin2]) pub3.insert_children([origin3]) src.insert_children([pub, pub2, pub3]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_source_addition(self): '''Test that adding additional sources succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/dev/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) # Now add another publisher to the repo self.ips_image.action = "update" pub2 = Publisher("extra") origin2 = Origin("http://ipkg.sfbay.sun.com/extra/") pub2.insert_children([origin2]) src.insert_children([pub2]) try: self.tr_ips.execute(dry_run=DRY_RUN) 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)) def test_mirrors(self): '''Test creating mirrors succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") mirror = Mirror("http://ipkg.central.sun.com:8000/") pub.insert_children([origin, mirror]) src.insert_children([pub]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_set_property(self): '''Test that setting properties succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") pub2 = Publisher("contrib.opensolaris.org") origin2 = Origin("http://ipkg.sfbay.sun.com/contrib/") pub3 = Publisher("extra") origin3 = Origin("http://ipkg.sfbay.sun.com/extra/") pub.insert_children([origin]) pub2.insert_children([origin2]) pub3.insert_children([origin3]) src.insert_children([pub, pub2, pub3]) self.soft_node.insert_children([src]) prop = Property("display-copyrights", 'False') prop2 = Property("preferred-publisher", "extra") self.ips_image.insert_children([prop, prop2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_set_create_facets(self): '''Test that creating facets succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) facet = Facet("facet.doc", 'True') self.ips_image.insert_children([facet]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_set_invalid_facets(self): '''Ensure an error is raised for an invalid facet''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) facet = Facet("doc", 'True') self.ips_image.insert_children([facet]) self.assertRaises(Exception, self.tr_ips.execute) def test_progress_estimate(self): '''Test that progress estimate succeeds''' self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs", "SUNWcsd", "entire", "SUNWmd", "babel_install"] try: estimate = self.tr_ips.get_progress_estimate() except Exception as err: self.fail(str(err)) self.assertTrue(estimate == self.tr_ips.DEFAULT_PROG_EST * \ (len(self.tr_node.contents) / self.tr_ips.DEFAULT_PKG_NUM)) def test_invalid_args(self): '''Ensure error raised when repo components are set as args''' image_args = Args(arg_dict={"prefix": "prefix string"}) self.ips_image.insert_children([image_args]) self.assertRaises(ValueError, self.tr_ips.execute, dry_run=DRY_RUN) # Test repo_uri fails self.ips_image.delete_children() image_args = Args(arg_dict={"repo_uri": "url string"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) # Test origins fails self.ips_image.delete_children() image_args = Args(arg_dict={"origins": "origin string"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) # Test mirrors fails self.ips_image.delete_children() image_args = Args(arg_dict={"mirrors": "mirror string"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) def test_checkpoint_soft_node_match(self): '''The checkpoint and software node match''' try: tr_ips = TransferIPS("IPS transfer") except Exception as err: self.fail(str(err))
class TestCPIOFunctions(unittest.TestCase): TEST_DST_DIR = "/tmp/cpio_test_dir" TEST_SRC_DIR = "/" TEST_FILE_LIST_FILE = "/tmp/test_file_list" TEST_CONTENTS_LIST = [] TEST_DIR_LIST_FILE = "/tmp/test_dir_list" TEST_SKIP_FILE_LIST_FILE = "/tmp/test_skip_file_list" TEST_DIR_EXCL_LIST_FILE = "/tmp/test_dir_excl_list" TEST_MEDIA_TRANSFORM = "/tmp/media_transform" def setUp(self): InstallEngine._instance = None InstallEngine() self.engine = InstallEngine.get_instance() self.doc = self.engine.data_object_cache.volatile self.soft_node = Software("CPIO_Transfer", "CPIO") self.tr_node = CPIOSpec() self.soft_node.insert_children([self.tr_node]) self.doc.insert_children([self.soft_node]) self.tr_cpio = TransferCPIO("CPIO_Transfer") def tearDown(self): if os.access(self.TEST_DST_DIR, os.F_OK): shutil.rmtree(self.TEST_DST_DIR) if os.access(self.TEST_FILE_LIST_FILE, os.F_OK): os.unlink(self.TEST_FILE_LIST_FILE) if os.access(self.TEST_DIR_LIST_FILE, os.F_OK): os.unlink(self.TEST_DIR_LIST_FILE) if os.access(self.TEST_SKIP_FILE_LIST_FILE, os.F_OK): os.unlink(self.TEST_SKIP_FILE_LIST_FILE) if os.access(self.TEST_DST_DIR, os.F_OK): os.unlink(self.TEST_DST_DIR) if os.access(self.TEST_MEDIA_TRANSFORM, os.F_OK): os.unlink(self.TEST_MEDIA_TRANSFORM) if os.access("/tmp/media_not_exec", os.F_OK): os.unlink("/tmp/media_not_exec") self.engine.data_object_cache.clear() self.doc = None self.engine = None self.soft_node = None self.tr_node = None self.tr_cpio = None InstallEngine._instance = None TEST_CONTENTS_LIST = [] def test_software_type(self): self.assertTrue(self.soft_node.tran_type == "CPIO") def test_entire(self): '''Test transfer all of /etc/X11 to /rpool/cpio_test_dir succeeds''' # 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 = ["./"] 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_cleanup_temp_files_nonexistent_file(self): '''Test cleanup temp files should check nonexistent''' self.tr_cpio._transfer_list = [{'action': 'install', 'cpio_args': '-pdum', 'contents': '/noexist'}] try: self.tr_cpio._cleanup_tmp_files() 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_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_dir_list(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]) # 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)) 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)) def test_cpio_w_empty_list(self): ''' Test that an error is raised when contents list is empty''' # 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.assertRaises(Exception, self.tr_cpio.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) 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)) def test_skip_file_list_list(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 self.tr_node.contents = ["etc/dhcp"] # 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.tr_node2.contents = ["etc/dhcp/duid", "etc/dhcp/iaid"] self.soft_node.insert_children([self.tr_node2]) # Set up the destination dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) try: self.tr_cpio.execute(dry_run=True) except Exception as err: self.fail(str(err)) 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)) 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_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_dst_not_specified(self): ''' Test that an error is raised when dst is not specified''' # Test that an error is raised. src = Source() src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11") path = Dir(src_path) src.insert_children([path]) self.soft_node.insert_children([src]) self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True) def test_skip_file_list_file_not_valid(self): '''Test that an error is raised for invalid skip_file_list file''' # 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]) 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_file" self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True) def test_dir_list_not_valid(self): '''Test that an error is raised for invalid dir_list file''' 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 = "/tmp/invalid_dir_file" self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True) 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_media_transform_not_valid(self): '''Test that an error is raised for invalid media_transform executable ''' 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 = "/tmp/invalid_transform_file" self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True) def test_media_transform_not_executable(self): '''Test media_transform doesn't have correct permissions error ''' 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 = "/tmp/media_not_exec" open(self.tr_node.contents, 'w') os.chmod(self.tr_node.contents, 01666) self.assertRaises(Exception, self.tr_cpio.execute, dry_run=False) try: os.unlink(self.tr_node.contents) except (Exception): pass def test_progress_estimate_invalid_src(self): '''Test the progress estimate value when src is invalid. ''' src = Source() src_path = os.path.join(self.TEST_SRC_DIR, "/bogus") 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 = ["./"] try: progress_estimate = self.tr_cpio.get_progress_estimate() except: self.assertTrue(False) self.assertTrue(progress_estimate == 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)) 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) 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_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_checkpoint_soft_node_match(self): '''The checkpoint and software node match ''' try: tr_cpio = TransferCPIO("CPIO_Transfer") except Exception as err: self.fail(str(err)) def test_checkpoint_soft_node_mismatch(self): '''The checkpoint and software node match as expected ''' self.assertRaises(Exception, TransferCPIO, "CPIO Transfer")
class TestCPIOFunctions(unittest.TestCase): TEST_DST_DIR = "/tmp/cpio_test_dir" TEST_SRC_DIR = "/" TEST_FILE_LIST_FILE = "/tmp/test_file_list" TEST_CONTENTS_LIST = [] TEST_DIR_LIST_FILE = "/tmp/test_dir_list" TEST_SKIP_FILE_LIST_FILE = "/tmp/test_skip_file_list" TEST_DIR_EXCL_LIST_FILE = "/tmp/test_dir_excl_list" TEST_MEDIA_TRANSFORM = "/tmp/media_transform" def setUp(self): InstallEngine._instance = None InstallEngine() self.engine = InstallEngine.get_instance() self.doc = self.engine.data_object_cache.volatile self.soft_node = Software("CPIO_Transfer", "CPIO") self.tr_node = CPIOSpec() self.soft_node.insert_children([self.tr_node]) self.doc.insert_children([self.soft_node]) self.tr_cpio = TransferCPIO("CPIO_Transfer") def tearDown(self): if os.access(self.TEST_DST_DIR, os.F_OK): shutil.rmtree(self.TEST_DST_DIR) if os.access(self.TEST_FILE_LIST_FILE, os.F_OK): os.unlink(self.TEST_FILE_LIST_FILE) if os.access(self.TEST_DIR_LIST_FILE, os.F_OK): os.unlink(self.TEST_DIR_LIST_FILE) if os.access(self.TEST_SKIP_FILE_LIST_FILE, os.F_OK): os.unlink(self.TEST_SKIP_FILE_LIST_FILE) if os.access(self.TEST_DST_DIR, os.F_OK): os.unlink(self.TEST_DST_DIR) if os.access(self.TEST_MEDIA_TRANSFORM, os.F_OK): os.unlink(self.TEST_MEDIA_TRANSFORM) if os.access("/tmp/media_not_exec", os.F_OK): os.unlink("/tmp/media_not_exec") self.engine.data_object_cache.clear() self.doc = None self.engine = None self.soft_node = None self.tr_node = None self.tr_cpio = None InstallEngine._instance = None TEST_CONTENTS_LIST = [] def test_software_type(self): self.assertTrue(self.soft_node.tran_type == "CPIO") def test_entire(self): '''Test transfer all of /etc/X11 to /rpool/cpio_test_dir succeeds''' # 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 = ["./"] 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_cleanup_temp_files_nonexistent_file(self): '''Test cleanup temp files should check nonexistent''' self.tr_cpio._transfer_list = [{ 'action': 'install', 'cpio_args': '-pdum', 'contents': '/noexist' }] try: self.tr_cpio._cleanup_tmp_files() 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_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_dir_list(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]) # 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)) 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)) def test_cpio_w_empty_list(self): ''' Test that "empty contents list" 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 self.tr_node.action = "install" self.tr_node.contents = [] try: self.tr_cpio.execute(dry_run=True) except Exception as err: self.fail(str(err)) 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)) 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)) def test_skip_file_list_list(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 self.tr_node.contents = ["etc/dhcp"] # 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.tr_node2.contents = ["etc/dhcp/duid", "etc/dhcp/iaid"] self.soft_node.insert_children([self.tr_node2]) # Set up the destination dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) try: self.tr_cpio.execute(dry_run=True) except Exception as err: self.fail(str(err)) 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)) 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_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_dst_not_specified(self): ''' Test that an error is raised when dst is not specified''' # Test that an error is raised. src = Source() src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11") path = Dir(src_path) src.insert_children([path]) self.soft_node.insert_children([src]) self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True) def test_skip_file_list_file_not_valid(self): '''Test that an error is raised for invalid skip_file_list file''' # 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]) 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_file" self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True) def test_dir_list_not_valid(self): '''Test that an error is raised for invalid dir_list file''' 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 = "/tmp/invalid_dir_file" self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True) 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_media_transform_not_valid(self): '''Test that an error is raised for invalid media_transform executable ''' 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 = "/tmp/invalid_transform_file" self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True) def test_media_transform_not_executable(self): '''Test media_transform doesn't have correct permissions error ''' 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 = "/tmp/media_not_exec" open(self.tr_node.contents, 'w') os.chmod(self.tr_node.contents, 01666) self.assertRaises(Exception, self.tr_cpio.execute, dry_run=False) try: os.unlink(self.tr_node.contents) except (Exception): pass def test_progress_estimate_invalid_src(self): '''Test the progress estimate value when src is invalid. ''' src = Source() src_path = os.path.join(self.TEST_SRC_DIR, "/bogus") 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 = ["./"] try: progress_estimate = self.tr_cpio.get_progress_estimate() except: self.assertTrue(False) self.assertTrue(progress_estimate == 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)) 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) 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_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_checkpoint_soft_node_match(self): '''The checkpoint and software node match ''' try: tr_cpio = TransferCPIO("CPIO_Transfer") except Exception as err: self.fail(str(err)) def test_checkpoint_soft_node_mismatch(self): '''The checkpoint and software node match as expected ''' self.assertRaises(Exception, TransferCPIO, "CPIO Transfer")
def test_info(self): '''Test that the arguments get into the node correctly''' # just dst, need to check default repo soft_node = Software("transfer test 1") tr_node = IPSSpec() soft_node.insert_children([tr_node]) self.doc.insert_children([soft_node]) dst = Destination() ips_image = Image("/rpool/dc", "create") self.img_type = ImType("full") ips_image.insert_children([self.img_type]) dst.insert_children([ips_image]) src = Source() pub = Publisher() origin = Origin("http://pkg.omniti.com/omnios/release") pub.insert_children([origin]) src.insert_children([pub]) # first check src and dst soft_node.insert_children([dst, src, soft_node]) soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.omniti.com/omnios/release") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, False) self.assertEqual(tr.action, None) self.assertEqual(tr.contents, None) self.assertEqual(tr.app_callback, None) self.assertEqual(tr.purge_history, False) # pkg install list is set tr_node.action = "install" tr_node.contents = ["SUNWcs", "SUNWcsr"] soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.omniti.com/omnios/release") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, False) self.assertEqual(tr.contents, ["SUNWcs", "SUNWcsr"]) self.assertEqual(tr.action, "install") self.assertEqual(tr.purge_history, False) self.assertEqual(tr.app_callback, None) # pkg uninstall list is set tr_node.action = "uninstall" tr_node.contents = ["SUNWcs"] soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.omniti.com/omnios/release") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, False) self.assertEqual(tr.action, "uninstall") self.assertEqual(tr.contents, ["SUNWcs"]) self.assertEqual(tr.purge_history, False) self.assertEqual(tr.app_callback, None) # purge history is set to true tr_node.purge_history = True soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.omniti.com/omnios/release") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, False) self.assertEqual(tr.action, "uninstall") self.assertEqual(tr.contents, ["SUNWcs"]) self.assertEqual(tr.purge_history, True) # is zone is set to True self.img_type.zone = True soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.omniti.com/omnios/release") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, "full") self.assertEqual(img_type[0].zone, True) self.assertEqual(tr.action, "uninstall") self.assertEqual(tr.contents, ["SUNWcs"]) self.assertEqual(tr.purge_history, True) # completeness is set to IMG_TYPE_PARTIAL self.img_type.completeness = IMG_TYPE_PARTIAL soft_list = self.doc.get_children("transfer test 1", Software) for soft in soft_list: tr_list = soft.get_children(class_type=IPSSpec) for tr in tr_list: src_list = soft.get_children("source", Source) self.assertEqual(len(src_list), 1) pub = src_list[0].get_children("publisher", Publisher) origin = pub[0].get_children("origin", Origin) self.assertEqual(origin[0].origin, "http://pkg.omniti.com/omnios/release") dst_list = soft.get_children("destination", Destination) self.assertEqual(len(dst_list), 1) image = dst_list[0].get_children("image", Image) self.assertEqual(len(image), 1) img_type = image[0].get_children("img_type", ImType) self.assertEqual(len(img_type), 1) self.assertEqual(image[0].img_root, "/rpool/dc") self.assertEqual(image[0].action, "create") self.assertEqual(img_type[0].completeness, IMG_TYPE_PARTIAL) self.assertEqual(img_type[0].zone, True) self.assertEqual(tr.action, "uninstall") self.assertEqual(tr.contents, ["SUNWcs"]) self.assertEqual(tr.purge_history, 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)
def perform_installation(self): '''method which actually does the installation.''' # establish the timer that will update the screen messaging timer = glib.timeout_add(INSTALLATION_TIMEOUT, self._update_screen_message) eng = InstallEngine.get_instance() errsvc.clear_error_list() eng.execute_checkpoints(start_from=TRANSFER_PREP, pause_before=VARSHARE_DATASET) # Setup progress handling self.setup_progress_handling() self.logger.info("Setting up software to install/uninstall") # Add the list of packages to be removed after the install to the DOC pkg_remove_list = [ 'pkg:/system/install/media/internal', 'pkg:/system/install/gui-install' ] pkg_spec = IPSSpec(action=IPSSpec.UNINSTALL, contents=pkg_remove_list) pkg_rm_node = Software(CLEANUP_CPIO_INSTALL, type="IPS") pkg_rm_node.insert_children(pkg_spec) eng.doc.volatile.insert_children(pkg_rm_node) # Setup system configuration data profile = from_engine() gui_profile = eng.data_object_cache.volatile.get_first_child( name="GUI Install", class_type=InstallProfile) if gui_profile is None: SystemExit('Internal Error, GUI Install DOC not found') profile.system = SystemInfo(hostname=gui_profile.hostname, tz_region=gui_profile.continent, tz_country=gui_profile.country, tz_timezone=gui_profile.timezone, locale=gui_profile.default_locale) profile.nic = NetworkInfo(net_type="automatic") # Setup user configuration data root = UserInfo(login_name="root", is_role=True, password=gui_profile.userpassword, expire="0") user = UserInfo(gid=10, shell="/usr/bin/bash", login_name=gui_profile.loginname, real_name=gui_profile.username, password=gui_profile.userpassword, roles="root", profiles="System Administrator", sudoers="ALL=(ALL) ALL") profile.users = UserInfoContainer(user, root) self.logger.debug('from_engine returned %s', profile) gui_profile.set_log(DEFAULT_LOG_LOCATION, LOG_LOCATION_FINAL) # Run the registered checkpoints errsvc.clear_error_list() eng.execute_checkpoints(callback=self.install_callback) self.logger.info("Install Started") return False
def do_ti_install(install_data, screen, update_status_func): '''Installation engine for text installer. Raises InstallationError for any error occurred during install. ''' sysconfig_profile = sysconfig.profile.from_engine() # # The following information is needed for installation. # Make sure they are provided before even starting # # timezone timezone = sysconfig_profile.system.tz_timezone LOGGER.debug("time zone: %s", timezone) # Validate the value specified for timezone if not tz_isvalid(timezone): LOGGER.error("Timezone value specified (%s) is not valid", timezone) raise ti_utils.InstallationError # Compute the time to set. install_time = datetime.datetime.now() + \ sysconfig_profile.system.time_offset # Set the system time to the time specified by the user. cmd = ["/usr/bin/date", install_time.strftime("%m%d%H%M%y")] Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE, logger=LOGGER) hostname = sysconfig_profile.system.hostname LOGGER.debug("hostname: " + hostname) engine = InstallEngine.get_instance() doc = engine.doc # look to see if the target disk has 'whole_disk' set disk = get_desired_target_disk(doc) if disk.whole_disk: inst_device_size = disk.disk_prop.dev_size else: # look for a GPT partition first gpt_partition = get_solaris_gpt_partition(doc) if gpt_partition is None: solaris_slice = get_solaris_slice(doc) if solaris_slice is None: raise ti_utils.InstallationError("Unable to find solaris " "slice") inst_device_size = solaris_slice.size else: inst_device_size = gpt_partition.size LOGGER.info("Installation Device Size: %s", inst_device_size) minimum_size = screen.tc.minimum_target_size LOGGER.info("Minimum required size: %s", minimum_size) if inst_device_size < minimum_size: LOGGER.error("Size of device specified for installation " "is too small") LOGGER.error("Size of install device: %s", inst_device_size) LOGGER.error("Minimum required size: %s", minimum_size) raise ti_utils.InstallationError recommended_size = screen.tc.recommended_target_size LOGGER.info("Recommended size: %s", recommended_size) if inst_device_size < recommended_size: # Warn users that their install target size is not optimal # Just log the warning, but continue with the installation. LOGGER.warning("Size of device specified for installation is " "not optimal") LOGGER.warning("Size of install device: %s", inst_device_size) LOGGER.warning("Recommended size: %s", recommended_size) (swap_type, swap_size, dump_type, dump_size) = \ screen.tc.calc_swap_dump_size(minimum_size, inst_device_size, swap_included=True) desired_zpool = get_desired_target_zpool(doc) if swap_type == TargetController.SWAP_DUMP_ZVOL: desired_zpool.add_zvol("swap", swap_size.get(Size.mb_units), Size.mb_units, use="swap") if dump_type == TargetController.SWAP_DUMP_ZVOL: desired_zpool.add_zvol("dump", dump_size.get(Size.mb_units), Size.mb_units, use="dump", create_failure_ok=True) LOGGER.info("Swap type: %s", swap_type) LOGGER.info("Swap size: %s", swap_size) LOGGER.info("Dump type: %s", dump_type) LOGGER.info("Dump size: %s", dump_size) # Specify for the shared datasets <root_pool>/export and # <root_pool>/export/home be created. We will specify # a mountpoint for <root_pool>/export dataset. # We must not specify a mountpoint for <root_pool>/export/home. # It should inherit the mountpoint from <root_pool>/export. desired_zpool.add_filesystem("export", mountpoint="/export") desired_zpool.add_filesystem("export/home") # Add the list of packages to be removed after the install to the DOC pkg_remove_list = [ 'pkg:/system/install/media/internal', 'pkg:/system/install/text-install' ] pkg_spec = IPSSpec(action=IPSSpec.UNINSTALL, contents=pkg_remove_list) pkg_rm_node = Software(CLEANUP_CPIO_INSTALL, type="IPS") pkg_rm_node.insert_children(pkg_spec) doc.volatile.insert_children(pkg_rm_node) # execute the prepare transfer checkpoint. This checkpoint must be # executed by itself, before executing any of the transfer related # checkpoints. The transfer checkpoints requires data setup from the # prepare transfer checkpoint. status, failed_cp = engine.execute_checkpoints( start_from=TRANSFER_PREP, pause_before=VARSHARE_DATASET) if status != InstallEngine.EXEC_SUCCESS: err_data = errsvc.get_errors_by_mod_id(TRANSFER_PREP)[0] LOGGER.error("%s checkpoint failed" % TRANSFER_PREP) err = err_data.error_data[liberrsvc.ES_DATA_EXCEPTION] LOGGER.error(err) raise ti_utils.InstallationError("Failed to execute checkpoint " "%s", TRANSFER_PREP) global INSTALL_STATUS INSTALL_STATUS = InstallStatus(screen, update_status_func) LOGGER.debug("Executing rest of checkpoints") engine.execute_checkpoints(callback=exec_callback, dry_run=install_data.no_install_mode) INSTALL_STATUS.report_status() if INSTALL_STATUS.exec_status is InstallEngine.EXEC_CANCELED: raise ti_utils.InstallationCanceledError("User selected cancel.") if INSTALL_STATUS.exec_status is InstallEngine.EXEC_FAILED: raise ti_utils.InstallationError("Failed executing checkpoints") if install_data.no_install_mode: # all subsequent code depends on the install target being setup return new_be = get_desired_target_be(doc) install_mountpoint = new_be.mountpoint # If swap was created, add appropriate entry to <target>/etc/vfstab LOGGER.debug("install mountpoint: %s", install_mountpoint) LOGGER.debug("new_be: %s", new_be) screen.tc.setup_vfstab_for_swap(ROOT_POOL, install_mountpoint) post_install_cleanup(install_data)
class TestIPSFunctions(unittest.TestCase): IPS_IMG_DIR = "/rpool/test_ips" 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 tearDown(self): self.engine.data_object_cache.clear() InstallEngine._instance = None self.doc = None self.soft_node = None self.tr_node = None self.tr_ips = None self.engine = None def test_create(self): '''Test that the IPS Transfer object is created''' try: try_ips = TransferIPS("IPS transfer") except (TypeError, NameError): self.fail("Failed to create TransferIPS object") def test_install(self): '''Test that an IPS package can be installed''' self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs", "entire"] try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_uninstall(self): '''Test that an IPS package can be uninstalled''' self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs", "system/library/svm-rcm"] self.tr_node2 = IPSSpec() self.tr_node2.action = "uninstall" self.tr_node2.contents = ["system/library/svm-rcm"] self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_purge_history(self): '''Test that the history is purged''' self.tr_node.purge_history = True self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs"] try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) 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_image_args(self): '''Test that setting Args for the image works''' image_args = Args(arg_dict={"force": True}) self.ips_image.insert_children([image_args]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_ssl_key_in_image_args(self): '''Test that setting ssl_key in image_args produces an error''' image_args = Args(arg_dict={"ssl_key": "aaa"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) def test_ssl_cert_in_image_args(self): '''Test that setting ssl_cert in image_args produces an error''' image_args = Args(arg_dict={"ssl_cert": "aaa"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) def test_install_args(self): '''Test that setting Args for the install works''' install_args = Args(arg_dict={"refresh_catalogs": False}) self.tr_node.insert_children([install_args]) self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs"] try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_uninstall_args(self): '''Test that setting Args for the uninstall works''' uninstall_args = Args(arg_dict={"update_index": False}) self.tr_node.action = "install" self.tr_node.contents = ["SUNWcs", "system/library/svm-rcm"] self.tr_node2 = IPSSpec() self.tr_node2.action = "uninstall" self.tr_node2.contents = ["system/library/svm-rcm"] self.tr_node2.insert_children([uninstall_args]) self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_install_reject_noargs(self): '''Test that an IPS package can be rejected''' self.tr_node.action = "install" self.tr_node.contents = ["solaris-large-server"] self.tr_node.reject_list = ["slocate"] self.tr_node2 = IPSSpec() self.tr_node2.action = "install" self.tr_node2.contents = ["system/library/svm-rcm"] self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_install_reject_with_args(self): '''Test that an IPS package can be rejected with args''' install_args = Args(arg_dict={"update_index": False}) self.tr_node.action = "install" self.tr_node.reject_list = ["slocate"] self.tr_node.contents = ["solaris-large-server"] self.tr_node.insert_children([install_args]) self.tr_node2 = IPSSpec() self.tr_node2.action = "install" self.tr_node2.contents = ["system/library/svm-rcm"] self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_avoid_noargs(self): '''Test that an IPS package can be avoided''' self.tr_node.action = "avoid" self.tr_node.contents = ["solaris-large-server"] self.tr_node2 = IPSSpec() self.tr_node2.action = "avoid" self.tr_node2.contents = ["system/library/svm-rcm"] self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_avoid_with_args(self): '''Test that an IPS package can be avoided with args''' install_args = Args(arg_dict={"update_index": False}) self.tr_node.action = "avoid" self.tr_node.contents = ["solaris-large-server"] self.tr_node.insert_children([install_args]) self.tr_node2 = IPSSpec() self.tr_node2.action = "avoid" self.tr_node2.contents = ["system/library/svm-rcm"] self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_unavoid_noargs(self): '''Test that an IPS package can be unavoided''' self.tr_node.action = "unavoid" self.tr_node.contents = ["solaris-large-server"] self.tr_node2 = IPSSpec() self.tr_node2.action = "unavoid" self.tr_node2.contents = ["system/library/svm-rcm"] self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_unavoid_with_args(self): '''Test that an IPS package can be rejected with args''' install_args = Args(arg_dict={"update_index": False}) self.tr_node.action = "unavoid" self.tr_node.contents = ["solaris-large-server"] self.tr_node.insert_children([install_args]) self.tr_node2 = IPSSpec() self.tr_node2.action = "unavoid" self.tr_node2.contents = ["system/library/svm-rcm"] self.soft_node.insert_children([self.tr_node2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_default_publisher(self): '''Test that using the default publisher succeeds''' src = Source() pub = Publisher() origin = Origin("http://ipkg.sfbay.sun.com/release/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_multiple_sources(self): '''Test that setting multiple sources succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") pub2 = Publisher("contrib.opensolaris.org") origin2 = Origin("http://ipkg.sfbay.sun.com/contrib/") pub3 = Publisher("extra") origin3 = Origin("http://ipkg.sfbay.sun.com/extra/") pub.insert_children([origin]) pub2.insert_children([origin2]) pub3.insert_children([origin3]) src.insert_children([pub, pub2, pub3]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_source_addition(self): '''Test that adding additional sources succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/dev/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) # Now add another publisher to the repo self.ips_image.action = "update" pub2 = Publisher("extra") origin2 = Origin("http://ipkg.sfbay.sun.com/extra/") pub2.insert_children([origin2]) src.insert_children([pub2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_source_omit_name_first_success(self): '''Test that omitting name is allowed for first publisher''' src = Source() pub = Publisher("") origin = Origin("http://ipkg.sfbay.sun.com/dev/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_source_omit_additional_publ_name_fails_1(self): '''Test that adding additional sources omitting name fails''' src = Source() pub = Publisher("") origin = Origin("http://ipkg.sfbay.sun.com/dev/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) # Now add another publisher to the repo self.ips_image.action = "update" pub2 = Publisher("") origin2 = Origin("http://ipkg.sfbay.sun.com/extra/") pub2.insert_children([origin2]) src.insert_children([pub2]) try: self.tr_ips.execute(dry_run=DRY_RUN) self.fail("Shouldn't succeed omitting name of second publisher") except ValueError as err: pass except Exception as err: self.fail(str(err)) def test_source_omit_additional_publ_name_fails_2(self): '''Test that adding additional sources omitting name fails''' src = Source() pub = Publisher("") origin = Origin("http://ipkg.sfbay.sun.com/dev/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) # Now add another publisher to the repo self.ips_image.action = "update" pub2 = Publisher("extra") origin2 = Origin("http://ipkg.sfbay.sun.com/extra/") pub2.insert_children([origin2]) src.insert_children([pub2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) # Now add another publisher to the repo self.ips_image.action = "update" pub3 = Publisher("") origin3 = Origin("http://ipkg.sfbay.sun.com/an-other/") pub3.insert_children([origin3]) src.insert_children([pub3]) try: self.tr_ips.execute(dry_run=DRY_RUN) self.fail("Shouldn't succeed omitting name of third publisher") except ValueError as err: pass 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)) def test_mirrors(self): '''Test creating mirrors succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") mirror = Mirror("http://ipkg.central.sun.com:8000/") pub.insert_children([origin, mirror]) src.insert_children([pub]) self.soft_node.insert_children([src]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_set_property(self): '''Test that setting properties succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") pub2 = Publisher("contrib.opensolaris.org") origin2 = Origin("http://ipkg.sfbay.sun.com/contrib/") pub3 = Publisher("extra") origin3 = Origin("http://ipkg.sfbay.sun.com/extra/") pub.insert_children([origin]) pub2.insert_children([origin2]) pub3.insert_children([origin3]) src.insert_children([pub, pub2, pub3]) self.soft_node.insert_children([src]) prop = Property("display-copyrights", 'False') prop2 = Property("preferred-publisher", "extra") self.ips_image.insert_children([prop, prop2]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_set_create_facets(self): '''Test that creating facets succeeds''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) facet = Facet("facet.doc", 'True') self.ips_image.insert_children([facet]) try: self.tr_ips.execute(dry_run=DRY_RUN) except Exception as err: self.fail(str(err)) def test_set_invalid_facets(self): '''Ensure an error is raised for an invalid facet''' src = Source() pub = Publisher("opensolaris.org") origin = Origin("http://ipkg.sfbay.sun.com/release/") pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) facet = Facet("doc", 'True') self.ips_image.insert_children([facet]) self.assertRaises(Exception, self.tr_ips.execute) def test_progress_estimate(self): '''Test that progress estimate succeeds''' self.tr_node.action = "install" self.tr_node.contents = [ "SUNWcs", "SUNWcsd", "entire", "SUNWmd", "babel_install" ] try: estimate = self.tr_ips.get_progress_estimate() except Exception as err: self.fail(str(err)) self.assertTrue(estimate == self.tr_ips.DEFAULT_PROG_EST * \ (len(self.tr_node.contents) / self.tr_ips.DEFAULT_PKG_NUM)) def test_invalid_args(self): '''Ensure error raised when repo components are set as args''' image_args = Args(arg_dict={"prefix": "prefix string"}) self.ips_image.insert_children([image_args]) self.assertRaises(ValueError, self.tr_ips.execute, dry_run=DRY_RUN) # Test repo_uri fails self.ips_image.delete_children() image_args = Args(arg_dict={"repo_uri": "url string"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) # Test origins fails self.ips_image.delete_children() image_args = Args(arg_dict={"origins": "origin string"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) # Test mirrors fails self.ips_image.delete_children() image_args = Args(arg_dict={"mirrors": "mirror string"}) self.ips_image.insert_children([image_args]) self.assertRaises(Exception, self.tr_ips.execute, dry_run=DRY_RUN) def test_checkpoint_soft_node_match(self): '''The checkpoint and software node match''' try: tr_ips = TransferIPS("IPS transfer") except Exception as err: self.fail(str(err))
class TestTransferSVR4Functions(unittest.TestCase): '''Tests for the TransferSVR4 class''' TEST_SRC_DIR = ROOT + "/var/tmp" TEST_DST_DIR = ROOT + "/tmp" def setUp(self): InstallEngine._instance = None InstallEngine() self.engine = InstallEngine.get_instance() self.doc = self.engine.data_object_cache.volatile self.soft_node = Software("SVR4Transfer", "SVR4") self.tr_node = SVR4Spec() self.soft_node.insert_children([self.tr_node]) self.doc.insert_children([self.soft_node]) self.tr_svr4 = TransferSVR4("SVR4Transfer") self.make_dummy_pkg(self.TEST_SRC_DIR + "/SUNWpkg1") self.make_dummy_pkg(self.TEST_SRC_DIR + "/SUNWpkg2") self.make_dummy_pkg(self.TEST_SRC_DIR + "/SUNWpkg3") if not os.path.isdir(AbstractSVR4.ADMIN_FILE_DIR): os.makedirs(AbstractSVR4.ADMIN_FILE_DIR, 0755) def tearDown(self): self.engine.data_object_cache.clear() self.doc = None self.engine = None self.soft_node = None self.tr_node = None self.tr_svr4 = None InstallEngine._instance = None shutil.rmtree(self.TEST_SRC_DIR + "/SUNWpkg1") shutil.rmtree(self.TEST_SRC_DIR + "/SUNWpkg2") shutil.rmtree(self.TEST_SRC_DIR + "/SUNWpkg3") if os.path.isdir(AbstractSVR4.ADMIN_FILE_DIR): os.removedirs(AbstractSVR4.ADMIN_FILE_DIR) def make_dummy_pkg(self, where): os.makedirs(where) fd = open(where + "/pkgmap", "w") fd.close() fd = open(where + "/pkginfo", "w") fd.close() def test_software_type(self): self.assertTrue(self.soft_node.tran_type == "SVR4") def test_cancel(self): '''Test the cancel method''' try: self.tr_svr4.cancel() except Exception as err: self.fail(str(err)) def test_check_cancel_event(self): self.tr_svr4._cancel_event = True try: self.tr_svr4.check_cancel_event() except Exception as err: self.fail(str(err)) def test_validate_dst(self): '''Test error is raised when no destination is registered''' self.tr_svr4.dst = None self.assertRaises(Exception, self.tr_svr4._validate_input) def test_validate_src(self): '''Test error is raised when no source is registered''' self.tr_svr4.dst = "/mydest" self.tr_svr4.src = None self.assertRaises(Exception, self.tr_svr4._validate_input) def test_validate_no_transfer_list(self): '''Test error is raised when transfer list is empty''' self.tr_svr4.dst = "/mydest" self.tr_svr4._transfer_list = [] self.assertRaises(Exception, self.tr_svr4._validate_input) def test_validate_no_args(self): ''''Test error is raised when no args are provided''' self.tr_svr4.dst = "/mydest" self.tr_svr4.src = "/mysrc" self.tr_svr4._transfer_list = [{'action': 'install', 'contents': ['mypkg']}, {'action': 'uninstall', 'contents': ["myuninstallpkg"]}] self.assertRaises(Exception, self.tr_svr4._validate_input) 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) 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 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_dst_not_specified(self): '''Test error when dst is not specified ''' src = Source() pub = Publisher() origin = Origin(self.TEST_SRC_DIR) pub.insert_children([origin]) src.insert_children([pub]) self.soft_node.insert_children([src]) self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True) 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_more_than_one_same_soft_node(self): '''Test error when multiple software nodes with same name ''' soft_node2 = Software("SVR4Transfer") self.doc.insert_children([soft_node2]) tr_node2 = SVR4Spec() soft_node2.insert_children([tr_node2]) self.doc.insert_children([soft_node2]) self.assertRaises(Exception, TransferSVR4, "SVR4Transfer") def test_more_than_one_soft_node(self): '''Test checkpoint and software node match correctly ''' 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"] soft_node2 = Software("SVR4Transfer2") self.doc.insert_children([soft_node2]) try: self.tr_svr4.execute(dry_run=True) except Exception as err: self.fail(str(err)) def test_checkpoint_soft_node_mismatch(self): '''Test fail when checkpoint and software node don't match ''' self.assertRaises(Exception, TransferSVR4, "SVR4_Transfer") def test_multiple_args_declared(self): '''Test having multiple args fails''' args = Args({"svr4_args": "-n -d"}) self.tr_node.insert_children([args]) args2 = Args({"svr4_args": "-n -d, mi"}) self.tr_node.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"] self.assertRaises(Exception, self.tr_svr4.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) 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_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)) 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 test_transfer_fail_install(self): '''Test that the transfer mechanism to install 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 = "install" self.tr_node.contents = ["SUNWpkg0"] self.assertRaises(Exception, self.tr_svr4.execute, dry_run=False) 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_install_bad_args(self): '''Test that the transfer install fails with bad SVR4 package 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 = "install" self.tr_node.contents = ["SUNWpkg1"] 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)