Example #1
0
def create_volume_type_config(volume_type):
    """
    Returns a VolumeTypeConfig object
    :param volume_type: a SNAPS-OO VolumeType object
    """

    control = None
    if volume_type.encryption:
        if (volume_type.encryption.control_location ==
                ControlLocation.front_end.value):
            control = ControlLocation.front_end
        else:
            control = ControlLocation.back_end

    if volume_type and volume_type.encryption:
        encrypt_settings = VolumeTypeEncryptionConfig(
            name=volume_type.encryption.__class__,
            provider_class=volume_type.encryption.provider,
            control_location=control,
            cipher=volume_type.encryption.cipher,
            key_size=volume_type.encryption.key_size)
    else:
        encrypt_settings = None

    qos_spec_name = None
    if volume_type.qos_spec:
        qos_spec_name = volume_type.qos_spec.name

    return VolumeTypeConfig(name=volume_type.name,
                            encryption=encrypt_settings,
                            qos_spec_name=qos_spec_name,
                            public=volume_type.public)
Example #2
0
 def test_config_with_name_only(self):
     settings = VolumeTypeConfig(**{'name': 'foo'})
     self.assertEqual('foo', settings.name)
     self.assertIsNone(settings.description)
     self.assertIsNone(settings.qos_spec_name)
     self.assertIsNone(settings.encryption)
     self.assertFalse(settings.public)
Example #3
0
    def test_volume_type_with_qos_and_encryption(self):
        """
        Creates a Volume Type object with encryption and an associated QoS Spec
        """
        encryption_settings = VolumeTypeEncryptionConfig(
            name='foo',
            provider_class='bar',
            control_location=ControlLocation.back_end)
        self.volume_type_creator = OpenStackVolumeType(
            self.admin_os_creds,
            VolumeTypeConfig(name=self.volume_type_name,
                             encryption=encryption_settings,
                             qos_spec_name=self.qos_creator.qos_settings.name))

        vol_type = self.volume_type_creator.create()
        self.assertEqual(self.volume_type_creator.volume_type_settings.name,
                         vol_type.name)
        self.assertEqual(self.volume_type_creator.volume_type_settings.name,
                         vol_type.name)
        self.assertIsNotNone(vol_type.qos_spec)
        self.assertEqual(
            self.volume_type_creator.volume_type_settings.qos_spec_name,
            vol_type.qos_spec.name)
        self.assertIsNotNone(vol_type.encryption)

        self.assertEqual(encryption_settings.control_location.value,
                         vol_type.encryption.control_location)

        vol_type_query = cinder_utils.get_volume_type_by_id(
            self.cinder, vol_type.id)
        self.assertIsNotNone(vol_type_query)
        self.assertEqual(vol_type, vol_type_query)
Example #4
0
    def setUp(self):
        super(self.__class__, self).__start__()

        guid = self.__class__.__name__ + '-' + str(uuid.uuid4())
        self.volume_name = guid + '-vol'
        self.volume_type_name = guid + '-vol-type'

        self.volume_type_creator = OpenStackVolumeType(
            self.admin_os_creds, VolumeTypeConfig(name=self.volume_type_name))
        self.volume_type_creator.create()
        self.volume_creator = None
Example #5
0
 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 = VolumeTypeConfig(name=volume_type_name)
     self.volume_type = None
     self.cinder = cinder_utils.cinder_client(
         self.os_creds, self.os_session)
Example #6
0
    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 = VolumeTypeConfig(
            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)
Example #7
0
 def test_all(self):
     encryption_settings = VolumeTypeEncryptionConfig(
         name='foo', provider_class='bar',
         control_location=ControlLocation.back_end)
     settings = VolumeTypeConfig(
         name='foo', description='desc', encryption=encryption_settings,
         qos_spec_name='spec_name', public=True)
     self.assertEqual('foo', settings.name)
     self.assertEqual('desc', settings.description)
     self.assertEqual('spec_name', settings.qos_spec_name)
     self.assertEqual(encryption_settings, settings.encryption)
     self.assertTrue(True, settings.public)
