Skip to content

Commit

Permalink
Add Python 3.12 and remove Python 3.6 usage. (#258)
Browse files Browse the repository at this point in the history
* Add Python 3.12 and remove Python 3.6 usage.

* Update test_layers test case.

* Update CircleCI config.

* Remove now unused test logic

* Correct install status for unsupported runtimes

* Upgrade infra to 3.12

* Fix check for install failure case

* Update version for release

---------

Co-authored-by: Tim Pansino <[email protected]>
  • Loading branch information
umaannamalai and TimPansino authored Jan 18, 2024
1 parent 41ad0ed commit 7881047
Show file tree
Hide file tree
Showing 11 changed files with 667 additions and 664 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ orbs:
jobs:
test:
docker:
- image: cimg/python:3.11
- image: cimg/python:3.12
steps:
- checkout
- run:
Expand All @@ -19,7 +19,7 @@ jobs:

code-style:
docker:
- image: cimg/python:3.11
- image: cimg/python:3.12
steps:
- checkout
- run:
Expand All @@ -38,7 +38,7 @@ jobs:
release:
docker:
- image: cimg/python:3.11
- image: cimg/python:3.12
steps:
- checkout
- run:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-slim
FROM python:3.12-slim
RUN useradd -r -u 1000 newrelic-lambda-cli
USER newrelic-lambda-cli
WORKDIR /home/newrelic-lambda-cli
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ requests_toolbelt = "*"
moto = {extras = ["all"], version = "*"}

[requires]
python_version = "3.11"
python_version = "3.12"
1,253 changes: 636 additions & 617 deletions Pipfile.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ A CLI to install the New Relic AWS Lambda integration and layers.
* python3.9
* python3.10
* python3.11
* python3.12

**Note:** Automatic handler wrapping is only supported for Node.js, Python and Java. For other runtimes,
manual function wrapping is required using the runtime specific New Relic agent.

## Requirements

* Python >= 3.3 <= 3.11
* Python >= 3.3 <= 3.12
* Retrieve your [New relic Account ID](https://docs.newrelic.com/docs/accounts/install-new-relic/account-setup/account-id) and [User API Key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#user-api-key)

## Recommendations
Expand Down
2 changes: 1 addition & 1 deletion newrelic_lambda_cli/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _add_new_relic(input, config, nr_license_key):
"Unsupported Lambda runtime for '%s': %s"
% (config["Configuration"]["FunctionArn"], runtime)
)
return True
return False

architectures = config["Configuration"].get("Architectures", ["x86_64"])
architecture = architectures[0]
Expand Down
8 changes: 4 additions & 4 deletions newrelic_lambda_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
},
"provided": {"LambdaExtension": True},
"provided.al2": {"LambdaExtension": True},
"python3.6": {
"Handler": "newrelic_lambda_wrapper.handler",
"LambdaExtension": False,
},
"python3.7": {
"Handler": "newrelic_lambda_wrapper.handler",
"LambdaExtension": True,
Expand All @@ -60,6 +56,10 @@
"Handler": "newrelic_lambda_wrapper.handler",
"LambdaExtension": True,
},
"python3.12": {
"Handler": "newrelic_lambda_wrapper.handler",
"LambdaExtension": True,
},
}


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="newrelic-lambda-cli",
version="0.7.6",
version="0.8.0",
python_requires=">=3.3",
description="A CLI to install the New Relic AWS Lambda integration and layers.",
long_description=README,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def test_remove_integration_role(aws_credentials):
def test_install_log_ingestion(aws_credentials, mock_function_config):
mock_session = MagicMock()
mock_client = mock_session.client.return_value
mock_client.get_function.return_value = mock_function_config("python3.6")
mock_client.get_function.return_value = mock_function_config("python3.7")

assert (
install_log_ingestion(
Expand Down Expand Up @@ -451,7 +451,7 @@ def test_update_log_ingestion(aws_credentials, mock_function_config):
)

mock_client.get_function.reset_mock(return_value=True)
mock_client.get_function.return_value = mock_function_config("python3.6")
mock_client.get_function.return_value = mock_function_config("python3.7")
mock_client.describe_stacks.return_value = {"Stacks": [{"StackStatus": None}]}

assert (
Expand Down
48 changes: 15 additions & 33 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
def test_add_new_relic(aws_credentials, mock_function_config):
session = boto3.Session(region_name="us-east-1")

config = mock_function_config("python3.11")
config = mock_function_config("python3.12")

assert config["Configuration"]["Handler"] == "original_handler"

Expand Down Expand Up @@ -71,10 +71,10 @@ def test_add_new_relic(aws_credentials, mock_function_config):
config,
nr_license_key=None,
)
is True
is False
)

