Skip to content

Commit fd7b0cf

Browse files
committed
#1222 raise an exception if not found find a lbaas instance
1 parent c1477f8 commit fd7b0cf

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

SoftLayer/managers/load_balancer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
:license: MIT, see LICENSE for more details.
77
"""
8+
from SoftLayer import exceptions
89
from SoftLayer.managers import ordering
910
from SoftLayer import utils
1011

@@ -110,12 +111,14 @@ def get_lbaas_by_name(self, name, mask=None):
110111
111112
:param name: Name of the LBaaS instance
112113
:param mask:
113-
:returns: SoftLayer_Network_LBaaS_LoadBalancer or an empty dictionary if the name is not found.
114+
:returns: SoftLayer_Network_LBaaS_LoadBalancer.
114115
"""
115116
object_filter = {'name': {'operation': name}}
116117
this_lbs = self.lbaas.getAllObjects(filter=object_filter, mask=mask)
118+
if not this_lbs:
119+
raise exceptions.SoftLayerError("Unable to find LBaaS with name: {}".format(name))
117120

118-
return this_lbs[0] if this_lbs else {}
121+
return this_lbs[0]
119122

120123
def delete_lb_member(self, identifier, member_id):
121124
"""Removes a member from a LBaaS instance

tests/managers/loadbal_tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
them directly to the API.
99
"""
1010
import SoftLayer
11+
from SoftLayer import exceptions
1112
from SoftLayer.fixtures import SoftLayer_Network_LBaaS_LoadBalancer
1213
from SoftLayer import testing
1314

@@ -192,3 +193,9 @@ def test_get_lbaas_by_name(self):
192193
load_bal = self.lb_mgr.get_lbaas_by_name(name)
193194
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getAllObjects')
194195
self.assertIsNotNone(load_bal)
196+
197+
def test_get_lbaas_by_name_fails(self):
198+
load_bal_mock = self.set_mock('SoftLayer_Network_LBaaS_LoadBalancer', 'getAllObjects')
199+
load_bal_mock.return_value = []
200+
name = 'test'
201+
self.assertRaises(exceptions.SoftLayerError, self.lb_mgr.get_lbaas_by_name, name)

0 commit comments

Comments
 (0)