Ver código fonte

AMBARI-3263. Ambar-client updates for JIRA-3201. (Andrew Onischuk via mahadev)

Mahadev Konar 12 anos atrás
pai
commit
91ead9e80d

+ 0 - 22
ambari-client/src/main/python/ambari_client/ambari_api.py

@@ -129,28 +129,6 @@ class AmbariClient(RestResource):
     @return  ClusterModel object.
     """
     return clusters._create_cluster(self, cluster_name, version)
-  
-  def create_host(self, host_name, ip, rack_info='/default-rack'):
-    """
-    Create a host
-    @param root_resource: The root Resource.
-    @param host_name: Host name
-    @param ip: IP address
-    @param rack_info: Rack id. Default None
-    @return: A HostModel object
-    """
-    return hosts._create_host(self, host_name, ip, rack_info)
-  
-  
-  def create_hosts(self, host_list):
-    """
-    Create a host
-    @param root_resource: The root Resource.
-    @param host_list: ModelList list of hosts
-    @return: A HostModel object
-    """
-    return hosts._create_hosts(self, host_list)
-
 
   def delete_cluster(self , cluster_name):
     """

+ 21 - 0
ambari-client/src/test/python/TestAmbariClient.py

@@ -96,6 +96,27 @@ class TestAmbariClient(unittest.TestCase):
       
     self.assertEqual(len(all_hosts), 12, "There should be 12 hosts from the response")
     
+  @patch("ambari_client.core.http_client.HttpClient")  
+  def test_get_host_valid(self , http_client):
+    """
+    Get host
+    This testcase checks if client.get_host returns a correct host
+    """
+    http_client_mock = MagicMock()
+    http_client.returned_obj = http_client_mock
+    mocked_code = "200" 
+    mocked_content = "text/plain"
+    
+    linestring = open('json/get_host.json', 'r').read()
+    mocked_response = linestring
+    expected_dict_output = {'ip': '10.0.2.15', 'host_name': 'dev06.hortonworks.com', 'rack_info': '/default-rack'}
+    
+    http_client_mock.invoke.return_value = mocked_response , mocked_code , mocked_content
+    client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)
+    host = client.get_host('dev06.hortonworks.com')
+    
+    self.assertEqual(host.to_json_dict(), expected_dict_output)
+    
        
   @patch("ambari_client.core.http_client.HttpClient")  
   def test_get_cluster_valid(self , http_client):

+ 63 - 0
ambari-client/src/test/python/json/get_host.json

@@ -0,0 +1,63 @@
+{
+  "href" : "http://localhost:8080/api/v1/hosts/dev06.hortonworks.com",
+  "Hosts" : {
+    "cpu_count" : 4,
+    "desired_configs" : null,
+    "disk_info" : [
+      {
+        "available" : "45333752",
+        "used" : "5748252",
+        "percent" : "12%",
+        "size" : "51606140",
+        "type" : "ext4",
+        "mountpoint" : "/"
+      },
+      {
+        "available" : "5517976",
+        "used" : "272",
+        "percent" : "1%",
+        "size" : "5518248",
+        "type" : "tmpfs",
+        "mountpoint" : "/dev/shm"
+      },
+      {
+        "available" : "432210",
+        "used" : "38034",
+        "percent" : "9%",
+        "size" : "495844",
+        "type" : "ext4",
+        "mountpoint" : "/boot"
+      },
+      {
+        "available" : "44459840",
+        "used" : "184252",
+        "percent" : "1%",
+        "size" : "47033288",
+        "type" : "ext4",
+        "mountpoint" : "/home"
+      },
+      {
+        "available" : "136400692",
+        "used" : "840256712",
+        "percent" : "87%",
+        "size" : "976657404",
+        "type" : "vboxsf",
+        "mountpoint" : "/media/sf_share"
+      }
+    ],
+    "host_health_report" : "",
+    "host_name" : "dev06.hortonworks.com",
+    "host_state" : "HEARTBEAT_LOST",
+    "host_status" : "UNKNOWN",
+    "ip" : "10.0.2.15",
+    "last_agent_env" : null,
+    "last_heartbeat_time" : 0,
+    "last_registration_time" : 1378228232506,
+    "os_arch" : "x86_64",
+    "os_type" : "centos6",
+    "ph_cpu_count" : 1,
+    "public_host_name" : "dev06.hortonworks.com",
+    "rack_info" : "/default-rack",
+    "total_mem" : 11041505
+  }
+}