Merge "Add os_collect_config attribute to server resources"
This commit is contained in:
commit
46e42c5184
@ -19,6 +19,7 @@ from heat.engine import attributes
|
|||||||
from heat.engine import constraints
|
from heat.engine import constraints
|
||||||
from heat.engine import properties
|
from heat.engine import properties
|
||||||
from heat.engine.resources import server_base
|
from heat.engine.resources import server_base
|
||||||
|
from heat.engine import support
|
||||||
|
|
||||||
cfg.CONF.import_opt('default_software_config_transport', 'heat.common.config')
|
cfg.CONF.import_opt('default_software_config_transport', 'heat.common.config')
|
||||||
cfg.CONF.import_opt('default_user_data_format', 'heat.common.config')
|
cfg.CONF.import_opt('default_user_data_format', 'heat.common.config')
|
||||||
@ -81,16 +82,23 @@ class DeployedServer(server_base.BaseServer):
|
|||||||
}
|
}
|
||||||
|
|
||||||
ATTRIBUTES = (
|
ATTRIBUTES = (
|
||||||
NAME_ATTR
|
NAME_ATTR, OS_COLLECT_CONFIG
|
||||||
) = (
|
) = (
|
||||||
'name'
|
'name', 'os_collect_config'
|
||||||
)
|
)
|
||||||
|
|
||||||
attributes_schema = {
|
attributes_schema = {
|
||||||
NAME_ATTR: attributes.Schema(
|
NAME_ATTR: attributes.Schema(
|
||||||
_('Name of the server.'),
|
_('Name of the server.'),
|
||||||
type=attributes.Schema.STRING
|
type=attributes.Schema.STRING
|
||||||
)
|
),
|
||||||
|
OS_COLLECT_CONFIG: attributes.Schema(
|
||||||
|
_('The os-collect-config configuration for the server''s local '
|
||||||
|
'agent to be configured to connect to Heat to retrieve '
|
||||||
|
'deployment data.'),
|
||||||
|
type=attributes.Schema.MAP,
|
||||||
|
support_status=support.SupportStatus(version='9.0.0')
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, name, json_snippet, stack):
|
def __init__(self, name, json_snippet, stack):
|
||||||
|
@ -137,10 +137,12 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
|
|||||||
|
|
||||||
ATTRIBUTES = (
|
ATTRIBUTES = (
|
||||||
NAME_ATTR, ADDRESSES, NETWORKS_ATTR, FIRST_ADDRESS,
|
NAME_ATTR, ADDRESSES, NETWORKS_ATTR, FIRST_ADDRESS,
|
||||||
INSTANCE_NAME, ACCESSIPV4, ACCESSIPV6, CONSOLE_URLS, TAGS_ATTR
|
INSTANCE_NAME, ACCESSIPV4, ACCESSIPV6, CONSOLE_URLS, TAGS_ATTR,
|
||||||
|
OS_COLLECT_CONFIG
|
||||||
) = (
|
) = (
|
||||||
'name', 'addresses', 'networks', 'first_address',
|
'name', 'addresses', 'networks', 'first_address',
|
||||||
'instance_name', 'accessIPv4', 'accessIPv6', 'console_urls', 'tags'
|
'instance_name', 'accessIPv4', 'accessIPv6', 'console_urls', 'tags',
|
||||||
|
'os_collect_config'
|
||||||
)
|
)
|
||||||
|
|
||||||
# valid image Status
|
# valid image Status
|
||||||
@ -637,7 +639,14 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
|
|||||||
_('Tags from the server. Supported since client version 2.26.'),
|
_('Tags from the server. Supported since client version 2.26.'),
|
||||||
support_status=support.SupportStatus(version='8.0.0'),
|
support_status=support.SupportStatus(version='8.0.0'),
|
||||||
type=attributes.Schema.LIST
|
type=attributes.Schema.LIST
|
||||||
)
|
),
|
||||||
|
OS_COLLECT_CONFIG: attributes.Schema(
|
||||||
|
_('The os-collect-config configuration for the server''s local '
|
||||||
|
'agent to be configured to connect to Heat to retrieve '
|
||||||
|
'deployment data.'),
|
||||||
|
support_status=support.SupportStatus(version='9.0.0'),
|
||||||
|
type=attributes.Schema.MAP
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
default_client_name = 'nova'
|
default_client_name = 'nova'
|
||||||
@ -1051,6 +1060,8 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
|
|||||||
if name == self.FIRST_ADDRESS:
|
if name == self.FIRST_ADDRESS:
|
||||||
return self.client_plugin().server_to_ipaddress(
|
return self.client_plugin().server_to_ipaddress(
|
||||||
self.resource_id) or ''
|
self.resource_id) or ''
|
||||||
|
if name == self.OS_COLLECT_CONFIG:
|
||||||
|
return self.metadata_get().get('os-collect-config', {})
|
||||||
if name == self.NAME_ATTR:
|
if name == self.NAME_ATTR:
|
||||||
return self._server_name()
|
return self._server_name()
|
||||||
try:
|
try:
|
||||||
|
@ -18,6 +18,7 @@ from oslo_log import log as logging
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
|
from heat.engine import attributes
|
||||||
from heat.engine.clients import progress
|
from heat.engine.clients import progress
|
||||||
from heat.engine.resources import stack_user
|
from heat.engine.resources import stack_user
|
||||||
|
|
||||||
@ -129,6 +130,8 @@ class BaseServer(stack_user.StackUser):
|
|||||||
self.client('swift').put_object(
|
self.client('swift').put_object(
|
||||||
container, object_name, jsonutils.dumps(meta))
|
container, object_name, jsonutils.dumps(meta))
|
||||||
|
|
||||||
|
self.attributes.reset_resolved_values()
|
||||||
|
|
||||||
def _create_transport_credentials(self, props):
|
def _create_transport_credentials(self, props):
|
||||||
if self.transport_poll_server_cfn(props):
|
if self.transport_poll_server_cfn(props):
|
||||||
self._create_user()
|
self._create_user()
|
||||||
@ -184,6 +187,8 @@ class BaseServer(stack_user.StackUser):
|
|||||||
return
|
return
|
||||||
if name == self.NAME_ATTR:
|
if name == self.NAME_ATTR:
|
||||||
return self._server_name()
|
return self._server_name()
|
||||||
|
if name == self.OS_COLLECT_CONFIG:
|
||||||
|
return self.metadata_get().get('os-collect-config', {})
|
||||||
|
|
||||||
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
|
||||||
if tmpl_diff.metadata_changed():
|
if tmpl_diff.metadata_changed():
|
||||||
@ -307,3 +312,17 @@ class BaseServer(stack_user.StackUser):
|
|||||||
def check_delete_complete(self, prg):
|
def check_delete_complete(self, prg):
|
||||||
if not prg:
|
if not prg:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _show_resource(self):
|
||||||
|
rsrc_dict = super(BaseServer, self)._show_resource()
|
||||||
|
rsrc_dict.setdefault(
|
||||||
|
self.OS_COLLECT_CONFIG,
|
||||||
|
self.metadata_get().get('os-collect-config', {}))
|
||||||
|
return rsrc_dict
|
||||||
|
|
||||||
|
def get_attribute(self, key, *path):
|
||||||
|
if key == self.OS_COLLECT_CONFIG:
|
||||||
|
occ = self.metadata_get().get('os-collect-config', {})
|
||||||
|
return attributes.select_from_attribute(occ, path)
|
||||||
|
else:
|
||||||
|
return super(BaseServer, self).get_attribute(key, *path)
|
||||||
|
@ -349,3 +349,18 @@ class DeployedServersTest(common.HeatTestCase):
|
|||||||
},
|
},
|
||||||
'deployments': []
|
'deployments': []
|
||||||
}, server.metadata_get())
|
}, server.metadata_get())
|
||||||
|
|
||||||
|
def test_resolve_attribute_os_collect_config(self):
|
||||||
|
metadata_url, server = (
|
||||||
|
self._server_create_software_config_poll_temp_url())
|
||||||
|
|
||||||
|
# FnGetAtt usage belows requires the resource to have a stack set
|
||||||
|
(tmpl, stack) = self._setup_test_stack('stack_name')
|
||||||
|
server.stack = stack
|
||||||
|
|
||||||
|
self.assertEqual({
|
||||||
|
'request': {
|
||||||
|
'metadata_url': metadata_url
|
||||||
|
},
|
||||||
|
'collectors': ['request', 'local']
|
||||||
|
}, server.FnGetAtt('os_collect_config'))
|
||||||
|
@ -394,6 +394,7 @@ class ServersTest(common.HeatTestCase):
|
|||||||
def test_server_create(self):
|
def test_server_create(self):
|
||||||
return_server = self.fc.servers.list()[1]
|
return_server = self.fc.servers.list()[1]
|
||||||
return_server.id = '5678'
|
return_server.id = '5678'
|
||||||
|
return_server._info['os_collect_config'] = {}
|
||||||
server_name = 'test_server_create'
|
server_name = 'test_server_create'
|
||||||
stack_name = '%s_s' % server_name
|
stack_name = '%s_s' % server_name
|
||||||
server = self._create_test_server(return_server, server_name)
|
server = self._create_test_server(return_server, server_name)
|
||||||
@ -444,6 +445,7 @@ class ServersTest(common.HeatTestCase):
|
|||||||
if server.attributes._resolved_values.get('tags'):
|
if server.attributes._resolved_values.get('tags'):
|
||||||
del server.attributes._resolved_values['tags']
|
del server.attributes._resolved_values['tags']
|
||||||
self.assertIsNone(server.FnGetAtt('tags'))
|
self.assertIsNone(server.FnGetAtt('tags'))
|
||||||
|
self.assertEqual({}, server.FnGetAtt('os_collect_config'))
|
||||||
|
|
||||||
def test_server_create_metadata(self):
|
def test_server_create_metadata(self):
|
||||||
stack_name = 'create_metadata_test_stack'
|
stack_name = 'create_metadata_test_stack'
|
||||||
@ -789,6 +791,22 @@ class ServersTest(common.HeatTestCase):
|
|||||||
'deployments': []
|
'deployments': []
|
||||||
}, server.metadata_get())
|
}, server.metadata_get())
|
||||||
|
|
||||||
|
@mock.patch.object(heat_plugin.HeatClientPlugin, 'url_for')
|
||||||
|
def test_resolve_attribute_os_collect_config(self, fake_url):
|
||||||
|
fake_url.return_value = 'the-cfn-url'
|
||||||
|
server = self._server_create_software_config()
|
||||||
|
|
||||||
|
self.assertEqual({
|
||||||
|
'cfn': {
|
||||||
|
'access_key_id': '4567',
|
||||||
|
'metadata_url': 'the-cfn-url/v1/',
|
||||||
|
'path': 'WebServer.Metadata',
|
||||||
|
'secret_access_key': '8901',
|
||||||
|
'stack_name': 'software_config_s'
|
||||||
|
},
|
||||||
|
'collectors': ['ec2', 'cfn', 'local']
|
||||||
|
}, server.FnGetAtt('os_collect_config'))
|
||||||
|
|
||||||
@mock.patch.object(heat_plugin.HeatClientPlugin, 'url_for')
|
@mock.patch.object(heat_plugin.HeatClientPlugin, 'url_for')
|
||||||
def test_server_create_software_config_metadata(self, fake_url):
|
def test_server_create_software_config_metadata(self, fake_url):
|
||||||
md = {'os-collect-config': {'polling_interval': 10}}
|
md = {'os-collect-config': {'polling_interval': 10}}
|
||||||
|
Loading…
Reference in New Issue
Block a user