From acd3ccf05a97a31ec49639d136383fad10b1709c Mon Sep 17 00:00:00 2001 From: Dean Birch Date: Wed, 6 Jun 2018 10:29:49 +0100 Subject: Fix idempotency of decompress_file Calling decompress_file would modify decompress_command_map. This meant that if multiple decompressions of the same compression type occurred, the latter ones would fail. Fix this by taking a local copy of decompress_command_map before any modifications are made. Also unit test added to catch future regression. Change-Id: I5c4781d0f5b49672d61cff9c4c2afe977765b8f9 --- lava_dispatcher/test/test_compression.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lava_dispatcher/test') 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 . +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) -- cgit v1.2.3