Ejemplo n.º 1
0
    def handle(self, request, data):
        try:
            set_dict, unset_list = utils.parse_str_meta(data['group_specs'])
            if set_dict:
                manila.share_group_type_set_specs(
                    request, self.initial["id"], set_dict)
            if unset_list:
                get = manila.share_group_type_get_specs(
                    request, self.initial["id"])

                # NOTE(vponomaryov): skip keys that are already unset
                to_unset = set(unset_list).intersection(set(get.keys()))
                if to_unset:
                    manila.share_group_type_unset_specs(
                        request, self.initial["id"], to_unset)
            msg = _(
                "Successfully updated group specs for share group type '%s'.")
            msg = msg % self.initial['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:
            msg = _("Unable to update group_specs for share group type.")
            exceptions.handle(request, msg)
            return False
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    def test_share_group_type_set_specs(self):
        sgt = 'fake_share_group_type'
        group_specs = 'fake_specs'

        result = api.share_group_type_set_specs(self.request, sgt, group_specs)

        get_method = self.manilaclient.share_group_types.get
        self.assertIsNotNone(result)
        self.assertEqual(get_method.return_value.set_keys.return_value, result)
        get_method.assert_called_once_with(sgt)
        get_method.return_value.set_keys.assert_called_once_with(group_specs)
Ejemplo n.º 4
0
    def test_share_group_type_set_specs(self):
        sgt = 'fake_share_group_type'
        group_specs = 'fake_specs'

        result = api.share_group_type_set_specs(self.request, sgt, group_specs)

        get_method = self.manilaclient.share_group_types.get
        self.assertIsNotNone(result)
        self.assertEqual(get_method.return_value.set_keys.return_value, result)
        get_method.assert_called_once_with(sgt)
        get_method.return_value.set_keys.assert_called_once_with(group_specs)