Skip to content
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

Detect kernel version before swap file creation #428

Merged
merged 20 commits into from
Aug 18, 2020

Conversation

otubo
Copy link
Contributor

@otubo otubo commented Jun 11, 2020

According to man page `man 8 swapon', "Preallocated swap files are
supported on XFS since Linux 4.18". This patch checks for kernel version
before attepting to create swapfile, using dd for XFS only on kernel
versions <= 4.18 or btrfs.

This is the updated version taking into consideration all the comments on the PR#218

Signed-off-by: Eduardo Otubo otubo@redhat.com

According to man page `man 8 swapon', "Preallocated swap files are
supported on XFS since Linux 4.18". This patch checks for kernel version
before attepting to create swapfile, using dd for XFS only on kernel
versions <= 4.18 or btrfs.

Signed-off-by: Eduardo Otubo <otubo@redhat.com>
Replaced the regex by the os function calls and put it on a separate
function inside util.py module.

Signed-off-by: Eduardo Otubo <otubo@redhat.com>
@otubo
Copy link
Contributor Author

otubo commented Jun 11, 2020

I left the commit log in this new PR so we could check the history. But it could be squashed upon final merge.

Copy link
Collaborator

@igalic igalic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

cloudinit/util.py Show resolved Hide resolved
cloudinit/util.py Show resolved Hide resolved
@OddBloke OddBloke self-assigned this Jun 16, 2020
Copy link
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up! This approach looks good to me. I have one inline comment, and I'd like to see some testing for the new util function and new cc_mounts behaviour.

cloudinit/config/cc_mounts.py Outdated Show resolved Hide resolved
otubo and others added 3 commits June 23, 2020 14:11
Co-authored-by: Daniel Watkins <daniel@daniel-watkins.co.uk>
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
Signed-off-by: Eduardo Otubo <otubo@redhat.com>
@otubo otubo requested a review from OddBloke June 23, 2020 15:17
Copy link
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the tests! I have some comments. :-)

tests/unittests/test_util.py Outdated Show resolved Hide resolved
tests/unittests/test_util.py Outdated Show resolved Hide resolved
tests/unittests/test_handler/test_handler_mounts.py Outdated Show resolved Hide resolved
tests/unittests/test_handler/test_handler_mounts.py Outdated Show resolved Hide resolved
otubo added 2 commits July 6, 2020 18:13
Wrapping test_kernel_version() into class TestKernelVersion() and
adding pytest parametrize decoration. In order to have it working,
the cache decoration would have to be removed, though. Otherwise the
function cache would always return the same value and would fail the
tests.

Signed-off-by: Eduardo Otubo <otubo@redhat.com>
Splitting test_swap_creation_method into 3 different cases for different
filesystems. Leaving the methods way of asserting the test with only
cc_mounts.handle() function. Like test_swap_integrity() does.

Signed-off-by: Eduardo Otubo <otubo@redhat.com>

[0] pytest-dev/pytest#3484
Copy link
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! Just one inline question about the tests.

tests/unittests/test_handler/test_handler_mounts.py Outdated Show resolved Hide resolved
Creating a new class of tests TestSwapFileCreation() for this purpose.
The class still uses test_helpers.FilesystemMockingTestCase to mock
a file system so swap file can be created.

Also added a check on cloudinit/config/cc_mounts.py to make sure the
swap file really exists, which is not the case on unittests. The swap
file is not being created, the test just makes sure if the correct calls
are being done.

Signed-off-by: Eduardo Otubo <otubo@redhat.com>
@otubo
Copy link
Contributor Author

otubo commented Jul 9, 2020

Looking at the diff, it looks incredibly messy to review. Looks like I replaced TestFstabHandling with TestSwapFileCreation and then again readded TestFstabHandling down below. If this is too terrible to review, I can close this PR and open a new one with squashed commits for easier reading :)

@otubo
Copy link
Contributor Author

otubo commented Jul 9, 2020

argh, I could swear I had this flake stuff fixed before my commit

@otubo otubo requested a review from OddBloke July 10, 2020 12:37
@github-actions
Copy link

Hello! Thank you for this proposed change to cloud-init. This pull request is now marked as stale as it has not seen any activity in 14 days. If no activity occurs within the next 7 days, this pull request will automatically close.

If you are waiting for code review and you are seeing this message, apologies! Please reply, tagging powersj, and he will ensure that someone takes a look soon.

(If the pull request is closed, please do feel free to reopen it if you wish to continue working on it.)

@github-actions github-actions bot added the stale-pr Pull request is stale; will be auto-closed soon label Jul 30, 2020
@otubo otubo requested a review from OddBloke July 31, 2020 07:45
@OddBloke OddBloke removed the stale-pr Pull request is stale; will be auto-closed soon label Aug 6, 2020
Copy link
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much there, I think, thanks for your work! I've requested one additional test inline, but that should be largely copy/paste of what you already have for the other tests, so hopefully not too tricky!

@otubo otubo requested a review from OddBloke August 17, 2020 12:36
@mitechie
Copy link
Contributor

Thanks for the update. Github is noting you have some conflicts before landing. Can you peek at those, please?

Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 thanks for the updates @otubo

@blackboxsw blackboxsw dismissed OddBloke’s stale review August 18, 2020 21:10

Review comments and unit tests are addressed.

@blackboxsw blackboxsw merged commit b749548 into canonical:master Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants