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_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 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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_transfer_fail_uninstall(self): '''Test that the transfer mechanism to uninstall fails with a non-existent package ''' src = Source() pub = Publisher() origin = Origin(self.TEST_SRC_DIR) pub.insert_children([origin]) src.insert_children([pub]) dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) self.soft_node.insert_children([src, dst]) self.tr_node.action = 'uninstall' self.tr_node.contents = ["SUNWpkg0"] self.assertRaises(Exception, self.tr_svr4.execute, dry_run=False)
def test_uninstall_bad_args(self): '''Test transfer uninstall fails with bad args ''' src = Source() pub = Publisher() origin = Origin(self.TEST_SRC_DIR) pub.insert_children([origin]) src.insert_children([pub]) dst = Destination() path = Dir(self.TEST_DST_DIR) dst.insert_children([path]) self.soft_node.insert_children([src, dst]) args = Args({"svr4_args": "-q -r -s -t"}) self.tr_node.insert_children([args]) self.tr_node.action = "uninstall" self.tr_node.contents = ["SUNWpkg1"] self.assertRaises(Exception, self.tr_svr4.execute, dry_run=False)
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_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 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_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)