소스 검색

AMBARI-5362. Automatic bootstrap failed on CentOS 6.5 (No module named common_functions). (Andrew Onischuk via swagle)

Siddharth Wagle 11 년 전
부모
커밋
f2078a0571
2개의 변경된 파일28개의 추가작업 그리고 7개의 파일을 삭제
  1. 22 2
      ambari-server/src/main/python/bootstrap.py
  2. 6 5
      ambari-server/src/test/python/TestBootstrap.py

+ 22 - 2
ambari-server/src/main/python/bootstrap.py

@@ -37,7 +37,7 @@ MAX_PARALLEL_BOOTSTRAPS = 20
 # How many seconds to wait between polling parallel bootstraps
 POLL_INTERVAL_SEC = 1
 DEBUG=False
-PYTHON_ENV="env PYTHONPATH=$PYTHONPATH:/usr/lib/python2.6/site-packages "
+PYTHON_ENV="env PYTHONPATH=$PYTHONPATH:/tmp "
 
 
 class HostLog:
@@ -75,6 +75,7 @@ class SCP:
 
   def run(self):
     scpcommand = ["scp",
+                  "-r",
                   "-o", "ConnectTimeout=60",
                   "-o", "BatchMode=yes",
                   "-o", "StrictHostKeyChecking=no",
@@ -140,6 +141,7 @@ class Bootstrap(threading.Thread):
   AMBARI_REPO_FILENAME = "ambari.repo"
   SETUP_SCRIPT_FILENAME = "setupAgent.py"
   PASSWORD_FILENAME = "host_pass"
+  COMMON_FUNCTIONS="/usr/lib/python2.6/site-packages/common_functions"
 
   def __init__(self, host, shared_state):
     threading.Thread.__init__(self)
@@ -201,6 +203,9 @@ class Bootstrap(threading.Thread):
 
   def getOsCheckScriptRemoteLocation(self):
     return self.getRemoteName(self.OS_CHECK_SCRIPT_FILENAME)
+  
+  def getCommonFunctionsRemoteLocation(self):
+    return self.TEMP_FOLDER;
 
   def getUtime(self):
     return int(time.time())
@@ -225,6 +230,19 @@ class Bootstrap(threading.Thread):
     result = scp.run()
     self.host_log.write("\n")
     return result
+  
+  def copyCommonFunctions(self):
+    # Copying the os check script file
+    fileToCopy = self.COMMON_FUNCTIONS
+    target = self.getCommonFunctionsRemoteLocation()
+    params = self.shared_state
+    self.host_log.write("==========================\n")
+    self.host_log.write("Copying common functions script...")
+    scp = SCP(params.user, params.sshkey_file, self.host, fileToCopy,
+              target, params.bootdir, self.host_log)
+    result = scp.run()
+    self.host_log.write("\n")
+    return result
 
 
   def getMoveRepoFileWithPasswordCommand(self, targetDir):
@@ -327,6 +345,7 @@ class Bootstrap(threading.Thread):
     params = self.shared_state
     self.host_log.write("==========================\n")
     self.host_log.write("Running OS type check...")
+    
     command = "chmod a+x %s && %s %s" % \
               (self.getOsCheckScriptRemoteLocation(),
                PYTHON_ENV + self.getOsCheckScriptRemoteLocation(), params.cluster_os_type)
@@ -436,7 +455,8 @@ class Bootstrap(threading.Thread):
     """ Copy files and run commands on remote host """
     self.status["start_time"] = time.time()
     # Population of action queue
-    action_queue = [self.copyOsCheckScript,
+    action_queue = [self.copyCommonFunctions,
+                    self.copyOsCheckScript,
                     self.runOsCheckScript,
                     self.checkSudoPackage
     ]

+ 6 - 5
ambari-server/src/test/python/TestBootstrap.py

@@ -238,7 +238,7 @@ class TestBootstrap(TestCase):
     self.assertTrue(log_sample in log['text'])
     self.assertTrue(error_sample in log['text'])
     command_str = str(popenMock.call_args[0][0])
-    self.assertEquals(command_str, "['scp', '-o', 'ConnectTimeout=60', '-o', "
+    self.assertEquals(command_str, "['scp', '-r', '-o', 'ConnectTimeout=60', '-o', "
         "'BatchMode=yes', '-o', 'StrictHostKeyChecking=no', '-i', 'sshkey_file',"
         " 'src/file', 'root@dummy-host:dst/file']")
     self.assertEqual(retcode["exitstatus"], 0)
@@ -458,8 +458,9 @@ class TestBootstrap(TestCase):
     res = bootstrap_obj.runOsCheckScript()
     self.assertEquals(res, expected)
     command = str(init_mock.call_args[0][3])
-    self.assertEqual(command, "chmod a+x OsCheckScriptRemoteLocation &&"
-                              " env PYTHONPATH=$PYTHONPATH:/usr/lib/python2.6/site-packages OsCheckScriptRemoteLocation centos6")
+    self.assertEqual(command,
+                     "chmod a+x OsCheckScriptRemoteLocation && "
+                     "env PYTHONPATH=$PYTHONPATH:/tmp OsCheckScriptRemoteLocation centos6")
 
 
   @patch.object(SSH, "__init__")
@@ -657,7 +658,7 @@ class TestBootstrap(TestCase):
     hasPassword_mock.return_value = False
     try_to_execute_mock.return_value = {"exitstatus": 0, "log":"log0", "errormsg":"errormsg0"}
     bootstrap_obj.run()
-    self.assertEqual(try_to_execute_mock.call_count, 5) # <- Adjust if changed
+    self.assertEqual(try_to_execute_mock.call_count, 6) # <- Adjust if changed
     self.assertTrue(createDoneFile_mock.called)
     self.assertEqual(bootstrap_obj.getStatus()["return_code"], 0)
 
@@ -668,7 +669,7 @@ class TestBootstrap(TestCase):
     hasPassword_mock.return_value = True
     try_to_execute_mock.return_value = {"exitstatus": 0, "log":"log0", "errormsg":"errormsg0"}
     bootstrap_obj.run()
-    self.assertEqual(try_to_execute_mock.call_count, 8) # <- Adjust if changed
+    self.assertEqual(try_to_execute_mock.call_count, 9) # <- Adjust if changed
     self.assertTrue(createDoneFile_mock.called)
     self.assertEqual(bootstrap_obj.getStatus()["return_code"], 0)