aboutsummaryrefslogtreecommitdiffstats
path: root/molecule/default/tests/test_server_setup_multi_instance.py
diff options
context:
space:
mode:
Diffstat (limited to 'molecule/default/tests/test_server_setup_multi_instance.py')
-rw-r--r--molecule/default/tests/test_server_setup_multi_instance.py68
1 files changed, 39 insertions, 29 deletions
diff --git a/molecule/default/tests/test_server_setup_multi_instance.py b/molecule/default/tests/test_server_setup_multi_instance.py
index a235e2b..90c941c 100644
--- a/molecule/default/tests/test_server_setup_multi_instance.py
+++ b/molecule/default/tests/test_server_setup_multi_instance.py
@@ -1,12 +1,13 @@
"""Tests for borg server multi-instance repos and storage quota features"""
+
import pytest
import re
-testinfra_hosts = ['borg-server']
+testinfra_hosts = ["borg-server"]
SERVER_CONFIG = {
- 'user': 'borg',
- 'home': '/opt/borg',
+ "user": "borg",
+ "home": "/opt/borg",
}
@@ -22,13 +23,14 @@ class TestBorgSSHSetupMultiInstance:
auth_keys = host.file(f"{config['home']}/.ssh/authorized_keys")
content = auth_keys.content_string
lines_with_both_repos = [
- line for line in content.split('\n')
+ line
+ for line in content.split("\n")
if line
and f"{config['home']}/configs" in line
and f"{config['home']}/home-data" in line
]
assert len(lines_with_both_repos) == 1, (
- 'Expected exactly one authorized_keys line containing both configs and home-data repos, '
+ "Expected exactly one authorized_keys line containing both configs and home-data repos, "
f"found {len(lines_with_both_repos)}"
)
@@ -43,8 +45,12 @@ class TestBorgSSHSetupMultiInstance:
configs_count = restricted_repos.count(f"{config['home']}/configs")
home_data_count = restricted_repos.count(f"{config['home']}/home-data")
- assert configs_count == 1, f"configs repo should appear once in authorized_keys, found {configs_count}"
- assert home_data_count == 1, f"home-data repo should appear once in authorized_keys, found {home_data_count}"
+ assert configs_count == 1, (
+ f"configs repo should appear once in authorized_keys, found {configs_count}"
+ )
+ assert home_data_count == 1, (
+ f"home-data repo should appear once in authorized_keys, found {home_data_count}"
+ )
def test_authorized_keys_multi_instance_no_cross_host_repos(self, host, config):
"""Verify multi-instance host doesn't have repos from other hosts in authorized_keys"""
@@ -52,8 +58,9 @@ class TestBorgSSHSetupMultiInstance:
content = auth_keys.content_string
multi_lines = [
- line for line in content.split('\n')
- if line.rstrip().endswith('root@borg-client-multi')
+ line
+ for line in content.split("\n")
+ if line.rstrip().endswith("root@borg-client-multi")
]
assert len(multi_lines) == 1, (
f"Should have exactly one entry for borg-client-multi, found {len(multi_lines)}"
@@ -62,17 +69,17 @@ class TestBorgSSHSetupMultiInstance:
multi_line = multi_lines[0]
assert f"{config['home']}/configs" in multi_line, (
- 'borg-client-multi line should contain configs repo'
+ "borg-client-multi line should contain configs repo"
)
assert f"{config['home']}/home-data" in multi_line, (
- 'borg-client-multi line should contain home-data repo'
+ "borg-client-multi line should contain home-data repo"
)
assert f"{config['home']}/borg-client" not in multi_line, (
- 'borg-client-multi should NOT have access to borg-client repo'
+ "borg-client-multi should NOT have access to borg-client repo"
)
assert f"{config['home']}/borg-client-2" not in multi_line, (
- 'borg-client-multi should NOT have access to borg-client-2 repo'
+ "borg-client-multi should NOT have access to borg-client-2 repo"
)
@@ -84,9 +91,9 @@ class TestBorgSSHSetupStorageQuota:
auth_keys = host.file(f"{config['home']}/.ssh/authorized_keys")
content = auth_keys.content_string
- quotas = re.findall(r'--storage-quota (\S+)', content)
- assert '10G' in quotas, '10G quota should be set for configs-keys repo'
- assert '50G' in quotas, '50G quota should be set for home-data-keys repo'
+ quotas = re.findall(r"--storage-quota (\S+)", content)
+ assert "10G" in quotas, "10G quota should be set for configs-keys repo"
+ assert "50G" in quotas, "50G quota should be set for home-data-keys repo"
def test_authorized_keys_multi_keys_different_quotas(self, host, config):
"""Verify per-repo keys can have different storage quotas"""
@@ -94,22 +101,25 @@ class TestBorgSSHSetupStorageQuota:
content = auth_keys.content_string
multi_keys_lines = [
- line for line in content.split('\n')
- if line and 'root@borg-client-multi-keys' in line
+ line
+ for line in content.split("\n")
+ if line and "root@borg-client-multi-keys" in line
]
assert len(multi_keys_lines) == 2, (
f"Should have two entries for borg-client-multi-keys, found {len(multi_keys_lines)}"
)
- configs_line = [l for l in multi_keys_lines if 'configs-keys' in l][0]
- home_data_line = [l for l in multi_keys_lines if 'home-data-keys' in l][0]
+ configs_line = [line for line in multi_keys_lines if "configs-keys" in line][0]
+ home_data_line = [
+ line for line in multi_keys_lines if "home-data-keys" in line
+ ][0]
- assert '--storage-quota 10G' in configs_line, (
- 'configs-keys should have 10G quota'
+ assert "--storage-quota 10G" in configs_line, (
+ "configs-keys should have 10G quota"
)
- assert '--storage-quota 50G' in home_data_line, (
- 'home-data-keys should have 50G quota'
+ assert "--storage-quota 50G" in home_data_line, (
+ "home-data-keys should have 50G quota"
)
@@ -121,14 +131,14 @@ class TestBorgRepositoryMultiInstance:
home_data_repo = host.file(f"{config['home']}/home-data")
configs_exists = configs_repo.exists
home_data_exists = home_data_repo.exists
- assert configs_exists or 'skip' or home_data_exists or True
+ assert configs_exists or "skip" or home_data_exists or True
def test_configs_repo_accessible(self, host, config):
c = host.run(f"borg list {config['user']}@localhost:{config['home']}/configs")
- if c.rc != 0 and 'does not exist' in c.stderr:
- pytest.skip('configs repo not created in this test run')
+ if c.rc != 0 and "does not exist" in c.stderr:
+ pytest.skip("configs repo not created in this test run")
def test_home_data_repo_accessible(self, host, config):
c = host.run(f"borg list {config['user']}@localhost:{config['home']}/home-data")
- if c.rc != 0 and 'does not exist' in c.stderr:
- pytest.skip('home-data repo not created in this test run')
+ if c.rc != 0 and "does not exist" in c.stderr:
+ pytest.skip("home-data repo not created in this test run")