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

[2/2] ambari git commit: AMBARI-12938. Accumulo Install failed on Ubuntu or Debian using non-root and umask 027 (aonishuk)

AMBARI-12938. Accumulo Install failed on Ubuntu or Debian using non-root and umask 027 (aonishuk)


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

Branch: refs/heads/branch-2.1
Commit: 5618e3312a2e92186b2dca771f9d2fe19c0cb346
Parents: 2b75832
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Mon Aug 31 16:40:26 2015 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Mon Aug 31 16:40:26 2015 +0300

----------------------------------------------------------------------
 .../TestRepositoryResource.py                   | 18 +++---
 .../libraries/providers/repository.py           | 62 ++++++++++++--------
 2 files changed, 47 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5618e331/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 0f30178..8f2b55a 100644
--- a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
@@ -166,13 +166,15 @@ class TestRepositoryResource(TestCase):
       self.assertEquals(template_name, '/tmp/1.txt')
       self.assertEquals(template_content, 'deb http://download.base_url.org/rpm/ a b c')
       
-      copy_item = str(file_mock.call_args_list[1])
-      self.assertEqual(copy_item, "call('/etc/apt/sources.list.d/HDP.list', content=StaticFile('/tmp/1.txt'))")
+      copy_item0 = str(file_mock.call_args_list[1])
+      copy_item1 = str(file_mock.call_args_list[2])
+      self.assertEqual(copy_item0, "call('/tmp/1.txt', content=StaticFile('/etc/apt/sources.list.d/HDP.list'))")
+      self.assertEqual(copy_item1, "call('/etc/apt/sources.list.d/HDP.list', content=StaticFile('/tmp/1.txt'))")
       #'apt-get update -qq -o Dir::Etc::sourcelist="sources.list.d/HDP.list" -o APT::Get::List-Cleanup="0"')
       execute_command_item = execute_mock.call_args_list[0][0][0]
 
       self.assertEqual(checked_call_mock.call_args_list[0][0][0], ['apt-get', 'update', '-qq', '-o', 'Dir::Etc::sourcelist=sources.list.d/HDP.list', '-o', 'Dir::Etc::sourceparts=-', '-o', 'APT::Get::List-Cleanup=0'])
-      self.assertEqual(execute_command_item, 'apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 123ABCD')
+      self.assertEqual(execute_command_item, ('apt-key', 'adv', '--recv-keys', '--keyserver', 'keyserver.ubuntu.com', '123ABCD'))
 
     @patch("resource_management.libraries.providers.repository.checked_call")
     @patch.object(tempfile, "NamedTemporaryFile")
@@ -207,12 +209,14 @@ class TestRepositoryResource(TestCase):
       self.assertEquals(template_name, '/tmp/1.txt')
       self.assertEquals(template_content, 'deb http://download.base_url.org/rpm/ a b c')
 
-      copy_item = str(file_mock.call_args_list[1])
-      self.assertEqual(copy_item, "call('/etc/apt/sources.list.d/HDP.list', content=StaticFile('/tmp/1.txt'))")
+      copy_item0 = str(file_mock.call_args_list[1])
+      copy_item1 = str(file_mock.call_args_list[2])
+      self.assertEqual(copy_item0, "call('/tmp/1.txt', content=StaticFile('/etc/apt/sources.list.d/HDP.list'))")
+      self.assertEqual(copy_item1, "call('/etc/apt/sources.list.d/HDP.list', content=StaticFile('/tmp/1.txt'))")
       execute_command_item = execute_mock.call_args_list[0][0][0]
 
       self.assertEqual(checked_call_mock.call_args_list[0][0][0], ['apt-get', 'update', '-qq', '-o', 'Dir::Etc::sourcelist=sources.list.d/HDP.list', '-o', 'Dir::Etc::sourceparts=-', '-o', 'APT::Get::List-Cleanup=0'])
-      self.assertEqual(execute_command_item, 'apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 123ABCD')
+      self.assertEqual(execute_command_item, ('apt-key', 'adv', '--recv-keys', '--keyserver', 'keyserver.ubuntu.com', '123ABCD'))
 
     @patch.object(tempfile, "NamedTemporaryFile")
     @patch("resource_management.libraries.providers.repository.Execute")