Example #8
0
    def test_create_with_qos(self):
        """
        Tests the cinder_utils.create_volume_type() with an associated QoS Spec
        """
        volume_type_settings = VolumeTypeConfig(
            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)
Example #9
0
 def test_all_string(self):
     encryption_settings = {
         'name': 'foo', 'provider_class': 'bar',
         'control_location': 'back-end'}
     settings = VolumeTypeConfig(
         name='foo', description='desc', encryption=encryption_settings,
         qos_spec_name='spec_name', public='true')
     self.assertEqual('foo', settings.name)
     self.assertEqual('desc', settings.description)
     self.assertEqual('spec_name', settings.qos_spec_name)
     self.assertEqual(VolumeTypeEncryptionConfig(**encryption_settings),
                      settings.encryption)
     self.assertTrue(settings.public)
Example #10
0
 def test_config_all(self):
     encryption_settings = {
         'name': 'foo', 'provider_class': 'bar',
         'control_location': 'back-end'}
     settings = VolumeTypeConfig(
         **{'name': 'foo', 'description': 'desc',
            'encryption': encryption_settings,
            'qos_spec_name': 'spec_name', 'public': 'false'})
     self.assertEqual('foo', settings.name)
     self.assertEqual('desc', settings.description)
     self.assertEqual('spec_name', settings.qos_spec_name)
     self.assertEqual(VolumeTypeEncryptionConfig(**encryption_settings),
                      settings.encryption)
     self.assertFalse(settings.public)
Example #11
0
    def setUp(self):
        """
        Instantiates the CreateVolumeType object that is responsible for
        downloading and creating an OS volume type file within OpenStack
        """
        super(self.__class__, self).__start__()

        guid = uuid.uuid4()
        self.volume_type_settings = VolumeTypeConfig(
            name=self.__class__.__name__ + '-' + str(guid))

        self.cinder = cinder_utils.cinder_client(self.admin_os_creds,
                                                 self.admin_os_session)
        self.volume_type_creator = OpenStackVolumeType(
            self.admin_os_creds, self.volume_type_settings)
Example #12
0
    def test_create_with_encryption(self):
        """
        Tests the cinder_utils.create_volume_type() where encryption has been
        configured
        """
        encryption_settings = VolumeTypeEncryptionConfig(
            name='foo', provider_class='bar',
            control_location=ControlLocation.back_end)
        volume_type_settings = VolumeTypeConfig(
            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)
Example #13
0
    def test_create_with_qos_and_encryption(self):
        """
        Tests the cinder_utils.create_volume_type() with encryption and an
        associated QoS Spec
        """
        encryption_settings = VolumeTypeEncryptionConfig(
            name='foo', provider_class='bar',
            control_location=ControlLocation.back_end)
        volume_type_settings = VolumeTypeConfig(
            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)
Example #14
0
    def test_volume_type_with_qos(self):
        """
        Creates a Volume Type object with an associated QoS Spec
        """
        self.volume_type_creator = OpenStackVolumeType(
            self.admin_os_creds,
            VolumeTypeConfig(name=self.volume_type_name,
                             qos_spec_name=self.qos_creator.qos_settings.name))

        vol_type = self.volume_type_creator.create()
        self.assertEqual(self.volume_type_creator.volume_type_settings.name,
                         vol_type.name)
        self.assertEqual(self.volume_type_creator.volume_type_settings.name,
                         vol_type.name)
        self.assertIsNotNone(vol_type.qos_spec)
        self.assertEqual(
            self.volume_type_creator.volume_type_settings.qos_spec_name,
            vol_type.qos_spec.name)
        self.assertIsNone(vol_type.encryption)

        vol_type_query = cinder_utils.get_volume_type_by_id(
            self.cinder, vol_type.id)
        self.assertIsNotNone(vol_type_query)
        self.assertEqual(vol_type, vol_type_query)
Example #15
0
 def test_empty_config(self):
     with self.assertRaises(VolumeTypeConfigError):
         VolumeTypeConfig(**dict())
Example #16
0
 def test_no_params(self):
     with self.assertRaises(VolumeTypeConfigError):
         VolumeTypeConfig()