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

« back to all changes in this revision

Viewing changes to neutron/tests/unit/vmware/nsxlib/base.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 (c) 2014 VMware, Inc.
2
 
#
3
 
# Licensed under the Apache License, Version 2.0 (the "License");
4
 
# you may not use this file except in compliance with the License.
5
 
# You may obtain a copy of the License at
6
 
#
7
 
#    http://www.apache.org/licenses/LICENSE-2.0
8
 
#
9
 
# Unless required by applicable law or agreed to in writing, software
10
 
# distributed under the License is distributed on an "AS IS" BASIS,
11
 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
 
# implied.
13
 
# See the License for the specific language governing permissions and
14
 
# limitations under the License.
15
 
#
16
 
 
17
 
import mock
18
 
 
19
 
from neutron.plugins.vmware.api_client import client
20
 
from neutron.plugins.vmware.api_client import exception
21
 
from neutron.plugins.vmware.api_client import version
22
 
from neutron.plugins.vmware.common import config  # noqa
23
 
from neutron.plugins.vmware import nsx_cluster as cluster
24
 
from neutron.tests import base
25
 
from neutron.tests.unit import test_api_v2
26
 
from neutron.tests.unit import vmware
27
 
from neutron.tests.unit.vmware.apiclient import fake
28
 
 
29
 
_uuid = test_api_v2._uuid
30
 
 
31
 
 
32
 
class NsxlibTestCase(base.BaseTestCase):
33
 
 
34
 
    def setUp(self):
35
 
        self.fc = fake.FakeClient(vmware.STUBS_PATH)
36
 
        self.mock_nsxapi = mock.patch(vmware.NSXAPI_NAME, autospec=True)
37
 
        instance = self.mock_nsxapi.start()
38
 
        instance.return_value.login.return_value = "the_cookie"
39
 
        fake_version = getattr(self, 'fake_version', "3.0")
40
 
        instance.return_value.get_version.return_value = (
41
 
            version.Version(fake_version))
42
 
 
43
 
        instance.return_value.request.side_effect = self.fc.fake_request
44
 
        self.fake_cluster = cluster.NSXCluster(
45
 
            name='fake-cluster', nsx_controllers=['1.1.1.1:999'],
46
 
            default_tz_uuid=_uuid(), nsx_user='foo', nsx_password='bar')
47
 
        self.fake_cluster.api_client = client.NsxApiClient(
48
 
            ('1.1.1.1', '999', True),
49
 
            self.fake_cluster.nsx_user, self.fake_cluster.nsx_password,
50
 
            self.fake_cluster.http_timeout,
51
 
            self.fake_cluster.retries, self.fake_cluster.redirects)
52
 
 
53
 
        super(NsxlibTestCase, self).setUp()
54
 
        self.addCleanup(self.fc.reset_all)
55
 
 
56
 
    def _build_tag_dict(self, tags):
57
 
        # This syntax is needed for python 2.6 compatibility
58
 
        return dict((t['scope'], t['tag']) for t in tags)
59
 
 
60
 
 
61
 
class NsxlibNegativeBaseTestCase(base.BaseTestCase):
62
 
 
63
 
    def setUp(self):
64
 
        self.fc = fake.FakeClient(vmware.STUBS_PATH)
65
 
        self.mock_nsxapi = mock.patch(vmware.NSXAPI_NAME, autospec=True)
66
 
        instance = self.mock_nsxapi.start()
67
 
        instance.return_value.login.return_value = "the_cookie"
68
 
        # Choose 3.0, but the version is irrelevant for the aim of
69
 
        # these tests as calls are throwing up errors anyway
70
 
        fake_version = getattr(self, 'fake_version', "3.0")
71
 
        instance.return_value.get_version.return_value = (
72
 
            version.Version(fake_version))
73
 
 
74
 
        def _faulty_request(*args, **kwargs):
75
 
            raise exception.NsxApiException()
76
 
 
77
 
        instance.return_value.request.side_effect = _faulty_request
78
 
        self.fake_cluster = cluster.NSXCluster(
79
 
            name='fake-cluster', nsx_controllers=['1.1.1.1:999'],
80
 
            default_tz_uuid=_uuid(), nsx_user='foo', nsx_password='bar')
81
 
        self.fake_cluster.api_client = client.NsxApiClient(
82
 
            ('1.1.1.1', '999', True),
83
 
            self.fake_cluster.nsx_user, self.fake_cluster.nsx_password,
84
 
            self.fake_cluster.http_timeout,
85
 
            self.fake_cluster.retries, self.fake_cluster.redirects)
86
 
 
87
 
        super(NsxlibNegativeBaseTestCase, self).setUp()
88
 
        self.addCleanup(self.fc.reset_all)