From 5d1762fec6a7d3f2eaa5f7e4e7ac048e77843cb0 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Tue, 15 Dec 2015 08:55:00 +1300 Subject: [PATCH] Build list of enabled os-collect-config collectors When changing the software_config_transport for an existing server, os-collect-config will continue using the data from the old transport which will become increasingly stale and will sometimes mask values from the new transport. The default list of collectors in os-collect-config is: heat_local, ec2, cfn, heat, request, local, zaqar This change explicitly enables these collectors: ec2, , local ``ec2`` is the nova metadata service, so should always be enabled. ``local`` allows local file overrides - this is generally unused but is enabled for users who choose to use it for additional config data, or to override the heat provided data. ``heat_local`` is only used on the first run of an unconfigured os-collect-config for bootstrapping its own config file, so it can and should be disabled for subsequent polling. Change-Id: I9cdb057212c7a4404f6966a55cde9eab5ad86759 Closes-Bug: #1523676 --- .../engine/resources/openstack/nova/server.py | 30 ++++++++++++++----- heat/tests/openstack/nova/test_server.py | 24 +++++++++++---- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/heat/engine/resources/openstack/nova/server.py b/heat/engine/resources/openstack/nova/server.py index 1140814ae7..cc20d1d748 100644 --- a/heat/engine/resources/openstack/nova/server.py +++ b/heat/engine/resources/openstack/nova/server.py @@ -580,6 +580,9 @@ class Server(stack_user.StackUser, sh.SchedulerHintsMixin, meta['deployments'] = meta.get('deployments', []) meta['os-collect-config'] = meta.get('os-collect-config', {}) occ = meta['os-collect-config'] + collectors = ['ec2'] + occ['collectors'] = collectors + # set existing values to None to override any boot-time config occ_keys = ('heat', 'zaqar', 'cfn', 'request') for occ_key in occ_keys: @@ -597,21 +600,18 @@ class Server(stack_user.StackUser, sh.SchedulerHintsMixin, 'project_id': self.stack.stack_user_project_id, 'stack_id': self.stack.identifier().stack_path(), 'resource_name': self.name}}) + collectors.append('heat') elif self.transport_zaqar_message(props): queue_id = self.physical_resource_name() self.data_set('metadata_queue_id', queue_id) - zaqar_plugin = self.client_plugin('zaqar') - zaqar = zaqar_plugin.create_for_tenant( - self.stack.stack_user_project_id, self._user_token()) - queue = zaqar.queue(queue_id) occ.update({'zaqar': { 'user_id': self._get_user_id(), 'password': self.password, 'auth_url': self.context.auth_url, 'project_id': self.stack.stack_user_project_id, 'queue_id': queue_id}}) - queue.post({'body': meta, 'ttl': zaqar_plugin.DEFAULT_TTL}) + collectors.append('zaqar') elif self.transport_poll_server_cfn(props): heat_client_plugin = self.stack.clients.client_plugin('heat') @@ -622,6 +622,7 @@ class Server(stack_user.StackUser, sh.SchedulerHintsMixin, 'secret_access_key': self.secret_key, 'stack_name': self.stack.name, 'path': '%s.Metadata' % self.name}}) + collectors.append('cfn') elif self.transport_poll_temp_url(props): container = self.physical_resource_name() @@ -638,13 +639,28 @@ class Server(stack_user.StackUser, sh.SchedulerHintsMixin, self.data_set('metadata_put_url', put_url) self.data_set('metadata_object_name', object_name) + collectors.append('request') occ.update({'request': { 'metadata_url': url}}) + + collectors.append('local') + self.metadata_set(meta) + + # push replacement polling config to any existing push-based sources + queue_id = self.data().get('metadata_queue_id') + if queue_id: + zaqar_plugin = self.client_plugin('zaqar') + zaqar = zaqar_plugin.create_for_tenant( + self.stack.stack_user_project_id, self._user_token()) + queue = zaqar.queue(queue_id) + queue.post({'body': meta, 'ttl': zaqar_plugin.DEFAULT_TTL}) + + object_name = self.data().get('metadata_object_name') + if object_name: + container = self.physical_resource_name() self.client('swift').put_object( container, object_name, jsonutils.dumps(meta)) - self.metadata_set(meta) - def _register_access_key(self): """Access is limited to this resource, which created the keypair.""" def access_allowed(resource_name): diff --git a/heat/tests/openstack/nova/test_server.py b/heat/tests/openstack/nova/test_server.py index 62f49cc7a0..dcfa879d68 100644 --- a/heat/tests/openstack/nova/test_server.py +++ b/heat/tests/openstack/nova/test_server.py @@ -772,7 +772,8 @@ class ServersTest(common.HeatTestCase): 'path': 'WebServer.Metadata', 'secret_access_key': '8901', 'stack_name': 'software_config_s' - } + }, + 'collectors': ['ec2', 'cfn', 'local'] }, 'deployments': [] }, server.metadata_get()) @@ -792,6 +793,7 @@ class ServersTest(common.HeatTestCase): 'secret_access_key': '8901', 'stack_name': 'software_config_s' }, + 'collectors': ['ec2', 'cfn', 'local'], 'polling_interval': 10 }, 'deployments': [] @@ -853,7 +855,8 @@ class ServersTest(common.HeatTestCase): 'resource_name': 'WebServer', 'stack_id': 'software_config_s/%s' % stack.id, 'user_id': '1234' - } + }, + 'collectors': ['ec2', 'heat', 'local'] }, 'deployments': [] }, server.metadata_get()) @@ -872,6 +875,7 @@ class ServersTest(common.HeatTestCase): 'stack_id': 'software_config_s/%s' % stack.id, 'user_id': '1234' }, + 'collectors': ['ec2', 'heat', 'local'], 'polling_interval': 10 }, 'deployments': [] @@ -933,6 +937,8 @@ class ServersTest(common.HeatTestCase): server.physical_resource_name(), object_name) self.assertEqual(test_path, urlparse.urlparse(metadata_put_url).path) self.assertEqual(test_path, urlparse.urlparse(metadata_url).path) + sc.put_object.assert_called_once_with( + container_name, object_name, jsonutils.dumps(md)) sc.head_container.return_value = {'x-container-object-count': '0'} server._delete_temp_url() @@ -951,7 +957,8 @@ class ServersTest(common.HeatTestCase): 'os-collect-config': { 'request': { 'metadata_url': metadata_url - } + }, + 'collectors': ['ec2', 'request', 'local'] }, 'deployments': [] }, server.metadata_get()) @@ -966,6 +973,7 @@ class ServersTest(common.HeatTestCase): 'request': { 'metadata_url': metadata_url }, + 'collectors': ['ec2', 'request', 'local'], 'polling_interval': 10 }, 'deployments': [] @@ -1041,7 +1049,8 @@ class ServersTest(common.HeatTestCase): 'auth_url': 'http://server.test:5000/v2.0', 'project_id': '8888', 'queue_id': queue_id - } + }, + 'collectors': ['ec2', 'zaqar', 'local'] }, 'deployments': [] }, server.metadata_get()) @@ -1058,6 +1067,7 @@ class ServersTest(common.HeatTestCase): 'project_id': '8888', 'queue_id': queue_id }, + 'collectors': ['ec2', 'zaqar', 'local'], 'polling_interval': 10 }, 'deployments': [] @@ -1670,7 +1680,8 @@ class ServersTest(common.HeatTestCase): 'path': 'WebServer.Metadata', 'secret_access_key': '8901', 'stack_name': 'update_meta_sc' - } + }, + 'collectors': ['ec2', 'cfn', 'local'] }, 'deployments': []} self.assertEqual(expected_md, server.metadata_get()) @@ -1706,6 +1717,7 @@ class ServersTest(common.HeatTestCase): 'secret_access_key': '8901', 'stack_name': 'update_meta_sc' }, + 'collectors': ['ec2', 'cfn', 'local'], 'polling_interval': 10 }, 'deployments': []} @@ -1741,6 +1753,7 @@ class ServersTest(common.HeatTestCase): 'secret_access_key': '8901', 'stack_name': 'update_meta_sc' }, + 'collectors': ['ec2', 'cfn', 'local'], 'polling_interval': 10 }, 'deployments': []} @@ -1787,6 +1800,7 @@ class ServersTest(common.HeatTestCase): 'request': { 'metadata_url': 'the_url', }, + 'collectors': ['ec2', 'request', 'local'], 'polling_interval': 10 }, 'deployments': []}