Skip to content

Commit 4a2fd82

Browse files
committed
compute: Make 'hypervisor show' a bit faster
In the event that a user provides a hypervisor name rather than an ID to the 'hypervisor show' command, passing 'details=True' (the default) to 'find_hypervisor' will ensure we get the detailed response we need. However, this comes at the cost of retrieving reams of additional irrelevant data for all the other hypervisors. Rather than doing this, use a summary view and then a second call to fetch only the hypervisor we care about. Change-Id: I92b53802e41a962c6f916c3a111dc2de7c12d0fc Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Closes-bug: #2072965
1 parent a59262e commit 4a2fd82

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

openstackclient/compute/v2/hypervisor.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ def get_parser(self, prog_name):
165165

166166
def take_action(self, parsed_args):
167167
compute_client = self.app.client_manager.sdk_connection.compute
168-
hypervisor = compute_client.find_hypervisor(
169-
parsed_args.hypervisor, ignore_missing=False
170-
).copy()
168+
169+
hypervisor_id = compute_client.find_hypervisor(
170+
parsed_args.hypervisor, ignore_missing=False, details=False
171+
).id
172+
hypervisor = compute_client.get_hypervisor(hypervisor_id).copy()
171173

172174
# Some of the properties in the hypervisor object need to be processed
173175
# before they get reported to the user. We spend this section

openstackclient/tests/unit/compute/v2/test_hypervisor.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,11 @@ def setUp(self):
296296
}
297297
)
298298

299-
# Return value of compute_client.find_hypervisor
300299
self.compute_sdk_client.find_hypervisor.return_value = self.hypervisor
300+
self.compute_sdk_client.get_hypervisor.return_value = self.hypervisor
301301

302-
# Return value of compute_client.aggregates()
303302
self.compute_sdk_client.aggregates.return_value = []
304303

305-
# Return value of compute_client.get_hypervisor_uptime()
306304
uptime_info = {
307305
'status': self.hypervisor.status,
308306
'state': self.hypervisor.state,
@@ -429,6 +427,13 @@ def test_hypervisor_show(self):
429427
self.assertEqual(self.columns_v288, columns)
430428
self.assertCountEqual(self.data_v288, data)
431429

430+
self.compute_sdk_client.find_hypervisor.assert_called_once_with(
431+
self.hypervisor.name, ignore_missing=False, details=False
432+
)
433+
self.compute_sdk_client.get_hypervisor.assert_called_once_with(
434+
self.hypervisor.id
435+
)
436+
432437
def test_hypervisor_show_pre_v288(self):
433438
self.set_compute_api_version('2.87')
434439

@@ -448,6 +453,13 @@ def test_hypervisor_show_pre_v288(self):
448453
self.assertEqual(self.columns, columns)
449454
self.assertCountEqual(self.data, data)
450455

456+
self.compute_sdk_client.find_hypervisor.assert_called_once_with(
457+
self.hypervisor.name, ignore_missing=False, details=False
458+
)
459+
self.compute_sdk_client.get_hypervisor.assert_called_once_with(
460+
self.hypervisor.id
461+
)
462+
451463
def test_hypervisor_show_pre_v228(self):
452464
self.set_compute_api_version('2.27')
453465

@@ -472,6 +484,13 @@ def test_hypervisor_show_pre_v228(self):
472484
self.assertEqual(self.columns, columns)
473485
self.assertCountEqual(self.data, data)
474486

487+
self.compute_sdk_client.find_hypervisor.assert_called_once_with(
488+
self.hypervisor.name, ignore_missing=False, details=False
489+
)
490+
self.compute_sdk_client.get_hypervisor.assert_called_once_with(
491+
self.hypervisor.id
492+
)
493+
475494
def test_hypervisor_show_uptime_not_implemented(self):
476495
self.set_compute_api_version('2.87')
477496

@@ -543,3 +562,10 @@ def test_hypervisor_show_uptime_not_implemented(self):
543562

544563
self.assertEqual(expected_columns, columns)
545564
self.assertCountEqual(expected_data, data)
565+
566+
self.compute_sdk_client.find_hypervisor.assert_called_once_with(
567+
self.hypervisor.name, ignore_missing=False, details=False
568+
)
569+
self.compute_sdk_client.get_hypervisor.assert_called_once_with(
570+
self.hypervisor.id
571+
)

0 commit comments

Comments
 (0)