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

storaged: Fix writing fstab when modifying NFS mounts #18169

Merged
merged 1 commit into from Jan 16, 2023

Conversation

martinpitt
Copy link
Member

readlines() keeps the \n line endings, so joining the array with \n caused extra empty lines to be inserted between each existing line. Move to splitlines() instead, which strips the \n and also makes the del special case obsolete.

Make the integration test much more picky: Don't just assert the single line we expect to get added, but the full file. This will catch not only extra empty lines, but also accidental removals or unexpected ordering.

https://bugzilla.redhat.com/show_bug.cgi?id=2160256

@martinpitt
Copy link
Member Author

Without the fix, the test fails like this, reproducing the bug:

Traceback (most recent call last):
  File "/var/home/martin/upstream/cockpit/realms/test/verify/check-storage-nfs", line 65, in testNfsClient
    self.assertEqual(new_fstab, orig_fstab + "127.0.0.1:/home/foo /mnt/test nfs defaults")
AssertionError: "\n\n#\n\n# /etc/fstab\n\n# Created by anaco[788 chars]ts\n" != "\n#\n# /etc/fstab\n# Created by anaconda on[756 chars]ults"
- 
  
  #
- 
  # /etc/fstab
- 
  # Created by anaconda on Sat Nov  5 08:17:27 2022
- 
  #
- 
  # Accessible filesystems, by reference, are maintained under '/dev/disk/'.
- 
  # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
- 
  #
- 
  # After editing this file, run 'systemctl daemon-reload' to update systemd
- 
  # units generated from this file.
- 
  #
- 
  UUID=3975d5e5-e66a-44c3-90f7-dc2d1c7859d1 /                       btrfs   subvol=root,compress=zstd:1 0 0
- 
  UUID=efdb1b15-eb33-4f1d-acb8-885e29df6783 /boot                   ext4    defaults        1 2
- 
  UUID=C0A6-C7D5          /boot/efi               vfat    defaults,uid=0,gid=0,umask=077,shortname=winnt 0 2
- 
  UUID=3975d5e5-e66a-44c3-90f7-dc2d1c7859d1 /home                   btrfs   subvol=home,compress=zstd:1 0 0
- 
- 127.0.0.1:/home/foo /mnt/test nfs defaults
?                                           -
+ 127.0.0.1:/home/foo /mnt/test nfs defaults

@martinpitt martinpitt temporarily deployed to cockpit-dist January 13, 2023 07:55 — with GitHub Actions Inactive
@@ -58,8 +60,9 @@ class TestStorageNfs(StorageCase):
b.wait_text_not("#nfs-mounts tr:contains(/mnt/test) .pf-c-progress__status", "")

# Should be saved to fstab
self.assertEqual(m.execute("grep -w nfs /etc/fstab").strip(),
"127.0.0.1:/home/foo /mnt/test nfs defaults")
self.maxDiff = None
Copy link
Member

Choose a reason for hiding this comment

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

is maxDiff used anywhere?

Copy link
Member

Choose a reason for hiding this comment

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

This line should be removed, I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

I kept it in as otherwise you don't get a diff like in the comment above, but just a message that gives you the first few characters and a "if you want to see the full diff, set maxDiff".

I don't feel strongly about it at all, though -- I'm happy to take it out, and we can put it back in locally if we need to debug it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ich hab es outgetaked. 😁

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, it's a unittest thing? I didn't know that, I thought it's some debugging leftovers.

So, up to you, really. But if we keep it in, it needs a comment.

(Inheritance is wonderful... :-)

Copy link
Member

Choose a reason for hiding this comment

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

So, up to you, really. But if we keep it in, it needs a comment.

Per IRC, let's not.

Copy link
Member

@mvollmer mvollmer left a comment

Choose a reason for hiding this comment

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

Looks good in general, thanks!

readlines() keeps the `\n` line endings, so joining the array with `\n`
caused extra empty lines to be inserted between each existing line. Move
to splitlines() instead, which strips the `\n` and also makes the `del`
special case obsolete.

Make the integration test much more picky: Don't just assert the single
line we expect to get added, but the full file. This will catch not only
extra empty lines, but also accidental removals or unexpected ordering.

https://bugzilla.redhat.com/show_bug.cgi?id=2160256
@martinpitt martinpitt temporarily deployed to cockpit-dist January 13, 2023 15:58 — with GitHub Actions Inactive
@mvollmer mvollmer merged commit 61817e4 into cockpit-project:main Jan 16, 2023
41 checks passed
@martinpitt martinpitt deleted the nfs-fstab branch January 16, 2023 08:07
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.

None yet

2 participants