7068993 if filesys swap is placed before / then valid profile generates error
authorKristina Tripp <Kristina.Tripp@Sun.COM>
Wed, 27 Jul 2011 10:12:11 -0600
changeset 1331 41bc8cab0ad5
parent 1330 0792cdd3bfed
child 1332 952bc94b5917
7068993 if filesys swap is placed before / then valid profile generates error 7070859 filesys mirror <device> <device> all swap is incorrectly being supported
usr/src/cmd/js2ai/modules/conv.py
usr/src/cmd/js2ai/modules/test/test_conv.py
usr/src/cmd/js2ai/modules/test/test_js2ai.py
--- a/usr/src/cmd/js2ai/modules/conv.py	Tue Jul 26 12:52:00 2011 -0700
+++ b/usr/src/cmd/js2ai/modules/conv.py	Wed Jul 27 10:12:11 2011 -0600
@@ -1228,16 +1228,9 @@
             self.__unsupported_value(line_num, _("<size>"), size)
             return
         if size != SIZE_ALL:
-            match_pattern = NUM_PATTERN.match(size)
-            if not match_pattern:
-                self.logger.error(_("%(file)s: line %(lineno)d: invalid "
-                                    "fdisk <size> specified: %(size)s") % \
-                                    {"file": self.profile_name,
-                                     "lineno": line_num,
-                                     "size": size})
-                self._report.add_conversion_error()
-            # fdisk partition size is specified in MB
-            size += "mb"
+            size = self.__size_conversion(line_num, keyword, size)
+            if size is None:
+                return
 
         if self._root_pool is None and \
           self._partitioning == PARTITIONING_DEFAULT and \
@@ -1372,9 +1365,9 @@
             return None
         return device
 
-    def __filesys_size_conversion(self, line_num, keyword, size):
+    def __size_conversion(self, line_num, keyword, size):
         """Perform the necessary conversion for fileys size.  Returns None
-           and generates error if size is not supported or invalid.
+           and generates error if not a valid numeric size.
 
         """
         match_pattern = SIZE_PATTERN.match(size)
@@ -1385,18 +1378,15 @@
             else:
                 # Jumpstart uses m and g not mb and gb like installer wants
                 size += "b"
-        elif size in [SIZE_FREE, SIZE_EXISTING]:
-            self.__unsupported_syntax(line_num, keyword,
-                _("sizes other than a number, auto, or all are not supported"))
-            return None
-        elif size not in [SIZE_AUTO, SIZE_ALL]:
+        else:
             self.logger.error(_("%(file)s: line %(lineno)d: invalid "
-                                "size '%(size)s' specified for filesys") % \
+                                "size '%(size)s' specified for %(key)s") % \
                                 {"file": self.profile_name, \
                                  "lineno": line_num,
+                                 "key": keyword,
                                  "size": size})
             self._report.add_conversion_error()
-            return None
+            size = None
         return size
 
     def __convert_filesys_mirror_entry(self, line_num, keyword, values):
@@ -1440,9 +1430,6 @@
         if not self.__is_valid_filesys_mount(line_num, mount):
             return
 
-        if mount == "swap" and self._root_pool is None:
-            if not self.__swap_force_root_pool_creation(line_num):
-                return
         device1 = self.__device_conversion(line_num=line_num, device=device1,
                                            allow_any_value=False,
                                            use_rootdisk=False)
@@ -1455,7 +1442,13 @@
         if device2 is None:
             return
 
-        size = self.__filesys_size_conversion(line_num, keyword, size)
+        if size in [SIZE_FREE, SIZE_EXISTING, SIZE_ALL, SIZE_AUTO]:
+            self.__unsupported_syntax(line_num, keyword,
+                _("sizes other than a number are not supported for "
+                  "filesys mirror swap"))
+            return None
+
+        size = self.__size_conversion(line_num, keyword, size)
         if size is None:
             return
 
@@ -1547,9 +1540,6 @@
             self._report.add_conversion_error()
         if not self.__is_valid_filesys_mount(line_num, mount):
             return
