Merge ~jasonzio/cloud-init:fixmounterrormatch into cloud-init:master

Proposed by Jason Zions
Status: Superseded
Proposed branch: ~jasonzio/cloud-init:fixmounterrormatch
Merge into: cloud-init:master
Diff against target: 53 lines (+15/-16)
2 files modified
cloudinit/sources/DataSourceAzure.py (+1/-1)
tests/unittests/test_datasource/test_azure.py (+14/-15)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing
Review via email: mp+357669@code.launchpad.net

This proposal has been superseded by a proposal from 2018-11-12.

Commit message

azure: Accept variation in error msg from mount for ntfs volumes

If Azure detects an ntfs filesystem type during mount attempt, it should
still report the resource device as reformattable. There are slight
differences in error message format on RedHat and SuSE. This patch
simplifies the expected error match to work on both distributions.

LP: #1799338

Description of the change

Fixes lp:1799338 by omitting the prefix of the error message from the text-to-match. This skips the part of the error message that differs between RHEL and SUSE without introducing a regexp match, which would be needlessly expensive in this case.

To post a comment you must log in.
Revision history for this message
Chad Smith (chad.smith) wrote :

Thank you for this branch.

 I'm trying to decide if it's worth noting the SLES/RHEL differences by extending the existing unit test test_ntfs_mount_errors_true in tests/unittests/test_datasource/test_azure.py.

I like getting test coverage to explain what 'mocked' expectation are and why to give future-us context on what to worry about with a change.

How's this patch look?

diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 4c5c6c1..b4bc48d 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -1510,21 +1510,20 @@ class TestCanDevBeReformatted(CiTestCase):
                     '/dev/sda1': {'num': 1, 'fs': 'ntfs', 'files': []}
                 }}})

- err = ("Unexpected error while running command.\n",
- "Command: ['mount', '-o', 'ro,sync', '-t', 'auto', ",
- "'/dev/sda1', '/fake-tmp/dir']\n"
- "Exit code: 32\n"
- "Reason: -\n"
- "Stdout: -\n"
- "Stderr: mount: unknown filesystem type 'ntfs'")
- self.m_mount_cb.side_effect = MountFailedError(
- 'Failed mounting %s to %s due to: %s' %
- ('/dev/sda', '/fake-tmp/dir', err))
-
- value, msg = dsaz.can_dev_be_reformatted('/dev/sda',
- preserve_ntfs=False)
- self.assertTrue(value)
- self.assertIn('cannot mount NTFS, assuming', msg)
+ error_msgs = [
+ "Stderr: mount: unknown filesystem type 'ntfs'", # RHEL
+ "Stderr: mount: /dev/sdb1: unknown filesystem type 'ntfs'" # SLES
+ ]
+
+ for err_msg in error_msgs:
+ self.m_mount_cb.side_effect = MountFailedError(
+ 'Failed mounting %s to %s due to: %s' %
+ ('/dev/sda', '/fake-tmp/dir', err_msg))
+
+ value, msg = dsaz.can_dev_be_reformatted(
+ '/dev/sda', preserve_ntfs=False)
+ self.assertTrue(value)
+ self.assertIn('cannot mount NTFS, assuming', msg)

     def test_never_destroy_ntfs_config_false(self):
         """Normally formattable situation with never_destroy_ntfs set."""

Revision history for this message
Chad Smith (chad.smith) wrote :

Jason, I also reformatted the commit message on this branch to align a bit more with our typical git log format. If that message makes sense or needs correction please feel free to "wordsmith" it.

Revision history for this message
Jason Zions (jasonzio) wrote :

> I like getting test coverage to explain what 'mocked' expectation are and why
> to give future-us context on what to worry about with a change.
>
>
> How's this patch look?

That looks pretty good to me. It trades off mocking the entire body of the error message in favor of mocking the only part that gets looked at. As long as that last statement is true (i.e. no code examining a failed mount attempt looks at anything but the captured Stderr part), you nicely capture the platform distinction and make sure we don't screw it up in the future.

Revision history for this message
Jason Zions (jasonzio) wrote :

> Jason, I also reformatted the commit message on this branch to align a bit
> more with our typical git log format. If that message makes sense or needs
> correction please feel free to "wordsmith" it.

LGTM. I couldn't find a doc describing the preferred git log format for this project, but I admit I failed to read a half-dozen merge requests to see what previous changes looked like, so that's my error. :-)

Revision history for this message
Chad Smith (chad.smith) wrote :

