incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject git commit: AMBARI-2719. Passwordless sudo bootstrap scenario is broken. (Dmitry Lysnichenko via smohanty)
Date Thu, 25 Jul 2013 17:38:38 GMT
Updated Branches:
  refs/heads/branch-1.2.5 8e29058bc -> f46939a8f


AMBARI-2719. Passwordless sudo bootstrap scenario is broken. (Dmitry Lysnichenko via smohanty)


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

Branch: refs/heads/branch-1.2.5
Commit: f46939a8fb23b7a36b0acf415dfc35d6e806884e
Parents: 8e29058
Author: Sumit Mohanty <smohanty@hortonworks.com>
Authored: Thu Jul 25 10:37:34 2013 -0700
Committer: Sumit Mohanty <smohanty@hortonworks.com>
Committed: Thu Jul 25 10:37:34 2013 -0700

----------------------------------------------------------------------
 ambari-server/src/main/python/bootstrap.py     | 32 +++++++++++++++++-
 ambari-server/src/test/python/TestBootstrap.py | 36 +++++++++++++++++++--
 2 files changed, 65 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/f46939a8/ambari-server/src/main/python/bootstrap.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/bootstrap.py b/ambari-server/src/main/python/bootstrap.py
index 407374e..35e6715 100755
--- a/ambari-server/src/main/python/bootstrap.py
+++ b/ambari-server/src/main/python/bootstrap.py
@@ -342,6 +342,23 @@ class BootStrap:
   def hasPassword(self):
     return self.passwordFile is not None and self.passwordFile != 'null'
 
+  def getMoveRepoFileWithPasswordCommand(self, targetDir):
+    return "sudo -S mv " + str(self.getRemoteName(self.AMBARI_REPO_FILENAME))\
+           + " " + os.path.join(str(targetDir), self.AMBARI_REPO_FILENAME) + \
+           " < " + str(self.getPasswordFile())
+
+
+  def getMoveRepoFileWithoutPasswordCommand(self, targetDir):
+    return "sudo mv " + str(self.getRemoteName(self.AMBARI_REPO_FILENAME)) +\
+            " " + os.path.join(str(targetDir), self.AMBARI_REPO_FILENAME)
+
+  def getMoveRepoFileCommand(self, targetDir):
+    if self.hasPassword():
+      return self.getMoveRepoFileWithPasswordCommand(targetDir)
+    else:
+      return self.getMoveRepoFileWithoutPasswordCommand(targetDir)
+
+
 
   def copyOsCheckScript(self):
     try:
@@ -374,7 +391,7 @@ class BootStrap:
     try:
       # Copying the files
       fileToCopy = self.getRepoFile()
-      target = self.getRepoFile()
+      target = self.getRemoteName(self.AMBARI_REPO_FILENAME)
       logging.info("Copying repo file to 'tmp' folder...")
       pscp = PSCP(self.successive_hostlist, self.user, self.sshkeyFile, fileToCopy, target,
self.bootdir)
       pscp.run()
@@ -389,6 +406,19 @@ class BootStrap:
       self.statuses = unite_statuses(self.statuses, out)
 
       logging.info("Moving repo file...")
+      targetDir = self.getRepoDir()
+      command = self.getMoveRepoFileCommand(targetDir)
+      pssh = PSSH(self.successive_hostlist, self.user, self.sshkeyFile, self.bootdir, command=command)
+      pssh.run()
+      out = pssh.getstatus()
+      # Preparing report about failed hosts
+      failed_current = get_difference(self.successive_hostlist, skip_failed_hosts(out))
+      self.successive_hostlist = skip_failed_hosts(out)
+      failed = get_difference(self.hostlist, self.successive_hostlist)
+      logging.info("Parallel scp returns for moving repo file. All failed hosts are: " +
str(failed) +
+                   ". Failed on last step: " + str(failed_current))
+      #updating statuses
+      self.statuses = unite_statuses(self.statuses, out)
 
       target = self.getRemoteName(self.SETUP_SCRIPT_FILENAME)
       pscp = PSCP(self.successive_hostlist, self.user, self.sshkeyFile, self.setupAgentFile,
target, self.bootdir)

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/f46939a8/ambari-server/src/test/python/TestBootstrap.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestBootstrap.py b/ambari-server/src/test/python/TestBootstrap.py
index 5288f65..076bc64 100644
--- a/ambari-server/src/test/python/TestBootstrap.py
+++ b/ambari-server/src/test/python/TestBootstrap.py
@@ -358,7 +358,9 @@ class TestBootstrap(TestCase):
   @patch.object(Popen, "communicate")
   @patch.object(BootStrap, "createDoneFiles")
   @patch.object(BootStrap, "getRunSetupWithPasswordCommand")
