Merge "Update scheduler to use image-traits"

This commit is contained in:
Zuul 2018-06-29 07:18:55 +00:00 committed by Gerrit Code Review
commit 89baac0310
2 changed files with 21 additions and 18 deletions

View File

@ -1527,6 +1527,8 @@ class CinderFixtureNewAttachFlow(fixtures.Fixture):
# This represents a bootable image-backed volume to test
# boot-from-volume scenarios.
IMAGE_BACKED_VOL = '6ca404f3-d844-4169-bb96-bc792f37de98'
# This represents a bootable image-backed volume with required traits
# as part of volume image metadata
IMAGE_WITH_TRAITS_BACKED_VOL = '6194fc02-c60e-4a01-a8e5-600798208b5f'
def __init__(self, test):
@ -1606,8 +1608,8 @@ class CinderFixtureNewAttachFlow(fixtures.Fixture):
}
# Check for our special image-backed volume.
if (volume_id == self.IMAGE_BACKED_VOL or
volume_id == self.IMAGE_WITH_TRAITS_BACKED_VOL):
if volume_id in (self.IMAGE_BACKED_VOL,
self.IMAGE_WITH_TRAITS_BACKED_VOL):
# Make it a bootable volume.
volume['bootable'] = True
if volume_id == self.IMAGE_BACKED_VOL:
@ -1620,7 +1622,6 @@ class CinderFixtureNewAttachFlow(fixtures.Fixture):
# Add the image_id metadata with traits.
volume['volume_image_metadata'] = {
'image_id': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
"container_format": "ami",
"trait:HW_CPU_X86_SGX": "required",
}

View File

@ -3530,9 +3530,10 @@ class TraitsBasedSchedulingTest(integrated_helpers.ProviderUsageBaseTestCase):
flavor_id=flavor_id, networks='none')
return self.api.post_server({'server': server_req})
def _create_server_with_volume(self, flavor_id, volume_id):
def _create_volume_backed_server_with_traits(self, flavor_id, volume_id):
"""Create a server with block device mapping(volume) with the given
flavor and volume id's
flavor and volume id's. Either the flavor or the image backing the
volume is expected to have the traits
:param flavor_id: the flavor id
:param volume_id: the volume id
:return: create server response
@ -3544,8 +3545,7 @@ class TraitsBasedSchedulingTest(integrated_helpers.ProviderUsageBaseTestCase):
'flavorRef': flavor_id,
'name': 'test_image_trait_on_volume_backed',
# We don't care about networking for this test. This
# requires
# microversion >= 2.37.
# requires microversion >= 2.37.
'networks': 'none',
'block_device_mapping_v2': [{
'boot_index': 0,
@ -3615,8 +3615,9 @@ class TraitsBasedSchedulingTest(integrated_helpers.ProviderUsageBaseTestCase):
def test_image_trait_on_volume_backed_instance(self):
"""Tests that when trying to launch a volume-backed instance with a
required trait on the image, the instance ends up on the single compute
node resource provider that also has that trait in Placement.
required trait on the image metadata contained within the volume,
the instance ends up on the single compute node resource provider
that also has that trait in Placement.
"""
# Decorate compute2 resource provider with volume image metadata trait.
rp_uuid = self._get_provider_uuid_by_host(self.compute2.host)
@ -3625,7 +3626,7 @@ class TraitsBasedSchedulingTest(integrated_helpers.ProviderUsageBaseTestCase):
self.useFixture(nova_fixtures.CinderFixtureNewAttachFlow(self))
# Create our server with a volume containing the image meta data with a
# required trait
server = self._create_server_with_volume(
server = self._create_volume_backed_server_with_traits(
self.flavor_without_trait['id'],
nova_fixtures.CinderFixtureNewAttachFlow.
IMAGE_WITH_TRAITS_BACKED_VOL)
@ -3637,11 +3638,11 @@ class TraitsBasedSchedulingTest(integrated_helpers.ProviderUsageBaseTestCase):
def test_flavor_image_trait_on_volume_backed_instance(self):
"""Tests that when trying to launch a volume-backed instance with a
required trait on flavor AND a required trait on the image,
the instance ends up on the single compute node resource provider that
also has those traits in Placement.
required trait on flavor AND a required trait on the image metadata
contained within the volume, the instance ends up on the single
compute node resource provider that also has those traits in Placement.
"""
# Decorate compute2 resource provider with volume image metadatz trait.
# Decorate compute2 resource provider with volume image metadata trait.
rp_uuid = self._get_provider_uuid_by_host(self.compute2.host)
self._set_provider_traits(rp_uuid, ['HW_CPU_X86_VMX',
'HW_CPU_X86_SGX'])
@ -3649,7 +3650,7 @@ class TraitsBasedSchedulingTest(integrated_helpers.ProviderUsageBaseTestCase):
self.useFixture(nova_fixtures.CinderFixtureNewAttachFlow(self))
# Create our server with a flavor trait and a volume containing the
# image meta data with a required trait
server = self._create_server_with_volume(
server = self._create_volume_backed_server_with_traits(
self.flavor_with_trait['id'],
nova_fixtures.CinderFixtureNewAttachFlow.
IMAGE_WITH_TRAITS_BACKED_VOL)
@ -3714,12 +3715,13 @@ class TraitsBasedSchedulingTest(integrated_helpers.ProviderUsageBaseTestCase):
def test_image_trait_on_volume_backed_instance_no_valid_host(self):
"""Tests that when trying to launch a volume-backed instance with a
required trait on the image fails to find a valid host since no compute
node resource providers have the trait.
required trait on the image metadata contained within the volume
fails to find a valid host since no compute node resource providers
have the trait.
"""
self.useFixture(nova_fixtures.CinderFixtureNewAttachFlow(self))
# Create our server with a volume
server = self._create_server_with_volume(
server = self._create_volume_backed_server_with_traits(
self.flavor_without_trait['id'],
nova_fixtures.CinderFixtureNewAttachFlow.
IMAGE_WITH_TRAITS_BACKED_VOL)