Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
5f923b7b
Commit
5f923b7b
authored
Dec 13, 2012
by
JINMEI Tatuya
Browse files
[2380] catch some invalid command line arguments, and log setups
parent
e7f01efd
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/bin/loadzone/Makefile.am
View file @
5f923b7b
...
...
@@ -5,13 +5,18 @@ bin_SCRIPTS = b10-loadzone
bin_SCRIPTS
+=
b10-loadzone-ng
noinst_SCRIPTS
=
run_loadzone.sh
nodist_pylogmessage_PYTHON
=
$(PYTHON_LOGMSGPKG_DIR)
/work/loadzone_messages.py
pylogmessagedir
=
$(pyexecdir)
/isc/log_messages/
CLEANFILES
=
b10-loadzone
# tentative setup: clean this up:
CLEANFILES
+=
b10-loadzone-ng
CLEANFILES
+=
$(PYTHON_LOGMSGPKG_DIR)
/work/loadzone_messages.py
CLEANFILES
+=
$(PYTHON_LOGMSGPKG_DIR)
/work/loadzone_messages.pyc
man_MANS
=
b10-loadzone.8
DISTCLEANFILES
=
$(man_MANS)
EXTRA_DIST
=
$(man_MANS)
b10-loadzone.xml
EXTRA_DIST
=
$(man_MANS)
b10-loadzone.xml
loadzone_messages.mes
if
GENERATE_DOCS
...
...
@@ -26,6 +31,11 @@ $(man_MANS):
endif
# Define rule to build logging source files from message file
$(PYTHON_LOGMSGPKG_DIR)/work/loadzone_messages.py
:
loadzone_messages.mes
$(top_builddir)
/src/lib/log/compiler/message
\
-d
$(PYTHON_LOGMSGPKG_DIR)
/work
-p
$(srcdir)
/loadzone_messages.mes
b10-loadzone
:
b10-loadzone.py
$(SED)
-e
"s|@@PYTHONPATH@@|@pyexecdir@|"
\
-e
"s|@@LOCALSTATEDIR@@|
$(localstatedir)
|"
\
...
...
@@ -33,7 +43,7 @@ b10-loadzone: b10-loadzone.py
chmod
a+x
$@
# tentatively named "-ng".
b10-loadzone-ng
:
loadzone.py
b10-loadzone-ng
:
loadzone.py
$(PYTHON_LOGMSGPKG_DIR)/work/loadzone_messages.py
$(SED)
-e
"s|@@PYTHONPATH@@|@pyexecdir@|"
loadzone.py
>
$@
chmod
a+x
$@
...
...
src/bin/loadzone/loadzone.py.in
View file @
5f923b7b
...
...
@@ -18,11 +18,19 @@
import sys
sys.path.append('@@PYTHONPATH@@')
from optparse import OptionParser
from isc.dns import *
import isc.log
from isc.log_messages.loadzone_messages import *
isc.log.init("b10-loadzone", buffer=
Tru
e)
isc.log.init("b10-loadzone", buffer=
Fals
e)
logger = isc.log.Logger("loadzone")
class BadArgument(Exception):
'''An exception indicating an error in command line argument.
'''
pass
def set_cmd_options(parser):
'''Helper function to set command-line options.
...
...
@@ -35,13 +43,32 @@ class LoadZoneRunner:
'''
def __init__(self, command_args):
self.__command_args = command_args
# These are essentially private, and defined as "protected" for the
# convenience of tests inspecting them
self._zone_class = None
self._zone_name = None
def _parse_args(self):
usage_txt = 'usage: %prog [options] zonename zonefile'
parser = OptionParser(usage=usage_txt)
set_cmd_options(parser)
(options, args) = parser.parse_args(args=command_args)
(options, args) = parser.parse_args(args=self.__command_args)
if len(args) != 2:
raise BadArgument('Unexpected number of arguments: %d (must be 2)'
% (len(args)))
try:
self._zone_name = Name(args[0])
except Exception as ex: # too broad, but there's no better granurality
raise BadArgument("Invalid zone name '" + args[0] + "': " +
str(ex))
def run(self):
pass
try:
self._parse_args()
except BadArgument as ex:
logger.error(LOADZONE_ARGUMENT_ERROR, ex)
if '__main__' == __name__:
runner = LoadZoneRunner(sys.argv[1:])
...
...
src/bin/loadzone/loadzone_messages.mes
0 → 100644
View file @
5f923b7b
# Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# When you add a message to this file, it is a good idea to run
# <topsrcdir>/tools/reorder_message_file.py to make sure the
# messages are in the correct order.
% LOADZONE_ARGUMENT_ERROR Error in command line arguments: %1
src/bin/loadzone/tests/loadzone_test.py
View file @
5f923b7b
...
...
@@ -17,21 +17,43 @@
import
unittest
from
loadzone
import
*
from
isc.dns
import
*
import
isc.log
TEST_ZONE_NAME
=
Name
(
'example.org'
)
class
TestLoadZoneRunner
(
unittest
.
TestCase
):
def
setUp
(
self
):
pass
# default command line arguments
self
.
__args
=
[
'example.org'
,
'example.zone'
]
self
.
__runner
=
LoadZoneRunner
(
self
.
__args
)
def
tearDown
(
self
):
pass
def
test_
dummy
(
self
):
def
test_
init
(
self
):
'''
Test the old socket file is removed (if any) and a new socket
is created when the ddns server is created.
'''
runner
=
LoadZoneRunner
([
'-h'
,
'example.org'
,
'example.zone'
])
self
.
assertIsNone
(
self
.
__runner
.
_zone_class
)
self
.
assertIsNone
(
self
.
__runner
.
_zone_name
)
def
test_parse_args
(
self
):
self
.
__runner
.
_parse_args
()
self
.
assertEqual
(
TEST_ZONE_NAME
,
self
.
__runner
.
_zone_name
)
def
test_parse_bad_args
(
self
):
# There must be exactly 2 non-option arguments: zone name and zone file
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
self
.
assertRaises
(
BadArgument
,
LoadZoneRunner
([
'bad..name'
,
'example.zone'
]).
_parse_args
)
if
__name__
==
"__main__"
:
isc
.
log
.
resetUnitTestRootLogger
()
...
...
src/lib/python/isc/log_messages/Makefile.am
View file @
5f923b7b
...
...
@@ -14,6 +14,7 @@ EXTRA_DIST += config_messages.py
EXTRA_DIST
+=
notify_out_messages.py
EXTRA_DIST
+=
libddns_messages.py
EXTRA_DIST
+=
libxfrin_messages.py
EXTRA_DIST
+=
loadzone_messages.py
EXTRA_DIST
+=
server_common_messages.py
EXTRA_DIST
+=
dbutil_messages.py
...
...
@@ -31,6 +32,7 @@ CLEANFILES += config_messages.pyc
CLEANFILES
+=
notify_out_messages.pyc
CLEANFILES
+=
libddns_messages.pyc
CLEANFILES
+=
libxfrin_messages.pyc
CLEANFILES
+=
loadzone_messages.pyc
CLEANFILES
+=
server_common_messages.pyc
CLEANFILES
+=
dbutil_messages.pyc
...
...
src/lib/python/isc/log_messages/loadzone_messages.py
0 → 100644
View file @
5f923b7b
from
work.loadzone_messages
import
*
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment