1
# Copyright 2014 Big Switch Networks, Inc.
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain 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,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
20
from neutron.tests.unit.bigswitch import test_router_db
22
PLUGIN = 'neutron.plugins.bigswitch.plugin'
23
SERVERMANAGER = PLUGIN + '.servermanager'
24
SERVERPOOL = SERVERMANAGER + '.ServerPool'
25
SERVERRESTCALL = SERVERMANAGER + '.ServerProxy.rest_call'
26
HTTPCON = SERVERMANAGER + '.httplib.HTTPConnection'
29
class CapabilitiesTests(test_router_db.RouterDBTestBase):
31
def test_floating_ip_capability(self):
32
with contextlib.nested(
33
mock.patch(SERVERRESTCALL,
34
return_value=(200, None, '["floatingip"]', None)),
35
mock.patch(SERVERPOOL + '.rest_create_floatingip',
36
return_value=(200, None, None, None)),
37
mock.patch(SERVERPOOL + '.rest_delete_floatingip',
38
return_value=(200, None, None, None))
39
) as (mock_rest, mock_create, mock_delete):
40
with self.floatingip_with_assoc() as fip:
42
mock_create.assert_has_calls(
43
[mock.call(fip['floatingip']['tenant_id'], fip['floatingip'])]
45
mock_delete.assert_has_calls(
46
[mock.call(fip['floatingip']['tenant_id'],
47
fip['floatingip']['id'])]
50
def test_floating_ip_capability_neg(self):
51
with contextlib.nested(
52
mock.patch(SERVERRESTCALL,
53
return_value=(200, None, '[""]', None)),
54
mock.patch(SERVERPOOL + '.rest_update_network',
55
return_value=(200, None, None, None))
56
) as (mock_rest, mock_netupdate):
57
with self.floatingip_with_assoc() as fip:
59
updates = [call[0][2]['floatingips']
60
for call in mock_netupdate.call_args_list]
61
all_floats = [f['floating_ip_address']
62
for floats in updates for f in floats]
63
self.assertIn(fip['floatingip']['floating_ip_address'], all_floats)
65
def test_keep_alive_capability(self):
67
SERVERRESTCALL, return_value=(200, None, '["keep-alive"]', None)
69
# perform a task to cause capabilities to be retrieved
70
with self.floatingip_with_assoc():
72
# stop default HTTP patch since we need a magicmock
74
# now mock HTTP class instead of REST so we can see headers
75
conmock = mock.patch(HTTPCON).start()
76
instance = conmock.return_value
77
instance.getresponse.return_value.getheader.return_value = 'HASHHEADER'
79
callheaders = instance.request.mock_calls[0][1][3]
80
self.assertIn('Connection', callheaders)
81
self.assertEqual(callheaders['Connection'], 'keep-alive')