diff options
| author | Jenkins <jenkins@review.openstack.org> | 2017-04-29 03:25:55 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2017-04-29 03:25:55 +0000 |
| commit | 524b2b36ff431ea2565a7b68b67346f7c6b92233 (patch) | |
| tree | 2145e5458e8afcd9e4d162f40daabd88efabe193 /openstackclient | |
| parent | efcf3b22ad22152331f7a42f0bfc4cc67205b8da (diff) | |
| parent | 2c5405ed5e69eb5b000d47d92e1019b8bb9b54f9 (diff) | |
| download | python-openstackclient-524b2b36ff431ea2565a7b68b67346f7c6b92233.tar.gz | |
Merge "Fix volume qos spec list"
Diffstat (limited to 'openstackclient')
| -rw-r--r-- | openstackclient/tests/functional/volume/v3/test_qos.py | 3 | ||||
| -rw-r--r-- | openstackclient/tests/unit/volume/v1/test_qos_specs.py | 65 | ||||
| -rw-r--r-- | openstackclient/tests/unit/volume/v2/test_qos_specs.py | 28 | ||||
| -rw-r--r-- | openstackclient/volume/v1/qos_specs.py | 19 | ||||
| -rw-r--r-- | openstackclient/volume/v2/qos_specs.py | 19 |
5 files changed, 106 insertions, 28 deletions
diff --git a/openstackclient/tests/functional/volume/v3/test_qos.py b/openstackclient/tests/functional/volume/v3/test_qos.py index 46965ced..a7af3c5b 100644 --- a/openstackclient/tests/functional/volume/v3/test_qos.py +++ b/openstackclient/tests/functional/volume/v3/test_qos.py @@ -10,9 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -from openstackclient.tests.functional.volume.v2 import test_qos as v2 import os +from openstackclient.tests.functional.volume.v2 import test_qos as v2 + class QosTests(v2.QosTests): """Functional tests for volume qos. """ diff --git a/openstackclient/tests/unit/volume/v1/test_qos_specs.py b/openstackclient/tests/unit/volume/v1/test_qos_specs.py index e3dc1e78..a88c1cd8 100644 --- a/openstackclient/tests/unit/volume/v1/test_qos_specs.py +++ b/openstackclient/tests/unit/volume/v1/test_qos_specs.py @@ -13,6 +13,7 @@ # under the License. # +import copy import mock from mock import call @@ -309,13 +310,30 @@ class TestQosDisassociate(TestQos): class TestQosList(TestQos): - qos_spec = volume_fakes.FakeQos.create_one_qos() + qos_specs = volume_fakes.FakeQos.create_qoses(count=2) qos_association = volume_fakes.FakeQos.create_one_qos_association() + columns = ( + 'ID', + 'Name', + 'Consumer', + 'Associations', + 'Properties', + ) + data = [] + for q in qos_specs: + data.append(( + q.id, + q.name, + q.consumer, + qos_association.name, + utils.format_dict(q.specs), + )) + def setUp(self): super(TestQosList, self).setUp() - self.qos_mock.list.return_value = [self.qos_spec] + self.qos_mock.list.return_value = self.qos_specs self.qos_mock.get_associations.return_value = [self.qos_association] # Get the command object to test @@ -330,22 +348,35 @@ class TestQosList(TestQos): columns, data = self.cmd.take_action(parsed_args) self.qos_mock.list.assert_called_with() - collist = ( - 'ID', - 'Name', - 'Consumer', - 'Associations', - 'Properties', + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, list(data)) + + def test_qos_list_no_association(self): + self.qos_mock.reset_mock() + self.qos_mock.get_associations.side_effect = [ + [self.qos_association], + exceptions.NotFound("NotFound"), + ] + + arglist = [] + verifylist = [] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + self.qos_mock.list.assert_called_with() + + self.assertEqual(self.columns, columns) + + ex_data = copy.deepcopy(self.data) + ex_data[1] = ( + self.qos_specs[1].id, + self.qos_specs[1].name, + self.qos_specs[1].consumer, + None, + utils.format_dict(self.qos_specs[1].specs), ) - self.assertEqual(collist, columns) - datalist = (( - self.qos_spec.id, - self.qos_spec.name, - self.qos_spec.consumer, - self.qos_association.name, - utils.format_dict(self.qos_spec.specs), - ), ) - self.assertEqual(datalist, tuple(data)) + self.assertEqual(ex_data, list(data)) class TestQosSet(TestQos): diff --git a/openstackclient/tests/unit/volume/v2/test_qos_specs.py b/openstackclient/tests/unit/volume/v2/test_qos_specs.py index 35d9a345..8f145a7e 100644 --- a/openstackclient/tests/unit/volume/v2/test_qos_specs.py +++ b/openstackclient/tests/unit/volume/v2/test_qos_specs.py @@ -13,6 +13,7 @@ # under the License. # +import copy import mock from mock import call @@ -342,6 +343,33 @@ class TestQosList(TestQos): self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) + def test_qos_list_no_association(self): + self.qos_mock.reset_mock() + self.qos_mock.get_associations.side_effect = [ + [self.qos_association], + exceptions.NotFound("NotFound"), + ] + + arglist = [] + verifylist = [] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + self.qos_mock.list.assert_called_with() + + self.assertEqual(self.columns, columns) + + ex_data = copy.deepcopy(self.data) + ex_data[1] = ( + self.qos_specs[1].id, + self.qos_specs[1].name, + self.qos_specs[1].consumer, + None, + utils.format_dict(self.qos_specs[1].specs), + ) + self.assertEqual(ex_data, list(data)) + class TestQosSet(TestQos): diff --git a/openstackclient/volume/v1/qos_specs.py b/openstackclient/volume/v1/qos_specs.py index bae8c1ab..26c91829 100644 --- a/openstackclient/volume/v1/qos_specs.py +++ b/openstackclient/volume/v1/qos_specs.py @@ -186,11 +186,20 @@ class ListQos(command.Lister): qos_specs_list = volume_client.qos_specs.list() for qos in qos_specs_list: - qos_associations = volume_client.qos_specs.get_associations(qos) - if qos_associations: - associations = [association.name - for association in qos_associations] - qos._info.update({'associations': associations}) + try: + qos_associations = volume_client.qos_specs.get_associations( + qos, + ) + if qos_associations: + associations = [ + association.name for association in qos_associations + ] + qos._info.update({'associations': associations}) + except Exception as ex: + if type(ex).__name__ == 'NotFound': + qos._info.update({'associations': None}) + else: + raise display_columns = ( 'ID', 'Name', 'Consumer', 'Associations', 'Properties') diff --git a/openstackclient/volume/v2/qos_specs.py b/openstackclient/volume/v2/qos_specs.py index 8e1d67b5..c7160581 100644 --- a/openstackclient/volume/v2/qos_specs.py +++ b/openstackclient/volume/v2/qos_specs.py @@ -187,11 +187,20 @@ class ListQos(command.Lister): qos_specs_list = volume_client.qos_specs.list() for qos in qos_specs_list: - qos_associations = volume_client.qos_specs.get_associations(qos) - if qos_associations: - associations = [association.name - for association in qos_associations] - qos._info.update({'associations': associations}) + try: + qos_associations = volume_client.qos_specs.get_associations( + qos, + ) + if qos_associations: + associations = [ + association.name for association in qos_associations + ] + qos._info.update({'associations': associations}) + except Exception as ex: + if type(ex).__name__ == 'NotFound': + qos._info.update({'associations': None}) + else: + raise display_columns = ( 'ID', 'Name', 'Consumer', 'Associations', 'Properties') |
