Ejemplo n.º 1
0
 def test_success(self, init):
     # Setup
     services = {
         BEACON_SERVICE: ["bs1", "bs2", "bs3"],
         CERTIFICATE_SERVICE: ["cs1"],
         DNS_SERVICE: ["ds1", "ds2"],
         PATH_SERVICE: [],
         SIBRA_SERVICE: ["sb1"],
     }
     server = SCIONDnsServer("srvid", "conf_dir")
     server.zk = create_mock(['wait_connected'])
     server.domain = self.DOMAIN
     server._parties = {}
     for i in SCIONDnsServer.SRV_TYPES:
         party = create_mock(["list"])
         party.list.return_value = services[i]
         server._parties[i] = party
     server._parse_srv_inst = create_mock()
     server.lock = create_mock(['__enter__', '__exit__'])
     server.resolver = create_mock(["services"])
     domain_set = set(
         [self.DOMAIN.add(srv) for srv in SCIONDnsServer.SRV_TYPES])
     # Call
     server._sync_zk_state()
     # Tests
     server.zk.wait_connected.assert_called_once_with(timeout=10.0)
     ntools.eq_(domain_set, set(server.services))
     for type_, insts in services.items():
         for inst in insts:
             server._parse_srv_inst.assert_any_call(inst,
                                                    self.DOMAIN.add(type_))
     ntools.ok_(server.lock.mock_calls)
     ntools.eq_(server.resolver.services, server.services)
Ejemplo n.º 2
0
 def test_connloss(self, init):
     # Setup
     server = SCIONDnsServer("srvid", "conf_dir")
     server.zk = create_mock(['wait_connected'])
     server.domain = self.DOMAIN
     party = create_mock(["list"])
     party.list.side_effect = ZkNoConnection
     server._parties = {SCIONDnsServer.SRV_TYPES[0]: party}
     # Call
     server._sync_zk_state()
Ejemplo n.º 3
0
 def test_no_conn(self, init):
     # Setup
     server = SCIONDnsServer("srvid", "conf_dir")
     server.zk = create_mock(['wait_connected'])
     server.zk.wait_connected.side_effect = ZkNoConnection
     # Call
     server._sync_zk_state()
     # Tests
     server.zk.wait_connected.assert_called_once_with(timeout=10.0)
     ntools.eq_(server.services, {})
Ejemplo n.º 4
0
 def test(self, init, sleep):
     # Setup
     server = SCIONDnsServer("srvid", "conf_dir")
     server._sync_zk_state = create_mock()
     server.udp_server = create_mock(["start_thread", "isAlive"])
     server.tcp_server = create_mock(["start_thread", "isAlive"])
     sleep.side_effect = []
     # Call
     ntools.assert_raises(StopIteration, server.run)
     # Tests
     ntools.eq_(server._sync_zk_state.call_count, 2)
     server.udp_server.start_thread.assert_called_once_with()
     server.tcp_server.start_thread.assert_called_once_with()
     server.udp_server.isAlive.assert_called_once_with()
     server.tcp_server.isAlive.assert_called_once_with()
     sleep.assert_called_once_with(server.SYNC_TIME)