- Volume - snaps.openstack.create\_volume.OpenStackVolume
- - snaps.openstack.create\_volume.VolumeSettings
+ - snaps.config.volume.VolumeConfig
- name - the volume type's name (required)
- description - the volume type's description (optional)
.. code:: python
- from snaps.openstack.create\_volume import VolumeSettings, OpenStackVolume
+ from snaps.config.volume import VolumeConfig
+ from snaps.openstack.create\_volume import OpenStackVolume
- vol_settings = VolumeSettings(name='stack-name')
+ vol_settings = VolumeConfig(name='stack-name')
vol_creator = OpenStackVolume(os_creds, vol_settings)
vol_creator.create()
Ensures that all required members are included when constructing a
Output domain object (for Heat)
+VolumeConfigUnitTests
+---------------------
+
+Ensures that all required members are included when constructing a
+VolumeConfig object
+
VolumeSettingsUnitTests
-----------------------
Ensures that all required members are included when constructing a
-VolumeSettings object
+deprecated VolumeSettings object
VolumeDomainObjectTests
-----------------------
SettingsUtilsUnitTests
----------------------
-Ensures that the settings_utils.py#create_volume_settings() function properly
+Ensures that the settings_utils.py#create_volume_config() function properly
maps a snaps.domain.Volume object correctly to a
-snaps.openstack.create_volume.VolumeSettings object as well as a
+snaps.config.volume.VolumeConfig object as well as a
snaps.domain.VolumeType object to a
-snaps.openstack.create_volume.VolumeSettings object
+snaps.config.volume.VolumeConfig object
Ensures that the settings_utils.py#create_flavor_config() function properly
import yaml
from snaps import file_utils
-from snaps.config.volume_type import VolumeTypeConfig
from snaps.config.flavor import FlavorConfig
from snaps.config.image import ImageConfig
from snaps.config.keypair import KeypairConfig
from snaps.config.qos import QoSConfig
from snaps.config.router import RouterConfig
from snaps.config.user import UserConfig
+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_security_group import (
OpenStackSecurityGroup, SecurityGroupSettings)
from snaps.openstack.create_user import OpenStackUser
-from snaps.openstack.create_volume import OpenStackVolume, VolumeSettings
+from snaps.openstack.create_volume import OpenStackVolume
from snaps.openstack.create_volume_type import OpenStackVolumeType
from snaps.openstack.os_credentials import OSCreds, ProxySettings
from snaps.openstack.utils import deploy_utils
# Create volume types
vol_dict = __create_instances(
- os_creds_dict, OpenStackVolume, VolumeSettings,
+ os_creds_dict, OpenStackVolume, VolumeConfig,
os_config.get('volumes'), 'volume', clean, users_dict)
creators.append(vol_dict)
--- /dev/null
+# 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.volume import VolumeConfigError, VolumeConfig
+
+
+class VolumeConfigUnitTests(unittest.TestCase):
+ """
+ Tests the construction of the VolumeConfig class
+ """
+
+ def test_no_params(self):
+ with self.assertRaises(VolumeConfigError):
+ VolumeConfig()
+
+ def test_empty_config(self):
+ with self.assertRaises(VolumeConfigError):
+ VolumeConfig(**dict())
+
+ def test_name_only(self):
+ settings = VolumeConfig(name='foo')
+ self.assertEqual('foo', settings.name)
+ self.assertIsNone(settings.description)
+ self.assertEquals(1, settings.size)
+ self.assertIsNone(settings.image_name)
+ self.assertIsNone(settings.type_name)
+ self.assertIsNone(settings.availability_zone)
+ self.assertFalse(settings.multi_attach)
+
+ def test_config_with_name_only(self):
+ settings = VolumeConfig(**{'name': 'foo'})
+ self.assertEqual('foo', settings.name)
+ self.assertIsNone(settings.description)
+ self.assertEquals(1, settings.size)
+ self.assertIsNone(settings.image_name)
+ self.assertIsNone(settings.type_name)
+ self.assertIsNone(settings.availability_zone)
+ self.assertFalse(settings.multi_attach)
+
+ def test_all_strings(self):
+ settings = VolumeConfig(
+ name='foo', description='desc', size='2', image_name='image',
+ type_name='type', availability_zone='zone1', multi_attach='true')
+
+ self.assertEqual('foo', settings.name)
+ self.assertEqual('desc', settings.description)
+ self.assertEqual(2, settings.size)
+ self.assertEqual('image', settings.image_name)
+ self.assertEqual('type', settings.type_name)
+ self.assertEqual('zone1', settings.availability_zone)
+ self.assertTrue(settings.multi_attach)
+
+ def test_all_correct_type(self):
+ settings = VolumeConfig(
+ name='foo', description='desc', size=2, image_name='image',
+ type_name='bar', availability_zone='zone1', multi_attach=True)
+
+ self.assertEqual('foo', settings.name)
+ self.assertEqual('desc', settings.description)
+ self.assertEqual(2, settings.size)
+ self.assertEqual('image', settings.image_name)
+ self.assertEqual('bar', settings.type_name)
+ self.assertEqual('zone1', settings.availability_zone)
+ self.assertTrue(settings.multi_attach)
+
+ def test_config_all(self):
+ settings = VolumeConfig(
+ **{'name': 'foo', 'description': 'desc', 'size': '2',
+ 'image_name': 'foo', 'type_name': 'bar',
+ 'availability_zone': 'zone1', 'multi_attach': 'true'})
+
+ self.assertEqual('foo', settings.name)
+ self.assertEqual('desc', settings.description)
+ self.assertEqual(2, settings.size)
+ self.assertEqual('foo', settings.image_name)
+ self.assertEqual('bar', settings.type_name)
+ self.assertEqual('zone1', settings.availability_zone)
+ self.assertTrue(settings.multi_attach)
--- /dev/null
+# 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.
+
+
+class VolumeConfig(object):
+ def __init__(self, **kwargs):
+ """
+ Constructor
+ :param name: the volume's name (required)
+ :param description: the volume's name (optional)
+ :param size: the volume's size in GB (default 1)
+ :param image_name: when a glance image is used for the image source
+ (optional)
+ :param type_name: the associated volume's type name (optional)
+ :param availability_zone: the name of the compute server on which to
+ deploy the volume (optional)
+ :param multi_attach: when true, volume can be attached to more than one
+ server (default False)
+ """
+
+ self.name = kwargs.get('name')
+ self.description = kwargs.get('description')
+ self.size = int(kwargs.get('size', 1))
+ self.image_name = kwargs.get('image_name')
+ self.type_name = kwargs.get('type_name')
+ self.availability_zone = kwargs.get('availability_zone')
+
+ if kwargs.get('availability_zone'):
+ self.multi_attach = bool(kwargs.get('availability_zone'))
+ else:
+ self.multi_attach = False
+
+ if not self.name:
+ raise VolumeConfigError("The attribute name is required")
+
+
+class VolumeConfigError(Exception):
+ """
+ Exception to be thrown when an volume settings are incorrect
+ """
+
+ def __init__(self, message):
+ Exception.__init__(self, message)
self.__heat_cli, cinder, self.__stack)
for volume in volumes:
- settings = settings_utils.create_volume_settings(volume)
+ settings = settings_utils.create_volume_config(volume)
creator = OpenStackVolume(self._os_creds, settings)
out.append(creator)
from cinderclient.exceptions import NotFound
+from snaps.config.volume import VolumeConfig
from snaps.openstack.openstack_creator import OpenStackVolumeObject
from snaps.openstack.utils import cinder_utils
return status == expected_status_code
-class VolumeSettings:
- def __init__(self, **kwargs):
- """
- Constructor
- :param name: the volume's name (required)
- :param description: the volume's name (optional)
- :param size: the volume's size in GB (default 1)
- :param image_name: when a glance image is used for the image source
- (optional)
- :param type_name: the associated volume's type name (optional)
- :param availability_zone: the name of the compute server on which to
- deploy the volume (optional)
- :param multi_attach: when true, volume can be attached to more than one
- server (default False)
- """
-
- self.name = kwargs.get('name')
- self.description = kwargs.get('description')
- self.size = int(kwargs.get('size', 1))
- self.image_name = kwargs.get('image_name')
- self.type_name = kwargs.get('type_name')
- self.availability_zone = kwargs.get('availability_zone')
-
- if kwargs.get('availability_zone'):
- self.multi_attach = bool(kwargs.get('availability_zone'))
- else:
- self.multi_attach = False
-
- if not self.name:
- raise VolumeSettingsError("The attribute name is required")
-
-
-class VolumeSettingsError(Exception):
+class VolumeSettings(VolumeConfig):
"""
- Exception to be thrown when an volume settings are incorrect
+ Class to hold the configuration settings required for creating OpenStack
+ Volume Type Encryption objects
+ deprecated
"""
- def __init__(self, message):
- Exception.__init__(self, message)
+ def __init__(self, **kwargs):
+ from warnings import warn
+ warn('Use snaps.config.volume.VolumeConfig instead',
+ DeprecationWarning)
+ super(self.__class__, self).__init__(**kwargs)
class VolumeCreationError(Exception):
from novaclient.exceptions import BadRequest
from snaps import file_utils
+from snaps.config.volume import VolumeConfig
from snaps.config.router import RouterConfig
from snaps.config.keypair import KeypairConfig
from snaps.openstack import create_network, create_router
from snaps.openstack.create_security_group import (
SecurityGroupSettings, OpenStackSecurityGroup, SecurityGroupRuleSettings,
Direction, Protocol)
-from snaps.openstack.create_volume import OpenStackVolume, VolumeSettings
+from snaps.openstack.create_volume import OpenStackVolume
from snaps.openstack.tests import openstack_tests, validation_utils
from snaps.openstack.tests.os_source_file_test import (
OSIntegrationTestCase, OSComponentTestCase)
net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet',
router_name=guid + '-pub-router', external_net=self.ext_net_name)
- self.volume_settings1 = VolumeSettings(
+ self.volume_settings1 = VolumeConfig(
name=self.__class__.__name__ + '-' + str(guid) + '-1')
- self.volume_settings2 = VolumeSettings(
+ self.volume_settings2 = VolumeConfig(
name=self.__class__.__name__ + '-' + str(guid) + '-2')
# Initialize for tearDown()
# limitations under the License.
from cinderclient.exceptions import NotFound, BadRequest
+from snaps.config.volume import VolumeConfig, VolumeConfigError
from snaps.config.volume_type import VolumeTypeConfig
from snaps.openstack.create_image import OpenStackImage
from snaps.openstack.create_volume_type import OpenStackVolumeType
import uuid
from snaps.openstack.create_volume import (
- VolumeSettings, VolumeSettingsError, OpenStackVolume)
+ VolumeSettings, OpenStackVolume)
from snaps.openstack.tests.os_source_file_test import OSIntegrationTestCase
from snaps.openstack.utils import cinder_utils
"""
def test_no_params(self):
- with self.assertRaises(VolumeSettingsError):
+ with self.assertRaises(VolumeConfigError):
VolumeSettings()
def test_empty_config(self):
- with self.assertRaises(VolumeSettingsError):
+ with self.assertRaises(VolumeConfigError):
VolumeSettings(**dict())
def test_name_only(self):
super(self.__class__, self).__start__()
guid = uuid.uuid4()
- self.volume_settings = VolumeSettings(
+ self.volume_settings = VolumeConfig(
name=self.__class__.__name__ + '-' + str(guid))
self.cinder = cinder_utils.cinder_client(self.os_creds)
Tests the creation of an OpenStack volume with a negative size to
ensure it raises a BadRequest exception.
"""
- volume_settings = VolumeSettings(
+ volume_settings = VolumeConfig(
name=self.__class__.__name__ + '-' + str(self.guid), size=-1)
# Create Volume
Tests the creation of an OpenStack volume with a type that does not
exist to ensure it raises a NotFound exception.
"""
- volume_settings = VolumeSettings(
+ volume_settings = VolumeConfig(
name=self.__class__.__name__ + '-' + str(self.guid),
type_name='foo')
Tests the creation of an OpenStack volume with an image that does not
exist to ensure it raises a BadRequest exception.
"""
- volume_settings = VolumeSettings(
+ volume_settings = VolumeConfig(
name=self.__class__.__name__ + '-' + str(self.guid),
image_name='foo')
Tests the creation of an OpenStack volume with an availability zone
that does not exist to ensure it raises a BadRequest exception.
"""
- volume_settings = VolumeSettings(
+ volume_settings = VolumeConfig(
name=self.__class__.__name__ + '-' + str(self.guid),
availability_zone='foo')
"""
self.volume_creator = OpenStackVolume(
self.os_creds,
- VolumeSettings(name=self.volume_name, type_name='foo'))
+ VolumeConfig(name=self.volume_name, type_name='foo'))
with self.assertRaises(NotFound):
self.volume_creator.create()
"""
self.volume_creator = OpenStackVolume(
self.os_creds,
- VolumeSettings(name=self.volume_name,
- type_name=self.volume_type_name))
+ VolumeConfig(
+ name=self.volume_name, type_name=self.volume_type_name))
created_volume = self.volume_creator.create(block=True)
self.assertIsNotNone(created_volume)
"""
self.volume_creator = OpenStackVolume(
self.os_creds,
- VolumeSettings(name=self.volume_name, image_name='foo'))
+ VolumeConfig(name=self.volume_name, image_name='foo'))
with self.assertRaises(BadRequest):
self.volume_creator.create(block=True)
"""
self.volume_creator = OpenStackVolume(
self.os_creds,
- VolumeSettings(name=self.volume_name, image_name=self.image_name))
+ VolumeConfig(name=self.volume_name, image_name=self.image_name))
created_volume = self.volume_creator.create(block=True)
self.assertIsNotNone(created_volume)
import uuid
from snaps import file_utils
-from snaps.config.volume_type import (
- ControlLocation, VolumeTypeEncryptionConfig, VolumeTypeConfig)
from snaps.config.flavor import FlavorConfig
from snaps.config.keypair import KeypairConfig
from snaps.config.router import RouterConfig
+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_network import (
PortSettings, SubnetSettings, NetworkSettings)
from snaps.openstack.create_security_group import (
SecurityGroupSettings, SecurityGroupRuleSettings)
-from snaps.openstack.create_volume import VolumeSettings
from snaps.openstack.utils import (
neutron_utils, nova_utils, heat_utils, glance_utils)
port_settings=filtered_settings)
-def create_volume_settings(volume):
+def create_volume_config(volume):
"""
Returns a VolumeSettings object
:param volume: a SNAPS-OO Volume object
"""
- return VolumeSettings(
+ return VolumeConfig(
name=volume.name, description=volume.description,
size=volume.size, type_name=volume.type,
availability_zone=volume.availability_zone,
import time
from cinderclient.exceptions import NotFound, BadRequest
+from snaps.config.volume import VolumeConfig
from snaps.config.volume_type import (
VolumeTypeConfig, ControlLocation, VolumeTypeEncryptionConfig)
from snaps.config.qos import Consumer, QoSConfig
from snaps.openstack import create_volume
-from snaps.openstack.create_volume import VolumeSettings
+from snaps.openstack.create_qos import Consumer
from snaps.openstack.tests import validation_utils
from snaps.openstack.tests.os_source_file_test import OSComponentTestCase
from snaps.openstack.utils import cinder_utils
"""
Tests the cinder_utils.create_volume()
"""
- volume_settings = VolumeSettings(name=self.volume_name)
+ volume_settings = VolumeConfig(name=self.volume_name)
self.volume = cinder_utils.create_volume(
self.cinder, volume_settings)
self.assertIsNotNone(self.volume)
"""
Tests the cinder_utils.create_volume()
"""
- volume_settings = VolumeSettings(name=self.volume_name)
+ volume_settings = VolumeConfig(name=self.volume_name)
self.volume = cinder_utils.create_volume(
self.cinder, volume_settings)
self.assertIsNotNone(self.volume)
import os
from snaps import file_utils
+from snaps.config.volume import VolumeConfig
from snaps.config.flavor import FlavorConfig
from snaps.openstack import create_instance
from snaps.openstack.create_flavor import OpenStackFlavor
from snaps.openstack.create_instance import (
VmInstanceSettings, OpenStackVmInstance)
from snaps.openstack.create_network import OpenStackNetwork, PortSettings
-from snaps.openstack.create_volume import OpenStackVolume, VolumeSettings
+from snaps.openstack.create_volume import OpenStackVolume
from snaps.openstack.tests import openstack_tests
from snaps.openstack.tests.os_source_file_test import OSComponentTestCase
from snaps.openstack.utils import (
self.flavor_creator.create()
# Create Volume
- volume_settings = VolumeSettings(
+ volume_settings = VolumeConfig(
name=self.__class__.__name__ + '-' + str(guid))
self.volume_creator = OpenStackVolume(
self.os_creds, volume_settings)
volume = Volume(
name='vol-name', volume_id='vol-id', description='desc', size=99,
vol_type='vol-type', availability_zone='zone1', multi_attach=True)
- settings = settings_utils.create_volume_settings(volume)
+ settings = settings_utils.create_volume_config(volume)
self.assertEqual(volume.name, settings.name)
self.assertEqual(volume.description, settings.description)
self.assertEqual(volume.size, settings.size)
import logging
import unittest
+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
from snaps.config.tests.stack_tests import StackConfigUnitTests
VolumeTypeConfigUnitTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
VolumeTypeSettingsUnitTests))
+ suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
+ VolumeConfigUnitTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
VolumeSettingsUnitTests))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(