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 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_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 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])
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))
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)
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)
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))