Add Debian persistence acceptance drill
This commit is contained in:
@@ -16,6 +16,65 @@ spec.loader.exec_module(ops)
|
||||
|
||||
|
||||
class ArchiveTests(unittest.TestCase):
|
||||
def test_persistence_layout_resolves_shared_keys_and_database(self):
|
||||
config = {
|
||||
"services": {
|
||||
"api": {"volumes": [{"type": "volume", "source": "app-keys", "target": "/var/lib/guestops/keys"}]},
|
||||
"worker": {"volumes": [{"type": "volume", "source": "app-keys", "target": "/var/lib/guestops/keys"}]},
|
||||
"mongo": {"volumes": [{"type": "volume", "source": "mongo-data", "target": "/data/db"}]},
|
||||
},
|
||||
"volumes": {
|
||||
"app-keys": {"name": "guestops_app-keys"},
|
||||
"mongo-data": {"name": "guestops_mongo-data"},
|
||||
},
|
||||
}
|
||||
self.assertEqual(ops.persistence_layout(config), {"keys": "guestops_app-keys", "database": "guestops_mongo-data"})
|
||||
|
||||
def test_persistence_layout_rejects_anonymous_or_split_keys(self):
|
||||
config = {
|
||||
"services": {
|
||||
"api": {"volumes": [{"type": "volume", "source": "api-keys", "target": "/var/lib/guestops/keys"}]},
|
||||
"worker": {"volumes": [{"type": "volume", "source": "worker-keys", "target": "/var/lib/guestops/keys"}]},
|
||||
"mongo": {"volumes": [{"type": "volume", "source": "mongo-data", "target": "/data/db"}]},
|
||||
},
|
||||
"volumes": {"api-keys": {}, "worker-keys": {}, "mongo-data": {}},
|
||||
}
|
||||
with self.assertRaisesRegex(RuntimeError, "key volumes differ"):
|
||||
ops.persistence_layout(config)
|
||||
|
||||
config["services"]["worker"]["volumes"][0] = {"type": "volume", "target": "/var/lib/guestops/keys"}
|
||||
with self.assertRaisesRegex(RuntimeError, "named persistent volume"):
|
||||
ops.persistence_layout(config)
|
||||
|
||||
def test_persistence_drill_requires_explicit_restart_confirmation(self):
|
||||
with self.assertRaisesRegex(RuntimeError, "confirm-restart"):
|
||||
ops.persistence_drill(type("Args", (), {"confirm_restart": False})())
|
||||
|
||||
def test_persistence_drill_restarts_then_recreates_stateless_services(self):
|
||||
compose_calls = []
|
||||
inventory = json.dumps({"bytes": 1, "collections": {"hotels": {"count": 1, "indexes": []}}}).encode()
|
||||
|
||||
def compose(*args, **kwargs):
|
||||
compose_calls.append(args)
|
||||
return b"a" * 30 if args[-1] == "--backup-probe" else b""
|
||||
|
||||
def mongo(script):
|
||||
return inventory if "storageSize" in script else b""
|
||||
|
||||
with patch.object(ops, "configuration", return_value={}), \
|
||||
patch.object(ops, "persistence_layout", return_value={"keys": "keys", "database": "data"}), \
|
||||
patch.object(ops, "volume_identity", side_effect=lambda name: {"name": name, "driver": "local", "scope": "local"}), \
|
||||
patch.object(ops, "compose", side_effect=compose), \
|
||||
patch.object(ops, "mongo", side_effect=mongo), \
|
||||
patch.object(ops, "wait_for", side_effect=lambda action, message: action()), \
|
||||
patch.object(ops, "readiness"):
|
||||
ops.persistence_drill(type("Args", (), {"confirm_restart": True})())
|
||||
|
||||
self.assertIn(("restart", "-t", "150", "mongo"), compose_calls)
|
||||
self.assertIn(("restart", "-t", "150", "api", "worker"), compose_calls)
|
||||
self.assertIn(("up", "-d", "--no-build", "--force-recreate", "api", "worker"), compose_calls)
|
||||
self.assertTrue(any("--verify-backup-probe" in call for call in compose_calls))
|
||||
|
||||
def test_empty_provider_templates_are_not_secret_configuration(self):
|
||||
for section, target in (("Pms", "/run/guestops/pms.json"), ("Payments", "/run/guestops/payments.json")):
|
||||
self.assertFalse(ops.provider_configured({section: {"Hotels": {}}}, target))
|
||||
|
||||
Reference in New Issue
Block a user