|
|
|
|
@ -11,6 +11,7 @@ from pathlib import Path
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
SCRIPT = ROOT / "docker-configs" / "upgrade-daprs-to-data-gateway.sh"
|
|
|
|
|
DEPLOYMENT_CHECK = ROOT / "docker-configs" / "check-deployment-version.sh"
|
|
|
|
|
INSTALLER = ROOT / "docker-configs" / "docker-compose_install.sh"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DataGatewayUpgradeTests(unittest.TestCase):
|
|
|
|
|
@ -35,10 +36,21 @@ class DataGatewayUpgradeTests(unittest.TestCase):
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
docker.chmod(0o755)
|
|
|
|
|
curl = bin_dir / "curl"
|
|
|
|
|
curl.write_text(
|
|
|
|
|
"#!/bin/sh\n"
|
|
|
|
|
"while [ \"$#\" -gt 0 ]; do\n"
|
|
|
|
|
" if [ \"$1\" = -o ]; then output=$2; shift 2; else shift; fi\n"
|
|
|
|
|
"done\n"
|
|
|
|
|
"cp \"$FREEDMR_TEST_UPGRADER\" \"$output\"\n",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
curl.chmod(0o755)
|
|
|
|
|
self.environment = os.environ.copy()
|
|
|
|
|
self.environment["PATH"] = (
|
|
|
|
|
str(bin_dir) + os.pathsep + self.environment["PATH"]
|
|
|
|
|
)
|
|
|
|
|
self.environment["FREEDMR_TEST_UPGRADER"] = str(SCRIPT)
|
|
|
|
|
|
|
|
|
|
def run_upgrade(self, *arguments):
|
|
|
|
|
return subprocess.run(
|
|
|
|
|
@ -49,6 +61,18 @@ class DataGatewayUpgradeTests(unittest.TestCase):
|
|
|
|
|
env=self.environment,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def run_installer(self, *arguments):
|
|
|
|
|
environment = dict(self.environment)
|
|
|
|
|
environment["FREEDMR_INSTALL_CONFIG_DIR"] = str(self.config_dir)
|
|
|
|
|
environment["FREEDMR_INSTALL_BASE_URL"] = "https://unused.invalid"
|
|
|
|
|
return subprocess.run(
|
|
|
|
|
["/bin/bash", str(INSTALLER), *arguments],
|
|
|
|
|
check=False,
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True,
|
|
|
|
|
env=environment,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_migrates_using_values_from_config_and_compose(self):
|
|
|
|
|
result = self.run_upgrade("--yes")
|
|
|
|
|
|
|
|
|
|
@ -92,6 +116,18 @@ class DataGatewayUpgradeTests(unittest.TestCase):
|
|
|
|
|
generated_key = parser.get("DATA-GATEWAY", "PASSPHRASE")
|
|
|
|
|
self.assertRegex(generated_key, r"^[0-9a-f]{20}$")
|
|
|
|
|
self.assertTrue(all(item["key"] == generated_key for item in relationships))
|
|
|
|
|
relationship_file = self.config_dir / "data-gateway-relationships.json"
|
|
|
|
|
self.assertEqual(json.loads(relationship_file.read_text()), relationships)
|
|
|
|
|
self.assertIn(
|
|
|
|
|
"FREEDMR_GATEWAY_FBP_RELATIONSHIPS_FILE: "
|
|
|
|
|
"/config/data-gateway-relationships.json",
|
|
|
|
|
compose,
|
|
|
|
|
)
|
|
|
|
|
self.assertIn(
|
|
|
|
|
"/etc/freedmr/data-gateway-relationships.json:"
|
|
|
|
|
"/config/data-gateway-relationships.json:ro",
|
|
|
|
|
compose,
|
|
|
|
|
)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
len(list(self.config_dir.glob("freedmr.cfg.before-data-gateway.*"))),
|
|
|
|
|
1,
|
|
|
|
|
@ -223,7 +259,7 @@ class DataGatewayUpgradeTests(unittest.TestCase):
|
|
|
|
|
second = self.run_upgrade("--yes")
|
|
|
|
|
|
|
|
|
|
self.assertEqual(second.returncode, 0, second.stderr)
|
|
|
|
|
self.assertIn("already at version 1", second.stdout)
|
|
|
|
|
self.assertIn("already at version 2", second.stdout)
|
|
|
|
|
self.assertEqual(self.config.read_bytes(), original_config)
|
|
|
|
|
self.assertEqual(self.compose.read_bytes(), original_compose)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
@ -247,7 +283,7 @@ class DataGatewayUpgradeTests(unittest.TestCase):
|
|
|
|
|
second = self.run_upgrade("--yes")
|
|
|
|
|
|
|
|
|
|
self.assertEqual(second.returncode, 0, second.stderr)
|
|
|
|
|
self.assertIn("already at version 1", second.stdout)
|
|
|
|
|
self.assertIn("already at version 2", second.stdout)
|
|
|
|
|
self.assertEqual(self.config.read_bytes(), original_config)
|
|
|
|
|
self.assertEqual(self.compose.read_bytes(), original_compose)
|
|
|
|
|
|
|
|
|
|
@ -282,7 +318,7 @@ class DataGatewayUpgradeTests(unittest.TestCase):
|
|
|
|
|
self.assertEqual(parser.get("DATA-GATEWAY", "PASSPHRASE"), expected_key)
|
|
|
|
|
self.assertTrue(parser.getboolean("DATA-GATEWAY", "ENABLED"))
|
|
|
|
|
self.assertIn(
|
|
|
|
|
"# FREEDMR_DEPLOYMENT_VERSION=1",
|
|
|
|
|
"# FREEDMR_DEPLOYMENT_VERSION=2",
|
|
|
|
|
self.config.read_text(encoding="utf-8"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -313,7 +349,7 @@ class DataGatewayUpgradeTests(unittest.TestCase):
|
|
|
|
|
self.assertEqual(result.returncode, 2)
|
|
|
|
|
self.assertIn("another FreeDMR deployment upgrade", result.stderr)
|
|
|
|
|
|
|
|
|
|
def test_refuses_conflicting_native_relationship_layout(self):
|
|
|
|
|
def test_preserves_existing_native_relationship_layout(self):
|
|
|
|
|
first = self.run_upgrade("--yes")
|
|
|
|
|
self.assertEqual(first.returncode, 0, first.stderr)
|
|
|
|
|
self.compose.write_text(
|
|
|
|
|
@ -323,15 +359,71 @@ class DataGatewayUpgradeTests(unittest.TestCase):
|
|
|
|
|
),
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
original_config = self.config.read_bytes()
|
|
|
|
|
original_compose = self.compose.read_bytes()
|
|
|
|
|
result = self.run_upgrade("--yes")
|
|
|
|
|
|
|
|
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
|
relationships = self._relationships(self.compose.read_text(encoding="utf-8"))
|
|
|
|
|
self.assertEqual(relationships[1]["peer_network_id"], 99999)
|
|
|
|
|
relationship_file = self.config_dir / "data-gateway-relationships.json"
|
|
|
|
|
self.assertEqual(json.loads(relationship_file.read_text()), relationships)
|
|
|
|
|
|
|
|
|
|
def test_upgrades_version_one_native_complex_relationships(self):
|
|
|
|
|
first = self.run_upgrade("--yes")
|
|
|
|
|
self.assertEqual(first.returncode, 0, first.stderr)
|
|
|
|
|
relationship_file = self.config_dir / "data-gateway-relationships.json"
|
|
|
|
|
relationship_file.unlink()
|
|
|
|
|
self.config.write_text(
|
|
|
|
|
self.config.read_text(encoding="utf-8").replace(
|
|
|
|
|
"# FREEDMR_DEPLOYMENT_VERSION=2",
|
|
|
|
|
"# FREEDMR_DEPLOYMENT_VERSION=1",
|
|
|
|
|
),
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
compose = self.compose.read_text(encoding="utf-8")
|
|
|
|
|
compose = compose.replace(
|
|
|
|
|
" FREEDMR_GATEWAY_FBP_RELATIONSHIPS_FILE: "
|
|
|
|
|
"/config/data-gateway-relationships.json\n",
|
|
|
|
|
"",
|
|
|
|
|
).replace(
|
|
|
|
|
" - '/etc/freedmr/data-gateway-relationships.json:"
|
|
|
|
|
"/config/data-gateway-relationships.json:ro'\n",
|
|
|
|
|
"",
|
|
|
|
|
)
|
|
|
|
|
compose = compose.replace(
|
|
|
|
|
'"peer_network_id":23402',
|
|
|
|
|
'"peer_network_id":99999',
|
|
|
|
|
)
|
|
|
|
|
self.compose.write_text(compose, encoding="utf-8")
|
|
|
|
|
|
|
|
|
|
result = self.run_upgrade("--yes")
|
|
|
|
|
|
|
|
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
|
updated = self.compose.read_text(encoding="utf-8")
|
|
|
|
|
relationships = self._relationships(updated)
|
|
|
|
|
self.assertEqual(relationships[1]["peer_network_id"], 99999)
|
|
|
|
|
self.assertEqual(json.loads(relationship_file.read_text()), relationships)
|
|
|
|
|
self.assertIn("# FREEDMR_DEPLOYMENT_VERSION=2", self.config.read_text())
|
|
|
|
|
|
|
|
|
|
def test_installer_delegates_existing_deployment_to_upgrader(self):
|
|
|
|
|
result = self.run_installer("--yes")
|
|
|
|
|
|
|
|
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
|
|
|
self.assertIn("deployment upgrade to version 2 complete", result.stdout)
|
|
|
|
|
self.assertIn("fresh-install steps were not run", result.stdout)
|
|
|
|
|
self.assertNotIn("Installing required packages", result.stdout)
|
|
|
|
|
self.assertTrue(
|
|
|
|
|
(self.config_dir / "data-gateway-relationships.json").is_file()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_installer_refuses_incomplete_existing_deployment(self):
|
|
|
|
|
self.compose.unlink()
|
|
|
|
|
original_config = self.config.read_bytes()
|
|
|
|
|
|
|
|
|
|
result = self.run_installer("--yes")
|
|
|
|
|
|
|
|
|
|
self.assertEqual(result.returncode, 2)
|
|
|
|
|
self.assertIn("do not match the configured HDStack layout", result.stderr)
|
|
|
|
|
self.assertIn("deployment is incomplete", result.stderr)
|
|
|
|
|
self.assertEqual(self.config.read_bytes(), original_config)
|
|
|
|
|
self.assertEqual(self.compose.read_bytes(), original_compose)
|
|
|
|
|
|
|
|
|
|
def test_refuses_unrecognised_legacy_service_without_changes(self):
|
|
|
|
|
self.compose.write_text(
|
|
|
|
|
@ -379,7 +471,7 @@ class DeploymentVersionCheckTests(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_current_deployment_is_accepted_silently(self):
|
|
|
|
|
self.config.write_text(
|
|
|
|
|
"# FREEDMR_DEPLOYMENT_VERSION=1\n[GLOBAL]\n",
|
|
|
|
|
"# FREEDMR_DEPLOYMENT_VERSION=2\n[GLOBAL]\n",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|