-  def test_commands_with_password_are_called_for_user_with_password(self, getRunSetupWithPasswordCommand_method,
+  @patch.object(BootStrap, "getMoveRepoFileWithPasswordCommand")
+  def test_commands_with_password_are_called_for_user_with_password(self, getMoveRepoFileWithPasswordCommand_method,
+                                                                    getRunSetupWithPasswordCommand_method,
                                                                     createDoneFiles_method,
                                                                     communicate_method,
                                                                     SSH_writeLogToFile_method,
@@ -371,6 +373,7 @@ class TestBootstrap(TestCase):
     createDoneFiles_method.return_value = None
 
     getRunSetupWithPasswordCommand_method.return_value = ""
+    getMoveRepoFileWithPasswordCommand_method.return_value = ""
 
     os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
     hosts = ["hostname"]
@@ -383,11 +386,15 @@ class TestBootstrap(TestCase):
     bootstrap_obj.successive_hostlist = hosts
     bootstrap_obj.runSetupAgent()
     self.assertTrue(getRunSetupWithPasswordCommand_method.called)
+    self.assertTrue(getMoveRepoFileWithPasswordCommand_method.called)
     getRunSetupWithPasswordCommand_method.reset()
+    getMoveRepoFileWithPasswordCommand_method.reset()
     getRunSetupWithPasswordCommand_method.reset()
+    getMoveRepoFileWithPasswordCommand_method.reset()
     bootstrap_obj.successive_hostlist = None
     bootstrap_obj.copyOsCheckScript()
     self.assertTrue(getRunSetupWithPasswordCommand_method.called)
+    self.assertTrue(getMoveRepoFileWithPasswordCommand_method.called)
 
   @patch.object(bootstrap, "get_difference")
   @patch.object(SCP, "writeLogToFile")
@@ -395,7 +402,9 @@ class TestBootstrap(TestCase):
   @patch.object(Popen, "communicate")
   @patch.object(BootStrap, "createDoneFiles")
   @patch.object(BootStrap, "getRunSetupWithoutPasswordCommand")
-  def test_commands_without_password_are_called_for_passwordless_user(self, getRunSetupWithoutPasswordCommand_method,
+  @patch.object(BootStrap, "getMoveRepoFileWithoutPasswordCommand")
+  def test_commands_without_password_are_called_for_passwordless_user(self, getMoveRepoFileWithoutPasswordCommand_method,
+                                                                      getRunSetupWithoutPasswordCommand_method,
                                                                       createDoneFiles_method,
                                                                       communicate_method,
                                                                       SSH_writeLogToFile_method,
@@ -407,6 +416,7 @@ class TestBootstrap(TestCase):
     createDoneFiles_method.return_value = None
 
     getRunSetupWithoutPasswordCommand_method.return_value = ""
+    getMoveRepoFileWithoutPasswordCommand_method.return_value = ""
 
     os.environ[AMBARI_PASSPHRASE_VAR_NAME] = ""
     hosts = ["hostname"]
@@ -419,16 +429,21 @@ class TestBootstrap(TestCase):
     bootstrap_obj.successive_hostlist = hosts
     bootstrap_obj.runSetupAgent()
     self.assertTrue(getRunSetupWithoutPasswordCommand_method.called)
+    self.assertTrue(getMoveRepoFileWithoutPasswordCommand_method.called)
     getRunSetupWithoutPasswordCommand_method.reset()
+    getMoveRepoFileWithoutPasswordCommand_method.reset()
 
     get_difference_mock.return_value = None
     self.assertTrue(bootstrap_obj.copyNeededFiles() == 0)
     self.assertTrue(getRunSetupWithoutPasswordCommand_method.called)
+    self.assertTrue(getMoveRepoFileWithoutPasswordCommand_method.called)
     getRunSetupWithoutPasswordCommand_method.reset()
+    getMoveRepoFileWithoutPasswordCommand_method.reset()
 
     bootstrap_obj.successive_hostlist = None
     bootstrap_obj.copyNeededFiles()
     self.assertTrue(getRunSetupWithoutPasswordCommand_method.called)
+    self.assertTrue(getMoveRepoFileWithoutPasswordCommand_method.called)
 
   @patch.object(BootStrap, "runSetupAgent")
   @patch.object(BootStrap, "copyNeededFiles")
@@ -631,6 +646,23 @@ class TestBootstrap(TestCase):
     self.assertTrue(ret == 1)
 
 
+  @patch.object(BootStrap, "getRemoteName")
+  @patch.object(BootStrap, "hasPassword")
+  def test_getRepoFile(self, hasPassword_mock, getRemoteName_mock):
+    bootstrap = BootStrap(["hostname"], "user", "sshKeyFile", "scriptDir",
+                          "bootdir", "setupAgentFile",
+                          "ambariServer", "centos6", "version", "8440")
+    # Without password
+    hasPassword_mock.return_value = False
+    getRemoteName_mock.return_value = "RemoteName"
+    rf = bootstrap.getMoveRepoFileCommand("target")
+    self.assertEquals(rf, "sudo mv RemoteName target/ambari.repo")
+    # With password
+    hasPassword_mock.return_value = True
+    getRemoteName_mock.return_value = "RemoteName"
+    rf = bootstrap.getMoveRepoFileCommand("target")
+    self.assertEquals(rf, "sudo -S mv RemoteName target/ambari.repo < RemoteName")
+
 
   def test_PSSH_constructor_argument_validation(self):
     dummy_command = "command"


Mime
View raw message