no worries Jason, thanks for the feedback. I'll add something to the hacking doc @ https://cloudinit.readthedocs.io/en/latest/topics/hacking.html to describe our formats (as we've recently changed them).

Revision history for this message
Chad Smith (chad.smith) wrote :

Jason, if you get a chance to apply the patch I suggested and push it back up, we'll land this branch.

Much thanks

Revision history for this message
Jason Zions (jasonzio) wrote :

I hadn't realized the ball was in my court; I'll take care of this as quickly as I can.

4d23c58... by Jason Zions <email address hidden>

Check both RHEL and SLES error behavior for ntfs mounts

Revision history for this message
Jason Zions (jasonzio) wrote :

> Jason, if you get a chance to apply the patch I suggested and push it back up,
> we'll land this branch.
>
> Much thanks

I have made the changes and pushed them; just waiting on you now.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:4d23c5887d5d146f431057d67251929607ede9fe
https://jenkins.ubuntu.com/server/job/cloud-init-ci/431/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/431/rebuild

review: Needs Fixing (continuous-integration)

Unmerged commits

4d23c58... by Jason Zions <email address hidden>

Check both RHEL and SLES error behavior for ntfs mounts

b8b0db1... by Jason Zions <email address hidden>

Accept variation in error msg from mount for ntfs volumes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index 7bdd43d..19e6d6d 100644
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -716,7 +716,7 @@ def can_dev_be_reformatted(devpath, preserve_ntfs):
716 file_count = util.mount_cb(cand_path, count_files, mtype="ntfs",716 file_count = util.mount_cb(cand_path, count_files, mtype="ntfs",
717 update_env_for_mount={'LANG': 'C'})717 update_env_for_mount={'LANG': 'C'})
718 except util.MountFailedError as e:718 except util.MountFailedError as e:
719 if "mount: unknown filesystem type 'ntfs'" in str(e):719 if "unknown filesystem type 'ntfs'" in str(e):
720 return True, (bmsg + ' but this system cannot mount NTFS,'720 return True, (bmsg + ' but this system cannot mount NTFS,'
721 ' assuming there are no important files.'721 ' assuming there are no important files.'
722 ' Formatting allowed.')722 ' Formatting allowed.')
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 4c5c6c1..f8c6566 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -1510,21 +1510,20 @@ class TestCanDevBeReformatted(CiTestCase):
1510 '/dev/sda1': {'num': 1, 'fs': 'ntfs', 'files': []}1510 '/dev/sda1': {'num': 1, 'fs': 'ntfs', 'files': []}
1511 }}})1511 }}})
15121512
1513 err = ("Unexpected error while running command.\n",1513 error_msgs = [
1514 "Command: ['mount', '-o', 'ro,sync', '-t', 'auto', ",1514 "Stderr: mount: unknown filesystem type 'ntfs'", # RHEL
1515 "'/dev/sda1', '/fake-tmp/dir']\n"1515 "Stderr: mount: /dev/sdb1: unknown filesystem type 'ntfs'" # SLES
1516 "Exit code: 32\n"1516 ]
1517 "Reason: -\n"1517
1518 "Stdout: -\n"1518 for err_msg in error_msgs:
1519 "Stderr: mount: unknown filesystem type 'ntfs'")1519 self.m_mount_cb.side_effect = MountFailedError(
1520 self.m_mount_cb.side_effect = MountFailedError(1520 "Failed mounting %s to %s due to: \nUnexpected.\n%s" %
1521 'Failed mounting %s to %s due to: %s' %1521 ('/dev/sda', '/fake-tmp/dir', err_msg))
1522 ('/dev/sda', '/fake-tmp/dir', err))1522
15231523 value, msg = dsaz.can_dev_be_reformatted('/dev/sda',
1524 value, msg = dsaz.can_dev_be_reformatted('/dev/sda',1524 preserve_ntfs=False)
1525 preserve_ntfs=False)1525 self.assertTrue(value)
1526 self.assertTrue(value)1526 self.assertIn('cannot mount NTFS, assuming', msg)
1527 self.assertIn('cannot mount NTFS, assuming', msg)
15281527
1529 def test_never_destroy_ntfs_config_false(self):1528 def test_never_destroy_ntfs_config_false(self):
1530 """Normally formattable situation with never_destroy_ntfs set."""1529 """Normally formattable situation with never_destroy_ntfs set."""

Subscribers

People subscribed via source and target branches