def test_delete_volume_type_encryption(self): volume_type = self.cinder_volume_types.first() volume_type.id = u'1' formData = { 'action': 'volume_types__delete_encryption__%s' % volume_type.id } encryption_list = (self.cinder_volume_encryption_types.list()[0], self.cinder_volume_encryption_types.list()[1]) cinder.extension_supported(IsA(http.HttpRequest), 'VolumeTypeEncryption')\ .AndReturn(True) cinder.volume_type_list_with_qos_associations( IsA(http.HttpRequest))\ .AndReturn(self.cinder_volume_types.list()) cinder.qos_spec_list(IsA(http.HttpRequest))\ .AndReturn(self.cinder_qos_specs.list()) cinder.volume_encryption_type_list(IsA(http.HttpRequest))\ .AndReturn(encryption_list) cinder.volume_encryption_type_delete(IsA(http.HttpRequest), volume_type.id) self.mox.ReplayAll() res = self.client.post( reverse('horizon:admin:volumes:volume_types_tab'), formData) redirect = reverse('horizon:admin:volumes:volume_types_tab') self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, redirect)
def test_create_cgroup(self): cgroup = self.cinder_consistencygroups.first() volume_types = self.cinder_volume_types.list() az = self.cinder_availability_zones.first().zoneName formData = { 'volume_types': '1', 'name': 'test CG', 'description': 'test desc', 'availability_zone': az } cinder.volume_type_list(IsA(http.HttpRequest)).\ AndReturn(volume_types) cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\ AndReturn(volume_types) cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn( self.cinder_availability_zones.list()) cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\ .AndReturn(True) cinder.volume_cgroup_list(IsA( http.HttpRequest)).\ AndReturn(self.cinder_consistencygroups.list()) cinder.volume_cgroup_create( IsA(http.HttpRequest), formData['volume_types'], formData['name'], formData['description'], availability_zone=formData['availability_zone'])\ .AndReturn(cgroup) self.mox.ReplayAll() url = reverse('horizon:virtual:volumes:cgroups:create') res = self.client.post(url, formData) self.assertNoFormErrors(res)
def test_volume_types_tab(self): encryption_list = (self.cinder_volume_encryption_types.list()[0], self.cinder_volume_encryption_types.list()[1]) cinder.volume_type_list_with_qos_associations( IsA(http.HttpRequest)).\ AndReturn(self.volume_types.list()) cinder.qos_spec_list(IsA(http.HttpRequest)).\ AndReturn(self.cinder_qos_specs.list()) cinder.volume_encryption_type_list(IsA(http.HttpRequest))\ .AndReturn(encryption_list) cinder.extension_supported(IsA(http.HttpRequest), 'VolumeTypeEncryption').MultipleTimes()\ .AndReturn(True) self.mox.ReplayAll() res = self.client.get(reverse( 'horizon:admin:volumes:volume_types_tab')) self.assertEqual(res.status_code, 200) self.assertTemplateUsed( res, 'admin/volumes/volume_types/volume_types_tables.html') volume_types = res.context['volume_types_table'].data self.assertItemsEqual(volume_types, self.volume_types.list()) qos_specs = res.context['qos_specs_table'].data self.assertItemsEqual(qos_specs, self.cinder_qos_specs.list())
def test_create_cgroup_exception(self): volume_types = self.volume_types.list() az = self.cinder_availability_zones.first().zoneName formData = { 'volume_types': '1', 'name': 'test CG', 'description': 'test desc', 'availability_zone': az } cinder.volume_type_list(IsA(http.HttpRequest)).\ AndReturn(volume_types) cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\ AndReturn(volume_types) cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn( self.cinder_availability_zones.list()) cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\ .AndReturn(True) cinder.volume_cgroup_list(IsA( http.HttpRequest)).\ AndReturn(self.cinder_consistencygroups.list()) cinder.volume_cgroup_create( IsA(http.HttpRequest), formData['volume_types'], formData['name'], formData['description'], availability_zone=formData['availability_zone'])\ .AndRaise(self.exceptions.cinder) self.mox.ReplayAll() url = reverse('horizon:project:volumes:cgroups:create') res = self.client.post(url, formData) self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)
def test_create_cgroup_exception(self): volume_types = self.cinder_volume_types.list() volume_type_id = self.cinder_volume_types.first().id az = self.cinder_availability_zones.first().zoneName formData = {'volume_types': '1', 'name': 'test CG', 'description': 'test desc', 'availability_zone': az, 'add_vtypes_to_cgroup_role_member': [volume_type_id]} cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\ .AndReturn(True) cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn( self.cinder_availability_zones.list()) cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(volume_types) cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\ AndReturn(volume_types) cinder.volume_cgroup_list(IsA(http.HttpRequest)).\ AndReturn(self.cinder_consistencygroups.list()) cinder.volume_cgroup_create( IsA(http.HttpRequest), formData['volume_types'], formData['name'], formData['description'], availability_zone=formData['availability_zone'])\ .AndRaise(self.exceptions.cinder) self.mox.ReplayAll() url = reverse('horizon:project:cgroups:create') res = self.client.post(url, formData) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, INDEX_URL) self.assertIn("Unable to create consistency group.", res.cookies.output())
def test_delete_volume_type_encryption(self): volume_type = self.volume_types.first() volume_type.id = u'1' formData = {'action': 'volume_types__delete_encryption__%s' % volume_type.id} encryption_list = (self.cinder_volume_encryption_types.list()[0], self.cinder_volume_encryption_types.list()[1]) cinder.extension_supported(IsA(http.HttpRequest), 'VolumeTypeEncryption')\ .AndReturn(True) cinder.volume_type_list_with_qos_associations( IsA(http.HttpRequest))\ .AndReturn(self.volume_types.list()) cinder.qos_spec_list(IsA(http.HttpRequest))\ .AndReturn(self.cinder_qos_specs.list()) cinder.volume_encryption_type_list(IsA(http.HttpRequest))\ .AndReturn(encryption_list) cinder.volume_encryption_type_delete(IsA(http.HttpRequest), volume_type.id) self.mox.ReplayAll() res = self.client.post( reverse('horizon:admin:volumes:volume_types_tab'), formData) redirect = reverse('horizon:admin:volumes:volume_types_tab') self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, redirect)
def test_create_cgroup(self): cgroup = self.cinder_consistencygroups.first() volume_types = self.cinder_volume_types.list() az = self.cinder_availability_zones.first().zoneName formData = {'volume_types': '1', 'name': 'test CG', 'description': 'test desc', 'availability_zone': az} cinder.volume_type_list(IsA(http.HttpRequest)).\ AndReturn(volume_types) cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\ AndReturn(volume_types) cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn( self.cinder_availability_zones.list()) cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\ .AndReturn(True) cinder.volume_cgroup_list(IsA( http.HttpRequest)).\ AndReturn(self.cinder_consistencygroups.list()) cinder.volume_cgroup_create( IsA(http.HttpRequest), formData['volume_types'], formData['name'], formData['description'], availability_zone=formData['availability_zone'])\ .AndReturn(cgroup) self.mox.ReplayAll() url = reverse('horizon:virtual:volumes:cgroups:create') res = self.client.post(url, formData) self.assertNoFormErrors(res)
def test_volume_types_tab(self): encryption_list = (self.cinder_volume_encryption_types.list()[0], self.cinder_volume_encryption_types.list()[1]) cinder.volume_type_list_with_qos_associations( IsA(http.HttpRequest)).\ AndReturn(self.cinder_volume_types.list()) cinder.qos_spec_list(IsA(http.HttpRequest)).\ AndReturn(self.cinder_qos_specs.list()) cinder.volume_encryption_type_list(IsA(http.HttpRequest))\ .AndReturn(encryption_list) cinder.extension_supported(IsA(http.HttpRequest), 'VolumeTypeEncryption').MultipleTimes()\ .AndReturn(True) self.mox.ReplayAll() res = self.client.get( reverse('horizon:admin:volumes:volume_types_tab')) self.assertEqual(res.status_code, 200) self.assertTemplateUsed( res, 'admin/volumes/volume_types/volume_types_tables.html') volume_types = res.context['volume_types_table'].data self.assertItemsEqual(volume_types, self.cinder_volume_types.list()) qos_specs = res.context['qos_specs_table'].data self.assertItemsEqual(qos_specs, self.cinder_qos_specs.list())
def test_delete_volume_type_exception(self): volume_type = self.volume_types.first() formData = {'action': 'volume_types__delete__%s' % volume_type.id} encryption_list = (self.cinder_volume_encryption_types.list()[0], self.cinder_volume_encryption_types.list()[1]) cinder.volume_type_list_with_qos_associations( IsA(http.HttpRequest)).\ AndReturn(self.volume_types.list()) cinder.qos_spec_list(IsA(http.HttpRequest)).\ AndReturn(self.cinder_qos_specs.list()) cinder.volume_encryption_type_list(IsA(http.HttpRequest))\ .AndReturn(encryption_list) cinder.volume_type_delete(IsA(http.HttpRequest), str(volume_type.id))\ .AndRaise(exceptions.BadRequest()) self.mox.ReplayAll() res = self.client.post( reverse('horizon:admin:volumes:volumes_tab'), formData) redirect = reverse('horizon:admin:volumes:volumes_tab') self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, redirect)
def test_create_cgroup_exception(self): volume_types = self.cinder_volume_types.list() az = self.cinder_availability_zones.first().zoneName formData = {'volume_types': '1', 'name': 'test CG', 'description': 'test desc', 'availability_zone': az} cinder.volume_type_list(IsA(http.HttpRequest)).\ AndReturn(volume_types) cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\ AndReturn(volume_types) cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn( self.cinder_availability_zones.list()) cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\ .AndReturn(True) cinder.volume_cgroup_list(IsA( http.HttpRequest)).\ AndReturn(self.cinder_consistencygroups.list()) cinder.volume_cgroup_create( IsA(http.HttpRequest), formData['volume_types'], formData['name'], formData['description'], availability_zone=formData['availability_zone'])\ .AndRaise(self.exceptions.cinder) self.mox.ReplayAll() url = reverse('horizon:project:volumes:cgroups:create') res = self.client.post(url, formData) self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)
def get_volume_types_data(self): try: volume_types = cinder.volume_type_list_with_qos_associations(self.request) except Exception: volume_types = [] exceptions.handle(self.request, _("Unable to retrieve volume types")) # Gather volume type encryption information try: vol_type_enc_list = cinder.volume_encryption_type_list(self.request) except Exception: vol_type_enc_list = [] msg = _("Unable to retrieve volume type encryption information.") exceptions.handle(self.request, msg) vol_type_enc_dict = SortedDict([(e.volume_type_id, e) for e in vol_type_enc_list]) for volume_type in volume_types: vol_type_enc = vol_type_enc_dict.get(volume_type.id, None) if vol_type_enc is not None: volume_type.encryption = vol_type_enc volume_type.encryption.name = volume_type.name else: volume_type.encryption = None return volume_types
def get_volume_types_data(self): try: volume_types = \ cinder.volume_type_list_with_qos_associations(self.request) except Exception: volume_types = [] exceptions.handle(self.request, _("Unable to retrieve volume types")) # Gather volume type encryption information try: vol_type_enc_list = cinder.volume_encryption_type_list( self.request) except Exception: vol_type_enc_list = [] msg = _('Unable to retrieve volume type encryption information.') exceptions.handle(self.request, msg) vol_type_enc_dict = OrderedDict([(e.volume_type_id, e) for e in vol_type_enc_list]) for volume_type in volume_types: vol_type_enc = vol_type_enc_dict.get(volume_type.id, None) if vol_type_enc is not None: volume_type.encryption = vol_type_enc volume_type.encryption.name = volume_type.name else: volume_type.encryption = None return volume_types
def get_volume_types_data(self): try: volume_types = \ cinder.volume_type_list_with_qos_associations(self.request) except Exception: volume_types = [] exceptions.handle(self.request, _("Unable to retrieve volume types")) encryption_allowed = policy.check( (("volume", "volume_extension:volume_type_encryption"),), self.request) if encryption_allowed: # Gather volume type encryption information try: vol_type_enc_list = cinder.volume_encryption_type_list( self.request) except Exception: vol_type_enc_list = [] msg = _( 'Unable to retrieve volume type encryption information.') exceptions.handle(self.request, msg) vol_type_enc_dict = OrderedDict([(e.volume_type_id, e) for e in vol_type_enc_list]) for volume_type in volume_types: vol_type_enc = vol_type_enc_dict.get(volume_type.id, None) if vol_type_enc is not None: volume_type.encryption = vol_type_enc volume_type.encryption.name = volume_type.name else: volume_type.encryption = None return volume_types
def test_volume_types_tab(self): cinder.volume_type_list_with_qos_associations( IsA(http.HttpRequest)).\ AndReturn(self.volume_types.list()) cinder.qos_spec_list(IsA(http.HttpRequest)).\ AndReturn(self.cinder_qos_specs.list()) self.mox.ReplayAll() res = self.client.get( reverse('horizon:admin:volumes:volume_types_tab')) self.assertEqual(res.status_code, 200) self.assertTemplateUsed( res, 'admin/volumes/volume_types/volume_types_tables.html') volume_types = res.context['volume_types_table'].data self.assertItemsEqual(volume_types, self.volume_types.list()) qos_specs = res.context['qos_specs_table'].data self.assertItemsEqual(qos_specs, self.cinder_qos_specs.list())
def test_volume_types_tab(self): cinder.volume_type_list_with_qos_associations( IsA(http.HttpRequest)).\ AndReturn(self.volume_types.list()) cinder.qos_spec_list(IsA(http.HttpRequest)).\ AndReturn(self.cinder_qos_specs.list()) self.mox.ReplayAll() res = self.client.get(reverse( 'horizon:admin:volumes:volume_types_tab')) self.assertEqual(res.status_code, 200) self.assertTemplateUsed( res, 'admin/volumes/volume_types/volume_types_tables.html') volume_types = res.context['volume_types_table'].data self.assertItemsEqual(volume_types, self.volume_types.list()) qos_specs = res.context['qos_specs_table'].data self.assertItemsEqual(qos_specs, self.cinder_qos_specs.list())
def handle(self, request, context): selected_vol_types = context['volume_types'] try: vol_types = cinder.volume_type_list_with_qos_associations( request) except Exception: msg = _('Unable to get volume type list') exceptions.check_message(["Connection", "refused"], msg) return False # ensure that all selected volume types share same backend name backend_name = None invalid_backend = False for selected_vol_type in selected_vol_types: if invalid_backend: continue for vol_type in vol_types: if selected_vol_type != vol_type.id: continue if (hasattr(vol_type, "extra_specs") and 'volume_backend_name' in vol_type.extra_specs): vol_type_backend = \ vol_type.extra_specs['volume_backend_name'] if vol_type_backend is None: invalid_backend = True break if backend_name is None: backend_name = vol_type_backend if vol_type_backend != backend_name: invalid_backend = True break else: invalid_backend = True break if invalid_backend: msg = _('All selected volume types must be associated ' 'with the same volume backend name.') exceptions.handle(request, msg) return False try: vtypes_str = ",".join(context['volume_types']) self.object = \ cinder.volume_cgroup_create( request, vtypes_str, context['name'], description=context['description'], availability_zone=context['availability_zone']) except Exception: exceptions.handle(request, _('Unable to create consistency ' 'group.')) return False return True
def get_volume_types_data(self): try: volume_types = \ cinder.volume_type_list_with_qos_associations(self.request) except Exception: volume_types = [] exceptions.handle(self.request, _("Unable to retrieve volume types")) return volume_types
def test_delete_volume_type(self): volume_type = self.cinder_volume_types.first() formData = {'action': 'volume_types__delete__%s' % volume_type.id} encryption_list = (self.cinder_volume_encryption_types.list()[0], self.cinder_volume_encryption_types.list()[1]) cinder.volume_type_list_with_qos_associations( IsA(http.HttpRequest)).\ AndReturn(self.cinder_volume_types.list()) cinder.qos_spec_list(IsA(http.HttpRequest)).\ AndReturn(self.cinder_qos_specs.list()) cinder.volume_encryption_type_list(IsA(http.HttpRequest))\ .AndReturn(encryption_list) cinder.volume_type_delete(IsA(http.HttpRequest), volume_type.id) self.mox.ReplayAll() res = self.client.post(INDEX_URL, formData) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, INDEX_URL)