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

fix: Remove hardcoded /var/lib/cloud hotplug path #4940

Merged
merged 3 commits into from
Feb 26, 2024

Conversation

TheRealFalcon
Copy link
Member

Proposed Commit Message

fix: Remove hardcoded /var/lib/cloud hotplug path

The cloud dir is configurable, so we shouldn't be hardcoding the
hotplug.enabled file location

Additional Context

https://jenkins.canonical.com/server-team/view/cloud-init/job/cloud-init-integration-focal-lxd_vm/407/testReport/junit/tests.integration_tests.test_paths/TestHonorCloudDir/test_honor_cloud_dir/

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

The cloud dir is configurable, so we shouldn't be hardcoding the
hotplug.enabled file location
enable_hotplug(mocks.m_init, "net")

assert [
call([EventType.HOTPLUG])
] == mocks.m_init.datasource.get_supported_events.call_args_list
assert [call()] == m_read_hotplug_enabled_file.call_args_list
m_read_hotplug_enabled_file.assert_called_once()
Copy link
Collaborator

Choose a reason for hiding this comment

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

would there be any value to checking not only .assert_called_once() but also the call list since read_hotplug_enabled_file() now accepts an argument?

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 don't think so. We're mocking that argument in all of the tests anyway, so I don't think we really get any signal from introspecting the argument.

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.

D'oh. My suggestion on the previous PR about locating this hard-coded path in settings was short-sighted. +1. I should have thought about that aspect in review, especially given Brett's ongoing work on other dynamic path concerns with the configurable /run/cloud-init work in #4820.

self.target_file = target_file

def get_cpath(self, *args):
return self.target_file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably overkill, but none of these tests assert we are specifically looking at hotplug.enabled in get_cpath. So, our implementation of read_hotplug_enabled_file could change to get_cpath("warnings") with no test failures.
Can we assert we are validating the specific hotplug.enabled lookup in Paths somehow in these tests. Maybe just something like:

--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -3231,6 +3231,9 @@ class MockPath:
         self.target_file = target_file
 
     def get_cpath(self, *args):
+        assert args == (
+            "hotplug.enabled",
+        ), f"Invalid get_cpath argument {args}"
         return self.target_file

Copy link
Contributor

@aciba90 aciba90 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for taking care of this!

@TheRealFalcon TheRealFalcon merged commit beddd97 into canonical:main Feb 26, 2024
29 checks passed
@TheRealFalcon TheRealFalcon deleted the hotplug-path branch February 26, 2024 13:52
blackboxsw pushed a commit that referenced this pull request Feb 27, 2024
The cloud dir is configurable, so we shouldn't be hardcoding the
hotplug.enabled file location
blackboxsw pushed a commit that referenced this pull request Feb 27, 2024
The cloud dir is configurable, so we shouldn't be hardcoding the
hotplug.enabled file location
blackboxsw pushed a commit that referenced this pull request Feb 27, 2024
The cloud dir is configurable, so we shouldn't be hardcoding the
hotplug.enabled file location
holmanb pushed a commit to holmanb/cloud-init that referenced this pull request Mar 5, 2024
The cloud dir is configurable, so we shouldn't be hardcoding the
hotplug.enabled file location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants