Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions SoftLayer/CLI/loadbal/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.exceptions import SoftLayerAPIError
from SoftLayer import utils


Expand Down Expand Up @@ -55,9 +56,9 @@ def cli(env, identifier, uuid, interval, retry, timeout, url):
for key in clean_template.keys():
check[key] = clean_template[key]

result = mgr.update_lb_health_monitors(lb_uuid, [check])

if result:
try:
mgr.update_lb_health_monitors(lb_uuid, [check])
click.secho('Health Check {} updated successfully'.format(uuid), fg='green')
else:
click.secho('ERROR: Failed to update {}'.format(uuid), fg='red')
except SoftLayerAPIError as exception:
click.secho('Failed to update {}'.format(uuid), fg='red')
click.secho("ERROR: {}".format(exception.faultString), fg='red')
138 changes: 115 additions & 23 deletions SoftLayer/fixtures/SoftLayer_Network_LBaaS_LoadBalancer.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,121 @@
getObject = {
'accountId': 1234,
'address': '01-307608-ams01.clb.appdomain.cloud',
'createDate': '2019-08-12T07:49:43-06:00',
'id': 1111111,
'isPublic': 0,
'locationId': 265592,
'modifyDate': '2019-08-13T16:26:06-06:00',
'name': 'dcabero-01',
'operatingStatus': 'ONLINE',
'provisioningStatus': 'ACTIVE',
'type': 0,
'useSystemPublicIpPool': 1,
'uuid': '1a1aa111-4474-4e16-9f02-4de959229b85',
'listenerCount': 4,
'memberCount': 1,
'datacenter': {
'id': 265592,
'longName': 'Amsterdam 1',
'name': 'ams01',
'statusId': 2
'accountId': 1234,
'address': '01-307608-ams01.clb.appdomain.cloud',
'createDate': '2019-08-12T07:49:43-06:00',
'id': 1111111,
'isPublic': 0,
'locationId': 265592,
'modifyDate': '2019-08-13T16:26:06-06:00',
'name': 'dcabero-01',
'operatingStatus': 'ONLINE',
'provisioningStatus': 'ACTIVE',
'type': 0,
'useSystemPublicIpPool': 1,
'uuid': '1a1aa111-4474-4e16-9f02-4de959229b85',
'listenerCount': 4,
'memberCount': 1,
'previousErrorText': 'test',
'datacenter': {
'id': 265592,
'longName': 'Amsterdam 1',
'name': 'ams01',
'statusId': 2
},
'healthMonitors': [
{
'createDate': '2019-08-20T18:05:09-04:00',
'interval': 5,
'maxRetries': 2,
'modifyDate': '2019-08-20T18:05:18-04:00',
'monitorType': 'HTTP',
'provisioningStatus': 'ACTIVE',
'timeout': 2,
'urlPath': '/',
'uuid': 'c11111c1-f5ab-4c15-ba96-d7b95dc7c824'
}
}
],
'l7Pools': [
{
'createDate': '2019-08-19T16:33:37-04:00',
'id': 222222,
'loadBalancingAlgorithm': 'ROUNDROBIN',
'modifyDate': None,
'name': 'test',
'protocol': 'HTTP',
'provisioningStatus': 'ACTIVE',
'uuid': 'a1111111-c5e7-413f-9f78-84f6c5e1ca04'
}
],
'listeners': [
{
'defaultPool': {
'healthMonitor': {
'uuid': '222222ab-bbcc-4f32-9b31-1b6d3a1959c8'
},
'protocol': 'HTTP',
'protocolPort': 256,
'uuid': 'ab1a1abc-0e83-4690-b5d4-1359625dba8f',
}
},
{'connectionLimit': None,
'createDate': '2019-08-21T17:19:25-04:00',
'defaultPool': {'createDate': '2019-08-21T17:19:25-04:00',
'healthMonitor': {'createDate': '2019-08-21T17:17:04-04:00',
'id': 859330,
'interval': 5,
'maxRetries': 2,
'modifyDate': '2019-08-21T17:17:15-04:00',
'monitorType': 'HTTP',
'provisioningStatus': 'ACTIVE',
'timeout': 2,
'urlPath': '/',
'uuid': '55e00152-75fd-4f94-9263-cb4c6e005f12'},
'loadBalancingAlgorithm': 'ROUNDROBIN',
'members': [{'address': '10.136.4.220',
'createDate': '2019-08-12T09:49:43-04:00',
'id': 1023118,
'modifyDate': '2019-08-12T09:52:54-04:00',
'provisioningStatus': 'ACTIVE',
'uuid': 'ba23a166-faa4-4eb2-96e7-ef049d65ce60',
'weight': 50}],
'modifyDate': '2019-08-21T17:19:33-04:00',
'protocol': 'HTTP',
'protocolPort': 230,
'provisioningStatus': 'ACTIVE',
'uuid': '1c5f3ba6-ec7d-4cf8-8815-9bb174224a76'},
'id': 889072,
'l7Policies': [{'action': 'REJECT',
'createDate': '2019-08-21T18:17:41-04:00',
'id': 215204,
'modifyDate': None,
'name': 'trestst',
'priority': 1,
'redirectL7PoolId': None,
'uuid': 'b8c30aae-3979-49a7-be8c-fb70e43a6b4b'}],
'modifyDate': '2019-08-22T10:58:02-04:00',
'protocol': 'HTTP',
'protocolPort': 110,
'provisioningStatus': 'ACTIVE',
'tlsCertificateId': None,
'uuid': 'a509723d-a3cb-4ae4-bc5b-5ecf04f890ff'}
],
'members': [
{
'address': '10.0.0.1',
'createDate': '2019-08-12T09:49:43-04:00',
'modifyDate': '2019-08-12T09:52:54-04:00',
'provisioningStatus': 'ACTIVE',
'uuid': 'ba23a166-faa4-4eb2-96e7-ef049d65ce60',
'weight': 50
}
],
'sslCiphers': [
{
'id': 2, 'name': 'ECDHE-RSA-AES256-GCM-SHA384'
}
],
}
getAllObjects = [getObject]


