From 594e4d2b15dcf59fc7dc1b8380b096382a0b1cb1 Mon Sep 17 00:00:00 2001 From: spisarski Date: Mon, 20 Nov 2017 13:51:18 -0700 Subject: Refactoring of VmInstanceSettings to extend VmInstanceConfig VmInstanceSettings, FloatingIPSettings and nova_utils have a runtime cyclical dependency. This patch reduces this dependency and deprecates the VmInstanceSettings and FloatingIPSettings class with snaps.config.vm_inst VmInstanceConfig and FloatingIpConfg classes JIRA: SNAPS-218 Change-Id: I95688130256bca1df4a5c347bdb741019ae0937e Signed-off-by: spisarski --- docs/how-to-use/APITests.rst | 2 +- docs/how-to-use/UnitTests.rst | 16 +- examples/demo.py | 8 +- examples/launch.py | 4 +- snaps/config/tests/vm_inst_tests.py | 242 +++++++++++++++++++++ snaps/config/vm_inst.py | 163 ++++++++++++++ snaps/openstack/create_instance.py | 152 ++----------- snaps/openstack/create_stack.py | 6 +- snaps/openstack/tests/create_instance_tests.py | 120 +++++----- snaps/openstack/tests/create_router_tests.py | 2 +- snaps/openstack/utils/deploy_utils.py | 2 +- snaps/openstack/utils/nova_utils.py | 4 +- snaps/openstack/utils/settings_utils.py | 21 +- snaps/openstack/utils/tests/heat_utils_tests.py | 2 +- snaps/openstack/utils/tests/nova_utils_tests.py | 8 +- .../openstack/utils/tests/settings_utils_tests.py | 15 +- snaps/provisioning/tests/ansible_utils_tests.py | 5 +- snaps/test_suite_builder.py | 6 + 18 files changed, 540 insertions(+), 238 deletions(-) create mode 100644 snaps/config/tests/vm_inst_tests.py create mode 100644 snaps/config/vm_inst.py diff --git a/docs/how-to-use/APITests.rst b/docs/how-to-use/APITests.rst index 83edd66..ee0d894 100644 --- a/docs/how-to-use/APITests.rst +++ b/docs/how-to-use/APITests.rst @@ -563,7 +563,7 @@ settings_utils_tests.py - SettingsUtilsVmInstTests +---------------------------------------+---------------+-----------------------------------------------------------+ | Test Name | API | Description | +=======================================+===============+===========================================================+ -| test_derive_vm_inst_settings | Neutron 2 | Tests to ensure that derived VmInstanceSettings from an | +| test_derive_vm_inst_config | Neutron 2 | Tests to ensure that derived VmInstanceSettings from an | | | | OpenStack VM instance is correct | +---------------------------------------+---------------+-----------------------------------------------------------+ | test_derive_image_settings | Neutron 2 | Tests to ensure that derived ImageConfig from an | diff --git a/docs/how-to-use/UnitTests.rst b/docs/how-to-use/UnitTests.rst index c053372..7f7c6ae 100644 --- a/docs/how-to-use/UnitTests.rst +++ b/docs/how-to-use/UnitTests.rst @@ -348,11 +348,17 @@ VolumeDomainObjectTests Ensures that all required members are included when constructing a Volume domain object (for Cinder) +FloatingIpConfigUnitTests +------------------------- + +Ensures that all required members are included when constructing a +FloatingIpConfig object + FloatingIpSettingsUnitTests --------------------------- Ensures that all required members are included when constructing a -FloatingIpSettings object +depecated FloatingIpSettings object FloatingIpDomainObjectTests --------------------------- @@ -360,11 +366,17 @@ FloatingIpDomainObjectTests Ensures that all required members are included when constructing a FloatingIp domain object +VmInstanceConfigUnitTests +------------------------- + +Ensures that all required members are included when constructing a +VmInstanceConfig object + VmInstanceSettingsUnitTests --------------------------- Ensures that all required members are included when constructing a -VmInstanceSettings object +deprecated VmInstanceSettings object VmInstDomainObjectTests ----------------------- diff --git a/examples/demo.py b/examples/demo.py index c888d7b..87c095b 100644 --- a/examples/demo.py +++ b/examples/demo.py @@ -1,4 +1,7 @@ import logging + +from snaps.config.vm_inst import VmInstanceConfig + logging.basicConfig(level=logging.INFO) # Credentials @@ -48,12 +51,11 @@ flavor.create() # Instances from snaps.config.network import PortConfig -from snaps.openstack.create_instance import ( - VmInstanceSettings, OpenStackVmInstance) +from snaps.openstack.create_instance import OpenStackVmInstance port_settings = PortConfig( name='test-port', network_name=network_settings.name) -instance_settings = VmInstanceSettings( +instance_settings = VmInstanceConfig( name='test-inst', flavor=flavor_settings.name, port_settings=[port_settings]) diff --git a/examples/launch.py b/examples/launch.py index 9320512..8810c32 100644 --- a/examples/launch.py +++ b/examples/launch.py @@ -34,11 +34,11 @@ from snaps.config.project import ProjectConfig from snaps.config.qos import QoSConfig from snaps.config.router import RouterConfig from snaps.config.user import UserConfig +from snaps.config.vm_inst import VmInstanceConfig from snaps.config.volume import VolumeConfig from snaps.config.volume_type import VolumeTypeConfig from snaps.openstack.create_flavor import OpenStackFlavor from snaps.openstack.create_image import OpenStackImage -from snaps.openstack.create_instance import VmInstanceSettings from snaps.openstack.create_keypairs import OpenStackKeypair from snaps.openstack.create_network import OpenStackNetwork from snaps.openstack.create_project import OpenStackProject @@ -218,7 +218,7 @@ def __create_vm_instances(os_creds_dict, os_users_dict, instances_config, if image_dict: image_creator = image_dict.get(conf.get('imageName')) if image_creator: - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( **instance_config['instance']) kp_creator = keypairs_dict.get( conf.get('keypair_name')) diff --git a/snaps/config/tests/vm_inst_tests.py b/snaps/config/tests/vm_inst_tests.py new file mode 100644 index 0000000..71d2e0b --- /dev/null +++ b/snaps/config/tests/vm_inst_tests.py @@ -0,0 +1,242 @@ +# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs") +# and others. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import unittest + +from snaps.config.network import PortConfig +from snaps.config.vm_inst import ( + FloatingIpConfig, VmInstanceConfig, FloatingIpConfigError, + VmInstanceConfigError) + + +class VmInstanceConfigUnitTests(unittest.TestCase): + """ + Tests the construction of the VmInstanceConfig class + """ + + def test_no_params(self): + with self.assertRaises(VmInstanceConfigError): + VmInstanceConfig() + + def test_empty_config(self): + with self.assertRaises(VmInstanceConfigError): + VmInstanceConfig(config=dict()) + + def test_name_only(self): + with self.assertRaises(VmInstanceConfigError): + VmInstanceConfig(name='foo') + + def test_config_with_name_only(self): + with self.assertRaises(VmInstanceConfigError): + VmInstanceConfig(config={'name': 'foo'}) + + def test_name_flavor_only(self): + with self.assertRaises(VmInstanceConfigError): + VmInstanceConfig(name='foo', flavor='bar') + + def test_config_with_name_flavor_only(self): + with self.assertRaises(VmInstanceConfigError): + VmInstanceConfig(config={'name': 'foo', 'flavor': 'bar'}) + + def test_name_flavor_port_only(self): + port_settings = PortConfig(name='foo-port', network_name='bar-net') + settings = VmInstanceConfig(name='foo', flavor='bar', + port_settings=[port_settings]) + self.assertEqual('foo', settings.name) + self.assertEqual('bar', settings.flavor) + self.assertEqual(1, len(settings.port_settings)) + self.assertEqual('foo-port', settings.port_settings[0].name) + self.assertEqual('bar-net', settings.port_settings[0].network_name) + self.assertEqual(0, len(settings.security_group_names)) + self.assertEqual(0, len(settings.floating_ip_settings)) + self.assertIsNone(settings.sudo_user) + self.assertEqual(900, settings.vm_boot_timeout) + self.assertEqual(300, settings.vm_delete_timeout) + self.assertEqual(180, settings.ssh_connect_timeout) + self.assertIsNone(settings.availability_zone) + self.assertIsNone(settings.volume_names) + + def test_config_with_name_flavor_port_only(self): + port_settings = PortConfig(name='foo-port', network_name='bar-net') + settings = VmInstanceConfig( + **{'name': 'foo', 'flavor': 'bar', 'ports': [port_settings]}) + self.assertEqual('foo', settings.name) + self.assertEqual('bar', settings.flavor) + self.assertEqual(1, len(settings.port_settings)) + self.assertEqual('foo-port', settings.port_settings[0].name) + self.assertEqual('bar-net', settings.port_settings[0].network_name) + self.assertEqual(0, len(settings.security_group_names)) + self.assertEqual(0, len(settings.floating_ip_settings)) + self.assertIsNone(settings.sudo_user) + self.assertEqual(900, settings.vm_boot_timeout) + self.assertEqual(300, settings.vm_delete_timeout) + self.assertEqual(180, settings.ssh_connect_timeout) + self.assertIsNone(settings.availability_zone) + self.assertIsNone(settings.volume_names) + + def test_all(self): + port_settings = PortConfig(name='foo-port', network_name='bar-net') + fip_settings = FloatingIpConfig(name='foo-fip', port_name='bar-port', + router_name='foo-bar-router') + + settings = VmInstanceConfig( + name='foo', flavor='bar', port_settings=[port_settings], + security_group_names=['sec_grp_1'], + floating_ip_settings=[fip_settings], sudo_user='joe', + vm_boot_timeout=999, vm_delete_timeout=333, + ssh_connect_timeout=111, availability_zone='server name', + volume_names=['vol1']) + self.assertEqual('foo', settings.name) + self.assertEqual('bar', settings.flavor) + self.assertEqual(1, len(settings.port_settings)) + self.assertEqual('foo-port', settings.port_settings[0].name) + self.assertEqual('bar-net', settings.port_settings[0].network_name) + self.assertEqual(1, len(settings.security_group_names)) + self.assertEqual('sec_grp_1', settings.security_group_names[0]) + self.assertEqual(1, len(settings.floating_ip_settings)) + self.assertEqual('foo-fip', settings.floating_ip_settings[0].name) + self.assertEqual('bar-port', + settings.floating_ip_settings[0].port_name) + self.assertEqual('foo-bar-router', + settings.floating_ip_settings[0].router_name) + self.assertEqual('joe', settings.sudo_user) + self.assertEqual(999, settings.vm_boot_timeout) + self.assertEqual(333, settings.vm_delete_timeout) + self.assertEqual(111, settings.ssh_connect_timeout) + self.assertEqual('server name', settings.availability_zone) + self.assertEqual('vol1', settings.volume_names[0]) + + def test_config_all(self): + port_settings = PortConfig(name='foo-port', network_name='bar-net') + fip_settings = FloatingIpConfig(name='foo-fip', port_name='bar-port', + router_name='foo-bar-router') + + settings = VmInstanceConfig( + **{'name': 'foo', 'flavor': 'bar', 'ports': [port_settings], + 'security_group_names': ['sec_grp_1'], + 'floating_ips': [fip_settings], 'sudo_user': 'joe', + 'vm_boot_timeout': 999, 'vm_delete_timeout': 333, + 'ssh_connect_timeout': 111, 'availability_zone': 'server name', + 'volume_names': ['vol2']}) + self.assertEqual('foo', settings.name) + self.assertEqual('bar', settings.flavor) + self.assertEqual(1, len(settings.port_settings)) + self.assertEqual('foo-port', settings.port_settings[0].name) + self.assertEqual('bar-net', settings.port_settings[0].network_name) + self.assertEqual(1, len(settings.security_group_names)) + self.assertEqual(1, len(settings.floating_ip_settings)) + self.assertEqual('foo-fip', settings.floating_ip_settings[0].name) + self.assertEqual('bar-port', + settings.floating_ip_settings[0].port_name) + self.assertEqual('foo-bar-router', + settings.floating_ip_settings[0].router_name) + self.assertEqual('joe', settings.sudo_user) + self.assertEqual(999, settings.vm_boot_timeout) + self.assertEqual(333, settings.vm_delete_timeout) + self.assertEqual(111, settings.ssh_connect_timeout) + self.assertEqual('server name', settings.availability_zone) + self.assertEqual('vol2', settings.volume_names[0]) + + +class FloatingIpConfigUnitTests(unittest.TestCase): + """ + Tests the construction of the FloatingIpConfig class + """ + + def test_no_params(self): + with self.assertRaises(FloatingIpConfigError): + FloatingIpConfig() + + def test_empty_config(self): + with self.assertRaises(FloatingIpConfigError): + FloatingIpConfig(**dict()) + + def test_name_only(self): + with self.assertRaises(FloatingIpConfigError): + FloatingIpConfig(name='foo') + + def test_config_with_name_only(self): + with self.assertRaises(FloatingIpConfigError): + FloatingIpConfig(**{'name': 'foo'}) + + def test_name_port_only(self): + with self.assertRaises(FloatingIpConfigError): + FloatingIpConfig(name='foo', port_name='bar') + + def test_config_with_name_port_only(self): + with self.assertRaises(FloatingIpConfigError): + FloatingIpConfig(**{'name': 'foo', 'port_name': 'bar'}) + + def test_name_router_only(self): + with self.assertRaises(FloatingIpConfigError): + FloatingIpConfig(name='foo', router_name='bar') + + def test_config_with_name_router_only(self): + with self.assertRaises(FloatingIpConfigError): + FloatingIpConfig(**{'name': 'foo', 'router_name': 'bar'}) + + def test_name_port_router_name_only(self): + settings = FloatingIpConfig(name='foo', port_name='foo-port', + router_name='bar-router') + self.assertEqual('foo', settings.name) + self.assertEqual('foo-port', settings.port_name) + self.assertIsNone(settings.port_id) + self.assertEqual('bar-router', settings.router_name) + self.assertIsNone(settings.subnet_name) + self.assertTrue(settings.provisioning) + + def test_name_port_router_id_only(self): + settings = FloatingIpConfig(name='foo', port_id='foo-port', + router_name='bar-router') + self.assertEqual('foo', settings.name) + self.assertEqual('foo-port', settings.port_id) + self.assertIsNone(settings.port_name) + self.assertEqual('bar-router', settings.router_name) + self.assertIsNone(settings.subnet_name) + self.assertTrue(settings.provisioning) + + def test_config_with_name_port_router_only(self): + settings = FloatingIpConfig( + **{'name': 'foo', 'port_name': 'foo-port', + 'router_name': 'bar-router'}) + self.assertEqual('foo', settings.name) + self.assertEqual('foo-port', settings.port_name) + self.assertIsNone(settings.port_id) + self.assertEqual('bar-router', settings.router_name) + self.assertIsNone(settings.subnet_name) + self.assertTrue(settings.provisioning) + + def test_all(self): + settings = FloatingIpConfig(name='foo', port_name='foo-port', + router_name='bar-router', + subnet_name='bar-subnet', + provisioning=False) + self.assertEqual('foo', settings.name) + self.assertEqual('foo-port', settings.port_name) + self.assertIsNone(settings.port_id) + self.assertEqual('bar-router', settings.router_name) + self.assertEqual('bar-subnet', settings.subnet_name) + self.assertFalse(settings.provisioning) + + def test_config_all(self): + settings = FloatingIpConfig( + **{'name': 'foo', 'port_name': 'foo-port', + 'router_name': 'bar-router', 'subnet_name': 'bar-subnet', + 'provisioning': False}) + self.assertEqual('foo', settings.name) + self.assertEqual('foo-port', settings.port_name) + self.assertIsNone(settings.port_id) + self.assertEqual('bar-router', settings.router_name) + self.assertEqual('bar-subnet', settings.subnet_name) + self.assertFalse(settings.provisioning) diff --git a/snaps/config/vm_inst.py b/snaps/config/vm_inst.py new file mode 100644 index 0000000..9533ea1 --- /dev/null +++ b/snaps/config/vm_inst.py @@ -0,0 +1,163 @@ +# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs") +# and others. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from snaps.config.network import PortConfig + + +class VmInstanceConfig(object): + """ + Class responsible for holding configuration setting for a VM Instance + """ + + def __init__(self, **kwargs): + """ + Constructor + :param name: the name of the VM + :param flavor: the VM's flavor name + :param port_settings: the port configuration settings (required) + :param security_group_names: a set of names of the security groups to + add to the VM + :param floating_ip_settings: the floating IP configuration settings + :param sudo_user: the sudo user of the VM that will override the + instance_settings.image_user when trying to + connect to the VM + :param vm_boot_timeout: the amount of time a thread will sleep waiting + for an instance to boot + :param vm_delete_timeout: the amount of time a thread will sleep + waiting for an instance to be deleted + :param ssh_connect_timeout: the amount of time a thread will sleep + waiting obtaining an SSH connection to a VM + :param availability_zone: the name of the compute server on which to + deploy the VM (optional) + :param volume_names: a list of the names of the volume to attach + (optional) + :param userdata: the string contents of any optional cloud-init script + to execute after the VM has been activated. + This value may also contain a dict who's key value + must contain the key 'cloud-init_file' which denotes + the location of some file containing the cloud-init + script + """ + self.name = kwargs.get('name') + self.flavor = kwargs.get('flavor') + self.sudo_user = kwargs.get('sudo_user') + self.userdata = kwargs.get('userdata') + + self.port_settings = list() + port_settings = kwargs.get('ports') + if not port_settings: + port_settings = kwargs.get('port_settings') + if port_settings: + for port_setting in port_settings: + if isinstance(port_setting, dict): + self.port_settings.append(PortConfig(**port_setting)) + elif isinstance(port_setting, PortConfig): + self.port_settings.append(port_setting) + + if kwargs.get('security_group_names'): + if isinstance(kwargs['security_group_names'], list): + self.security_group_names = kwargs['security_group_names'] + elif isinstance(kwargs['security_group_names'], set): + self.security_group_names = kwargs['security_group_names'] + elif isinstance(kwargs['security_group_names'], str): + self.security_group_names = [kwargs['security_group_names']] + else: + raise VmInstanceConfigError( + 'Invalid data type for security_group_names attribute') + else: + self.security_group_names = set() + + self.floating_ip_settings = list() + floating_ip_settings = kwargs.get('floating_ips') + if not floating_ip_settings: + floating_ip_settings = kwargs.get('floating_ip_settings') + if floating_ip_settings: + for floating_ip_config in floating_ip_settings: + if isinstance(floating_ip_config, FloatingIpConfig): + self.floating_ip_settings.append(floating_ip_config) + else: + self.floating_ip_settings.append(FloatingIpConfig( + **floating_ip_config['floating_ip'])) + + self.vm_boot_timeout = kwargs.get('vm_boot_timeout', 900) + self.vm_delete_timeout = kwargs.get('vm_delete_timeout', 300) + self.ssh_connect_timeout = kwargs.get('ssh_connect_timeout', 180) + self.availability_zone = kwargs.get('availability_zone') + self.volume_names = kwargs.get('volume_names') + + if self.volume_names and not isinstance(self.volume_names, list): + raise VmInstanceConfigError('volume_names must be a list') + + if not self.name or not self.flavor: + raise VmInstanceConfigError( + 'Instance configuration requires the attributes: name, flavor') + + if len(self.port_settings) == 0: + raise VmInstanceConfigError( + 'Instance configuration requires port settings (aka. NICS)') + + +class FloatingIpConfig(object): + """ + Class responsible for holding configuration settings for a floating IP + """ + + def __init__(self, **kwargs): + """ + Constructor + :param name: the name of the floating IP + :param port_name: the name of the router to the external network + :param router_name: the name of the router to the external network + :param subnet_name: the name of the subnet on which to attach the + floating IP + :param provisioning: when true, this floating IP can be used for + provisioning + + TODO - provisioning flag is a hack as I have only observed a single + Floating IPs that actually works on an instance. Multiple floating IPs + placed on different subnets from the same port are especially + troublesome as you cannot predict which one will actually connect. + For now, it is recommended not to setup multiple floating IPs on an + instance unless absolutely necessary. + """ + self.name = kwargs.get('name') + self.port_name = kwargs.get('port_name') + self.port_id = kwargs.get('port_id') + self.router_name = kwargs.get('router_name') + self.subnet_name = kwargs.get('subnet_name') + if kwargs.get('provisioning') is not None: + self.provisioning = kwargs['provisioning'] + else: + self.provisioning = True + + # if not self.name or not self.port_name or not self.router_name: + if not self.name or not self.router_name: + raise FloatingIpConfigError( + 'The attributes name, port_name and router_name are required') + + if not self.port_name and not self.port_id: + raise FloatingIpConfigError( + 'The attributes port_name or port_id are required') + + +class VmInstanceConfigError(Exception): + """ + Exception to be thrown when an VM instance settings are incorrect + """ + + +class FloatingIpConfigError(Exception): + """ + Exception to be thrown when an VM instance settings are incorrect + """ diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py index 58d6105..59bb8e4 100644 --- a/snaps/openstack/create_instance.py +++ b/snaps/openstack/create_instance.py @@ -18,7 +18,7 @@ import time from neutronclient.common.exceptions import PortNotFoundClient from novaclient.exceptions import NotFound, BadRequest -from snaps.config.network import PortConfig +from snaps.config.vm_inst import VmInstanceConfig, FloatingIpConfig from snaps.openstack.openstack_creator import OpenStackComputeObject from snaps.openstack.utils import glance_utils, cinder_utils from snaps.openstack.utils import neutron_utils @@ -768,152 +768,26 @@ class OpenStackVmInstance(OpenStackComputeObject): return False -class VmInstanceSettings: +class VmInstanceSettings(VmInstanceConfig): """ - Class responsible for holding configuration setting for a VM Instance + Deprecated, use snaps.config.vm_inst.VmInstanceConfig instead """ - def __init__(self, **kwargs): - """ - Constructor - :param name: the name of the VM - :param flavor: the VM's flavor name - :param port_settings: the port configuration settings (required) - :param security_group_names: a set of names of the security groups to - add to the VM - :param floating_ip_settings: the floating IP configuration settings - :param sudo_user: the sudo user of the VM that will override the - instance_settings.image_user when trying to - connect to the VM - :param vm_boot_timeout: the amount of time a thread will sleep waiting - for an instance to boot - :param vm_delete_timeout: the amount of time a thread will sleep - waiting for an instance to be deleted - :param ssh_connect_timeout: the amount of time a thread will sleep - waiting obtaining an SSH connection to a VM - :param availability_zone: the name of the compute server on which to - deploy the VM (optional) - :param volume_names: a list of the names of the volume to attach - (optional) - :param userdata: the string contents of any optional cloud-init script - to execute after the VM has been activated. - This value may also contain a dict who's key value - must contain the key 'cloud-init_file' which denotes - the location of some file containing the cloud-init - script - """ - self.name = kwargs.get('name') - self.flavor = kwargs.get('flavor') - self.sudo_user = kwargs.get('sudo_user') - self.userdata = kwargs.get('userdata') - - self.port_settings = list() - port_settings = kwargs.get('ports') - if not port_settings: - port_settings = kwargs.get('port_settings') - if port_settings: - for port_setting in port_settings: - if isinstance(port_setting, dict): - self.port_settings.append(PortConfig(**port_setting)) - elif isinstance(port_setting, PortConfig): - self.port_settings.append(port_setting) - - if kwargs.get('security_group_names'): - if isinstance(kwargs['security_group_names'], list): - self.security_group_names = kwargs['security_group_names'] - elif isinstance(kwargs['security_group_names'], set): - self.security_group_names = kwargs['security_group_names'] - elif isinstance(kwargs['security_group_names'], str): - self.security_group_names = [kwargs['security_group_names']] - else: - raise VmInstanceSettingsError( - 'Invalid data type for security_group_names attribute') - else: - self.security_group_names = set() - - self.floating_ip_settings = list() - floating_ip_settings = kwargs.get('floating_ips') - if not floating_ip_settings: - floating_ip_settings = kwargs.get('floating_ip_settings') - if floating_ip_settings: - for floating_ip_config in floating_ip_settings: - if isinstance(floating_ip_config, FloatingIpSettings): - self.floating_ip_settings.append(floating_ip_config) - else: - self.floating_ip_settings.append(FloatingIpSettings( - **floating_ip_config['floating_ip'])) + from warnings import warn + warn('Use snaps.config.vm_inst.VmInstanceConfig instead', + DeprecationWarning) + super(self.__class__, self).__init__(**kwargs) - self.vm_boot_timeout = kwargs.get('vm_boot_timeout', 900) - self.vm_delete_timeout = kwargs.get('vm_delete_timeout', 300) - self.ssh_connect_timeout = kwargs.get('ssh_connect_timeout', 180) - self.availability_zone = kwargs.get('availability_zone') - self.volume_names = kwargs.get('volume_names') - if self.volume_names and not isinstance(self.volume_names, list): - raise VmInstanceSettingsError('volume_names must be a list') - - if not self.name or not self.flavor: - raise VmInstanceSettingsError( - 'Instance configuration requires the attributes: name, flavor') - - if len(self.port_settings) == 0: - raise VmInstanceSettingsError( - 'Instance configuration requires port settings (aka. NICS)') - - -class FloatingIpSettings: +class FloatingIpSettings(FloatingIpConfig): """ - Class responsible for holding configuration settings for a floating IP + Deprecated, use snaps.config.vm_inst.FloatingIpConfig instead """ - def __init__(self, **kwargs): - """ - Constructor - :param name: the name of the floating IP - :param port_name: the name of the router to the external network - :param router_name: the name of the router to the external network - :param subnet_name: the name of the subnet on which to attach the - floating IP - :param provisioning: when true, this floating IP can be used for - provisioning - - TODO - provisioning flag is a hack as I have only observed a single - Floating IPs that actually works on an instance. Multiple floating IPs - placed on different subnets from the same port are especially - troublesome as you cannot predict which one will actually connect. - For now, it is recommended not to setup multiple floating IPs on an - instance unless absolutely necessary. - """ - self.name = kwargs.get('name') - self.port_name = kwargs.get('port_name') - self.port_id = kwargs.get('port_id') - self.router_name = kwargs.get('router_name') - self.subnet_name = kwargs.get('subnet_name') - if kwargs.get('provisioning') is not None: - self.provisioning = kwargs['provisioning'] - else: - self.provisioning = True - - # if not self.name or not self.port_name or not self.router_name: - if not self.name or not self.router_name: - raise FloatingIpSettingsError( - 'The attributes name, port_name and router_name are required') - - if not self.port_name and not self.port_id: - raise FloatingIpSettingsError( - 'The attributes port_name or port_id are required') - - -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 - """ + from warnings import warn + warn('Use snaps.config.vm_inst.FloatingIpConfig instead', + DeprecationWarning) + super(self.__class__, self).__init__(**kwargs) class VmInstanceCreationError(Exception): diff --git a/snaps/openstack/create_stack.py b/snaps/openstack/create_stack.py index 1fcc5b4..fa0a0c5 100644 --- a/snaps/openstack/create_stack.py +++ b/snaps/openstack/create_stack.py @@ -267,7 +267,7 @@ class OpenStackHeatStack(OpenStackCloudObject, object): self.__heat_cli, neutron, self.__stack) for routers in stack_routers: - settings = settings_utils.create_router_settings( + settings = settings_utils.create_router_config( neutron, routers) creator = OpenStackRouter(self._os_creds, settings) out.append(creator) @@ -292,7 +292,7 @@ class OpenStackHeatStack(OpenStackCloudObject, object): glance = glance_utils.glance_client(self._os_creds) for stack_server in stack_servers: - vm_inst_settings = settings_utils.create_vm_inst_settings( + vm_inst_settings = settings_utils.create_vm_inst_config( nova, neutron, stack_server) image_settings = settings_utils.determine_image_config( glance, stack_server, self.image_settings) @@ -375,7 +375,7 @@ class OpenStackHeatStack(OpenStackCloudObject, object): self.__heat_cli, nova, self.__stack) for keypair in keypairs: - settings = settings_utils.create_keypair_settings( + settings = settings_utils.create_keypair_config( self.__heat_cli, self.__stack, keypair, outputs_pk_key) creator = OpenStackKeypair(self._os_creds, settings) out.append(creator) diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py index f806100..be83879 100644 --- a/snaps/openstack/tests/create_instance_tests.py +++ b/snaps/openstack/tests/create_instance_tests.py @@ -29,13 +29,15 @@ from snaps.config.image import ImageConfig from snaps.config.keypair import KeypairConfig from snaps.config.network import PortConfig, NetworkConfig, SubnetConfig from snaps.config.router import RouterConfig +from snaps.config.vm_inst import ( + VmInstanceConfig, FloatingIpConfig, VmInstanceConfigError, + FloatingIpConfigError) from snaps.config.volume import VolumeConfig from snaps.openstack import create_network, create_router from snaps.openstack.create_flavor import OpenStackFlavor from snaps.openstack.create_image import OpenStackImage from snaps.openstack.create_instance import ( - VmInstanceSettings, OpenStackVmInstance, FloatingIpSettings, - VmInstanceSettingsError, FloatingIpSettingsError) + VmInstanceSettings, OpenStackVmInstance, FloatingIpSettings) from snaps.openstack.create_keypairs import OpenStackKeypair from snaps.openstack.create_network import OpenStackNetwork from snaps.openstack.create_router import OpenStackRouter @@ -61,27 +63,27 @@ class VmInstanceSettingsUnitTests(unittest.TestCase): """ def test_no_params(self): - with self.assertRaises(VmInstanceSettingsError): + with self.assertRaises(VmInstanceConfigError): VmInstanceSettings() def test_empty_config(self): - with self.assertRaises(VmInstanceSettingsError): + with self.assertRaises(VmInstanceConfigError): VmInstanceSettings(config=dict()) def test_name_only(self): - with self.assertRaises(VmInstanceSettingsError): + with self.assertRaises(VmInstanceConfigError): VmInstanceSettings(name='foo') def test_config_with_name_only(self): - with self.assertRaises(VmInstanceSettingsError): + with self.assertRaises(VmInstanceConfigError): VmInstanceSettings(config={'name': 'foo'}) def test_name_flavor_only(self): - with self.assertRaises(VmInstanceSettingsError): + with self.assertRaises(VmInstanceConfigError): VmInstanceSettings(name='foo', flavor='bar') def test_config_with_name_flavor_only(self): - with self.assertRaises(VmInstanceSettingsError): + with self.assertRaises(VmInstanceConfigError): VmInstanceSettings(config={'name': 'foo', 'flavor': 'bar'}) def test_name_flavor_port_only(self): @@ -190,35 +192,35 @@ class FloatingIpSettingsUnitTests(unittest.TestCase): """ def test_no_params(self): - with self.assertRaises(FloatingIpSettingsError): + with self.assertRaises(FloatingIpConfigError): FloatingIpSettings() def test_empty_config(self): - with self.assertRaises(FloatingIpSettingsError): + with self.assertRaises(FloatingIpConfigError): FloatingIpSettings(**dict()) def test_name_only(self): - with self.assertRaises(FloatingIpSettingsError): + with self.assertRaises(FloatingIpConfigError): FloatingIpSettings(name='foo') def test_config_with_name_only(self): - with self.assertRaises(FloatingIpSettingsError): + with self.assertRaises(FloatingIpConfigError): FloatingIpSettings(**{'name': 'foo'}) def test_name_port_only(self): - with self.assertRaises(FloatingIpSettingsError): + with self.assertRaises(FloatingIpConfigError): FloatingIpSettings(name='foo', port_name='bar') def test_config_with_name_port_only(self): - with self.assertRaises(FloatingIpSettingsError): + with self.assertRaises(FloatingIpConfigError): FloatingIpSettings(**{'name': 'foo', 'port_name': 'bar'}) def test_name_router_only(self): - with self.assertRaises(FloatingIpSettingsError): + with self.assertRaises(FloatingIpConfigError): FloatingIpSettings(name='foo', router_name='bar') def test_config_with_name_router_only(self): - with self.assertRaises(FloatingIpSettingsError): + with self.assertRaises(FloatingIpConfigError): FloatingIpSettings(**{'name': 'foo', 'router_name': 'bar'}) def test_name_port_router_name_only(self): @@ -376,7 +378,7 @@ class SimpleHealthCheck(OSIntegrationTestCase): Tests the creation of an OpenStack instance with a single port and ensures that it's assigned IP address is the actual. """ - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -492,7 +494,7 @@ class CreateInstanceSimpleTests(OSIntegrationTestCase): Tests the creation of an OpenStack instance with a single port with a static IP without a Floating IP. """ - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -674,11 +676,11 @@ class CreateInstanceSingleNetworkTests(OSIntegrationTestCase): ip_addrs=[ {'subnet_name': sub_settings[0].name, 'ip': ip_1}]) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings], - floating_ip_settings=[FloatingIpSettings( + floating_ip_settings=[FloatingIpConfig( name=self.floating_ip_name, port_name=self.port_1_name, router_name=self.pub_net_config.router_settings.name)]) @@ -702,12 +704,12 @@ class CreateInstanceSingleNetworkTests(OSIntegrationTestCase): name=self.port_1_name, network_name=self.pub_net_config.network_settings.name) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings], security_group_names=[self.sec_grp_creator.sec_grp_settings.name], - floating_ip_settings=[FloatingIpSettings( + floating_ip_settings=[FloatingIpConfig( name=self.floating_ip_name, port_name=self.port_1_name, router_name=self.pub_net_config.router_settings.name)]) @@ -737,12 +739,12 @@ class CreateInstanceSingleNetworkTests(OSIntegrationTestCase): name=self.port_1_name, network_name=self.pub_net_config.network_settings.name) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings], security_group_names=[self.sec_grp_creator.sec_grp_settings.name], - floating_ip_settings=[FloatingIpSettings( + floating_ip_settings=[FloatingIpConfig( name=self.floating_ip_name, port_name=self.port_1_name, router_name=self.pub_net_config.router_settings.name)]) @@ -774,12 +776,12 @@ class CreateInstanceSingleNetworkTests(OSIntegrationTestCase): name=self.port_1_name, network_name=self.pub_net_config.network_settings.name) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings], security_group_names=[self.sec_grp_creator.sec_grp_settings.name], - floating_ip_settings=[FloatingIpSettings( + floating_ip_settings=[FloatingIpConfig( name=self.floating_ip_name, port_name=self.port_1_name, router_name=self.pub_net_config.router_settings.name)]) @@ -967,12 +969,12 @@ class CreateInstanceIPv6NetworkTests(OSIntegrationTestCase): port_settings = PortConfig( name=self.port1_name, network_name=network_settings.name) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings], security_group_names=[self.sec_grp_creator.sec_grp_settings.name], - floating_ip_settings=[FloatingIpSettings( + floating_ip_settings=[FloatingIpConfig( name='fip1', port_name=self.port1_name, router_name=router_settings.name)]) @@ -1015,12 +1017,12 @@ class CreateInstanceIPv6NetworkTests(OSIntegrationTestCase): port_settings = PortConfig( name=self.port1_name, network_name=network_settings.name) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings], security_group_names=[self.sec_grp_creator.sec_grp_settings.name], - floating_ip_settings=[FloatingIpSettings( + floating_ip_settings=[FloatingIpConfig( name='fip1', port_name=self.port1_name, router_name=router_settings.name)]) @@ -1135,7 +1137,7 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase): network_name=self.net_config.network_settings.name, ip_addrs=[{'subnet_name': sub_settings[0].name, 'ip': ip}]) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) @@ -1162,7 +1164,7 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase): network_name=self.net_config.network_settings.name, ip_addrs=[{'subnet_name': sub_settings[0].name, 'ip': ip}]) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) @@ -1185,7 +1187,7 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase): network_name=self.net_config.network_settings.name, mac_address=mac_addr) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) @@ -1209,7 +1211,7 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase): network_name=self.net_config.network_settings.name, mac_address='foo') - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) @@ -1235,7 +1237,7 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase): mac_address=mac_addr, ip_addrs=[{'subnet_name': sub_settings[0].name, 'ip': ip}]) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) @@ -1265,7 +1267,7 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase): network_name=self.net_config.network_settings.name, allowed_address_pairs=[pair]) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) @@ -1297,7 +1299,7 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase): network_name=self.net_config.network_settings.name, allowed_address_pairs=[pair]) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) @@ -1323,7 +1325,7 @@ class CreateInstancePortManipulationTests(OSIntegrationTestCase): network_name=self.net_config.network_settings.name, allowed_address_pairs=[pair]) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) @@ -1439,7 +1441,7 @@ class CreateInstanceOnComputeHost(OSIntegrationTestCase): name=self.port_base_name + '-' + str(ctr), network_name=self.priv_net_config.network_settings.name) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=inst_name, flavor=self.flavor_creator.flavor_settings.name, availability_zone=zone, @@ -1653,12 +1655,12 @@ class CreateInstancePubPrivNetTests(OSIntegrationTestCase): ctr += 1 # Create instance - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=ports_settings, security_group_names=[self.sec_grp_creator.sec_grp_settings.name], - floating_ip_settings=[FloatingIpSettings( + floating_ip_settings=[FloatingIpConfig( name=self.floating_ip_name, port_name=self.port_1_name, router_name=self.pub_net_config.router_settings.name)]) @@ -1796,7 +1798,7 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase): Tests the addition of a security group created after the instance. """ # Create instance - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -1830,7 +1832,7 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase): Tests the addition of a security group that no longer exists. """ # Create instance - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -1874,7 +1876,7 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase): self.sec_grp_creators.append(sec_grp_creator) # Create instance - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, security_group_names=[sec_grp_settings.name], @@ -1910,7 +1912,7 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase): self.sec_grp_creators.append(sec_grp_creator) # Create instance - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -1945,7 +1947,7 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase): self.sec_grp_creators.append(sec_grp_creator) # Create instance - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, security_group_names=[sec_grp_settings.name], @@ -2125,7 +2127,7 @@ class CreateInstanceFromThreePartImage(OSIntegrationTestCase): """ Tests the creation of an OpenStack instance from a 3-part image. """ - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -2260,7 +2262,7 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): self.image_creator = OpenStackImage(self.os_creds, os_image_settings) self.image_creator.create() - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -2296,7 +2298,7 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): self.image_creator = OpenStackImage(self.os_creds, os_image_settings) self.image_creator.create() - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -2328,7 +2330,7 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): self.assertEqual(self.image_creator.get_image().id, test_image_creator.get_image().id) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -2363,7 +2365,7 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): test_image = OpenStackImage(self.os_creds, test_image_settings) test_image.create() - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -2443,7 +2445,7 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): self.image_creator = OpenStackImage(self.os_creds, os_image_settings) self.image_creator.create() - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -2513,7 +2515,7 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): self.assertIsNotNone(self.image_creator.get_kernel_image()) self.assertIsNotNone(self.image_creator.get_ramdisk_image()) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -2583,7 +2585,7 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): self.assertIsNotNone(self.image_creator.get_kernel_image()) self.assertIsNotNone(self.image_creator.get_ramdisk_image()) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -2623,7 +2625,7 @@ class CreateInstanceMockOfflineTests(OSComponentTestCase): self.assertEqual(self.image_creator.get_image().id, test_image_creator.get_image().id) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings]) @@ -2819,7 +2821,7 @@ class CreateInstanceTwoNetTests(OSIntegrationTestCase): ctr += 1 # Configure instances - instance1_settings = VmInstanceSettings( + instance1_settings = VmInstanceConfig( name=self.vm_inst1_name, flavor=self.flavor_creator.flavor_settings.name, userdata=_get_ping_userdata(self.ip2), @@ -2831,7 +2833,7 @@ class CreateInstanceTwoNetTests(OSIntegrationTestCase): 'ip': self.ip1 }], network_name=self.network_creators[0].network_settings.name)]) - instance2_settings = VmInstanceSettings( + instance2_settings = VmInstanceConfig( name=self.vm_inst2_name, flavor=self.flavor_creator.flavor_settings.name, userdata=_get_ping_userdata(self.ip1), @@ -2992,7 +2994,7 @@ class CreateInstanceVolumeTests(OSIntegrationTestCase): """ Tests the creation of an OpenStack instance with a single volume. """ - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings], @@ -3015,7 +3017,7 @@ class CreateInstanceVolumeTests(OSIntegrationTestCase): """ Tests the creation of an OpenStack instance with a single volume. """ - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings], diff --git a/snaps/openstack/tests/create_router_tests.py b/snaps/openstack/tests/create_router_tests.py index 5c34037..09471a3 100644 --- a/snaps/openstack/tests/create_router_tests.py +++ b/snaps/openstack/tests/create_router_tests.py @@ -380,7 +380,7 @@ class CreateRouterSuccessTests(OSIntegrationTestCase): responsible for creating the router :return: the derived RouterConfig object """ - derived_settings = settings_utils.create_router_settings( + derived_settings = settings_utils.create_router_config( self.neutron, router) self.assertIsNotNone(derived_settings) self.assertEqual( diff --git a/snaps/openstack/utils/deploy_utils.py b/snaps/openstack/utils/deploy_utils.py index 8c8431d..8cd6dd3 100644 --- a/snaps/openstack/utils/deploy_utils.py +++ b/snaps/openstack/utils/deploy_utils.py @@ -121,7 +121,7 @@ def create_vm_instance(os_creds, instance_settings, image_settings, """ Creates a VM instance :param os_creds: The OpenStack credentials - :param instance_settings: Instance of VmInstanceSettings + :param instance_settings: Instance of VmInstanceConfig :param image_settings: The object containing image settings :param keypair_creator: The object responsible for creating the keypair associated with this VM instance. (optional) diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py index b974f2e..ffc9240 100644 --- a/snaps/openstack/utils/nova_utils.py +++ b/snaps/openstack/utils/nova_utils.py @@ -125,7 +125,7 @@ def get_server(nova, vm_inst_settings=None, server_name=None): """ Returns a VmInst object for the first server instance found. :param nova: the Nova client - :param vm_inst_settings: the VmInstanceSettings object from which to build + :param vm_inst_settings: the VmInstanceConfig object from which to build the query if not None :param server_name: the server with this name to return if vm_inst_settings is not None @@ -146,7 +146,7 @@ def get_server_connection(nova, vm_inst_settings=None, server_name=None): """ Returns a VmInst object for the first server instance found. :param nova: the Nova client - :param vm_inst_settings: the VmInstanceSettings object from which to build + :param vm_inst_settings: the VmInstanceConfig object from which to build the query if not None :param server_name: the server with this name to return if vm_inst_settings is not None diff --git a/snaps/openstack/utils/settings_utils.py b/snaps/openstack/utils/settings_utils.py index ab26d3d..5433570 100644 --- a/snaps/openstack/utils/settings_utils.py +++ b/snaps/openstack/utils/settings_utils.py @@ -19,11 +19,10 @@ from snaps.config.flavor import FlavorConfig from snaps.config.keypair import KeypairConfig from snaps.config.network import SubnetConfig, PortConfig, NetworkConfig from snaps.config.router import RouterConfig +from snaps.config.vm_inst import VmInstanceConfig, FloatingIpConfig from snaps.config.volume import VolumeConfig from snaps.config.volume_type import ( ControlLocation, VolumeTypeEncryptionConfig, VolumeTypeConfig) -from snaps.openstack.create_instance import ( - VmInstanceSettings, FloatingIpSettings) from snaps.openstack.create_security_group import ( SecurityGroupSettings, SecurityGroupRuleSettings) from snaps.openstack.utils import ( @@ -93,7 +92,7 @@ def create_subnet_config(neutron, network): return out -def create_router_settings(neutron, router): +def create_router_config(neutron, router): """ Returns a RouterConfig object :param neutron: the neutron client @@ -202,7 +201,7 @@ def create_flavor_config(flavor): is_public=flavor.is_public) -def create_keypair_settings(heat_cli, stack, keypair, pk_output_key): +def create_keypair_config(heat_cli, stack, keypair, pk_output_key): """ Instantiates a KeypairConfig object from a Keypair domain objects :param heat_cli: the heat client @@ -228,7 +227,7 @@ def create_keypair_settings(heat_cli, stack, keypair, pk_output_key): return KeypairConfig(name=keypair.name) -def create_vm_inst_settings(nova, neutron, server): +def create_vm_inst_config(nova, neutron, server): """ Returns a NetworkConfig object :param nova: the nova client @@ -252,10 +251,10 @@ def create_vm_inst_settings(nova, neutron, server): kwargs['port_settings'] = __create_port_config( neutron, net_tuples) kwargs['security_group_names'] = server.sec_grp_names - kwargs['floating_ip_settings'] = __create_floatingip_settings( + kwargs['floating_ip_settings'] = __create_floatingip_config( neutron, kwargs['port_settings']) - return VmInstanceSettings(**kwargs) + return VmInstanceConfig(**kwargs) def __create_port_config(neutron, networks): @@ -292,13 +291,13 @@ def __create_port_config(neutron, networks): return out -def __create_floatingip_settings(neutron, port_settings): +def __create_floatingip_config(neutron, port_settings): """ - Returns a list of FloatingIPSettings objects as they pertain to an + Returns a list of FloatingIpConfig objects as they pertain to an existing deployed server instance :param neutron: the neutron client :param port_settings: list of SNAPS-OO PortConfig objects - :return: a list of FloatingIPSettings objects or an empty list if no + :return: a list of FloatingIpConfig objects or an empty list if no floating IPs have been created """ base_fip_name = 'fip-' @@ -340,7 +339,7 @@ def __create_floatingip_settings(neutron, port_settings): if subnet: kwargs['subnet_name'] = subnet.name - out.append(FloatingIpSettings(**kwargs)) + out.append(FloatingIpConfig(**kwargs)) fip_ctr += 1 diff --git a/snaps/openstack/utils/tests/heat_utils_tests.py b/snaps/openstack/utils/tests/heat_utils_tests.py index 2f1e7cc..298dc31 100644 --- a/snaps/openstack/utils/tests/heat_utils_tests.py +++ b/snaps/openstack/utils/tests/heat_utils_tests.py @@ -313,7 +313,7 @@ class HeatUtilsCreateComplexStackTests(OSComponentTestCase): servers = heat_utils.get_stack_servers( self.heat_client, nova, self.stack) for server in servers: - vm_settings = settings_utils.create_vm_inst_settings( + vm_settings = settings_utils.create_vm_inst_config( nova, neutron, server) img_settings = settings_utils.determine_image_config( glance, server, diff --git a/snaps/openstack/utils/tests/nova_utils_tests.py b/snaps/openstack/utils/tests/nova_utils_tests.py index 6d4bc3c..c4bc9cb 100644 --- a/snaps/openstack/utils/tests/nova_utils_tests.py +++ b/snaps/openstack/utils/tests/nova_utils_tests.py @@ -21,12 +21,12 @@ import os from snaps import file_utils from snaps.config.flavor import FlavorConfig from snaps.config.network import PortConfig +from snaps.config.vm_inst import VmInstanceConfig from snaps.config.volume import VolumeConfig from snaps.openstack import create_instance from snaps.openstack.create_flavor import OpenStackFlavor from snaps.openstack.create_image import OpenStackImage -from snaps.openstack.create_instance import ( - VmInstanceSettings, OpenStackVmInstance) +from snaps.openstack.create_instance import OpenStackVmInstance from snaps.openstack.create_network import OpenStackNetwork from snaps.openstack.create_volume import OpenStackVolume from snaps.openstack.tests import openstack_tests @@ -265,7 +265,7 @@ class NovaUtilsInstanceTests(OSComponentTestCase): self.port = neutron_utils.create_port( self.neutron, self.os_creds, port_settings) - self.instance_settings = VmInstanceSettings( + self.instance_settings = VmInstanceConfig( name=guid + '-vm_inst', flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) @@ -385,7 +385,7 @@ class NovaUtilsInstanceVolumeTests(OSComponentTestCase): port_settings = PortConfig( name=guid + '-port', network_name=network_settings.name) - instance_settings = VmInstanceSettings( + instance_settings = VmInstanceConfig( name=guid + '-vm_inst', flavor=self.flavor_creator.flavor_settings.name, port_settings=[port_settings]) diff --git a/snaps/openstack/utils/tests/settings_utils_tests.py b/snaps/openstack/utils/tests/settings_utils_tests.py index b34e68b..d0390e2 100644 --- a/snaps/openstack/utils/tests/settings_utils_tests.py +++ b/snaps/openstack/utils/tests/settings_utils_tests.py @@ -22,6 +22,7 @@ from snaps.config.network import SubnetConfig, NetworkConfig, PortConfig from snaps.config.flavor import FlavorConfig from snaps.config.keypair import KeypairConfig from snaps.config.qos import Consumer +from snaps.config.vm_inst import VmInstanceConfig, FloatingIpConfig from snaps.domain.flavor import Flavor from snaps.domain.volume import ( Volume, VolumeType, VolumeTypeEncryption, QoSSpec) @@ -144,7 +145,7 @@ class SettingsUtilsNetworkingTests(OSComponentTestCase): class SettingsUtilsVmInstTests(OSComponentTestCase): """ - Tests the ability to reverse engineer VmInstanceSettings objects from + Tests the ability to reverse engineer VmInstanceConfig objects from existing VMs/servers deployed to OpenStack """ @@ -238,11 +239,11 @@ class SettingsUtilsVmInstTests(OSComponentTestCase): name=self.port_1_name, network_name=self.pub_net_config.network_settings.name)) - instance_settings = create_instance.VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=ports_settings, - floating_ip_settings=[create_instance.FloatingIpSettings( + floating_ip_settings=[FloatingIpConfig( name=self.floating_ip_name, port_name=self.port_1_name, router_name=self.pub_net_config.router_settings.name)]) @@ -317,16 +318,16 @@ class SettingsUtilsVmInstTests(OSComponentTestCase): # super(self.__class__, self).__clean__() - def test_derive_vm_inst_settings(self): + def test_derive_vm_inst_config(self): """ - Validates the utility function settings_utils#create_vm_inst_settings - returns an acceptable VmInstanceSettings object + Validates the utility function settings_utils#create_vm_inst_config + returns an acceptable VmInstanceConfig object """ self.inst_creator.create(block=True) server = nova_utils.get_server( self.nova, vm_inst_settings=self.inst_creator.instance_settings) - derived_vm_settings = settings_utils.create_vm_inst_settings( + derived_vm_settings = settings_utils.create_vm_inst_config( self.nova, self.neutron, server) self.assertIsNotNone(derived_vm_settings) self.assertIsNotNone(derived_vm_settings.port_settings) diff --git a/snaps/provisioning/tests/ansible_utils_tests.py b/snaps/provisioning/tests/ansible_utils_tests.py index b78249e..0e55f1f 100644 --- a/snaps/provisioning/tests/ansible_utils_tests.py +++ b/snaps/provisioning/tests/ansible_utils_tests.py @@ -22,6 +22,7 @@ from scp import SCPClient from snaps.config.flavor import FlavorConfig from snaps.config.keypair import KeypairConfig from snaps.config.network import PortConfig +from snaps.config.vm_inst import VmInstanceConfig, FloatingIpConfig from snaps.openstack import create_flavor from snaps.openstack import create_image @@ -141,11 +142,11 @@ class AnsibleProvisioningTests(OSIntegrationTestCase): name=self.port_1_name, network_name=self.pub_net_config.network_settings.name)) - instance_settings = create_instance.VmInstanceSettings( + instance_settings = VmInstanceConfig( name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=ports_settings, - floating_ip_settings=[create_instance.FloatingIpSettings( + floating_ip_settings=[FloatingIpConfig( name=self.floating_ip_name, port_name=self.port_1_name, router_name=self.pub_net_config.router_settings.name)]) diff --git a/snaps/test_suite_builder.py b/snaps/test_suite_builder.py index 2d2427f..542b8ff 100644 --- a/snaps/test_suite_builder.py +++ b/snaps/test_suite_builder.py @@ -18,6 +18,8 @@ import unittest from snaps.config.tests.network_tests import ( NetworkConfigUnitTests, SubnetConfigUnitTests, PortConfigUnitTests) +from snaps.config.tests.vm_inst_tests import VmInstanceConfigUnitTests, \ + FloatingIpConfigUnitTests from snaps.config.tests.volume_tests import VolumeConfigUnitTests from snaps.config.tests.volume_type_tests import VolumeTypeConfigUnitTests from snaps.config.tests.qos_tests import QoSConfigUnitTests @@ -208,8 +210,12 @@ def add_unit_tests(suite): RouterDomainObjectTests)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase( InterfaceRouterDomainObjectTests)) + suite.addTest(unittest.TestLoader().loadTestsFromTestCase( + FloatingIpConfigUnitTests)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase( FloatingIpSettingsUnitTests)) + suite.addTest(unittest.TestLoader().loadTestsFromTestCase( + VmInstanceConfigUnitTests)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase( VmInstanceSettingsUnitTests)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase( -- cgit 1.2.3-korg