diff options
author | Zuul <zuul@review.opendev.org> | 2022-06-23 06:37:35 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-06-23 06:37:35 +0000 |
commit | c37ea72a6b2c424136ed2ee2cd378928021da78e (patch) | |
tree | 604d663d45fd6f64ac71282e05614613236d08a6 | |
parent | a25bcb3121c4c994e135a4316d7d08626daa926b (diff) | |
parent | 06071f5e9b518680e84cc58a4bd5a4e6d164d358 (diff) | |
download | heat-c37ea72a6b2c424136ed2ee2cd378928021da78e.tar.gz |
Merge "Add REBUILD option to user_data_update_policy"
3 files changed, 43 insertions, 3 deletions
diff --git a/heat/engine/resources/openstack/nova/server.py b/heat/engine/resources/openstack/nova/server.py index 7fdd31e4d..6cb782a4a 100644 --- a/heat/engine/resources/openstack/nova/server.py +++ b/heat/engine/resources/openstack/nova/server.py @@ -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: diff --git a/heat/tests/openstack/nova/test_server.py b/heat/tests/openstack/nova/test_server.py index 529a22d57..1ed657ff2 100644 --- a/heat/tests/openstack/nova/test_server.py +++ b/heat/tests/openstack/nova/test_server.py @@ -2363,6 +2363,26 @@ class ServersTest(common.HeatTestCase): 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' (tmpl, stack) = self._setup_test_stack(stack_name) diff --git a/releasenotes/notes/add-rebuild-for-user_data_update_policy-b1a229f3f551ea4b.yaml b/releasenotes/notes/add-rebuild-for-user_data_update_policy-b1a229f3f551ea4b.yaml new file mode 100644 index 000000000..70aee6684 --- /dev/null +++ b/releasenotes/notes/add-rebuild-for-user_data_update_policy-b1a229f3f551ea4b.yaml @@ -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. |