26
26
Example Run
27
27
-----------
28
28
29
+ .. warning::
30
+
31
+ We advice not to run tempest cleanup on production environments.
32
+
29
33
.. warning::
30
34
31
35
If step 1 is skipped in the example below, the cleanup procedure
45
49
* ``--init-saved-state``: Initializes the saved state of the OpenStack
46
50
deployment and will output a ``saved_state.json`` file containing resources
47
51
from your deployment that will be preserved from the cleanup command. This
48
- should be done prior to running Tempest tests.
52
+ should be done prior to running Tempest tests. Note, that if other users of
53
+ your cloud could have created resources after running ``--init-saved-state``,
54
+ it would not protect those resources as they wouldn't be present in the
55
+ saved_state.json file.
49
56
50
57
* ``--delete-tempest-conf-objects``: If option is present, then the command
51
58
will delete the admin project in addition to the resources associated with
58
65
global objects that will be removed (domains, flavors, images, roles,
59
66
projects, and users). Once the cleanup command is executed (e.g. run without
60
67
parameters), running it again with ``--dry-run`` should yield an empty
61
- report.
68
+ report. We STRONGLY ENCOURAGE to run ``tempest cleanup`` with ``--dry-run``
69
+ first and then verify that the resources listed in the ``dry_run.json`` file
70
+ are meant to be deleted.
71
+
72
+ * ``--prefix``: Only resources that match the prefix will be deleted. When this
73
+ option is used, ``saved_state.json`` file is not needed (no need to run with
74
+ ``--init-saved-state`` first).
75
+
76
+ All tempest resources are created with the prefix value from the config
77
+ option ``resource_name_prefix`` in tempest.conf. To cleanup only the
78
+ resources created by tempest, you should use the prefix set in your
79
+ tempest.conf (the default value of ``resource_name_prefix`` is ``tempest``.
80
+
81
+ Note, that some resources are not named thus they will not be deleted when
82
+ filtering based on the prefix. This option will be ignored when
83
+ ``--init-saved-state`` is used so that it can capture the true init state -
84
+ all resources present at that moment. If there is any ``saved_state.json``
85
+ file present (e.g. if you ran the tempest cleanup with ``--init-saved-state``
86
+ before) and you run the tempest cleanup with ``--prefix``, the
87
+ ``saved_state.json`` file will be ignored and cleanup will be done based on
88
+ the passed prefix only.
62
89
63
90
* ``--help``: Print the help text for the command and parameters.
64
91
@@ -157,6 +184,7 @@ def _cleanup(self):
157
184
is_dry_run = self .options .dry_run
158
185
is_preserve = not self .options .delete_tempest_conf_objects
159
186
is_save_state = False
187
+ cleanup_prefix = self .options .prefix
160
188
161
189
if is_dry_run :
162
190
self .dry_run_data ["_projects_to_clean" ] = {}
@@ -168,7 +196,8 @@ def _cleanup(self):
168
196
'is_dry_run' : is_dry_run ,
169
197
'saved_state_json' : self .json_data ,
170
198
'is_preserve' : False ,
171
- 'is_save_state' : is_save_state }
199
+ 'is_save_state' : is_save_state ,
200
+ 'prefix' : cleanup_prefix }
172
201
project_service = cleanup_service .ProjectService (admin_mgr , ** kwargs )
173
202
projects = project_service .list ()
174
203
LOG .info ("Processing %s projects" , len (projects ))
@@ -182,6 +211,7 @@ def _cleanup(self):
182
211
'saved_state_json' : self .json_data ,
183
212
'is_preserve' : is_preserve ,
184
213
'is_save_state' : is_save_state ,
214
+ 'prefix' : cleanup_prefix ,
185
215
'got_exceptions' : self .GOT_EXCEPTIONS }
186
216
LOG .info ("Processing global services" )
187
217
for service in self .global_services :
@@ -206,6 +236,7 @@ def _clean_project(self, project):
206
236
project_id = project ['id' ]
207
237
project_name = project ['name' ]
208
238
project_data = None
239
+ cleanup_prefix = self .options .prefix
209
240
if is_dry_run :
210
241
project_data = dry_run_data ["_projects_to_clean" ][project_id ] = {}
211
242
project_data ['name' ] = project_name
@@ -216,6 +247,7 @@ def _clean_project(self, project):
216
247
'is_preserve' : is_preserve ,
217
248
'is_save_state' : False ,
218
249
'project_id' : project_id ,
250
+ 'prefix' : cleanup_prefix ,
219
251
'got_exceptions' : self .GOT_EXCEPTIONS }
220
252
for service in self .project_associated_services :
221
253
svc = service (self .admin_mgr , ** kwargs )
@@ -243,10 +275,26 @@ def get_parser(self, prog_name):
243
275
help = "Generate JSON file:" + DRY_RUN_JSON +
244
276
", that reports the objects that would have "
245
277
"been deleted had a full cleanup been run." )
278
+ parser .add_argument ('--prefix' , dest = 'prefix' , default = None ,
279
+ help = "Only resources that match the prefix will "
280
+ "be deleted (resources in saved_state.json are "
281
+ "not taken into account). All tempest resources "
282
+ "are created with the prefix value set by "
283
+ "resource_name_prefix in tempest.conf, default "
284
+ "prefix is tempest. Note that some resources are "
285
+ "not named thus they will not be deleted when "
286
+ "filtering based on the prefix. This opt will be "
287
+ "ignored when --init-saved-state is used so that "
288
+ "it can capture the true init state - all "
289
+ "resources present at that moment." )
246
290
return parser
247
291
248
292
def get_description (self ):
249
- return 'Cleanup after tempest run'
293
+ return ('tempest cleanup tool, read the full documentation before '
294
+ 'using this tool. We advice not to run it on production '
295
+ 'environments. On environments where also other users may '
296
+ 'create resources, we strongly advice using --dry-run '
297
+ 'argument first and verify the content of dry_run.json file.' )
250
298
251
299
def _init_state (self ):
252
300
LOG .info ("Initializing saved state." )
@@ -257,6 +305,10 @@ def _init_state(self):
257
305
'saved_state_json' : data ,
258
306
'is_preserve' : False ,
259
307
'is_save_state' : True ,
308
+ # must be None as we want to capture true init state
309
+ # (all resources present) thus no filtering based
310
+ # on the prefix
311
+ 'prefix' : None ,
260
312
'got_exceptions' : self .GOT_EXCEPTIONS }
261
313
for service in self .global_services :
262
314
svc = service (admin_mgr , ** kwargs )
0 commit comments