def register_link(self, device_port, to_device_spec): """Registers a port linking between device port and to_device_sped.""" link = Link(self._api, self, {}) link.set_peer_a_name(device_port.get_device_name()) link.set_peer_a_port_id(device_port.get_id()) link.set_peer_b_name(to_device_spec['device']) link.set_peer_b_port_id(to_device_spec['port_id']) self._links.append(link) return link
def setUp(self): self._api = MagicMock() self._context = MagicMock() self._simple_link_data = yaml.load(""" links: - link: peer_A: [bridge-000-001, 1] peer_B: [router-000-001, 2] """) self._link_data = self._simple_link_data['links'][0].get('link') self._link = Link(self._api, self._context, self._link_data)
def test_peer_name_and_port_id(self): self._link = Link(self._api, self._context, {}) self.assertEqual(None, self._link.get_peer_a_name()) self.assertEqual(None, self._link.get_peer_a_port_id()) self._link.set_peer_a_name('foo') self._link.set_peer_a_port_id(33) self.assertEqual('foo', self._link.get_peer_a_name()) self.assertEqual(33, self._link.get_peer_a_port_id()) self.assertEqual(None, self._link.get_peer_b_name()) self.assertEqual(None, self._link.get_peer_b_port_id()) self._link.set_peer_b_name('bar') self._link.set_peer_b_port_id(44) self.assertEqual('bar', self._link.get_peer_b_name()) self.assertEqual(44, self._link.get_peer_b_port_id())
class LinkTest(unittest.TestCase): def setUp(self): self._api = MagicMock() self._context = MagicMock() self._simple_link_data = yaml.load(""" links: - link: peer_A: [bridge-000-001, 1] peer_B: [router-000-001, 2] """) self._link_data = self._simple_link_data['links'][0].get('link') self._link = Link(self._api, self._context, self._link_data) def test_peer_names_and_port_ids(self): self.assertEqual('bridge-000-001', self._link.get_peer_a_name()) self.assertEqual(1, self._link.get_peer_a_port_id()) self.assertEqual('router-000-001', self._link.get_peer_b_name()) self.assertEqual(2, self._link.get_peer_b_port_id()) def test_peer_name_and_port_id(self): self._link = Link(self._api, self._context, {}) self.assertEqual(None, self._link.get_peer_a_name()) self.assertEqual(None, self._link.get_peer_a_port_id()) self._link.set_peer_a_name('foo') self._link.set_peer_a_port_id(33) self.assertEqual('foo', self._link.get_peer_a_name()) self.assertEqual(33, self._link.get_peer_a_port_id()) self.assertEqual(None, self._link.get_peer_b_name()) self.assertEqual(None, self._link.get_peer_b_port_id()) self._link.set_peer_b_name('bar') self._link.set_peer_b_port_id(44) self.assertEqual('bar', self._link.get_peer_b_name()) self.assertEqual(44, self._link.get_peer_b_port_id()) def test_build(self): mock_port = MagicMock() self._context.get_device_port.return_value = mock_port self._link.build() self.assertIn(call('bridge-000-001', 1), self._context.get_device_port.mock_calls) self.assertIn(call('router-000-001', 2), self._context.get_device_port.mock_calls) mock_port.link.assert_called_once_with(mock_port) def test_build_no_port(self): self._context.get_device_port.return_value = None self.assertRaisesRegexp(PeerDevicePortNotFoundException, 'No corresponding peer device port found.', self._link.build)
def add_link(self, link_data): link = Link(self._api, self, link_data) self._links.append(link) return link