Created new class FlavorSettingsError. 95/37695/1
authorspisarski <s.pisarski@cablelabs.com>
Tue, 18 Jul 2017 16:09:36 +0000 (10:09 -0600)
committerspisarski <s.pisarski@cablelabs.com>
Tue, 18 Jul 2017 16:09:36 +0000 (10:09 -0600)
Raising FlavorSettingsError in FlavorSettings instead of Exception.

JIRA: SNAPS-131

Change-Id: I1cbd077f97bd9294e7bb87fc51c4125d0ef23f42
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
snaps/openstack/create_flavor.py
snaps/openstack/tests/create_flavor_tests.py

index 42264b0..afa11cf 100644 (file)
@@ -149,28 +149,36 @@ class FlavorSettings:
             self.metadata = None
 
         if not self.name or not self.ram or not self.disk or not self.vcpus:
-            raise Exception(
+            raise FlavorSettingsError(
                 'The attributes name, ram, disk, and vcpus are required for'
                 'FlavorSettings')
 
         if not isinstance(self.ram, int):
-            raise Exception('The ram attribute must be a integer')
+            raise FlavorSettingsError('The ram attribute must be a integer')
 
         if not isinstance(self.disk, int):
-            raise Exception('The ram attribute must be a integer')
+            raise FlavorSettingsError('The ram attribute must be a integer')
 
         if not isinstance(self.vcpus, int):
-            raise Exception('The vcpus attribute must be a integer')
+            raise FlavorSettingsError('The vcpus attribute must be a integer')
 
         if self.ephemeral and not isinstance(self.ephemeral, int):
-            raise Exception('The ephemeral attribute must be an integer')
+            raise FlavorSettingsError(
+                'The ephemeral attribute must be an integer')
 
         if self.swap and not isinstance(self.swap, int):
-            raise Exception('The swap attribute must be an integer')
+            raise FlavorSettingsError('The swap attribute must be an integer')
 
         if self.rxtx_factor and not isinstance(self.rxtx_factor, (int, float)):
-            raise Exception(
+            raise FlavorSettingsError(
                 'The is_public attribute must be an integer or float')
 
         if self.is_public and not isinstance(self.is_public, bool):
-            raise Exception('The is_public attribute must be a boolean')
+            raise FlavorSettingsError(
+                'The is_public attribute must be a boolean')
+
+
+class FlavorSettingsError(Exception):
+    """
+    Exception to be thrown when an flavor settings are incorrect
+    """
index 5d7e4c4..11306f4 100644 (file)
@@ -15,7 +15,8 @@
 import unittest
 import uuid
 
-from snaps.openstack.create_flavor import FlavorSettings, OpenStackFlavor
+from snaps.openstack.create_flavor import FlavorSettings, OpenStackFlavor, \
+    FlavorSettingsError
 from snaps.openstack.tests.os_source_file_test import OSComponentTestCase
 from snaps.openstack.utils import nova_utils
 
@@ -28,169 +29,169 @@ class FlavorSettingsUnitTests(unittest.TestCase):
     """
 
     def test_no_params(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings()
 
     def test_empty_config(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(config=dict())
 
     def test_name_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo')
 
     def test_config_with_name_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(config={'name': 'foo'})
 
     def test_name_ram_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1)
 
     def test_config_with_name_ram_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(config={'name': 'foo', 'ram': 1})
 
     def test_name_ram_disk_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk=1)
 
     def test_config_with_name_ram_disk_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(config={'name': 'foo', 'ram': 1, 'disk': 1})
 
     def test_ram_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram='bar', disk=2, vcpus=3, ephemeral=4,
                            swap=5, rxtx_factor=6.0,
                            is_public=False)
 
     def test_config_ram_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 'bar', 'disk': 2, 'vcpus': 3,
                         'ephemeral': 4, 'swap': 5,
                         'rxtx_factor': 6.0, 'is_public': False})
 
     def test_ram_float(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1.5, disk=2, vcpus=3, ephemeral=4,
                            swap=5, rxtx_factor=6.0, is_public=False)
 
     def test_config_ram_float(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1.5, 'disk': 2, 'vcpus': 3,
                         'ephemeral': 4, 'swap': 5,
                         'rxtx_factor': 6.0, 'is_public': False})
 
     def test_disk_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk='bar', vcpus=3, ephemeral=4,
                            swap=5, rxtx_factor=6.0,
                            is_public=False)
 
     def test_config_disk_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1, 'disk': 'bar', 'vcpus': 3,
                         'ephemeral': 4, 'swap': 5,
                         'rxtx_factor': 6.0, 'is_public': False})
 
     def test_disk_float(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk=2.5, vcpus=3, ephemeral=4,
                            swap=5, rxtx_factor=6.0, is_public=False)
 
     def test_config_disk_float(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1, 'disk': 2.5, 'vcpus': 3,
                         'ephemeral': 4, 'swap': 5,
                         'rxtx_factor': 6.0, 'is_public': False})
 
     def test_vcpus_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk=2, vcpus='bar', ephemeral=4,
                            swap=5, rxtx_factor=6.0,
                            is_public=False)
 
     def test_config_vcpus_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1, 'disk': 2, 'vcpus': 'bar',
                         'ephemeral': 4, 'swap': 5,
                         'rxtx_factor': 6.0, 'is_public': False})
 
     def test_ephemeral_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk=2, vcpus=3, ephemeral='bar',
                            swap=5, rxtx_factor=6.0,
                            is_public=False)
 
     def test_config_ephemeral_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1, 'disk': 2, 'vcpus': 3,
                         'ephemeral': 'bar', 'swap': 5,
                         'rxtx_factor': 6.0, 'is_public': False})
 
     def test_ephemeral_float(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk=2, vcpus=3, ephemeral=4.5,
                            swap=5, rxtx_factor=6.0, is_public=False)
 
     def test_config_ephemeral_float(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1, 'disk': 2, 'vcpus': 3,
                         'ephemeral': 4.5, 'swap': 5,
                         'rxtx_factor': 6.0, 'is_public': False})
 
     def test_swap_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk=2, vcpus=3, ephemeral=4,
                            swap='bar', rxtx_factor=6.0,
                            is_public=False)
 
     def test_config_swap_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1, 'disk': 2, 'vcpus': 3,
                         'ephemeral': 4, 'swap': 'bar',
                         'rxtx_factor': 6.0, 'is_public': False})
 
     def test_swap_float(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk=2, vcpus=3, ephemeral=4,
                            swap=5.5, rxtx_factor=6.0, is_public=False)
 
     def test_config_swap_float(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1, 'disk': 2, 'vcpus': 3,
                         'ephemeral': 4, 'swap': 5.5,
                         'rxtx_factor': 6.0, 'is_public': False})
 
     def test_rxtx_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk=2, vcpus=3, ephemeral=4,
                            swap=5, rxtx_factor='bar', is_public=False)
 
     def test_config_rxtx_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1, 'disk': 2, 'vcpus': 3,
                         'ephemeral': 4, 'swap': 5,
                         'rxtx_factor': 'bar', 'is_public': False})
 
     def test_is_pub_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(name='foo', ram=1, disk=2, vcpus=3, ephemeral=4,
                            swap=5, rxtx_factor=6.0, is_public='bar')
 
     def test_config_is_pub_string(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FlavorSettingsError):
             FlavorSettings(
                 config={'name': 'foo', 'ram': 1, 'disk': 2, 'vcpus': 3,
                         'ephemeral': 4, 'swap': 5,