~corey.bryant/ubuntu/trusty/neutron/lp1318721

« back to all changes in this revision

Viewing changes to neutron/tests/unit/bigswitch/test_servermanager.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Corey Bryant
  • Date: 2014-10-06 09:15:06 UTC
  • mfrom: (1.1.14)
  • mto: (29.1.2 trusty-security)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20141006091506-k5hdva17naps5ll4
[ Corey Bryant ]
* Resynchronize with stable/icehouse (4a0210e) (LP: #1377136):
  - [3a30d19] Deletes floating ip related connection states
  - [dd4b77f] Forbid regular users to reset admin-only attrs to default values
  - [dc2c893] Add delete operations for the ODL MechanismDriver
  - [b51e2c7] Add missing ml2 plugin to migration 1fcfc149aca4
  - [a17a500] Don't convert numeric protocol values to int
  - [3a85946] NSX: Optionally not enforce nat rule match length check
  - [645f984] Don't spawn metadata-proxy for non-isolated nets
  - [b464d89] Big Switch: Check for 'id' in port before lookup
  - [3116ffa] use TRUE in SQL for boolean var
  - [3520e66] call security_groups_member_updated in port_update
  - [50e1534] Don't allow user to set firewall rule with port and no protocol
  - [0061533] BSN: Add context to backend request for debugging
  - [6de6d61] Improve ODL ML2 Exception Handling
  - [2a4153d] Send network name and uuid to subnet create
  - [b5e3c9a] BSN: Allow concurrent reads to consistency DB
  - [b201432] Big Switch: Retry on 503 errors from backend
  - [f6c47ee] NSX: log request body to NSX as debug
  - [97d622a] Fix metadata agent's auth info caching
  - [255df45] NSX: Correct allowed_address_pair return value on create_port
  - [5bea041] Neutron should not use the neutronclient utils module for import_class
  - [d5314e2] Cisco N1kv plugin to send subtype on network profile creation
  - [f32d1ce] Pass object to policy when finding fields to strip
  - [8b5f6be] Call policy.init() once per API request
  - [9a6d811] Perform policy checks only once on list responses
  - [c48db90] Datacenter moid should not be tuple
  - [161d465] Allow unsharing a network used as gateway/floatingip
  - [9574a2f] Add support for router scheduling in Cisco N1kv Plugin
  - [6f54565] Fix func job hook script permission problems
  - [ea43103] Add hook scripts for the functional infra job
  - [8161cb7] Fixes Hyper-V agent issue on Hyper-V 2008 R2
  - [8e99cfd] Fixes Hyper-V issue due to ML2 RPC versioning
  - [69f9121] Ensure ip6tables are used only if ipv6 is enabled in kernel
  - [399b809] Remove explicit dependency on amqplib
  - [a872143] Clear entries in Cisco N1KV specific tables on rollback
  - [ad82fad] Verify ML2 type driver exists before calling del
  - [af2cc98] Big Switch: Only update hash header on success
  - [b1e5eec] Ignore variable column widths in ovsdb functional tests
  - [4a0210e] VMWare: don't notify on disassociate_floatingips()

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import mock
22
22
from oslo.config import cfg
23
23
 
 
24
from neutron import context
24
25
from neutron.manager import NeutronManager
25
26
from neutron.openstack.common import importutils
 
27
from neutron.openstack.common import jsonutils
26
28
from neutron.plugins.bigswitch import servermanager
27
29
from neutron.tests.unit.bigswitch import test_restproxy_plugin as test_rp
28
30
 
80
82
            rmock.assert_called_with('GET', '/health', '', {}, [], False)
81
83
            self.assertEqual(1, len(lmock.mock_calls))
82
84
 
 
85
    def test_consistency_hash_header(self):
 
86
        # mock HTTP class instead of rest_call so we can see headers
 
87
        with mock.patch(HTTPCON) as conmock:
 
88
            rv = conmock.return_value
 
89
            rv.getresponse.return_value.getheader.return_value = 'HASHHEADER'
 
90
            rv.getresponse.return_value.status = 200
 
91
            rv.getresponse.return_value.read.return_value = ''
 
92
            with self.network():
 
93
                callheaders = rv.request.mock_calls[0][1][3]
 
94
                self.assertIn('X-BSN-BVS-HASH-MATCH', callheaders)
 
95
                # first call will be empty to indicate no previous state hash
 
96
                self.assertEqual(callheaders['X-BSN-BVS-HASH-MATCH'], '')
 
97
                # change the header that will be received on delete call
 
98
                rv.getresponse.return_value.getheader.return_value = 'HASH2'
 
99
 
 
100
            # net delete should have used header received on create
 
101
            callheaders = rv.request.mock_calls[1][1][3]
 
102
            self.assertEqual(callheaders['X-BSN-BVS-HASH-MATCH'], 'HASHHEADER')
 
103
 
 
104
            # create again should now use header received from prev delete
 
105
            with self.network():
 
106
                callheaders = rv.request.mock_calls[2][1][3]
 
107
                self.assertIn('X-BSN-BVS-HASH-MATCH', callheaders)
 
108
                self.assertEqual(callheaders['X-BSN-BVS-HASH-MATCH'],
 
109
                                 'HASH2')
 
110
 
 
111
    def test_consistency_hash_header_no_update_on_bad_response(self):
 
112
        # mock HTTP class instead of rest_call so we can see headers
 
113
        with mock.patch(HTTPCON) as conmock:
 
114
            rv = conmock.return_value
 
115
            rv.getresponse.return_value.getheader.return_value = 'HASHHEADER'
 
116
            rv.getresponse.return_value.status = 200
 
117
            rv.getresponse.return_value.read.return_value = ''
 
118
            with self.network():
 
119
                # change the header that will be received on delete call
 
120
                rv.getresponse.return_value.getheader.return_value = 'EVIL'
 
121
                rv.getresponse.return_value.status = 'GARBAGE'
 
122
 
 
123
            # create again should not use header from delete call
 
124
            with self.network():
 
125
                callheaders = rv.request.mock_calls[2][1][3]
 
126
                self.assertIn('X-BSN-BVS-HASH-MATCH', callheaders)
 
127
                self.assertEqual(callheaders['X-BSN-BVS-HASH-MATCH'],
 
128
                                 'HASHHEADER')
 
129
 
83
130
    def test_file_put_contents(self):
84
131
        pl = NeutronManager.get_plugin()
85
132
        with mock.patch(SERVERMANAGER + '.open', create=True) as omock:
109
156
                mock.call.write('certdata')
110
157
            ])
