diff options
-rw-r--r-- | lava_dispatcher/test/test_compression.py | 19 | ||||
-rw-r--r-- | lava_dispatcher/utils/compression.py | 6 |
2 files changed, 23 insertions, 2 deletions
diff --git a/lava_dispatcher/test/test_compression.py b/lava_dispatcher/test/test_compression.py index e3b43a9d2..9950a5cb6 100644 --- a/lava_dispatcher/test/test_compression.py +++ b/lava_dispatcher/test/test_compression.py @@ -18,9 +18,13 @@ # along # with this program; if not, see <http://www.gnu.org/licenses>. +import copy import os import hashlib +from lava_common.exceptions import InfrastructureError from lava_dispatcher.test.test_basic import Factory, StdoutTestCase +from lava_dispatcher.utils.compression import decompress_file +from lava_dispatcher.utils.compression import decompress_command_map class TestDecompression(StdoutTestCase): @@ -73,3 +77,18 @@ class TestDecompression(StdoutTestCase): self.assertEqual(outputsha, sha256sum) self.assertEqual(outputsize, filesize) self.assertEqual(outputfile, '10MB') + + def test_multiple_decompressions(self): + """ + Previously had an issue with decompress_command_map being modified. + This should be a constant. If this is modified during calling decompress_file + then a regression has occurred. + :return: + """ + # Take a complete copy of decompress_command_map before it has been modified + copy_of_command_map = copy.deepcopy(decompress_command_map) + # Call decompress_file, we only need it to create the command required, + # it doesn't need to complete successfully. + with self.assertRaises(InfrastructureError): + decompress_file("/tmp/test.xz", "zip") + self.assertEqual(copy_of_command_map, decompress_command_map) diff --git a/lava_dispatcher/utils/compression.py b/lava_dispatcher/utils/compression.py index c25916124..276fff97b 100644 --- a/lava_dispatcher/utils/compression.py +++ b/lava_dispatcher/utils/compression.py @@ -57,7 +57,8 @@ def compress_file(infile, compression): which(compress_command_map[compression][0]) with chdir(os.path.dirname(infile)): - cmd = compress_command_map[compression] + # local copy for idempotency + cmd = compress_command_map[compression][:] cmd.append(infile) try: subprocess.check_output(cmd) @@ -76,7 +77,8 @@ def decompress_file(infile, compression): which(decompress_command_map[compression][0]) with chdir(os.path.dirname(infile)): - cmd = decompress_command_map[compression] + # local copy for idempotency + cmd = decompress_command_map[compression][:] cmd.append(infile) outfile = infile if infile.endswith(compression): |