diff --git a/config/capif-sdk-config.json b/config/capif-sdk-config.json index b9cc6ad17f75291a759710bf947b234816674ea5..c84591d36602b2796f60b23fd4f6018698431ade 100644 --- a/config/capif-sdk-config.json +++ b/config/capif-sdk-config.json @@ -38,5 +38,5 @@ "publisher_apf_id":"APF73e3458fb483c3c65f2f7e126ec851", "publisher_aefs_ids":["AEF07a01ccd74a160c195e69b4f116d66","AEFb5c206b46fc68c192aed6870899ea1"] }, - "api_description_path":"/Users/IDB0128/git_repos/pesp_capif_sdk/samples/provider_api_description_sample.json" + "api_description_path":"/Users/IDB0128/git_repos/pesp_capif_sdk/test/netapp-provider-api-spec.json" } \ No newline at end of file diff --git a/netapp-samples/netapp-invoker-sample/netapp-invoker.py b/netapp-samples/netapp-invoker-sample/netapp-invoker.py index 54a5e609f7ac14cee0f7e3253ee1c762b19316d1..3fd2d3d7e264f313b81025f4d107f1a151384da7 100644 --- a/netapp-samples/netapp-invoker-sample/netapp-invoker.py +++ b/netapp-samples/netapp-invoker-sample/netapp-invoker.py @@ -1,4 +1,3 @@ -from sdk import CAPIFInvokerConnector, ServiceDiscoverer import sys import os @@ -7,7 +6,7 @@ import os script_dir = os.path.dirname(os.path.abspath(__file__)) # Directorio actual del script sdk_path = os.path.join(script_dir, '..', '..', 'sdk') # Subir dos niveles y apuntar a 'sdk' sys.path.insert(0, sdk_path) - +from sdk import CAPIFInvokerConnector, ServiceDiscoverer capif_sdk_config_path = "/Users/dgs/Downloads/capif_sdk/invoker/config.json" capif_sdk_config_path = "/Users/IDB0128/git_repos/pesp_capif_sdk/netapp-samples/netapp-invoker-sample/capif-sdk-config-sample.json" diff --git a/test/capif-sdk-config-sample-test.json b/test/capif-sdk-config-sample-test.json index 308e20f46df1d47e833a260ab207918d950856bb..5834dfc3d8a01e18ddd01b905ed34e6404491aab 100644 --- a/test/capif-sdk-config-sample-test.json +++ b/test/capif-sdk-config-sample-test.json @@ -34,11 +34,11 @@ "service-kpis": "" }, "publish_req": { - "service_api_id": "475efe88f362be86e6818967a1b1c2", - "publisher_apf_id": "APF69c4e696697fcd7815ccddb36cf730", + "service_api_id": "b975bc7437732c3b503de8a76e50a8", + "publisher_apf_id": "APFb7a2e035e70e8a8928ae3b811ae083", "publisher_aefs_ids": [ - "AEF295be601e3fad4886d0207f2371493", - "AEF6cc62d5779ca43df0e95c7908524f2" + "AEF95f7fd34d9163a8d4e64694bd0f9c1", + "AEF5d3bde7bacba44152076162b10ece7" ] }, "api_description_path": "./netapp-provider-api-spec.json" diff --git a/test/netapp-provider-api-spec-2.json b/test/netapp-provider-api-spec-2.json new file mode 100755 index 0000000000000000000000000000000000000000..6dde5d9e42e258ac41fcf17842425a904a9c2133 --- /dev/null +++ b/test/netapp-provider-api-spec-2.json @@ -0,0 +1,214 @@ +{ + "apiName": "Test-2", + "aefProfiles": [ + { + "aefId": "AEF9a7601d5ceb912131057165215b0fc", + "versions": [ + { + "apiVersion": "v1", + "expiry": "2100-11-30T10:32:02.004Z", + "resources": [ + { + "resourceName": "MONITORING_SUBSCRIPTIONS", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/{scsAsId}/subscriptions", + "custOpName": "http_post", + "operations": [ + "GET", + "POST" + ], + "description": "Endpoint to manage monitoring subscriptions" + }, + { + "resourceName": "MONITORING_SUBSCRIPTION_SINGLE", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/{scsAsId}/subscriptions/{subscriptionId}", + "custOpName": "http_get", + "operations": [ + "GET", + "PUT", + "DELETE" + ], + "description": "Endpoint to manage single subscription" + } + ], + "custOperations": [ + { + "commType": "REQUEST_RESPONSE", + "custOpName": "string", + "operations": [ + "POST" + ], + "description": "string" + } + ] + } + ], + "protocol": "HTTP_1_1", + "dataFormat": "JSON", + "securityMethods": [ + "Oauth", + "PSK" + ], + "interfaceDescriptions": [ + { + "ipv4Addr": "127.0.0.1", + "port": 8888, + "securityMethods": [ + "Oauth" + ] + } + ] + }, + { + "aefId": "AEF5b81eb7ab85703209c1dac2002793f", + "versions": [ + { + "apiVersion": "v1", + "expiry": "2100-11-30T10:32:02.004Z", + "resources": [ + { + "resourceName": "TSN_LIST_PROFILES", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/profile", + "custOpName": "http_get", + "operations": [ + "GET" + ], + "description": "Endpoint for retrieving the list of available TSN profiles" + }, + { + "resourceName": "TSN_DETAIL_PROFILE", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/profile?name={profileName}", + "custOpName": "http_get", + "operations": [ + "GET" + ], + "description": "Endpoint for retrieving information about a single TSN profile" + }, + { + "resourceName": "TSN_APPLY_CONFIGURATION", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/apply", + "custOpName": "http_post", + "operations": [ + "POST" + ], + "description": "Endpoint for configuring TSN connection parameters" + }, + { + "resourceName": "TSN_CLEAR_CONFIGURATION", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/clear", + "custOpName": "http_post", + "operations": [ + "POST" + ], + "description": "Endpoint for removing a previous TSN connection configuration" + } + ], + "custOperations": [ + { + "commType": "REQUEST_RESPONSE", + "custOpName": "string", + "operations": [ + "POST" + ], + "description": "string" + } + ] + } + ], + "protocol": "HTTP_1_1", + "dataFormat": "JSON", + "securityMethods": [ + "Oauth" + ], + "interfaceDescriptions": [ + { + "ipv4Addr": "127.0.0.1", + "port": 8899, + "securityMethods": [ + "Oauth" + ] + } + ] + }, + { + "aefId": "AEF81595f00c76092899d538992a3f60d", + "versions": [ + { + "apiVersion": "v1", + "expiry": "2100-11-30T10:32:02.004Z", + "resources": [ + { + "resourceName": "MONITORING_SUBSCRIPTIONS", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/{scsAsId}/subscriptions", + "custOpName": "http_post", + "operations": [ + "GET", + "POST" + ], + "description": "Endpoint to manage monitoring subscriptions" + }, + { + "resourceName": "MONITORING_SUBSCRIPTION_SINGLE", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/{scsAsId}/subscriptions/{subscriptionId}", + "custOpName": "http_get", + "operations": [ + "GET", + "PUT", + "DELETE" + ], + "description": "Endpoint to manage single subscription" + } + ], + "custOperations": [ + { + "commType": "REQUEST_RESPONSE", + "custOpName": "string", + "operations": [ + "POST" + ], + "description": "string" + } + ] + } + ], + "protocol": "HTTP_1_1", + "dataFormat": "JSON", + "securityMethods": [ + "Oauth", + "PSK" + ], + "interfaceDescriptions": [ + { + "ipv4Addr": "127.0.0.1", + "port": 8888, + "securityMethods": [ + "Oauth" + ] + } + ] + } + ], + "description": "API of dummy netapp to test", + "supportedFeatures": "fffff", + "shareableInfo": { + "isShareable": true, + "capifProvDoms": [ + "string" + ] + }, + "serviceAPICategory": "string", + "apiSuppFeats": "fffff", + "pubApiPath": { + "ccfIds": [ + "string" + ] + }, + "ccfId": "string" +} \ No newline at end of file diff --git a/test/netapp-provider-api-spec-3.json b/test/netapp-provider-api-spec-3.json new file mode 100755 index 0000000000000000000000000000000000000000..12cb9bb69c8427c2c4f1fe7426e5d3397deebfdd --- /dev/null +++ b/test/netapp-provider-api-spec-3.json @@ -0,0 +1,155 @@ +{ + "apiName": "Test-3", + "aefProfiles": [ + { + "aefId": "AEFc125f6f9dd5739a73b94c3e0fb6dd1", + "versions": [ + { + "apiVersion": "v1", + "expiry": "2100-11-30T10:32:02.004Z", + "resources": [ + { + "resourceName": "MONITORING_SUBSCRIPTIONS", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/{scsAsId}/subscriptions", + "custOpName": "http_post", + "operations": [ + "GET", + "POST" + ], + "description": "Endpoint to manage monitoring subscriptions" + }, + { + "resourceName": "MONITORING_SUBSCRIPTION_SINGLE", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/{scsAsId}/subscriptions/{subscriptionId}", + "custOpName": "http_get", + "operations": [ + "GET", + "PUT", + "DELETE" + ], + "description": "Endpoint to manage single subscription" + } + ], + "custOperations": [ + { + "commType": "REQUEST_RESPONSE", + "custOpName": "string", + "operations": [ + "POST" + ], + "description": "string" + } + ] + } + ], + "protocol": "HTTP_1_1", + "dataFormat": "JSON", + "securityMethods": [ + "Oauth", + "PSK" + ], + "interfaceDescriptions": [ + { + "ipv4Addr": "127.0.0.1", + "port": 8888, + "securityMethods": [ + "Oauth" + ] + } + ] + }, + { + "aefId": "AEFb1a2a317fff0d10f08676431ae4a68", + "versions": [ + { + "apiVersion": "v1", + "expiry": "2100-11-30T10:32:02.004Z", + "resources": [ + { + "resourceName": "TSN_LIST_PROFILES", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/profile", + "custOpName": "http_get", + "operations": [ + "GET" + ], + "description": "Endpoint for retrieving the list of available TSN profiles" + }, + { + "resourceName": "TSN_DETAIL_PROFILE", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/profile?name={profileName}", + "custOpName": "http_get", + "operations": [ + "GET" + ], + "description": "Endpoint for retrieving information about a single TSN profile" + }, + { + "resourceName": "TSN_APPLY_CONFIGURATION", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/apply", + "custOpName": "http_post", + "operations": [ + "POST" + ], + "description": "Endpoint for configuring TSN connection parameters" + }, + { + "resourceName": "TSN_CLEAR_CONFIGURATION", + "commType": " SUBSCRIBE_NOTIFY", + "uri": "/clear", + "custOpName": "http_post", + "operations": [ + "POST" + ], + "description": "Endpoint for removing a previous TSN connection configuration" + } + ], + "custOperations": [ + { + "commType": "REQUEST_RESPONSE", + "custOpName": "string", + "operations": [ + "POST" + ], + "description": "string" + } + ] + } + ], + "protocol": "HTTP_1_1", + "dataFormat": "JSON", + "securityMethods": [ + "Oauth" + ], + "interfaceDescriptions": [ + { + "ipv4Addr": "127.0.0.1", + "port": 8899, + "securityMethods": [ + "Oauth" + ] + } + ] + } + ], + "description": "API of dummy netapp to test", + "supportedFeatures": "fffff", + "shareableInfo": { + "isShareable": true, + "capifProvDoms": [ + "string" + ] + }, + "serviceAPICategory": "string", + "apiSuppFeats": "fffff", + "pubApiPath": { + "ccfIds": [ + "string" + ] + }, + "ccfId": "string" +} \ No newline at end of file diff --git a/test/netapp-provider-api-spec.json b/test/netapp-provider-api-spec.json index d41d9f8c77e80bb10b219869d4be8efa2af8ce60..fa47e235272f6091fe5db9731ee1b2021af1d410 100755 --- a/test/netapp-provider-api-spec.json +++ b/test/netapp-provider-api-spec.json @@ -2,7 +2,7 @@ "apiName": "Test", "aefProfiles": [ { - "aefId": "AEF295be601e3fad4886d0207f2371493", + "aefId": "AEF95f7fd34d9163a8d4e64694bd0f9c1", "versions": [ { "apiVersion": "v1", @@ -61,7 +61,7 @@ ] }, { - "aefId": "AEF6cc62d5779ca43df0e95c7908524f2", + "aefId": "AEF5d3bde7bacba44152076162b10ece7", "versions": [ { "apiVersion": "v1", diff --git a/test/test.py b/test/test.py index 79aa9e70ffacfbbb8113e0d6da9dffc55036297d..3c0fe30460f6ec2c745b9ad4d3e5f72623e93def 100644 --- a/test/test.py +++ b/test/test.py @@ -11,6 +11,129 @@ from sdk import CAPIFProviderConnector, CAPIFInvokerConnector, ServiceDiscoverer capif_sdk_config_path = "./capif-sdk-config-sample-test.json" +def preparation_for_update(APFs,AEFs,second_netapp_api): + with open(capif_sdk_config_path, 'r') as file: + config = json.load(file) + config['apfs']=APFs + config['aefs']=AEFs + if second_netapp_api: + config['api_description_path']="./netapp-provider-api-spec-2.json" + else: + config['api_description_path']="./netapp-provider-api-spec-3.json" + with open(capif_sdk_config_path, 'w') as file: + json.dump(config, file, indent=4) + + capif_provider_connector = CAPIFProviderConnector(config_file=capif_sdk_config_path) + + return capif_provider_connector + +def ensure_update(Chosen_apf,Chosen_aefs,second_netapp_api): + + if second_netapp_api: + # Obtención de los AEFs ids y APFs ids para publicar una API + with open(capif_sdk_config_path, 'r') as file: + config = json.load(file) + + provider_folder = config.get('provider_folder') + username_folder = config.get('capif_username') + if not provider_folder: + raise ValueError("El valor 'provider_folder' no está definido en el archivo de configuración.") + + detailspath = os.path.join(provider_folder, username_folder, "capif_provider_details.json") + if not os.path.exists(detailspath): + raise FileNotFoundError(f"No se encontró el archivo {detailspath}") + + with open(detailspath, 'r') as file: + details = json.load(file) + + APF = details.get(Chosen_apf) + AEF1 = details.get(Chosen_aefs[0]) + AEF2 = details.get(Chosen_aefs[1]) + AEF3 = details.get(Chosen_aefs[2]) + + if not APF or not AEF1 or not AEF2: + raise ValueError("No se encontraron todos los valores necesarios en 'Capif_provider_details.json'") + + # Actualización del archivo de configuración + config['publish_req']['publisher_apf_id'] = APF + config['publish_req']['publisher_aefs_ids'] = [AEF1,AEF2,AEF3] + + with open(capif_sdk_config_path, 'w') as file: + json.dump(config, file, indent=4) # Guarda el JSON con formato + + print("Archivo de configuración actualizado correctamente.") + else: + with open(capif_sdk_config_path, 'r') as file: + config = json.load(file) + + provider_folder = config.get('provider_folder') + username_folder = config.get('capif_username') + if not provider_folder: + raise ValueError("El valor 'provider_folder' no está definido en el archivo de configuración.") + + detailspath = os.path.join(provider_folder, username_folder, "capif_provider_details.json") + if not os.path.exists(detailspath): + raise FileNotFoundError(f"No se encontró el archivo {detailspath}") + + with open(detailspath, 'r') as file: + details = json.load(file) + + APF = details.get('APF-1_api_prov_func_id') + AEF1 = details.get('AEF-1_api_prov_func_id') + AEF2 = details.get('AEF-2_api_prov_func_id') + + if not APF or not AEF1 or not AEF2: + raise ValueError("No se encontraron todos los valores necesarios en 'Capif_provider_details.json'") + + # Actualización del archivo de configuración + config['publish_req']['publisher_apf_id'] = APF + config['publish_req']['publisher_aefs_ids'] = [AEF1, AEF2] + + with open(capif_sdk_config_path, 'w') as file: + json.dump(config, file, indent=4) # Guarda el JSON con formato + + print("Archivo de configuración actualizado correctamente.") + + capif_provider_connector = CAPIFProviderConnector(config_file=capif_sdk_config_path) + + capif_provider_connector.publish_services() + + print("PROVIDER PUBLISH COMPLETED") + + PublishedApis = os.path.join(provider_folder, username_folder, "Published-Apis.json") + if not os.path.exists(PublishedApis): + raise FileNotFoundError(f"No se encontró el archivo {PublishedApis}") + + with open(PublishedApis, 'r') as file: + PublishedApis = json.load(file) + if second_netapp_api: + service_api_id = PublishedApis.get('Test-2') + else: + service_api_id = PublishedApis.get('Test-3') + + with open(capif_sdk_config_path, 'r') as file: + config = json.load(file) + + config['publish_req']['service_api_id'] = service_api_id + + with open(capif_sdk_config_path, 'w') as file: + json.dump(config, file, indent=4) # Guarda el JSON con formato + + capif_provider_connector = CAPIFProviderConnector(config_file=capif_sdk_config_path) + + capif_provider_connector.update_service() + + print("PROVIDER UPDATE SERVICE COMPLETED") + + capif_provider_connector.get_all_services() + + print("PROVIDER GET ALL SERVICES COMPLETED") + + capif_provider_connector.get_service() + + print("PROVIDER GET SERVICE COMPLETED") + + if __name__ == "__main__": try: # Inicialización del conector @@ -100,6 +223,10 @@ if __name__ == "__main__": discoverer.get_tokens() print("SERVICE GET TOKENS COMPLETED") + + capif_invoker_connector.update_invoker() + + print("INVOKER UPDATE SERVICE COMPLETED") capif_invoker_connector.offboard_invoker() @@ -109,7 +236,29 @@ if __name__ == "__main__": print("PROVIDER UNPUBLISH SERVICE COMPLETED") - # capif_provider_connector.update_service() + capif_provider_connector=preparation_for_update("2","4",True) + + capif_provider_connector.update_provider() + + Chosen_apf= "APF-2_api_prov_func_id" + + Chosen_aefs= ["AEF-1_api_prov_func_id","AEF-3_api_prov_func_id","AEF-4_api_prov_func_id"] + + ensure_update(Chosen_apf,Chosen_aefs,True) + + print("PROVIDER UPDATE ONE COMPLETED") + + capif_provider_connector=preparation_for_update("1","2",False) + + capif_provider_connector.update_provider() + + Chosen_apf= "APF-1_api_prov_func_id" + + Chosen_aefs= ["AEF-1_api_prov_func_id","AEF-2_api_prov_func_id"] + + ensure_update(Chosen_apf,Chosen_aefs,False) + + print("PROVIDER UPDATE TWO COMPLETED") capif_provider_connector.offboard_provider() @@ -123,3 +272,4 @@ if __name__ == "__main__": print(f"Error al leer el archivo JSON: {e}") except Exception as e: print(f"Error inesperado: {e}") +