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_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_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_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_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_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_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_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_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_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_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_cpio_w_file_list_file(self): '''Test copy of a file list file succeeds''' # Copy /bin/xclock and /bin/pv.sh to /rpool/cpio_test_dir # using a file list file as the contents souce # Set up the source src = Source() path = Dir(self.TEST_SRC_DIR) src.insert_children([path]) # Set up the destination dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) # Insert the source and dest into the Software node self.soft_node.insert_children([src, dst]) # The CPIO values that are specified self.tr_node.action = "install" self.tr_node.contents = self.TEST_FILE_LIST_FILE with open(self.TEST_FILE_LIST_FILE, 'w') as filehandle: filehandle.write("bin/xclock" + "\n") filehandle.write("bin/pv.sh" + "\n") try: self.tr_cpio.execute(dry_run=True) except Exception as err: self.fail(str(err))
def test_cleanup_temp_files(self): '''Test the cleanup of the temporary files''' # Set up the source src = Source() src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11") path = Dir(src_path) src.insert_children([path]) # Set up the destination dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) # Insert the source and dest into the Software node self.soft_node.insert_children([src, dst]) # The CPIO values that are specified self.tr_node.action = "install" self.tr_node.contents = ["./"] self.tr_cpio._parse_input() try: self.tr_cpio._cleanup_tmp_files() except Exception as err: self.fail(str(err))
def test_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 setUp(self): InstallEngine._instance = None InstallEngine() self.engine = InstallEngine.get_instance() self.doc = self.engine.data_object_cache.volatile self.soft_node = Software("P5I transfer") self.tr_node = P5ISpec() dst = Destination() self.ips_image = Image(IPS_IMG_DIR, "create") dst.insert_children([self.ips_image]) self.soft_node.insert_children([self.tr_node, dst]) self.doc.insert_children([self.soft_node])
def test_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_src_not_exist(self): ''' Test that an error is raised when src doesn't exist.''' #Set up the source src = Source() path = Dir("/hello") src.insert_children([path]) dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) self.soft_node.insert_children([src, dst]) self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
def test_src_not_exist(self): '''Test that an error is raised when the source doesn't exist''' src = Source() pub = Publisher() origin = Origin("/doesnt_exist") pub.insert_children([origin]) src.insert_children([pub]) dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) self.soft_node.insert_children([src, dst]) self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
def setUp(self): InstallEngine._instance = None InstallEngine() self.engine = InstallEngine.get_instance() self.doc = self.engine.data_object_cache.volatile self.soft_node = Software("IPS transfer") self.tr_node = IPSSpec() dst = Destination() self.ips_image = Image(self.IPS_IMG_DIR, "create") ips_im_type = ImType("full") self.ips_image.insert_children([ips_im_type]) dst.insert_children([self.ips_image]) self.soft_node.insert_children([self.tr_node, dst]) self.doc.insert_children([self.soft_node]) self.tr_ips = TransferIPS("IPS transfer")
def test_dir_excl_list_not_valid(self): '''Test that an error is raised for invalid dir_excl_list''' src = Source() src_path = os.path.join(self.TEST_SRC_DIR, "etc/X11") path = Dir(src_path) src.insert_children([path]) dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) self.soft_node.insert_children([src, dst]) # The CPIO values that are specified self.tr_node.action = "uninstall" self.tr_node.contents = "/tmp/invalid_dir_file" self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
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_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_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_bad_args_name(self): '''Test having invalid args key fails''' args = Args({"svr44444_args": "-n -d"}) self.tr_node.insert_children([args]) src = Source() pub = Publisher() origin = Origin(self.TEST_SRC_DIR) pub.insert_children([origin]) src.insert_children([pub]) dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) self.soft_node.insert_children([src, dst]) self.tr_node.action = "install" self.tr_node.contents = ["SUNWpkg1"] self.assertRaises(Exception, self.tr_svr4.execute, dry_run=True)
def test_cpio_no_contents(self): ''' Test that an error is raised when no contents exist''' # Set up the source src = Source() path = Dir(self.TEST_SRC_DIR) src.insert_children([path]) # Set up the destination dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) # Insert the source and dest into the Software node self.soft_node.insert_children([src, dst]) # The CPIO values that are specified - no contents self.tr_node.action = "install" self.assertRaises(Exception, self.tr_cpio.execute, dry_run=True)
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_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_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_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))