ソースを参照

AMBARI-3353. Ambari-Client Bootstrap fails due to odd status response style. (andrew onischuk via mahadev)

Mahadev Konar 11 年 前
コミット
cedc67afb2
1 ファイル変更24 行追加3 行削除
  1. 24 3
      ambari-client/src/main/python/ambari_client/model/host.py

+ 24 - 3
ambari-client/src/main/python/ambari_client/model/host.py

@@ -177,11 +177,32 @@ def _bootstrap_hosts(root_resource , hosts_list, ssh_key):
   @param hosts_list list of host_names.
   @return: A  StatusModel object.
   """
-  #payload_dic = {'sshKey':ssh_key , 'hosts':hosts_list}
   payload_dic = {'sshKey':ssh_key.encode('string_escape') , 'hosts':hosts_list}
   resp = root_resource.post(paths.BOOTSTRAP_PATH, payload_dic , content_type="application/json")
-  LOG.debug(resp)
-  return utils.ModelUtils.create_model(status.StatusModel, resp, root_resource, "NO_KEY")
+  status_dict = _bootstrap_resp_to_status_dict(resp)
+  return utils.ModelUtils.create_model(status.StatusModel, status_dict, root_resource, "NO_KEY")
+
+def _bootstrap_resp_to_status_dict(resp):
+  """
+  Bootstrap response has a little odd format
+  that's why we have to convert it to the normal
+  format to handle it properly later.
+  """
+  
+  # if we got other response, like an error 400 happened on higher level
+  if isinstance( resp['status'], int ):
+    return resp
+  
+  new_resp = {}
+  
+  if resp['status'] == "OK":
+    new_resp['status'] = 201
+  else: # ERROR
+    new_resp['status'] = 500
+    
+  new_resp['message'] = resp['log']
+  new_resp['requestId'] = resp['requestId']
+  return new_resp