Skip to content

Commit

Permalink
Merge pull request #1493 from awslabs/develop
Browse files Browse the repository at this point in the history
chore: v0.30.0
  • Loading branch information
awood45 committed Oct 30, 2019
2 parents 5caeb32 + e30ce9f commit 380183e
Show file tree
Hide file tree
Showing 185 changed files with 1,574 additions and 768 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -18,7 +18,7 @@ integ-test:
func-test:
# Verify function test coverage only for `samcli.local` package
@echo Telemetry Status: $(SAM_CLI_TELEMETRY)
pytest --cov samcli.local --cov samcli.commands.local --cov-report term-missing tests/functional
pytest --cov samcli.local --cov samcli.commands.local --cov-report term-missing tests/functional/commands/validate tests/functional/commands/cli/test_global_config.py

smoke-test:
# Smoke tests run in parallel
Expand Down
5 changes: 5 additions & 0 deletions appveyor-windows.yml
Expand Up @@ -25,6 +25,7 @@ environment:
HOME: 'C:\Users\appveyor'
HOMEDRIVE: 'C:'
HOMEPATH: 'C:\Users\appveyor'
NOSE_PARAMETERIZED_NO_WARN: 1

init:
# Uncomment this for RDP
Expand Down Expand Up @@ -59,11 +60,15 @@ install:
# Switch to Docker Linux containers
- ps: Switch-DockerLinux

# Check for git executable
- "git --version"

# Echo final Path
- "echo %PATH%"

test_script:
# Reactivate virtualenv before running tests
- "git --version"
- "venv\\Scripts\\activate"
- "docker system prune -a -f"
- "pytest -vv tests/integration"
Expand Down
12 changes: 12 additions & 0 deletions appveyor.yml
Expand Up @@ -12,11 +12,13 @@ environment:
- PYTHON_HOME: "C:\\Python36-x64"
PYTHON_VERSION: '3.6.8'
PYTHON_ARCH: '64'
NOSE_PARAMETERIZED_NO_WARN: 1

- PYTHON_HOME: "C:\\Python37-x64"
PYTHON_VERSION: '3.7.4'
PYTHON_ARCH: '64'
RUN_SMOKE: 1
NOSE_PARAMETERIZED_NO_WARN: 1

for:
-
Expand All @@ -30,12 +32,16 @@ for:
- "echo %PATH%"
- "python --version"
# Upgrade setuptools, wheel and virtualenv
- "SET PATH=%PYTHON_HOME%;%PATH%"
- "echo %PYTHON_HOME%"
- "echo %PATH%"
- "python -m pip install --upgrade setuptools wheel virtualenv"

# Create new virtual environment and activate it
- "rm -rf venv"
- "python -m virtualenv venv"
- "venv\\Scripts\\activate"
- "python --version"

build_script:
# Activate virtualenv again on windows
Expand All @@ -48,6 +54,9 @@ for:
- "venv\\Scripts\\activate"
- "pytest --cov samcli --cov-report term-missing --cov-fail-under 95 tests/unit"
- "pylint --rcfile .pylintrc samcli"
# There are some functional tests that are currently broken due to not being updated with changed code or still running with node4.3 runtimes
# We need to update those but this allows us to at least runs the ones we currently have working
- "pytest tests/functional/commands/validate tests/functional/commands/cli/test_global_config.py"

# Runs only in Linux
- sh: "pytest -vv tests/integration"
Expand Down Expand Up @@ -88,6 +97,9 @@ for:
test_script:
- "pytest --cov samcli --cov-report term-missing --cov-fail-under 95 tests/unit"
- "pylint --rcfile .pylintrc samcli"
# There are some functional tests that are currently broken due to not being updated with changed code or still running with node4.3 runtimes
# We need to update those but this allows us to at least runs the ones we currently have working
- "pytest tests/functional/commands/validate tests/functional/commands/cli/test_global_config.py"

# Runs only in Linux
- sh: "pytest -vv tests/integration"
Expand Down
121 changes: 121 additions & 0 deletions designs/debug_mode_multiple_exposed_ports.md
@@ -0,0 +1,121 @@
Title: Template for design documents
====================================

What is the problem?
--------------------
Currently, there is one port is exposed from Docker instance when running lambda in debug mode.
This port is used to connect a debugger. In my case, I need two ports to be exposed due to Debugger
implementation specific (the Debugger connect to two sockets to collect different information).

