Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9F1F910886 for ; Thu, 20 Mar 2014 19:26:29 +0000 (UTC) Received: (qmail 4852 invoked by uid 500); 20 Mar 2014 19:26:29 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 4825 invoked by uid 500); 20 Mar 2014 19:26:28 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 4813 invoked by uid 99); 20 Mar 2014 19:26:28 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Mar 2014 19:26:28 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id D58AE986BA9; Thu, 20 Mar 2014 19:26:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dmitriusan@apache.org To: commits@ambari.apache.org Message-Id: <2a80535382514f51877c076f8cc47e7f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: AMBARI-5164. Warning logs for missing .hash files in the agent logs (dlysnichenko) Date: Thu, 20 Mar 2014 19:26:27 +0000 (UTC) Repository: ambari Updated Branches: refs/heads/trunk 112c758df -> b73aca825 AMBARI-5164. Warning logs for missing .hash files in the agent logs (dlysnichenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b73aca82 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b73aca82 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b73aca82 Branch: refs/heads/trunk Commit: b73aca82558159bf104457f6724aa0dc41647791 Parents: 112c758 Author: Lisnichenko Dmitro Authored: Thu Mar 20 21:24:51 2014 +0200 Committer: Lisnichenko Dmitro Committed: Thu Mar 20 21:24:51 2014 +0200 ---------------------------------------------------------------------- .../python/ambari_server/resourceFilesKeeper.py | 58 ++++---------------- .../src/test/python/TestResourceFilesKeeper.py | 38 +++---------- 2 files changed, 18 insertions(+), 78 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b73aca82/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 ba2fdf2..1e1bdb6 100644 --- a/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py +++ b/ambari-server/src/main/python/ambari_server/resourceFilesKeeper.py @@ -76,10 +76,10 @@ class ResourceFilesKeeper(): """ stacks_root = os.path.join(self.resources_dir, self.STACKS_DIR) self.dbg_out("Updating archives for stack dirs at {0}...".format(stacks_root)) - active_stacks = self.list_active_stacks(stacks_root) - self.dbg_out("Active stacks: {0}".format(pprint.pformat(active_stacks))) - # Iterate over active stack directories - for stack_dir in active_stacks: + valid_stacks = self.list_stacks(stacks_root) + self.dbg_out("Stacks: {0}".format(pprint.pformat(valid_stacks))) + # Iterate over stack directories + for stack_dir in valid_stacks: for root, dirs, _ in os.walk(stack_dir): for d in dirs: if d in self.ARCHIVABLE_DIRS: @@ -95,21 +95,21 @@ class ResourceFilesKeeper(): - def list_active_stacks(self, stacks_root): + def list_stacks(self, stacks_root): """ - Builds a list of stack directories, that are active (enabled) + Builds a list of stack directories """ - active_stacks = [] # Format: + valid_stacks = [] # Format: glob_pattern = "{0}/*/*".format(stacks_root) try: stack_dirs = glob.glob(glob_pattern) for directory in stack_dirs: metainfo_file = os.path.join(directory, self.METAINFO_XML) - if os.path.exists(metainfo_file) and self.is_active_stack(metainfo_file): - active_stacks.append(directory) - return active_stacks + if os.path.exists(metainfo_file): + valid_stacks.append(directory) + return valid_stacks except Exception, err: - raise KeeperException("Can not list active stacks: {0}".format(str(err))) + raise KeeperException("Can not list stacks: {0}".format(str(err))) def update_directory_archive(self, directory): @@ -225,42 +225,6 @@ class ResourceFilesKeeper(): print text - def is_active_stack(self, xmlfile): - try: - xmldoc = minidom.parse(xmlfile) - value = self.xpath_like_bycicle(xmldoc, ['metainfo', 'versions', 'active']) - return value.lower().strip() == 'true' - except Exception, err: - raise KeeperException("Can not parse XML file {0} : {1}", - xmlfile, str(err)) - - - def xpath_like_bycicle(self, xml_doc, path): - # Default Python 2.6 distribution have no good XPATH support, - # implementing own bycicle here - cur_elem = xml_doc - for name in path: - elem = self.find_xml_element_by_name(cur_elem._get_childNodes(), name) - if name: - cur_elem = elem - else: - return None - # Select text in tags - value = cur_elem._get_childNodes()[0].nodeValue - if value: - return value.lower().strip() - else: - return None - - - def find_xml_element_by_name(self, elements, element_name): - for xml_element in elements: - if xml_element.nodeType == xml_element.ELEMENT_NODE and \ - xml_element.nodeName == element_name: - return xml_element - return None - - def main(argv=None): """ This method is called by maven during rpm creation. http://git-wip-us.apache.org/repos/asf/ambari/blob/b73aca82/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 5c9e30f..a62cbb9 100644 --- a/ambari-server/src/test/python/TestResourceFilesKeeper.py +++ b/ambari-server/src/test/python/TestResourceFilesKeeper.py @@ -66,7 +66,7 @@ class TestResourceFilesKeeper(TestCase): @patch.object(ResourceFilesKeeper, "update_directory_archive") - @patch.object(ResourceFilesKeeper, "list_active_stacks") + @patch.object(ResourceFilesKeeper, "list_stacks") @patch("os.path.abspath") def test_update_directory_archieves(self, abspath_mock, list_active_stacks_mock, @@ -91,20 +91,18 @@ class TestResourceFilesKeeper(TestCase): @patch("glob.glob") @patch("os.path.exists") - @patch.object(ResourceFilesKeeper, "is_active_stack") - def test_list_active_stacks(self, is_active_stack_mock, exists_mock, glob_mock): + 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", "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']") + 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_active_stacks(self.SOME_PATH) + resource_files_keeper.list_stacks(self.SOME_PATH) self.fail('KeeperException not thrown') except KeeperException: pass # Expected @@ -304,28 +302,6 @@ class TestResourceFilesKeeper(TestCase): self.assertFalse(resource_files_keeper.is_ignored("1.sh")) - 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)) - - - def exc_side_effect(self, *a): raise Exception("horrible_exc")