b0519cf0ad
Resources could be created before the extension was enabled in the setup. In that case, no bindings are created for them. In that case, we should gracefully return default (True) value when extracting the value using the mixin; and we should also create binding model on update request, if there is no existing binding model for the resource. While at it, introduced a constant to store the default value for port security (True) and changed several tests to use the constant instead of extracting it from extension resource map. Change-Id: I8607cdecdc16c5f94635c94e2f02700c732806eb Closes-Bug: #1509312
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
# 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.
|
|
|
|
import mock
|
|
|
|
from neutron.db import portsecurity_db as pd
|
|
from neutron.db import portsecurity_db_common as pdc
|
|
from neutron.tests import base
|
|
|
|
common = pdc.PortSecurityDbCommon
|
|
|
|
|
|
class FakePlugin(pd.PortSecurityDbMixin):
|
|
|
|
supported_extension_aliases = ['port-security']
|
|
|
|
|
|
class PortSecurityDbMixinTestCase(base.BaseTestCase):
|
|
|
|
def setUp(self):
|
|
super(PortSecurityDbMixinTestCase, self).setUp()
|
|
self.plugin = FakePlugin()
|
|
|
|
@mock.patch.object(common, '_extend_port_security_dict')
|
|
def test__extend_port_security_dict_relies_on_common(self, extend):
|
|
response = mock.Mock()
|
|
dbdata = mock.Mock()
|
|
self.plugin._extend_port_security_dict(response, dbdata)
|
|
extend.assert_called_once_with(response, dbdata)
|
|
|
|
@mock.patch.object(common, '_extend_port_security_dict')
|
|
def test__extend_port_security_dict_ignored_if_extension_disabled(self,
|
|
extend):
|
|
response = mock.Mock()
|
|
dbdata = mock.Mock()
|
|
self.plugin.supported_extension_aliases = []
|
|
self.plugin._extend_port_security_dict(response, dbdata)
|
|
self.assertFalse(extend.called)
|