Skip to content

Commit

Permalink
Merge pull request #66 from remind101/remove_stack_caching
Browse files Browse the repository at this point in the history
Remove stack caching from provider
  • Loading branch information
phobologic committed Aug 11, 2015
2 parents bbd14ea + 7d10ee1 commit 6d33081
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion stacker/actions/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .base import BaseAction
from .. import exceptions, util
from ..providers.exceptions import StackDidNotChange
from ..exceptions import StackDidNotChange
from ..plan import COMPLETE, SKIPPED, SUBMITTED, Plan

logger = logging.getLogger(__name__)
Expand Down
8 changes: 6 additions & 2 deletions stacker/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


class StackDoesNotExist(Exception):

def __init__(self, stack_name, *args, **kwargs):
Expand Down Expand Up @@ -42,3 +40,9 @@ def __init__(self, cls, error, *args, **kwargs):
error,
)
super(ImproperlyConfigured, self).__init__(message, *args, **kwargs)


class StackDidNotChange(Exception):
"""Exception raised when there are no changes to be made by the
provider.
"""
26 changes: 11 additions & 15 deletions stacker/providers/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import boto
from boto import cloudformation

from . import exceptions
from .. import exceptions
from .base import BaseProvider
from ..util import retry_with_backoff

Expand All @@ -23,7 +23,7 @@ def get_output_dict(stack):
"""
outputs = {}
for output in stack.outputs:
logger.debug(" %s %s: %s", stack.name, output.key,
logger.debug(" %s %s: %s", stack.stack_name, output.key,
output.value)
outputs[output.key] = output.value
return outputs
Expand All @@ -47,13 +47,13 @@ def retry_on_throttling(fn, attempts=3, args=None, kwargs=None):
retry more than attempts.
"""
def _throttling_checker(exc):
if exc.status == 400 and "Throttling" in exc.message:
if exc.status == 400 and exc.error_code == "Throttling":
logger.debug("AWS throttling calls.")
return True
return False

return retry_with_backoff(fn, args=args, kwargs=kwargs, attempts=attempts,
exc_list=[boto.exception.BotoServerError],
exc_list=(boto.exception.BotoServerError, ),
retry_checker=_throttling_checker)


Expand All @@ -74,7 +74,6 @@ class Provider(BaseProvider):

def __init__(self, region, **kwargs):
self.region = region
self._stacks = {}
self._outputs = {}

@property
Expand All @@ -85,16 +84,13 @@ def cloudformation(self):
return self._cloudformation

def get_stack(self, stack_name, **kwargs):
if stack_name not in self._stacks:
try:
self._stacks[stack_name] = \
retry_on_throttling(self.cloudformation.describe_stacks,
args=[stack_name])[0]
except boto.exception.BotoServerError as e:
if 'does not exist' not in e.message:
raise
raise exceptions.StackDoesNotExist(stack_name)
return self._stacks[stack_name]
try:
return retry_on_throttling(self.cloudformation.describe_stacks,
args=[stack_name])[0]
except boto.exception.BotoServerError as e:
if 'does not exist' not in e.message:
raise
raise exceptions.StackDoesNotExist(stack_name)

def get_stack_status(self, stack, **kwargs):
return stack.stack_status
Expand Down
6 changes: 0 additions & 6 deletions stacker/providers/exceptions.py

This file was deleted.

2 changes: 1 addition & 1 deletion stacker/tests/actions/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from stacker.context import Context
from stacker import exceptions
from stacker.plan import COMPLETE, PENDING, SKIPPED, SUBMITTED
from stacker.providers.exceptions import StackDidNotChange
from stacker.exceptions import StackDidNotChange
from stacker.providers.base import BaseProvider


Expand Down
1 change: 1 addition & 0 deletions stacker/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def retry_with_backoff(function, args=None, kwargs=None, attempts=5,
exc_list = (Exception, )
while True:
attempt += 1
logger.debug("Calling %s, attempt %d.", function, attempt)
sleep_time = min(max_delay, min_delay * attempt)
try:
return function(*args, **kwargs)
Expand Down

0 comments on commit 6d33081

Please sign in to comment.