From 09bc8450b2b0c4f60eb4a241efc548d13c5c9912 Mon Sep 17 00:00:00 2001 From: sebdet Date: Thu, 23 May 2019 17:34:07 +0200 Subject: Rework the loop state Rework the state loop so there is no bug in the loop state anymore, now the components are scanned + upgrade to 4.0.4 Issue-ID: CLAMP-384 Change-Id: If7649238ee52864c84bfb9b6b8471d1738752e29 Signed-off-by: sebdet --- src/test/resources/http-cache/third_party_proxy.py | 69 +++++++++++++++++----- 1 file changed, 54 insertions(+), 15 deletions(-) (limited to 'src/test/resources/http-cache') diff --git a/src/test/resources/http-cache/third_party_proxy.py b/src/test/resources/http-cache/third_party_proxy.py index 0db977bb4..ce61ea063 100755 --- a/src/test/resources/http-cache/third_party_proxy.py +++ b/src/test/resources/http-cache/third_party_proxy.py @@ -127,10 +127,10 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w') as f: f.write(jsonGenerated) return True - elif self.path.startswith("/dcae-operationstatus") and http_type == "GET": + elif self.path.startswith("/dcae-operationstatus/install") and http_type == "GET": if not _file_available: - print "self.path start with /dcae-operationstatus, generating response json..." - jsonGenerated = "{\"operationType\": \"operationType1\", \"status\": \"succeeded\"}" + print "self.path start with /dcae-operationstatus/install, generating response json..." + jsonGenerated = "{\"operationType\": \"install\", \"status\": \"succeeded\"}" print "jsonGenerated: " + jsonGenerated try: @@ -145,24 +145,29 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w') as f: f.write(jsonGenerated) return True - elif self.path.startswith("/sdc/v1/catalog/services/") and http_type == "POST": + elif self.path.startswith("/dcae-operationstatus/uninstall") and http_type == "GET": if not _file_available: - print "self.path start with /sdc/v1/catalog/services/, generating response json..." - jsondata = json.loads(self.data_string) - jsonGenerated = "{\"artifactName\":\"" + jsondata['artifactName'] + "\",\"artifactType\":\"" + jsondata['artifactType'] + "\",\"artifactURL\":\"" + self.path + "\",\"artifactDescription\":\"" + jsondata['description'] + "\",\"artifactChecksum\":\"ZjJlMjVmMWE2M2M1OTM2MDZlODlmNTVmZmYzNjViYzM=\",\"artifactUUID\":\"" + str(uuid.uuid4()) + "\",\"artifactVersion\":\"1\"}" + print "self.path start with /dcae-operationstatus/uninstall, generating response json..." + jsonGenerated = "{\"operationType\": \"uninstall\", \"status\": \"succeeded\"}" print "jsonGenerated: " + jsonGenerated - os.makedirs(cached_file_folder, 0777) + try: + os.makedirs(cached_file_folder, 0777) + except OSError as e: + if e.errno != errno.EEXIST: + raise + print(cached_file_folder+" already exists") + with open(cached_file_header, 'w') as f: f.write("{\"Content-Length\": \"" + str(len(jsonGenerated)) + "\", \"Content-Type\": \"application/json\"}") with open(cached_file_content, 'w') as f: f.write(jsonGenerated) - return True; - elif self.path.startswith("/dcae-deployments/") and (http_type == "PUT" or http_type == "DELETE"): + return True + elif self.path.startswith("/sdc/v1/catalog/services/") and http_type == "POST": if not _file_available: - print "self.path start with /dcae-deployments/, generating response json..." - #jsondata = json.loads(self.data_string) - jsonGenerated = "{\"links\":{\"status\":\"http:\/\/" + PROXY_ADDRESS + "\/dcae-operationstatus\",\"test2\":\"test2\"}}" + print "self.path start with /sdc/v1/catalog/services/, generating response json..." + jsondata = json.loads(self.data_string) + jsonGenerated = "{\"artifactName\":\"" + jsondata['artifactName'] + "\",\"artifactType\":\"" + jsondata['artifactType'] + "\",\"artifactURL\":\"" + self.path + "\",\"artifactDescription\":\"" + jsondata['description'] + "\",\"artifactChecksum\":\"ZjJlMjVmMWE2M2M1OTM2MDZlODlmNTVmZmYzNjViYzM=\",\"artifactUUID\":\"" + str(uuid.uuid4()) + "\",\"artifactVersion\":\"1\"}" print "jsonGenerated: " + jsonGenerated os.makedirs(cached_file_folder, 0777) @@ -171,6 +176,30 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w') as f: f.write(jsonGenerated) return True + 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\"}}" + print "jsonGenerated: " + jsonGenerated + if not os.path.exists(cached_file_folder): + os.makedirs(cached_file_folder, 0777) + with open(cached_file_header, 'w+') as f: + f.write("{\"Content-Length\": \"" + str(len(jsonGenerated)) + "\", \"Content-Type\": \"application/json\"}") + with open(cached_file_content, 'w+') as f: + f.write(jsonGenerated) + return True + 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\"}}" + print "jsonGenerated: " + jsonGenerated + if not os.path.exists(cached_file_folder): + os.makedirs(cached_file_folder, 0777) + with open(cached_file_header, 'w+') as f: + f.write("{\"Content-Length\": \"" + str(len(jsonGenerated)) + "\", \"Content-Type\": \"application/json\"}") + with open(cached_file_content, 'w+') as f: + f.write(jsonGenerated) + return True elif (self.path.startswith("/pdp/api/") and (http_type == "PUT" or http_type == "DELETE")) or (self.path.startswith("/pdp/api/policyEngineImport") and http_type == "POST"): print "self.path start with /pdp/api/, copying body to response ..." if not os.path.exists(cached_file_folder): @@ -180,7 +209,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 == "POST": + elif self.path.startswith("/policy/api/v1/policytypes/") and http_type == "POST": print "self.path start with POST new policy API /pdp/api/, copying body to response ..." if not os.path.exists(cached_file_folder): os.makedirs(cached_file_folder, 0777) @@ -189,11 +218,21 @@ 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 == "DELETE": + elif self.path.startswith("/policy/api/v1/policytypes/") and http_type == "DELETE": print "self.path start with DELETE new policy API /policy/api/v1/policyTypes/ ..." if not os.path.exists(cached_file_folder): os.makedirs(cached_file_folder, 0777) + with open(cached_file_header, 'w+') as f: + f.write("{\"Content-Length\": \"" + str(len("")) + "\", \"Content-Type\": \""+str("")+"\"}") + with open(cached_file_content, 'w+') as f: + f.write(self.data_string) + return True + elif self.path.startswith("/policy/pap/v1/pdps/policies") and http_type == "POST": + print "self.path start with POST new policy API /policy/pap/v1/pdps/ ..." + if not os.path.exists(cached_file_folder): + os.makedirs(cached_file_folder, 0777) + with open(cached_file_header, 'w+') as f: f.write("{\"Content-Length\": \"" + str(len("")) + "\", \"Content-Type\": \""+str("")+"\"}") with open(cached_file_content, 'w+') as f: -- cgit 1.2.3-korg