config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
config["Configuration"]["Layers"] = [{"Arn": get_arn_prefix("us-east-1")}]
assert (
_add_new_relic(
Expand All @@ -93,7 +93,7 @@ def test_add_new_relic(aws_credentials, mock_function_config):

with patch("newrelic_lambda_cli.layers.index") as mock_index:
mock_index.return_value = []
config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
assert (
_add_new_relic(
layer_install(
Expand Down Expand Up @@ -190,15 +190,15 @@ def test_add_new_relic(aws_credentials, mock_function_config):
) as mock_isatty:
mock_isatty.return_value = True
mock_prompt.return_value = 0
result = layer_selection(mock_layers, "python3.11", "x86_64")
result = layer_selection(mock_layers, "python3.12", "x86_64")
assert result == "arn:aws:lambda:us-east-1:123456789:layer/javajava"

with patch("sys.stdout.isatty") as mock_isatty:
mock_isatty.return_value = False
with pytest.raises(UsageError):
layer_selection(mock_layers, "python3.11", "x86_64")
layer_selection(mock_layers, "python3.12", "x86_64")

config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
_add_new_relic(
layer_install(
session=session,
Expand All @@ -216,7 +216,7 @@ def test_add_new_relic(aws_credentials, mock_function_config):
in config["Configuration"]["Environment"]["Variables"]
)

config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
config["Configuration"]["Environment"]["Variables"]["NEW_RELIC_FOO"] = "bar"
config["Configuration"]["Layers"] = [{"Arn": get_arn_prefix("us-east-1")}]
update_kwargs = _add_new_relic(
Expand All @@ -234,30 +234,12 @@ def test_add_new_relic(aws_credentials, mock_function_config):
assert "NEW_RELIC_FOO" in update_kwargs["Environment"]["Variables"]
assert update_kwargs["Layers"][0] != get_arn_prefix("us-east-1")

config = mock_function_config("python3.6")
update_kwargs = _add_new_relic(
layer_install(
session=session,
aws_region="us-east-1",
nr_account_id=12345,
enable_extension=True,
enable_extension_function_logs=True,
upgrade=True,
),
config,
"foobarbaz",
)
assert (
update_kwargs["Environment"]["Variables"]["NEW_RELIC_LAMBDA_EXTENSION_ENABLED"]
== "false"
)


@mock_lambda
def test_remove_new_relic(aws_credentials, mock_function_config):
session = boto3.Session(region_name="us-east-1")

config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
config["Configuration"]["Handler"] = "newrelic_lambda_wrapper.handler"
config["Configuration"]["Environment"]["Variables"][
"NEW_RELIC_LAMBDA_HANDLER"
Expand All @@ -281,7 +263,7 @@ def test_remove_new_relic(aws_credentials, mock_function_config):
is True
)

config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
config["Configuration"]["Handler"] = "what is this?"
assert (
_remove_new_relic(
Expand Down Expand Up @@ -352,7 +334,7 @@ def test_install_failure(aws_credentials, mock_function_config):
"newrelic_lambda_cli.layers._get_license_key_outputs"
) as mock_get_license_key_outputs:
mock_get_license_key_outputs.return_value = ("license_arn", "12345", "policy")
config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
mock_client.get_function.return_value = config
with pytest.raises(UsageError):
install(
Expand All @@ -370,7 +352,7 @@ def test_install(aws_credentials, mock_function_config):
mock_client = mock_session.client.return_value
mock_client.get_function.reset_mock(return_value=True)
mock_get_license_key_outputs.return_value = ("license_arn", "12345", "policy")
config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
mock_client.get_function.return_value = config
with pytest.raises(UsageError):
install(
Expand All @@ -393,11 +375,11 @@ def test_install(aws_credentials, mock_function_config):
install(
layer_install(nr_account_id=12345, session=mock_session), "foobarbaz"
)
is True
is False
)

mock_client.get_function.reset_mock(return_value=True)
config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
mock_client.get_function.return_value = config
assert (
install(
Expand Down Expand Up @@ -443,7 +425,7 @@ def test_uninstall(aws_credentials, mock_function_config):
assert uninstall(layer_uninstall(session=mock_session), "foobarbaz") is True

mock_client.get_function.reset_mock(return_value=True)
config = mock_function_config("python3.11")
config = mock_function_config("python3.12")
mock_client.get_function.return_value = config
assert uninstall(layer_uninstall(session=mock_session), "foobarbaz") is False

Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def test_supports_lambda_extension():
"python3.9",
"python3.10",
"python3.11",
"python3.12",
)
)
assert not any(
Expand Down

0 comments on commit 7881047

Please sign in to comment.