2020-03-27 10:13:31 +01:00
|
|
|
#!/usr/bin/python3
|
2021-06-03 08:37:05 +02:00
|
|
|
|
2020-03-27 10:13:31 +01:00
|
|
|
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
#
|
2020-03-27 10:13:31 +01:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
#
|
|
|
|
# See the COPYRIGHT file distributed with this work for additional
|
|
|
|
# information regarding copyright ownership.
|
|
|
|
|
|
|
|
from datetime import datetime
|
2020-04-14 17:02:21 +02:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2023-12-22 15:56:58 +01:00
|
|
|
import isctest.mark
|
2020-03-27 10:13:31 +01:00
|
|
|
|
2023-11-24 15:50:08 +01:00
|
|
|
pytest.register_assert_rewrite("generic")
|
|
|
|
import generic
|
|
|
|
|
2022-06-07 16:27:23 +02:00
|
|
|
requests = pytest.importorskip("requests")
|
2022-03-14 08:59:32 +01:00
|
|
|
|
2024-08-19 18:54:13 +02:00
|
|
|
pytestmark = [
|
2024-10-11 11:30:26 +02:00
|
|
|
isctest.mark.with_json_c,
|
2024-08-19 18:54:13 +02:00
|
|
|
pytest.mark.extra_artifacts(
|
|
|
|
[
|
|
|
|
"ns2/*.jnl",
|
|
|
|
"ns2/*.signed",
|
|
|
|
"ns2/dsset-*",
|
|
|
|
"ns2/K*",
|
|
|
|
"ns2/dnssec.db.signed",
|
|
|
|
"ns2/dnssec.*.id",
|
|
|
|
"ns2/manykeys.*.id",
|
|
|
|
"ns2/signzone.out.*",
|
|
|
|
"ns3/_default.nzd",
|
|
|
|
"ns3/example-tcp.db",
|
|
|
|
"ns3/example-tls.db",
|
|
|
|
"ns3/example.db",
|
|
|
|
]
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
2020-03-27 10:13:31 +01:00
|
|
|
|
|
|
|
# JSON helper functions
|
2020-04-14 17:02:21 +02:00
|
|
|
def fetch_zones_json(statsip, statsport):
|
2022-06-07 16:27:23 +02:00
|
|
|
r = requests.get(
|
|
|
|
"http://{}:{}/json/v1/zones".format(statsip, statsport), timeout=600
|
|
|
|
)
|
2020-03-27 10:13:31 +01:00
|
|
|
assert r.status_code == 200
|
|
|
|
|
|
|
|
data = r.json()
|
|
|
|
return data["views"]["_default"]["zones"]
|
|
|
|
|
|
|
|
|
2020-04-14 17:02:21 +02:00
|
|
|
def fetch_traffic_json(statsip, statsport):
|
2022-06-07 16:27:23 +02:00
|
|
|
r = requests.get(
|
|
|
|
"http://{}:{}/json/v1/traffic".format(statsip, statsport), timeout=600
|
|
|
|
)
|
2020-04-14 17:02:21 +02:00
|
|
|
assert r.status_code == 200
|
|
|
|
|
|
|
|
data = r.json()
|
|
|
|
|
|
|
|
return data["traffic"]
|
|
|
|
|
|
|
|
|
|
|
|
def load_timers_json(zone, primary=True):
|
2022-06-07 16:27:23 +02:00
|
|
|
name = zone["name"]
|
2020-03-27 10:13:31 +01:00
|
|
|
|
|
|
|
# Check if the primary zone timer exists
|
2022-06-07 16:27:23 +02:00
|
|
|
assert "loaded" in zone
|
|
|
|
loaded = datetime.strptime(zone["loaded"], generic.fmt)
|
2020-03-27 10:13:31 +01:00
|
|
|
|
|
|
|
if primary:
|
|
|
|
# Check if the secondary zone timers does not exist
|
2022-06-07 16:27:23 +02:00
|
|
|
assert "expires" not in zone
|
|
|
|
assert "refresh" not in zone
|
2020-03-27 10:13:31 +01:00
|
|
|
expires = None
|
|
|
|
refresh = None
|
|
|
|
else:
|
2022-06-07 16:27:23 +02:00
|
|
|
assert "expires" in zone
|
|
|
|
assert "refresh" in zone
|
|
|
|
expires = datetime.strptime(zone["expires"], generic.fmt)
|
|
|
|
refresh = datetime.strptime(zone["refresh"], generic.fmt)
|
2020-03-27 10:13:31 +01:00
|
|
|
|
|
|
|
return (name, loaded, expires, refresh)
|
|
|
|
|
|
|
|
|
2020-04-14 17:02:21 +02:00
|
|
|
def load_zone_json(zone):
|
2022-06-07 16:27:23 +02:00
|
|
|
name = zone["name"]
|
2020-04-14 17:02:21 +02:00
|
|
|
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
2020-03-27 10:13:31 +01:00
|
|
|
def test_zone_timers_primary_json(statsport):
|
2022-06-07 16:27:23 +02:00
|
|
|
generic.test_zone_timers_primary(
|
|
|
|
fetch_zones_json,
|
|
|
|
load_timers_json,
|
|
|
|
statsip="10.53.0.1",
|
|
|
|
statsport=statsport,
|
|
|
|
zonedir="ns1",
|
|
|
|
)
|
2020-03-27 10:13:31 +01:00
|
|
|
|
|
|
|
|
2020-04-14 17:02:21 +02:00
|
|
|
def test_zone_timers_secondary_json(statsport):
|
2022-06-07 16:27:23 +02:00
|
|
|
generic.test_zone_timers_secondary(
|
|
|
|
fetch_zones_json,
|
|
|
|
load_timers_json,
|
|
|
|
statsip="10.53.0.3",
|
|
|
|
statsport=statsport,
|
|
|
|
zonedir="ns3",
|
|
|
|
)
|
2020-03-27 10:13:31 +01:00
|
|
|
|
|
|
|
|
2020-04-14 17:02:21 +02:00
|
|
|
def test_zone_with_many_keys_json(statsport):
|
2022-06-07 16:27:23 +02:00
|
|
|
generic.test_zone_with_many_keys(
|
|
|
|
fetch_zones_json, load_zone_json, statsip="10.53.0.2", statsport=statsport
|
|
|
|
)
|
2020-03-27 10:13:31 +01:00
|
|
|
|
|
|
|
|
2024-08-12 15:43:19 +02:00
|
|
|
@isctest.mark.flaky(max_runs=2, rerun_filter=isctest.mark.with_tsan)
|
2023-12-04 18:10:42 +01:00
|
|
|
def test_traffic_json(statsport):
|
|
|
|
generic.test_traffic(fetch_traffic_json, statsip="10.53.0.2", statsport=statsport)
|