Cache boot time roles for vendordata.

Some external vendordata services want to provide metadata
based on the role of the user who started the instance. It
would be confusing if the metadata returned changed later
if the role of the user changed, so we cache the boot time
roles and then pass those to the external vendordata
service.

Change-Id: Ieb84c945f4f9a21c2b7b892f9b1ead84dca441e9
This commit is contained in:
Michael Still 2017-01-09 15:15:20 +11:00 committed by Stephen Finucane
parent 5ca61e4534
commit 6d8b58dc6f
4 changed files with 23 additions and 6 deletions

View File

@ -78,7 +78,9 @@ class DynamicVendorData(vendordata.VendorDataDriver):
'image-id': self.instance.image_ref,
'user-data': self.instance.user_data,
'hostname': self.instance.hostname,
'metadata': self.instance.metadata}
'metadata': self.instance.metadata,
'boot-roles': self.instance.system_metadata.get(
'boot_roles', '')}
headers = {'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'openstack-nova-vendordata'}

View File

@ -1887,6 +1887,11 @@ class ComputeManager(manager.Manager):
action=fields.NotificationAction.CREATE,
phase=fields.NotificationPhase.START)
# NOTE(mikal): cache the keystone roles associated with the instance
# at boot time for later reference
instance.system_metadata.update(
{'boot_roles': ','.join(context.roles)})
self._check_device_tagging(requested_networks, block_device_mapping)
try:

View File

@ -8232,12 +8232,14 @@ class ComputeAPITestCase(BaseTestCase):
self.assertEqual(instance.task_state, task_states.REBUILDING)
sys_meta = {k: v for k, v in instance.system_metadata.items()
if not k.startswith('instance_type')}
self.assertEqual(sys_meta,
self.assertEqual(
{'image_kernel_id': uuids.kernel_id,
'image_min_disk': '1',
'image_ramdisk_id': uuids.ramdisk_id,
'image_something_else': 'meow',
'preserved': 'preserve this!'})
'image_min_disk': '1',
'image_ramdisk_id': uuids.ramdisk_id,
'image_something_else': 'meow',
'preserved': 'preserve this!',
'boot_roles': ''},
sys_meta)
def test_rebuild(self):
self._test_rebuild(vm_state=vm_states.ACTIVE)

View File

@ -0,0 +1,8 @@
---
features:
- |
The vendordata metadata system now caches boot time roles. Some external
vendordata services want to provide metadata based on the role of the user
who started the instance. It would be confusing if the metadata returned
changed later if the role of the user changed, so we cache the boot time
roles and then pass those to the external vendordata service.