Exemple #1
0
 def test(self, init, zone_resolver, dns_server, udp_server, tcp_server,
          dns_logger, zookeeper):
     # Setup
     server = SCIONDnsServer("srvid", "conf_dir")
     server.lock = "lock"
     server.domain = "domain"
     server.addr = create_mock(["host"])
     server.addr.host = "127.0.0.1"
     server.id = "srvid"
     server.topology = create_mock(["isd_as", "zookeepers"])
     server.topology.isd_as = "isd as"
     server.topology.zookeepers = ["zk0", "zk1"]
     server._setup_parties = create_mock()
     # Call
     server.setup()
     # Tests
     zone_resolver.assert_called_once_with("lock", "domain")
     dns_server.assert_any_call(zone_resolver.return_value,
                                port=SCION_DNS_PORT,
                                address="127.0.0.1",
                                server=udp_server,
                                logger=dns_logger.return_value)
     dns_server.assert_any_call(zone_resolver.return_value,
                                port=SCION_DNS_PORT,
                                address="127.0.0.1",
                                server=tcp_server,
                                logger=dns_logger.return_value)
     ntools.eq_(dns_server.call_count, 2)
     zookeeper.assert_called_once_with(
         "isd as", DNS_SERVICE, "srvid\0%d\000127.0.0.1" % SCION_DNS_PORT,
         ["zk0", "zk1"])
     ntools.eq_(server._parties, {})
     server._setup_parties.assert_called_once_with()
Exemple #2
0
 def test(self, init):
     # Setup
     server = SCIONDnsServer("srvid", "conf_dir")
     srv_domain = self.DOMAIN.add(BEACON_SERVICE)
     server.services = {srv_domain: ["addr0"]}
     # Call
     server._parse_srv_inst("name\0port\0addr1\0addr2", srv_domain)
     # Tests
     ntools.eq_(server.services[srv_domain], ["addr0", "addr1", "addr2"])
Exemple #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, {})
Exemple #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)
Exemple #5
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()
Exemple #6
0
 def test(self, _):
     server = SCIONDnsServer("srvid", "conf_dir")
     server.zk = create_mock(["retry", "party_setup"])
     server.addr = create_mock(["isd_as"])
     server.addr.isd_as = "30-10"
     server._parties = {}
     # Call
     server._setup_parties()
     # Tests
     for srv in server.SRV_TYPES:
         autojoin = False
         if srv == DNS_SERVICE:
             autojoin = True
         server.zk.retry.assert_any_call("Joining %s party" % srv,
                                         server.zk.party_setup,
                                         prefix="/30-10/%s" % srv,
                                         autojoin=autojoin)
     ntools.eq_(server.zk.retry.call_count, len(server.SRV_TYPES))
Exemple #7
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)