diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 798d3d3fcf..a1330e0195 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -113,7 +113,7 @@ def _get_ip_address(addresses, address_type, ip_address_family): ) -def _prep_server_detail(compute_client, server): +def _prep_server_detail(compute_client, image_client, server): """Prepare the detailed server dict for printing :param compute_client: a compute client instance @@ -130,7 +130,7 @@ def _prep_server_detail(compute_client, server): if image_info: image_id = image_info.get('id', '') try: - image = utils.find_resource(compute_client.images, image_id) + image = utils.find_resource(image_client.images, image_id) info['image'] = "%s (%s)" % (image.name, image_id) except Exception: info['image'] = image_id @@ -450,12 +450,13 @@ class CreateServer(command.ShowOne): def take_action(self, parsed_args): compute_client = self.app.client_manager.compute volume_client = self.app.client_manager.volume + image_client = self.app.client_manager.image # Lookup parsed_args.image image = None if parsed_args.image: image = utils.find_resource( - compute_client.images, + image_client.images, parsed_args.image, ) @@ -629,7 +630,7 @@ class CreateServer(command.ShowOne): sys.stdout.write(_('Error creating server\n')) raise SystemExit - details = _prep_server_detail(compute_client, server) + details = _prep_server_detail(compute_client, image_client, server) return zip(*sorted(six.iteritems(details))) @@ -797,6 +798,7 @@ class ListServer(command.Lister): def take_action(self, parsed_args): compute_client = self.app.client_manager.compute identity_client = self.app.client_manager.identity + image_client = self.app.client_manager.image project_id = None if parsed_args.project: @@ -826,7 +828,7 @@ class ListServer(command.Lister): # image name is given, map it to ID. image_id = None if parsed_args.image: - image_id = utils.find_resource(compute_client.images, + image_id = utils.find_resource(image_client.images, parsed_args.image).id search_opts = { @@ -1164,13 +1166,14 @@ class RebuildServer(command.ShowOne): def take_action(self, parsed_args): compute_client = self.app.client_manager.compute + image_client = self.app.client_manager.image server = utils.find_resource( compute_client.servers, parsed_args.server) # If parsed_args.image is not set, default to the currently used one. image_id = parsed_args.image or server._info.get('image', {}).get('id') - image = utils.find_resource(compute_client.images, image_id) + image = utils.find_resource(image_client.images, image_id) server = server.rebuild(image, parsed_args.password) if parsed_args.wait: @@ -1186,7 +1189,7 @@ class RebuildServer(command.ShowOne): sys.stdout.write(_('Error rebuilding server\n')) raise SystemExit - details = _prep_server_detail(compute_client, server) + details = _prep_server_detail(compute_client, image_client, server) return zip(*sorted(six.iteritems(details))) @@ -1561,7 +1564,8 @@ class ShowServer(command.ShowOne): sys.stderr.write(_("Error retrieving diagnostics data\n")) return ({}, {}) else: - data = _prep_server_detail(compute_client, server) + data = _prep_server_detail(compute_client, + self.app.client_manager.image, server) return zip(*sorted(six.iteritems(data))) diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 5722118989..54f36209c0 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -36,10 +36,6 @@ class TestServer(compute_fakes.TestComputev2): self.servers_mock = self.app.client_manager.compute.servers self.servers_mock.reset_mock() - # Get a shortcut to the compute client ImageManager Mock - self.cimages_mock = self.app.client_manager.compute.images - self.cimages_mock.reset_mock() - # Get a shortcut to the compute client FlavorManager Mock self.flavors_mock = self.app.client_manager.compute.flavors self.flavors_mock.reset_mock() @@ -259,7 +255,7 @@ class TestServerCreate(TestServer): self.servers_mock.create.return_value = self.new_server self.image = image_fakes.FakeImage.create_one_image() - self.cimages_mock.get.return_value = self.image + self.images_mock.get.return_value = self.image self.flavor = compute_fakes.FakeFlavor.create_one_flavor() self.flavors_mock.get.return_value = self.flavor @@ -859,7 +855,7 @@ class TestServerList(TestServer): self.servers_mock.list.return_value = self.servers self.image = image_fakes.FakeImage.create_one_image() - self.cimages_mock.get.return_value = self.image + self.images_mock.get.return_value = self.image self.flavor = compute_fakes.FakeFlavor.create_one_flavor() self.flavors_mock.get.return_value = self.flavor @@ -943,7 +939,7 @@ class TestServerList(TestServer): parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) - self.cimages_mock.get.assert_any_call(self.image.id) + self.images_mock.get.assert_any_call(self.image.id) self.search_opts['image'] = self.image.id self.servers_mock.list.assert_called_with(**self.kwargs) @@ -1019,7 +1015,7 @@ class TestServerRebuild(TestServer): # Return value for utils.find_resource for image self.image = image_fakes.FakeImage.create_one_image() - self.cimages_mock.get.return_value = self.image + self.images_mock.get.return_value = self.image # Fake the rebuilt new server. new_server = compute_fakes.FakeServer.create_one_server() @@ -1059,7 +1055,7 @@ class TestServerRebuild(TestServer): self.cmd.take_action(parsed_args) self.servers_mock.get.assert_called_with(self.server.id) - self.cimages_mock.get.assert_called_with(self.image.id) + self.images_mock.get.assert_called_with(self.image.id) self.server.rebuild.assert_called_with(self.image, None) def test_rebuild_with_current_image_and_password(self): @@ -1078,7 +1074,7 @@ class TestServerRebuild(TestServer): self.cmd.take_action(parsed_args) self.servers_mock.get.assert_called_with(self.server.id) - self.cimages_mock.get.assert_called_with(self.image.id) + self.images_mock.get.assert_called_with(self.image.id) self.server.rebuild.assert_called_with(self.image, password) @mock.patch.object(common_utils, 'wait_for_status', return_value=True) @@ -1106,7 +1102,7 @@ class TestServerRebuild(TestServer): ) self.servers_mock.get.assert_called_with(self.server.id) - self.cimages_mock.get.assert_called_with(self.image.id) + self.images_mock.get.assert_called_with(self.image.id) self.server.rebuild.assert_called_with(self.image, None) @mock.patch.object(common_utils, 'wait_for_status', return_value=False) @@ -1130,7 +1126,7 @@ class TestServerRebuild(TestServer): ) self.servers_mock.get.assert_called_with(self.server.id) - self.cimages_mock.get.assert_called_with(self.image.id) + self.images_mock.get.assert_called_with(self.image.id) self.server.rebuild.assert_called_with(self.image, None) @@ -1628,7 +1624,7 @@ class TestServerShow(TestServer): # This is the return value for utils.find_resource() self.servers_mock.get.return_value = self.server - self.cimages_mock.get.return_value = self.image + self.images_mock.get.return_value = self.image self.flavors_mock.get.return_value = self.flavor # Get the command object to test @@ -1986,6 +1982,7 @@ class TestServerGeneral(TestServer): # Call _prep_server_detail(). server_detail = server._prep_server_detail( self.app.client_manager.compute, + self.app.client_manager.image, _server ) # 'networks' is used to create _server. Remove it.