-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK] [CLI] kms quota Closes #17 Reviewed-by: None <None> Reviewed-by: Irina Pereiaslavskaia <[email protected]>
- Loading branch information
1 parent
11c342f
commit 9dead1c
Showing
8 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
"""KMS Quota v1 action implementations""" | ||
import logging | ||
|
||
from osc_lib import utils | ||
from osc_lib.command import command | ||
|
||
from otcextensions.i18n import _ | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class ListKMSQuota(command.Lister): | ||
_description = _('List KMS Quotas') | ||
columns = ('quota', 'used', 'type') | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(ListKMSQuota, self).get_parser(prog_name) | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
client = self.app.client_manager.kms | ||
|
||
data = client.quotas() | ||
|
||
return ( | ||
self.columns, | ||
(utils.get_item_properties( | ||
s, | ||
self.columns | ||
) for s in data) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from openstack import resource | ||
from otcextensions.sdk import quotamixin | ||
|
||
|
||
class Quota(quotamixin.QuotaProxyMixin, resource.Resource): | ||
"""Key Management Service Quota resource""" | ||
resources_key = 'quotas.resources' | ||
base_path = '/quota' | ||
|
||
# capabilities | ||
allow_list = True | ||
|
||
#: Properties | ||
#: Quota type, value is ``CMK`` or ``grant_per_CMK`` | ||
type = resource.Body('type') | ||
#: Used quota | ||
used = resource.Body('used', type=int) | ||
#: Total quota | ||
quota = resource.Body('quota', type=int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from openstack import _log | ||
|
||
from otcextensions.tests.functional import base | ||
|
||
_logger = _log.setup_logging('openstack') | ||
|
||
|
||
class TestQuota(base.BaseFunctionalTest): | ||
|
||
def setUp(self): | ||
super(TestQuota, self).setUp() | ||
self.kms = self.conn.kms | ||
|
||
def test_list(self): | ||
objects = list(self.kms.quotas()) | ||
|
||
self.assertEqual(len(objects), 2) | ||
|
||
for obj in objects: | ||
self.assertIsInstance(obj, dict) | ||
self.assertIn("quota", obj.keys()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import mock | ||
|
||
from otcextensions.osclient.kms.v1 import quota | ||
from otcextensions.tests.unit.osclient.kms.v1 import fakes | ||
|
||
|
||
class TestKMSQuota(fakes.TestKMS): | ||
|
||
def setUp(self): | ||
super(TestKMSQuota, self).setUp() | ||
self.client = self.app.client_manager.kms | ||
|
||
|
||
class TestListKMSQuota(TestKMSQuota): | ||
quotas = fakes.FakeQuota.create_multiple(2) | ||
columns = ('quota', 'used', 'type') | ||
|
||
data = [] | ||
|
||
for s in quotas: | ||
data.append(( | ||
s.quota, | ||
s.used, | ||
s.type | ||
)) | ||
|
||
def setUp(self): | ||
super(TestListKMSQuota, self).setUp() | ||
self.cmd = quota.ListKMSQuota(self.app, None) | ||
self.client.quotas = mock.Mock() | ||
|
||
def test_list_quota(self): | ||
arglist = [ | ||
] | ||
|
||
verifylist = [ | ||
] | ||
|
||
# Verify cm is triggereg with default parameters | ||
parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||
|
||
# Set the response | ||
self.client.quotas.side_effect = [ | ||
self.quotas | ||
] | ||
|
||
# Trigger the action | ||
columns, data = self.cmd.take_action(parsed_args) | ||
|
||
self.client.quotas.assert_called_once_with() | ||
|
||
self.assertEqual(self.columns, columns) | ||
self.assertEqual(self.data, list(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from openstack.tests.unit import base | ||
|
||
from otcextensions.sdk.kms.v1 import quota | ||
|
||
|
||
class TestQuota(base.TestCase): | ||
|
||
def test_basic(self): | ||
sot = quota.Quota() | ||
self.assertEqual('quotas.resources', sot.resources_key) | ||
self.assertEqual('/quota', sot.base_path) | ||
self.assertTrue(sot.allow_list) | ||
self.assertFalse(sot.allow_create) | ||
self.assertFalse(sot.allow_fetch) | ||
self.assertFalse(sot.allow_commit) | ||
self.assertFalse(sot.allow_delete) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
features: | ||
- | | ||
SDK KMS Quota list operation support. | ||
CLI List KMS Quotas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters