コード例 #1
0
    def test_write_hash_sum(self):
        NEW_HASH = "new_hash"
        resource_files_keeper = ResourceFilesKeeper(
            self.TEST_RESOURCES_DIR, self.DUMMY_UNCHANGEABLE_PACKAGE)
        resource_files_keeper.write_hash_sum(self.DUMMY_UNCHANGEABLE_PACKAGE,
                                             NEW_HASH)
        hash_sum = resource_files_keeper.read_hash_sum(
            self.DUMMY_UNCHANGEABLE_PACKAGE)
        self.assertEquals(hash_sum, NEW_HASH)

        # Revert to previous value
        resource_files_keeper.write_hash_sum(self.DUMMY_UNCHANGEABLE_PACKAGE,
                                             self.DUMMY_HASH)
        hash_sum = resource_files_keeper.read_hash_sum(
            self.DUMMY_UNCHANGEABLE_PACKAGE)
        self.assertEquals(hash_sum, self.DUMMY_HASH)

        # Test exception handling
        with patch("__builtin__.open") as open_mock:
            open_mock.side_effect = self.exc_side_effect
            try:
                resource_files_keeper.write_hash_sum("path-to-directory",
                                                     self.DUMMY_HASH)
                self.fail('KeeperException not thrown')
            except KeeperException:
                pass  # Expected
            except Exception, e:
                self.fail('Unexpected exception thrown:' + str(e))
コード例 #2
0
 def test_update_directory_archieves(self, abspath_mock,
                                     list_active_stacks_mock,
                                     list_common_services_mock,
                                     update_directory_archive_mock):
   list_active_stacks_mock.return_value = [self.DUMMY_UNCHANGEABLE_STACK,
                                           self.DUMMY_UNCHANGEABLE_STACK,
                                           self.DUMMY_UNCHANGEABLE_STACK]
   list_common_services_mock.return_value = [self.DUMMY_UNCHANGEABLE_COMMON_SERVICES,
                                             self.DUMMY_UNCHANGEABLE_COMMON_SERVICES]
   abspath_mock.side_effect = lambda s : s
   resource_files_keeper = ResourceFilesKeeper(self.TEST_RESOURCES_DIR, self.TEST_STACKS_DIR)
   resource_files_keeper.update_directory_archieves()
   self.assertEquals(pprint.pformat(
     update_directory_archive_mock.call_args_list),
           "[call('../resources/TestAmbaryServer.samples/"
           "dummy_stack/HIVE/package'),\n "
           "call('../resources/TestAmbaryServer.samples/"
           "dummy_stack/HIVE/package'),\n "
           "call('../resources/TestAmbaryServer.samples/"
           "dummy_stack/HIVE/package'),\n "
           "call('../resources/TestAmbaryServer.samples/"
           "dummy_common_services/HIVE/0.11.0.2.0.5.0/package'),\n "
           "call('../resources/TestAmbaryServer.samples/"
           "dummy_common_services/HIVE/0.11.0.2.0.5.0/package'),\n "
           "call('../resources/custom_actions'),\n "
           "call('../resources/host_scripts')]")
   pass
コード例 #3
0
 def test_update_directory_archieves(self, abspath_mock,
                                     list_active_stacks_mock,
                                     list_common_services_mock,
                                     update_directory_archive_mock):
     list_active_stacks_mock.return_value = [
         self.DUMMY_UNCHANGEABLE_STACK, self.DUMMY_UNCHANGEABLE_STACK,
         self.DUMMY_UNCHANGEABLE_STACK
     ]
     list_common_services_mock.return_value = [
         self.DUMMY_UNCHANGEABLE_COMMON_SERVICES,
         self.DUMMY_UNCHANGEABLE_COMMON_SERVICES
     ]
     abspath_mock.side_effect = lambda s: s
     resource_files_keeper = ResourceFilesKeeper(self.TEST_RESOURCES_DIR,
                                                 self.TEST_STACKS_DIR)
     resource_files_keeper.update_directory_archieves()
     self.assertEquals(
         pprint.pformat(update_directory_archive_mock.call_args_list),
         "[call('../resources/TestAmbaryServer.samples/"
         "dummy_stack/HIVE/package'),\n "
         "call('../resources/TestAmbaryServer.samples/"
         "dummy_stack/HIVE/package'),\n "
         "call('../resources/TestAmbaryServer.samples/"
         "dummy_stack/HIVE/package'),\n "
         "call('../resources/TestAmbaryServer.samples/"
         "dummy_common_services/HIVE/0.11.0.2.0.5.0/package'),\n "
         "call('../resources/TestAmbaryServer.samples/"
         "dummy_common_services/HIVE/0.11.0.2.0.5.0/package'),\n "
         "call('../resources/custom_actions'),\n "
         "call('../resources/host_scripts')]")
     pass
コード例 #4
0
  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_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
    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.assertTrue(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
    read_hash_sum_mock.return_value = self.DUMMY_HASH
    count_hash_sum_mock.return_value = self.YA_HASH
    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.assertTrue(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
    read_hash_sum_mock.return_value = self.DUMMY_HASH
    count_hash_sum_mock.return_value = self.DUMMY_HASH
    resource_files_keeper.update_directory_archive(self.SOME_PATH)
    self.assertTrue(read_hash_sum_mock.called)
    self.assertTrue(count_hash_sum_mock.called)
    self.assertFalse(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()

    # Check that no saved hash file is created when zipping failed
    zip_directory_mock.side_effect = self.keeper_exc_side_effect
    read_hash_sum_mock.return_value = self.DUMMY_HASH
    count_hash_sum_mock.return_value = self.YA_HASH
    try:
      resource_files_keeper.update_directory_archive(self.SOME_PATH)
      self.fail('KeeperException not thrown')
    except KeeperException:
      pass # Expected
    except Exception, e:
      self.fail('Unexpected exception thrown:' + str(e))
コード例 #5
0
  def test_update_directory_archive(self, write_hash_sum_mock,
                                    zip_directory_mock, read_hash_sum_mock,
                                    count_hash_sum_mock):
    # 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
    resource_files_keeper = ResourceFilesKeeper(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.assertTrue(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
    read_hash_sum_mock.return_value = self.DUMMY_HASH
    count_hash_sum_mock.return_value = self.YA_HASH
    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.assertTrue(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
    read_hash_sum_mock.return_value = self.DUMMY_HASH
    count_hash_sum_mock.return_value = self.DUMMY_HASH
    resource_files_keeper.update_directory_archive(self.SOME_PATH)
    self.assertTrue(read_hash_sum_mock.called)
    self.assertTrue(count_hash_sum_mock.called)
    self.assertFalse(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()

    # Check that no saved hash file is created when zipping failed
    zip_directory_mock.side_effect = self.keeper_exc_side_effect
    read_hash_sum_mock.return_value = self.DUMMY_HASH
    count_hash_sum_mock.return_value = self.YA_HASH
    try:
      resource_files_keeper.update_directory_archive(self.SOME_PATH)
      self.fail('KeeperException not thrown')
    except KeeperException:
      pass # Expected
    except Exception, e:
      self.fail('Unexpected exception thrown:' + str(e))
コード例 #6
0
ファイル: serverUtils.py プロジェクト: nishantmonu51/ambari-1
def refresh_stack_hash(properties):
  resources_location = get_resources_location(properties)
  stacks_location = get_stack_location(properties)
  resource_files_keeper = ResourceFilesKeeper(resources_location, stacks_location)

  try:
    print "Organizing resource files at {0}...".format(resources_location,
                                                       verbose=get_verbose())
    resource_files_keeper.perform_housekeeping()
  except KeeperException, ex:
    msg = "Can not organize resource files at {0}: {1}".format(
      resources_location, str(ex))
    raise FatalException(-1, msg)
コード例 #7
0
def refresh_stack_hash(properties):
  resources_location = get_resources_location(properties)
  stacks_location = get_stack_location(properties)
  resource_files_keeper = ResourceFilesKeeper(resources_location, stacks_location)

  try:
    print "Organizing resource files at {0}...".format(resources_location,
                                                       verbose=get_verbose())
    resource_files_keeper.perform_housekeeping()
  except KeeperException, ex:
    msg = "Can not organize resource files at {0}: {1}".format(
      resources_location, str(ex))
    raise FatalException(-1, msg)
コード例 #8
0
ファイル: serverUtils.py プロジェクト: fanzhidongyzby/ambari
def refresh_stack_hash(properties):
  stack_location = get_stack_location(properties)
  # Hack: we determine resource dir as a parent dir for stack_location
  resources_location = os.path.dirname(stack_location)
  resource_files_keeper = ResourceFilesKeeper(resources_location)

  try:
    # print "Organizing resource files at {0}...".format(resources_location, verbose=get_verbose())
    print "Organizing resource files..."
    resource_files_keeper.perform_housekeeping()
  except KeeperException, ex:
    msg = "Can not organize resource files at {0}: {1}".format(
      resources_location, str(ex))
    raise FatalException(-1, msg)
コード例 #9
0
ファイル: serverUtils.py プロジェクト: screeley44/ambari
def refresh_stack_hash(properties):
    stack_location = get_stack_location(properties)
    # Hack: we determine resource dir as a parent dir for stack_location
    resources_location = os.path.dirname(stack_location)
    resource_files_keeper = ResourceFilesKeeper(resources_location)

    try:
        print "Organizing resource files at {0}...".format(
            resources_location, verbose=get_verbose())
        resource_files_keeper.perform_housekeeping()
    except KeeperException, ex:
        msg = "Can not organize resource files at {0}: {1}".format(
            resources_location, str(ex))
        raise FatalException(-1, msg)
コード例 #10
0
 def test_update_directory_archieves(self, abspath_mock,
                                     list_active_stacks_mock,
                                     list_common_services_mock,
                                     update_directory_archive_mock):
   list_active_stacks_mock.return_value = [self.DUMMY_UNCHANGEABLE_STACK,
                                           self.DUMMY_UNCHANGEABLE_STACK,
                                           self.DUMMY_UNCHANGEABLE_STACK]
   list_common_services_mock.return_value = [self.DUMMY_UNCHANGEABLE_COMMON_SERVICES,
                                             self.DUMMY_UNCHANGEABLE_COMMON_SERVICES]
   abspath_mock.side_effect = lambda s : s
   resource_files_keeper = ResourceFilesKeeper(self.TEST_RESOURCES_DIR, self.TEST_STACKS_DIR)
   resource_files_keeper.update_directory_archieves()
   self.assertEquals(pprint.pformat(
     update_directory_archive_mock.call_args_list),
     self.UPDATE_DIRECTORY_ARCHIVE_CALL_LIST)
   pass
コード例 #11
0
  def test_list_common_services(self, exists_mock, glob_mock):
    resource_files_keeper = ResourceFilesKeeper(self.TEST_RESOURCES_DIR, self.SOME_PATH)
    # Test normal execution flow
    glob_mock.return_value = ["common_service1", "common_service2", "common_service3"]
    exists_mock.side_effect = [True, False, True]
    res = resource_files_keeper.list_common_services(self.SOME_PATH)
    self.assertEquals(pprint.pformat(res), "['common_service1', 'common_service3']")

    # Test exception handling
    glob_mock.side_effect = self.keeper_exc_side_effect
    try:
      resource_files_keeper.list_common_services(self.SOME_PATH)
      self.fail('KeeperException not thrown')
    except KeeperException:
      pass # Expected
    except Exception, e:
      self.fail('Unexpected exception thrown:' + str(e))
コード例 #12
0
  def test_count_hash_sum(self):
    # Test normal flow
    resource_files_keeper = ResourceFilesKeeper(self.TEST_RESOURCES_DIR, self.DUMMY_UNCHANGEABLE_PACKAGE)
    test_dir = os.path.join(self.DUMMY_UNCHANGEABLE_PACKAGE)
    hash_sum = resource_files_keeper.count_hash_sum(test_dir)
    self.assertEquals(hash_sum, self.DUMMY_UNCHANGEABLE_PACKAGE_HASH)

    # Test exception handling
    with patch("__builtin__.open") as open_mock:
      open_mock.side_effect = self.exc_side_effect
      try:
        resource_files_keeper.count_hash_sum(test_dir)
        self.fail('KeeperException not thrown')
      except KeeperException:
        pass # Expected
      except Exception, e:
        self.fail('Unexpected exception thrown:' + str(e))
コード例 #13
0
  def test_count_hash_sum(self):
    # Test normal flow
    resource_files_keeper = ResourceFilesKeeper(self.DUMMY_UNCHANGEABLE_PACKAGE)
    test_dir = os.path.join(self.DUMMY_UNCHANGEABLE_PACKAGE)
    hash_sum = resource_files_keeper.count_hash_sum(test_dir)
    self.assertEquals(hash_sum, self.DUMMY_UNCHANGEABLE_PACKAGE_HASH)

    # Test exception handling
    with patch("__builtin__.open") as open_mock:
      open_mock.side_effect = self.exc_side_effect
      try:
        resource_files_keeper.count_hash_sum(test_dir)
        self.fail('KeeperException not thrown')
      except KeeperException:
        pass # Expected
      except Exception, e:
        self.fail('Unexpected exception thrown:' + str(e))
コード例 #14
0
  def test_list_stacks(self, exists_mock, glob_mock):
    resource_files_keeper = ResourceFilesKeeper(self.SOME_PATH)
    # Test normal execution flow
    glob_mock.return_value = ["stack1", "stack2", "stack3"]
    exists_mock.side_effect = [True, False, True]
    res = resource_files_keeper.list_stacks(self.SOME_PATH)
    self.assertEquals(pprint.pformat(res), "['stack1', 'stack3']")

    # Test exception handling
    glob_mock.side_effect = self.keeper_exc_side_effect
    try:
      resource_files_keeper.list_stacks(self.SOME_PATH)
      self.fail('KeeperException not thrown')
    except KeeperException:
      pass # Expected
    except Exception, e:
      self.fail('Unexpected exception thrown:' + str(e))
コード例 #15
0
    def test_zip_directory(self):
        # Test normal flow
        resource_files_keeper = ResourceFilesKeeper(
            self.TEST_RESOURCES_DIR, self.DUMMY_UNCHANGEABLE_PACKAGE)
        resource_files_keeper.zip_directory(self.DUMMY_UNCHANGEABLE_PACKAGE)
        arc_file = os.path.join(self.DUMMY_UNCHANGEABLE_PACKAGE,
                                ResourceFilesKeeper.ARCHIVE_NAME)
        # Arc file should not be empty
        arc_size = os.path.getsize(arc_file)
        self.assertTrue(40000 < arc_size < 50000)
        # After creating zip, count hash sum of dir (should not change)
        hash_val = resource_files_keeper.count_hash_sum(
            self.DUMMY_UNCHANGEABLE_PACKAGE)
        self.assertEquals(hash_val, self.DUMMY_UNCHANGEABLE_PACKAGE_HASH)
        # Remove arc file
        os.unlink(arc_file)

        # Test exception handling
        with patch("os.path.join") as join_mock:
            join_mock.side_effect = self.exc_side_effect
            try:
                resource_files_keeper.zip_directory("path-to-directory")
                self.fail('KeeperException not thrown')
            except KeeperException:
                pass  # Expected
            except Exception, e:
                self.fail('Unexpected exception thrown:' + str(e))
コード例 #16
0
 def test_is_ignored(self):
   resource_files_keeper = ResourceFilesKeeper(self.DUMMY_UNCHANGEABLE_PACKAGE)
   self.assertTrue(resource_files_keeper.is_ignored(".hash"))
   self.assertTrue(resource_files_keeper.is_ignored("archive.zip"))
   self.assertTrue(resource_files_keeper.is_ignored("dummy.pyc"))
   self.assertFalse(resource_files_keeper.is_ignored("dummy.py"))
   self.assertFalse(resource_files_keeper.is_ignored("1.sh"))
コード例 #17
0
  def test_read_hash_sum(self):
    resource_files_keeper = ResourceFilesKeeper(self.TEST_RESOURCES_DIR, self.DUMMY_UNCHANGEABLE_PACKAGE)
    hash_sum = resource_files_keeper.read_hash_sum(self.DUMMY_UNCHANGEABLE_PACKAGE)
    self.assertEquals(hash_sum, "dummy_hash")

    # Test exception handling
    # If file exists, should rethrow exception
    with patch("os.path.isfile") as isfile_mock:
      isfile_mock.return_value = True
      with patch("__builtin__.open") as open_mock:
        open_mock.side_effect = self.exc_side_effect
        try:
          resource_files_keeper.read_hash_sum("path-to-directory")
          self.fail('KeeperException not thrown')
        except KeeperException:
          pass # Expected
        except Exception, e:
          self.fail('Unexpected exception thrown:' + str(e))
コード例 #18
0
  def test_read_hash_sum(self):
    resource_files_keeper = ResourceFilesKeeper(self.DUMMY_UNCHANGEABLE_PACKAGE)
    hash_sum = resource_files_keeper.read_hash_sum(self.DUMMY_UNCHANGEABLE_PACKAGE)
    self.assertEquals(hash_sum, "dummy_hash")

    # Test exception handling
    # If file exists, should rethrow exception
    with patch("os.path.isfile") as isfile_mock:
      isfile_mock.return_value = True
      with patch("__builtin__.open") as open_mock:
        open_mock.side_effect = self.exc_side_effect
        try:
          resource_files_keeper.read_hash_sum("path-to-directory")
          self.fail('KeeperException not thrown')
        except KeeperException:
          pass # Expected
        except Exception, e:
          self.fail('Unexpected exception thrown:' + str(e))
コード例 #19
0
  def test_list_active_stacks(self, is_active_stack_mock, exists_mock, glob_mock):
    resource_files_keeper = ResourceFilesKeeper(self.SOME_PATH)
    # Test normal execution flow
    glob_mock.return_value = ["stack1", "stack2", "stack3", "stack4", "stack5"]
    exists_mock.side_effect = [True, True, False, True, True]
    is_active_stack_mock.side_effect = [True, False,      False, True]
    res = resource_files_keeper.list_active_stacks(self.SOME_PATH)
    self.assertEquals(pprint.pformat(res), "['stack1', 'stack5']")

    # Test exception handling
    glob_mock.side_effect = self.keeper_exc_side_effect
    try:
      resource_files_keeper.list_active_stacks(self.SOME_PATH)
      self.fail('KeeperException not thrown')
    except KeeperException:
      pass # Expected
    except Exception, e:
      self.fail('Unexpected exception thrown:' + str(e))
コード例 #20
0
  def test_zip_directory(self):
    # Test normal flow
    resource_files_keeper = ResourceFilesKeeper(self.DUMMY_UNCHANGEABLE_PACKAGE)
    resource_files_keeper.zip_directory(self.DUMMY_UNCHANGEABLE_PACKAGE)
    arc_file = os.path.join(self.DUMMY_UNCHANGEABLE_PACKAGE,
                            ResourceFilesKeeper.ARCHIVE_NAME)
    # Arc file should not be empty
    arc_size=os.path.getsize(arc_file)
    self.assertTrue(40000 < arc_size < 50000)
    # After creating zip, count hash sum of dir (should not change)
    hash_val = resource_files_keeper.count_hash_sum(self.DUMMY_UNCHANGEABLE_PACKAGE)
    self.assertEquals(hash_val, self.DUMMY_UNCHANGEABLE_PACKAGE_HASH)
    # Remove arc file
    os.unlink(arc_file)

    # Test exception handling
    with patch("os.path.join") as join_mock:
      join_mock.side_effect = self.exc_side_effect
      try:
        resource_files_keeper.zip_directory("path-to-directory")
        self.fail('KeeperException not thrown')
      except KeeperException:
        pass # Expected
      except Exception, e:
        self.fail('Unexpected exception thrown:' + str(e))
コード例 #21
0
 def test_is_ignored(self):
   resource_files_keeper = ResourceFilesKeeper(self.DUMMY_UNCHANGEABLE_PACKAGE)
   self.assertTrue(resource_files_keeper.is_ignored(".hash"))
   self.assertTrue(resource_files_keeper.is_ignored("archive.zip"))
   self.assertTrue(resource_files_keeper.is_ignored("dummy.pyc"))
   self.assertFalse(resource_files_keeper.is_ignored("dummy.py"))
   self.assertFalse(resource_files_keeper.is_ignored("1.sh"))
コード例 #22
0
  def test_write_hash_sum(self):
    NEW_HASH = "new_hash"
    resource_files_keeper = ResourceFilesKeeper(self.DUMMY_UNCHANGEABLE_PACKAGE)
    resource_files_keeper.write_hash_sum(
      self.DUMMY_UNCHANGEABLE_PACKAGE, NEW_HASH)
    hash_sum = resource_files_keeper.read_hash_sum(self.DUMMY_UNCHANGEABLE_PACKAGE)
    self.assertEquals(hash_sum, NEW_HASH)

    # Revert to previous value
    resource_files_keeper.write_hash_sum(
      self.DUMMY_UNCHANGEABLE_PACKAGE, self.DUMMY_HASH)
    hash_sum = resource_files_keeper.read_hash_sum(self.DUMMY_UNCHANGEABLE_PACKAGE)
    self.assertEquals(hash_sum, self.DUMMY_HASH)

    # Test exception handling
    with patch("__builtin__.open") as open_mock:
      open_mock.side_effect = self.exc_side_effect
      try:
        resource_files_keeper.write_hash_sum("path-to-directory", self.DUMMY_HASH)
        self.fail('KeeperException not thrown')
      except KeeperException:
        pass # Expected
      except Exception, e:
        self.fail('Unexpected exception thrown:' + str(e))
コード例 #23
0
 def test_is_active_stack(self):
   # Test normal flow
   resource_files_keeper = ResourceFilesKeeper(self.DUMMY_UNCHANGEABLE_PACKAGE)
   self.assertTrue(
     resource_files_keeper.is_active_stack(
       os.path.join(self.DUMMY_ACTIVE_STACK, ResourceFilesKeeper.METAINFO_XML)))
   self.assertFalse(
     resource_files_keeper.is_active_stack(
       os.path.join(self.DUMMY_INACTIVE_STACK, ResourceFilesKeeper.METAINFO_XML)))
   # Test exception handling
   with patch("xml.dom.minidom.parse") as parse_mock:
     parse_mock.side_effect = self.exc_side_effect
     try:
       resource_files_keeper.is_active_stack("path-to-xml")
       self.fail('KeeperException not thrown')
     except KeeperException:
       pass # Expected
     except Exception, e:
       self.fail('Unexpected exception thrown:' + str(e))
コード例 #24
0
            self.fail('Unexpected exception thrown:' + str(e))
        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 nozip option
        read_hash_sum_mock.return_value = None
        count_hash_sum_mock.return_value = self.YA_HASH
        resource_files_keeper = ResourceFilesKeeper(self.TEST_RESOURCES_DIR,
                                                    self.SOME_PATH,
                                                    nozip=True)
        resource_files_keeper.update_directory_archive(self.SOME_PATH)
        self.assertTrue(read_hash_sum_mock.called)
        self.assertTrue(count_hash_sum_mock.called)
        self.assertFalse(zip_directory_mock.called)
        self.assertTrue(write_hash_sum_mock.called)
        pass

    def test_count_hash_sum(self):
        # Test normal flow
        resource_files_keeper = ResourceFilesKeeper(
            self.TEST_RESOURCES_DIR, self.DUMMY_UNCHANGEABLE_PACKAGE)
        test_dir = os.path.join(self.DUMMY_UNCHANGEABLE_PACKAGE)
        hash_sum = resource_files_keeper.count_hash_sum(test_dir)
        self.assertEquals(hash_sum, self.DUMMY_UNCHANGEABLE_PACKAGE_HASH)
コード例 #25
0
 def test_perform_housekeeping(self, update_directory_archieves_mock):
     resource_files_keeper = ResourceFilesKeeper("/dummy-resources",
                                                 "/dummy-path")
     resource_files_keeper.perform_housekeeping()
     update_directory_archieves_mock.assertCalled()
     pass
コード例 #26
0
 def test_perform_housekeeping(self, update_directory_archieves_mock):
   resource_files_keeper = ResourceFilesKeeper("/dummy-path")
   resource_files_keeper.perform_housekeeping()
   update_directory_archieves_mock.assertCalled()
コード例 #27
0
    except Exception, e:
      self.fail('Unexpected exception thrown:' + str(e))
    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 nozip option
    read_hash_sum_mock.return_value = None
    count_hash_sum_mock.return_value = self.YA_HASH
    resource_files_keeper = ResourceFilesKeeper(self.SOME_PATH, nozip=True)
    resource_files_keeper.update_directory_archive(self.SOME_PATH)
    self.assertTrue(read_hash_sum_mock.called)
    self.assertTrue(count_hash_sum_mock.called)
    self.assertFalse(zip_directory_mock.called)
    self.assertTrue(write_hash_sum_mock.called)


  def test_count_hash_sum(self):
    # Test normal flow
    resource_files_keeper = ResourceFilesKeeper(self.DUMMY_UNCHANGEABLE_PACKAGE)
    test_dir = os.path.join(self.DUMMY_UNCHANGEABLE_PACKAGE)
    hash_sum = resource_files_keeper.count_hash_sum(test_dir)
    self.assertEquals(hash_sum, self.DUMMY_UNCHANGEABLE_PACKAGE_HASH)

    # Test exception handling