getLoadBalancerMemberHealth = [
{
'poolUuid': '1c5f3ba6-ec7d-4cf8-8815-9bb174224a76',
Expand Down
109 changes: 109 additions & 0 deletions tests/CLI/modules/loadbal_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"""
SoftLayer.tests.CLI.modules.loadbal
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
"""

import mock

from SoftLayer.CLI.exceptions import ArgumentError
from SoftLayer import exceptions
from SoftLayer.fixtures import SoftLayer_Network_LBaaS_LoadBalancer
from SoftLayer import testing


class LoadBalTests(testing.TestCase):

@mock.patch('SoftLayer.CLI.loadbal.members.click')
def test_lb_member_add_private(self, click):
lbaas_id = '1111111'
member_ip_address = '10.0.0.1'
result = self.run_command(['loadbal', 'member-add', '--private', '-m', member_ip_address, lbaas_id])
output = 'Member {} added'.format(member_ip_address)
self.assert_no_fail(result)
click.secho.assert_called_with(output, fg='green')

@mock.patch('SoftLayer.CLI.loadbal.members.click')
def test_lb_member_add_public(self, click):
lbaas_id = '1111111'
member_ip_address = '10.0.0.1'
result = self.run_command(['loadbal', 'member-add', '--public', '-m', member_ip_address, lbaas_id])
output = 'Member {} added'.format(member_ip_address)
self.assert_no_fail(result)
click.secho.assert_called_with(output, fg='green')

@mock.patch('SoftLayer.LoadBalancerManager.add_lb_member')
def test_lb_member_add_public_fails(self, add_lb_member):
lbaas_id = '1111111'
member_ip_address = '10.0.0.1'
fault_string = 'publicIpAddress must be a string'
add_lb_member.side_effect = exceptions.SoftLayerAPIError(mock.ANY, fault_string)
result = self.run_command(['loadbal', 'member-add', '--public', '-m', member_ip_address, lbaas_id])
self.assertIn('This LB requires a Public IP address for its members and none was supplied',
result.output)
self.assertIn("ERROR: {}".format(fault_string),
result.output)

@mock.patch('SoftLayer.LoadBalancerManager.add_lb_member')
def test_lb_member_add_private_fails(self, add_lb_member):
lbaas_id = '1111111'
member_ip_address = '10.0.0.1'
fault_string = 'privateIpAddress must be a string'
add_lb_member.side_effect = exceptions.SoftLayerAPIError(mock.ANY, fault_string)
result = self.run_command(['loadbal', 'member-add', '--private', '-m', member_ip_address, lbaas_id])
self.assertIn('This LB requires a Private IP address for its members and none was supplied',
result.output)
self.assertIn("ERROR: {}".format(fault_string),
result.output)

@mock.patch('SoftLayer.managers.load_balancer.LoadBalancerManager.delete_lb_member')
def test_lb_member_del_fails(self, delete):
lbaas_id = '1111111'
lbaas_member_uuid = "x123x123-123x-123x-123x-123a123b123c"
delete.side_effect = exceptions.SoftLayerAPIError(mock.ANY, mock.ANY)
result = self.run_command(['loadbal', 'member-del', '-m', lbaas_member_uuid, lbaas_id])
self.assertIn("ERROR:", result.output)

@mock.patch('SoftLayer.CLI.loadbal.members.click')
def test_lb_member_del(self, click):
lbaas_id = '1111111'
lbaas_member_uuid = "x123x123-123x-123x-123x-123a123b123c"
result = self.run_command(['loadbal', 'member-del', '-m', lbaas_member_uuid, lbaas_id])
output = 'Member {} removed'.format(lbaas_member_uuid)
self.assert_no_fail(result)
click.secho.assert_called_with(output, fg='green')

@mock.patch('SoftLayer.CLI.loadbal.health.click')
def test_lb_health_manage(self, click):
lb_id = '1111111'
lb_check_uuid = '222222ab-bbcc-4f32-9b31-1b6d3a1959c8'
result = self.run_command(['loadbal', 'health', lb_id, '--uuid', lb_check_uuid,
'-i', '60', '-r', '10', '-t', '10', '-u', '/'])
self.assert_no_fail(result)
output = 'Health Check {} updated successfully'.format(lb_check_uuid)
click.secho.assert_called_with(output, fg='green')

def test_lb_health_manage_args_time_fails(self):
result = self.run_command(['lb', 'health', '1111111', '--uuid', '222222ab-bbcc-4f32-9b31-1b6d3a1959c8'])
self.assertIsInstance(result.exception, ArgumentError)

@mock.patch('SoftLayer.LoadBalancerManager.get_lb')
def test_lb_health_update_tcp_url_fails(self, get_lb):
get_lb.return_value = SoftLayer_Network_LBaaS_LoadBalancer.getObject
get_lb.return_value['listeners'][0]['defaultPool']['protocol'] = 'TCP'

result = self.run_command(['lb', 'health', '1111111', '--uuid', '222222ab-bbcc-4f32-9b31-1b6d3a1959c8',
'-i', '60', '-r', '10', '-t', '10', '-u', '/'])
self.assertIsInstance(result.exception, ArgumentError)

@mock.patch('SoftLayer.LoadBalancerManager.update_lb_health_monitors')
def test_lb_health_update_fails(self, update_lb_health_monitors):
update_lb_health_monitors.side_effect = exceptions.SoftLayerAPIError(mock.ANY, mock.ANY)

result = self.run_command(['lb', 'health', '1111111', '--uuid', '222222ab-bbcc-4f32-9b31-1b6d3a1959c8',
'-i', '60', '-r', '10', '-t', '10', '-u', '/'])
self.assertIn("ERROR:", result.output)

def test_lb_detail(self):
result = self.run_command(['lb', 'detail', '1111111'])
self.assert_no_fail(result)