Skip to content

Commit

Permalink
Merge pull request #528 from linode/dev
Browse files Browse the repository at this point in the history
v5.44.2
  • Loading branch information
jriddle-linode authored Oct 4, 2023
2 parents 32fd489 + 8619b72 commit 506c011
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 98 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/e2e-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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$')
Expand Down
4 changes: 1 addition & 3 deletions linodecli/api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
42 changes: 1 addition & 41 deletions linodecli/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.",
Expand Down
3 changes: 1 addition & 2 deletions linodecli/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 37 additions & 0 deletions scripts/add_to_xml_test_report.py
Original file line number Diff line number Diff line change
@@ -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}')
1 change: 1 addition & 0 deletions tests/integration/events/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/image/test_plugin_image_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/tags/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from tests.integration.helpers import (
delete_target_id,
exec_failing_test_command,
exec_test_command,
)
Expand All @@ -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):
Expand Down
1 change: 0 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
image = linode/ubuntu21.10
token = notafaketoken
type = g6-nanode-1
mysql_engine = mysql/8.0.26
"""

LOADED_FILES = {}
Expand Down
21 changes: 9 additions & 12 deletions tests/unit/test_api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,37 @@ 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,
create_operation,
SimpleNamespace(
generic_arg="foo",
region=None,
engine=None,
image=None,
),
)
assert (
json.dumps(
{
"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(),
),
)
Expand All @@ -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,
}
)
Expand All @@ -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,
),
)
Expand All @@ -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,
}
)
Expand Down
37 changes: 0 additions & 37 deletions tests/unit/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"}]},
Expand All @@ -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"
Expand Down Expand Up @@ -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"}]},
Expand All @@ -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()
Expand Down

0 comments on commit 506c011

Please sign in to comment.