Skip to content

Commit bc6cff7

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "compute: Make 'hypervisor show' a bit faster"
2 parents 6312a6f + 4a2fd82 commit bc6cff7

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

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)