Commit b41b7dc3 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[master] Merge branch 'trac1369'

parents 6bda5426 b7b90e50
......@@ -158,7 +158,7 @@ class MockDataSourceClient():
return (DataSourceClient.PARTIALMATCH, self)
raise ValueError('Unexpected input to mock client: bug in test case?')
def find(self, name, rrtype, target, options):
def find(self, name, rrtype, target=None, options=ZoneFinder.FIND_DEFAULT):
'''Mock ZoneFinder.find().
It returns the predefined SOA RRset to queries for SOA of the common
......@@ -1751,8 +1751,7 @@ class TestXFRSessionWithSQLite3(TestXfrinConnection):
def get_zone_serial(self):
result, finder = self.conn._datasrc_client.find_zone(TEST_ZONE_NAME)
self.assertEqual(DataSourceClient.SUCCESS, result)
result, soa = finder.find(TEST_ZONE_NAME, RRType.SOA(),
None, ZoneFinder.FIND_DEFAULT)
result, soa = finder.find(TEST_ZONE_NAME, RRType.SOA())
self.assertEqual(ZoneFinder.SUCCESS, result)
self.assertEqual(1, soa.get_rdata_count())
return get_soa_serial(soa.get_rdata()[0])
......@@ -1760,7 +1759,7 @@ class TestXFRSessionWithSQLite3(TestXfrinConnection):
def record_exist(self, name, type):
result, finder = self.conn._datasrc_client.find_zone(TEST_ZONE_NAME)
self.assertEqual(DataSourceClient.SUCCESS, result)
result, soa = finder.find(name, type, None, ZoneFinder.FIND_DEFAULT)
result, soa = finder.find(name, type)
return result == ZoneFinder.SUCCESS
def test_do_ixfrin_sqlite3(self):
......
......@@ -95,7 +95,7 @@ class MockDataSrcClient:
return (isc.datasrc.DataSourceClient.NOTFOUND, None)
return (isc.datasrc.DataSourceClient.SUCCESS, self)
def find(self, name, rrtype, target, options):
def find(self, name, rrtype, target=None, options=ZoneFinder.FIND_DEFAULT):
'''Mock ZoneFinder.find().
(At the moment) this method only handles query for type SOA.
......
......@@ -46,6 +46,7 @@ Return the RR class of the zone.\n\
// - Return type: use tuple instead of the dedicated FindResult type
// - NULL->None
// - exceptions
// - description of the 'target' parameter (must be None for now)
const char* const ZoneFinder_find_doc = "\
find(name, type, target=None, options=FIND_DEFAULT) -> (integer, RRset)\n\
\n\
......@@ -74,6 +75,7 @@ answer for the search key. Specifically,\n\
- If the target isn't None, all RRsets under the domain are inserted\n\
there and SUCCESS (or NXDOMAIN, in case of empty domain) is returned\n\
instead of normall processing. This is intended to handle ANY query.\n\
(Note: the Python version doesn't support this feature yet)\n\
\n\
Note: This behavior is controversial as we discussed in\n\
https://lists.isc.org/pipermail/bind10-dev/2011-January/001918.html We\n\
......@@ -105,8 +107,7 @@ internal error in the datasource.\n\
Parameters:\n\
name The domain name to be searched for.\n\
type The RR type to be searched for.\n\
target If target is not None, insert all RRs under the domain\n\
into it.\n\
target Must be None.\n\
options The search options.\n\
\n\
Return Value(s): A tuple of a result code (integer) and an RRset object\n\
......
......@@ -53,26 +53,29 @@ namespace isc_datasrc_internal {
PyObject* ZoneFinder_helper(ZoneFinder* finder, PyObject* args) {
if (finder == NULL) {
PyErr_SetString(getDataSourceException("Error"),
"Internal error in find() wrapper; finder object NULL");
"Internal error in find() wrapper; "
"finder object NULL");
return (NULL);
}
PyObject *name;
PyObject *rrtype;
PyObject *target;
int options_int;
if (PyArg_ParseTuple(args, "O!O!OI", &name_type, &name,
PyObject* name;
PyObject* rrtype;
PyObject* target = Py_None;
unsigned int options_int = ZoneFinder::FIND_DEFAULT;
if (PyArg_ParseTuple(args, "O!O!|OI", &name_type, &name,
&rrtype_type, &rrtype,
&target, &options_int)) {
try {
if (target != Py_None) {
PyErr_SetString(PyExc_TypeError,
"find(): target must be None in this version");
return (NULL);
}
ZoneFinder::FindOptions options =
static_cast<ZoneFinder::FindOptions>(options_int);
ZoneFinder::FindResult find_result(
finder->find(PyName_ToName(name),
PyRRType_ToRRType(rrtype),
NULL,
options
));
ZoneFinder::Result r = find_result.code;
const ZoneFinder::FindResult find_result(
finder->find(PyName_ToName(name), PyRRType_ToRRType(rrtype),
NULL, options));
const ZoneFinder::Result r = find_result.code;
isc::dns::ConstRRsetPtr rrsp = find_result.rrset;
if (rrsp) {
// Use N instead of O so the refcount isn't increased twice
......
......@@ -285,6 +285,24 @@ class DataSrcClient(unittest.TestCase):
self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
rrset.to_text())
# Check the optional parameters are optional
result, rrset = finder.find(isc.dns.Name("www.example.com"),
isc.dns.RRType.A())
self.assertEqual(finder.SUCCESS, result)
self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
rrset.to_text())
result, rrset = finder.find(isc.dns.Name("www.example.com"),
isc.dns.RRType.A(), None)
self.assertEqual(finder.SUCCESS, result)
self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
rrset.to_text())
# Invalid value for the "target"
self.assertRaises(TypeError, finder.find,
isc.dns.Name("www.example.com"),
isc.dns.RRType.A(), True)
result, rrset = finder.find(isc.dns.Name("www.sql1.example.com"),
isc.dns.RRType.A(),
None,
......@@ -385,6 +403,36 @@ class DataSrcUpdater(unittest.TestCase):
# can't construct directly
self.assertRaises(TypeError, isc.datasrc.ZoneUpdater)
def test_update_finder(self):
# Check basic behavior of updater's finder
dsc = isc.datasrc.DataSourceClient("sqlite3", WRITE_ZONE_DB_CONFIG)
updater = dsc.get_updater(isc.dns.Name("example.com"), False)
result, rrset = updater.find(isc.dns.Name("www.example.com"),
isc.dns.RRType.A(),
None,
ZoneFinder.FIND_DEFAULT)
self.assertEqual(ZoneFinder.SUCCESS, result)
self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
rrset.to_text())
# Omit optional parameters
result, rrset = updater.find(isc.dns.Name("www.example.com"),
isc.dns.RRType.A())
self.assertEqual(ZoneFinder.SUCCESS, result)
self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
rrset.to_text())
result, rrset = updater.find(isc.dns.Name("www.example.com"),
isc.dns.RRType.A(), None)
self.assertEqual(ZoneFinder.SUCCESS, result)
self.assertEqual("www.example.com. 3600 IN A 192.0.2.1\n",
rrset.to_text())
# Invalid value for 'target'
self.assertRaises(TypeError, updater.find,
isc.dns.Name("www.example.com"),
isc.dns.RRType.A(), 1)
def test_update_delete_commit(self):
dsc = isc.datasrc.DataSourceClient("sqlite3", WRITE_ZONE_DB_CONFIG)
......
......@@ -284,14 +284,12 @@ class NotifyOut:
format_zone_str(zone_name, zone_class))
return []
result, ns_rrset = finder.find(zone_name, RRType.NS(), None,
finder.FIND_DEFAULT)
result, ns_rrset = finder.find(zone_name, RRType.NS())
if result is not finder.SUCCESS or ns_rrset is None:
logger.warn(NOTIFY_OUT_ZONE_NO_NS,
format_zone_str(zone_name, zone_class))
return []
result, soa_rrset = finder.find(zone_name, RRType.SOA(), None,
finder.FIND_DEFAULT)
result, soa_rrset = finder.find(zone_name, RRType.SOA())
if result is not finder.SUCCESS or soa_rrset is None or \
soa_rrset.get_rdata_count() != 1:
logger.warn(NOTIFY_OUT_ZONE_BAD_SOA,
......@@ -304,13 +302,11 @@ class NotifyOut:
ns_name = Name(ns_rdata.to_text())
if soa_mname == ns_name:
continue
result, rrset = finder.find(ns_name, RRType.A(), None,
finder.FIND_DEFAULT)
result, rrset = finder.find(ns_name, RRType.A())
if result is finder.SUCCESS and rrset is not None:
addrs.extend([a.to_text() for a in rrset.get_rdata()])
result, rrset = finder.find(ns_name, RRType.AAAA(), None,
finder.FIND_DEFAULT)
result, rrset = finder.find(ns_name, RRType.AAAA())
if result is finder.SUCCESS and rrset is not None:
addrs.extend([aaaa.to_text() for aaaa in rrset.get_rdata()])
......@@ -504,8 +500,7 @@ class NotifyOut:
zone_name.to_text() + '/' +
zone_class.to_text() + ' not found')
result, soa_rrset = finder.find(zone_name, RRType.SOA(), None,
finder.FIND_DEFAULT)
result, soa_rrset = finder.find(zone_name, RRType.SOA())
if result is not finder.SUCCESS or soa_rrset is None or \
soa_rrset.get_rdata_count() != 1:
raise NotifyOutDataSourceError('_get_zone_soa: Zone ' +
......
Markdown is supported
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