def handle(self, request, data): try: set_dict, unset_list = utils.parse_str_meta(data['group_specs']) if unset_list: msg = _("Expected only pairs of key=value.") raise ValidationError(message=msg) is_public = ( self.enable_public_share_group_type_creation and data["is_public"]) share_group_type = manila.share_group_type_create( request, data["name"], share_types=data['share_types'], is_public=is_public) if set_dict: manila.share_group_type_set_specs( request, share_group_type.id, set_dict) msg = _("Successfully created share group type: " "%s") % share_group_type.name messages.success(request, msg) return True except ValidationError as e: # handle error without losing dialog self.api_error(e.messages[0]) return False except Exception: exceptions.handle(request, _('Unable to create share group type.')) return False
def test_share_group_type_create(self, kwargs): name = 'fake_sgt_name' sts = ['fake', 'list', 'of', 'share', 'types'] result = api.share_group_type_create(self.request, name, sts, **kwargs) self.assertIsNotNone(result) self.assertEqual( self.manilaclient.share_group_types.create.return_value, result) self.manilaclient.share_group_types.create.assert_called_once_with( name=name, share_types=sts, is_public=kwargs.get('is_public', False), group_specs=kwargs.get('group_specs'))