BIND 10 trac2380, updated. 07a0de0905f93bea39de048b3db8ed2fe24ef0a9 [2380] clarified the expected range for log levels

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Dec 18 07:49:10 UTC 2012


The branch, trac2380 has been updated
       via  07a0de0905f93bea39de048b3db8ed2fe24ef0a9 (commit)
       via  437477418c413c8a56adcb59441984dd5399f8a5 (commit)
       via  ad24f3f000a06f18ee1dba28ea2b38f8512f2c82 (commit)
       via  fbd4c46f6c801a5a662d28e75ed3f5014c2ae112 (commit)
       via  d87cdaba29e56dd4b2f8db30749f04a66fa70d43 (commit)
       via  d1f88a92073bfe44db618ecf0b88a05c5dd79aa4 (commit)
       via  ed47bd72388da8de0ab5e92d44da12942ba49b35 (commit)
      from  2c49df942a07bdcdf335a5794e779a1fc0f870c5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 07a0de0905f93bea39de048b3db8ed2fe24ef0a9
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Dec 17 23:48:19 2012 -0800

    [2380] clarified the expected range for log levels

commit 437477418c413c8a56adcb59441984dd5399f8a5
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Dec 17 23:46:05 2012 -0800

    [2380] allow -c omittable.

commit ad24f3f000a06f18ee1dba28ea2b38f8512f2c82
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Dec 17 22:36:09 2012 -0800

    [2380] added final '\n' to progress report on succesful completion.

commit fbd4c46f6c801a5a662d28e75ed3f5014c2ae112
Merge: d87cdab 2c49df9
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Dec 17 22:21:43 2012 -0800

    [2380] Merge branch 'trac2380' of ssh://git.bind10.isc.org/var/bind10/git/bind10 into trac2380

commit d87cdaba29e56dd4b2f8db30749f04a66fa70d43
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Dec 17 21:03:49 2012 -0800

    [2380] also renamed load_iteration_limit to report_interval
    
    as it means what it's really meant, and less confusing regarding the
    previous commit.

commit d1f88a92073bfe44db618ecf0b88a05c5dd79aa4
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Dec 17 20:59:45 2012 -0800

    [2380] clarified the intent of load iteration setting

commit ed47bd72388da8de0ab5e92d44da12942ba49b35
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Mon Dec 17 20:46:28 2012 -0800

    [2380] showed the number of loaded RRs and loading time, best effort basis.

-----------------------------------------------------------------------

Summary of changes:
 doc/guide/bind10-guide.xml              |    2 +
 src/bin/loadzone/b10-loadzone.xml       |   44 ++++++++++++----------
 src/bin/loadzone/loadzone.py.in         |   62 +++++++++++++++++++++++--------
 src/bin/loadzone/loadzone_messages.mes  |   14 ++++++-
 src/bin/loadzone/tests/loadzone_test.py |   46 +++++++++++++----------
 5 files changed, 112 insertions(+), 56 deletions(-)

-----------------------------------------------------------------------
diff --git a/doc/guide/bind10-guide.xml b/doc/guide/bind10-guide.xml
index 72892d9..336cc9b 100644
--- a/doc/guide/bind10-guide.xml
+++ b/doc/guide/bind10-guide.xml
@@ -451,6 +451,8 @@ var/
           <para>Load desired zone file(s), for example:
             <screen>$ <userinput>b10-loadzone <replaceable>-c '{"database_file": "/usr/local/var/bind10/zone.sqlite3"}'</replaceable> <replaceable>your.zone.example.org</replaceable> <replaceable>your.zone.file</replaceable></userinput></screen>
           </para>
+	  (If you use the sqlite3 data source with the default DB
+	  file, you can omit the -c option).
         </listitem>
 
         <listitem>
diff --git a/src/bin/loadzone/b10-loadzone.xml b/src/bin/loadzone/b10-loadzone.xml
index 5174f44..d181503 100644
--- a/src/bin/loadzone/b10-loadzone.xml
+++ b/src/bin/loadzone/b10-loadzone.xml
@@ -44,11 +44,11 @@
   <refsynopsisdiv>
     <cmdsynopsis>
       <command>b10-loadzone</command>
