Skip to content

Commit faa87b3

Browse files
huizhgaborigloi
authored andcommitted
CA-227716: Refine the error messages.
1. Parse the error output to give the user friendly message including: update_precheck_failed_conflict_present update_precheck_failed_wrong_server_version update_precheck_failed_prerequisite_missing 2. Set default locale for yum command environment. Signed-off-by: Hui Zhang <[email protected]>
1 parent 0f1f186 commit faa87b3

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

ocaml/idl/datamodel.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,11 +1208,11 @@ let _ =
12081208
~doc:"This update has already been applied to all hosts in the pool." ();
12091209
error Api_errors.update_precheck_failed_unknown_error [ "update"; "info" ]
12101210
~doc:"The update precheck stage failed with an unknown error." ();
1211-
error Api_errors.update_precheck_failed_prerequisite_missing [ "update"; "info" ]
1211+
error Api_errors.update_precheck_failed_prerequisite_missing [ "update"; "prerequisite_update" ]
12121212
~doc:"The update precheck stage failed: prerequisite update(s) are missing." ();
1213-
error Api_errors.update_precheck_failed_conflict_present ["update"; "info"]
1214-
~doc:"The update precheck stage failed: conflicting updates are present." ();
1215-
error Api_errors.update_precheck_failed_wrong_server_version ["update"; "info"]
1213+
error Api_errors.update_precheck_failed_conflict_present ["update"; "conflict_update"]
1214+
~doc:"The update precheck stage failed: conflicting update(s) are present." ();
1215+
error Api_errors.update_precheck_failed_wrong_server_version ["update"; "installed_version"; "required_version "]
12161216
~doc:"The update precheck stage failed: the server is of an incorrect version." ();
12171217
error Api_errors.update_precheck_failed_out_of_space ["update"; "available_space"; "required_space "]
12181218
~doc:"The update precheck stage failed: the server does not have enough space." ();

scripts/extensions/pool_update.apply

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def failure_message(code, params):
4545

4646
def execute_apply(session, update_package, yum_conf_file):
4747
cmd = ['yum', 'install', '-y', '--noplugins', '-c', yum_conf_file, update_package]
48-
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
48+
yum_env = os.environ.copy()
49+
yum_env['LANG'] = 'C'
50+
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True, env=yum_env)
4951
output, _ = p.communicate()
5052
xcp.logger.info('pool_update.apply %r returncode=%r output=%r', cmd, p.returncode, output)
5153
if p.returncode != 0:

