diff options
author | 2017-10-18 11:52:51 -0600 | |
---|---|---|
committer | 2017-10-18 11:52:51 -0600 | |
commit | d5d282dd1ffab96e85332bea580689c3297a25f8 (patch) | |
tree | 08463781fc00cf65301d69faaf1325be8cb6fc96 /snaps/openstack/utils/tests/cinder_utils_tests.py | |
parent | 530153597deb5030c296358431d9549d13b7288b (diff) |
Second patch for volume support.
* Added support for volume types
* Created tests for volume types, QoS Spec, and encryption
JIRA: SNAPS-196
Change-Id: I9154fc20772191cecf4f2f9feb7e8d8634167a9c
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/utils/tests/cinder_utils_tests.py')
-rw-r--r-- | snaps/openstack/utils/tests/cinder_utils_tests.py | 320 |
1 files changed, 308 insertions, 12 deletions
diff --git a/snaps/openstack/utils/tests/cinder_utils_tests.py b/snaps/openstack/utils/tests/cinder_utils_tests.py index e6ad2a0..a45167e 100644 --- a/snaps/openstack/utils/tests/cinder_utils_tests.py +++ b/snaps/openstack/utils/tests/cinder_utils_tests.py @@ -15,9 +15,11 @@ import logging import uuid -from cinderclient.exceptions import NotFound +from cinderclient.exceptions import NotFound, BadRequest from snaps.openstack.create_qos import QoSSettings, Consumer +from snaps.openstack.create_volume_type import ( + VolumeTypeSettings, VolumeTypeEncryptionSettings, ControlLocation) from snaps.openstack.tests import validation_utils from snaps.openstack.tests.os_source_file_test import OSComponentTestCase from snaps.openstack.utils import cinder_utils @@ -86,15 +88,14 @@ class CinderUtilsQoSTests(OSComponentTestCase): """ qos_settings = QoSSettings(name=self.qos_name, specs=self.specs, consumer=Consumer.both) - self.qos = cinder_utils.create_qos( - self.cinder, qos_settings) + self.qos = cinder_utils.create_qos(self.cinder, qos_settings) self.assertIsNotNone(self.qos) qos1 = cinder_utils.get_qos(self.cinder, qos_settings=qos_settings) self.assertIsNotNone(qos1) validation_utils.objects_equivalent(self.qos, qos1) - qos2 = cinder_utils.get_qos(self.cinder, qos_name=qos_settings.name) + qos2 = cinder_utils.get_qos_by_id(self.cinder, qos1.id) self.assertIsNotNone(qos2) validation_utils.objects_equivalent(self.qos, qos2) @@ -104,15 +105,14 @@ class CinderUtilsQoSTests(OSComponentTestCase): """ qos_settings = QoSSettings(name=self.qos_name, specs=self.specs, consumer=Consumer.front_end) - self.qos = cinder_utils.create_qos( - self.cinder, qos_settings) + self.qos = cinder_utils.create_qos(self.cinder, qos_settings) self.assertIsNotNone(self.qos) qos1 = cinder_utils.get_qos(self.cinder, qos_settings=qos_settings) self.assertIsNotNone(qos1) validation_utils.objects_equivalent(self.qos, qos1) - qos2 = cinder_utils.get_qos(self.cinder, qos_name=qos_settings.name) + qos2 = cinder_utils.get_qos_by_id(self.cinder, qos1.id) self.assertIsNotNone(qos2) validation_utils.objects_equivalent(self.qos, qos2) @@ -122,15 +122,14 @@ class CinderUtilsQoSTests(OSComponentTestCase): """ qos_settings = QoSSettings(name=self.qos_name, specs=self.specs, consumer=Consumer.back_end) - self.qos = cinder_utils.create_qos( - self.cinder, qos_settings) + self.qos = cinder_utils.create_qos(self.cinder, qos_settings) self.assertIsNotNone(self.qos) qos1 = cinder_utils.get_qos(self.cinder, qos_settings=qos_settings) self.assertIsNotNone(qos1) validation_utils.objects_equivalent(self.qos, qos1) - qos2 = cinder_utils.get_qos(self.cinder, qos_name=qos_settings.name) + qos2 = cinder_utils.get_qos_by_id(self.cinder, qos1.id) self.assertIsNotNone(qos2) validation_utils.objects_equivalent(self.qos, qos2) @@ -139,8 +138,7 @@ class CinderUtilsQoSTests(OSComponentTestCase): Tests the cinder_utils.create_qos() """ qos_settings = QoSSettings(name=self.qos_name, consumer=Consumer.both) - self.qos = cinder_utils.create_qos( - self.cinder, qos_settings) + self.qos = cinder_utils.create_qos(self.cinder, qos_settings) self.assertIsNotNone(self.qos) self.assertEqual(self.qos_name, self.qos.name) @@ -152,3 +150,301 @@ class CinderUtilsQoSTests(OSComponentTestCase): cinder_utils.delete_qos(self.cinder, self.qos) self.assertIsNone(cinder_utils.get_qos( self.cinder, qos_settings=qos_settings)) + + +class CinderUtilsSimpleVolumeTypeTests(OSComponentTestCase): + """ + Tests the creation of a Volume Type without any external settings such as + QoS Specs or encryption + """ + + def setUp(self): + """ + Instantiates the CreateVolume object that is responsible for + downloading and creating an OS volume file within OpenStack + """ + guid = uuid.uuid4() + volume_type_name = self.__class__.__name__ + '-' + str(guid) + self.volume_type_settings = VolumeTypeSettings(name=volume_type_name) + self.volume_type = None + self.cinder = cinder_utils.cinder_client(self.os_creds) + + def tearDown(self): + """ + Cleans the remote OpenStack objects + """ + if self.volume_type: + try: + cinder_utils.delete_volume_type(self.cinder, self.volume_type) + except NotFound: + pass + + def test_create_simple_volume_type(self): + """ + Tests the cinder_utils.create_volume_type(), get_volume_type(), and + get_volume_type_by_id() + """ + self.volume_type = cinder_utils.create_volume_type( + self.cinder, self.volume_type_settings) + self.assertIsNotNone(self.volume_type) + self.assertEqual(self.volume_type_settings.name, self.volume_type.name) + + volume_type1 = cinder_utils.get_volume_type( + self.cinder, volume_type_settings=self.volume_type_settings) + self.assertEquals(self.volume_type, volume_type1) + self.assertEquals(self.volume_type_settings.public, + volume_type1.public) + + volume_type2 = cinder_utils.get_volume_type_by_id( + self.cinder, volume_type1.id) + self.assertEquals(self.volume_type, volume_type2) + self.assertIsNone(self.volume_type.encryption) + + def test_create_delete_volume_type(self): + """ + Primarily tests the cinder_utils.delete_volume() + """ + self.volume_type = cinder_utils.create_volume_type( + self.cinder, self.volume_type_settings) + self.assertIsNotNone(self.volume_type) + self.assertEqual(self.volume_type_settings.name, self.volume_type.name) + + volume_type = cinder_utils.get_volume_type( + self.cinder, volume_type_settings=self.volume_type_settings) + self.assertIsNotNone(volume_type) + validation_utils.objects_equivalent(self.volume_type, volume_type) + self.assertIsNone(self.volume_type.encryption) + + cinder_utils.delete_volume_type(self.cinder, self.volume_type) + self.assertIsNone(cinder_utils.get_volume_type_by_id( + self.cinder, self.volume_type.id)) + + +class CinderUtilsAddEncryptionTests(OSComponentTestCase): + """ + Tests the creation of an encryption and association to and existing + VolumeType object + """ + + def setUp(self): + """ + Instantiates the CreateVolume object that is responsible for + downloading and creating an OS volume file within OpenStack + """ + guid = uuid.uuid4() + self.encryption_name = self.__class__.__name__ + '-' + str(guid) + self.encryption = None + + self.cinder = cinder_utils.cinder_client(self.os_creds) + + volume_type_name = self.__class__.__name__ + '-' + str(guid) + '-type' + self.volume_type = cinder_utils.create_volume_type( + self.cinder, VolumeTypeSettings(name=volume_type_name)) + + def tearDown(self): + """ + Cleans the remote OpenStack objects + """ + if self.encryption: + try: + cinder_utils.delete_volume_type_encryption( + self.cinder, self.volume_type) + except NotFound: + pass + + if self.volume_type: + try: + cinder_utils.delete_volume_type(self.cinder, self.volume_type) + except NotFound: + pass + + def test_create_simple_encryption(self): + """ + Tests the cinder_utils.create_volume_encryption(), + get_volume_encryption(), and get_volume_encryption_by_id() + """ + encryption_settings = VolumeTypeEncryptionSettings( + name=self.encryption_name, provider_class='foo', + control_location=ControlLocation.front_end) + self.encryption = cinder_utils.create_volume_encryption( + self.cinder, self.volume_type, encryption_settings) + self.assertIsNotNone(self.encryption) + self.assertEqual('foo', self.encryption.provider) + self.assertEqual(ControlLocation.front_end.value, + self.encryption.control_location) + + encryption1 = cinder_utils.get_volume_encryption_by_type( + self.cinder, self.volume_type) + self.assertEquals(self.encryption, encryption1) + + def test_create_delete_encryption(self): + """ + Primarily tests the cinder_utils.delete_volume_type_encryption() + """ + encryption_settings = VolumeTypeEncryptionSettings( + name=self.encryption_name, provider_class='LuksEncryptor', + control_location=ControlLocation.back_end) + self.encryption = cinder_utils.create_volume_encryption( + self.cinder, self.volume_type, encryption_settings) + self.assertIsNotNone(self.encryption) + self.assertEqual('LuksEncryptor', self.encryption.provider) + self.assertEqual(ControlLocation.back_end.value, + self.encryption.control_location) + + encryption1 = cinder_utils.get_volume_encryption_by_type( + self.cinder, self.volume_type) + self.assertEquals(self.encryption, encryption1) + + cinder_utils.delete_volume_type_encryption( + self.cinder, self.volume_type) + + encryption2 = cinder_utils.get_volume_encryption_by_type( + self.cinder, self.volume_type) + self.assertIsNone(encryption2) + + def test_create_with_all_attrs(self): + """ + Tests the cinder_utils.create_volume_encryption() with all valid + settings + """ + encryption_settings = VolumeTypeEncryptionSettings( + name=self.encryption_name, provider_class='foo', + cipher='bar', control_location=ControlLocation.back_end, + key_size=1) + self.encryption = cinder_utils.create_volume_encryption( + self.cinder, self.volume_type, encryption_settings) + self.assertIsNotNone(self.encryption) + self.assertEqual('foo', self.encryption.provider) + self.assertEqual('bar', self.encryption.cipher) + self.assertEqual(1, self.encryption.key_size) + self.assertEqual(ControlLocation.back_end.value, + self.encryption.control_location) + + encryption1 = cinder_utils.get_volume_encryption_by_type( + self.cinder, self.volume_type) + self.assertEquals(self.encryption, encryption1) + + def test_create_bad_key_size(self): + """ + Tests the cinder_utils.create_volume_encryption() raises an exception + when the provider class does not exist + """ + encryption_settings = VolumeTypeEncryptionSettings( + name=self.encryption_name, provider_class='foo', + cipher='bar', control_location=ControlLocation.back_end, + key_size=-1) + + with self.assertRaises(BadRequest): + self.encryption = cinder_utils.create_volume_encryption( + self.cinder, self.volume_type, encryption_settings) + + +class CinderUtilsVolumeTypeCompleteTests(OSComponentTestCase): + """ + Tests to ensure that a volume type can have a QoS Spec added to it + """ + + def setUp(self): + """ + Creates objects for testing cinder_utils.py + """ + guid = uuid.uuid4() + self.qos_name = self.__class__.__name__ + '-' + str(guid) + '-qos' + self.vol_type_name = self.__class__.__name__ + '-' + str(guid) + self.specs = {'foo': 'bar'} + self.cinder = cinder_utils.cinder_client(self.os_creds) + qos_settings = QoSSettings(name=self.qos_name, specs=self.specs, + consumer=Consumer.both) + self.qos = cinder_utils.create_qos(self.cinder, qos_settings) + self.volume_type = None + + def tearDown(self): + """ + Cleans the remote OpenStack objects + """ + if self.volume_type: + if self.volume_type.encryption: + try: + cinder_utils.delete_volume_type_encryption( + self.cinder, self.volume_type) + except NotFound: + pass + try: + cinder_utils.delete_volume_type(self.cinder, self.volume_type) + except NotFound: + pass + + if self.qos: + try: + cinder_utils.delete_qos(self.cinder, self.qos) + except NotFound: + pass + + def test_create_with_encryption(self): + """ + Tests the cinder_utils.create_volume_type() where encryption has been + configured + """ + encryption_settings = VolumeTypeEncryptionSettings( + name='foo', provider_class='bar', + control_location=ControlLocation.back_end) + volume_type_settings = VolumeTypeSettings( + name=self.vol_type_name, encryption=encryption_settings) + self.volume_type = cinder_utils.create_volume_type( + self.cinder, volume_type_settings) + + vol_encrypt = cinder_utils.get_volume_encryption_by_type( + self.cinder, self.volume_type) + self.assertIsNotNone(vol_encrypt) + self.assertIsNone(self.volume_type.qos_spec) + self.assertEqual(self.volume_type.encryption, vol_encrypt) + self.assertEqual(self.volume_type.id, vol_encrypt.volume_type_id) + + def test_create_with_qos(self): + """ + Tests the cinder_utils.create_volume_type() with an associated QoS Spec + """ + volume_type_settings = VolumeTypeSettings( + name=self.vol_type_name, qos_spec_name=self.qos_name) + self.volume_type = cinder_utils.create_volume_type( + self.cinder, volume_type_settings) + + self.assertIsNotNone(self.volume_type) + self.assertIsNone(self.volume_type.encryption) + self.assertIsNotNone(self.volume_type.qos_spec) + self.assertEqual(self.qos.id, self.volume_type.qos_spec.id) + + def test_create_with_invalid_qos(self): + """ + Tests the cinder_utils.create_volume_type() when the QoS Spec name + does not exist + """ + volume_type_settings = VolumeTypeSettings( + name=self.vol_type_name, qos_spec_name='foo') + + self.volume_type = cinder_utils.create_volume_type( + self.cinder, volume_type_settings) + + self.assertIsNone(self.volume_type.qos_spec) + + def test_create_with_qos_and_encryption(self): + """ + Tests the cinder_utils.create_volume_type() with encryption and an + associated QoS Spec + """ + encryption_settings = VolumeTypeEncryptionSettings( + name='foo', provider_class='bar', + control_location=ControlLocation.back_end) + volume_type_settings = VolumeTypeSettings( + name=self.vol_type_name, qos_spec_name=self.qos_name, + encryption=encryption_settings) + self.volume_type = cinder_utils.create_volume_type( + self.cinder, volume_type_settings) + + self.assertIsNotNone(self.volume_type) + vol_encrypt = cinder_utils.get_volume_encryption_by_type( + self.cinder, self.volume_type) + self.assertIsNotNone(vol_encrypt) + self.assertEqual(self.volume_type.id, vol_encrypt.volume_type_id) + self.assertIsNotNone(self.volume_type.qos_spec) + self.assertEqual(self.qos.id, self.volume_type.qos_spec.id) |