-
Notifications
You must be signed in to change notification settings - Fork 1.1k
LXD storage backend integration tests #1602
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
Merged
blackboxsw
merged 24 commits into
canonical:main
from
holmanb:holmanb/lxd_storage_integration
Jul 28, 2022
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9a4c49a
rename file more generic
holmanb df734ef
Add tests for lxd backends
holmanb 6ff4e8d
use verification func
holmanb 3ee7ba5
drop lvm workaround (not needed?
holmanb 34f8a5b
fmt
holmanb ec83781
check package install
holmanb d2e1c5f
test
holmanb 18d8ea0
unmask
holmanb 34c1da6
ignore test for a sec
holmanb 2243540
Workaround kernel bug
holmanb 4a075be
tests
holmanb baf5553
tests
holmanb b21ec5c
don't configure storage twice
holmanb 2bd230b
pop key
holmanb a6d76a8
tests
holmanb 0aef404
typing
holmanb 7b24279
typing
holmanb 866115c
suggestions
holmanb 62522d7
change behavior based on the existance of a kmod
holmanb e76c877
less metaphysical, more kmod testing
holmanb dfca33c
fmt
holmanb 7119057
thanks @blackboxsw
holmanb 8e7000f
fmt
holmanb d28e87e
tests: update verify_clean_log warning text add check for apt install
blackboxsw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| """Integration tests for LXD bridge creation. | ||
|
|
||
| (This is ported from | ||
| ``tests/cloud_tests/testcases/modules/lxd_bridge.yaml``.) | ||
| """ | ||
| import re | ||
| import warnings | ||
|
|
||
| import pytest | ||
| import yaml | ||
|
|
||
| from tests.integration_tests.util import verify_clean_log | ||
|
|
||
| BRIDGE_USER_DATA = """\ | ||
| #cloud-config | ||
| lxd: | ||
| init: | ||
| storage_backend: btrfs | ||
| bridge: | ||
| mode: new | ||
| name: lxdbr0 | ||
| ipv4_address: 10.100.100.1 | ||
| ipv4_netmask: 24 | ||
| ipv4_dhcp_first: 10.100.100.100 | ||
| ipv4_dhcp_last: 10.100.100.200 | ||
| ipv4_nat: true | ||
| domain: lxd | ||
| mtu: 9000 | ||
| """ | ||
|
|
||
| STORAGE_USER_DATA = """\ | ||
| #cloud-config | ||
| bootcmd: [ "apt-get --yes remove {0}", "! command -v {2}", "{3}" ] | ||
| lxd: | ||
| init: | ||
| storage_backend: {1} | ||
| """ | ||
|
|
||
|
|
||
| @pytest.mark.no_container | ||
| @pytest.mark.user_data(BRIDGE_USER_DATA) | ||
| class TestLxdBridge: | ||
| @pytest.mark.parametrize("binary_name", ["lxc", "lxd"]) | ||
| def test_binaries_installed(self, class_client, binary_name): | ||
| """Check that the expected LXD binaries are installed""" | ||
| assert class_client.execute(["which", binary_name]).ok | ||
|
|
||
| def test_bridge(self, class_client): | ||
| """Check that the given bridge is configured""" | ||
| cloud_init_log = class_client.read_from_file("/var/log/cloud-init.log") | ||
| verify_clean_log(cloud_init_log) | ||
|
|
||
| # The bridge should exist | ||
| assert class_client.execute("ip addr show lxdbr0") | ||
|
|
||
| raw_network_config = class_client.execute("lxc network show lxdbr0") | ||
| network_config = yaml.safe_load(raw_network_config) | ||
| assert "10.100.100.1/24" == network_config["config"]["ipv4.address"] | ||
|
|
||
|
|
||
| def validate_storage(validate_client, pkg_name, command): | ||
| log = validate_client.read_from_file("/var/log/cloud-init.log") | ||
| assert re.search(f"apt-get.*install.*{pkg_name}", log) is not None | ||
| verify_clean_log(log, ignore_deprecations=False) | ||
| return log | ||
|
|
||
|
|
||
| @pytest.mark.no_container | ||
| @pytest.mark.user_data( | ||
| STORAGE_USER_DATA.format("btrfs-progs", "btrfs", "mkfs.btrfs", "true") | ||
| ) | ||
| def test_storage_btrfs(client): | ||
| validate_storage(client, "btrfs-progs", "mkfs.btrfs") | ||
|
|
||
|
|
||
| @pytest.mark.no_container | ||
| @pytest.mark.user_data( | ||
| STORAGE_USER_DATA.format( | ||
| "lvm2", | ||
| "lvm", | ||
| "lvcreate", | ||
| "apt-get install " | ||
| "thin-provisioning-tools && systemctl unmask lvm2-lvmpolld.socket", | ||
| ) | ||
| ) | ||
| def test_storage_lvm(client): | ||
| log = client.read_from_file("/var/log/cloud-init.log") | ||
|
|
||
| # Note to self | ||
|
Contributor
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. Nice one! |
||
| if "doesn't use thinpool by default on Ubuntu due to LP" not in log: | ||
| warnings.warn("LP 1982780 has been fixed, update to allow thinpools") | ||
|
|
||
| validate_storage(client, "lvm2", "lvcreate") | ||
|
|
||
|
|
||
| @pytest.mark.no_container | ||
| @pytest.mark.user_data( | ||
| STORAGE_USER_DATA.format("zfsutils-linux", "zfs", "zpool", "true") | ||
| ) | ||
| def test_storage_zfs(client): | ||
| validate_storage(client, "zfsutils-linux", "zpool") | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This issue isn't limited to ubuntu, it's possible that this is a problem on any given OS/kernel if the right kernel modules are not included.
I think we instead want to perform a check to see if the dm-thin-pool module is present for the active kernel.
We can either do that through:
2 subp.subp(['modinfo', 'dm-thin-pool']) and check if we hit ProcesseExecutionError "modinfo: ERROR: Module dm-thin-pools not found.".
I'd lean toward solution #1 because solution #2 requires either a strict package dependency on
kmodor optional runtime package dependency on kmow which I don't think we should grow broadly in cloud-init for this one off use-case when all we need it for is a file check.Uh oh!
There was an error while loading. Please reload this page.
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.
Since this config module is limited to ubuntu, I think it is ubuntu-specific.
This approach causes a behavioral change that would be unpleasant to debug: kmod package update will change cloud-init behavior under this scheme. However, since we're logging this when the kmod is missing, I guess there is a breadcrumb.
I'll grab the first option in case we want to extend cc_lxd support to other linux distros.
Thanks!
Uh oh!
There was an error while loading. Please reload this page.
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.
Note to self: If we get rid of the cast-to-list in
system_info(), we get a named tuple for free (and more readable code).Uh oh!
There was an error while loading. Please reload this page.
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.
+1 I was thinking the same, though we'd maybe have to look at how that is represented in
/run/cloud-init/instance-data.jsonto be sure we aren't doing some funky object-style annotations in the JSON output as I believe this data is surfaced there too.