
Stops the default HTTPConnection patch used by the Big Switch tests before patching HTTPConnection with another substitution. This prevents mock from losing track of the default patch which was resulting in it not consistently being stopped by the stopall call in cleanup. This also corrects an incorrectly targeted mock for the HTTP patch in one of the test files. Closes-Bug: #1303605 Change-Id: Ia5b374c5f8d3a7905d915de4f1f8d4f3a6f0e58d
85 lines
3.4 KiB
Python
85 lines
3.4 KiB
Python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
# Copyright 2014 Big Switch Networks, Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
# @author Kevin Benton
|
|
|
|
from contextlib import nested
|
|
import mock
|
|
|
|
from neutron.tests.unit.bigswitch import test_router_db
|
|
|
|
PLUGIN = 'neutron.plugins.bigswitch.plugin'
|
|
SERVERMANAGER = PLUGIN + '.servermanager'
|
|
SERVERPOOL = SERVERMANAGER + '.ServerPool'
|
|
SERVERRESTCALL = SERVERMANAGER + '.ServerProxy.rest_call'
|
|
HTTPCON = SERVERMANAGER + '.HTTPConnection'
|
|
|
|
|
|
class CapabilitiesTests(test_router_db.RouterDBTestBase):
|
|
|
|
def test_floating_ip_capability(self):
|
|
with nested(
|
|
mock.patch(SERVERRESTCALL,
|
|
return_value=(200, None, None, '["floatingip"]')),
|
|
mock.patch(SERVERPOOL + '.rest_create_floatingip',
|
|
return_value=(200, None, None, None)),
|
|
mock.patch(SERVERPOOL + '.rest_delete_floatingip',
|
|
return_value=(200, None, None, None))
|
|
) as (mock_rest, mock_create, mock_delete):
|
|
with self.floatingip_with_assoc() as fip:
|
|
pass
|
|
mock_create.assert_has_calls(
|
|
[mock.call(fip['floatingip']['tenant_id'], fip['floatingip'])]
|
|
)
|
|
mock_delete.assert_has_calls(
|
|
[mock.call(fip['floatingip']['tenant_id'],
|
|
fip['floatingip']['id'])]
|
|
)
|
|
|
|
def test_floating_ip_capability_neg(self):
|
|
with nested(
|
|
mock.patch(SERVERRESTCALL,
|
|
return_value=(200, None, None, '[""]')),
|
|
mock.patch(SERVERPOOL + '.rest_update_network',
|
|
return_value=(200, None, None, None))
|
|
) as (mock_rest, mock_netupdate):
|
|
with self.floatingip_with_assoc() as fip:
|
|
pass
|
|
updates = [call[0][2]['floatingips']
|
|
for call in mock_netupdate.call_args_list]
|
|
all_floats = [f['floating_ip_address']
|
|
for floats in updates for f in floats]
|
|
self.assertIn(fip['floatingip']['floating_ip_address'], all_floats)
|
|
|
|
def test_keep_alive_capability(self):
|
|
with mock.patch(
|
|
SERVERRESTCALL, return_value=(200, None, None, '["keep-alive"]')
|
|
):
|
|
# perform a task to cause capabilities to be retrieved
|
|
with self.floatingip_with_assoc():
|
|
pass
|
|
# stop default HTTP patch since we need a magicmock
|
|
self.httpPatch.stop()
|
|
# now mock HTTP class instead of REST so we can see headers
|
|
conmock = mock.patch(HTTPCON).start()
|
|
instance = conmock.return_value
|
|
instance.getresponse.return_value.getheader.return_value = 'HASHHEADER'
|
|
with self.network():
|
|
callheaders = instance.request.mock_calls[0][1][3]
|
|
self.assertIn('Connection', callheaders)
|
|
self.assertEqual(callheaders['Connection'], 'keep-alive')
|