Shubhendu Tripathi has uploaded a new change for review. Change subject: setup: Write the answer file if file path is valid ......................................................................
setup: Write the answer file if file path is valid Added a exception handling to make sure answer file gets written only if the file path is valid one. If the path is invalid, instead of erroring out and marking the whole setup as failed, it shows a warning and setup is marked as completed successfully. A valid use case is calling "engine-setup --generate-answer =root/engine-answer.txt". In this case the current working dir does not contain a directory with name root. In the above scenario, earlier engine setup used to display an error saying "No such file or directory: '<CurrDir>/root/ engine-answer.txt'". Also the overall engine-setup output used to report "[ ERROR ] Execution of setup failed". With the fix, now the output looks as below - [WARNING] [Errno 2] No such file or directory: '<CurrDir>/root/engine-answer.txt' and the overall engine setup reports a success as below - "[ INFO ] Execution of setup completed successfully" Change-Id: I8c595449e631f0bdb9524d74bdc3d9b1a256439f Bug-Url: https://bugzilla.redhat.com/1089067 Signed-off-by: Shubhendu Tripathi <shtri...@redhat.com> --- M packaging/setup/plugins/ovirt-engine-common/base/core/answerfile.py 1 file changed, 34 insertions(+), 30 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/31/27731/1 diff --git a/packaging/setup/plugins/ovirt-engine-common/base/core/answerfile.py b/packaging/setup/plugins/ovirt-engine-common/base/core/answerfile.py index 415e7c2..ccbff15 100644 --- a/packaging/setup/plugins/ovirt-engine-common/base/core/answerfile.py +++ b/packaging/setup/plugins/ovirt-engine-common/base/core/answerfile.py @@ -75,38 +75,42 @@ name=answer, ) ) - with open(self.resolveFile(answer), 'w') as f: - os.fchmod(f.fileno(), 0o600) - f.write( - ( - '# action=%s\n' - '[environment:default]\n' - ) % ( - self.environment[ - osetupcons.CoreEnv.ACTION - ], + # Generate the answer file only if valid path is passed + try: + with open(self.resolveFile(answer), 'w') as f: + os.fchmod(f.fileno(), 0o600) + f.write( + ( + '# action=%s\n' + '[environment:default]\n' + ) % ( + self.environment[ + osetupcons.CoreEnv.ACTION + ], + ) ) - ) - consts = [] - for constobj in self.environment[ - osetupcons.CoreEnv.SETUP_ATTRS_MODULES - ]: - consts.extend(constobj.__dict__['__osetup_attrs__']) - for c in consts: - for k in c.__dict__.values(): - if hasattr(k, '__osetup_attrs__'): - if k.__osetup_attrs__['answerfile']: - k = k.fget(None) - if k in self.environment: - v = self.environment[k] - f.write( - '%s=%s:%s\n' % ( - k, - common.typeName(v), - '\n'.join(v) if isinstance(v, list) - else v, + consts = [] + for constobj in self.environment[ + osetupcons.CoreEnv.SETUP_ATTRS_MODULES + ]: + consts.extend(constobj.__dict__['__osetup_attrs__']) + for c in consts: + for k in c.__dict__.values(): + if hasattr(k, '__osetup_attrs__'): + if k.__osetup_attrs__['answerfile']: + k = k.fget(None) + if k in self.environment: + v = self.environment[k] + f.write( + '%s=%s:%s\n' % ( + k, + common.typeName(v), + '\n'.join(v) if isinstance(v, list) + else v, + ) ) - ) + except IOError as e: + self.logger.warning(e) # vim: expandtab tabstop=4 shiftwidth=4 -- To view, visit http://gerrit.ovirt.org/27731 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8c595449e631f0bdb9524d74bdc3d9b1a256439f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shubhendu Tripathi <shtri...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches