Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
get elb helpers shouldn't raise if none elbs exist. (#238)
Browse files Browse the repository at this point in the history
* get elb helpers shouldn't raise if none elbs exist.

* Remove offending test as well.
  • Loading branch information
ltsampros authored and mattpep committed Dec 16, 2016
1 parent c2cdba6 commit 07a8f3a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
10 changes: 3 additions & 7 deletions bootstrap_cfn/fab_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,22 +990,18 @@ def get_public_elbs(f=None):
"""
Returns a list of internet-facing ELBs from the CloudFormation
configuration containing items for which the filter function f
returns True, or everything. Raises an error if the list is empty.
returns True, or everything. or None if empty.
"""
elbs = get_all_elbs(f)
if len(elbs) < 1:
raise PublicELBNotFoundError
return elbs


def get_first_public_elb():
"""
Returns the first public ELB if exists, or raise an error.
Returns the first public ELB if exists or None.
"""
elbs = get_all_elbs()
if len(elbs) < 1:
raise PublicELBNotFoundError
return elbs[0]
return next(iter(elbs), None)


@task
Expand Down
11 changes: 0 additions & 11 deletions tests/test_fab_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,6 @@ def test_get_first_public_elb(self, get_all_elbs_function):
first_elb = fab_tasks.get_first_public_elb()
self.assertEqual(first_elb, "unittest_elb")

@patch('bootstrap_cfn.fab_tasks.get_all_elbs', return_value=[])
def test_no_public_elb(self, get_all_elbs_function):
'''
Check if exception is raised when no elbs found
Args:
get_all_elbs_function: mock of get_all_elbs(), a list of elbs
'''
with self.assertRaises(errors.PublicELBNotFoundError):
fab_tasks.get_first_public_elb()

@patch('bootstrap_cfn.fab_tasks.get_connection')
@patch('bootstrap_cfn.fab_tasks.get_zone_name', return_value="dsd.io")
@patch('bootstrap_cfn.fab_tasks.get_legacy_name', return_value="unittest-dev")
Expand Down

0 comments on commit 07a8f3a

Please sign in to comment.