def test_select_device_hash(self): h = hooks.PlumbingHooks(None, devices=devices1) d = h._select_device_hash(TENANT_ID) self.assertEqual(d['name'], EXPECTED_DEV1) h = hooks.PlumbingHooks(None, devices=devices2) d = h._select_device_hash(TENANT_ID) self.assertEqual(d['name'], EXPECTED_DEV2)
def test_select_device_db(self): h = hooks.PlumbingHooks(None, devices=devices1) db = self.open_session() d = h._select_device_db(TENANT_ID, db_session=db) self.assertEqual(d['name'], EXPECTED_DEV1) db = self.open_session() z = list(db.query(models.A10TenantBinding)) self.assertEqual(z[0].tenant_id, TENANT_ID) self.assertEqual(z[0].device_name, EXPECTED_DEV1) h = hooks.PlumbingHooks(None, devices=devices2) db = self.open_session() d = h._select_device_db(TENANT_ID, db_session=db) self.assertEqual(d['name'], EXPECTED_DEV1) # 1 is not a typo
def __init__(self, openstack_driver, **kw): super(FakeA10OpenstackLB, self).__init__( mock.MagicMock(), **kw) self.openstack_driver = mock.MagicMock() self.plumbing_hooks = hooks.PlumbingHooks(self) self.openstack_context = _build_openstack_context()
def reset_mocks(self): self.openstack_driver = mock.MagicMock() self.plumbing_hooks = hooks.PlumbingHooks(self) self.last_client = self._get_a10_client(self.device_info) return self.last_client
def _get_a10_client(self, device_info): self.device_info = device_info self.last_client = mock.MagicMock() self.plumbing_hooks = hooks.PlumbingHooks(self) return self.last_client
def test_select_device(self): hooks = plumbing_hooks.PlumbingHooks(self.a) a = hooks.select_device("first-token") hooks.select_device("second-token") self.assertEqual(a, hooks.select_device("first-token"))