+      <arg><option>-c <replaceable class="parameter">datasrc_config</replaceable></option></arg>
       <arg><option>-d <replaceable class="parameter">debug_level</replaceable></option></arg>
       <arg><option>-i <replaceable class="parameter">report_interval</replaceable></option></arg>
       <arg><option>-t <replaceable class="parameter">datasrc_type</replaceable></option></arg>
       <arg><option>-C <replaceable class="parameter">zone_class</replaceable></option></arg>
-      <arg choice="req">-c <replaceable class="parameter">datasrc_config</replaceable></arg>
       <arg choice="req">zone name</arg>
       <arg choice="req">zone file</arg>
     </cmdsynopsis>
@@ -110,6 +110,27 @@
     <title>ARGUMENTS</title>
 
     <variablelist>
+      <varlistentry>
+        <term>-c <replaceable class="parameter">datasrc_config</replaceable></term>
+        <listitem><para>
+          Specifies configuration of the data source in the JSON
+          format.  The configuration contents depend on the type of
+	  the data source, and that's the same as what would be
+	  specified for the BIND 10 servers (see the data source
+          configuration section of the BIND 10 guide).  For example,
+	  for an SQLite3 data source, it would look like
+	  '{"database_file": "path-to-sqlite3-db-file"}'.
+	  <note>
+	    <simpara>For SQLite3 data source with the default DB file,
+	      this option can be omitted; in other cases including
+	      for any other types of data sources when supported,
+	      this option is currently mandatory in practice.
+	      In a future version it will be possible to retrieve the
+	      configuration from the BIND 10 server configuration (if
+	      it exists).
+	  </simpara></note>
+        </para></listitem>
+      </varlistentry>
 
       <varlistentry>
         <term>-d <replaceable class="parameter">debug_level</replaceable> </term>
@@ -154,24 +175,6 @@
       </varlistentry>
 
       <varlistentry>
-        <term>-c <replaceable class="parameter">datasrc_config</replaceable></term>
-        <listitem><para>
-          Specifies configuration of the data source in the JSON
-          format.  The configuration contents depend on the type of
-	  the data source, and that's the same as what would be
-	  specified for the BIND 10 servers (see the data source
-          configuration section of the BIND 10 guide).  For example,
-	  for an SQLite3 data source, it would look like
-	  '{"database_file": "path-to-sqlite3-db-file"}'.
-	  <note>
-	    <simpara>This option currently cannot be omitted.  In a future
-              version it will be possible to retrieve the configuration from
-              the BIND 10 server configuration (if it exists).
-	  </simpara></note>
-        </para></listitem>
-      </varlistentry>
-
-      <varlistentry>
         <term><replaceable class="parameter">zone name</replaceable></term>
         <listitem><para>
           The name of the zone to create or update.  This must be a valid DNS
@@ -233,7 +236,8 @@
       responsibility to fix the errors and reload it.  When the
       library is updated with the post load checks, it will be more
       sophisticated and the such zone won't be successfully loaded.
-
+    </para>
+    <para>
       There are some other issues noted in the DESCRIPTION section.
     </para>
   </refsect1>
