Skip to content

Commit 23dab1e

Browse files
Merge pull request #933 from rlrossiter/edit-rule-fix
Add fix for unsetting of values in edit SG rules
2 parents cad3dd2 + 950d200 commit 23dab1e

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

SoftLayer/managers/network.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,19 @@ def edit_securitygroup_rule(self, group_id, rule_id, remote_ip=None,
320320
"""
321321
successful = False
322322
obj = {}
323-
if remote_ip:
323+
if remote_ip is not None:
324324
obj['remoteIp'] = remote_ip
325-
if remote_group:
325+
if remote_group is not None:
326326
obj['remoteGroupId'] = remote_group
327-
if direction:
327+
if direction is not None:
328328
obj['direction'] = direction
329-
if ethertype:
329+
if ethertype is not None:
330330
obj['ethertype'] = ethertype
331-
if port_max:
331+
if port_max is not None:
332332
obj['portRangeMax'] = port_max
333-
if port_min:
333+
if port_min is not None:
334334
obj['portRangeMin'] = port_min
335-
if protocol:
335+
if protocol is not None:
336336
obj['protocol'] = protocol
337337

338338
if obj:

tests/managers/network_tests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,23 @@ def test_edit_securitygroup_rule(self):
244244
args=([{'id': 500,
245245
'direction': 'ingress'}],))
246246

247+
def test_edit_securitygroup_rule_unset(self):
248+
# Test calling edit rule with falsy values, which are used
249+
# to unset those values in the API
250+
result = self.network.edit_securitygroup_rule(100, 500,
251+
protocol='',
252+
port_min=-1,
253+
port_max=-1,
254+
ethertype='',
255+
remote_ip='')
256+
257+
self.assertTrue(result)
258+
self.assert_called_with('SoftLayer_Network_SecurityGroup',
259+
'editRules', identifier=100,
260+
args=([{'id': 500, 'protocol': '',
261+
'portRangeMin': -1, 'portRangeMax': -1,
262+
'ethertype': '', 'remoteIp': ''}],))
263+
247264
def test_get_rwhois(self):
248265
result = self.network.get_rwhois()
249266

0 commit comments

Comments
 (0)