7035125 - install_ict/generate_sc_profile.py imports a DC python module, causing undesired dependencies
authorGinnie Wray<virginia.wray@oracle.com>
Thu, 14 Apr 2011 10:26:09 -0600
changeset 1074 417ee935427f
parent 1073 7ff3ee2fcf57
child 1075 df96871c232d
7035125 - install_ict/generate_sc_profile.py imports a DC python module, causing undesired dependencies
usr/src/lib/install_ict/generate_sc_profile.py
usr/src/lib/install_ict/test/test_gen_sc_profile.py
--- a/usr/src/lib/install_ict/generate_sc_profile.py	Thu Apr 14 09:56:06 2011 -0600
+++ b/usr/src/lib/install_ict/generate_sc_profile.py	Thu Apr 14 10:26:09 2011 -0600
@@ -30,7 +30,7 @@
 import os
 import shutil
 
-from solaris_install.distro_const.configuration import Configuration
+from solaris_install.data_object.data_dict import DataObjectDict
 
 
 class GenerateSCProfile(ICT.ICTBaseClass):
@@ -86,8 +86,8 @@
             self.logger.debug('Keyboard layout has not been identified')
             self.logger.debug('It will be configured to', ICT.KBD_DEFAULT)
             keyboard_layout = ICT.KBD_DEFAULT