@@ -241,7 +245,7 @@ class TestRepositoryResource(TestCase):
       self.assertEquals(template_name, '/tmp/1.txt')
       self.assertEquals(template_content, 'deb http://download.base_url.org/rpm/ a b c')
       
-      self.assertEqual(file_mock.call_count, 1)
+      self.assertEqual(file_mock.call_count, 2)
       self.assertEqual(execute_mock.call_count, 0)
       
     

http://git-wip-us.apache.org/repos/asf/ambari/blob/5618e331/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 2faa7c1..11002cc 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
@@ -74,39 +74,49 @@ class UbuntuRepositoryProvider(Provider):
   repo_dir = "/etc/apt/sources.list.d"
   update_cmd = ['apt-get', 'update', '-qq', '-o', 'Dir::Etc::sourcelist=sources.list.d/{repo_file_name}', '-o', 'Dir::Etc::sourceparts=-', '-o', 'APT::Get::List-Cleanup=0']
   missing_pkey_regex = "The following signatures couldn't be verified because the public key is not available: NO_PUBKEY ([A-Z0-9]+)"
-  add_pkey_cmd = "apt-key adv --recv-keys --keyserver keyserver.ubuntu.com {pkey}"
+  app_pkey_cmd_prefix = ('apt-key', 'adv', '--recv-keys', '--keyserver', 'keyserver.ubuntu.com')
 
   def action_create(self):
     with Environment.get_instance_copy() as env:
       with tempfile.NamedTemporaryFile() as 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)
-
-        new_content = InlineTemplate(self.resource.repo_template, package_type=self.package_type,
-                                      base_url=self.resource.base_url,
-                                      components=' '.join(self.resource.components)).get_content()
-        old_content = ''
-        if self.resource.append_to_file and os.path.isfile(repo_file_path):
-            old_content = sudo.read_file(repo_file_path) + '\n'
-
-        File(tmpf.name, content=old_content+new_content)
-
-        if not os.path.isfile(repo_file_path) or not filecmp.cmp(tmpf.name, repo_file_path):
-          File(repo_file_path,
-               content = StaticFile(tmpf.name)
+        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)
+  
+          new_content = InlineTemplate(self.resource.repo_template, package_type=self.package_type,
+                                        base_url=self.resource.base_url,
+                                        components=' '.join(self.resource.components)).get_content()
+          old_content = ''
+          if self.resource.append_to_file and os.path.isfile(repo_file_path):
+              old_content = sudo.read_file(repo_file_path) + '\n'
+  
+          File(tmpf.name, 
+               content=old_content+new_content
           )
           
-          update_cmd_formatted = [format(x) for x in self.update_cmd]
-          # this is time expensive
-          retcode, out = checked_call(update_cmd_formatted, sudo=True)
-          
-          # add public keys for new repos
-          missing_pkeys = set(re.findall(self.missing_pkey_regex, out))
-          for pkey in missing_pkeys:
-            Execute(format(self.add_pkey_cmd),
-                    timeout = 15, # in case we are on the host w/o internet (using localrepo), we should ignore hanging
-                    ignore_failures = True
+          if os.path.isfile(repo_file_path):
+            # a copy of old repo file, which will be readable by current user
+            File(old_repo_tmpf.name, 
+                 content=StaticFile(repo_file_path),
+            )
+  
+          if not os.path.isfile(repo_file_path) or not filecmp.cmp(tmpf.name, old_repo_tmpf.name):
+            File(repo_file_path,
+                 content = StaticFile(tmpf.name)
             )
+            
+            update_cmd_formatted = [format(x) for x in self.update_cmd]
+            # this is time expensive
+            retcode, out = checked_call(update_cmd_formatted, sudo=True, quiet=False)
+            
+            # add public keys for new repos
+            missing_pkeys = set(re.findall(self.missing_pkey_regex, out))
+            for pkey in missing_pkeys:
+              Execute(self.app_pkey_cmd_prefix + (pkey,),
+                      timeout = 15, # in case we are on the host w/o internet (using localrepo), we should ignore hanging
+                      ignore_failures = True,
+                      sudo = True,
+              )
   
   def action_remove(self):
     with Environment.get_instance_copy() as env: