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

ambari git commit: AMBARI-14217: RU: Spark install failed after upgrade (Dmitro Lisnichenko via jluniya)

Repository: ambari
Updated Branches:
  refs/heads/trunk 858d3fc11 -> 751cb1439


AMBARI-14217: RU: Spark install failed after upgrade (Dmitro Lisnichenko via jluniya)


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

Branch: refs/heads/trunk
Commit: 751cb14399a6527f342284b5130515d24ea3711d
Parents: 858d3fc
Author: Jayush Luniya <jl...@hortonworks.com>
Authored: Mon Dec 7 21:41:14 2015 -0800
Committer: Jayush Luniya <jl...@hortonworks.com>
Committed: Mon Dec 7 21:41:14 2015 -0800

----------------------------------------------------------------------
 .../TestRepositoryResource.py                   | 50 +++++++++++++++++++-
 .../libraries/providers/repository.py           | 37 +++++++++++----
 2 files changed, 76 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/751cb143/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
index b3e2291..a69b57b 100644
--- a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
@@ -136,7 +136,55 @@ class TestRepositoryResource(TestCase):
 
             self.assertEqual(expected_template_arguments, template_item.context._dict)
             self.assertEqual(RHEL_SUSE_DEFAULT_TEMPLATE, template)
-    
+
+
+    @patch.object(OSCheck, "is_suse_family")
+    @patch.object(OSCheck, "is_ubuntu_family")
+    @patch.object(OSCheck, "is_redhat_family")
+    @patch.object(System, "os_family", new='suse')
+    @patch("resource_management.libraries.providers.repository.File")
+    @patch("resource_management.libraries.providers.repository.checked_call")
+    @patch("resource_management.core.sudo.read_file")
+    @patch("os.path.isfile", new=MagicMock(return_value=True))
+    def test_recreate_repo_suse(self, read_file_mock, checked_call_mock, file_mock,
+                              is_redhat_family, is_ubuntu_family, is_suse_family):
+        is_redhat_family.return_value = False
+        is_ubuntu_family.return_value = False
+        is_suse_family.return_value = True
+        read_file_mock.return_value = "Dummy repo file contents"
+        checked_call_mock.return_value = 0, "Flushing zypper cache"
+        with Environment('/') as env:
+          with patch.object(repository, "__file__", new='/ambari/test/repo/dummy/path/file'):
+            # Check that zypper cache is flushed
+            Repository('hadoop',
+                       base_url='http://download.base_url.org/rpm/',
+                       mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                       repo_template = RHEL_SUSE_DEFAULT_TEMPLATE,
+                       repo_file_name='Repository')
+
+            self.assertTrue(checked_call_mock.called)
+
+            expected_repo_file_content = "[hadoop]\nname=hadoop\nmirrorlist=https://mirrors.base_url.org/?repo=Repository&arch=$basearch\n\npath=/\nenabled=1\ngpgcheck=0"
+            template = file_mock.call_args[1]['content']
+            self.assertEqual(expected_repo_file_content, template)
+
+            # Check that if content is equal, zypper cache is not flushed
+            checked_call_mock.reset_mock()
+            read_file_mock.return_value = expected_repo_file_content
+
+            Repository('hadoop',
+                       base_url='http://download.base_url.org/rpm/',
+                       mirror_list='https://mirrors.base_url.org/?repo=Repository&arch=$basearch',
+                       repo_template = RHEL_SUSE_DEFAULT_TEMPLATE,
+                       repo_file_name='Repository')
+
+            self.assertFalse(checked_call_mock.called)
+
+            expected_repo_file_content = "[hadoop]\nname=hadoop\nmirrorlist=https://mirrors.base_url.org/?repo=Repository&arch=$basearch\n\npath=/\nenabled=1\ngpgcheck=0"
+            template = file_mock.call_args[1]['content']
+            self.assertEqual(expected_repo_file_content, template)
+
+
     @patch.object(OSCheck, "is_suse_family")
     @patch.object(OSCheck, "is_ubuntu_family")
     @patch.object(OSCheck, "is_redhat_family")

http://git-wip-us.apache.org/repos/asf/ambari/blob/751cb143/ambari-common/src/main/python/resource_management/libraries/providers/repository.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/providers/repository.py b/ambari-common/src/main/python/resource_management/libraries/providers/repository.py
index 11002cc..5f0c089 100644
--- a/ambari-common/src/main/python/resource_management/libraries/providers/repository.py
+++ b/ambari-common/src/main/python/resource_management/libraries/providers/repository.py
@@ -33,11 +33,16 @@ from resource_management.libraries.functions.format import format
 from resource_management.core.environment import Environment
 from resource_management.core.shell import checked_call
 from resource_management.core import sudo
+from resource_management.core.logger import Logger
 import re
 
 REPO_TEMPLATE_FOLDER = 'data'
 
+
 class RhelSuseRepositoryProvider(Provider):
+
+  update_cmd = ['zypper', 'clean', '--all']
+
   def action_create(self):
     with Environment.get_instance_copy() as env:
       repo_file_name = self.resource.repo_file_name
@@ -45,12 +50,23 @@ class RhelSuseRepositoryProvider(Provider):
       new_content = InlineTemplate(self.resource.repo_template, repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name,
                              base_url=self.resource.base_url, mirror_list=self.resource.mirror_list)
       repo_file_path = format("{repo_dir}/{repo_file_name}.repo")
-      if self.resource.append_to_file and os.path.isfile(repo_file_path):
-        content = sudo.read_file(repo_file_path) + '\n' + new_content.get_content()
-      else:
+
+      if os.path.isfile(repo_file_path):
+        existing_content_str = sudo.read_file(repo_file_path)
+        new_content_str = new_content.get_content()
+        if existing_content_str != new_content_str and OSCheck.is_suse_family():
+          # We need to reset package manager's cache when we replace base urls
+          # at existing repo. That is a case at least under SLES
+          Logger.info("Flushing package manager cache since repo file content is about to change")
+          checked_call(self.update_cmd, sudo=True)
+        if self.resource.append_to_file:
+          content = existing_content_str + '\n' + new_content_str
+        else:
+          content = new_content_str
+      else: # If repo file does not exist yet
         content = new_content
-        
-      File(repo_file_path, 
+
+      File(repo_file_path,
            content=content
       )
   
@@ -60,7 +76,7 @@ class RhelSuseRepositoryProvider(Provider):
       repo_dir = get_repo_dir()
 
       File(format("{repo_dir}/{repo_file_name}.repo"),
-           action = "delete")
+           action="delete")
     
   
 def get_repo_dir():
@@ -69,6 +85,7 @@ def get_repo_dir():
   elif OSCheck.is_suse_family():
     return '/etc/zypp/repos.d'
 
+
 class UbuntuRepositoryProvider(Provider):
   package_type = "deb"
   repo_dir = "/etc/apt/sources.list.d"
@@ -80,8 +97,8 @@ class UbuntuRepositoryProvider(Provider):
     with Environment.get_instance_copy() as env:
       with tempfile.NamedTemporaryFile() as tmpf:
         with tempfile.NamedTemporaryFile() as old_repo_tmpf:
-          repo_file_name = format("{repo_file_name}.list",repo_file_name = self.resource.repo_file_name)
-          repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir = self.repo_dir)
+          repo_file_name = format("{repo_file_name}.list",repo_file_name=self.resource.repo_file_name)
+          repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir=self.repo_dir)
   
           new_content = InlineTemplate(self.resource.repo_template, package_type=self.package_type,
                                         base_url=self.resource.base_url,
@@ -120,8 +137,8 @@ class UbuntuRepositoryProvider(Provider):
   
   def action_remove(self):
     with Environment.get_instance_copy() as env:
-      repo_file_name = format("{repo_file_name}.list",repo_file_name = self.resource.repo_file_name)
-      repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir = self.repo_dir)
+      repo_file_name = format("{repo_file_name}.list", repo_file_name=self.resource.repo_file_name)
+      repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir=self.repo_dir)
       
       if os.path.isfile(repo_file_path):
         File(repo_file_path,