What will be changed?
---------------------
SAM CLI has a ``--debug-port`` parameter that provide a port. This parameter is stored in DebugContext object.
``DebugContext`` should store an array of ports instead of a single port. This array should be transformed
into a map containing each stored port when passing to docker container arguments.

Success criteria for the change
-------------------------------
All ports specified via single or multiple ``--debug-port`` SAM CLI options should be exposed by docker container.

Out-of-Scope
------------

User Experience Walkthrough
---------------------------
From the user perspective, it should only provide an ability to specify multiple ``--debug-port`` options:
``--debug-port 5600 --debug-port 5601``

Implementation
==============

CLI Changes
-----------

SAM CLI provide an option to specify multiple ports ``--debug-port 5600 --debug-port 5601``.

### Breaking Change

No changes.

Design
------

Update ``--debug-port`` option to allow to use it multiple times in SAM CLI.
The option type should take only integer values. The value is stored in ``DebugContext``.
This value should be converted into a map of ``{ container_port : host_port }``
that is passed to ``ports`` argument when creating a docker container.

`.samrc` Changes
----------------

No changes.

Security
--------

No changes.

**What new dependencies (libraries/cli) does this change require?**

**What other Docker container images are you using?**

**Are you creating a new HTTP endpoint? If so explain how it will be
created & used**

**Are you connecting to a remote API? If so explain how is this
connection secured**

**Are you reading/writing to a temporary folder? If so, what is this
used for and when do you clean up?**

**How do you validate new .samrc configuration?**

What is your Testing Plan (QA)?
===============================

Goal
----
Make sure SAM CLI users can specify multiple ports and those ports are exposed
after creating a docker container in debug mode:

``sam local invoke --template <path_to_template>/template.yaml --event <path_to_event>/event.json --debugger-path <path_to_debugger> --debug-port 5600 --debug-port 5601``

Pre-requesites
--------------
Running SAM CLI with debug mode.

Test Scenarios/Cases
--------------------
1. Single port is specified: ``--debug-port 5600``
2. Multiple ports are specified: ``--debug-port 5600 --debug-port 5601``
3. No ports specified: ``--debug-port ``
4. No ``--debug-port`` parameter is specified

Expected Results
----------------
1. Single port is exposed in docker container
2. All specified ports are exposed in docker container
3. No ports exposed.
4. No ports exposed.

Pass/Fail
---------

Documentation Changes
=====================

