Use image client for images instead of compute
With the deprecation of the Nova proxy APIs in microversion 2.36 [1], any operation that uses a microversion higher than 2.36 and works with images will fail because the /images endpoint will return 404. This patch updates openstackclient to query images using the image client in places where previously the compute client was used. [1] http://docs.openstack.org/developer/nova/api_microversion_history.html#id33 Change-Id: Ia66e44e530799ce6531922dcf6a84e38528c8725 Closes-bug: 1630161
This commit is contained in:
parent
11ef43da49
commit
98f803e0f0
@ -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
|
"""Prepare the detailed server dict for printing
|
||||||
|
|
||||||
:param compute_client: a compute client instance
|
:param compute_client: a compute client instance
|
||||||
@ -130,7 +130,7 @@ def _prep_server_detail(compute_client, server):
|
|||||||
if image_info:
|
if image_info:
|
||||||
image_id = image_info.get('id', '')
|
image_id = image_info.get('id', '')
|
||||||
try:
|
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)
|
info['image'] = "%s (%s)" % (image.name, image_id)
|
||||||
except Exception:
|
except Exception:
|
||||||
info['image'] = image_id
|
info['image'] = image_id
|
||||||
@ -450,12 +450,13 @@ class CreateServer(command.ShowOne):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.volume
|
||||||
|
image_client = self.app.client_manager.image
|
||||||
|
|
||||||
# Lookup parsed_args.image
|
# Lookup parsed_args.image
|
||||||
image = None
|
image = None
|
||||||
if parsed_args.image:
|
if parsed_args.image:
|
||||||
image = utils.find_resource(
|
image = utils.find_resource(
|
||||||
compute_client.images,
|
image_client.images,
|
||||||
parsed_args.image,
|
parsed_args.image,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -629,7 +630,7 @@ class CreateServer(command.ShowOne):
|
|||||||
sys.stdout.write(_('Error creating server\n'))
|
sys.stdout.write(_('Error creating server\n'))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
details = _prep_server_detail(compute_client, server)
|
details = _prep_server_detail(compute_client, image_client, server)
|
||||||
return zip(*sorted(six.iteritems(details)))
|
return zip(*sorted(six.iteritems(details)))
|
||||||
|
|
||||||
|
|
||||||
@ -797,6 +798,7 @@ class ListServer(command.Lister):
|
|||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
|
image_client = self.app.client_manager.image
|
||||||
|
|
||||||
project_id = None
|
project_id = None
|
||||||
if parsed_args.project:
|
if parsed_args.project:
|
||||||
@ -826,7 +828,7 @@ class ListServer(command.Lister):
|
|||||||
# image name is given, map it to ID.
|
# image name is given, map it to ID.
|
||||||
image_id = None
|
image_id = None
|
||||||
if parsed_args.image:
|
if parsed_args.image:
|
||||||
image_id = utils.find_resource(compute_client.images,
|
image_id = utils.find_resource(image_client.images,
|
||||||
parsed_args.image).id
|
parsed_args.image).id
|
||||||
|
|
||||||
search_opts = {
|
search_opts = {
|
||||||
@ -1164,13 +1166,14 @@ class RebuildServer(command.ShowOne):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
|
image_client = self.app.client_manager.image
|
||||||
|
|
||||||
server = utils.find_resource(
|
server = utils.find_resource(
|
||||||
compute_client.servers, parsed_args.server)
|
compute_client.servers, parsed_args.server)
|
||||||
|
|
||||||
# If parsed_args.image is not set, default to the currently used one.
|
# 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_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)
|
server = server.rebuild(image, parsed_args.password)
|
||||||
if parsed_args.wait:
|
if parsed_args.wait:
|
||||||
@ -1186,7 +1189,7 @@ class RebuildServer(command.ShowOne):
|
|||||||
sys.stdout.write(_('Error rebuilding server\n'))
|
sys.stdout.write(_('Error rebuilding server\n'))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
details = _prep_server_detail(compute_client, server)
|
details = _prep_server_detail(compute_client, image_client, server)
|
||||||
return zip(*sorted(six.iteritems(details)))
|
return zip(*sorted(six.iteritems(details)))
|
||||||
|
|
||||||
|
|
||||||
@ -1561,7 +1564,8 @@ class ShowServer(command.ShowOne):
|
|||||||
sys.stderr.write(_("Error retrieving diagnostics data\n"))
|
sys.stderr.write(_("Error retrieving diagnostics data\n"))
|
||||||
return ({}, {})
|
return ({}, {})
|
||||||
else:
|
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)))
|
return zip(*sorted(six.iteritems(data)))
|
||||||
|
|
||||||
|
@ -36,10 +36,6 @@ class TestServer(compute_fakes.TestComputev2):
|
|||||||
self.servers_mock = self.app.client_manager.compute.servers
|
self.servers_mock = self.app.client_manager.compute.servers
|
||||||
self.servers_mock.reset_mock()
|
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
|
# Get a shortcut to the compute client FlavorManager Mock
|
||||||
self.flavors_mock = self.app.client_manager.compute.flavors
|
self.flavors_mock = self.app.client_manager.compute.flavors
|
||||||
self.flavors_mock.reset_mock()
|
self.flavors_mock.reset_mock()
|
||||||
@ -259,7 +255,7 @@ class TestServerCreate(TestServer):
|
|||||||
self.servers_mock.create.return_value = self.new_server
|
self.servers_mock.create.return_value = self.new_server
|
||||||
|
|
||||||
self.image = image_fakes.FakeImage.create_one_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
|
||||||
|
|
||||||
self.flavor = compute_fakes.FakeFlavor.create_one_flavor()
|
self.flavor = compute_fakes.FakeFlavor.create_one_flavor()
|
||||||
self.flavors_mock.get.return_value = self.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.servers_mock.list.return_value = self.servers
|
||||||
|
|
||||||
self.image = image_fakes.FakeImage.create_one_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
|
||||||
|
|
||||||
self.flavor = compute_fakes.FakeFlavor.create_one_flavor()
|
self.flavor = compute_fakes.FakeFlavor.create_one_flavor()
|
||||||
self.flavors_mock.get.return_value = self.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)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
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.search_opts['image'] = self.image.id
|
||||||
self.servers_mock.list.assert_called_with(**self.kwargs)
|
self.servers_mock.list.assert_called_with(**self.kwargs)
|
||||||
@ -1019,7 +1015,7 @@ class TestServerRebuild(TestServer):
|
|||||||
|
|
||||||
# Return value for utils.find_resource for image
|
# Return value for utils.find_resource for image
|
||||||
self.image = image_fakes.FakeImage.create_one_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.
|
# Fake the rebuilt new server.
|
||||||
new_server = compute_fakes.FakeServer.create_one_server()
|
new_server = compute_fakes.FakeServer.create_one_server()
|
||||||
@ -1059,7 +1055,7 @@ class TestServerRebuild(TestServer):
|
|||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.servers_mock.get.assert_called_with(self.server.id)
|
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)
|
self.server.rebuild.assert_called_with(self.image, None)
|
||||||
|
|
||||||
def test_rebuild_with_current_image_and_password(self):
|
def test_rebuild_with_current_image_and_password(self):
|
||||||
@ -1078,7 +1074,7 @@ class TestServerRebuild(TestServer):
|
|||||||
self.cmd.take_action(parsed_args)
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.servers_mock.get.assert_called_with(self.server.id)
|
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)
|
self.server.rebuild.assert_called_with(self.image, password)
|
||||||
|
|
||||||
@mock.patch.object(common_utils, 'wait_for_status', return_value=True)
|
@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.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)
|
self.server.rebuild.assert_called_with(self.image, None)
|
||||||
|
|
||||||
@mock.patch.object(common_utils, 'wait_for_status', return_value=False)
|
@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.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)
|
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()
|
# This is the return value for utils.find_resource()
|
||||||
self.servers_mock.get.return_value = self.server
|
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
|
self.flavors_mock.get.return_value = self.flavor
|
||||||
|
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
@ -1986,6 +1982,7 @@ class TestServerGeneral(TestServer):
|
|||||||
# Call _prep_server_detail().
|
# Call _prep_server_detail().
|
||||||
server_detail = server._prep_server_detail(
|
server_detail = server._prep_server_detail(
|
||||||
self.app.client_manager.compute,
|
self.app.client_manager.compute,
|
||||||
|
self.app.client_manager.image,
|
||||||
_server
|
_server
|
||||||
)
|
)
|
||||||
# 'networks' is used to create _server. Remove it.
|
# 'networks' is used to create _server. Remove it.
|
||||||
|
Loading…
Reference in New Issue
Block a user