def test_ovsbridge_lookup_zero_ports_success(self, mock_run_cmd): call_br_exists = ['ovs-vsctl', 'br-exists', 'bridge'] br_exists_return = ['', '', 0] call_list_ports = ['ovs-vsctl', 'list-ports', 'bridge'] list_ports_return = ['', '', 0] mock_run_cmd_calls = [call(call_br_exists), call(call_list_ports)] mock_run_cmd.side_effect = [br_exists_return, list_ports_return] lookup_dict = OVSBridgeModel().lookup('bridge') mock_run_cmd.assert_has_calls(mock_run_cmd_calls) self.assertEqual('bridge', lookup_dict.get('name')) self.assertEqual([], lookup_dict.get('ports'))
def test_ovsbridge_lookup_one_interface_success(self, mock_run_cmd): call_br_exists = ['ovs-vsctl', 'br-exists', 'bridge'] br_exists_return = ['', '', 0] call_list_ports = ['ovs-vsctl', 'list-ports', 'bridge'] list_ports_return = ['iface1\n', '', 0] call_iface1_lookup = ['ovs-vsctl', 'list', 'Port', 'iface1'] iface1_lookup_output = \ self.get_list_port_output('iface1', '[single_uuid]') iface1_lookup_return = [iface1_lookup_output, '', 0] call_iface1_interface_lookup = ['ovs-vsctl', 'list', 'Interface', 'single_uuid'] interface_lookup_output = \ self.get_list_interfaces_output('iface1', iface_uuid='single_uuid') interface_lookup_return = [interface_lookup_output, '', 0] mock_run_cmd_calls = [ call(call_br_exists), call(call_list_ports), call(call_iface1_lookup), call(call_iface1_interface_lookup), ] mock_run_cmd.side_effect = [ br_exists_return, list_ports_return, iface1_lookup_return, interface_lookup_return ] lookup_dict = OVSBridgeModel().lookup('bridge') mock_run_cmd.assert_has_calls(mock_run_cmd_calls) self.assertEqual('bridge', lookup_dict.get('name')) iface1_dict = { 'type': 'interface', 'name': 'iface1', 'admin_state': 'down', 'link_state': 'down', 'mac_in_use': '16:bd:8d:f8:aa:f6', 'statistics': { 'collisions': '0', 'rx_bytes': '0', 'rx_crc_err': '0', 'rx_dropped': '0', 'rx_errors': '0', 'rx_frame_err': '0', 'rx_over_err': '0', 'rx_packets': '0', 'tx_bytes': '0', 'tx_dropped': '0', 'tx_errors': '0', 'tx_packets': '0' } } self.assertEqual(1, len(lookup_dict.get('ports'))) self.assertEqual(iface1_dict, lookup_dict.get('ports')[0])