24933105 Flavor RAM not aligned to 256Mb causes error in nova.virt.solariszones.driver
authorSean Wilcox <sean.wilcox@oracle.com>
Tue, 08 Nov 2016 11:16:49 -0700
changeset 7265 078a4fa1d5a1
parent 7264 86d356dd86aa
child 7266 02c0ccd65cf9
24933105 Flavor RAM not aligned to 256Mb causes error in nova.virt.solariszones.driver
components/openstack/nova/files/solariszones/driver.py
--- a/components/openstack/nova/files/solariszones/driver.py	Tue Nov 08 11:16:49 2016 -0700
+++ b/components/openstack/nova/files/solariszones/driver.py	Tue Nov 08 11:16:49 2016 -0700
@@ -236,6 +236,11 @@
     return result
 
 
+class MemoryAlignmentIncorrect(exception.FlavorMemoryTooSmall):
+    msg_fmt = _("Requested flavor, %(flavor)s, memory size %(memsize)s does "
+                "not align on %(align)s boundary.")
+
+
 class SolarisVolumeAPI(API):
     """ Extending the volume api to support additional cinder sub-commands
     """
@@ -1160,6 +1165,24 @@
         # - looks like it's OK
         self._validated_archives.append(instance['image_ref'])
 
+    def _validate_flavor(self, instance):
+        """Validate the flavor for compatibility with zone brands"""
+        flavor = self._get_flavor(instance)
+        extra_specs = flavor['extra_specs'].copy()
+        brand = extra_specs.get('zonecfg:brand', ZONE_BRAND_SOLARIS)
+
+        if brand == ZONE_BRAND_SOLARIS_KZ:
+            # verify the memory is 256mb aligned
+            test_size = Size('256MB')
+            instance_size = Size('%sMB' % instance['memory_mb'])
+
+            if instance_size.byte_value % test_size.byte_value:
+                # non-zero result so it doesn't align
+                raise MemoryAlignmentIncorrect(
+                    flavor=flavor['name'],
+                    memsize=str(instance['memory_mb']),
+                    align='256')
+
     def _suri_from_volume_info(self, connection_info):
         """Returns a suri(5) formatted string based on connection_info.
         Currently supports local ZFS volume, NFS, Fibre Channel and iSCSI
@@ -2146,6 +2169,7 @@
         """
         image = self._fetch_image(context, instance)
         self._validate_image(context, image, instance)
+        self._validate_flavor(instance)
 
         # c1d0 is the standard dev for the default boot device.
         # Irrelevant value for ZFS, but Cinder gets stroppy without it.