[CRIU] [PATCH v3 2/2] Fix RPC configuration file test case

Adrian Reber adrian at lisas.de
Wed Dec 19 21:04:58 MSK 2018


From: Adrian Reber <areber at redhat.com>

The relevant test case test_rpc_with_configuration_file_overwriting_rpc()
was actually designed around the broken behaviour. It was only working
if a previous configuration file (set via environment variable in this
case) and the RPC configuration file have the same name. The test case
which tests that RPC configuration file settings are overwriting direct
RPC settings now makes sure that no other configuration file is set via
the environment variable. If it would be set, the test case would still
succeed, even with the previous patch applied. Which is and which was the
correct behaviour.

So the main reason for this change is to test the more likely use case
that the environment based configuration file and the RPC configuration
file have different names.

Signed-off-by: Adrian Reber <areber at redhat.com>
---
 test/others/rpc/config_file.py | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/test/others/rpc/config_file.py b/test/others/rpc/config_file.py
index f21d194b0..df3d1873e 100755
--- a/test/others/rpc/config_file.py
+++ b/test/others/rpc/config_file.py
@@ -33,10 +33,18 @@ def setup_config_file(content):
 
 
 def cleanup_config_file(path):
-	del os.environ['CRIU_CONFIG_FILE']
+	if os.environ.get('CRIU_CONFIG_FILE', None) is not None:
+		del os.environ['CRIU_CONFIG_FILE']
 	os.unlink(path)
 
 
+def cleanup_output(path):
+	for f in (does_not_exist, log_file):
+		f = os.path.join(path, f)
+		if os.access(f, os.F_OK):
+			os.unlink(f)
+
+
 def setup_criu_dump_request():
 	# Create criu msg, set it's type to dump request
 	# and set dump options. Checkout more options in protobuf/rpc.proto
@@ -146,6 +154,9 @@ def test_rpc_with_configuration_file_overwriting_rpc():
 	content = 'log-file ' + log + '\n'
 	content += 'no-tcp-established\nno-shell-job'
 	path = setup_config_file(content)
+	# Only set the configuration file via RPC;
+	# not via environment variable
+	del os.environ['CRIU_CONFIG_FILE']
 	req = setup_criu_dump_request()
 	req.opts.config_file = path
 	_, s = setup_swrk()
@@ -160,14 +171,13 @@ parser.add_argument('dir', type = str, help = "Directory where CRIU images shoul
 
 args = vars(parser.parse_args())
 
-try:
-	# optional cleanup
-	os.unlink(os.path.join(args['dir'], does_not_exist))
-	os.unlink(os.path.join(args['dir'], log_file))
-except OSError:
-	pass
+cleanup_output(args['dir'])
 
 test_broken_configuration_file()
+cleanup_output(args['dir'])
 test_rpc_without_configuration_file()
+cleanup_output(args['dir'])
 test_rpc_with_configuration_file()
+cleanup_output(args['dir'])
 test_rpc_with_configuration_file_overwriting_rpc()
+cleanup_output(args['dir'])
-- 
2.18.0



More information about the CRIU mailing list