From 41251311be3eb6caf84630614a0b7f2d1b1d7af7 Mon Sep 17 00:00:00 2001 From: Youjung Kim <126618609+ykim-1@users.noreply.github.com> Date: Wed, 13 Sep 2023 08:24:43 -0700 Subject: [PATCH 1/4] test: add more fields to xml report for test aggregation tool (#519) --- .github/workflows/e2e-suite.yml | 14 ++++++++++++ scripts/add_to_xml_test_report.py | 37 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 scripts/add_to_xml_test_report.py diff --git a/.github/workflows/e2e-suite.yml b/.github/workflows/e2e-suite.yml index 2ac4397bd..cdfa2425b 100644 --- a/.github/workflows/e2e-suite.yml +++ b/.github/workflows/e2e-suite.yml @@ -46,6 +46,20 @@ jobs: env: LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN }} + - name: Set release version env + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Add additional information to XML report + run: | + echo $RELEASE_VERSION + echo ${{ env.RELEASE_VERSION }} + filename=$(ls | grep -E '^[0-9]{12}_cli_test_report\.xml$') + python scripts/add_to_xml_test_report.py \ + --branch_name "${{ env.RELEASE_VERSION }}" \ + --gha_run_id "$GITHUB_RUN_ID" \ + --gha_run_number "$GITHUB_RUN_NUMBER" \ + --xmlfile "${filename}" + - name: Upload test results run: | filename=$(ls | grep -E '^[0-9]{12}_cli_test_report\.xml$') diff --git a/scripts/add_to_xml_test_report.py b/scripts/add_to_xml_test_report.py new file mode 100644 index 000000000..41b4cef17 --- /dev/null +++ b/scripts/add_to_xml_test_report.py @@ -0,0 +1,37 @@ +import argparse +import xml.etree.ElementTree as ET + +# Parse command-line arguments +parser = argparse.ArgumentParser(description='Modify XML with workflow information') +parser.add_argument('--branch_name', required=True) +parser.add_argument('--gha_run_id', required=True) +parser.add_argument('--gha_run_number', required=True) +parser.add_argument('--xmlfile', required=True) # Added argument for XML file path + +args = parser.parse_args() + +# Open and parse the XML file +xml_file_path = args.xmlfile +tree = ET.parse(xml_file_path) +root = tree.getroot() + +# Create new elements for the information +branch_name_element = ET.Element('branch_name') +branch_name_element.text = args.branch_name + +gha_run_id_element = ET.Element('gha_run_id') +gha_run_id_element.text = args.gha_run_id + +gha_run_number_element = ET.Element('gha_run_number') +gha_run_number_element.text = args.gha_run_number + +# Add the new elements to the root of the XML +root.append(branch_name_element) +root.append(gha_run_id_element) +root.append(gha_run_number_element) + +# Save the modified XML +modified_xml_file_path = xml_file_path # Overwrite it +tree.write(modified_xml_file_path) + +print(f'Modified XML saved to {modified_xml_file_path}') From bcb3ba0c80f5daf093272c41ec8a848cccd3e6c5 Mon Sep 17 00:00:00 2001 From: Youjung Kim <126618609+ykim-1@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:04:12 -0700 Subject: [PATCH 2/4] test: fix/skip integration test failures (#524) --- tests/integration/events/test_events.py | 1 + tests/integration/image/test_plugin_image_upload.py | 3 +-- tests/integration/tags/test_tags.py | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/integration/events/test_events.py b/tests/integration/events/test_events.py index 152129aae..10456edb2 100644 --- a/tests/integration/events/test_events.py +++ b/tests/integration/events/test_events.py @@ -184,6 +184,7 @@ def test_filter_events_by_entity_id(): ) +@pytest.mark.skip(reason="https://github.com/linode/linode-cli/issues/500") def test_create_domain_and_filter_domain_events(events_setup): domain_id = events_setup result = exec_test_command( diff --git a/tests/integration/image/test_plugin_image_upload.py b/tests/integration/image/test_plugin_image_upload.py index 8e1ef15d9..2d9c1fa28 100644 --- a/tests/integration/image/test_plugin_image_upload.py +++ b/tests/integration/image/test_plugin_image_upload.py @@ -80,9 +80,8 @@ def test_file_upload( assert process.returncode == 0 # Assertions now using keywords due to some chars getting cut off from lack of terminal space - assert re.search("cli-test", output) + assert re.search("[0-9][0-9]+.[0-9]%", output) assert re.search("test", output) - assert re.search("pending", output) # Get the new image from the API process = exec_test_command( diff --git a/tests/integration/tags/test_tags.py b/tests/integration/tags/test_tags.py index 0b0dfe649..a316b8875 100644 --- a/tests/integration/tags/test_tags.py +++ b/tests/integration/tags/test_tags.py @@ -3,6 +3,7 @@ import pytest from tests.integration.helpers import ( + delete_target_id, exec_failing_test_command, exec_test_command, ) @@ -20,8 +21,11 @@ def test_create_tag(): exec_test_command( BASE_CMD + ["create", "--label", unique_tag, "--text", "--no-headers"] ).stdout.decode() + yield unique_tag + delete_target_id("tags", unique_tag) + @pytest.mark.smoke def test_view_unique_tag(test_create_tag): 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 3/4] 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() From 8619b7259b19381aee22d5105752fb83b42bfc44 Mon Sep 17 00:00:00 2001 From: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:15:37 -0400 Subject: [PATCH 4/4] fix: Display empty lists when using `--json` (#526) --- linodecli/output.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/linodecli/output.py b/linodecli/output.py index 379abf799..86c5d9461 100644 --- a/linodecli/output.py +++ b/linodecli/output.py @@ -372,8 +372,7 @@ def _select_json_elements(keys, json_res): results.append(selected) - if len(results) > 0: - ret[k] = results + ret[k] = results return ret