diff --git a/src/bin/loadzone/loadzone.py.in b/src/bin/loadzone/loadzone.py.in
index 5b8f69d..525ff31 100755
--- a/src/bin/loadzone/loadzone.py.in
+++ b/src/bin/loadzone/loadzone.py.in
@@ -56,13 +56,12 @@ def set_cmd_options(parser):
 
     '''
     parser.add_option("-c", "--datasrc-conf", dest="conf", action="store",
-                      help="""(Mandatory) configuration of datasrc to load
-the zone in.  Example:
-'{"database_file": "/path/to/dbfile/db.sqlite3"}'""",
+                      help="""configuration of datasrc to load the zone in.
+Example: '{"database_file": "/path/to/dbfile/db.sqlite3"}'""",
                       metavar='CONFIG')
     parser.add_option("-d", "--debug", dest="debug_level",
                       type='int', action="store", default=None,
-                      help="enable debug logs with the specified level")
+                      help="enable debug logs with the specified level [0-99]")
     parser.add_option("-i", "--report-interval", dest="report_interval",
                       type='int', action="store",
                       default=LOAD_INTERVAL_DEFAULT,
@@ -110,7 +109,7 @@ class LoadZoneRunner:
         self._datasrc_type = None
         self._log_severity = 'INFO'
         self._log_debuglevel = 0
-        self._load_iteration_limit = LOAD_INTERVAL_DEFAULT
+        self._report_interval = LOAD_INTERVAL_DEFAULT
 
         self._config_log()
 
@@ -149,10 +148,10 @@ class LoadZoneRunner:
                     self._log_debuglevel)
         self._config_log()
 
-        if options.conf is None:
-            raise BadArgument('data source config option cannot be omitted')
-        self._datasrc_config = options.conf
         self._datasrc_type = options.datasrc_type
+        self._datasrc_config = options.conf
+        if options.conf is None:
+            self._datasrc_config = self._get_datasrc_config(self._datasrc_type)
         try:
             self._zone_class = RRClass(options.zone_class)
         except isc.dns.InvalidRRClass as ex:
@@ -161,11 +160,11 @@ class LoadZoneRunner:
             raise BadArgument("RR class is not supported: " +
                               str(self._zone_class))
 
-        self._load_iteration_limit = int(options.report_interval)
-        if self._load_iteration_limit < 0:
+        self._report_interval = int(options.report_interval)
+        if self._report_interval < 0:
             raise BadArgument(
                 'Invalid report interval (must be non negative): %d' %
-                self._load_iteration_limit)
+                self._report_interval)
 
         if len(args) != 2:
             raise BadArgument('Unexpected number of arguments: %d (must be 2)'
@@ -177,6 +176,27 @@ class LoadZoneRunner:
                               str(ex))
         self._zone_file = args[1]
 
+    def _get_datasrc_config(self, datasrc_type):
+        ''''Return the default data source configuration of given type.
+
+        Right now, it only supports SQLite3, and hardcodes the syntax
+        of the default configuration.  It's a kind of workaround to balance
+        convenience of users and minimizing hardcoding of data source
+        specific logic in the entire tool.  In future this should be
+        more sophisticated.
+
+        This is essentially a private helper method for _parse_arg(),
+        but defined as "protected" so tests can use it directly.
+
+        '''
+        if datasrc_type != 'sqlite3':
+            raise BadArgument('default config is not available for ' +
+                              datasrc_type)
+
+        default_db_file = bind10_config.DATA_PATH + '/zone.sqlite3'
+        logger.info(LOADZONE_SQLITE3_USING_DEFAULT_CONFIG, default_db_file)
+        return '{"database_file": "' + default_db_file + '"}'
+
     def __cancel_create(self):
         '''sqlite3-only hack: delete the zone just created on load failure.
 
@@ -228,17 +248,25 @@ class LoadZoneRunner:
             loader = ZoneLoader(datasrc_client, self._zone_name,
                                 self._zone_file)
             self.__start_time = time.time()
-            if self._load_iteration_limit > 0:
-                limit = self._load_iteration_limit
+            if self._report_interval > 0:
+                limit = self._report_interval
             else:
+                # Even if progress report is suppressed, we still load
+                # incrementally so we won't delay catching signals too long.
                 limit = LOAD_INTERVAL_DEFAULT
             while (not self.__interrupted and
                    not loader.load_incremental(limit)):
-                self.__loaded_rrs += self._load_iteration_limit
-                if self._load_iteration_limit > 0:
+                self.__loaded_rrs += self._report_interval
+                if self._report_interval > 0:
                     self._report_progress(self.__loaded_rrs)
             if self.__interrupted:
                 raise LoadFailure('loading interrupted by signal')
+
+            # On successfully completion, add final '\n' to the progress
+            # report output (on failure don't bother to make it prettier).
+            if (self._report_interval > 0 and
+                self.__loaded_rrs >= self._report_interval):
+                sys.stdout.write('\n')
         except Exception as ex:
             # release any remaining lock held in the client/loader
             loader, datasrc_client = None, None
@@ -284,7 +312,9 @@ class LoadZoneRunner:
             self._set_signal_handlers()
             self._parse_args()
             self._do_load()
