Skip to content

Commit

Permalink
Handle volume-backed instances in IsolatedHostsFilter
Browse files Browse the repository at this point in the history
The RequestSpec.image object for a volume-backed instance will
not have the 'id' attribute set because the
nova.utils.get_image_metadata_from_volume() method doesn't convert
the volume['volume_image_metadata']['image_id'] into the ImageMeta.id
field. It is unclear if there are intentional reasons for omitting
this information, but the IsolatedHostsFilter has just never supported
filtering for volume-backed instances based on a provided image id.

The logic within the filter depends on the
restrict_isolated_hosts_to_isolated_images config option, which
defaults to True. When True, a volume-backed instance will not be
put on an isolated host. When False, a volume-backed instance can
go on any host, isolated or not.

Again, it's unclear if we should actually be filtering volume-backed
servers using the image_id from the volume_image_metadata or not,
but it's not what we've historically done so this change simply
fixes the regression bug.

Change-Id: Ieb8abb1a3f04ce008f9617e051e4d720dbe6917a
Closes-Bug: #1746483
  • Loading branch information
mriedem committed Feb 11, 2018
1 parent 4f9667b commit 0a7427d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion nova/scheduler/filters/isolated_hosts_filter.py
Expand Up @@ -59,7 +59,10 @@ def host_passes(self, host_state, spec_obj):
return ((not restrict_isolated_hosts_to_isolated_images) or
(host_state.host not in isolated_hosts))

image_ref = spec_obj.image.id if spec_obj.image else None
# Check to see if the image id is set since volume-backed instances
# can be created without an imageRef in the server create request.
image_ref = spec_obj.image.id \
if spec_obj.image and 'id' in spec_obj.image else None
image_isolated = image_ref in isolated_images
host_isolated = host_state.host in isolated_hosts

Expand Down
12 changes: 8 additions & 4 deletions nova/tests/functional/regressions/test_bug_1746483.py
Expand Up @@ -92,7 +92,11 @@ def test_boot_from_volume_with_isolated_image(self):
# networks='none'.
with utils.temporary_mutation(self.api, microversion='2.37'):
server = self.api.post_server(server_req_body)
server = self._wait_for_state_change(self.api, server, 'ERROR')
# Due to bug 1746483 we expect scheduling to fail.
self.assertIn("Cannot load 'id' in the base class",
server['fault']['message'])
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
# NOTE(mriedem): The instance is successfully scheduled but since
# the image_id from the volume_image_metadata isn't stored in the
# RequestSpec.image.id, and restrict_isolated_hosts_to_isolated_images
# is True, the isolated host (host1) is filtered out because the
# filter doesn't have enough information to know if the image within
# the volume can be used on that host.
self.assertEqual('host2', server['OS-EXT-SRV-ATTR:host'])

0 comments on commit 0a7427d

Please sign in to comment.