Fix the DCAE query
[clamp.git] / src / test / resources / http-cache / third_party_proxy.py
index 0381ab1..7fe3168 100755 (executable)
@@ -43,7 +43,7 @@ parser.add_argument("--temp",     "-t", default=tempfile.mkdtemp(), type=str, he
 parser.add_argument("--proxy"         , type=str, help="Url of the  Act as a proxy. If not set, this script only uses the cache and will return a 404 if files aren't found")
 parser.add_argument("--port",     "-P", type=int, default="8081", help="Port on which the proxy should listen to")
 parser.add_argument("--verbose",  "-v", type=bool, help="Print more information in case of error")
-parser.add_argument("--proxyaddress","-a", type=str, help="Address of this proxy, generally either third_party_proxy:8085 or localhost:8085 depending if started with docker-compose or not")
+parser.add_argument("--proxyaddress","-a", type=str, help="Address of this proxy, generally either third-party-proxy:8085 or localhost:8085 depending if started with docker-compose or not")
 options = parser.parse_args()
 
 
@@ -179,7 +179,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
      elif self.path.startswith("/dcae-deployments/") and http_type == "PUT":
             print "self.path start with /dcae-deployments/ DEPLOY, generating response json..."
             #jsondata = json.loads(self.data_string)
-            jsonGenerated = "{\"operationType\":\"install\",\"status\":\"processing\",\"links\":{\"status\":\"http:\/\/" + PROXY_ADDRESS + "\/dcae-operationstatus/install\"}}"
+            jsonGenerated = "{\"operationType\":\"install\",\"status\":\"processing\",\"links\":{\"status\":\"http:\/\/" + PROXY_ADDRESS + "\/dcae-operationstatus/install?test=test\"}}"
             print "jsonGenerated: " + jsonGenerated
             if not os.path.exists(cached_file_folder):
                 os.makedirs(cached_file_folder, 0777)
@@ -191,7 +191,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
      elif self.path.startswith("/dcae-deployments/") and http_type == "DELETE":
             print "self.path start with /dcae-deployments/ UNDEPLOY, generating response json..."
             #jsondata = json.loads(self.data_string)
-            jsonGenerated = "{\"operationType\":\"uninstall\",\"status\":\"processing\",\"links\":{\"status\":\"http:\/\/" + PROXY_ADDRESS + "\/dcae-operationstatus/uninstall\"}}"
+            jsonGenerated = "{\"operationType\":\"uninstall\",\"status\":\"processing\",\"links\":{\"status\":\"http:\/\/" + PROXY_ADDRESS + "\/dcae-operationstatus/uninstall?test=test\"}}"
             print "jsonGenerated: " + jsonGenerated
             if not os.path.exists(cached_file_folder):
                 os.makedirs(cached_file_folder, 0777)
@@ -237,7 +237,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
         with open(cached_file_content, 'w+') as f:
                 f.write(self.data_string)
         return True
-     elif self.path.startswith("/policy/api/v1/policytypes/") and http_type == "GET":
+     elif (self.path.startswith("/policy/pap/v1/policies/deployed/")) and http_type == "GET":
         print "self.path start with /policy/api/v1/policytypes/, generating response json..."
         jsonGenerated =  "{\"policyTypeId\": \"onap.policies.controlloop.operational\",\"policyTypeVersion\": \"1.0.0\",\"policyId\": \"OPERATIONAL_z711F_v1_0_ResourceInstanceName1_tca\"}"
         print "jsonGenerated: " + jsonGenerated
@@ -249,6 +249,22 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
         with open(cached_file_content, 'w') as f:
             f.write(jsonGenerated)
         return True
+     elif self.path.startswith("/dcae-service-types") and http_type == "GET":
+        if not _file_available:
+            self.path = "/dcae-service-types"
+            cached_file_folder = '%s/%s' % (TMP_ROOT, self.path)
+            cached_file_content = self._get_cached_content_file_name(cached_file_folder)
+            cached_file_header = self._get_cached_header_file_name(cached_file_folder)
+            print "self.path start with /dcae-service-types, generating response json..."
+            response = "{\"links\": {\"previousLink\": {\"title\": \"string\",\"rel\": \"string\",\"uri\": \"string\",\"uriBuilder\": {},\"rels\": [\"string\"],\"params\": {\"additionalProp1\": \"string\",\"additionalProp2\": \"string\",\"additionalProp3\": \"string\"},\"type\": \"string\"},\"nextLink\": {\"title\": \"string\",\"rel\": \"string\",\"uri\": \"string\",\"uriBuilder\": {},\"rels\": [\"string\"],\"params\": {\"additionalProp1\": \"string\",\"additionalProp2\": \"string\",\"additionalProp3\": \"string\"},\"type\": \"string\"}},\"totalCount\": 1,\"items\": [{\"owner\": \"testOwner\",\"application\": \"testApplication\",\"component\": \"testComponent\",\"typeName\": \"testTypeName\",\"typeVersion\": 0,\"blueprintTemplate\": \"testBlueprintTemplate\",\"serviceIds\": [\"serviceId1\", \"serviceId2\"],\"vnfTypes\": [\"vnfType1\", \"vnfType2\"],\"serviceLocations\": [\"serviceLocation1\", \"serviceLocation2\"],\"asdcServiceId\": \"testAsdcServiceId\",\"asdcResourceId\": \"0\",\"asdcServiceURL\": \"testAsdcServiceURL\",\"typeId\": \"testtypeId\",\"selfLink\": {\"title\": \"selfLinkTitle\",\"rel\": \"selfLinkRel\",\"uri\": \"selfLinkUri\",\"uriBuilder\": {},\"rels\": [\"string\"],\"params\": {\"additionalProp1\": \"string\",\"additionalProp2\": \"string\",\"additionalProp3\": \"string\"},\"type\": \"string\"},\"created\": \"2020-01-22T09:38:15.436Z\",\"deactivated\": \"2020-01-22T09:38:15.437Z\"},{\"owner\": \"testOwner2\",\"application\": \"testApplication1\",\"component\": \"testComponent2\",\"typeName\": \"testTypeName2\",\"typeVersion\": 0,\"blueprintTemplate\": \"testBlueprintTemplate2\",\"serviceIds\": [\"serviceId3\", \"serviceId4\"],\"vnfTypes\": [\"vnfType13\", \"vnfType4\"],\"serviceLocations\": [\"serviceLocation3\", \"serviceLocation4\"],\"asdcServiceId\": \"testAsdcServiceId\",\"asdcResourceId\": \"1\",\"asdcServiceURL\": \"testAsdcServiceURL2\",\"typeId\": \"testtypeId2\",\"selfLink\": {\"title\": \"selfLinkTitle\",\"rel\": \"selfLinkRel\",\"uri\": \"selfLinkUri\",\"uriBuilder\": {},\"rels\": [\"string\"],\"params\": {\"additionalProp1\": \"string\",\"additionalProp2\": \"string\",\"additionalProp3\": \"string\"},\"type\": \"string\"},\"created\": \"2020-01-22T09:38:15.436Z\",\"deactivated\": \"2020-01-22T09:38:15.437Z\"}]}"
+            print "jsonGenerated: " + response
+
+            os.makedirs(cached_file_folder, 0777)
+            with open(cached_file_header, 'w') as f:
+                f.write("{\"Content-Length\": \"" + str(len(response)) + "\", \"Content-Type\": \"application/json\"}")
+            with open(cached_file_content, 'w') as f:
+                f.write(response)
+        return True
      else:
         return False
 
@@ -281,6 +297,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
                 self.send_response(404)
                 self.end_headers()
                 self.wfile.write('404 Not found, no remote HOST specified on the emulator !!!')
+                print("HOST value is: %s " % (options.proxy))
                 return "404 Not found, no remote HOST specified on the emulator !!!"
 
             url = '%s%s' % (HOST, self.path)
@@ -299,12 +316,16 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
                 return response.content
         else:
             print("Request for data currently present in cache: %s" % (cached_file_folder,))
+            print("HOST value is: %s " % (HOST))
 
         self._send_content(cached_file_header, cached_file_content)
 
         if self.path.startswith("/dcae-service-types?asdcResourceId="):
             print "DCAE case deleting folder created " + cached_file_folder
             shutil.rmtree(cached_file_folder, ignore_errors=False, onerror=None)
+        elif self.path.startswith("/dcae-service-types"):
+            print "DCAE case deleting folder created " + cached_file_folder
+            shutil.rmtree(cached_file_folder, ignore_errors=False, onerror=None)
         else:
             print "NOT in DCAE case deleting folder created " + cached_file_folder