1 # Copyright (C) Internet Systems Consortium, Inc. ("ISC") 2 # 3 # SPDX-License-Identifier: MPL-2.0 4 # 5 # This Source Code Form is subject to the terms of the Mozilla Public 6 # License, v. 2.0. If a copy of the MPL was not distributed with this 7 # file, you can obtain one at https://mozilla.org/MPL/2.0/. 8 # 9 # See the COPYRIGHT file distributed with this work for additional 10 # information regarding copyright ownership. 11 12 13 import os 14 import pytest 15 16 import isctest 17 import isctest.mark 18 import isctest.run 19 20 pytestmark = [ 21 isctest.mark.with_lmdb, 22 pytest.mark.extra_artifacts( 23 ["ns1/_default.nzd", "ns1/_default.nzf~"], 24 ), 25 ] 26 27 28 def test_nzd2nzf(ns1): 29 zone_data = '"added.example" { type primary; file "added.db"; };' 30 msg = isctest.query.create("a.added.example.", "A") 31 32 # query for non-existing zone data 33 res = isctest.query.tcp(msg, ns1.ip) 34 isctest.check.refused(res) 35 36 # add new zone into the default NZD using "rndc addzone" 37 ns1.rndc(f"addzone {zone_data}") 38 39 # query for existing zone data 40 res = isctest.query.tcp(msg, ns1.ip) 41 isctest.check.noerror(res) 42 43 ns1.stop() 44 45 # dump "_default.nzd" to "_default.nzf" and check that it contains the expected content 46 cfg_dir = "ns1" 47 cmd = isctest.run.cmd([os.environ["NZD2NZF"], "_default.nzd"], cwd=cfg_dir) 48 assert f"zone {zone_data}" in cmd.out 49 nzf_filename = os.path.join(cfg_dir, "_default.nzf") 50 with open(nzf_filename, "w", encoding="utf-8") as nzf_file: 51 nzf_file.write(cmd.out) 52 53 # delete "_default.nzd" database 54 nzd_filename = os.path.join(cfg_dir, "_default.nzd") 55 os.remove(nzd_filename) 56 57 # start ns1 again, it should migrate "_default.nzf" to "_default.nzd" 58 ns1.start(["--noclean", "--restart", "--port", os.environ["PORT"]]) 59 60 # query for zone data from the migrated zone config 61 res = isctest.query.tcp(msg, ns1.ip) 62 isctest.check.noerror(res) 63