From bada5e1ada7ae487c4244cdec864a2bcad65238b Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Wed, 19 Dec 2018 18:04:58 +0000 Subject: [PATCH] Fix RPC configuration file test case 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 Signed-off-by: Andrei Vagin --- 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 b74cc0428..23a06615f 100755 --- a/test/others/rpc/config_file.py +++ b/test/others/rpc/config_file.py @@ -34,10 +34,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 @@ -155,6 +163,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() @@ -169,14 +180,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'])