1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
"""
SoftLayer.tests.managers.loadbal_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
A lot of these tests will use junk data because the manager just passes
them directly to the API.
"""
import SoftLayer
from SoftLayer import exceptions
from SoftLayer import fixtures
from SoftLayer.fixtures import SoftLayer_Network_LBaaS_LoadBalancer
from SoftLayer import testing
class LoadBalancerTests(testing.TestCase):
def set_up(self):
self.lb_mgr = SoftLayer.LoadBalancerManager(self.client)
def test_get_adcs(self):
self.lb_mgr.get_adcs()
self.assert_called_with('SoftLayer_Account', 'getApplicationDeliveryControllers')
def test_get_adc_masks(self):
self.lb_mgr.get_adcs(mask="mask[id]")
self.assert_called_with('SoftLayer_Account', 'getApplicationDeliveryControllers', mask="mask[id]")
def test_get_adc(self):
self.lb_mgr.get_adc(1234)
self.assert_called_with('SoftLayer_Network_Application_Delivery_Controller', 'getObject', identifier=1234)
def test_get_adc_mask(self):
self.lb_mgr.get_adc(1234, mask="mask[id]")
self.assert_called_with('SoftLayer_Network_Application_Delivery_Controller', 'getObject', identifier=1234,
mask="mask[id]")
def test_get_lbaas(self):
self.lb_mgr.get_lbaas()
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getAllObjects')
def test_get_lbaas_mask(self):
self.lb_mgr.get_lbaas(mask="mask[id]")
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getAllObjects', mask="mask[id]")
def test_get_lb(self):
lb = self.lb_mgr.get_lb(1234)
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getObject', identifier=1234)
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getLoadBalancerMemberHealth',
args=(lb.get('uuid'),))
self.assertIsNotNone(lb['health'])
def test_get_lb_mask(self):
lb = self.lb_mgr.get_lb(1234, mask="mask[id]")
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getObject', identifier=1234, mask="mask[id]")
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getLoadBalancerMemberHealth',
args=(lb.get('uuid'),))
self.assertIsNotNone(lb['health'])
def test_updated_lb_health(self):
uuid = '1234'
check = {'backendPort': '80'}
self.lb_mgr.update_lb_health_monitors(uuid, check)
self.assert_called_with('SoftLayer_Network_LBaaS_HealthMonitor', 'updateLoadBalancerHealthMonitors',
args=(uuid, check))
def test_get_lbaas_uuid_id_uuid(self):
uuid = '1a1aa111-4474-4e16-9f02-4de959229b85'
my_id = 1111111
lb_uuid, lb_id = self.lb_mgr.get_lbaas_uuid_id(uuid)
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getLoadBalancer', args=(uuid,))
self.assertEqual(lb_uuid, uuid)
self.assertEqual(lb_id, my_id)
def test_get_lbaas_uuid_id_id(self):
uuid = '1a1aa111-4474-4e16-9f02-4de959229b85'
my_id = 1111111
lb_uuid, lb_id = self.lb_mgr.get_lbaas_uuid_id(my_id)
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getObject', identifier=my_id)
self.assertEqual(lb_uuid, uuid)
self.assertEqual(lb_id, my_id)
def test_get_lbaas_uuid_id_name(self):
uuid = '1a1aa111-4474-4e16-9f02-4de959229b85'
my_id = 1111111
name = 'test-01'
lb_uuid, lb_id = self.lb_mgr.get_lbaas_uuid_id(name)
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getAllObjects')
self.assertEqual(lb_uuid, uuid)
self.assertEqual(lb_id, my_id)
def test_delete_lb_member(self):
uuid = 'aa-bb-cc'
member_id = 'dd-ee-ff'
self.lb_mgr.delete_lb_member(uuid, member_id)
self.assert_called_with('SoftLayer_Network_LBaaS_Member', 'deleteLoadBalancerMembers',
args=(uuid, [member_id]))
def test_add_lb_member(self):
uuid = 'aa-bb-cc'
member = {'privateIpAddress': '1.2.3.4'}
self.lb_mgr.add_lb_member(uuid, member)
self.assert_called_with('SoftLayer_Network_LBaaS_Member', 'addLoadBalancerMembers',
args=(uuid, [member]))
def test_add_lb_listener(self):
uuid = 'aa-bb-cc'
listener = {'id': 1}
self.lb_mgr.add_lb_listener(uuid, listener)
self.assert_called_with('SoftLayer_Network_LBaaS_Listener', 'updateLoadBalancerProtocols',
args=(uuid, [listener]))
def test_get_l7policies(self):
my_id = 1111111
self.lb_mgr.get_l7policies(my_id)
self.assert_called_with('SoftLayer_Network_LBaaS_Listener', 'getL7Policies', identifier=my_id)
def test_get_all_l7policies(self):
policies = self.lb_mgr.get_all_l7policies()
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getAllObjects')
self.assertIsInstance(policies, dict)
def test_add_lb_l7_pool(self):
uuid = 'aa-bb-cc'
pool = {'id': 1}
members = {'id': 1}
health = {'id': 1}
session = {'id': 1}
self.lb_mgr.add_lb_l7_pool(uuid, pool, members, health, session)
self.assert_called_with('SoftLayer_Network_LBaaS_L7Pool', 'createL7Pool',
args=(uuid, pool, members, health, session))
def test_del_lb_l7_pool(self):
uuid = 'aa-bb-cc'
self.lb_mgr.del_lb_l7_pool(uuid)
self.assert_called_with('SoftLayer_Network_LBaaS_L7Pool', 'deleteObject', identifier=uuid)
def test_remove_lb_listener(self):
uuid = 'aa-bb-cc'
listener = 'dd-ee-ff'
self.lb_mgr.remove_lb_listener(uuid, listener)
self.assert_called_with('SoftLayer_Network_LBaaS_Listener', 'deleteLoadBalancerProtocols',
args=(uuid, [listener]))
def test_order_lbaas(self):
datacenter = {'id': 1854895}
name = 'test-lb'
desc = 'my lb'
protocols = {'frontendPort': 80, 'frontendProtocol': 'HTTP'}
subnet_id = 12345
public = True
verify = False
package = [
{
'id': 805,
'keyNake': 'LBAAS',
'itemPrices': [
{
'id': 1,
'name': 'A test price',
'locationGroupId': None
},
{
'id': 2,
'name': 'A test price 2',
'locationGroupId': 123
}
]
}
]
mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
mock.return_value = package
order_data = {
'complexType': 'SoftLayer_Container_Product_Order_Network_LoadBalancer_AsAService',
'name': name,
'description': desc,
'locationObject': {'id': 1854895},
'packageId': package[0]['id'],
'useHourlyPricing': True, # Required since LBaaS is an hourly service
'prices': [{'id': package[0]['itemPrices'][0]['id']}],
'protocolConfigurations': protocols,
'subnets': [{'id': subnet_id}],
'isPublic': public
}
self.lb_mgr.order_lbaas(datacenter, name, desc, protocols, subnet_id, public, verify)
self.assert_called_with('SoftLayer_Product_Order', 'placeOrder', args=(order_data,))
self.assert_called_with('SoftLayer_Product_Package', 'getAllObjects')
verify = True
self.lb_mgr.order_lbaas(datacenter, name, desc, protocols, subnet_id, public, verify)
self.assert_called_with('SoftLayer_Product_Order', 'verifyOrder')
def test_lbaas_order_options(self):
self.lb_mgr.lbaas_order_options()
self.assert_called_with('SoftLayer_Product_Package', 'getAllObjects')
def test_cancel_lbaas(self):
uuid = 'aa-bb-cc'
self.lb_mgr.cancel_lbaas(uuid)
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'cancelLoadBalancer', args=(uuid,))
def test_get_lbaas_by_name(self):
name = SoftLayer_Network_LBaaS_LoadBalancer.getObject.get('name')
load_bal = self.lb_mgr.get_lbaas_by_name(name)
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'getAllObjects')
self.assertIsNotNone(load_bal)
def test_get_lbaas_by_name_fails(self):
load_bal_mock = self.set_mock('SoftLayer_Network_LBaaS_LoadBalancer', 'getAllObjects')
load_bal_mock.return_value = []
name = 'test'
self.assertRaises(exceptions.SoftLayerError, self.lb_mgr.get_lbaas_by_name, name)
def test_lbaas_update_protocol(self):
uuid = '1a1aa111-4474-4e16-9f02-4de959229b85'
protocol_configurations = [
{
"backendPort": 52,
"backendProtocol": 'HTTP',
"frontendPort": 216,
"frontendProtocol": 'HTTP',
"loadBalancingMethod": 'ROUNDROBIN',
"sessionType": 'SOURCE_IP',
"maxConn": 50
}
]
result = self.lb_mgr.add_protocols(uuid, protocol_configurations)
self.assertEqual(fixtures.SoftLayer_Network_LBaaS_Listener.updateLoadBalancerProtocols, result)
def test_lbaas_delete_protocol(self):
uuid = '1a1aa111-4474-4e16-9f02-4de959229b85'
uuid_delete = 'abba-aabb-cc'
result = self.lb_mgr.delete_protocol(uuid, uuid_delete)
self.assertEqual(fixtures.SoftLayer_Network_LBaaS_Listener.deleteLoadBalancerProtocols, result)
|