def test_open_no_such_file(self): with mock.patch('builtins.open', side_effect=IOError()) as mock_open: iptables._ib_mac_to_rmac_mapping(self.ports) self.assertEqual(self.ib_address, self.ib_port.address) self.assertEqual(self.ports, [self.ib_port, self.port]) mock_open.assert_called_once_with('/sys/class/net/eth0/eth/neighs', 'r')
def test_no_interfaces(self): CONF.set_override('ethoib_interfaces', [], 'iptables') with mock.patch('six.moves.builtins.open', self.fileobj, create=True) as mock_open: iptables._ib_mac_to_rmac_mapping(self.ports) self.assertEqual(self.ib_address, self.ib_port.address) self.assertEqual(self.ports, [self.ib_port, self.port]) mock_open.assert_not_called()
def test_matching_ib(self): with mock.patch('six.moves.builtins.open', self.fileobj, create=True) as mock_open: iptables._ib_mac_to_rmac_mapping(self.ports) self.assertEqual(self.expected_rmac, self.ib_port.address) self.assertEqual(self.ports, [self.ib_port, self.port]) mock_open.assert_called_once_with('/sys/class/net/eth0/eth/neighs', 'r')
def test_no_interfaces(self): CONF.set_override('ethoib_interfaces', [], 'iptables') with mock.patch('six.moves.builtins.open', self.fileobj, create=True) as mock_open: iptables._ib_mac_to_rmac_mapping(self.ports) self.assertEqual(self.ib_address, self.ib_port.address) self.assertEqual(self.ports, [self.ib_port, self.port]) mock_open.assert_not_called()
def test_open_no_such_file(self): with mock.patch('six.moves.builtins.open', side_effect=IOError()) as mock_open: iptables._ib_mac_to_rmac_mapping(self.ports) self.assertEqual(self.ib_address, self.ib_port.address) self.assertEqual(self.ports, [self.ib_port, self.port]) mock_open.assert_called_once_with('/sys/class/net/eth0/eth/neighs', 'r')
def test_matching_ib(self): with mock.patch('six.moves.builtins.open', self.fileobj, create=True) as mock_open: iptables._ib_mac_to_rmac_mapping(self.ports) self.assertEqual(self.expected_rmac, self.ib_port.address) self.assertEqual(self.ports, [self.ib_port, self.port]) mock_open.assert_called_once_with('/sys/class/net/eth0/eth/neighs', 'r')
def test_ib_not_match(self): self.ports[0].extra['client-id'] = 'foo' with mock.patch('six.moves.builtins.open', self.fileobj, create=True) as mock_open: iptables._ib_mac_to_rmac_mapping(self.ports) self.assertEqual(self.ib_address, self.ib_port.address) self.assertEqual(self.ports, [self.ib_port, self.port]) mock_open.assert_called_once_with('/sys/class/net/eth0/eth/neighs', 'r')
def test_ib_not_match(self): self.ports[0].extra['client-id'] = 'foo' with mock.patch('six.moves.builtins.open', self.fileobj, create=True) as mock_open: iptables._ib_mac_to_rmac_mapping(self.ports) self.assertEqual(self.ib_address, self.ib_port.address) self.assertEqual(self.ports, [self.ib_port, self.port]) mock_open.assert_called_once_with('/sys/class/net/eth0/eth/neighs', 'r')