-            logger.info(LOADZONE_DONE, self._zone_name, self._zone_class)
+            total_elapsed_txt = "%.2f" % (time.time() - self.__start_time)
+            logger.info(LOADZONE_DONE, self.__loaded_rrs, self._zone_name,
+                        self._zone_class, total_elapsed_txt)
             self._post_load_checks()
             return 0
         except BadArgument as ex:
diff --git a/src/bin/loadzone/loadzone_messages.mes b/src/bin/loadzone/loadzone_messages.mes
index 3cbd6fd..8680079 100644
--- a/src/bin/loadzone/loadzone_messages.mes
+++ b/src/bin/loadzone/loadzone_messages.mes
@@ -27,9 +27,16 @@ LOADZONE_ZONE_CREATED), but the loading operation has subsequently
 failed.  The newly created zone has been removed from the data source,
 so that the data source will go back to the original state.
 
-% LOADZONE_DONE Load zone %1/%2 completed
+% LOADZONE_DONE Loadded (at least) %1 RRs into zone %2/%3 in %4 seconds
 b10-loadzone has successfully loaded the specified zone.  If there was
 an old version of the zone in the data source, it is now deleted.
+It also prints (a lower bound of) the number of RRs that have been loaded
+and the time spent for the loading.  Due to a limitation of the
+current implementation of the underlying library however, it cannot show the
+exact number of the loaded RRs; it's counted for every N-th RR where N
+is the value of the -i command line option.  So, for smaller zones that
+don't even contain N RRs, the reported value will be 0.  This will be
+improved in a future version.
 
 % LOADZONE_LOAD_ERROR Failed to load zone %1/%2: %3
 Loading a zone by b10-loadzone fails for some reason in the middle of
@@ -58,3 +65,8 @@ have been cleanly canceled in this case, too.
 The specified zone to b10-loadzone to load does not exist in the
 specified data source.  b10-loadzone has created a new empty zone
 in the data source.
+
+% LOADZONE_SQLITE3_USING_DEFAULT_CONFIG Using default configuration with SQLite3 DB file %1
+The SQLite3 data source is specified as the data source type without a
+data source configuration.  b10-loadzone uses the default
+configuration with the default DB file for the BIND 10 system.
diff --git a/src/bin/loadzone/tests/loadzone_test.py b/src/bin/loadzone/tests/loadzone_test.py
index c9e258c..4f13c5d 100755
--- a/src/bin/loadzone/tests/loadzone_test.py
+++ b/src/bin/loadzone/tests/loadzone_test.py
@@ -20,6 +20,7 @@ from loadzone import *
 from isc.dns import *
 from isc.datasrc import *
 import isc.log
+import bind10_config
 import os
 import shutil
 
@@ -67,7 +68,7 @@ class TestLoadZoneRunner(unittest.TestCase):
         self.assertIsNone(self.__runner._zone_file)
         self.assertIsNone(self.__runner._datasrc_config)
         self.assertIsNone(self.__runner._datasrc_type)
-        self.assertEqual(10000, self.__runner._load_iteration_limit)
+        self.assertEqual(10000, self.__runner._report_interval)
         self.assertEqual('INFO', self.__runner._log_severity)
         self.assertEqual(0, self.__runner._log_debuglevel)
 
@@ -77,7 +78,7 @@ class TestLoadZoneRunner(unittest.TestCase):
         self.assertEqual(NEW_ZONE_TXT_FILE, self.__runner._zone_file)
         self.assertEqual(DATASRC_CONFIG, self.__runner._datasrc_config)
         self.assertEqual('sqlite3', self.__runner._datasrc_type) # default
-        self.assertEqual(10000, self.__runner._load_iteration_limit) # default
+        self.assertEqual(10000, self.__runner._report_interval) # default
         self.assertEqual(RRClass.IN(), self.__runner._zone_class) # default
         self.assertEqual('INFO', self.__runner._log_severity) # default
         self.assertEqual(0, self.__runner._log_debuglevel)
@@ -89,36 +90,28 @@ class TestLoadZoneRunner(unittest.TestCase):
         self.assertEqual(1, runner._log_debuglevel)
 
     def test_parse_bad_args(self):
