-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RHELC-1153] Port the restorable file to work with backup controller #935
Conversation
702e1c0
to
27ab6e2
Compare
27ab6e2
to
be344e7
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #935 +/- ##
==========================================
- Coverage 94.21% 94.21% -0.01%
==========================================
Files 47 47
Lines 4377 4444 +67
Branches 775 787 +12
==========================================
+ Hits 4124 4187 +63
- Misses 177 180 +3
- Partials 76 77 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems risky to me to just return if the backup_filepath doesn't exist in restore() at line 383; should the info message at least be a warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In restore(), maybe you should call the superclass restore method?
@jochapma about your questions:
As I'm thinking about it now, it might be better to warn the user during the enabling (backing up) the file, since during the rollback the user can't do anything with it and the warning is useless from my point of view. I'm not sure if exists case if this message would be printed, but I didn't want to get rid of this case. And as I'm looking into the code https://github.com/oamg/convert2rhel/pull/935/files#diff-8f4622020cde9a253bc82f69bf2b88910bcc5a84943db3c7d3a435becedfd4d5R354 it's mostly fine I would say. If the path doesn't exists we inform the user. If there we reach some exception, the critical is printed.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me! Approved
be344e7
to
67db959
Compare
convert2rhel/backup.py
Outdated
def enable(self): | ||
"""Save current version of a file""" | ||
# Prevent multiple backup | ||
if self.enabled: | ||
return | ||
|
||
loggerinst.info("Backing up %s." % self.filepath) | ||
if os.path.isfile(self.filepath): | ||
try: | ||
loggerinst.debug("Copying %s to %s." % (self.filepath, BACKUP_DIR)) | ||
shutil.copy2(self.filepath, BACKUP_DIR) | ||
|
||
except (OSError, IOError) as err: | ||
# IOError for py2 and OSError for py3 | ||
loggerinst.critical("Error(%s): %s" % (err.errno, err.strerror)) | ||
else: | ||
loggerinst.info("Can't find %s.", self.filepath) | ||
|
||
# Set the enabled value | ||
super(NewRestorableFile, self).enable() | ||
|
||
def restore(self, rollback=True): | ||
"""Restore a previously backed up file""" | ||
# We do not have backup | ||
if not self.enabled: | ||
loggerinst.info("%s hasn't been backed up." % self.filepath) | ||
return | ||
|
||
backup_filepath = os.path.join(BACKUP_DIR, os.path.basename(self.filepath)) | ||
if rollback: | ||
loggerinst.task("Rollback: Restore %s from backup" % self.filepath) | ||
else: | ||
loggerinst.info("Restoring %s from backup" % self.filepath) | ||
|
||
if not os.path.isfile(backup_filepath): | ||
loggerinst.info("%s hasn't been backed up." % self.filepath) | ||
return | ||
|
||
try: | ||
shutil.copy2(backup_filepath, self.filepath) | ||
except (OSError, IOError) as err: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of paths not being tested here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SpyTec I'm not sure if I understood. Do you mean not tested by unit tests or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's right, L353 L381 L389 L393-394 L399
67db959
to
042f62a
Compare
@SpyTec Added the unittests - hope I haven't missed anything. Changed roder of messages in |
042f62a
to
01fff71
Compare
Changed message from comment #875 (comment) |
5b02587
to
93e47b5
Compare
93e47b5
to
16c6c0b
Compare
except (OSError, IOError) as err: | ||
# IOError for py2 and OSError for py3 | ||
loggerinst.critical("Error(%s): %s" % (err.errno, err.strerror)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to have unit tests covering it. Unless I'm mistaken the Error we currently catch is for restore()
function
if self.enabled: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're testing the restore()
when enabled is off but not enable()
@SpyTec I would say we can close this PR as it was part of #875 which is already merged and released |
Gotcha, makes sense |
This PR ports the restorable file to work with backup controller. No functionality changed, the old restorable file is still being used and waiting for complete port. This is mainly for #875 where this part of code is going to be used for now.
Jira Issues:
Checklist
[RHELC-]
is part of the PR titleRelease Pending
if relevant