1
# Copyright 2015 VMware, Inc.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
20
from oslo_vmware.network.nsx.nsxv.api import api as nsxv_api
21
from oslo_vmware.network.nsx.nsxv.objects import loadbalancer as nsxv_lb
22
from tests import base
25
class NsxvLoadbalancerTestCase(base.TestCase):
28
'{"accelerationEnabled":false,"applicationProfile":[{'
29
'"applicationProfileId":"applicationProfile-1","insertXForwardedFor":'
30
'false,"name":"MDSrvProxy","persistence":{"cookieMode":"insert",'
31
'"cookieName":"JSESSIONID","expire":"30","method":"cookie"},'
32
'"serverSslEnabled":false,"sslPassthrough":false,"template":"HTTP"}],'
33
'"applicationRule":[],"enableServiceInsertion":false,"enabled":true,'
34
'"featureType":"loadbalancer_4.0","logging":{"enable":false,'
35
'"logLevel":"info"},"monitor":[{"interval":10,"maxRetries":3,"method":'
36
'"GET","monitorId":"monitor-1","name":"MDSrvMon","timeout":15,"type":'
37
'"http","url":"/"}],"pool":[{"algorithm":"round-robin",'
38
'"applicationRuleId":[],"member":[{"condition":"enabled","ipAddress":'
39
'"192.168.0.39","maxConn":0,"memberId":"member-1","minConn":0,'
40
'"monitorPort":8775,"name":"Member-1","port":8775,"weight":1}],'
41
'"monitorId":["monitor-1"],"name":"MDSrvPool","poolId":"pool-1",'
42
'"transparent":false}],"version":6,"virtualServer":[{'
43
'"accelerationEnabled":false,"applicationProfileId":'
44
'"applicationProfile-1","applicationRuleId":[],"connectionLimit":0,'
45
'"defaultPoolId":"pool-1","enableServiceInsertion":false,'
46
'"enabled":true,"ipAddress":"169.254.0.3","name":"MdSrv",'
47
'"port":"8775","protocol":"http","virtualServerId":'
48
'"virtualServer-1"}]}')
51
'{"accelerationEnabled": false, "applicationProfile": [{'
52
'"applicationProfileId": "applicationProfile-1", '
53
'"insertXForwardedFor": false, "name": "MDSrvProxy", "persistence": '
54
'{"expire": "30", "method": "cookie"}, "serverSslEnabled": false, '
55
'"sslPassthrough": false, "template": "HTTP"}],'
56
' "enableServiceInsertion": false, "enabled": true, "featureType": '
57
'"loadbalancer_4.0", "monitor": [{"interval": 10, "maxRetries": 3, '
58
'"method": "GET", "monitorId": "monitor-1", "name": "MDSrvMon", '
59
'"timeout": 15, "type": "http", "url": "/"}], "pool": [{"algorithm":'
60
' "round-robin", "member": [{"condition": "enabled", "ipAddress": '
61
'"192.168.0.39", "maxConn": 0, "memberId": "member-1", "minConn": 0, '
62
'"monitorPort": 8775, "name": "Member-1", "port": 8775, "weight": 1}],'
63
' "monitorId": ["monitor-1"], "name": "MDSrvPool", "poolId": "pool-1",'
64
' "transparent": false}], "virtualServer": [{"accelerationEnabled": '
65
'false, "applicationProfileId": "applicationProfile-1", '
66
'"connectionLimit": 0, "defaultPoolId": "pool-1", '
67
'"enableServiceInsertion": false, "enabled": true, "ipAddress": '
68
'"169.254.0.3", "name": "MdSrv", "port": "8775", "protocol": '
69
'"http", "virtualServerId": "virtualServer-1"}]}')
71
LB_URI = '/api/4.0/edges/%s/loadbalancer/config?async=true'
76
super(NsxvLoadbalancerTestCase, self).setUp()
77
self._lb = nsxv_lb.NsxvLoadbalancer()
78
self._nsxv = nsxv_api.NsxvApi(None, None, None, None)
80
def test_edge_loadbalancer(self):
82
v = json.loads(self.EDGE_OBJ_JSON)
84
with mock.patch.object(self._nsxv, 'do_request',
85
return_value=(h, v)) as mock_do_request:
87
lb = nsxv_lb.NsxvLoadbalancer.get_loadbalancer(
88
self._nsxv, self.EDGE_1)
91
lb.submit_to_backend(self._nsxv, self.EDGE_2)
93
mock_do_request.assert_called_with(
95
self.LB_URI % self.EDGE_2,