BIND 10 master, updated. 464682a2180c672f1ed12d8a56fd0a5ab3eb96ed Merge branch 'master' into trac1828
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jun 18 10:05:24 UTC 2012
The branch, master has been updated
via 464682a2180c672f1ed12d8a56fd0a5ab3eb96ed (commit)
via e295b40a31dedb3671705ab44c2683624f3d541c (commit)
via c37cc2d18c1b4b99432d0436603631a99377a0e6 (commit)
via c4b20d7ad5fce1557edfb53bfab66c26e1933d20 (commit)
via 6ad0070daba5438c84dd869afe260538bae2c55e (commit)
via 1fff16e186c477efe4c179c034849f97af6e3f33 (commit)
via 74b4b2f998f9512b2a326e81062da9099d1eeaf4 (commit)
via ff9dd7da0902101332312526c4b52d11f18650ba (commit)
via 8e741d81178c34d688f1c9cc3fecf15ac82c5f2c (commit)
via 7d741f7ea2ddc3ab22e37b12132b7e029e6da573 (commit)
via d295c9ec3b875e61d4453d69a569ffeabf132a69 (commit)
via 74dbc765acd11e59d8a144033e9202349a03157f (commit)
via 9040c49022e84e7b1398e84a14abd54f8d99ec8c (commit)
via bbeee5330ca6f6619b371b11ce8e54b705abc4ed (commit)
via 86b4a931b5857952c7036fb3c043b59d015269b0 (commit)
via 57449046356fda9a21f3cf2dc1e5faadaaf42d7c (commit)
via d96e91d14a55046b741dbc49eaa1b5fac5efc8d0 (commit)
via 3dd46b79138e68f3054430ae9f37a38a80ba0913 (commit)
via 1ece2eadd41752ca89bc9c6932942b9c39dc91ac (commit)
via 933d2b6f17ab8a634f392e94747074d2515fceb0 (commit)
via aef9cc2d584e6eda16792f126a6c018e61fd5d5e (commit)
via 6725498ecb8a8305608fd826116cfa09ac81a1bd (commit)
via 542d531257cec2b7368d5cde0fdfb7a5595aff8f (commit)
via fdb3dfbe8b71bb9a4d5414f7feb3307a8fd1cda6 (commit)
via eae421b4814a766ff14199a72e489768287654db (commit)
via a9d5033669d79cf4b786d471112b312977642fe5 (commit)
from 479e328c6685788093ff7fdece472629f863fd39 (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 464682a2180c672f1ed12d8a56fd0a5ab3eb96ed
Merge: e295b40 479e328
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jun 18 15:01:14 2012 +0530
Merge branch 'master' into trac1828
Conflicts:
src/bin/ddns/tests/ddns_test.py
src/bin/zonemgr/tests/zonemgr_test.py
-----------------------------------------------------------------------
Summary of changes:
src/bin/bind10/tests/bind10_test.py.in | 24 +++-
src/bin/bindctl/tests/bindctl_test.py | 30 ++---
src/bin/cmdctl/tests/cmdctl_test.py | 5 +
src/bin/ddns/ddns.py.in | 7 +-
src/bin/ddns/tests/ddns_test.py | 7 ++
src/bin/msgq/msgq.py.in | 1 +
src/bin/msgq/tests/msgq_test.py | 12 ++
src/bin/tests/process_rename_test.py.in | 7 +-
src/bin/xfrin/tests/xfrin_test.py | 3 +-
src/bin/xfrout/tests/xfrout_test.py.in | 41 +++----
src/bin/xfrout/xfrout.py.in | 13 ++-
src/bin/zonemgr/zonemgr.py.in | 2 +
src/lib/dns/python/tests/testutil.py | 16 +--
.../python/isc/bind10/tests/sockcreator_test.py | 17 ++-
.../python/isc/config/tests/module_spec_test.py | 16 +--
.../isc/util/cio/tests/socketsession_test.py | 122 ++++++++++----------
16 files changed, 191 insertions(+), 132 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in
index 3b80fb5..6ed7411 100644
--- a/src/bin/bind10/tests/bind10_test.py.in
+++ b/src/bin/bind10/tests/bind10_test.py.in
@@ -1055,22 +1055,29 @@ class TestPIDFile(unittest.TestCase):
# dump PID to the file, and confirm the content is correct
dump_pid(self.pid_file)
my_pid = os.getpid()
- self.assertEqual(my_pid, int(open(self.pid_file, "r").read()))
+ with open(self.pid_file, "r") as f:
+ self.assertEqual(my_pid, int(f.read()))
def test_dump_pid(self):
self.check_pid_file()
# make sure any existing content will be removed
- open(self.pid_file, "w").write('dummy data\n')
+ with open(self.pid_file, "w") as f:
+ f.write('dummy data\n')
self.check_pid_file()
def test_unlink_pid_file_notexist(self):
dummy_data = 'dummy_data\n'
- open(self.pid_file, "w").write(dummy_data)
+
+ with open(self.pid_file, "w") as f:
+ f.write(dummy_data)
+
unlink_pid_file("no_such_pid_file")
+
# the file specified for unlink_pid_file doesn't exist,
# and the original content of the file should be intact.
- self.assertEqual(dummy_data, open(self.pid_file, "r").read())
+ with open(self.pid_file, "r") as f:
+ self.assertEqual(dummy_data, f.read())
def test_dump_pid_with_none(self):
# Check the behavior of dump_pid() and unlink_pid_file() with None.
@@ -1079,9 +1086,14 @@ class TestPIDFile(unittest.TestCase):
self.assertFalse(os.path.exists(self.pid_file))
dummy_data = 'dummy_data\n'
- open(self.pid_file, "w").write(dummy_data)
+
+ with open(self.pid_file, "w") as f:
+ f.write(dummy_data)
+
unlink_pid_file(None)
- self.assertEqual(dummy_data, open(self.pid_file, "r").read())
+
+ with open(self.pid_file, "r") as f:
+ self.assertEqual(dummy_data, f.read())
def test_dump_pid_failure(self):
# the attempt to open file will fail, which should result in exception.
diff --git a/src/bin/bindctl/tests/bindctl_test.py b/src/bin/bindctl/tests/bindctl_test.py
index 1ddb916..bcfb6c5 100644
--- a/src/bin/bindctl/tests/bindctl_test.py
+++ b/src/bin/bindctl/tests/bindctl_test.py
@@ -425,6 +425,12 @@ class FakeBindCmdInterpreter(bindcmd.BindCmdInterpreter):
class TestBindCmdInterpreter(unittest.TestCase):
+ def setUp(self):
+ self.old_stdout = sys.stdout
+
+ def tearDown(self):
+ sys.stdout = self.old_stdout
+
def _create_invalid_csv_file(self, csvfilename):
import csv
csvfile = open(csvfilename, 'w')
@@ -447,19 +453,17 @@ class TestBindCmdInterpreter(unittest.TestCase):
self.assertEqual(new_csv_dir, custom_cmd.csv_file_dir)
def test_get_saved_user_info(self):
- old_stdout = sys.stdout
- sys.stdout = open(os.devnull, 'w')
- cmd = bindcmd.BindCmdInterpreter()
- users = cmd._get_saved_user_info('/notexist', 'csv_file.csv')
- self.assertEqual([], users)
-
- csvfilename = 'csv_file.csv'
- self._create_invalid_csv_file(csvfilename)
- users = cmd._get_saved_user_info('./', csvfilename)
- self.assertEqual([], users)
- os.remove(csvfilename)
- sys.stdout = old_stdout
-
+ with open(os.devnull, 'w') as f:
+ sys.stdout = f
+ cmd = bindcmd.BindCmdInterpreter()
+ users = cmd._get_saved_user_info('/notexist', 'csv_file.csv')
+ self.assertEqual([], users)
+
+ csvfilename = 'csv_file.csv'
+ self._create_invalid_csv_file(csvfilename)
+ users = cmd._get_saved_user_info('./', csvfilename)
+ self.assertEqual([], users)
+ os.remove(csvfilename)
class TestCommandLineOptions(unittest.TestCase):
def setUp(self):
diff --git a/src/bin/cmdctl/tests/cmdctl_test.py b/src/bin/cmdctl/tests/cmdctl_test.py
index 5fdabb4..856adf1 100644
--- a/src/bin/cmdctl/tests/cmdctl_test.py
+++ b/src/bin/cmdctl/tests/cmdctl_test.py
@@ -84,6 +84,7 @@ class TestSecureHTTPRequestHandler(unittest.TestCase):
self.handler.rfile = open("check.tmp", 'w+b')
def tearDown(self):
+ sys.stdout.close()
sys.stdout = self.old_stdout
self.handler.rfile.close()
os.remove('check.tmp')
@@ -306,6 +307,7 @@ class TestCommandControl(unittest.TestCase):
self.cmdctl = MyCommandControl(None, True)
def tearDown(self):
+ sys.stdout.close()
sys.stdout = self.old_stdout
def _check_config(self, cmdctl):
@@ -427,6 +429,9 @@ class TestSecureHTTPServer(unittest.TestCase):
MyCommandControl, verbose=True)
def tearDown(self):
+ # both sys.stdout and sys.stderr are the same, so closing one is
+ # sufficient
+ sys.stdout.close()
sys.stdout = self.old_stdout
sys.stderr = self.old_stderr
diff --git a/src/bin/ddns/ddns.py.in b/src/bin/ddns/ddns.py.in
index 76ffca0..8ddd2da 100755
--- a/src/bin/ddns/ddns.py.in
+++ b/src/bin/ddns/ddns.py.in
@@ -378,10 +378,13 @@ class DDNSServer:
Perform any cleanup that is necessary when shutting down the server.
Do NOT call this to initialize shutdown, use trigger_shutdown().
- Currently, it only causes the ModuleCCSession to send a message that
- this module is stopping.
'''
+ # tell the ModuleCCSession to send a message that this module is
+ # stopping.
self._cc.send_stopping()
+ # make sure any open socket is explicitly closed, per Python
+ # convention.
+ self._listen_socket.close()
def accept(self):
"""
diff --git a/src/bin/ddns/tests/ddns_test.py b/src/bin/ddns/tests/ddns_test.py
index b0b34ca..3343031 100755
--- a/src/bin/ddns/tests/ddns_test.py
+++ b/src/bin/ddns/tests/ddns_test.py
@@ -341,6 +341,10 @@ class TestDDNSServer(unittest.TestCase):
self.__select_answer = None
self.__select_exception = None
self.__hook_called = False
+ # Because we overwrite the _listen_socket, close any existing
+ # socket object.
+ if self.ddns_server._listen_socket is not None:
+ self.ddns_server._listen_socket.close()
self.ddns_server._listen_socket = FakeSocket(2)
ddns.select.select = self.__select
@@ -379,6 +383,9 @@ class TestDDNSServer(unittest.TestCase):
# Now make sure the clear_socket really works
ddns.clear_socket()
self.assertFalse(os.path.exists(ddns.SOCKET_FILE))
+ # Let ddns object complete any necessary cleanup (not part of the test,
+ # but for suppressing any warnings from the Python interpreter)
+ ddnss.shutdown_cleanup()
def test_initial_config(self):
# right now, the only configuration is the zone configuration, whose
diff --git a/src/bin/msgq/msgq.py.in b/src/bin/msgq/msgq.py.in
index 333ae89..58b1d87 100755
--- a/src/bin/msgq/msgq.py.in
+++ b/src/bin/msgq/msgq.py.in
@@ -177,6 +177,7 @@ class MsgQ:
# (note this is a catch-all, but we reraise it)
if os.path.exists(self.socket_file):
os.remove(self.socket_file)
+ self.listen_socket.close()
raise e
if self.poller:
diff --git a/src/bin/msgq/tests/msgq_test.py b/src/bin/msgq/tests/msgq_test.py
index fe4f7d4..6dc7d1c 100644
--- a/src/bin/msgq/tests/msgq_test.py
+++ b/src/bin/msgq/tests/msgq_test.py
@@ -156,6 +156,12 @@ class SendNonblock(unittest.TestCase):
except socket.error:
pass
+ # Explicitly close temporary socket pair as the Python
+ # interpreter expects it. It may not be 100% exception safe,
+ # but since this is only for tests we prefer brevity.
+ read.close()
+ write.close()
+
def test_infinite_sendmsg(self):
"""
Tries sending messages (and not reading them) until it either times
@@ -218,6 +224,12 @@ class SendNonblock(unittest.TestCase):
os.kill(queue_pid, signal.SIGTERM)
self.terminate_check(run)
+ # Explicitly close temporary socket pair as the Python
+ # interpreter expects it. It may not be 100% exception safe,
+ # but since this is only for tests we prefer brevity.
+ queue.close()
+ out.close()
+
def test_small_sends(self):
"""
Tests sending small data many times.
diff --git a/src/bin/tests/process_rename_test.py.in b/src/bin/tests/process_rename_test.py.in
index f96c023..1156b29 100644
--- a/src/bin/tests/process_rename_test.py.in
+++ b/src/bin/tests/process_rename_test.py.in
@@ -25,7 +25,8 @@ class TestRename(unittest.TestCase):
def __scan(self, directory, script, fun):
# Scan one script if it contains call to the renaming function
filename = os.path.join(directory, script)
- data = ''.join(open(filename).readlines())
+ with open(filename) as f:
+ data = ''.join(f.readlines())
prettyname = 'src' + filename[filename.rfind('../') + 2:]
self.assertTrue(fun.search(data),
"Didn't find a call to isc.util.process.rename in " + prettyname)
@@ -53,8 +54,8 @@ class TestRename(unittest.TestCase):
# Find all Makefile and extract names of scripts
for (d, _, fs) in os.walk('@top_builddir@'):
if 'Makefile' in fs:
- makefile = ''.join(open(os.path.join(d,
- "Makefile")).readlines())
+ with open(os.path.join(d, "Makefile")) as f:
+ makefile = ''.join(f.readlines())
for (var, _) in lines.findall(re.sub(excluded_lines, '',
makefile)):
for (script, _) in scripts.findall(var):
diff --git a/src/bin/xfrin/tests/xfrin_test.py b/src/bin/xfrin/tests/xfrin_test.py
index a860022..a1f4d28 100644
--- a/src/bin/xfrin/tests/xfrin_test.py
+++ b/src/bin/xfrin/tests/xfrin_test.py
@@ -2127,7 +2127,8 @@ class TestXfrin(unittest.TestCase):
self.assertFalse(self.xfr._module_cc.stopped);
self.xfr.shutdown()
self.assertTrue(self.xfr._module_cc.stopped);
- sys.stderr= self.stderr_backup
+ sys.stderr.close()
+ sys.stderr = self.stderr_backup
def _do_parse_zone_name_class(self):
return self.xfr._parse_zone_name_and_class(self.args)
diff --git a/src/bin/xfrout/tests/xfrout_test.py.in b/src/bin/xfrout/tests/xfrout_test.py.in
index b60535c..6f38b75 100644
--- a/src/bin/xfrout/tests/xfrout_test.py.in
+++ b/src/bin/xfrout/tests/xfrout_test.py.in
@@ -1196,26 +1196,28 @@ class TestUnixSockServer(unittest.TestCase):
# We test with UDP, as it can be "connected" without other
# endpoint. Note that in the current implementation _guess_remote()
# unconditionally returns SOCK_STREAM.
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- sock.connect(('127.0.0.1', 12345))
- self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
- ('127.0.0.1', 12345)),
- self.unix._guess_remote(sock.fileno()))
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
+ sock.connect(('127.0.0.1', 12345))
+ self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
+ ('127.0.0.1', 12345)),
+ self.unix._guess_remote(sock.fileno()))
+
if socket.has_ipv6:
# Don't check IPv6 address on hosts not supporting them
- sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
- sock.connect(('::1', 12345))
- self.assertEqual((socket.AF_INET6, socket.SOCK_STREAM,
- ('::1', 12345, 0, 0)),
- self.unix._guess_remote(sock.fileno()))
+ with socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) as sock:
+ sock.connect(('::1', 12345))
+ self.assertEqual((socket.AF_INET6, socket.SOCK_STREAM,
+ ('::1', 12345, 0, 0)),
+ self.unix._guess_remote(sock.fileno()))
+
# Try when pretending there's no IPv6 support
# (No need to pretend when there's really no IPv6)
xfrout.socket.has_ipv6 = False
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- sock.connect(('127.0.0.1', 12345))
- self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
- ('127.0.0.1', 12345)),
- self.unix._guess_remote(sock.fileno()))
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
+ sock.connect(('127.0.0.1', 12345))
+ self.assertEqual((socket.AF_INET, socket.SOCK_STREAM,
+ ('127.0.0.1', 12345)),
+ self.unix._guess_remote(sock.fileno()))
# Return it back
xfrout.socket.has_ipv6 = True
@@ -1375,19 +1377,13 @@ class TestUnixSockServer(unittest.TestCase):
self._remove_file(sock_file)
self.assertFalse(self.unix._sock_file_in_use(sock_file))
self._start_unix_sock_server(sock_file)
-
- old_stdout = sys.stdout
- sys.stdout = open(os.devnull, 'w')
self.assertTrue(self.unix._sock_file_in_use(sock_file))
- sys.stdout = old_stdout
def test_remove_unused_sock_file_in_use(self):
sock_file = 'temp.sock.file'
self._remove_file(sock_file)
self.assertFalse(self.unix._sock_file_in_use(sock_file))
self._start_unix_sock_server(sock_file)
- old_stdout = sys.stdout
- sys.stdout = open(os.devnull, 'w')
try:
self.unix._remove_unused_sock_file(sock_file)
except SystemExit:
@@ -1396,8 +1392,6 @@ class TestUnixSockServer(unittest.TestCase):
# This should never happen
self.assertTrue(False)
- sys.stdout = old_stdout
-
def test_remove_unused_sock_file_dir(self):
import tempfile
dir_name = tempfile.mkdtemp()
@@ -1411,6 +1405,7 @@ class TestUnixSockServer(unittest.TestCase):
# This should never happen
self.assertTrue(False)
+ sys.stdout.close()
sys.stdout = old_stdout
os.rmdir(dir_name)
diff --git a/src/bin/xfrout/xfrout.py.in b/src/bin/xfrout/xfrout.py.in
index 4dd12ce..89bf701 100755
--- a/src/bin/xfrout/xfrout.py.in
+++ b/src/bin/xfrout/xfrout.py.in
@@ -747,12 +747,14 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn,
# to care about the SOCK_STREAM parameter at all (which it really is,
# except for testing)
if socket.has_ipv6:
- sock = socket.fromfd(sock_fd, socket.AF_INET6, socket.SOCK_STREAM)
+ sock_domain = socket.AF_INET6
else:
# To make it work even on hosts without IPv6 support
# (Any idea how to simulate this in test?)
- sock = socket.fromfd(sock_fd, socket.AF_INET, socket.SOCK_STREAM)
- peer = sock.getpeername()
+ sock_domain = socket.AF_INET
+
+ with socket.fromfd(sock_fd, sock_domain, socket.SOCK_STREAM) as sock:
+ peer = sock.getpeername()
# Identify the correct socket family. Due to the above "trick",
# we cannot simply use sock.family.
@@ -761,6 +763,7 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn,
socket.inet_pton(socket.AF_INET6, peer[0])
except socket.error:
family = socket.AF_INET
+
return (family, socket.SOCK_STREAM, peer)
def finish_request(self, sock_fd, request_data):
@@ -802,8 +805,8 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn,
is being used by one running xfrout process. If it is,
return True, or else return False. '''
try:
- sock = socket.socket(socket.AF_UNIX)
- sock.connect(sock_file)
+ with socket.socket(socket.AF_UNIX) as sock:
+ sock.connect(sock_file)
except socket.error as err:
return False
else:
diff --git a/src/bin/zonemgr/zonemgr.py.in b/src/bin/zonemgr/zonemgr.py.in
index 87589a8..e56477e 100755
--- a/src/bin/zonemgr/zonemgr.py.in
+++ b/src/bin/zonemgr/zonemgr.py.in
@@ -428,6 +428,8 @@ class ZonemgrRefresh:
self._thread.join()
# Wipe out what we do not need
self._thread = None
+ self._read_sock.close()
+ self._write_sock.close()
self._read_sock = None
self._write_sock = None
diff --git a/src/lib/dns/python/tests/testutil.py b/src/lib/dns/python/tests/testutil.py
index 679f827..6a1397f 100644
--- a/src/lib/dns/python/tests/testutil.py
+++ b/src/lib/dns/python/tests/testutil.py
@@ -28,14 +28,14 @@ def read_wire_data(filename):
data = bytes()
for path in testdata_path.split(":"):
try:
- file = open(path + os.sep + filename, "r")
- for line in file:
- line = line.strip()
- if line == "" or line.startswith("#"):
- pass
- else:
- cur_data = bytes.fromhex(line)
- data += cur_data
+ with open(path + os.sep + filename, "r") as f:
+ for line in f:
+ line = line.strip()
+ if line == "" or line.startswith("#"):
+ pass
+ else:
+ cur_data = bytes.fromhex(line)
+ data += cur_data
return data
except IOError:
diff --git a/src/lib/python/isc/bind10/tests/sockcreator_test.py b/src/lib/python/isc/bind10/tests/sockcreator_test.py
index d97d21b..115064b 100644
--- a/src/lib/python/isc/bind10/tests/sockcreator_test.py
+++ b/src/lib/python/isc/bind10/tests/sockcreator_test.py
@@ -303,12 +303,16 @@ class WrapTests(unittest.TestCase):
# Transfer the descriptor
send_fd(t1.fileno(), p1.fileno())
- p1 = socket.fromfd(t2.read_fd(), socket.AF_UNIX, socket.SOCK_STREAM)
+ p1.close()
- # Now, pass some data trough the socket
- p1.send(b'A')
- data = p2.recv(1)
- self.assertEqual(b'A', data)
+ with socket.fromfd(t2.read_fd(), socket.AF_UNIX,
+ socket.SOCK_STREAM) as p1:
+ # Now, pass some data trough the socket
+ p1.send(b'A')
+ data = p2.recv(1)
+ self.assertEqual(b'A', data)
+
+ p2.close()
# Test the wrapping didn't hurt the socket's usual methods
t1.send(b'B')
@@ -318,6 +322,9 @@ class WrapTests(unittest.TestCase):
data = t1.recv(1)
self.assertEqual(b'C', data)
+ t1.close()
+ t2.close()
+
if __name__ == '__main__':
isc.log.init("bind10") # FIXME Should this be needed?
isc.log.resetUnitTestRootLogger()
diff --git a/src/lib/python/isc/config/tests/module_spec_test.py b/src/lib/python/isc/config/tests/module_spec_test.py
index fc53d23..bb2bcda 100644
--- a/src/lib/python/isc/config/tests/module_spec_test.py
+++ b/src/lib/python/isc/config/tests/module_spec_test.py
@@ -46,8 +46,8 @@ class TestModuleSpec(unittest.TestCase):
self.spec1(dd)
def test_open_file_obj(self):
- file1 = open(self.spec_file("spec1.spec"))
- dd = isc.config.module_spec_from_file(file1)
+ with open(self.spec_file("spec1.spec")) as file1:
+ dd = isc.config.module_spec_from_file(file1)
self.spec1(dd)
def test_open_bad_file_obj(self):
@@ -89,8 +89,8 @@ class TestModuleSpec(unittest.TestCase):
def validate_data(self, specfile_name, datafile_name):
dd = self.read_spec_file(specfile_name);
- data_file = open(self.spec_file(datafile_name))
- data_str = data_file.read()
+ with open(self.spec_file(datafile_name)) as data_file:
+ data_str = data_file.read()
data = isc.cc.data.parse_value_str(data_str)
return dd.validate_config(True, data)
@@ -109,8 +109,8 @@ class TestModuleSpec(unittest.TestCase):
def validate_command_params(self, specfile_name, datafile_name, cmd_name):
dd = self.read_spec_file(specfile_name);
- data_file = open(self.spec_file(datafile_name))
- data_str = data_file.read()
+ with open(self.spec_file(datafile_name)) as data_file:
+ data_str = data_file.read()
params = isc.cc.data.parse_value_str(data_str)
return dd.validate_command(cmd_name, params)
@@ -131,8 +131,8 @@ class TestModuleSpec(unittest.TestCase):
def test_statistics_validation(self):
def _validate_stat(specfile_name, datafile_name):
dd = self.read_spec_file(specfile_name);
- data_file = open(self.spec_file(datafile_name))
- data_str = data_file.read()
+ with open(self.spec_file(datafile_name)) as data_file:
+ data_str = data_file.read()
data = isc.cc.data.parse_value_str(data_str)
return dd.validate_statistics(True, data, [])
self.assertFalse(self.read_spec_file("spec1.spec").validate_statistics(True, None, None));
diff --git a/src/lib/python/isc/util/cio/tests/socketsession_test.py b/src/lib/python/isc/util/cio/tests/socketsession_test.py
index f2de999..6502aba 100644
--- a/src/lib/python/isc/util/cio/tests/socketsession_test.py
+++ b/src/lib/python/isc/util/cio/tests/socketsession_test.py
@@ -33,12 +33,15 @@ class TestForwarder(unittest.TestCase):
'''
def setUp(self):
+ self.listen_sock = None
self.forwarder = SocketSessionForwarder(TEST_UNIX_FILE)
if os.path.exists(TEST_UNIX_FILE):
os.unlink(TEST_UNIX_FILE)
self.large_text = b'a' * 65535
def tearDown(self):
+ if self.listen_sock is not None:
+ self.listen_sock.close()
if os.path.exists(TEST_UNIX_FILE):
os.unlink(TEST_UNIX_FILE)
@@ -125,60 +128,63 @@ class TestForwarder(unittest.TestCase):
def check_push_and_pop(self, family, type, protocol, local, remote,
data, new_connection):
- sock = self.create_socket(family, type, protocol, local, True)
- fwd_fd = sock.fileno()
- if protocol == IPPROTO_TCP:
- client_addr = ('::1', 0, 0, 0) if family == AF_INET6 \
- else ('127.0.0.1', 0)
- client_sock = self.create_socket(family, type, protocol,
- client_addr, False)
- client_sock.setblocking(False)
- try:
- client_sock.connect(local)
- except socket.error:
- pass
- server_sock, _ = sock.accept()
- fwd_fd = server_sock.fileno()
-
- # If a new connection is required, start the "server", have the
- # internal forwarder connect to it, and then internally accept it.
- if new_connection:
- self.start_listen()
- self.forwarder.connect_to_receiver()
- self.accept_sock = self.accept_forwarder()
-
- # Then push one socket session via the forwarder.
- self.forwarder.push(fwd_fd, family, type, protocol, local, remote,
- data)
-
- # Pop the socket session we just pushed from a local receiver, and
- # check the content.
- receiver = SocketSessionReceiver(self.accept_sock)
- signal.alarm(1)
- sock_session = receiver.pop()
- signal.alarm(0)
- passed_sock = sock_session[0]
- self.assertNotEqual(fwd_fd, passed_sock.fileno())
- self.assertEqual(family, passed_sock.family)
- self.assertEqual(type, passed_sock.type)
- self.assertEqual(protocol, passed_sock.proto)
- self.assertEqual(local, sock_session[1])
- self.assertEqual(remote, sock_session[2])
- self.assertEqual(data, sock_session[3])
-
- # Check if the passed FD is usable by sending some data from it.
- passed_sock.setblocking(True)
- if protocol == IPPROTO_UDP:
- self.assertEqual(len(TEST_DATA), passed_sock.sendto(TEST_DATA,
- local))
- sock.settimeout(10)
- self.assertEqual(TEST_DATA, sock.recvfrom(len(TEST_DATA))[0])
- else:
- server_sock.close()
- self.assertEqual(len(TEST_DATA), passed_sock.send(TEST_DATA))
- client_sock.setblocking(True)
- client_sock.settimeout(10)
- self.assertEqual(TEST_DATA, client_sock.recv(len(TEST_DATA)))
+ with self.create_socket(family, type, protocol, local, True) as sock:
+ fwd_fd = sock.fileno()
+ if protocol == IPPROTO_TCP:
+ client_addr = ('::1', 0, 0, 0) if family == AF_INET6 \
+ else ('127.0.0.1', 0)
+ client_sock = self.create_socket(family, type, protocol,
+ client_addr, False)
+ client_sock.setblocking(False)
+ try:
+ client_sock.connect(local)
+ except socket.error:
+ pass
+ server_sock, _ = sock.accept()
+ fwd_fd = server_sock.fileno()
+
+ # If a new connection is required, start the "server", have the
+ # internal forwarder connect to it, and then internally accept it.
+ if new_connection:
+ self.start_listen()
+ self.forwarder.connect_to_receiver()
+ self.accept_sock = self.accept_forwarder()
+
+ # Then push one socket session via the forwarder.
+ self.forwarder.push(fwd_fd, family, type, protocol, local, remote,
+ data)
+
+ # Pop the socket session we just pushed from a local receiver, and
+ # check the content.
+ receiver = SocketSessionReceiver(self.accept_sock)
+ signal.alarm(1)
+ sock_session = receiver.pop()
+ signal.alarm(0)
+ passed_sock = sock_session[0]
+ self.assertNotEqual(fwd_fd, passed_sock.fileno())
+ self.assertEqual(family, passed_sock.family)
+ self.assertEqual(type, passed_sock.type)
+ self.assertEqual(protocol, passed_sock.proto)
+ self.assertEqual(local, sock_session[1])
+ self.assertEqual(remote, sock_session[2])
+ self.assertEqual(data, sock_session[3])
+
+ # Check if the passed FD is usable by sending some data from it.
+ passed_sock.setblocking(True)
+ if protocol == IPPROTO_UDP:
+ self.assertEqual(len(TEST_DATA), passed_sock.sendto(TEST_DATA,
+ local))
+ sock.settimeout(10)
+ self.assertEqual(TEST_DATA, sock.recvfrom(len(TEST_DATA))[0])
+ else:
+ self.assertEqual(len(TEST_DATA), passed_sock.send(TEST_DATA))
+ client_sock.setblocking(True)
+ client_sock.settimeout(10)
+ self.assertEqual(TEST_DATA, client_sock.recv(len(TEST_DATA)))
+ server_sock.close()
+ client_sock.close()
+
+ passed_sock.close()
def test_push_and_pop(self):
# This is a straightforward port of C++ pushAndPop test. See the
@@ -237,10 +243,10 @@ class TestForwarder(unittest.TestCase):
s = socket.socket(socket.AF_UNIX, SOCK_STREAM, 0)
s.setblocking(False)
s.connect(TEST_UNIX_FILE)
- accept_sock = self.accept_forwarder()
- receiver = SocketSessionReceiver(accept_sock)
- s.close()
- self.assertRaises(SocketSessionError, receiver.pop)
+ with self.accept_forwarder() as accept_sock:
+ receiver = SocketSessionReceiver(accept_sock)
+ s.close()
+ self.assertRaises(SocketSessionError, receiver.pop)
class TestReceiver(unittest.TestCase):
# We only check a couple of failure cases on construction. Valid cases
More information about the bind10-changes
mailing list