def test_doc_registration_classes_from_module_in_list_same_prio(self): '''Validate registration of classes in a module list at same priority ''' # Compensate for indent indentation = '''\ ''' expected_registered_classes_str = '''\ ============================ Registered Classes: [Priority = 30] <class 'simple_data_object.SimpleDataObject'> <class 'simple_data_object.SimpleDataObject2'> <class 'simple_data_object.SimpleDataObject3'> <class 'simple_data_object.SimpleDataObject4'> <class 'simple_data_object.SimpleDataObject5'> <class 'simple_data_object.SimpleDataObjectHandlesChildren'> <class 'simple_data_object.SimpleDataObjectNoXml'> ============================ '''.replace(indentation, "") DataObjectCache.register_class([simple_data_object], priority=30) txt = self.doc.get_registered_classes_str() self.assertEquals(expected_registered_classes_str, txt, "EXPECTED:\n%s\nGOT:\n%s\n" % (expected_registered_classes_str, txt))
def test_doc_registration_classes_from_module_in_list_same_prio(self): '''Validate registration of classes in a module list at same priority ''' # Compensate for indent indentation = '''\ ''' expected_registered_classes_str = '''\ ============================ Registered Classes: [Priority = 30] <class 'simple_data_object.SimpleDataObject'> <class 'simple_data_object.SimpleDataObject2'> <class 'simple_data_object.SimpleDataObject3'> <class 'simple_data_object.SimpleDataObject4'> <class 'simple_data_object.SimpleDataObject5'> <class 'simple_data_object.SimpleDataObjectHandlesChildren'> <class 'simple_data_object.SimpleDataObjectNoXml'> ============================ '''.replace(indentation, "") DataObjectCache.register_class([simple_data_object], priority=30) txt = self.doc.get_registered_classes_str() self.assertEquals( expected_registered_classes_str, txt, "EXPECTED:\n%s\nGOT:\n%s\n" % (expected_registered_classes_str, txt))
def test_doc_registration_simple_data_object(self): '''Validate registration and selection of a single class''' try: DataObjectCache.register_class(SimpleDataObject) except (TypeError, ValueError): self.fail("Failed to register SimpleDataObject!") # Test that it's actually registered and will correclty return class. simple = SimpleDataObject("TestSimple") xml_elem = simple.to_xml() class_obj = DataObjectCache.find_class_to_handle(xml_elem) self.assertEqual(class_obj, SimpleDataObject, str(class_obj))
def test_doc_registration_multiple_handlers_highest_prio_selected(self): '''Validate highest priority class is selected when several handlers''' DataObjectCache.register_class(SimpleDataObjectSameTagHighPrio, priority=30) DataObjectCache.register_class(SimpleDataObjectSameTagNormPrio, priority=50) xml_elem = etree.Element(COMMON_TAG, name="some name") class_obj = DataObjectCache.find_class_to_handle(xml_elem) self.assertEqual(class_obj, SimpleDataObjectSameTagHighPrio)
def test_doc_registration_multiple_classes_same_prio(self): '''Validate registration of multiple classes at same priority''' # Compensate for indent indentation = '''\ ''' expected_registered_classes_str = '''\ ============================ Registered Classes: [Priority = 30] <class 'simple_data_object.SimpleDataObject'> <class 'simple_data_object.SimpleDataObject2'> <class 'simple_data_object.SimpleDataObject3'> <class 'simple_data_object.SimpleDataObject4'> ============================ '''.replace(indentation, "") DataObjectCache.register_class(SimpleDataObject, priority=30) DataObjectCache.register_class(SimpleDataObject2, priority=30) DataObjectCache.register_class(SimpleDataObject3, priority=30) DataObjectCache.register_class(SimpleDataObject4, priority=30) txt = self.doc.get_registered_classes_str() self.assertEquals( expected_registered_classes_str, txt, "EXPECTED:\n%s\nGOT:\n%s\n" % (expected_registered_classes_str, txt))
def test_doc_registration_get_registered_classes_str(self): '''Validate correct output from get_registered_classes_str()''' # Used as expected return string in method # Compensate for indent indentation = '''\ ''' expected_registered_classes_str = '''\ ============================ Registered Classes: [Priority = 30] <class 'simple_data_object.SimpleDataObject'> [Priority = 50] <class 'simple_data_object.SimpleDataObject2'> <class 'simple_data_object.SimpleDataObject3'> [Priority = 100] <class 'simple_data_object.SimpleDataObject4'> ============================ '''.replace(indentation, "") DataObjectCache.register_class(SimpleDataObject, priority=30) DataObjectCache.register_class(SimpleDataObject2) DataObjectCache.register_class(SimpleDataObject3, priority=50) DataObjectCache.register_class(SimpleDataObject4, priority=100) txt = self.doc.get_registered_classes_str() self.assertEquals( expected_registered_classes_str, txt, "EXPECTED:\n%s\nGOT:\n%s\n" % (expected_registered_classes_str, txt))
def test_doc_registration_get_registered_classes_str(self): '''Validate correct output from get_registered_classes_str()''' # Used as expected return string in method # Compensate for indent indentation = '''\ ''' expected_registered_classes_str = '''\ ============================ Registered Classes: [Priority = 30] <class 'simple_data_object.SimpleDataObject'> [Priority = 50] <class 'simple_data_object.SimpleDataObject2'> <class 'simple_data_object.SimpleDataObject3'> [Priority = 100] <class 'simple_data_object.SimpleDataObject4'> ============================ '''.replace(indentation, "") DataObjectCache.register_class(SimpleDataObject, priority=30) DataObjectCache.register_class(SimpleDataObject2) DataObjectCache.register_class(SimpleDataObject3, priority=50) DataObjectCache.register_class(SimpleDataObject4, priority=100) txt = self.doc.get_registered_classes_str() self.assertEquals(expected_registered_classes_str, txt, "EXPECTED:\n%s\nGOT:\n%s\n" % (expected_registered_classes_str, txt))
def test_doc_registration_multiple_classes_same_prio(self): '''Validate registration of multiple classes at same priority''' # Compensate for indent indentation = '''\ ''' expected_registered_classes_str = '''\ ============================ Registered Classes: [Priority = 30] <class 'simple_data_object.SimpleDataObject'> <class 'simple_data_object.SimpleDataObject2'> <class 'simple_data_object.SimpleDataObject3'> <class 'simple_data_object.SimpleDataObject4'> ============================ '''.replace(indentation, "") DataObjectCache.register_class(SimpleDataObject, priority=30) DataObjectCache.register_class(SimpleDataObject2, priority=30) DataObjectCache.register_class(SimpleDataObject3, priority=30) DataObjectCache.register_class(SimpleDataObject4, priority=30) txt = self.doc.get_registered_classes_str() self.assertEquals(expected_registered_classes_str, txt, "EXPECTED:\n%s\nGOT:\n%s\n" % (expected_registered_classes_str, txt))
def test_doc_registration_no_handler_found(self): '''Validate failure of no handler is found''' DataObjectCache.register_class(SimpleDataObject) DataObjectCache.register_class(SimpleDataObject2) DataObjectCache.register_class(SimpleDataObject3) DataObjectCache.register_class(SimpleDataObject4) # First ensure it works as expected. xml_elem = etree.Element("SimpleDataObject", name="handled") class_obj = DataObjectCache.find_class_to_handle(xml_elem) self.assertEqual(class_obj, SimpleDataObject) # Now ensure that it fails when expected. xml_elem_fail = etree.Element("not_handled", name="not_handled_name") class_obj = DataObjectCache.find_class_to_handle(xml_elem_fail) self.assertEqual(class_obj, None)
def setUp(self): '''Create DOC, and empty registry of classes, some children and refs''' # Hack to ensure that registry is empty before we use it, self.orig_registry = DOC._CACHE_CLASS_REGISTRY DOC._CACHE_CLASS_REGISTRY = dict() DataObjectCache.register_class([SimpleDataObject, SimpleDataObject2, SimpleDataObject3, SimpleDataObjectHandlesChildren]) # Create a tree that looks like: # # root # child_1 # child_1_1 # child_1_2 # child_2 # child_2_1 # child_2_1_1 # child_2_1_1_1 # child_2_1_1_2 # child_3 # child_3_1 # child_3_1_2 # child_3_1_2 # child_4 # child_5 # child_5_1 # child_5_2 # child_5_2_1 # child_5_2_2 # child_5_2_3 # child_5_2_3_1 # child_5_2_3_2 # child_5_2_3_3 # child_5_same_name # Create root node self.doc = DataObjectCache() # Create some persistent content self.persistent_root = SimpleDataObject("persistent_root") # Add some children, used by most tests. self.child_1 = SimpleDataObject2("child_1") self.child_2 = SimpleDataObject("child_2") self.child_3 = SimpleDataObject("child_3") self.child_4 = SimpleDataObject2("child_4") self.child_5 = SimpleDataObject3("child_5") self.do_list = list() self.do_list.append(self.child_1) self.do_list.append(self.child_2) self.do_list.append(self.child_3) self.do_list.append(self.child_4) self.do_list.append(self.child_5) self.persistent_root.insert_children(self.do_list) self.doc.persistent.insert_children(self.persistent_root) # Now let's add the children of children, etc. for use by # get_descendants() tests. # child_1 children self.child_1_1 = SimpleDataObject("child_1_1") self.child_1_2 = SimpleDataObject("child_1_2") self.child_1.insert_children([self.child_1_1, self.child_1_2]) # child_2 tree self.child_2_1 = SimpleDataObject2("child_2_1") self.child_2.insert_children(self.child_2_1) self.child_2_1_1 = SimpleDataObject2("child_2_1_1") self.child_2_1.insert_children(self.child_2_1_1) self.child_2_1_1_1 = SimpleDataObject2("child_2_1_1_1") self.child_2_1_1_2 = SimpleDataObject2("child_2_1_1_2") self.child_2_1_1.insert_children([self.child_2_1_1_1, self.child_2_1_1_2]) # child_3 tree self.child_3_1 = SimpleDataObject("child_3_1") self.child_3.insert_children(self.child_3_1) self.child_3_1_1 = SimpleDataObject("child_3_1_1") self.child_3_1_2 = SimpleDataObject("child_3_1_2") self.child_3_1_2_same_name = SimpleDataObject("child_3_1_2") self.child_3_1.insert_children([self.child_3_1_1, self.child_3_1_2, self.child_3_1_2_same_name]) # child_5 tree self.child_5_1 = SimpleDataObject("child_5_1") self.child_5_2 = SimpleDataObject("child_5_2") self.child_5.insert_children([self.child_5_1, self.child_5_2]) self.child_5_2_1 = SimpleDataObject("child_5_2_1") self.child_5_2_2 = SimpleDataObject("child_5_2_2") self.child_5_2_3 = SimpleDataObjectHandlesChildren("child_5_2_3") self.child_5_2.insert_children([self.child_5_2_1, self.child_5_2_2, self.child_5_2_3]) self.child_5_2_3_1 = SimpleDataObject("child_5_2_3_1") self.child_5_2_3_2 = SimpleDataObject("child_5_2_3_2") self.child_5_2_3_3 = SimpleDataObject("child_5_2_3_3") self.child_5_2_3_3_same_name = SimpleDataObject("child_5_2_3_3") self.child_5_2_3.insert_children([self.child_5_2_3_1, self.child_5_2_3_2, self.child_5_2_3_3, self.child_5_2_3_3_same_name]) # Create some volatile content, not much, just enough to test that it's # not overwritten on loading of snapshot. self.volatile_root = SimpleDataObject2("volatile_root") self.doc.volatile.insert_children(self.volatile_root)
if self.parent is None or class_type is None or \ not hasattr(class_type, "_label_disk"): return unsorted_children # retreive the DataObjectDict from the DOC cro_data = self.root_object.persistent.get_first_child( name=CRO_LABEL) # not all systems support croinfo so if the data_dict is empty or not # present in the DOC, return the unsorted list if not cro_data: return unsorted_children cro_dict = cro_data.data_dict # compare the first element of the croinfo tuple (the position) def compare(x, y): if isinstance(x, physical.Disk) and isinstance(y, physical.Disk) \ and x.ctd in cro_dict and y.ctd in cro_dict: return cmp(cro_dict[x.ctd][0], cro_dict[y.ctd][0]) return 0 # Default is to maintain location as-is # sort the children by croinfo order return sorted(unsorted_children, cmp=compare) # register all the DOC classes DataObjectCache.register_class(Target) DataObjectCache.register_class(logical) DataObjectCache.register_class(physical)
distro = Distro(name) if add_timestamp is not None: distro.add_timestamp = add_timestamp if http_proxy is not None: distro.http_proxy = http_proxy return distro class DistroSpec(SimpleXmlHandlerBase): TAG_NAME = "distro_spec" class IMGParams(SimpleXmlHandlerBase): TAG_NAME = "img_params" class MediaIM(SimpleXmlHandlerBase): TAG_NAME = "media_im" class VMIM(SimpleXmlHandlerBase): TAG_NAME = "vm_im" class MaxSize(SimpleXmlHandlerBase): TAG_NAME = "max_size" # register all the classes with the DOC DataObjectCache.register_class(sys.modules[__name__])
from solaris_install.configuration import configuration from solaris_install.data_object import DataObject from solaris_install.data_object.cache import DataObjectCache from solaris_install.data_object.data_dict import DataObjectDict from solaris_install.distro_const import execution_checkpoint from solaris_install.distro_const import distro_spec from solaris_install.distro_const.checkpoints.custom_script import CustomScript from solaris_install.engine.test.engine_test_utils import \ get_new_engine_instance, reset_engine from solaris_install.logger import InstallLogger # register all the DataObject classes with the DOC for mod in [configuration, distro_spec, execution_checkpoint]: for name, value in inspect.getmembers(mod, inspect.isclass): if issubclass(value, DataObject): DataObjectCache.register_class(value) class SimpleDataObject(DataObject): """Simple DataObject for testing""" def __init__(self, name, value1="Default1", value2="Defaut2", value3="Default3"): super(SimpleDataObject, self).__init__(name) self.value1 = value1 self.value2 = value2 self.value3 = value3
from solaris_install.transfer.cpio import TransferCPIO from solaris_install.transfer.ips import TransferIPS from solaris_install.transfer.p5i import TransferP5I from solaris_install.transfer.svr4 import TransferSVR4 __all__ = ["ips", "p5i", "cpio", "info", "prog", "svr4"] module_func_map = { "IPS": [TransferIPS.__module__, TransferIPS.__name__], "SVR4": [TransferSVR4.__module__, TransferSVR4.__name__], "CPIO": [TransferCPIO.__module__, TransferCPIO.__name__], "P5I": [TransferP5I.__module__, TransferP5I.__name__] } # register all the classes with the DOC DataObjectCache.register_class(info) def create_checkpoint(software_node): """ Generate a suitable Transfer checkpoint tuple. Given a specific Software data object, this method will generate a suitable set of arguments: checkpoint_name, module_path, checkpoint_class_name to pass to a call into InstallEngine.register_checkpoint(), e.g. ckpt_info = create_checkpoint(my_software) InstallEngine.register_checkpoint(*ckpt_info)
"pool") # reset the errsvc completely errsvc.clear_error_list() # re-insert every node in the Target tree to re-run validation for disk in self.get_descendants(class_type=physical.Disk): # only validate the disks that have children elements if disk.has_children: self.validate_node(disk) # validate the logical targets next logical_list = self.get_children(class_type=logical.Logical) if logical_list: self.validate_node(logical_list[0]) except Target.InvalidError as err: self.logger.debug("Final Validation failed") self.logger.debug(str(err)) return False else: # everything validates self.logger.debug("Final Validation succeeded") return True # register all the DOC classes DataObjectCache.register_class(Target) DataObjectCache.register_class(logical) DataObjectCache.register_class(physical)
arglist_element.set(Kwargs.NAME_LABEL, key) for val in value: argitem_element = etree.SubElement( arglist_element, Kwargs.ARGITEM_LABEL) argitem_element.text = val def do_from_xml(self, element): kwargs = Kwargs(Kwargs.KWARGS_LABEL) for arg_element in element.iterfind(Kwargs.ARG_LABEL): kwargs.args[arg_element.get(Kwargs.NAME_LABEL)] = arg_element.text for arglist_element in element.iterfind(Kwargs.ARGLIST_LABEL): arglist = [argitem.text for argitem in \ arglist_element.iterfind(Kwargs.ARGITEM_LABEL)] kwargs.arglist[arglist_element.get(Kwargs.NAME_LABEL)] = arglist # kwargs must be in the form of a dictionary to # allow the engine to validate them. The engine # cannot validate (Kwargs) objects. kwargs_dct = dict() if kwargs.args: kwargs_dct[Kwargs.ARG_LABEL] = kwargs.args if kwargs.arglist: kwargs_dct[Kwargs.ARGLIST_LABEL] = kwargs.arglist return kwargs_dct # register all the classes with the DOC DataObjectCache.register_class(sys.modules[__name__])
# Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. # """init module for the boot checkpoints""" from solaris_install.data_object.cache import DataObjectCache from solaris_install.boot.boot import BootMods, BootEntry __all__ = ["boot", "boot_spec"] # Register DataObject sub-classes with the DOC DataObjectCache.register_class(BootMods) DataObjectCache.register_class(BootEntry)
from solaris_install.data_object import DataObject from solaris_install.data_object.cache import DataObjectCache from solaris_install.data_object.data_dict import DataObjectDict from solaris_install.distro_const import execution_checkpoint from solaris_install.distro_const import distro_spec from solaris_install.distro_const.checkpoints.custom_script import CustomScript from solaris_install.engine.test.engine_test_utils import \ get_new_engine_instance, reset_engine from solaris_install.logger import InstallLogger # register all the DataObject classes with the DOC for mod in [configuration, distro_spec, execution_checkpoint]: for name, value in inspect.getmembers(mod, inspect.isclass): if issubclass(value, DataObject): DataObjectCache.register_class(value) class SimpleDataObject(DataObject): """Simple DataObject for testing""" def __init__(self, name, value1="Default1", value2="Defaut2", value3="Default3"): super(SimpleDataObject, self).__init__(name) self.value1 = value1 self.value2 = value2 self.value3 = value3 @classmethod def can_handle(cls, xml_node): """Doesn't support XML Import"""
# You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. # """init module for the boot checkpoints""" from solaris_install.data_object.cache import DataObjectCache from solaris_install.boot.boot import BootMods, BootEntry __all__ = ["boot", "boot_spec"] # Register DataObject sub-classes with the DOC DataObjectCache.register_class(BootMods) DataObjectCache.register_class(BootEntry)
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. # # This file is installed into # usr/lib/python2.7/vendor-packages/solaris_install/auto_install/ directory # and lets the Python interpreter know that this directory contains valid # Python modules which can be imported using following command: # from solaris_install.auto_install.<module_name> import <object> # """Init module for the Automated Installer package""" from solaris_install.data_object.cache import DataObjectCache import ai_instance # AI TransferFiles checkpoint name TRANSFER_FILES_CHECKPOINT = "transfer-ai-files" # Register local Data Objects, use relative module reference. DataObjectCache.register_class(ai_instance) __all__ = []
def test_doc_registration_simple_data_object_prio_100(self): '''Validate insertion of a class with prio 100''' try: DataObjectCache.register_class(SimpleDataObject, priority=100) except (TypeError, ValueError): self.fail("Failed to register SimpleDataObject with prio 100!")
from p5i import TransferP5I from svr4 import TransferSVR4 __all__ = ["ips", "p5i", "cpio", "info", "prog", "svr4"] module_func_map = { "IPS": [TransferIPS.__module__, TransferIPS.__name__], "SVR4": [TransferSVR4.__module__, TransferSVR4.__name__], "CPIO": [TransferCPIO.__module__, TransferCPIO.__name__], "P5I": [TransferP5I.__module__, TransferP5I.__name__] } # register all the classes with the DOC DataObjectCache.register_class(info) def create_checkpoint(software_node): """ Generate a suitable Transfer checkpoint tuple. Given a specific Software data object, this method will generate a suitable set of arguments: checkpoint_name, module_path, checkpoint_class_name to pass to a call into InstallEngine.register_checkpoint(), e.g. ckpt_info = create_checkpoint(my_software) InstallEngine.register_checkpoint(*ckpt_info)
# Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. # """ init module for configuration """ from solaris_install.data_object.cache import DataObjectCache from solaris_install.configuration.configuration import Configuration __all__ = ["configuration"] # Register the DOC classes DataObjectCache.register_class(Configuration)