Commit 805519d7 authored by Michal Vaner's avatar Michal Vaner
Browse files

Load zones from config knob

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac451@4045 e5f2f494-b856-4b98-b285-d166d9295462
parent fdc2c41b
......@@ -151,16 +151,15 @@ MemoryDatasourceConfig::build(ConstElementPtr config_value) {
isc_throw(AuthConfigError, "Missing zone file for zone: "
<< origin->str());
}
const result::Result result = memory_datasrc_->addZone(
ZonePtr(new MemoryZone(rrclass_, Name(origin->stringValue()))));
shared_ptr<MemoryZone> new_zone(new MemoryZone(rrclass_,
Name(origin->stringValue())));
const result::Result result = memory_datasrc_->addZone(new_zone);
if (result == result::EXIST) {
isc_throw(AuthConfigError, "zone "<< origin->str()
<< " already exists");
}
// TODO
// then load the zone from 'file', which is currently not implemented.
//
new_zone->load(file->stringValue());
}
}
......
......@@ -143,33 +143,42 @@ TEST_F(MemoryDatasrcConfigTest, addZeroZone) {
}
TEST_F(MemoryDatasrcConfigTest, addOneZone) {
parser->build(Element::fromJSON(
EXPECT_NO_THROW(parser->build(Element::fromJSON(
"[{\"type\": \"memory\","
" \"zones\": [{\"origin\": \"example.com\","
" \"file\": \"example.zone\"}]}]"));
parser->commit();
" \"file\": \"" TEST_DATA_DIR
"/example.zone\"}]}]")));
EXPECT_NO_THROW(parser->commit());
EXPECT_EQ(1, server.getMemoryDataSrc(rrclass)->getZoneCount());
// Check it actually loaded something
EXPECT_EQ(Zone::SUCCESS, server.getMemoryDataSrc(rrclass)->findZone(
Name("ns.example.com.")).zone->find(Name("ns.example.com."),
RRType::A()).code);
}
TEST_F(MemoryDatasrcConfigTest, addMultiZones) {
parser->build(Element::fromJSON(
EXPECT_NO_THROW(parser->build(Element::fromJSON(
"[{\"type\": \"memory\","
" \"zones\": [{\"origin\": \"example.com\","
" \"file\": \"example.zone\"},"
" \"file\": \"" TEST_DATA_DIR
"/example.zone\"},"
" {\"origin\": \"example.org\","
" \"file\": \"example.org.zone\"},"
" \"file\": \"" TEST_DATA_DIR
"/example.org.zone\"},"
" {\"origin\": \"example.net\","
" \"file\": \"example.net.zone\"}]}]"));
parser->commit();
" \"file\": \"" TEST_DATA_DIR
"/example.net.zone\"}]}]")));
EXPECT_NO_THROW(parser->commit());
EXPECT_EQ(3, server.getMemoryDataSrc(rrclass)->getZoneCount());
}
TEST_F(MemoryDatasrcConfigTest, replace) {
parser->build(Element::fromJSON(
EXPECT_NO_THROW(parser->build(Element::fromJSON(
"[{\"type\": \"memory\","
" \"zones\": [{\"origin\": \"example.com\","
" \"file\": \"example.zone\"}]}]"));
parser->commit();
" \"file\": \"" TEST_DATA_DIR
"/example.zone\"}]}]")));
EXPECT_NO_THROW(parser->commit());
EXPECT_EQ(1, server.getMemoryDataSrc(rrclass)->getZoneCount());
EXPECT_EQ(isc::datasrc::result::SUCCESS,
server.getMemoryDataSrc(rrclass)->findZone(
......@@ -179,13 +188,15 @@ TEST_F(MemoryDatasrcConfigTest, replace) {
// should replace the old one.
delete parser;
parser = createAuthConfigParser(server, "datasources");
parser->build(Element::fromJSON(
EXPECT_NO_THROW(parser->build(Element::fromJSON(
"[{\"type\": \"memory\","
" \"zones\": [{\"origin\": \"example.org\","
" \"file\": \"example.org.zone\"},"
" \"file\": \"" TEST_DATA_DIR
"/example.org.zone\"},"
" {\"origin\": \"example.net\","
" \"file\": \"example.net.zone\"}]}]"));
parser->commit();
" \"file\": \"" TEST_DATA_DIR
"/example.net.zone\"}]}]")));
EXPECT_NO_THROW(parser->commit());
EXPECT_EQ(2, server.getMemoryDataSrc(rrclass)->getZoneCount());
EXPECT_EQ(isc::datasrc::result::NOTFOUND,
server.getMemoryDataSrc(rrclass)->findZone(
......@@ -193,17 +204,18 @@ TEST_F(MemoryDatasrcConfigTest, replace) {
}
TEST_F(MemoryDatasrcConfigTest, remove) {
parser->build(Element::fromJSON(
EXPECT_NO_THROW(parser->build(Element::fromJSON(
"[{\"type\": \"memory\","
" \"zones\": [{\"origin\": \"example.com\","
" \"file\": \"example.zone\"}]}]"));
parser->commit();
" \"file\": \"" TEST_DATA_DIR
"/example.zone\"}]}]")));
EXPECT_NO_THROW(parser->commit());
EXPECT_EQ(1, server.getMemoryDataSrc(rrclass)->getZoneCount());
delete parser;
parser = createAuthConfigParser(server, "datasources");
parser->build(Element::fromJSON("[]"));
parser->commit();
EXPECT_NO_THROW(parser->build(Element::fromJSON("[]")));
EXPECT_NO_THROW(parser->commit());
EXPECT_EQ(AuthSrv::MemoryDataSrcPtr(), server.getMemoryDataSrc(rrclass));
}
......@@ -212,9 +224,11 @@ TEST_F(MemoryDatasrcConfigTest, adDuplicateZones) {
Element::fromJSON(
"[{\"type\": \"memory\","
" \"zones\": [{\"origin\": \"example.com\","
" \"file\": \"example.zone\"},"
" \"file\": \"" TEST_DATA_DIR
"/example.zone\"},"
" {\"origin\": \"example.com\","
" \"file\": \"example.com.zone\"}]}]")),
" \"file\": \"" TEST_DATA_DIR
"/example.com.zone\"}]}]")),
AuthConfigError);
}
......
......@@ -18,6 +18,7 @@ EXTRA_DIST += shortquestion_fromWire
EXTRA_DIST += shortresponse_fromWire
EXTRA_DIST += simplequery_fromWire.spec
EXTRA_DIST += simpleresponse_fromWire.spec
EXTRA_DIST += example.com.zone example.net.zone example.org.zone example.zone
EXTRA_DIST += example.com
EXTRA_DIST += example.sqlite3
......
example.com. 3600 IN SOA ns.example.com. admin.example.com. 1234 3600 1800 2419200 7200
example.com. 3600 IN NS ns.example.com.
ns.example.com. 3600 IN A 192.0.2.1
example.net. 3600 IN SOA ns.example.net. admin.example.net. 1234 3600 1800 2419200 7200
example.net. 3600 IN NS ns.example.net.
ns.example.net. 3600 IN A 192.0.2.1
example.org. 3600 IN SOA ns.example.org. admin.example.org. 1234 3600 1800 2419200 7200
example.org. 3600 IN NS ns.example.org.
ns.example.org. 3600 IN A 192.0.2.1
example.com. 3600 IN SOA ns.example.com. admin.example.com. 1234 3600 1800 2419200 7200
example.com. 3600 IN NS ns.example.com.
ns.example.com. 3600 IN A 192.0.2.1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment