Revision: 1166
Author:
J.S.P...@gmail.com
Date: Thu Aug 15 08:18:41 2013
Log: Adding option to supply view/zone options via a text file for
dnsmkzone and dnsmkview
http://code.google.com/p/roster-dns-management/source/detail?r=1166
Modified:
/trunk/roster-user-tools/roster_user_tools/data_flags.py
/trunk/roster-user-tools/scripts/dnsmkview
/trunk/roster-user-tools/scripts/dnsmkzone
/trunk/roster-user-tools/scripts/dnsrmview
/trunk/test/dnsmkview_test.py
/trunk/test/dnsmkzone_test.py
/trunk/test/dnsrmview_test.py
=======================================
--- /trunk/roster-user-tools/roster_user_tools/data_flags.py Thu Aug 15
08:06:22 2013
+++ /trunk/roster-user-tools/roster_user_tools/data_flags.py Thu Aug 15
08:18:41 2013
@@ -230,11 +230,19 @@
# List and Make
if( self.action != 'Remove' ):
self.parser.add_option('-o', '--options', action='store',
dest='options',
- help='String of extra zone/view options, '
- 'standard bind view clause syntax.',
- metavar='<view-options>', default=None)
+ help='String containing extra zone options, '
+ 'standard BIND zone clause syntax.',
+ metavar='<zone-options>', default=None)
self.AddFlagRule('options', command='forward', required=False)
self.AddFlagRule('options', command='reverse', required=False)
+
+ self.parser.add_option('-f', '--file', action='store',
dest='file_name',
+ help='Text file containing extra zone
options, '
+ 'standard BIND zone clause syntax.',
+ metavar='<file-name>', default=None)
+ self.AddFlagRule('file_name', command='forward', required=False)
+ self.AddFlagRule('file_name', command='reverse', required=False)
+
self.parser.add_option('--origin', action='store', dest='origin',
help='String of zone origin.',
metavar='<origin>',
default=None)
@@ -295,10 +303,17 @@
dest='view_subset', default=None,
help='String of view dependency.')
self.AddFlagRule('view_subset', required=not_list,
command='view_subset')
- self.parser.add_option('-o', '--options', action='store',
dest='options',
- help='View options.', metavar='<options>',
- default=None)
- self.AddFlagRule('options', required=False, command='dns_server_set')
+ if( self.action != 'Remove' ):
+ self.parser.add_option('-o', '--options', action='store',
dest='options',
+ help='String containing extra view options, '
+ 'standard BIND view clause syntax.',
+ metavar='<options>', default=None)
+ self.AddFlagRule('options', required=False, command='dns_server_set')
+ self.parser.add_option('-f', '--file-name', action='store',
dest='file_name',
+ help='Text file containing extra view
options, '
+ 'standard BIND view clause syntax.',
+ metavar='<file-name>', default=None)
+ self.AddFlagRule('file_name', required=False,
command='dns_server_set')
self.parser.add_option('-e', '--dns-server-set', action='store',
dest='dns_server_set', default=None,
help='String of dns server set name.')
=======================================
--- /trunk/roster-user-tools/scripts/dnsmkview Thu Jan 3 04:55:43 2013
+++ /trunk/roster-user-tools/scripts/dnsmkview Thu Aug 15 08:18:41 2013
@@ -84,6 +84,11 @@
except cli_common_lib.ArgumentError, error:
cli_common_lib.DnsError(str(error), 1)
+ if( options.file_name ):
+ file_handle = open(options.file_name, 'r')
+ options.options = file_handle.read().strip('\n')
+ file_handle.close()
+
views = roster_client_lib.RunFunction(
u'ListViews', options.username, credfile=options.credfile,
credstring=options.credstring, server_name=options.server,
=======================================
--- /trunk/roster-user-tools/scripts/dnsmkzone Thu Aug 15 08:06:22 2013
+++ /trunk/roster-user-tools/scripts/dnsmkzone Thu Aug 15 08:18:41 2013
@@ -83,6 +83,15 @@
if( options.origin and not options.origin.endswith('.') ):
cli_common_lib.DnsError('Zone origin must terminate with "."', 1)
+ if( options.options and options.file_name ):
+ cli_common_lib.DnsError('Cannot supply both the -o/--options and '
+ 'the -f/--file flag.', 1)
+
+ if( options.file_name ):
+ file_handle = open(options.file_name, 'r')
+ options.options = file_handle.read().strip('\n')
+ file_handle.close()
+
views = roster_client_lib.RunFunction(
u'ListViews', options.username, credfile=options.credfile,
credstring=options.credstring, kwargs={u'view_name':
options.view_name},
=======================================
--- /trunk/roster-user-tools/scripts/dnsrmview Sun Dec 23 19:12:56 2012
+++ /trunk/roster-user-tools/scripts/dnsrmview Thu Aug 15 08:18:41 2013
@@ -98,8 +98,7 @@
args=[options.view_name])
if( not options.quiet ):
- print 'REMOVED VIEW view_name: view_name: %s options %s' % (
- options.view_name, options.options)
+ print 'REMOVED VIEW view_name: view_name: %s' % options.view_name
elif( command == 'dns_server_set' ):
if( options.view_name not in views ):
=======================================
--- /trunk/test/dnsmkview_test.py Sun Dec 23 19:12:56 2012
+++ /trunk/test/dnsmkview_test.py Thu Aug 15 08:18:41 2013
@@ -63,6 +63,7 @@
CERTFILE=('test_data/dnsmgmt.cert.pem')
CREDFILE='%s/.dnscred' % os.getcwd()
EXEC='../roster-user-tools/scripts/dnsmkview'
+VIEW_OPTIONS_FILE = os.path.join(os.getcwd(), 'view_options.txt')
class options(object):
password = u'test'
@@ -124,6 +125,8 @@
def tearDown(self):
if( os.path.exists(CREDFILE) ):
os.remove(CREDFILE)
+ if( os.path.exists(VIEW_OPTIONS_FILE) ):
+ os.remove(VIEW_OPTIONS_FILE)
def testMakeView(self):
self.core_instance.MakeACL(u'acl1', u'
192.168.1.0/24')
@@ -221,6 +224,19 @@
'test_view dns_server_set: set1 view_order: 2 '
'view_options: None\n')
command.close()
+ self.core_instance.MakeDnsServerSet(u'set3')
+ open(VIEW_OPTIONS_FILE, 'w').write('recursion no;\n')
+ command = os.popen('python %s dns_server_set -v test_view -r 1 -e
set3 '
+ '--file-name=%s '
+ '-c %s -u %s -p %s '
+ '--config-file %s -s %s' % (
+ EXEC, VIEW_OPTIONS_FILE, CREDFILE, USERNAME,
+ self.password, USER_CONFIG, self.server_name))
+ self.assertEqual(command.read(),
+ 'ADDED DNS SERVER SET VIEW ASSIGNMENT: view_name: '
+ 'test_view dns_server_set: set3 view_order: 1 '
+ 'view_options: recursion no;\n')
+ command.close()
def testErrors(self):
self.core_instance.MakeDnsServerSet(u'set1')
=======================================
--- /trunk/test/dnsmkzone_test.py Thu Aug 15 08:06:22 2013
+++ /trunk/test/dnsmkzone_test.py Thu Aug 15 08:18:41 2013
@@ -63,6 +63,7 @@
CERTFILE=('test_data/dnsmgmt.cert.pem')
CREDFILE='%s/.dnscred' % os.getcwd()
EXEC='../roster-user-tools/scripts/dnsmkzone'
+ZONE_OPTIONS_FILE = 'zone_options.txt'
class options(object):
password = u'test'
@@ -127,6 +128,8 @@
def tearDown(self):
if( os.path.exists(CREDFILE) ):
os.remove(CREDFILE)
+ if( os.path.exists(ZONE_OPTIONS_FILE) ):
+ os.remove(ZONE_OPTIONS_FILE)
def testNoReverseRangeZoneAssignmentForMakeSlaveZone(self):
self.core_instance.MakeView(u'test_view')
@@ -233,13 +236,14 @@
'zone_origin': u'dept.univiersity.edu.'}}})
output = os.popen('python %s forward -z test_zone2 -v test_view
--origin '
'
dept2.univiersity.edu. --type master
--dont-make-any '
+ '--options="recursion no;\n" '
'-s %s -u %s -p %s --config-file %s' % (
EXEC, self.server_name, USERNAME,
PASSWORD, USER_CONFIG))
self.assertEqual(output.read(),
- 'ADDED FORWARD ZONE: zone_name: test_zone2
zone_type: '
- 'master zone_origin:
dept2.univiersity.edu. '
- 'zone_options: None view_name: test_view\n')
+ 'ADDED FORWARD ZONE: zone_name: test_zone2 zone_type: master '
+ 'zone_origin:
dept2.univiersity.edu. zone_options: recursion
no;\n '
+ 'view_name: test_view\n')
output.close()
self.assertEqual(self.core_instance.ListZones(),
{u'test_zone':
@@ -248,9 +252,34 @@
'zone_origin': u'dept.univiersity.edu.'}},
u'test_zone2':
{u'test_view':
- {'zone_type': u'master', 'zone_options': '',
+ {'zone_type': u'master', 'zone_options': u'recursion no;',
'zone_origin': u'dept2.univiersity.edu.'}}})
+ open(ZONE_OPTIONS_FILE, 'w').write('recursion no;\n')
+ output = os.popen('python %s forward -z test_zone3 -v test_view
--origin '
+ '
dept3.univiersity.edu. --type master
--dont-make-any '
+ '--file=%s -s %s -u %s -p %s --config-file %s' % (
+ EXEC, ZONE_OPTIONS_FILE, self.server_name,
USERNAME,
+ PASSWORD, USER_CONFIG))
+ self.assertEqual(output.read(),
+ 'ADDED FORWARD ZONE: zone_name: test_zone3
zone_type: '
+ 'master zone_origin:
dept3.univiersity.edu. '
+ 'zone_options: recursion no; view_name: test_view\n')
+ output.close()
+ self.assertEqual(self.core_instance.ListZones(),
+ {u'test_zone':
+ {u'test_view':
+ {'zone_type': u'master', 'zone_options': '',
+ 'zone_origin': u'dept.univiersity.edu.'}},
+ u'test_zone2':
+ {u'test_view':
+ {'zone_type': u'master', 'zone_options': u'recursion no;',
+ 'zone_origin': u'dept2.univiersity.edu.'}},
+ u'test_zone3':
+ {u'test_view':
+ {'zone_type': u'master', 'zone_options': u'recursion no;',
+ 'zone_origin': u'dept3.univiersity.edu.'}}})
+
def testMakeZoneWithViewAny(self):
self.core_instance.MakeView(u'any')
output = os.popen('python %s forward -v any -z test_zone --origin '
=======================================
--- /trunk/test/dnsrmview_test.py Sun Dec 23 19:12:56 2012
+++ /trunk/test/dnsrmview_test.py Thu Aug 15 08:18:41 2013
@@ -136,7 +136,7 @@
EXEC, CREDFILE, USERNAME, self.password,
USER_CONFIG,
self.server_name))
self.assertEqual(command.read(),
- 'REMOVED VIEW view_name: view_name: test_view options None\n')
+ 'REMOVED VIEW view_name: view_name: test_view\n')
command.close()
self.assertEqual(self.core_instance.ListViewToACLAssignments(), [])