-
Notifications
You must be signed in to change notification settings - Fork 410
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
OCPBUGS-11437: MCO keeps the pull secret to .orig file once it replaced #3759
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -817,51 +817,20 @@ func TestOriginalFileBackupRestore(t *testing.T) { | |
testDir, cleanup := setupTempDirWithEtc(t) | ||
defer cleanup() | ||
|
||
// Write a normal file as a control to make sure normal case works | ||
// Write a file in the /tmp dir to test whether orig files are selectively preserved | ||
controlFile := filepath.Join(testDir, "control-file") | ||
err := os.WriteFile(controlFile, []byte("control file contents"), 0755) | ||
assert.Nil(t, err) | ||
|
||
// Back up that normal file | ||
// Back up the tmp file | ||
err = createOrigFile(controlFile, controlFile) | ||
assert.Nil(t, err) | ||
|
||
// Now try again and make sure it knows it's already backed up | ||
// Now try again and make sure it knows it's already backed up if it should be | ||
err = createOrigFile(controlFile, controlFile) | ||
assert.Nil(t, err) | ||
|
||
// Restore the normal file | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Are these tests no longer needed or do they now fail with this new change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I am deleting those because they now fail with this new change. This is because the tests create files in the /tmp folder, try to create orig files for those and see if that is successful by restoring form the orig files. But the current workaround stops the orig file preservation for the files in the /tmp folder as they are not the original files shipped with the disk, so the tests are no longer valid. However, I have also tested the current createOrig' s functionality in preserving the files by putting a forceCreate variable in, so that when running the test, the origs are forcedly created for these /tmp files. After verifying its functionality, I removed those variables as well as the tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To give a bit more context, I think these tests aren't really needed anymore since we are now (properly) not preserving anything written to /tmp, since they shouldn't have been preserved in the first place. We could instead test preservation of |
||
err = restorePath(controlFile) | ||
assert.Nil(t, err) | ||
|
||
// The normal file worked, try it with a symlink | ||
// Write a file we can point a symlink at | ||
err = os.WriteFile(filepath.Join(testDir, "target-file"), []byte("target file contents"), 0755) | ||
assert.Nil(t, err) | ||
|
||
// Make a relative symlink | ||
relativeSymlink := filepath.Join(testDir, "etc", "relative-symlink-to-target-file") | ||
relativeSymlinkTarget := filepath.Join("..", "target-file") | ||
err = os.Symlink(relativeSymlinkTarget, relativeSymlink) | ||
assert.Nil(t, err) | ||
|
||
// Back up the relative symlink | ||
err = createOrigFile(relativeSymlink, relativeSymlink) | ||
assert.Nil(t, err) | ||
|
||
// Remove the symlink and write a file over it | ||
fileOverSymlink := filepath.Join(testDir, "etc", "relative-symlink-to-target-file") | ||
err = os.Remove(fileOverSymlink) | ||
assert.Nil(t, err) | ||
err = os.WriteFile(fileOverSymlink, []byte("replacement contents"), 0755) | ||
assert.Nil(t, err) | ||
|
||
// Try to back it up again make sure it knows it's already backed up | ||
err = createOrigFile(relativeSymlink, relativeSymlink) | ||
assert.Nil(t, err) | ||
|
||
// Finally, make sure we can restore the relative symlink if we rollback | ||
err = restorePath(relativeSymlink) | ||
assert.Nil(t, err) | ||
|
||
// Check whether there is an orig preservation for the path - OK: there is no back up for the tmp file | ||
_, err = os.Stat(origFileName(controlFile)) | ||
assert.True(t, os.IsNotExist(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.
suggestion (non-blocking): Since the
createOrigFile()
function now has a implicit dependency on therpm
binary, this test will fail if therpm
binary is not present in environment where the test is running.This is noteworthy for two reasons:
rpm
binary is not present andcreateOrigFile()
is called,exec.Command()
will return an error that indicates that therpm
binary is not found. However, the rest of the path increateOrigFile()
will assume that it just means that the file is not owned by an RPM. We could add some explicit checking to the RPM command to alleviate that concern.There are two ways we can mitigate this:
rpm
binary on it and skip the test if it is not found. You can do that like this:Out of the two, I think I prefer approach 1 because if, say, our base image was to somehow be missing the
rpm
binary, the test will fail loudly and explicitly. Whereas with approach 2, if the binary is missing, it will be silently skipped which could make diagnosis much more difficult in the future.