Skip to content

Commit

Permalink
[cli] migrate versioning into manage_lambda, support version publish …
Browse files Browse the repository at this point in the history
…by cluster
  • Loading branch information
Jack Naglieri committed Dec 12, 2017
1 parent 3a4b2f9 commit 7c97721
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
15 changes: 9 additions & 6 deletions stream_alert_cli/manage_lambda/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@

from stream_alert_cli import helpers
from stream_alert_cli.manage_lambda import package as stream_alert_packages
from stream_alert_cli.manage_lambda.version import LambdaVersion
from stream_alert_cli.terraform.generate import terraform_generate
from stream_alert_cli.version import LambdaVersion


PackageMap = namedtuple('package_attrs', ['package_class', 'targets', 'enabled'])


def _publish_version(packages, config):
def _publish_version(packages, config, clusters):
"""Publish production Lambda versions
Args:
packages (list of LambdaPackage classes)
packages (list[LambdaPackage])
config (CLIConfig)
clusters (set)
Returns:
bool: Result of Lambda version publishing
Expand All @@ -39,10 +41,11 @@ def _publish_version(packages, config):
for package in packages:
if package.package_name in global_packages:
published = LambdaVersion(
config=config, package=package, clustered_deploy=False).publish_function()
config=config, package=package).publish_function(clustered_deploy=False)
else:
published = LambdaVersion(
config=config, package=package).publish_function()
config=config, package=package).publish_function(clustered_deploy=True,
clusters=clusters)
if not published:
return False

Expand Down Expand Up @@ -135,7 +138,7 @@ def deploy(options, config):
sys.exit(1)

# Publish a new production Lambda version
if not _publish_version(packages, config):
if not _publish_version(packages, config, options.clusters):
return

# Regenerate the Terraform configuration with the new Lambda versions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ def __init__(self, **kwargs):
Keyword Args:
config (CLIConfig): Loaded StreamAlert CLI Config
package (LambdaPackage): The created Lambda Package
clustered_deploy (bool): Identifies cluster based Lambdas
"""
self.config = kwargs['config']
self.package = kwargs['package']
self.clustered_deploy = kwargs.get('clustered_deploy', True)

@staticmethod
def _version_helper(**kwargs):
Expand Down Expand Up @@ -140,6 +138,7 @@ def _publish_helper(self, **kwargs):
LOGGER_CLI.info('Published version %s for %s',
new_version, function_name)
self.config['lambda'][self.package.config_key]['current_version'] = new_version

self.config.write()

return True
Expand All @@ -156,10 +155,18 @@ def _publish(self, client, function_name, code_sha_256):

return new_version

def publish_function(self):
"""Main Publish Function method"""
if self.clustered_deploy:
for cluster in self.config.clusters():
def publish_function(self, **kwargs):
"""Main Publish Function method
Keyword Args:
clustered_deploy (bool): Identifies cluster based Lambdas
clusters (list): The list of clusters to deploy to
"""
clustered_deploy = kwargs.get('clustered_deploy', True)
clusters = kwargs.get('clusters', []) or self.config.clusters()

if clustered_deploy:
for cluster in clusters:
if not self._publish_helper(cluster=cluster):
return False
else:
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/stream_alert_cli/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from nose.tools import assert_equal, assert_true, assert_false, nottest

from stream_alert_cli.manage_lambda.package import AthenaPackage, RuleProcessorPackage
from stream_alert_cli.version import LambdaVersion
from stream_alert_cli.manage_lambda.version import LambdaVersion
from tests.unit.helpers.aws_mocks import MockLambdaClient
from tests.unit.helpers.base import basic_streamalert_config, MockCLIConfig

Expand All @@ -37,7 +37,6 @@ def test_publish_helper_clustered():
package = RuleProcessorPackage(config=config)
publish = LambdaVersion(
config=config,
clustered_deploy=True,
package=package
)
result = publish._publish_helper(cluster='prod')
Expand All @@ -56,7 +55,6 @@ def test_publish_helper():
package = AthenaPackage(config=config)
publish = LambdaVersion(
config=config,
clustered_deploy=False,
package=package
)
result = publish._publish_helper()
Expand All @@ -70,7 +68,6 @@ def test_version_helper():
package = AthenaPackage(basic_streamalert_config())
publish = LambdaVersion(
config=basic_streamalert_config(),
clustered_deploy=False,
package=package
)
current_version = 10
Expand All @@ -85,13 +82,12 @@ def test_version_helper():
assert_equal(result, current_version + 1)


@patch('stream_alert_cli.version.LOGGER_CLI')
@patch('stream_alert_cli.manage_lambda.version.LOGGER_CLI')
def test_version_helper_error(mock_logging):
"""CLI - Publish Helper Raises Error"""
package = AthenaPackage(basic_streamalert_config())
publish = LambdaVersion(
config=basic_streamalert_config(),
clustered_deploy=False,
package=package
)
current_version = 10
Expand Down

0 comments on commit 7c97721

Please sign in to comment.