~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2014 Big Switch Networks, Inc.
2
 
# All Rights Reserved.
3
 
#
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
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,
12
 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
 
# implied.
14
 
# See the License for the specific language governing permissions and
15
 
# limitations under the License.
16
 
 
17
 
import contextlib
18
 
import mock
19
 
 
20
 
from neutron.tests.unit.bigswitch import test_router_db
21
 
 
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'
27
 
 
28
 
 
29
 
class CapabilitiesTests(test_router_db.RouterDBTestBase):
30
 
 
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:
41
 
                pass
42
 
            mock_create.assert_has_calls(
43
 
                [mock.call(fip['floatingip']['tenant_id'], fip['floatingip'])]
44
 
            )
45
 
            mock_delete.assert_has_calls(
46
 
                [mock.call(fip['floatingip']['tenant_id'],
47
 
                           fip['floatingip']['id'])]
48
 
            )
49
 
 
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:
58
 
                pass
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)
64
 
 
65
 
    def test_keep_alive_capability(self):
66
 
        with mock.patch(
67
 
            SERVERRESTCALL, return_value=(200, None, '["keep-alive"]', None)
68
 
        ):
69
 
            # perform a task to cause capabilities to be retrieved
70
 
            with self.floatingip_with_assoc():
71
 
                pass
72
 
        # stop default HTTP patch since we need a magicmock
73
 
        self.httpPatch.stop()
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'
78
 
        with self.network():
79
 
            callheaders = instance.request.mock_calls[0][1][3]
80
 
            self.assertIn('Connection', callheaders)
81
 
            self.assertEqual(callheaders['Connection'], 'keep-alive')