-        # -c cannot be omitted (right now)
-        self.assertRaises(BadArgument,
-                          LoadZoneRunner(['example', 'example.zone']).
-                          _parse_args)
-
-        copt = ['-c', '0']      # template for the mandatory -c option
-
         # There must be exactly 2 non-option arguments: zone name and zone file
-        self.assertRaises(BadArgument, LoadZoneRunner(copt)._parse_args)
-        self.assertRaises(BadArgument, LoadZoneRunner(copt + ['example']).
+        self.assertRaises(BadArgument, LoadZoneRunner([])._parse_args)
+        self.assertRaises(BadArgument, LoadZoneRunner(['example']).
                           _parse_args)
         self.assertRaises(BadArgument, LoadZoneRunner(self.__args + ['0']).
                           _parse_args)
 
         # Bad zone name
+        args = ['example.org', 'example.zone'] # otherwise valid args
         self.assertRaises(BadArgument,
-                          LoadZoneRunner(copt + ['bad..name', 'example.zone']).
+                          LoadZoneRunner(['bad..name', 'example.zone'] + args).
                           _parse_args)
 
         # Bad class name
         self.assertRaises(BadArgument,
-                          LoadZoneRunner(copt + ['-C', 'badclass']).
+                          LoadZoneRunner(['-C', 'badclass'] + args).
                           _parse_args)
         # Unsupported class
         self.assertRaises(BadArgument,
-                          LoadZoneRunner(copt + ['-C', 'CH']).
-                          _parse_args)
+                          LoadZoneRunner(['-C', 'CH'] + args)._parse_args)
 
         # bad debug level
-        args = copt + ['example.org', 'example.zone'] # otherwise valid args
         self.assertRaises(BadArgument,
                           LoadZoneRunner(['-d', '-10'] + args)._parse_args)
 
@@ -126,13 +119,28 @@ class TestLoadZoneRunner(unittest.TestCase):
         self.assertRaises(BadArgument,
                           LoadZoneRunner(['-i', '-5'] + args)._parse_args)
 
+        # -c cannot be omitted unless it's type sqlite3 (right now)
+        self.assertRaises(BadArgument,
+                          LoadZoneRunner(['-t', 'memory'] + args)._parse_args)
+
+    def test_get_datasrc_config(self):
+        # For sqlite3, we use the config with the well-known DB file.
+        expected_conf = \
+            '{"database_file": "' + bind10_config.DATA_PATH + '/zone.sqlite3"}'
+        self.assertEqual(expected_conf,
+                         self.__runner._get_datasrc_config('sqlite3'))
+
+        # For other types, config must be given by hand for now
+        self.assertRaises(BadArgument, self.__runner._get_datasrc_config,
+                          'memory')
+
     def __common_load_setup(self):
         self.__runner._zone_class = RRClass.IN()
         self.__runner._zone_name = TEST_ZONE_NAME
         self.__runner._zone_file = NEW_ZONE_TXT_FILE
         self.__runner._datasrc_type = 'sqlite3'
         self.__runner._datasrc_config = DATASRC_CONFIG
-        self.__runner._load_iteration_limit = 1
+        self.__runner._report_interval = 1
         self.__reports = []
         self.__runner._report_progress = lambda x: self.__reports.append(x)
 
@@ -171,14 +179,14 @@ class TestLoadZoneRunner(unittest.TestCase):
     def test_load_update_skipped_report(self):
         '''successful loading, with reports for every 2 RRs'''
         self.__common_load_setup()
-        self.__runner._load_iteration_limit = 2
+        self.__runner._report_interval = 2
         self.__runner._do_load()
         self.assertEqual([2], self.__reports)
 
     def test_load_update_no_report(self):
         '''successful loading, without progress reports'''
         self.__common_load_setup()
-        self.__runner._load_iteration_limit = 0
+        self.__runner._report_interval = 0
         self.__runner._do_load()
         self.assertEqual([], self.__reports) # no report
         self.__check_zone_soa(NEW_SOA_TXT)   # but load is completed



More information about the bind10-changes mailing list