-        else:   
-            self.logger.debug('Detected [%s] keyboard layout' 
+        else:
+            self.logger.debug('Detected [%s] keyboard layout '
                               % keyboard_layout)
         return keyboard_layout
 
@@ -110,9 +110,6 @@
               On failure, errors raised are managed by the engine.
         '''
 
-        # The configuration source and destination
-        config = None
-
         # The optional configuration source and destination
         sc_profile_src = None
         sc_profile_dst = None
@@ -126,22 +123,28 @@
         # Perform a check to see if a configuration source or destination
         # has been provided in the DOC
         # Get the checkpoint info from the DOC
-        config = self.doc.get_descendants(name=self.name,
-                                          class_type=Configuration)
+        gen_sc_dict = self.doc.persistent.get_descendants(name=self.name,
+                                                          class_type=DataObjectDict)
 
         # Check that there is not more than one entry for sc configuration
-        if len(config) > 1:
-            raise ValueError("Only one value for a system configuration "
-                             "profile node can be specified with name ",
-                             self.name)
+        if gen_sc_dict:
+            if len(gen_sc_dict) > 1:
+                raise ValueError("Only one value for a system configuration "
+                                 "profile node can be specified with name ",
+                                 self.name)
 
-        # If there is a configuration entry, replace the default target profile
-        # with the one provided in the DOC
-        if len(config) != 0:
-            if config[0].source:
-                self.sc_template = config[0].source
-            if config[0].dest:
-                self.target_sc_profile = config[0].dest
+            # If there is a configuration entry, replace the default target
+            # profile or source with the one provided in the DOC
+            for sc_dict in gen_sc_dict:
+                if len(sc_dict.data_dict) > 1:
+                    raise ValueError("Only one source and destination may "
+                                     "be specified")
+
+                for source, dest in sc_dict.data_dict.items():
+                    if self.sc_template != source:
+                        self.sc_template = source
+                    if self.target_sc_profile != dest:
+                        self.target_sc_profile = dest
 
         sc_profile_src = os.path.join(self.target_dir,
                                       self.sc_template)
@@ -159,7 +162,7 @@
             if self.keyboard_layout == ICT.KBD_DEFAULT:
                 shutil.copy2(sc_profile_src, sc_profile_dst)
             else:
-                with open(sc_profile_dst, "w+")as dst_hndl: 
+                with open(sc_profile_dst, "w+")as dst_hndl:
                     with open(sc_profile_src, "r+") as fhndl:
                         for line in fhndl:
                             if ICT.KBD_DEFAULT in line and \
--- a/usr/src/lib/install_ict/test/test_gen_sc_profile.py	Thu Apr 14 09:56:06 2011 -0600
+++ b/usr/src/lib/install_ict/test/test_gen_sc_profile.py	Thu Apr 14 10:26:09 2011 -0600
@@ -35,11 +35,10 @@
 import unittest
 
 from common_create_simple_doc import CreateSimpleDataObjectCache
+from solaris_install.data_object.data_dict import DataObjectDict
+from solaris_install.ict import SC_TEMPLATE
 from solaris_install.ict.generate_sc_profile import GenerateSCProfile
-from solaris_install.engine.test.engine_test_utils import reset_engine, \
-    get_new_engine_instance
-
-from solaris_install.distro_const.configuration import Configuration
+from solaris_install.engine.test.engine_test_utils import reset_engine
 
 
 class TestGenerateSCProfile(unittest.TestCase):
@@ -100,6 +99,7 @@
 
         # Create a data object to hold the required data
         self.simple = CreateSimpleDataObjectCache(test_target=self.test_target)
+        self.sc_dict = {}
 
     def tearDown(self):
         reset_engine()
@@ -107,6 +107,7 @@
 
         if os.path.exists(self.test_target):
             shutil.rmtree(self.test_target)
+        self.sc_dict = {}
 
     def test_sc_profile_config_default(self):
         '''Test the default parameters of GenerateSCProfile'''
@@ -160,11 +161,12 @@
 
     def test_sc_profile_different_dest(self):
         '''Test different sc_profile destination succeeds'''
-        config_node = Configuration("generate_sc_profile")
-        config_node.dest = 'test_dir/my_sc_template.xml'
-        self.simple.doc.persistent.insert_children([config_node])
-        if not os.path.exists(os.path.dirname(config_node.dest)):
-            os.makedirs(os.path.dirname(config_node.dest))
+
+        self.sc_dict[SC_TEMPLATE] = 'test_dir/my_sc_template.xml'
+
+        sc_dod = DataObjectDict("generate_sc_profile", self.sc_dict,
+                                generate_xml=True)
+        self.simple.doc.persistent.insert_children([sc_dod])
 
         # Create the test source directory
         test_source = os.path.join(self.test_target,
@@ -190,13 +192,17 @@
 
     def test_more_than_one_profile_node(self):
         '''Test having multiple configurations fails'''
-        config_node = Configuration("generate_sc_profile")
-        config_node.dest = 'test_dir/my_sc_template.xml'
-        self.simple.doc.persistent.insert_children([config_node])
+        sc_dict2 = {}
 
-        config_node2 = Configuration("generate_sc_profile")
-        config_node2.source = "my_sc_profile2.xml"
-        self.simple.doc.persistent.insert_children([config_node2])
+        sc_dict2[SC_TEMPLATE] = 'test_dir/my_sc_template.xml'
+        sc_dod = DataObjectDict("generate_sc_profile", sc_dict2,
+                                generate_xml=True)
+        self.simple.doc.persistent.insert_children([sc_dod])
+
+        self.sc_dict[SC_TEMPLATE] = 'test_dir/my_sc_template.xml'
+        sc_dod_2 = DataObjectDict("generate_sc_profile", self.sc_dict,
+                                  generate_xml=True)
+        self.simple.doc.persistent.insert_children([sc_dod_2])
 
         # Instantiate the checkpoint
         gen_sc = GenerateSCProfile("generate_sc_profile")
@@ -213,6 +219,59 @@
         except Exception as e:
             self.fail(str(e))
 
+    def test_gen_sc_profile_src_dest(self):
+        '''Test passing in a source and a destination'''
+        alt_source = 'usr/share/install/sc2_template.xml'
+        test_source = os.path.join(self.test_target, alt_source)
+        if not os.path.exists(os.path.dirname(test_source)):
+            os.makedirs(os.path.dirname(test_source))
+
+        # Create the test sc_template.xml file
+        sc_tmp_string = ''
+        for sc_tmplt in self.sc_test_template:
+            sc_tmp_string += sc_tmplt + '\n'
+        with open(test_source, "w") as fh:
+            fh.writelines(sc_tmp_string)
+        fh.close()
+
+        self.sc_dict[alt_source] = 'test_dir/my_sc_template.xml'
+        sc_dod = DataObjectDict("generate_sc_profile", self.sc_dict,
+                                generate_xml=True)
+        self.simple.doc.persistent.insert_children([sc_dod])
+
+        gen_sc = GenerateSCProfile("generate_sc_profile")
+        try:
+            gen_sc.execute()
+        except Exception as e:
+            self.fail(str(e))
+
+    def test_gen_sc_profile_default_src(self):
+        '''Use the default source and a user defined destination'''
+
+        # Create the test source directory
+        test_source = os.path.join(self.test_target, SC_TEMPLATE)
+        if not os.path.exists(os.path.dirname(test_source)):
+            os.makedirs(os.path.dirname(test_source))
+
+        # Create the test sc_template.xml file
+        sc_tmp_string = ''
+        for sc_tmplt in self.sc_test_template:
+            sc_tmp_string += sc_tmplt + '\n'
+        with open(test_source, "w") as fh:
+            fh.writelines(sc_tmp_string)
+        fh.close()
+
+        self.sc_dict[SC_TEMPLATE] = 'test_dir/mysc_template.xml'
+        sc_dod = DataObjectDict("generate_sc_profile", self.sc_dict,
+                                generate_xml=True)
+        self.simple.doc.persistent.insert_children([sc_dod])
+
+        gen_sc = GenerateSCProfile("generate_sc_profile")
+        try:
+            gen_sc.execute()
+        except Exception as e:
+            self.fail(str(e))
+
     def test_get_progress_estimate(self):
         '''Test get progress estimate return value'''