diff --git a/node-runner-cli/Pipfile b/node-runner-cli/Pipfile index 16c5976c..b5794d4d 100644 --- a/node-runner-cli/Pipfile +++ b/node-runner-cli/Pipfile @@ -4,6 +4,7 @@ verify_ssl = true name = "pypi" [packages] +responses= "==0.23.3" requests = "==2.31.0" PyYAML = "==6.0.0" deepmerge = "==0.3.0" diff --git a/node-runner-cli/config/BaseConfig.py b/node-runner-cli/config/BaseConfig.py index f5ddd576..8dc010ab 100644 --- a/node-runner-cli/config/BaseConfig.py +++ b/node-runner-cli/config/BaseConfig.py @@ -59,6 +59,10 @@ def to_yaml(self): def to_file(self, config_file): config_to_dump = self.to_dict() with open(config_file, 'w') as f: + f.write("# WARNING!! This file is automatically generated and it is\n") + f.write("# overriden when on install/update commands.\n") + f.write("# Please consider re-running config/install commands rather\n") + f.write("# than manually edit this file\n") yaml.dump(config_to_dump, f, sort_keys=True, default_flow_style=False) diff --git a/node-runner-cli/templates/node-monitoring.yml.j2 b/node-runner-cli/templates/node-monitoring.yml.j2 index 3cb5b0c0..b3080f07 100644 --- a/node-runner-cli/templates/node-monitoring.yml.j2 +++ b/node-runner-cli/templates/node-monitoring.yml.j2 @@ -1,3 +1,8 @@ +# WARNING!! This file is automatically generated and it is +# overriden when on install/update commands. +# Please consider re-running config/install commands rather +# than manually edit this file + version: '2.4' services: diff --git a/node-runner-cli/templates/radix-fullnode-compose.yml.j2 b/node-runner-cli/templates/radix-fullnode-compose.yml.j2 index b445f3b3..4c174d4f 100644 --- a/node-runner-cli/templates/radix-fullnode-compose.yml.j2 +++ b/node-runner-cli/templates/radix-fullnode-compose.yml.j2 @@ -1,3 +1,8 @@ +# WARNING!! This file is automatically generated and it is +# overriden when on install/update commands. +# Please consider re-running config/install commands rather +# than manually edit this file + version: '3.8' services: {% if core_node is not none and core_node is defined %} diff --git a/node-runner-cli/templates/standalone-gateway-compose.yml.j2 b/node-runner-cli/templates/standalone-gateway-compose.yml.j2 index b1e63ec7..ecc24e50 100644 --- a/node-runner-cli/templates/standalone-gateway-compose.yml.j2 +++ b/node-runner-cli/templates/standalone-gateway-compose.yml.j2 @@ -1,3 +1,8 @@ +# WARNING!! This file is automatically generated and it is +# overriden when on install/update commands. +# Please consider re-running config/install commands rather +# than manually edit this file + version: '3.8' services: gateway_api: # This is the base -- the _image and _built containers are defined below diff --git a/node-runner-cli/templates/systemd-default.config.j2 b/node-runner-cli/templates/systemd-default.config.j2 index 65f8a5c8..2cab517a 100644 --- a/node-runner-cli/templates/systemd-default.config.j2 +++ b/node-runner-cli/templates/systemd-default.config.j2 @@ -1,3 +1,8 @@ +# WARNING!! This file is automatically generated and it is +# overriden when on install/update commands. +# Please consider re-running config/install commands rather +# than manually edit this file + ntp=false ntp.pool=pool.ntp.org diff --git a/node-runner-cli/tests/fixtures/gateway-docker-compose.yaml b/node-runner-cli/tests/fixtures/gateway-docker-compose.yaml index cb183b82..ed7d1b33 100644 --- a/node-runner-cli/tests/fixtures/gateway-docker-compose.yaml +++ b/node-runner-cli/tests/fixtures/gateway-docker-compose.yaml @@ -1,3 +1,8 @@ +# WARNING!! This file is automatically generated and it is +# overriden when on install/update commands. +# Please consider re-running config/install commands rather +# than manually edit this file + version: '3.8' services: gateway_api: # This is the base -- the _image and _built containers are defined below diff --git a/node-runner-cli/tests/unit/test_gateway_setup.py b/node-runner-cli/tests/unit/test_gateway_setup.py index 01e8065f..fababfd0 100644 --- a/node-runner-cli/tests/unit/test_gateway_setup.py +++ b/node-runner-cli/tests/unit/test_gateway_setup.py @@ -9,6 +9,7 @@ from deepdiff import DeepDiff from yaml import UnsafeLoader +from config.BaseConfig import SetupMode from config.DockerConfig import DockerConfig from config.SystemDConfig import SystemDConfig from setup.DockerSetup import DockerSetup @@ -125,6 +126,8 @@ def render_compose_fixture(self): @patch('sys.stdout', new_callable=StringIO) def test_setup_gateway_ask_core_api(self, mockout): + SetupMode.instance() + SetupMode.mode = "DETAILED" urllib3.disable_warnings() keyboard_input = ["", "CoreNodeName"] default_value = "http://localhost:3332" @@ -185,7 +188,8 @@ def test_setup_gateway_compose_file_fixture_test(self, mockout): with patch('builtins.input', side_effect=[install_keyboard_input]): GatewaySetup.conditionaly_install_standalone_gateway(config) - fixture_file = "./tests/fixtures/gateway-docker-compose.yaml" + tests_dir = dirname(dirname(__file__)) + fixture_file = join(tests_dir, "fixtures/gateway-docker-compose.yaml") with open(fixture_file) as f1: with open(config.gateway.docker_compose) as f2: self.assertEqual(f1.read(), f2.read()) diff --git a/node-runner-cli/tests/unit/test_systemd.py b/node-runner-cli/tests/unit/test_systemd.py index 59b37d74..f56ae44b 100644 --- a/node-runner-cli/tests/unit/test_systemd.py +++ b/node-runner-cli/tests/unit/test_systemd.py @@ -5,6 +5,7 @@ from unittest.mock import patch import urllib3 +import responses from babylonnode import main from config.CommonSystemDConfig import CommonSystemdConfig @@ -68,15 +69,21 @@ def test_systemd_dependencies(self): ["main", "systemd", "dependencies"]): main() + @responses.activate @patch('sys.stdout', new_callable=StringIO) def test_systemd_config(self, mockout): urllib3.disable_warnings() + responses.add( + responses.GET, + f'https://api.github.com/repos/radixdlt/babylon-nginx/releases/latest', + json={'tag_name': "v1"}, + status=200) with patch('builtins.input', side_effect=['Y']): with patch("sys.argv", ["main", "systemd", "config", "-m", "CORE", "-i", "18.133.170.30", "-t", "radix://tn1q28eygvxshszxk48jhjxdmyne06m3x6hfyvxg7a45qt8cksffx6z7uu6392@15.236.228.96", "-n", "2", "-k", "radix", "-d", "/tmp", "-dd", "/tmp", "-v", "randomvalidatoraddress", "-nk", - "-a"]): + "-a", "-r", "1"]): main() @unittest.skip("For verification only") @@ -102,7 +109,12 @@ def test_systemd_setup_default_config(self, mockout): f = open("/tmp/default.config", "r") default_config = f.read() - fixture = """ntp=false + fixture = """# WARNING!! This file is automatically generated and it is +# overriden when on install/update commands. +# Please consider re-running config/install commands rather +# than manually edit this file + +ntp=false ntp.pool=pool.ntp.org network.id=1 @@ -147,7 +159,12 @@ def test_systemd_setup_default_config_without_validator(self, mockout): f = open("/tmp/default.config", "r") default_config = f.read() - fixture = """ntp=false + fixture = """ # WARNING!! This file is automatically generated and it is +# overriden when on install/update commands. +# Please consider re-running config/install commands rather +# than manually edit this file + +ntp=false ntp.pool=pool.ntp.org network.id=1 @@ -186,7 +203,12 @@ def test_systemd_setup_default_config_jinja(self, mockout): settings.migration.use_olympia = False render_template = Renderer().load_file_based_template("systemd-default.config.j2").render( settings.to_dict()).rendered - fixture = """ntp=false + fixture = """# WARNING!! This file is automatically generated and it is +# overriden when on install/update commands. +# Please consider re-running config/install commands rather +# than manually edit this file + +ntp=false ntp.pool=pool.ntp.org network.id=1 @@ -317,7 +339,26 @@ def test_systemd_java_opts_increased_on_migration(self): environment_yaml = settings.create_environment_yaml() self.assertTrue("-Xms12g -Xmx12g" in environment_yaml) + @responses.activate def test_systemd_version_update(self): + responses.add( + responses.GET, + f'https://api.github.com/repos/radixdlt/babylon-node/releases/latest', + json={'tag_name': "v1"}, + status=200) + + responses.add( + responses.GET, + f'https://api.github.com/repos/radixdlt/babylon-gateway/releases/latest', + json={'tag_name': "v1"}, + status=200) + + responses.add( + responses.GET, + f'https://api.github.com/repos/radixdlt/babylon-nginx/releases/latest', + json={'tag_name': "v1"}, + status=200) + systemd_config = SystemDConfig({}) systemd_config.gateway.enabled = True systemd_config.core_node.core_release = "oldversion"