scripts/extensions/pool_update.precheck

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ UPDATE_PRECHECK_FAILED_PREREQUISITE_MISSING = 'UPDATE_PRECHECK_FAILED_PREREQUISI
2525
UPDATE_PRECHECK_FAILED_CONFLICT_PRESENT = 'UPDATE_PRECHECK_FAILED_CONFLICT_PRESENT'
2626
UPDATE_PRECHECK_FAILED_WRONG_SERVER_VERSION = 'UPDATE_PRECHECK_FAILED_WRONG_SERVER_VERSION'
2727
UPDATE_PRECHECK_FAILED_OUT_OF_SPACE = 'UPDATE_PRECHECK_FAILED_OUT_OF_SPACE'
28+
UPDATE_PREFIX = 'update-'
2829
INVALID_UPDATE = 'INVALID_UPDATE'
2930
CANNOT_FIND_UPDATE = 'CANNOT_FIND_UPDATE'
3031
ERROR_MESSAGE_START = 'Error: '
3132
ERROR_MESSAGE_END = 'You could try '
32-
ERROR_MESSAGE_CONFLICT = ' conflicts with '
33+
ERROR_MESSAGE_CONFLICTS_WITH = ' conflicts with '
34+
ERROR_MESSAGE_CONFLICTS = 'conflicts '
35+
ERROR_MESSAGE_PROCESSING_CONFLICT = '--> Processing Conflict:'
3336
ERROR_MESSAGE_PREREQUISITE = 'Requires: '
3437
ERROR_MESSAGE_VERSION_REQUIRED = 'Requires: '
3538
ERROR_MESSAGE_VERSION_INSTALLED = 'Installed: '
@@ -80,7 +83,9 @@ def execute_precheck(session, control_package, yum_conf_file, update_precheck_fi
8083
'PATCH_PRECHECK_LIVEPATCH_INCOMPLETE': 'ok_livepatch_incomplete',
8184
'PATCH_PRECHECK_LIVEPATCH_NOT_APPLICABLE': 'ok'}
8285
cmd = ['yum', 'install', '-y', '--noplugins', '-c', yum_conf_file, control_package]
83-
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
86+
yum_env = os.environ.copy()
87+
yum_env['LANG'] = 'C'
88+
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True, env=yum_env)
8489
output, _ = p.communicate()
8590
xcp.logger.info('pool_update.precheck %r returncode=%r output=%r', cmd, p.returncode, output)
8691
if p.returncode != 0:
@@ -91,15 +96,38 @@ def execute_precheck(session, control_package, yum_conf_file, update_precheck_fi
9196
if m:
9297
errmsg = m.group()
9398
errmsg = re.sub(ERROR_MESSAGE_END + '.+', '', errmsg, flags=re.DOTALL)
94-
errmsg = re.sub('\n +', ' ', errmsg, flags=re.DOTALL)
95-
if ERROR_MESSAGE_CONFLICT in errmsg:
96-
raise ConflictPresent(errmsg)
99+
precheckfailure_msg = re.sub('\n +', ' ', errmsg, flags=re.DOTALL)
100+
if ERROR_MESSAGE_CONFLICTS_WITH in errmsg and ERROR_MESSAGE_PROCESSING_CONFLICT in output:
101+
regex = ERROR_MESSAGE_PROCESSING_CONFLICT + '(.*)' + ERROR_MESSAGE_CONFLICTS + UPDATE_PREFIX + '(.+?)\n'
102+
conflict_tuples = re.findall(regex, output)
103+
if len(conflict_tuples) > 0:
104+
conflict_updates = ''
105+
for tuple in conflict_tuples:
106+
conflict_updates += tuple[1] + ' '
107+
raise ConflictPresent(conflict_updates.rstrip())
108+
else:
109+
raise PrecheckFailure(precheckfailure_msg)
97110
elif ERROR_MESSAGE_VERSION_REQUIRED in errmsg and ERROR_MESSAGE_VERSION_INSTALLED in errmsg:
98-
raise WrongServerVersion(errmsg)
111+
regex = ERROR_MESSAGE_VERSION_REQUIRED + '(.+?)\n.+ {2,2}(.+)$'
112+
match = re.search(regex, errmsg, flags=re.DOTALL)
113+
if match:
114+
required_version = match.group(1).rstrip()
115+
installed_version = match.group(2).rstrip()
116+
raise WrongServerVersion(required_version, installed_version)
117+
else:
118+
raise PrecheckFailure(precheckfailure_msg)
99119
elif ERROR_MESSAGE_PREREQUISITE in errmsg:
100-
raise PrerequisiteMissing(errmsg)
120+
regex = ERROR_MESSAGE_PREREQUISITE + UPDATE_PREFIX + '(.+?)\n'
121+
prerequisite_list = re.findall(regex, errmsg)
122+
if len(prerequisite_list) > 0:
123+
prerequisite_updates = ''
124+
for prerequisite in prerequisite_list:
125+
prerequisite_updates += prerequisite + ' '
126+
raise PrerequisiteMissing(prerequisite_updates.rstrip())
127+
else:
128+
raise PrecheckFailure(precheckfailure_msg)
101129
else:
102-
raise PrecheckFailure(errmsg)
130+
raise PrecheckFailure(precheckfailure_msg)
103131
else:
104132
raise PrecheckFailure()
105133
else:
@@ -180,7 +208,8 @@ if __name__ == '__main__':
180208
except ConflictPresent as e:
181209
print(failure_message(UPDATE_PRECHECK_FAILED_CONFLICT_PRESENT, [update_package, str(e)]))
182210
except WrongServerVersion as e:
183-
print(failure_message(UPDATE_PRECHECK_FAILED_WRONG_SERVER_VERSION, [update_package, str(e)]))
211+
required_version, installed_version = e.args
212+
print(failure_message(UPDATE_PRECHECK_FAILED_WRONG_SERVER_VERSION, [update_package, installed_version, required_version]))
184213
except InvalidUpdate as e:
185214
print(failure_message(INVALID_UPDATE, [update_package, str(e)]))
186215
except Exception as e:

0 commit comments

Comments
 (0)