Merge "Changes required for running CI tests (Pike pod)."
authorSteven Pisarski <s.pisarski@cablelabs.com>
Fri, 21 Jul 2017 13:34:14 +0000 (13:34 +0000)
committerGerrit Code Review <gerrit@opnfv.org>
Fri, 21 Jul 2017 13:34:14 +0000 (13:34 +0000)
snaps/openstack/create_flavor.py
snaps/openstack/create_instance.py
snaps/openstack/tests/create_flavor_tests.py
snaps/openstack/tests/create_instance_tests.py

index 42264b0..ec4c765 100644 (file)
@@ -20,7 +20,7 @@ from snaps.openstack.utils import nova_utils
 
 __author__ = 'spisarski'
 
-logger = logging.getLogger('create_image')
+logger = logging.getLogger('create_flavor')
 
 MEM_PAGE_SIZE_ANY = {'hw:mem_page_size': 'any'}
 MEM_PAGE_SIZE_LARGE = {'hw:mem_page_size': 'large'}
@@ -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 97f04f3..d5917a8 100644 (file)
@@ -126,7 +126,7 @@ class OpenStackVmInstance:
 
         if block:
             if not self.vm_active(block=True):
-                raise Exception(
+                raise VmInstanceCreationError(
                     'Fatal error, VM did not become ACTIVE within the alloted '
                     'time')
 
@@ -136,7 +136,7 @@ class OpenStackVmInstance:
                 nova_utils.add_security_group(self.__nova, self.__vm,
                                               sec_grp_name)
             else:
-                raise Exception(
+                raise VmInstanceCreationError(
                     'Cannot applying security group with name ' +
                     sec_grp_name +
                     ' to VM that did not activate with name - ' +
@@ -157,7 +157,7 @@ class OpenStackVmInstance:
             port = port_dict.get(floating_ip_setting.port_name)
 
             if not port:
-                raise Exception(
+                raise VmInstanceCreationError(
                     'Cannot find port object with name - ' +
                     floating_ip_setting.port_name)
 
@@ -178,9 +178,9 @@ class OpenStackVmInstance:
                     floating_ip_setting.router_name)
                 self.__add_floating_ip(floating_ip, port, subnet)
             else:
-                raise Exception('Unable to add floating IP to port,'
-                                ' cannot locate router with an external '
-                                'gateway ')
+                raise VmInstanceCreationError(
+                    'Unable to add floating IP to port, cannot locate router '
+                    'with an external gateway ')
 
     def __ext_gateway_by_router(self, router_name):
         """
@@ -314,11 +314,12 @@ class OpenStackVmInstance:
                     count -= 1
                     pass
         else:
-            raise Exception(
+            raise VmInstanceCreationError(
                 'Unable find IP address on which to place the floating IP')
 
         logger.error('Timeout attempting to add the floating IP to instance.')
-        raise Exception('Timeout while attempting add floating IP to instance')
+        raise VmInstanceCreationError(
+            'Timeout while attempting add floating IP to instance')
 
     def get_os_creds(self):
         """
@@ -568,7 +569,8 @@ class OpenStackVmInstance:
             return False
 
         if status == 'ERROR':
-            raise Exception('Instance had an error during deployment')
+            raise VmInstanceCreationError(
+                'Instance had an error during deployment')
         logger.debug(
             'Instance status [%s] is - %s', self.instance_settings.name,
             status)
@@ -743,7 +745,7 @@ class VmInstanceSettings:
             elif isinstance(kwargs['security_group_names'], str):
                 self.security_group_names = [kwargs['security_group_names']]
             else:
-                raise Exception(
+                raise VmInstanceSettingsError(
                     'Invalid data type for security_group_names attribute')
         else:
             self.security_group_names = set()
@@ -781,11 +783,11 @@ class VmInstanceSettings:
             self.availability_zone = None
 
         if not self.name or not self.flavor:
-            raise Exception(
+            raise VmInstanceSettingsError(
                 'Instance configuration requires the attributes: name, flavor')
 
         if len(self.port_settings) == 0:
-            raise Exception(
+            raise VmInstanceSettingsError(
                 'Instance configuration requires port settings (aka. NICS)')
 
 
@@ -822,6 +824,24 @@ class FloatingIpSettings:
             self.provisioning = True
 
         if not self.name or not self.port_name or not self.router_name:
-            raise Exception(
+            raise FloatingIpSettingsError(
                 'The attributes name, port_name and router_name are required '
                 'for FloatingIPSettings')
+
+
+class VmInstanceSettingsError(Exception):
+    """
+    Exception to be thrown when an VM instance settings are incorrect
+    """
+
+
+class FloatingIpSettingsError(Exception):
+    """
+    Exception to be thrown when an VM instance settings are incorrect
+    """
+
+
+class VmInstanceCreationError(Exception):
+    """
+    Exception to be thrown when an VM instance cannot be created
+    """
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,
index 6ea4ffc..75b0ed3 100644 (file)
@@ -20,12 +20,14 @@ import unittest
 import uuid
 
 import os
+from neutronclient.common.exceptions import InvalidIpForSubnetClient
 
 from snaps import file_utils
 from snaps.openstack.create_flavor import OpenStackFlavor, FlavorSettings
 from snaps.openstack.create_image import OpenStackImage, ImageSettings
 from snaps.openstack.create_instance import (
-    VmInstanceSettings, OpenStackVmInstance, FloatingIpSettings)
+    VmInstanceSettings, OpenStackVmInstance, FloatingIpSettings,
+    VmInstanceSettingsError, FloatingIpSettingsError)
 from snaps.openstack.create_keypairs import OpenStackKeypair, KeypairSettings
 from snaps.openstack.create_network import OpenStackNetwork, PortSettings
 from snaps.openstack.create_router import OpenStackRouter
@@ -50,27 +52,27 @@ class VmInstanceSettingsUnitTests(unittest.TestCase):
     """
 
     def test_no_params(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(VmInstanceSettingsError):
             VmInstanceSettings()
 
     def test_empty_config(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(VmInstanceSettingsError):
             VmInstanceSettings(config=dict())
 
     def test_name_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(VmInstanceSettingsError):
             VmInstanceSettings(name='foo')
 
     def test_config_with_name_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(VmInstanceSettingsError):
             VmInstanceSettings(config={'name': 'foo'})
 
     def test_name_flavor_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(VmInstanceSettingsError):
             VmInstanceSettings(name='foo', flavor='bar')
 
     def test_config_with_name_flavor_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(VmInstanceSettingsError):
             VmInstanceSettings(config={'name': 'foo', 'flavor': 'bar'})
 
     def test_name_flavor_port_only(self):
@@ -175,35 +177,35 @@ class FloatingIpSettingsUnitTests(unittest.TestCase):
     """
 
     def test_no_params(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FloatingIpSettingsError):
             FloatingIpSettings()
 
     def test_empty_config(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FloatingIpSettingsError):
             FloatingIpSettings(**dict())
 
     def test_name_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FloatingIpSettingsError):
             FloatingIpSettings(name='foo')
 
     def test_config_with_name_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FloatingIpSettingsError):
             FloatingIpSettings(**{'name': 'foo'})
 
     def test_name_port_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FloatingIpSettingsError):
             FloatingIpSettings(name='foo', port_name='bar')
 
     def test_config_with_name_port_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FloatingIpSettingsError):
             FloatingIpSettings(**{'name': 'foo', 'port_name': 'bar'})
 
     def test_name_router_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FloatingIpSettingsError):
             FloatingIpSettings(name='foo', router_name='bar')
 
     def test_config_with_name_router_only(self):
-        with self.assertRaises(Exception):
+        with self.assertRaises(FloatingIpSettingsError):
             FloatingIpSettings(**{'name': 'foo', 'router_name': 'bar'})
 
     def test_name_port_router_only(self):
@@ -882,7 +884,7 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase):
             self.os_creds, instance_settings,
             self.image_creator.image_settings)
 
-        with self.assertRaises(Exception):
+        with self.assertRaises(InvalidIpForSubnetClient):
             self.inst_creator.create()
 
     def test_set_custom_valid_mac(self):