~ubuntu-branches/ubuntu/wily/python-oslo.vmware/wily-proposed

« back to all changes in this revision

Viewing changes to tests/network/nsx/nsxv/test_nsxv_loadbalancer.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2015-03-04 10:25:46 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20150304102546-f0q5dshmrwtzj90g
Tags: 0.10.0-0ubuntu1
* New usptream release. 
* debian/control:
  - Transition to new namespace packages.
  - Add python-httplib2 and python-oslo.serialization

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2015 VMware, Inc.
 
2
# All Rights Reserved
 
3
#
 
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
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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
 
14
#    under the License.
 
15
 
 
16
import json
 
17
 
 
18
import mock
 
19
 
 
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
 
23
 
 
24
 
 
25
class NsxvLoadbalancerTestCase(base.TestCase):
 
26
 
 
27
    EDGE_OBJ_JSON = (
 
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"}]}')
 
49
 
 
50
    OUT_OBJ_JSON = (
 
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"}]}')
 
70
 
 
71
    LB_URI = '/api/4.0/edges/%s/loadbalancer/config?async=true'
 
72
    EDGE_1 = 'edge-x'
 
73
    EDGE_2 = 'edge-y'
 
74
 
 
75
    def setUp(self):
 
76
        super(NsxvLoadbalancerTestCase, self).setUp()
 
77
        self._lb = nsxv_lb.NsxvLoadbalancer()
 
78
        self._nsxv = nsxv_api.NsxvApi(None, None, None, None)
 
79
 
 
80
    def test_edge_loadbalancer(self):
 
81
        h = None
 
82
        v = json.loads(self.EDGE_OBJ_JSON)
 
83
 
 
84
        with mock.patch.object(self._nsxv, 'do_request',
 
85
                               return_value=(h, v)) as mock_do_request:
 
86
            # Retrieve Edge LB
 
87
            lb = nsxv_lb.NsxvLoadbalancer.get_loadbalancer(
 
88
                self._nsxv, self.EDGE_1)
 
89
 
 
90
            # Repost Edge LB
 
91
            lb.submit_to_backend(self._nsxv, self.EDGE_2)
 
92
 
 
93
            mock_do_request.assert_called_with(
 
94
                nsxv_api.HTTP_PUT,
 
95
                self.LB_URI % self.EDGE_2,
 
96
                self.OUT_OBJ_JSON,
 
97
                format='json',
 
98
                encode=False)