You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by tt...@apache.org on 2017/05/08 19:32:15 UTC

ambari git commit: AMBARI-20946: Archive zip not created if missing but hash file exists (Diego Santesteban via tthorpe)

Repository: ambari
Updated Branches:
  refs/heads/trunk 3dd206ccf -> e20305bc4


AMBARI-20946: Archive zip not created if missing but hash file exists (Diego Santesteban via tthorpe)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e20305bc
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e20305bc
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e20305bc

Branch: refs/heads/trunk
Commit: e20305bc4264de2d7b6d45d44575edeeeed14c6e
Parents: 3dd206c
Author: Tim Thorpe <tt...@apache.org>
Authored: Mon May 8 12:31:19 2017 -0700
Committer: Tim Thorpe <tt...@apache.org>
Committed: Mon May 8 12:31:19 2017 -0700

----------------------------------------------------------------------
 .../python/ambari_server/resourceFilesKeeper.py | 11 ++++++--
 .../src/test/python/TestResourceFilesKeeper.py  | 29 +++++++++++++++++---
 2 files changed, 34 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e20305bc/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py b/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
index dba6833..b41c400 100644
--- a/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
+++ b/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py
@@ -166,11 +166,17 @@ class ResourceFilesKeeper():
   def update_directory_archive(self, directory):
     """
     If hash sum for directory is not present or differs from saved value,
-    recalculates hash sum and creates directory archive
+    recalculates hash sum and creates directory archive. The archive is
+    also created if the existing archive does not exist, even if the
+    saved and current hash sums are matching.
     """
     skip_empty_directory = True
+
     cur_hash = self.count_hash_sum(directory)
     saved_hash = self.read_hash_sum(directory)
+
+    directory_archive_name = os.path.join(directory, self.ARCHIVE_NAME)
+
     if cur_hash != saved_hash:
       if not self.nozip:
         self.zip_directory(directory, skip_empty_directory)
@@ -180,6 +186,8 @@ class ResourceFilesKeeper():
       else:
         self.write_hash_sum(directory, cur_hash)
       pass
+    elif not os.path.isfile(directory_archive_name):
+      self.zip_directory(directory, skip_empty_directory)
 
   def count_hash_sum(self, directory):
     """
@@ -307,4 +315,3 @@ def main(argv=None):
 
 if __name__ == '__main__':
   main(sys.argv)
-

http://git-wip-us.apache.org/repos/asf/ambari/blob/e20305bc/ambari-server/src/test/python/TestResourceFilesKeeper.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestResourceFilesKeeper.py b/ambari-server/src/test/python/TestResourceFilesKeeper.py
index 4f7dc52..4f8bdd5 100644
--- a/ambari-server/src/test/python/TestResourceFilesKeeper.py
+++ b/ambari-server/src/test/python/TestResourceFilesKeeper.py
@@ -179,6 +179,7 @@ class TestResourceFilesKeeper(TestCase):
     except Exception, e:
       self.fail('Unexpected exception thrown:' + str(e))
 
+  @patch("os.path.isfile")
   @patch("os.path.exists")
   @patch("os.listdir")
   @patch.object(ResourceFilesKeeper, "count_hash_sum")
@@ -188,8 +189,10 @@ class TestResourceFilesKeeper(TestCase):
   def test_update_directory_archive(self, write_hash_sum_mock,
                                     zip_directory_mock, read_hash_sum_mock,
                                     count_hash_sum_mock,
-                                    os_listdir_mock, os_path_exists_mock):
+                                    os_listdir_mock, os_path_exists_mock,
+                                    os_path_isfile_mock):
     os_listdir_mock.return_value = ['file1', 'dir1']
+
     # Test situation when there is no saved directory hash
     read_hash_sum_mock.return_value = None
     count_hash_sum_mock.return_value = self.YA_HASH
@@ -206,10 +209,27 @@ class TestResourceFilesKeeper(TestCase):
     zip_directory_mock.reset_mock()
     write_hash_sum_mock.reset_mock()
 
-    # Test situation when saved directory hash == current hash
+    # Test situation where there is a .hash file, equal to the current hash,
+    # but no archive.zip file
+    count_hash_sum_mock.return_value = self.YA_HASH
+    read_hash_sum_mock.return_value = self.YA_HASH
+    os_path_isfile_mock.return_value = False
+    resource_files_keeper = ResourceFilesKeeper(self.TEST_RESOURCES_DIR, self.SOME_PATH)
+    resource_files_keeper.update_directory_archive(self.SOME_PATH)
+    self.assertTrue(read_hash_sum_mock.called)
+    self.assertTrue(count_hash_sum_mock.called)
+    self.assertTrue(zip_directory_mock.called)
+    self.assertFalse(write_hash_sum_mock.called)
+
+    read_hash_sum_mock.reset_mock()
+    count_hash_sum_mock.reset_mock()
+    zip_directory_mock.reset_mock()
+    write_hash_sum_mock.reset_mock()
+
+    # Test situation when saved directory hash == current hash and old archive does not exist
     read_hash_sum_mock.return_value = self.DUMMY_HASH
     count_hash_sum_mock.return_value = self.YA_HASH
-    os_path_exists_mock.return_value = True
+    os_path_isfile_mock.return_value = False
     resource_files_keeper.update_directory_archive(self.SOME_PATH)
     self.assertTrue(read_hash_sum_mock.called)
     self.assertTrue(count_hash_sum_mock.called)
@@ -221,10 +241,11 @@ class TestResourceFilesKeeper(TestCase):
     zip_directory_mock.reset_mock()
     write_hash_sum_mock.reset_mock()
 
-    # Test situation when saved directory hash == current hash
+    # Test situation when saved directory hash == current hash and old archive exists
     read_hash_sum_mock.return_value = self.DUMMY_HASH
     count_hash_sum_mock.return_value = self.DUMMY_HASH
     os_path_exists_mock.return_value = True
+    os_path_isfile_mock.return_value = True
     resource_files_keeper.update_directory_archive(self.SOME_PATH)
     self.assertTrue(read_hash_sum_mock.called)
     self.assertTrue(count_hash_sum_mock.called)