4a90dcd85f
This fixes the iptables unit tests that break with a randomized PYTHONHASHSEED (see the bug report). The chains for iptables are stored as sets to avoid duplicates. When they are output by iptables_manager their order can therefore be unpredictable. This was found hash seed 1016732220. To fix this we: - Sort the chains output by iptables_manager - Update the unit tests to check for sorted chains When multiple tables are processed, they can be processed in any order or dumped in any order. Found with hash seed 3728666619. To fix this we: - Traverse the tables in sorted order for dumping - Fix tests to allow for tables to be processed in any order Note: There are several other unrelated unit tests that also break with a randomized PYTHONHASHSEED, but they are not addressed here. They will be addressed in separate patches. Partial-bug: #1348818 Change-Id: Ic3f4cd85316c9fc2e78bc7f5e900cfac87baf39d
49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
# Copyright (c) 2013 NEC Corporation
|
|
# All Rights Reserved.
|
|
#
|
|
# 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.
|
|
#
|
|
# @author: Akihiro Motoki, NEC Corporation
|
|
|
|
|
|
"""setup_mock_calls and verify_mock_calls are convenient methods
|
|
to setup a sequence of mock calls.
|
|
|
|
expected_calls_and_values is a list of (expected_call, return_value):
|
|
|
|
expected_calls_and_values = [
|
|
(mock.call(["ovs-vsctl", self.TO, '--', "--may-exist", "add-port",
|
|
self.BR_NAME, pname], root_helper=self.root_helper),
|
|
None),
|
|
(mock.call(["ovs-vsctl", self.TO, "set", "Interface",
|
|
pname, "type=gre"], root_helper=self.root_helper),
|
|
None),
|
|
....
|
|
]
|
|
|
|
* expected_call should be mock.call(expected_arg, ....)
|
|
* return_value is passed to side_effect of a mocked call.
|
|
A return value or an exception can be specified.
|
|
"""
|
|
|
|
|
|
def setup_mock_calls(mocked_call, expected_calls_and_values):
|
|
return_values = [call[1] for call in expected_calls_and_values]
|
|
mocked_call.side_effect = return_values
|
|
|
|
|
|
def verify_mock_calls(mocked_call, expected_calls_and_values,
|
|
any_order=False):
|
|
expected_calls = [call[0] for call in expected_calls_and_values]
|
|
mocked_call.assert_has_calls(expected_calls, any_order=any_order)
|