Repository: ambari
Updated Branches:
  refs/heads/trunk 42ae84bbd -> 6734ea3de


AMBARI-8831. Test (and fix if needed) Agents as non-root on SLES and Ubuntu 
(aonishuk)


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

Branch: refs/heads/trunk
Commit: 6734ea3de788f849416c88f2fba52d29a145caae
Parents: 42ae84b
Author: Andrew Onishuk <[email protected]>
Authored: Fri Dec 19 19:35:45 2014 +0200
Committer: Andrew Onishuk <[email protected]>
Committed: Fri Dec 19 19:35:45 2014 +0200

----------------------------------------------------------------------
 .../python/resource_management/TestRepositoryResource.py     | 4 ++--
 .../resource_management/libraries/providers/repository.py    | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6734ea3d/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 4e4871a..3b83c0f 100644
--- a/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
+++ b/ambari-agent/src/test/python/resource_management/TestRepositoryResource.py
@@ -151,7 +151,7 @@ class TestRepositoryResource(TestCase):
       #'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 
APT::Get::List-Cleanup="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', 
'APT::Get::List-Cleanup=0'])
       self.assertEqual(execute_command_item, 'apt-key adv --recv-keys 
--keyserver keyserver.ubuntu.com 123ABCD')
 
     @patch.object(tempfile, "NamedTemporaryFile")
@@ -197,7 +197,7 @@ class TestRepositoryResource(TestCase):
           )
           
       self.assertEqual(str(file_mock.call_args), 
"call('/etc/apt/sources.list.d/HDP.list', action='delete')")
-      self.assertEqual(execute_mock.call_args[0][0], 'apt-get update -qq -o 
Dir::Etc::sourcelist="sources.list.d/HDP.list" -o APT::Get::List-Cleanup="0"')
+      self.assertEqual(execute_mock.call_args[0][0], ['apt-get', 'update', 
'-qq', '-o', 'Dir::Etc::sourcelist=sources.list.d/HDP.list', '-o', 
'APT::Get::List-Cleanup=0'])
 
     @patch("os.path.isfile", new=MagicMock(return_value=False))
     @patch.object(System, "os_family", new='ubuntu')

http://git-wip-us.apache.org/repos/asf/ambari/blob/6734ea3d/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 fc95fb3..c055c8c 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
@@ -54,7 +54,7 @@ repos_dirs = {
 class UbuntuRepositoryProvider(Provider):
   package_type = "deb"
   repo_dir = "/etc/apt/sources.list.d"
-  update_cmd = 'apt-get update -qq -o 
Dir::Etc::sourcelist="sources.list.d/{repo_file_name}" -o 
APT::Get::List-Cleanup="0"'
+  update_cmd = ['apt-get', 'update', '-qq', '-o', 
'Dir::Etc::sourcelist=sources.list.d/{repo_file_name}', '-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 (.+)"
   add_pkey_cmd = "apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 
{pkey}"
 
@@ -74,8 +74,9 @@ class UbuntuRepositoryProvider(Provider):
                content = StaticFile(tmpf.name)
           )
           
+          update_cmd_formatted = [format(x) for x in self.update_cmd]
           # this is time expensive
-          retcode, out = checked_call(format(self.update_cmd))
+          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))
@@ -95,4 +96,5 @@ class UbuntuRepositoryProvider(Provider):
              action = "delete")
         
         # this is time expensive
-        Execute(format(self.update_cmd))
+        update_cmd_formatted = [format(x) for x in self.update_cmd]
+        Execute(update_cmd_formatted)

Reply via email to