incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject [1/4] AMBARI-3311. Ambari-Client create unit tests for the methods of ClusterModel. (Andrew Onischuk via mahadev)
Date Thu, 26 Sep 2013 03:59:13 GMT
Updated Branches:
  refs/heads/trunk a8864ba53 -> a0386357b


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0386357/ambari-client/src/test/python/json/get_cluster_services.json
----------------------------------------------------------------------
diff --git a/ambari-client/src/test/python/json/get_cluster_services.json b/ambari-client/src/test/python/json/get_cluster_services.json
deleted file mode 100755
index 53bb2da..0000000
--- a/ambari-client/src/test/python/json/get_cluster_services.json
+++ /dev/null
@@ -1,120 +0,0 @@
-{
-  "href" : "http://localhost:8080/api/v1/clusters/test1/services?fields=*",
-  "items" : [
-    {
-      "href" : "http://localhost:8080/api/v1/clusters/test1/services/GANGLIA",
-      "ServiceInfo" : {
-        "cluster_name" : "test1",
-        "state" : "STARTED",
-        "service_name" : "GANGLIA",
-        "desired_configs" : {
-          "global" : "version1"
-        }
-      },
-      "components" : [
-        {
-          "href" : "http://localhost:8080/api/v1/clusters/test1/services/GANGLIA/components/GANGLIA_MONITOR",
-          "ServiceComponentInfo" : {
-            "cluster_name" : "test1",
-            "component_name" : "GANGLIA_MONITOR",
-            "service_name" : "GANGLIA"
-          }
-        },
-        {
-          "href" : "http://localhost:8080/api/v1/clusters/test1/services/GANGLIA/components/GANGLIA_SERVER",
-          "ServiceComponentInfo" : {
-            "cluster_name" : "test1",
-            "component_name" : "GANGLIA_SERVER",
-            "service_name" : "GANGLIA"
-          }
-        }
-      ]
-    },
-    {
-      "href" : "http://localhost:8080/api/v1/clusters/test1/services/MAPREDUCE",
-      "ServiceInfo" : {
-        "cluster_name" : "test1",
-        "state" : "STARTED",
-        "service_name" : "MAPREDUCE",
-        "desired_configs" : {
-          "mapred-site" : "version1",
-          "global" : "version1",
-          "core-site" : "version1"
-        }
-      },
-      "components" : [
-        {
-          "href" : "http://localhost:8080/api/v1/clusters/test1/services/MAPREDUCE/components/TASKTRACKER",
-          "ServiceComponentInfo" : {
-            "cluster_name" : "test1",
-            "component_name" : "TASKTRACKER",
-            "service_name" : "MAPREDUCE"
-          }
-        },
-        {
-          "href" : "http://localhost:8080/api/v1/clusters/test1/services/MAPREDUCE/components/MAPREDUCE_CLIENT",
-          "ServiceComponentInfo" : {
-            "cluster_name" : "test1",
-            "component_name" : "MAPREDUCE_CLIENT",
-            "service_name" : "MAPREDUCE"
-          }
-        },
-        {
-          "href" : "http://localhost:8080/api/v1/clusters/test1/services/MAPREDUCE/components/JOBTRACKER",
-          "ServiceComponentInfo" : {
-            "cluster_name" : "test1",
-            "component_name" : "JOBTRACKER",
-            "service_name" : "MAPREDUCE"
-          }
-        }
-      ]
-    },
-    {
-      "href" : "http://localhost:8080/api/v1/clusters/test1/services/HDFS",
-      "ServiceInfo" : {
-        "cluster_name" : "test1",
-        "state" : "STARTED",
-        "service_name" : "HDFS",
-        "desired_configs" : {
-          "global" : "version1",
-          "hdfs-site" : "version1",
-          "core-site" : "version1"
-        }
-      },
-      "components" : [
-        {
-          "href" : "http://localhost:8080/api/v1/clusters/test1/services/HDFS/components/SECONDARY_NAMENODE",
-          "ServiceComponentInfo" : {
-            "cluster_name" : "test1",
-            "component_name" : "SECONDARY_NAMENODE",
-            "service_name" : "HDFS"
-          }
-        },
-        {
-          "href" : "http://localhost:8080/api/v1/clusters/test1/services/HDFS/components/HDFS_CLIENT",
-          "ServiceComponentInfo" : {
-            "cluster_name" : "test1",
-            "component_name" : "HDFS_CLIENT",
-            "service_name" : "HDFS"
-          }
-        },
-        {
-          "href" : "http://localhost:8080/api/v1/clusters/test1/services/HDFS/components/NAMENODE",
-          "ServiceComponentInfo" : {
-            "cluster_name" : "test1",
-            "component_name" : "NAMENODE",
-            "service_name" : "HDFS"
-          }
-        },
-        {
-          "href" : "http://localhost:8080/api/v1/clusters/test1/services/HDFS/components/DATANODE",
-          "ServiceComponentInfo" : {
-            "cluster_name" : "test1",
-            "component_name" : "DATANODE",
-            "service_name" : "HDFS"
-          }
-        }
-      ]
-    }
-  ]
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0386357/ambari-client/src/test/python/json/get_components_from_stack.json
----------------------------------------------------------------------
diff --git a/ambari-client/src/test/python/json/get_components_from_stack.json b/ambari-client/src/test/python/json/get_components_from_stack.json
new file mode 100644
index 0000000..55a9c09
--- /dev/null
+++ b/ambari-client/src/test/python/json/get_components_from_stack.json
@@ -0,0 +1,41 @@
+{
+  "href" : "http://localhost:8080/api/v1/stacks2/HDP/versions/2.0.5/stackServices/YARN/serviceComponents?fields=*",
+  "items" : [
+    {
+      "href" : "http://localhost:8080/api/v1/stacks2/HDP/versions/2.0.5/stackServices/YARN/serviceComponents/NODEMANAGER",
+      "StackServiceComponents" : {
+        "component_category" : "SLAVE",
+        "component_name" : "NODEMANAGER",
+        "is_client" : false,
+        "is_master" : false,
+        "service_name" : "YARN",
+        "stack_name" : "HDP",
+        "stack_version" : "2.0.5"
+      }
+    },
+    {
+      "href" : "http://localhost:8080/api/v1/stacks2/HDP/versions/2.0.5/stackServices/YARN/serviceComponents/RESOURCEMANAGER",
+      "StackServiceComponents" : {
+        "component_category" : "MASTER",
+        "component_name" : "RESOURCEMANAGER",
+        "is_client" : false,
+        "is_master" : true,
+        "service_name" : "YARN",
+        "stack_name" : "HDP",
+        "stack_version" : "2.0.5"
+      }
+    },
+    {
+      "href" : "http://localhost:8080/api/v1/stacks2/HDP/versions/2.0.5/stackServices/YARN/serviceComponents/YARN_CLIENT",
+      "StackServiceComponents" : {
+        "component_category" : "CLIENT",
+        "component_name" : "YARN_CLIENT",
+        "is_client" : true,
+        "is_master" : false,
+        "service_name" : "YARN",
+        "stack_name" : "HDP",
+        "stack_version" : "2.0.5"
+      }
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0386357/ambari-client/src/test/python/json/get_service.json
----------------------------------------------------------------------
diff --git a/ambari-client/src/test/python/json/get_service.json b/ambari-client/src/test/python/json/get_service.json
deleted file mode 100755
index 0c9d5e7..0000000
--- a/ambari-client/src/test/python/json/get_service.json
+++ /dev/null
@@ -1,29 +0,0 @@
-{
-  "href" : "http://localhost:8080/api/v1/clusters/test1/services/GANGLIA",
-  "ServiceInfo" : {
-    "cluster_name" : "test1",
-    "state" : "STARTED",
-    "service_name" : "GANGLIA",
-    "desired_configs" : {
-      "global" : "version1"
-    }
-  },
-  "components" : [
-    {
-      "href" : "http://localhost:8080/api/v1/clusters/test1/services/GANGLIA/components/GANGLIA_MONITOR",
-      "ServiceComponentInfo" : {
-        "cluster_name" : "test1",
-        "component_name" : "GANGLIA_MONITOR",
-        "service_name" : "GANGLIA"
-      }
-    },
-    {
-      "href" : "http://localhost:8080/api/v1/clusters/test1/services/GANGLIA/components/GANGLIA_SERVER",
-      "ServiceComponentInfo" : {
-        "cluster_name" : "test1",
-        "component_name" : "GANGLIA_SERVER",
-        "service_name" : "GANGLIA"
-      }
-    }
-  ]
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/a0386357/ambari-client/src/test/python/utils/HttpClientInvoker.py
----------------------------------------------------------------------
diff --git a/ambari-client/src/test/python/utils/HttpClientInvoker.py b/ambari-client/src/test/python/utils/HttpClientInvoker.py
new file mode 100644
index 0000000..a8e34ec
--- /dev/null
+++ b/ambari-client/src/test/python/utils/HttpClientInvoker.py
@@ -0,0 +1,67 @@
+class HttpClientInvoker():
+  @staticmethod
+  def http_client_invoke_side_effects(*args, **kwargs):
+      print locals()
+      
+      if args[0] != "GET" and args[0] != "DELETE":
+        return "", 201 , "text/plain"
+      
+      mocked_code = 200 
+      mocked_content = "text/plain"
+      if args[1] == "//clusters/test1":
+        mocked_response = open('json/clustermodel_get_cluster.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/hosts/myhost":
+        mocked_response = open('json/clustermodel_get_host.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/hosts?fields=*":
+        mocked_response = open('json/clustermodel_get_all_hosts.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/configurations?type=global&tag=version1":
+        mocked_response = open('json/clustermodel_get_global_config.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/configurations?type=core-site&tag=version1":
+        mocked_response = open('json/clustermodel_get_core_site_config.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/configurations?type=hdfs-site&tag=version1":
+        mocked_response = open('json/clustermodel_get_hdfs_site_config.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/configurations?type=mapred-site&tag=version1":
+        mocked_response = open('json/clustermodel_get_mapred_site_config.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/services/GANGLIA":
+        mocked_response = open('json/clustermodel_get_service.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/services?fields=*":
+        mocked_response = open('json/clustermodel_get_all_services.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//stacks2/HDP/versions/2.0.5/stackServices/HDFS/serviceComponents?fields=*":
+        mocked_response = open('json/get_components_from_stack.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//hosts":
+        mocked_response = open('json/get_all_hosts.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test6/services/GANGLIA":
+        mocked_response = open('json/get_cluster_service.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test6/hosts/r01wn01/host_components/NAMENODE":
+        mocked_response = open('json/get_host_component.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test6/hosts/r01wn01/host_components?ServiceComponentInfo":
+        mocked_response = open('json/get_host_components.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test6/services/GANGLIA/components/GANGLIA_MONITOR":
+        mocked_response = open('json/get_service_component.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test6/services/GANGLIA/components?fields=*":
+        mocked_response = open('json/get_service_components.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/hosts/deleted_nonexistant_cluster":
+        mocked_response = open('json/error_deleting_host.json', 'r').read()
+        return mocked_response, mocked_code , mocked_content
+      elif args[1] == "//clusters/test1/hosts/hostname01":
+        mocked_response = None
+        return mocked_response, mocked_code , mocked_content
+      else:
+        print "Unknown url: %s" % args[1]
+        
\ No newline at end of file


Mime
View raw message