111
158
 
 
159
    def test_req_context_header(self):
 
160
        sp = NeutronManager.get_plugin().servers
 
161
        ncontext = context.Context('uid', 'tid')
 
162
        sp.set_context(ncontext)
 
163
        with mock.patch(HTTPCON) as conmock:
 
164
            rv = conmock.return_value
 
165
            rv.getresponse.return_value.getheader.return_value = 'HASHHEADER'
 
166
            sp.rest_action('GET', '/')
 
167
        callheaders = rv.request.mock_calls[0][1][3]
 
168
        self.assertIn(servermanager.REQ_CONTEXT_HEADER, callheaders)
 
169
        ctxdct = ncontext.to_dict()
 
170
        self.assertEqual(
 
171
            ctxdct, jsonutils.loads(
 
172
                callheaders[servermanager.REQ_CONTEXT_HEADER]))
 
173
 
112
174
    def test_capabilities_retrieval(self):
113
175
        sp = servermanager.ServerPool()
114
176
        with mock.patch(HTTPCON) as conmock:
186
248
            resp = sp.servers[0].rest_call('GET', '/')
187
249
            self.assertEqual(resp, (0, None, None, None))
188
250
 
 
251
    def test_retry_on_unavailable(self):
 
252
        pl = NeutronManager.get_plugin()
 
253
        with nested(
 
254
            mock.patch(SERVERMANAGER + '.ServerProxy.rest_call',
 
255
                       return_value=(httplib.SERVICE_UNAVAILABLE, 0, 0, 0)),
 
256
            mock.patch(SERVERMANAGER + '.time.sleep')
 
257
        ) as (srestmock, tmock):
 
258
            # making a call should trigger retries with sleeps in between
 
259
            pl.servers.rest_call('GET', '/', '', None, [])
 
260
            rest_call = [mock.call('GET', '/', '', None, False, reconnect=True,
 
261
                                   hash_handler=mock.ANY)]
 
262
            rest_call_count = (
 
263
                servermanager.HTTP_SERVICE_UNAVAILABLE_RETRY_COUNT + 1)
 
264
            srestmock.assert_has_calls(rest_call * rest_call_count)
 
265
            sleep_call = [mock.call(
 
266
                servermanager.HTTP_SERVICE_UNAVAILABLE_RETRY_INTERVAL)]
 
267
            # should sleep 1 less time than the number of calls
 
268
            sleep_call_count = rest_call_count - 1
 
269
            tmock.assert_has_calls(sleep_call * sleep_call_count)
 
270
 
189
271
 
190
272
class TestSockets(test_rp.BigSwitchProxyPluginV2TestCase):
191
273