diff --git a/openstackclient/tests/functional/volume/v3/test_qos.py b/openstackclient/tests/functional/volume/v3/test_qos.py index 46965ced08..a7af3c5b97 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 e3dc1e787a..a88c1cd83f 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 35d9a34575..8f145a7e3f 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 bae8c1ab0c..26c9182971 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 8e1d67b5c3..c71605818a 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')