@@ -44,7 +44,7 @@ def _upload_app_blueprint(app_tar):
44
44
app_data = f .read ()
45
45
length = os .path .getsize (app_tar )
46
46
47
- headers = utils . create_maintenance_headers ()
47
+ headers = {}
48
48
headers ['Content-Length' ] = length
49
49
headers ['Content-Type' ] = 'application/octet-stream'
50
50
params = urllib .urlencode (
@@ -53,7 +53,7 @@ def _upload_app_blueprint(app_tar):
53
53
54
54
endpoint = '{0}/blueprints/{1}' .format (_get_url_prefix (), BLUEPRINT_ID )
55
55
url = endpoint + '?' + params
56
- utils .http_request (url ,
56
+ utils .rest_request (url ,
57
57
data = app_data ,
58
58
headers = headers )
59
59
@@ -69,10 +69,9 @@ def _deploy_app():
69
69
'blueprint_id' : BLUEPRINT_ID ,
70
70
'inputs' : dep_inputs
71
71
}
72
- headers = utils .create_maintenance_headers ()
73
- headers .update ({'content-type' : 'application/json' })
72
+ headers = {'content-type' : 'application/json' }
74
73
75
- utils .http_request (
74
+ utils .rest_request (
76
75
'{0}/deployments/{1}' .format (_get_url_prefix (), DEPLOYMENT_ID ),
77
76
data = json .dumps (data ),
78
77
headers = headers )
@@ -92,10 +91,9 @@ def _install_sanity_app():
92
91
'deployment_id' : DEPLOYMENT_ID ,
93
92
'workflow_id' : 'install'
94
93
}
95
- headers = utils .create_maintenance_headers ()
96
- headers .update ({'content-type' : 'application/json' })
94
+ headers = {'content-type' : 'application/json' }
97
95
98
- resp = utils .http_request (
96
+ resp = utils .rest_request (
99
97
'{0}/executions' .format (_get_url_prefix ()),
100
98
method = 'POST' ,
101
99
data = json .dumps (data ),
@@ -112,27 +110,26 @@ def _install_sanity_app():
112
110
timeout_msg = 'Timed out while waiting for '
113
111
'deployment {0} to install' .format (DEPLOYMENT_ID ))
114
112
115
- resp_content = resp .readlines ()
116
- json_resp = json .loads (resp_content [0 ])
113
+ json_resp = json .loads (resp .content )
117
114
return json_resp ['id' ]
118
115
119
116
120
117
def _assert_logs_and_events (execution_id ):
121
- headers = utils .create_maintenance_headers ()
122
118
params = urllib .urlencode (
123
119
dict (execution_id = execution_id ,
124
120
type = 'cloudify_log' ))
125
121
126
122
endpoint = '{0}/events' .format (_get_url_prefix ())
127
123
url = endpoint + '?' + params
128
- resp = utils .http_request (url , method = 'GET' , headers = headers , timeout = 30 )
124
+ resp = utils .rest_request (url ,
125
+ method = 'GET' ,
126
+ timeout = 30 )
129
127
if not resp :
130
128
ctx .abort_operation ("Can't connect to elasticsearch" )
131
129
if resp .code != 200 :
132
130
ctx .abort_operation ('Failed to retrieve logs/events' )
133
131
134
- resp_content = resp .readlines ()
135
- json_resp = json .loads (resp_content [0 ])
132
+ json_resp = json .loads (resp .content )
136
133
137
134
if 'items' not in json_resp or not json_resp ['items' ]:
138
135
ctx .abort_operation ('No logs/events received' )
@@ -165,10 +162,9 @@ def _uninstall_sanity_app():
165
162
'deployment_id' : DEPLOYMENT_ID ,
166
163
'workflow_id' : 'uninstall'
167
164
}
168
- headers = utils .create_maintenance_headers ()
169
- headers .update ({'content-type' : 'application/json' })
165
+ headers = {'content-type' : 'application/json' }
170
166
171
- utils .http_request (
167
+ utils .rest_request (
172
168
'{0}/executions' .format (_get_url_prefix ()),
173
169
method = 'POST' ,
174
170
data = json .dumps (data ),
@@ -189,12 +185,10 @@ def _uninstall_sanity_app():
189
185
def _delete_sanity_deployment ():
190
186
if not _is_sanity_dep_exist ():
191
187
return
192
- headers = utils .create_maintenance_headers ()
193
188
194
- resp = utils .http_request (
189
+ resp = utils .rest_request (
195
190
'{0}/deployments/{1}' .format (_get_url_prefix (), DEPLOYMENT_ID ),
196
- method = 'DELETE' ,
197
- headers = headers )
191
+ method = 'DELETE' )
198
192
199
193
if resp .code != 200 :
200
194
ctx .abort_operation ('Failed deleting '
@@ -205,11 +199,9 @@ def _delete_sanity_deployment():
205
199
def _delete_sanity_blueprint ():
206
200
if not _is_sanity_blueprint_exist ():
207
201
return
208
- headers = utils .create_maintenance_headers ()
209
- resp = utils .http_request (
202
+ resp = utils .rest_request (
210
203
'{0}/blueprints/{1}' .format (_get_url_prefix (), BLUEPRINT_ID ),
211
- method = 'DELETE' ,
212
- headers = headers )
204
+ method = 'DELETE' )
213
205
214
206
if resp .code != 200 :
215
207
ctx .abort_operation ('Failed deleting '
@@ -223,23 +215,19 @@ def _delete_key_file():
223
215
224
216
225
217
def _is_sanity_dep_exist (should_fail = False ):
226
- headers = utils .create_maintenance_headers ()
227
- res = utils .http_request (
218
+ res = utils .rest_request (
228
219
'{0}/deployments/{1}' .format (_get_url_prefix (), DEPLOYMENT_ID ),
229
220
method = 'GET' ,
230
- headers = headers ,
231
221
should_fail = should_fail )
232
222
if not res :
233
223
return False
234
224
return res .code == 200
235
225
236
226
237
227
def _is_sanity_blueprint_exist (should_fail = False ):
238
- headers = utils .create_maintenance_headers ()
239
- res = utils .http_request (
228
+ res = utils .rest_request (
240
229
'{0}/blueprints/{1}' .format (_get_url_prefix (), BLUEPRINT_ID ),
241
230
method = 'GET' ,
242
- headers = headers ,
243
231
should_fail = should_fail )
244
232
if not res :
245
233
return False
@@ -276,7 +264,15 @@ def perform_sanity():
276
264
perform_sanity ()
277
265
278
266
if utils .is_upgrade or utils .is_rollback :
267
+ # Restore the snapshot at the end of the workflow.
279
268
utils .restore_upgrade_snapshot ()
280
269
281
270
if utils .is_upgrade :
271
+ # To keep the upgrade workflow idempotent, this flag is used to figure
272
+ # out if the next upgrade should dispose of old rollback data.
282
273
utils .set_upgrade_success_in_upgrade_meta ()
274
+
275
+ if utils .is_rollback :
276
+ # remove data created by the upgrade process.
277
+ utils .remove (utils .UPGRADE_METADATA_FILE )
278
+ utils .remove (utils .ES_UPGRADE_DUMP_PATH )
0 commit comments