You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/11/16 23:08:12 UTC

ambari git commit: AMBARI-13748. Being able to clean repository cache before installing open source components (Di Li via alejandro)

Repository: ambari
Updated Branches:
  refs/heads/trunk 364cee597 -> 5d35c6db7


AMBARI-13748. Being able to clean repository cache before installing open source components (Di Li via alejandro)


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

Branch: refs/heads/trunk
Commit: 5d35c6db7c3e7aac7aa870d392a414814003f9f9
Parents: 364cee5
Author: Alejandro Fernandez <af...@hortonworks.com>
Authored: Mon Nov 16 14:06:56 2015 -0800
Committer: Alejandro Fernandez <af...@hortonworks.com>
Committed: Mon Nov 16 14:07:17 2015 -0800

----------------------------------------------------------------------
 .../system_action_definitions.xml               | 10 ++++
 .../custom_actions/scripts/clear_repocache.py   | 56 ++++++++++++++++++++
 .../python/custom_actions/TestClearRepoCache.py | 53 ++++++++++++++++++
 3 files changed, 119 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5d35c6db/ambari-server/src/main/resources/custom_action_definitions/system_action_definitions.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_action_definitions/system_action_definitions.xml b/ambari-server/src/main/resources/custom_action_definitions/system_action_definitions.xml
index e725d68..6304baf 100644
--- a/ambari-server/src/main/resources/custom_action_definitions/system_action_definitions.xml
+++ b/ambari-server/src/main/resources/custom_action_definitions/system_action_definitions.xml
@@ -40,6 +40,16 @@
     <targetType>ALL</targetType>
   </actionDefinition>
   <actionDefinition>
+    <actionName>clear_repocache</actionName>
+    <actionType>SYSTEM</actionType>
+    <inputs/>
+    <targetService/>
+    <targetComponent/>
+    <defaultTimeout>60</defaultTimeout>
+    <description>Clear repository cache on hosts</description>
+    <targetType>ALL</targetType>
+  </actionDefinition>
+  <actionDefinition>
     <actionName>validate_configs</actionName>
     <actionType>SYSTEM</actionType>
     <inputs/>

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d35c6db/ambari-server/src/main/resources/custom_actions/scripts/clear_repocache.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/scripts/clear_repocache.py b/ambari-server/src/main/resources/custom_actions/scripts/clear_repocache.py
new file mode 100644
index 0000000..8fabc18
--- /dev/null
+++ b/ambari-server/src/main/resources/custom_actions/scripts/clear_repocache.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Ambari Agent
+
+"""
+from resource_management import Script, Execute, format
+from ambari_commons.os_check import OSCheck
+from resource_management.core import shell
+from resource_management.core.logger import Logger
+
+class ClearRepoCache(Script):
+
+  def actionexecute(self, env):
+    config = Script.get_config()
+    structured_output = {}
+    cmd = self.get_clearcache_cmd()
+
+    Logger.info("Clearing repository cache")
+    code, output = shell.call(cmd, sudo = True)
+    if 0 == code:
+      structured_output["clear_repocache"] = {"exit_code" : 0, "message": format("Repository cache successfully cleared!")}
+    else:
+      structured_output["clear_repocache"] = {"exit_code": code, "message": "Failed to clear repository cache! {0}".format(str(output))}
+    self.put_structured_out(structured_output)
+
+  def get_clearcache_cmd(self):
+    if OSCheck.is_redhat_family():
+      Logger.info("Clear repository cache for the RedHat OS family");
+      return ("/usr/bin/yum", "clean", "all")
+    elif OSCheck.is_suse_family():
+      Logger.info("Clear repository cache for the SUSE OS family");
+      return ('/usr/bin/zypper', 'refresh')
+    elif OSCheck.is_ubuntu_family():
+      Logger.info("Clear repository cache for the Ubuntu OS family");
+      return ('/usr/bin/apt-get', 'update')
+    else:
+      raise Exception("Unsupported OS family: '{0}' ".format(OSCheck.get_os_family()))
+
+if __name__ == "__main__":
+  ClearRepoCache().execute()

http://git-wip-us.apache.org/repos/asf/ambari/blob/5d35c6db/ambari-server/src/test/python/custom_actions/TestClearRepoCache.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/custom_actions/TestClearRepoCache.py b/ambari-server/src/test/python/custom_actions/TestClearRepoCache.py
new file mode 100644
index 0000000..1cd4a8f
--- /dev/null
+++ b/ambari-server/src/test/python/custom_actions/TestClearRepoCache.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Ambari Agent
+
+"""
+import os, sys
+
+from mock.mock import patch
+from mock.mock import MagicMock
+from unittest import TestCase
+
+from resource_management import *
+from resource_management import Script
+
+from ambari_commons.os_check import OSCheck
+from clear_repocache import ClearRepoCache
+
+class TestClearRepoCache(TestCase):
+
+
+  @patch.object(OSCheck, "is_suse_family")
+  @patch.object(OSCheck, "is_ubuntu_family")
+  @patch.object(OSCheck, "is_redhat_family")
+  @patch.object(Script, 'get_config')
+  @patch("resource_management.libraries.providers.repository.File")
+  @patch("resource_management.libraries.script.Script.put_structured_out")
+  @patch.object(System, "os_family", new='redhat')
+  def testClearRepoCache(self, structured_out_mock, file_mock, mock_config, is_redhat_mock, is_ubuntu_mock, is_suse_mock):
+    is_suse_mock.return_value = False
+    is_ubuntu_mock.return_value = False
+    is_redhat_mock.return_value = True
+    clearRepoCache = ClearRepoCache()
+
+    with Environment("/", test_mode=True) as env:
+      clearRepoCache.actionexecute(None)
+
+    self.assertTrue(structured_out_mock.called)