Open Issues
============
- [1463](https://github.com/awslabs/aws-sam-cli/issues/1463)

Task Breakdown
==============

- \[x\] Send a Pull Request with this design document
- \[ \] Build the command line interface
- \[ \] Build the underlying library
- \[x\] Unit tests
- \[x\] Functional Tests
- \[x\] Integration tests
- \[ \] Run all tests on Windows
- \[x\] Update documentation
3 changes: 2 additions & 1 deletion pyproject.toml
Expand Up @@ -4,7 +4,7 @@ requires = ["setuptools", "wheel"] # PEP 508 specifications.

[tool.black]
line-length = 120
target_version = ['py37', 'py27', 'py36']
target_version = ['py37', 'py36']
exclude = '''
(
Expand All @@ -17,6 +17,7 @@ exclude = '''
| dist
| pip-wheel-metadata
| samcli/local/init/templates
| tests/integration/testdata
)/
)
'''
4 changes: 2 additions & 2 deletions pytest.ini
@@ -1,5 +1,5 @@
[pytest]
env =
AWS_DEFAULT_REGION = ap-southeast-1
filterwarnings =
error
#filterwarnings =
# error
3 changes: 0 additions & 3 deletions requirements/base.txt
@@ -1,7 +1,5 @@
six~=1.11.0
chevron~=0.12
click~=7.0
enum34~=1.1.6; python_version<"3.4"
Flask~=1.0.2
boto3~=1.9, >=1.9.56
PyYAML~=5.1
Expand All @@ -10,7 +8,6 @@ aws-sam-translator==1.15.1
docker~=4.0
dateparser~=0.7
python-dateutil~=2.6
pathlib2~=2.3.2; python_version<"3.4"
requests==2.22.0
serverlessrepo==0.1.9
aws_lambda_builders==0.5.0
25 changes: 8 additions & 17 deletions requirements/dev.txt
@@ -1,20 +1,11 @@
coverage==4.3.4
pytest-cov==2.4.0
# astroid > 2.0.4 is not compatible with pylint1.7
astroid>=1.5.8,<2.1.0
pylint==1.7.2
coverage==4.5.4
pytest-cov==2.7.1
pylint==2.3.1

# Test requirements
pytest==3.6.0
py==1.5.1
pluggy==0.6.0
mock==2.0.0
parameterized==0.6.1
pathlib2==2.3.2; python_version<"3.4"
futures==3.2.0; python_version<"3.2.3"
# Py3.2 backport
backports.tempfile==1.0
pytest-xdist==1.20.0
pytest-forked==1.0.2
pytest==5.2.1
parameterized==0.7.0
pytest-xdist==1.30.0
pytest-forked==1.1.3
pytest-timeout==1.3.3
pytest-rerunfailures==5.0
pytest-rerunfailures==7.0
2 changes: 1 addition & 1 deletion samcli/__init__.py
Expand Up @@ -2,4 +2,4 @@
SAM CLI version
"""

__version__ = "0.23.0"
__version__ = "0.30.0"
19 changes: 4 additions & 15 deletions samcli/cli/command.py
Expand Up @@ -4,7 +4,6 @@

import logging
import importlib
import sys
from collections import OrderedDict

import click
Expand All @@ -24,13 +23,6 @@
"samcli.commands.publish",
]

DEPRECATION_NOTICE = (
"Deprecated : AWS SAM CLI no longer supports "
"installations on Python 2.7. "
"Install AWS SAM CLI via https://docs.aws.amazon.com/serverless-application-model/"
"latest/developerguide/serverless-sam-cli-install.html for continued support with new versions. \n"
)


class BaseCommand(click.MultiCommand):
"""
Expand All @@ -53,7 +45,7 @@ class BaseCommand(click.MultiCommand):
will produce a command name "baz".
"""

def __init__(self, cmd_packages=None, *args, **kwargs):
def __init__(self, *args, cmd_packages=None, **kwargs):
"""
Initializes the class, optionally with a list of available commands
Expand All @@ -69,9 +61,6 @@ def __init__(self, cmd_packages=None, *args, **kwargs):
self._commands = {}
self._commands = BaseCommand._set_commands(cmd_packages)

if sys.version_info.major == 2:
click.secho(DEPRECATION_NOTICE, fg="red", err=True)

@staticmethod
def _set_commands(package_names):
"""
Expand Down Expand Up @@ -109,18 +98,18 @@ def get_command(self, ctx, cmd_name):
"""
if cmd_name not in self._commands:
logger.error("Command %s not available", cmd_name)
return
return None

pkg_name = self._commands[cmd_name]

try:
mod = importlib.import_module(pkg_name)
except ImportError:
logger.exception("Command '%s' is not configured correctly. Unable to import '%s'", cmd_name, pkg_name)
return
return None

if not hasattr(mod, "cli"):
logger.error("Command %s is not configured correctly. It must expose an function called 'cli'", cmd_name)
return
return None

return mod.cli
6 changes: 5 additions & 1 deletion samcli/cli/context.py
Expand Up @@ -8,7 +8,7 @@
import click


class Context(object):
class Context:
"""
Top level context object for the CLI. Exposes common functionality required by a CLI, including logging,
environment config parsing, debug logging etc.
Expand Down Expand Up @@ -98,6 +98,8 @@ def command_path(self):
if click_core_ctx:
return click_core_ctx.command_path

return None

@staticmethod
def get_current_context():
"""
Expand Down Expand Up @@ -129,6 +131,8 @@ def my_command_handler(ctx):
if click_core_ctx:
return click_core_ctx.find_object(Context) or click_core_ctx.ensure_object(Context)

return None

def _refresh_session(self):
"""
Update boto3's default session by creating a new session based on values set in the context. Some properties of
Expand Down
7 changes: 2 additions & 5 deletions samcli/cli/global_config.py
Expand Up @@ -6,13 +6,10 @@
import logging
import uuid
import os
from pathlib import Path

import click

try:
from pathlib import Path
except ImportError: # pragma: no cover
from pathlib2 import Path # pragma: no cover

LOG = logging.getLogger(__name__)

Expand All @@ -21,7 +18,7 @@
TELEMETRY_ENABLED_KEY = "telemetryEnabled"


class GlobalConfig(object):
class GlobalConfig:
"""
Contains helper methods for global configuration files and values. Handles
configuration file creation, updates, and fetching in a platform-neutral way.
Expand Down

0 comments on commit 380183e

Please sign in to comment.