Merge "filter "updated_at" and "revision_number" in _gateway_ports_equal"

This commit is contained in:
Zuul 2018-12-01 09:36:11 +00:00 committed by Gerrit Code Review
commit 9ad2e05088
2 changed files with 33 additions and 1 deletions

View File

@ -29,6 +29,8 @@ from neutron.agent.linux import ip_lib
from neutron.agent.linux import keepalived from neutron.agent.linux import keepalived
from neutron.common import constants as const from neutron.common import constants as const
from neutron.common import utils as common_utils from neutron.common import utils as common_utils
from neutron.extensions import revisions
from neutron.extensions import timestamp
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
HA_DEV_PREFIX = 'ha-' HA_DEV_PREFIX = 'ha-'
@ -414,7 +416,8 @@ class HaRouter(router.RouterInfo):
def _get_filtered_dict(d, ignore): def _get_filtered_dict(d, ignore):
return {k: v for k, v in d.items() if k not in ignore} return {k: v for k, v in d.items() if k not in ignore}
keys_to_ignore = set([portbindings.HOST_ID]) keys_to_ignore = set([portbindings.HOST_ID, timestamp.UPDATED,
revisions.REVISION])
port1_filtered = _get_filtered_dict(port1, keys_to_ignore) port1_filtered = _get_filtered_dict(port1, keys_to_ignore)
port2_filtered = _get_filtered_dict(port2, keys_to_ignore) port2_filtered = _get_filtered_dict(port2, keys_to_ignore)
return port1_filtered == port2_filtered return port1_filtered == port2_filtered

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import copy
import signal import signal
import mock import mock
@ -20,12 +21,18 @@ from oslo_utils import uuidutils
from neutron.agent.l3 import ha_router from neutron.agent.l3 import ha_router
from neutron.agent.l3 import router_info from neutron.agent.l3 import router_info
from neutron.tests import base from neutron.tests import base
from neutron.tests.common import l3_test_common
from neutron.tests import tools from neutron.tests import tools
_uuid = uuidutils.generate_uuid _uuid = uuidutils.generate_uuid
class TestBasicRouterOperations(base.BaseTestCase): class TestBasicRouterOperations(base.BaseTestCase):
def setUp(self):
super(TestBasicRouterOperations, self).setUp()
self.device_exists_p = mock.patch(
'neutron.agent.linux.ip_lib.device_exists')
self.device_exists = self.device_exists_p.start()
def _create_router(self, router=None, **kwargs): def _create_router(self, router=None, **kwargs):
if not router: if not router:
@ -141,3 +148,25 @@ class TestBasicRouterOperations(base.BaseTestCase):
'ha_state') 'ha_state')
self.mock_open = IOError self.mock_open = IOError
self.assertEqual('unknown', ri.ha_state) self.assertEqual('unknown', ri.ha_state)
def test_gateway_ports_equal(self):
ri = self._create_router(mock.MagicMock())
ri.driver = mock.MagicMock()
subnet_id, qos_policy_id = _uuid(), _uuid()
_, old_gw_port = l3_test_common.prepare_ext_gw_test(
self, ri, True)
old_gw_port['qos_policy_id'] = qos_policy_id
new_gw_port = copy.deepcopy(old_gw_port)
new_gw_port.update({'binding:host_id': 'node02',
'updated_at': '2018-11-02T14:07:00',
'revision_number': 101,
'qos_policy_id': qos_policy_id})
self.assertTrue(ri._gateway_ports_equal(old_gw_port, new_gw_port))
fixed_ip = {'ip_address': '10.10.10.3', 'subnet_id': subnet_id}
new_gw_port['fixed_ips'].append(fixed_ip)
self.assertFalse(ri._gateway_ports_equal(old_gw_port, new_gw_port))
new_gw_port['fixed_ips'].remove(fixed_ip)
new_gw_port['qos_policy_id'] = _uuid()
self.assertFalse(ri._gateway_ports_equal(old_gw_port, new_gw_port))