-        if mount == "swap" and self._root_pool is None:
-            if not self.__swap_force_root_pool_creation(line_num):
-                return
 
         device = self.__device_conversion(line_num=line_num, device=device,
                                           allow_any_value=(size == SIZE_ALL),
@@ -1557,9 +1547,14 @@
         if device is None:
             return
 
-        size = self.__filesys_size_conversion(line_num, keyword, size)
-        if size is None:
-            return
+        if size in [SIZE_FREE, SIZE_EXISTING, SIZE_AUTO]:
+            self.__unsupported_syntax(line_num, keyword,
+                _("sizes other than a number or all are not supported"))
+            return None
+        if size != SIZE_ALL:
+            size = self.__size_conversion(line_num, keyword, size)
+            if size is None:
+                return
 
         if mount == "swap":
             self.__create_filesys_swap(line_num, device, size)
@@ -1759,7 +1754,7 @@
         #                                       <slice> | mirror [<slice>]+
         #
         # Input:        ${1}    - pool name
-        #               ${2}    - pool size (num, all, auto)
+        #               ${2}    - pool size (num, existing, auto)
         #               ${3}    - swap size (num, auto)
         #               ${4}    - dump size (num, auto)
         #               ${5}    - (mirror, <slice>, rootdisk.s??, any)
@@ -1785,65 +1780,37 @@
         self._root_pool_name = pool_name
 
         pool_size = values[1].lower()
-        match_pattern = SIZE_PATTERN.match(pool_size)
-        if match_pattern:
-            if match_pattern.group(2) == "":
-                # No size specified.  Default size is assumed to be in MB
-                pool_size += "mb"
-            else:
-                # Jumpstart uses m and g not mb and gb like installer wants
-                pool_size += "b"
-        elif pool_size not in [SIZE_AUTO, SIZE_ALL]:
-            self.logger.error(_("%(file)s: line %(lineno)d: invalid "
-                                "size '%(val)s' specified for pool") % \
-                                {"file": self.profile_name, \
-                                 "lineno": line_num,
-                                 "val": values[1]})
-            self._report.add_conversion_error()
-            return
+        if pool_size == SIZE_EXISTING:
+            self.__unsupported_syntax(line_num, keyword,
+                _("pool sizes other than a number or auto are not supported"))
+            return None
+        elif pool_size != SIZE_AUTO:
+            pool_size = self.__size_conversion(line_num, "<pool_size>",
+                                               pool_size)
+            if pool_size is None:
+                return
 
         swap_size = values[2].lower()
         noswap = "false"
-        match_pattern = SIZE_PATTERN.match(swap_size)
-        if match_pattern:
-            if match_pattern.group(1) == "0":
-                swap_size = None
-                noswap = "true"
-            elif match_pattern.group(2) == "":
-                # No size specified.  Default size is assumed to be in MB
-                swap_size += "mb"
-            else:
-                # Jumpstart uses m and g not mb and gb like installer wants
-                swap_size += "b"
+        if swap_size == "0":
+            swap_size = None
+            noswap = "true"
         elif swap_size != SIZE_AUTO:
-            self.logger.error(_("%(file)s: line %(lineno)d: invalid "
-                                "size '%(val)s' specified for swap") % \
-                                {"file": self.profile_name, \
-                                 "lineno": line_num, \
-                                 "val": values[2]})
-            self._report.add_conversion_error()
-            return
+            swap_size = self.__size_conversion(line_num, "<swap_size>",
+                                               swap_size)
+            if swap_size is None:
+                return
 
         dump_size = values[3].lower()
         nodump = "false"
-        match_pattern = SIZE_PATTERN.match(dump_size)
-        if match_pattern:
-            if match_pattern.group(1) == "0":
-                dump_size = None
-                nodump = "true"
-            if match_pattern.group(2) == "":
-                # No size specified.  Default size is assumed to be in MB
-                dump_size += "mb"
-            else:
-                # Jumpstart uses m and g not mb and gb like installer wants
-                dump_size += "b"
+        if dump_size == "0":
+            dump_size = None
+            nodump = "true"
         elif dump_size != SIZE_AUTO:
-            self.logger.error(_("%(file)s: line %(lineno)d: invalid size "
-                                "'%(val)s' specified for dump") % \
-                                {"file": self.profile_name, \
-                                 "lineno": line_num, "val": values[3]})
-            self._report.add_conversion_error()
-            return
+            dump_size = self.__size_conversion(line_num, "<dump_size>",
+                                               dump_size)
+            if dump_size is None:
+                return
 
         if values[4] == "mirror":
             # Mirror must have at least 2 slices
@@ -1865,7 +1832,7 @@
 
         updated_list = list()
         for device in devices:
-            allow_any = mirror == False and pool_size in [SIZE_AUTO, SIZE_ALL]
+            allow_any = mirror == False and pool_size == SIZE_AUTO
             update_device = \
                 self.__device_conversion(line_num=line_num,
                                          device=device,
--- a/usr/src/cmd/js2ai/modules/test/test_conv.py	Tue Jul 26 12:52:00 2011 -0700
+++ b/usr/src/cmd/js2ai/modules/test/test_conv.py	Wed Jul 27 10:12:11 2011 -0600
@@ -780,16 +780,7 @@
         report = ConversionReport()
         xml_data = XMLProfileData("test", kv_dict, report,
                                   self.default_xml, True, None)
-        self.assertEquals(report.has_errors(), True)
-        self.assertEquals(report.process_errors, 0,
-                          self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.conversion_errors, 0,
-                          self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.unsupported_items, 1,
-                          self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.validation_errors, 0,
-                          self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.warnings, 0,
+        self.assertEquals(report.has_errors(), False,
                           self.profile_failure_report(xml_data, report))
         self.validate_xml_output(xml_data)
 
@@ -866,16 +857,7 @@
         report = ConversionReport()
         xml_data = XMLProfileData("test", kv_dict, report,
                                   self.default_xml, True, None)
-        self.assertEquals(report.has_errors(), True)
-        self.assertEquals(report.process_errors, 0,
-                          self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.conversion_errors, 0,
-                          self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.unsupported_items, 1,
-                          self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.validation_errors, 0,
-                          self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.warnings, 0,
+        self.assertEquals(report.has_errors(), False,
                           self.profile_failure_report(xml_data, report))
         self.validate_xml_output(xml_data)
 
@@ -1168,9 +1150,9 @@
         key_value = KeyValues("partitioning", ["explicit"], 3)
         kv_dict[key_value.line_num] = key_value
 
-        # filesys mirror c1t0d0s0 c1t0d0s2 all /
+        # filesys mirror c1t0d0s0 c1t0d0s2 4000 /
         key_value = KeyValues("filesys", ["mirror", "c1t0d0s0", "c1t0d0s2",
-                              "all", "/"], 4)
+                              "40000", "/"], 4)
         kv_dict[key_value.line_num] = key_value
         report = ConversionReport()
         xml_data = XMLProfileData("test", kv_dict, report,
@@ -1356,7 +1338,7 @@
                           self.profile_failure_report(xml_data, report))
         self.assertEquals(report.conversion_errors, 1,
                           self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.unsupported_items, 1,
+        self.assertEquals(report.unsupported_items, 0,
                           self.profile_failure_report(xml_data, report))
         self.assertEquals(report.validation_errors, 0,
                           self.profile_failure_report(xml_data, report))
@@ -1381,9 +1363,9 @@
         self.assertEquals(report.has_errors(), True)
         self.assertEquals(report.process_errors, 0,
                           self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.conversion_errors, 1,
-                          self.profile_failure_report(xml_data, report))
-        self.assertEquals(report.unsupported_items, 1,
+        self.assertEquals(report.conversion_errors, 2,
+                          self.profile_failure_report(xml_data, report))
+        self.assertEquals(report.unsupported_items, 0,
                           self.profile_failure_report(xml_data, report))
         self.assertEquals(report.validation_errors, 0,
                           self.profile_failure_report(xml_data, report))
@@ -1574,6 +1556,60 @@
                           self.profile_failure_report(xml_data, report))
         self.validate_xml_output(xml_data)
 
+    def test_filesys_entry36(self):
+        """Tests filesys mirror with size of all"""
+        kv_dict = {}
+        key_value = KeyValues("install_type", ["initial_install"], 1)
+        kv_dict[key_value.line_num] = key_value
+        key_value = KeyValues("partitioning", ["explicit"], 3)
+        kv_dict[key_value.line_num] = key_value
+        key_value = KeyValues("filesys", ["mirror", "c0t0d0s1", "c0t1d0s1",
+            "all", "/"], 4)
+        kv_dict[key_value.line_num] = key_value
+        report = ConversionReport()
+        xml_data = XMLProfileData("test", kv_dict, report,
+                                  self.default_xml, True, None)
+        self.assertEquals(report.has_errors(), True)
+        self.assertEquals(report.process_errors, 0,
+                          self.profile_failure_report(xml_data, report))
+        self.assertEquals(report.conversion_errors, 0,
+                          self.profile_failure_report(xml_data, report))
+        self.assertEquals(report.unsupported_items, 1,
+                          self.profile_failure_report(xml_data, report))
+        self.assertEquals(report.validation_errors, 0,
+                          self.profile_failure_report(xml_data, report))
+        self.assertEquals(report.warnings, 0,
+                          self.profile_failure_report(xml_data, report))
+        self.validate_xml_output(xml_data)
+
+    def test_filesys_entry37(self):
+        """Tests filesys mirror swap with size of all"""
+        kv_dict = {}
+        key_value = KeyValues("install_type", ["initial_install"], 1)
+        kv_dict[key_value.line_num] = key_value
+        key_value = KeyValues("partitioning", ["explicit"], 3)
+        kv_dict[key_value.line_num] = key_value
+        key_value = KeyValues("filesys", ["mirror", "c0t0d0s1", "c0t1d0s1",
+            "all", "swap"], 4)
+        kv_dict[key_value.line_num] = key_value
+        key_value = KeyValues("filesys", ["c0t0d0s0", "20000", "/"], 5)
+        kv_dict[key_value.line_num] = key_value
+        report = ConversionReport()
+        xml_data = XMLProfileData("test", kv_dict, report,
+                                  self.default_xml, True, None)
+        self.assertEquals(report.has_errors(), True)
+        self.assertEquals(report.process_errors, 0,
+                          self.profile_failure_report(xml_data, report))
+        self.assertEquals(report.conversion_errors, 0,
+                          self.profile_failure_report(xml_data, report))
+        self.assertEquals(report.unsupported_items, 1,
+                          self.profile_failure_report(xml_data, report))
+        self.assertEquals(report.validation_errors, 0,
+                          self.profile_failure_report(xml_data, report))
+        self.assertEquals(report.warnings, 0,
+                          self.profile_failure_report(xml_data, report))
+        self.validate_xml_output(xml_data)
+
     def test_locale_entry1(self):
         """Tests locale for unsupported syntax"""
         kv_dict = {}
@@ -1843,7 +1879,7 @@
         key_value = KeyValues("install_type", ["initial_install"], 1)
         kv_dict[key_value.line_num] = key_value
         key_value = KeyValues("pool", ["rpool",
-            "all", "4g", "4g", "mirror", "c0t0d0s0", "c0t1d0s0"], 4)
+            "auto", "4g", "4g", "mirror", "c0t0d0s0", "c0t1d0s0"], 4)
         kv_dict[key_value.line_num] = key_value
         report = ConversionReport()
         xml_data = XMLProfileData("test", kv_dict, report,
@@ -1968,7 +2004,7 @@
         key_value = KeyValues("install_type", ["initial_install"], 1)
         kv_dict[key_value.line_num] = key_value
         key_value = KeyValues("pool", ["rpool",
-            "all", "auto", "auto", "any"], 4)
+            "auto", "auto", "auto", "any"], 4)
         kv_dict[key_value.line_num] = key_value
         report = ConversionReport()
         xml_data = XMLProfileData("test", kv_dict, report,
--- a/usr/src/cmd/js2ai/modules/test/test_js2ai.py	Tue Jul 26 12:52:00 2011 -0700
+++ b/usr/src/cmd/js2ai/modules/test/test_js2ai.py	Wed Jul 27 10:12:11 2011 -0600
@@ -1017,7 +1017,9 @@
     def test_p_option_valid_profile(self):
         """Tests calling js2ai with -p option set against a valid profile"""
 
-        sys.argv = ["js2ai", "-Sd", self.working_dir, "-p", self.profile_name,
+        sys.argv = ["js2ai", "-Sd", self.working_dir,
+                    "-D", self.working_dir,
+                    "-p", self.profile_name,
                     "-i", "none"]
         try:
             js2ai.main()
@@ -1176,7 +1178,8 @@
         rules/profiles, no errors
 
         """
-        sys.argv = ["js2ai", "-Srd", self.working_dir, "-i", "none"]
+        sys.argv = ["js2ai", "-Srd", self.working_dir,
+                    "-D", self.working_dir, "-i", "none"]
         try:
             js2ai.main()
         except SystemExit, err:
@@ -1239,7 +1242,8 @@
         with errors
 
         """
-        sys.argv = ["js2ai", "-rSd", self.working_dir, "-v", "-i", "none"]
+        sys.argv = ["js2ai", "-rSd", self.working_dir,
+                    "-D", self.working_dir, "-v", "-i", "none"]
         try:
             js2ai.main()
         except SystemExit, err:
@@ -1314,7 +1318,8 @@
         """Tests calling js2ai with -s option against valid sysidcfg, no errors
 
         """
-        sys.argv = ["js2ai", "-d", self.working_dir, "-s", self.working_dir]
+        sys.argv = ["js2ai", "-d", self.working_dir,
+                    "-D", self.working_dir, "-s"]
         try:
             js2ai.main()
         except SystemExit, err: