Add REBUILD option to user_data_update_policy

OS::Nova::Server supports it so here we add the heat support for it.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1802602

Change-Id: Ieb05ba6d6b670aff31f9f8c8debb86a6dd3b0245
This commit is contained in:
apetrich 2020-11-05 10:21:23 +01:00 committed by Rico Lin
parent 42b5f68bf0
commit 06071f5e9b
3 changed files with 43 additions and 3 deletions

View File

@ -548,11 +548,12 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
),
USER_DATA_UPDATE_POLICY: properties.Schema(
properties.Schema.STRING,
_('Policy on how to apply a user_data update; either by '
'ignoring it or by replacing the entire server.'),
_('Policy on how to apply a user_data update; by '
'ignoring it, by replacing the entire server, '
'or rebuild the server.'),
default='REPLACE',
constraints=[
constraints.AllowedValues(['REPLACE', 'IGNORE']),
constraints.AllowedValues(['REPLACE', 'IGNORE', 'REBUILD']),
],
support_status=support.SupportStatus(version='6.0.0'),
update_allowed=True
@ -1313,6 +1314,14 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
'kwargs': kwargs})
return prg
def _update_user_data_rebuild(self, after_props):
user_data = after_props[self.USER_DATA]
prg = progress.ServerUpdateProgress(
self.resource_id,
'rebuild',
handler_extra={'args': (user_data,)})
return prg
def _update_networks(self, server, after_props):
updaters = []
new_networks = after_props[self.NETWORKS]
@ -1404,6 +1413,12 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
if self.FLAVOR in prop_diff:
updaters.extend(self._update_flavor(after_props))
if self.USER_DATA in prop_diff:
# We only care about rebuild here. The standard replace is
# dealt elsewere
if after_props[self.USER_DATA_UPDATE_POLICY] == 'REBUILD':
updaters.append(self._update_user_data_rebuild(after_props))
if self.IMAGE in prop_diff:
updaters.append(self._update_image(after_props))
elif self.ADMIN_PASS in prop_diff:

View File

@ -2362,6 +2362,26 @@ class ServersTest(common.HeatTestCase):
scheduler.TaskRunner(server.update, update_template)()
self.assertEqual((server.UPDATE, server.COMPLETE), server.state)
@mock.patch.object(servers.Server, 'prepare_for_replace')
@mock.patch.object(nova.NovaClientPlugin, 'client')
def test_server_update_server_userdata_rebuild(self, mock_create,
mock_replace):
stack_name = 'update_udreplace'
(tmpl, stack) = self._setup_test_stack(stack_name)
self.patchobject(servers.Server, 'check_update_complete',
return_value=True)
resource_defns = tmpl.resource_definitions(stack)
server = servers.Server('server_update_userdata_ignore',
resource_defns['WebServer'], stack)
update_props = tmpl.t['Resources']['WebServer']['Properties'].copy()
update_props['user_data'] = 'changed'
update_props['user_data_update_policy'] = 'REBUILD'
update_template = server.t.freeze(properties=update_props)
updater = scheduler.TaskRunner(server.update, update_template)
self.assertRaises(resource.UpdateReplace, updater)
@mock.patch.object(servers.Server, 'prepare_for_replace')
def test_server_update_image_replace(self, mock_replace):
stack_name = 'update_imgrep'

View File

@ -0,0 +1,5 @@
---
features:
- |
Adding REBUILD option for user_data_update_policy so that
changes to user_data can be updated instead of a new create.