From 01a154cd45da9b6c523d1015c8aa0061363e1bbd Mon Sep 17 00:00:00 2001 From: Jacob Riddle <87780794+jriddle-linode@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:12:27 -0400 Subject: [PATCH] fix: remove dbaas configuration (#527) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 📝 Description **What does this PR do and why is this change necessary?** Removing dbaas configuraiton steps as dbaas is now opt-in only. ## ✔️ How to Test **How do I run the relevant unit/integration tests?** `pytest -v tests/unit/test_configuration.py` --- linodecli/api_request.py | 4 +-- linodecli/configuration/__init__.py | 42 +---------------------------- tests/unit/conftest.py | 1 - tests/unit/test_api_request.py | 21 +++++++-------- tests/unit/test_configuration.py | 37 ------------------------- 5 files changed, 11 insertions(+), 94 deletions(-) diff --git a/linodecli/api_request.py b/linodecli/api_request.py index f3c77e60b..4273aa6d2 100644 --- a/linodecli/api_request.py +++ b/linodecli/api_request.py @@ -206,9 +206,7 @@ def _build_request_body(ctx, operation, parsed_args) -> Optional[str]: # Merge defaults into body if applicable if ctx.defaults: - parsed_args = ctx.config.update( - parsed_args, operation.allowed_defaults, operation.action - ) + parsed_args = ctx.config.update(parsed_args, operation.allowed_defaults) to_json = {} diff --git a/linodecli/configuration/__init__.py b/linodecli/configuration/__init__.py index 8dca5ebaa..f9542998b 100644 --- a/linodecli/configuration/__init__.py +++ b/linodecli/configuration/__init__.py @@ -216,7 +216,7 @@ def plugin_get_value(self, key): # might be better to move this to argparsing during refactor and just have # configuration return defaults or keys or something def update( - self, namespace, allowed_defaults, action=None + self, namespace, allowed_defaults ): # pylint: disable=too-many-branches """ This updates a Namespace (as returned by ArgumentParser) with config values @@ -247,17 +247,6 @@ def update( value = None if self.config.has_option(username, key): value = self.config.get(username, key) - # different types of database creation use different endpoints, - # so we need to set the default engine value based on the type - elif key == "engine": - if action == "mysql-create" and self.config.has_option( - username, "mysql_engine" - ): - value = self.config.get(username, "mysql_engine") - elif action == "postgresql-create" and self.config.has_option( - username, "postgresql_engine" - ): - value = self.config.get(username, "postgresql_engine") else: value = ns_dict[key] @@ -354,15 +343,6 @@ def configure( images = [ i["id"] for i in _do_get_request(self.base_url, "/images")["data"] ] - engines_list = _do_get_request(self.base_url, "/databases/engines")[ - "data" - ] - mysql_engines = [ - e["id"] for e in engines_list if e["engine"] == "mysql" - ] - postgresql_engines = [ - e["id"] for e in engines_list if e["engine"] == "postgresql" - ] is_full_access = _check_full_access(self.base_url, token) @@ -414,26 +394,6 @@ def configure( ), ) - config["mysql_engine"] = _default_thing_input( - "Default Engine to create a Managed MySQL Database.", - mysql_engines, - "Default Engine (Optional): ", - "Please select a valid MySQL Database Engine, or press Enter to skip", - current_value=_config_get_with_default( - self.config, username, "mysql_engine" - ), - ) - - config["postgresql_engine"] = _default_thing_input( - "Default Engine to create a Managed PostgreSQL Database.", - postgresql_engines, - "Default Engine (Optional): ", - "Please select a valid PostgreSQL Database Engine, or press Enter to skip", - current_value=_config_get_with_default( - self.config, username, "postgresql_engine" - ), - ) - if auth_users: config["authorized_users"] = _default_thing_input( "Select the user that should be given default SSH access to new Linodes.", diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 8110e2917..e6a3e8129 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -17,7 +17,6 @@ image = linode/ubuntu21.10 token = notafaketoken type = g6-nanode-1 -mysql_engine = mysql/8.0.26 """ LOADED_FILES = {} diff --git a/tests/unit/test_api_request.py b/tests/unit/test_api_request.py index 9172bbbbd..167a2e087 100644 --- a/tests/unit/test_api_request.py +++ b/tests/unit/test_api_request.py @@ -56,8 +56,7 @@ def test_request_debug_info(self): assert "> " in output def test_build_request_body(self, mock_cli, create_operation): - create_operation.allowed_defaults = ["region", "engine"] - create_operation.action = "mysql-create" + create_operation.allowed_defaults = ["region", "image"] result = api_request._build_request_body( mock_cli, @@ -65,7 +64,7 @@ def test_build_request_body(self, mock_cli, create_operation): SimpleNamespace( generic_arg="foo", region=None, - engine=None, + image=None, ), ) assert ( @@ -73,22 +72,21 @@ def test_build_request_body(self, mock_cli, create_operation): { "generic_arg": "foo", "region": "us-southeast", - "engine": "mysql/8.0.26", + "image": "linode/ubuntu21.10", } ) == result ) def test_build_request_body_null_field(self, mock_cli, create_operation): - create_operation.allowed_defaults = ["region", "engine"] - create_operation.action = "mysql-create" + create_operation.allowed_defaults = ["region", "image"] result = api_request._build_request_body( mock_cli, create_operation, SimpleNamespace( generic_arg="foo", region=None, - engine=None, + image=None, nullable_int=ExplicitNullValue(), ), ) @@ -97,7 +95,7 @@ def test_build_request_body_null_field(self, mock_cli, create_operation): { "generic_arg": "foo", "region": "us-southeast", - "engine": "mysql/8.0.26", + "image": "linode/ubuntu21.10", "nullable_int": None, } ) @@ -107,15 +105,14 @@ def test_build_request_body_null_field(self, mock_cli, create_operation): def test_build_request_body_non_null_field( self, mock_cli, create_operation ): - create_operation.allowed_defaults = ["region", "engine"] - create_operation.action = "mysql-create" + create_operation.allowed_defaults = ["region", "image"] result = api_request._build_request_body( mock_cli, create_operation, SimpleNamespace( generic_arg="foo", region=None, - engine=None, + image=None, nullable_int=12345, ), ) @@ -124,7 +121,7 @@ def test_build_request_body_non_null_field( { "generic_arg": "foo", "region": "us-southeast", - "engine": "mysql/8.0.26", + "image": "linode/ubuntu21.10", "nullable_int": 12345, } ) diff --git a/tests/unit/test_configuration.py b/tests/unit/test_configuration.py index eb286c5dd..fe4e400b7 100644 --- a/tests/unit/test_configuration.py +++ b/tests/unit/test_configuration.py @@ -234,13 +234,6 @@ def test_update(self): assert "--no-defaults" not in f.getvalue() - # test that update default engine value correctly when creating database - create_db_action = "mysql-create" - f = io.StringIO() - with contextlib.redirect_stdout(f): - result = vars(conf.update(ns, allowed_defaults, create_db_action)) - assert result.get("engine") == "mysql/new-test-engine" - def test_write_config(self): """ Test CLIConfig.write_config() @@ -302,18 +295,6 @@ def mock_input(prompt): m.get( f"{self.base_url}/images", json={"data": [{"id": "test-image"}]} ) - m.get( - f"{self.base_url}/databases/engines", - json={ - "data": [ - {"id": "mysql/test-engine", "engine": "mysql"}, - { - "id": "postgresql/test-engine", - "engine": "postgresql", - }, - ] - }, - ) m.get( f"{self.base_url}/account/users", json={"data": [{"username": "cli-dev", "ssh_keys": "testkey"}]}, @@ -325,9 +306,6 @@ def mock_input(prompt): assert conf.get_value("image") == "test-image" assert conf.get_value("region") == "test-region" assert conf.get_value("authorized_users") == "cli-dev" - # make sure that we set the default engine value according to type of database - assert conf.get_value("mysql_engine") == "mysql/test-engine" - assert conf.get_value("postgresql_engine") == "postgresql/test-engine" assert conf.get_value("api_host") == "foobar.linode.com" assert conf.get_value("api_version") == "v4beta" assert conf.get_value("api_scheme") == "https" @@ -368,18 +346,6 @@ def mock_input(prompt): m.get( f"{self.base_url}/images", json={"data": [{"id": "test-image"}]} ) - m.get( - f"{self.base_url}/databases/engines", - json={ - "data": [ - {"id": "mysql/test-engine", "engine": "mysql"}, - { - "id": "postgresql/test-engine", - "engine": "postgresql", - }, - ] - }, - ) m.get( f"{self.base_url}/account/users", json={"data": [{"username": "cli-dev", "ssh_keys": "testkey"}]}, @@ -391,9 +357,6 @@ def mock_input(prompt): assert conf.get_value("region") == "test-region" assert conf.get_value("authorized_users") == "cli-dev" assert conf.config.get("DEFAULT", "default-user") == "DEFAULT" - # make sure that we set the default engine value according to type of database - assert conf.get_value("mysql_engine") == "mysql/test-engine" - assert conf.get_value("postgresql_engine") == "postgresql/test-engine" def test_default_thing_input_no_current(self, monkeypatch): stdout_buf = io.StringIO()