diff options
| author | Pavlo Shchelokovskyy <shchelokovskyy@gmail.com> | 2022-08-05 14:03:21 +0300 |
|---|---|---|
| committer | Stephen Finucane <sfinucan@redhat.com> | 2022-09-30 11:53:00 +0100 |
| commit | ec8dba29f9f646ec05c0d6fad32b4b3aaf99f6af (patch) | |
| tree | a1589bf23ca70adf67eaf6c25003839ef2caa54a /openstackclient/tests/unit/compute | |
| parent | 00d8d945a1869b723b9845b3e739928a7c4da00a (diff) | |
| download | python-openstackclient-ec8dba29f9f646ec05c0d6fad32b4b3aaf99f6af.tar.gz | |
Speed up standard flavor list command
currently this command tries to fetch extra_specs for any flavor
that does not have them (which is quite usual), regardless if the
command was even asked to display them (--long) at all.
This significantly slows down this command as it makes a lot of
unnecessary REST calls, one per each flavor to fetch extra_specs for.
With this patch, client only attempts to fetch flavor extra_specs if
the user actually called the client with --long.
Change-Id: Ia36414d891a41b641d7a9a04f0a1e7d43cfee351
Story: 2010343
Task: 46484
Diffstat (limited to 'openstackclient/tests/unit/compute')
| -rw-r--r-- | openstackclient/tests/unit/compute/v2/test_flavor.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/compute/v2/test_flavor.py b/openstackclient/tests/unit/compute/v2/test_flavor.py index 14dd3df2..33ebf546 100644 --- a/openstackclient/tests/unit/compute/v2/test_flavor.py +++ b/openstackclient/tests/unit/compute/v2/test_flavor.py @@ -523,6 +523,7 @@ class TestFlavorList(TestFlavor): self.sdk_client.flavors.assert_called_with( **kwargs ) + self.sdk_client.fetch_flavor_extra_specs.assert_not_called() self.assertEqual(self.columns, columns) self.assertEqual(self.data, tuple(data)) @@ -550,6 +551,7 @@ class TestFlavorList(TestFlavor): self.sdk_client.flavors.assert_called_with( **kwargs ) + self.sdk_client.fetch_flavor_extra_specs.assert_not_called() self.assertEqual(self.columns, columns) self.assertEqual(self.data, tuple(data)) @@ -577,6 +579,7 @@ class TestFlavorList(TestFlavor): self.sdk_client.flavors.assert_called_with( **kwargs ) + self.sdk_client.fetch_flavor_extra_specs.assert_not_called() self.assertEqual(self.columns, columns) self.assertEqual(self.data, tuple(data)) @@ -604,6 +607,7 @@ class TestFlavorList(TestFlavor): self.sdk_client.flavors.assert_called_with( **kwargs ) + self.sdk_client.fetch_flavor_extra_specs.assert_not_called() self.assertEqual(self.columns, columns) self.assertEqual(self.data, tuple(data)) @@ -631,6 +635,58 @@ class TestFlavorList(TestFlavor): self.sdk_client.flavors.assert_called_with( **kwargs ) + self.sdk_client.fetch_flavor_extra_specs.assert_not_called() + + self.assertEqual(self.columns_long, columns) + self.assertCountEqual(self.data_long, tuple(data)) + + def test_flavor_list_long_no_extra_specs(self): + # use flavor with no extra specs for this test + flavor = compute_fakes.FakeFlavor.create_one_flavor( + attrs={"extra_specs": {}}) + self.data = (( + flavor.id, + flavor.name, + flavor.ram, + flavor.disk, + flavor.ephemeral, + flavor.vcpus, + flavor.is_public, + ),) + self.data_long = (self.data[0] + ( + flavor.swap, + flavor.rxtx_factor, + format_columns.DictColumn(flavor.extra_specs) + ),) + self.api_mock.side_effect = [[flavor], [], ] + + self.sdk_client.flavors = self.api_mock + self.sdk_client.fetch_flavor_extra_specs = mock.Mock(return_value=None) + + arglist = [ + '--long', + ] + verifylist = [ + ('long', True), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # In base command class Lister in cliff, abstract method take_action() + # returns a tuple containing the column names and an iterable + # containing the data to be listed. + columns, data = self.cmd.take_action(parsed_args) + + # Set expected values + kwargs = { + 'is_public': True, + } + + self.sdk_client.flavors.assert_called_with( + **kwargs + ) + self.sdk_client.fetch_flavor_extra_specs.assert_called_once_with( + flavor) self.assertEqual(self.columns_long, columns) self.assertCountEqual(self.data_long, tuple(data)) @@ -662,6 +718,7 @@ class TestFlavorList(TestFlavor): self.sdk_client.flavors.assert_called_with( **kwargs ) + self.sdk_client.fetch_flavor_extra_specs.assert_not_called() self.assertEqual(self.columns, columns) self.assertEqual(tuple(self.data), tuple(data)) |
