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

« back to all changes in this revision

Viewing changes to neutron/tests/unit/ml2/test_mechanism_odl.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Corey Bryant
  • Date: 2014-10-06 09:15:06 UTC
  • mfrom: (28.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20141006091506-cesvev43moce4y74
Tags: 1:2014.1.3-0ubuntu1
[ 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:
14
14
#    under the License.
15
15
# @author: Kyle Mestery, Cisco Systems, Inc.
16
16
 
 
17
import mock
 
18
import requests
 
19
 
17
20
from neutron.plugins.common import constants
18
21
from neutron.plugins.ml2 import config as config
19
22
from neutron.plugins.ml2 import driver_api as api
20
23
from neutron.plugins.ml2.drivers import mechanism_odl
 
24
from neutron.tests import base
21
25
from neutron.tests.unit import test_db_plugin as test_plugin
22
26
 
23
27
PLUGIN_NAME = 'neutron.plugins.ml2.plugin.Ml2Plugin'
77
81
class OpenDaylightMechanismTestPortsV2(test_plugin.TestPortsV2,
78
82
                                       OpenDaylightTestCase):
79
83
    pass
 
84
 
 
85
 
 
86
class AuthMatcher(object):
 
87
    def __eq__(self, obj):
 
88
        return (obj.username == config.cfg.CONF.ml2_odl.username and
 
89
                obj.password == config.cfg.CONF.ml2_odl.password)
 
90
 
 
91
 
 
92
class OpenDaylightMechanismDriverTestCase(base.BaseTestCase):
 
93
 
 
94
    def setUp(self):
 
95
        super(OpenDaylightMechanismDriverTestCase, self).setUp()
 
96
        config.cfg.CONF.set_override('mechanism_drivers',
 
97
                                     ['logger', 'opendaylight'], 'ml2')
 
98
        config.cfg.CONF.set_override('url', 'http://127.0.0.1:9999', 'ml2_odl')
 
99
        config.cfg.CONF.set_override('username', 'someuser', 'ml2_odl')
 
100
        config.cfg.CONF.set_override('password', 'somepass', 'ml2_odl')
 
101
        self.mech = mechanism_odl.OpenDaylightMechanismDriver()
 
102
        self.mech.initialize()
 
103
 
 
104
    @staticmethod
 
105
    def _get_mock_delete_resource_context():
 
106
        current = {'id': '00000000-1111-2222-3333-444444444444'}
 
107
        context = mock.Mock(current=current)
 
108
        return context
 
109
 
 
110
    _status_code_msgs = {
 
111
        204: '',
 
112
        401: '401 Client Error: Unauthorized',
 
113
        403: '403 Client Error: Forbidden',
 
114
        404: '404 Client Error: Not Found',
 
115
        409: '409 Client Error: Conflict',
 
116
        501: '501 Server Error: Not Implemented'
 
117
    }
 
118
 
 
119
    @classmethod
 
120
    def _get_mock_request_response(cls, status_code):
 
121
        response = mock.Mock(status_code=status_code)
 
122
        response.raise_for_status = mock.Mock() if status_code < 400 else (
 
123
            mock.Mock(side_effect=requests.exceptions.HTTPError(
 
124
                cls._status_code_msgs[status_code])))
 
125
        return response
 
126
 
 
127
    def _test_delete_resource_postcommit(self, object_type, status_code,
 
128
                                         exc_class=None):
 
129
        self.mech.out_of_sync = False
 
130
        method = getattr(self.mech, 'delete_%s_postcommit' % object_type)
 
131
        context = self._get_mock_delete_resource_context()
 
132
        request_response = self._get_mock_request_response(status_code)
 
133
        with mock.patch('requests.request',
 
134
                        return_value=request_response) as mock_method:
 
135
            if exc_class is not None:
 
136
                self.assertRaises(exc_class, method, context)
 
137
            else:
 
138
                method(context)
 
139
        url = '%s/%ss/%s' % (config.cfg.CONF.ml2_odl.url, object_type,
 
140
                             context.current['id'])
 
141
        mock_method.assert_called_once_with(
 
142
            'delete', url=url, headers={'Content-Type': 'application/json'},
 
143
            data=None, auth=AuthMatcher(),
 
144
            timeout=config.cfg.CONF.ml2_odl.timeout)
 
145
 
 
146
    def test_delete_network_postcommit(self):
 
147
        self._test_delete_resource_postcommit('network',
 
148
                                              requests.codes.no_content)
 
149
        for status_code in (requests.codes.unauthorized,
 
150
                            requests.codes.not_found,
 
151
                            requests.codes.conflict):
 
152
            self._test_delete_resource_postcommit(
 
153
                'network', status_code, requests.exceptions.HTTPError)
 
154
 
 
155
    def test_delete_subnet_postcommit(self):
 
156
        self._test_delete_resource_postcommit('subnet',
 
157
                                              requests.codes.no_content)
 
158
        for status_code in (requests.codes.unauthorized,
 
159
                            requests.codes.not_found,
 
160
                            requests.codes.conflict,
 
161
                            requests.codes.not_implemented):
 
162
            self._test_delete_resource_postcommit(
 
163
                'subnet', status_code, requests.exceptions.HTTPError)
 
164
 
 
165
    def test_delete_port_postcommit(self):
 
166
        self._test_delete_resource_postcommit('port',
 
167
                                              requests.codes.no_content)
 
168
        for status_code in (requests.codes.unauthorized,
 
169
                            requests.codes.forbidden,
 
170
                            requests.codes.not_found,
 
171
                            requests.codes.not_implemented):
 
172
            self._test_delete_resource_postcommit(
 
173
                'port', status_code, requests.exceptions.HTTPError)