blob: c01dc09731421787953d96499399f2bdbf1b7c5d [file] [log] [blame]
kaihlavid1a1fb72019-06-13 16:11:48 +03001*** Settings ***
2Library Collections
3Library OperatingSystem
4Library RequestsLibrary
5Library ONAPLibrary.Utilities
kaihlavi22bc9232019-07-31 19:54:49 +03006Library ONAPLibrary.Templating WITH NAME Templating
kaihlavid1a1fb72019-06-13 16:11:48 +03007Resource common.robot
8
9***Variables ***
10${ASDC_CATALOG_SERVICES_PATH} /sdc2/rest/v1/catalog/services
11${ASDC_CATALOG_RESOURCES_PATH} /sdc2/rest/v1/catalog/resources
12${ASDC_CATALOG_LIFECYCLE_PATH} /lifecycleState
13${ASDC_CATALOG_SERVICE_RESOURCE_INSTANCE_PATH} /resourceInstance
14${ASDC_CATALOG_SERVICE_DISTRIBUTION_STATE_PATH} /distribution-state
15${ASDC_DISTRIBUTION_STATE_APPROVE_PATH} /approve
16
kaihlavi22bc9232019-07-31 19:54:49 +030017${SDC_CATALOG_RESOURCE_TEMPLATE} component_catalog_resource.jinja
18${SDC_CATALOG_SERVICE_TEMPLATE} catalog_service.jinja
19${SDC_ARTIFACT_UPLOAD_TEMPLATE} artifact_upload.jinja
20${SDC_USER_REMARKS_TEMPLATE} user_remarks.jinja
21${SDC_RESOURCE_INSTANCE_TEMPLATE} resource_instance.jinja
kaihlavid1a1fb72019-06-13 16:11:48 +030022
23${ASDC_BE_ENDPOINT} http://localhost:8080
24
25*** Keywords ***
26
27Create Catalog Resource Data
28 [Documentation] Creates and returns data for ASDC Catalog Resource
29 [Arguments] ${resource_name} ${vendor_name}
30 ${map}= Create Dictionary resource_name=${resource_name} vendor_name=${vendor_name}
kaihlavi22bc9232019-07-31 19:54:49 +030031 Templating.Create Environment sdc_catalog_resource ${ASSETS_DIR}
32 ${data}= Templating.Apply Template sdc_catalog_resource ${SDC_CATALOG_RESOURCE_TEMPLATE} ${map}
kaihlavid1a1fb72019-06-13 16:11:48 +030033 [Return] ${data}
34
35# Based on testsuite/robot/resources/asdc_interface.robot's 'Post ASDC Resource Request' keyword
36Post ASDC Resource Request Unauthenticated
37 [Documentation] Makes unauthenticated Post request for ASDC Catalog resource and returns its unique id
38 [Arguments] ${data}
39 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_RESOURCES_PATH} ${data} ${ASDC_DESIGNER_USER_ID}
40 Should Be Equal As Strings ${resp.status_code} 201
41 [Return] ${resp.json()['uniqueId']}
42
43# Based on testsuite/robot/resources/asdc_interface.robot's 'Run ASDC Post Request' keyword
44Run ASDC Post Request Unauthenticated
45 [Documentation] Runs an ASDC Post request without authentication and returns the HTTP response
46 [Arguments] ${data_path} ${data} ${user}=${ASDC_DESIGNER_USER_ID} ${MY_ASDC_BE_ENDPOINT}=${ASDC_BE_ENDPOINT}
47 Log Creating session ${MY_ASDC_BE_ENDPOINT}
48 ${session}= Create Session asdc ${MY_ASDC_BE_ENDPOINT}
49 ${uuid}= Generate UUID4
50 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json USER_ID=${user} X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID}
51 ${resp}= Post Request asdc ${data_path} data=${data} headers=${headers}
52 Log Received response from asdc ${resp.text}
53 [Return] ${resp}
54
55# Based on testsuite/robot/resources/asdc_interface.robot's 'Run ASDC MD5 Post Request' keyword
56Run ASDC MD5 Post Request Unauthenticated
57 [Documentation] Runs an ASDC post request with MD5 Checksum header without authentication and returns the HTTP response
58 [Arguments] ${data_path} ${data} ${user}=${ASDC_DESIGNER_USER_ID} ${MY_ASDC_BE_ENDPOINT}=${ASDC_BE_ENDPOINT}
59 Log Creating session ${MY_ASDC_BE_ENDPOINT}
kaihlavi22bc9232019-07-31 19:54:49 +030060 # This is needed to ensure that the data is in dict format - otherwise the checksum will not match
61 ${dict_data}= evaluate json.loads('''${data}''') json
kaihlavid1a1fb72019-06-13 16:11:48 +030062 ${session}= Create Session asdc ${MY_ASDC_BE_ENDPOINT}
63 ${uuid}= Generate UUID4
kaihlavi22bc9232019-07-31 19:54:49 +030064 ${data_string}= Evaluate json.dumps(${dict_data}) json
kaihlavid1a1fb72019-06-13 16:11:48 +030065 ${md5checksum}= Evaluate md5.new('''${data_string}''').hexdigest() modules=md5
66 ${base64md5checksum}= Evaluate base64.b64encode("${md5checksum}") modules=base64
67 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json USER_ID=${user} X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID} Content-MD5=${base64md5checksum}
kaihlavi22bc9232019-07-31 19:54:49 +030068 ${resp}= Post Request asdc ${data_path} data=${dict_data} headers=${headers}
kaihlavid1a1fb72019-06-13 16:11:48 +030069 Log Received response from asdc: ${resp.text}
70 [Return] ${resp}
71
72# Based on testsuite/robot/resources/asdc_interface.robot's 'Setup SDC Catalog Resource Deployment Artifact Properties' keyword
73Add Tosca Artifact To Resource
74 [Documentation] Add Tosca artifacts to given resource id
75 [Arguments] ${artifact} ${vf_id}
76 ${blueprint_data} OperatingSystem.Get File ${ASSETS_DIR}${artifact}.yaml
77 ${payloadData}= Evaluate base64.b64encode('''${blueprint_data}'''.encode('utf-8')) modules=base64
78 ${dict}= Create Dictionary artifactLabel=${artifact} artifactName=${artifact}.yaml artifactType=DCAE_TOSCA artifactGroupType=DEPLOYMENT description=${artifact}.yaml payloadData=${payloadData}
kaihlavi22bc9232019-07-31 19:54:49 +030079 Templating.Create Environment sdc_artifact_upload ${ASSETS_DIR}
80 ${data}= Templating.Apply Template sdc_artifact_upload ${SDC_ARTIFACT_UPLOAD_TEMPLATE} ${dict}
kaihlavid1a1fb72019-06-13 16:11:48 +030081 # POST artifactUpload to resource
82 ${resp}= Run ASDC MD5 Post Request Unauthenticated ${ASDC_CATALOG_RESOURCES_PATH}/${vf_id}/artifacts ${data} ${ASDC_DESIGNER_USER_ID}
83 Should Be Equal As Strings ${resp.status_code} 200
84 [Return] ${resp}
85
86# Directly copied from testsuite/robot/resources/asdc_interface.robot
87Certify ASDC Catalog Resource
88 [Documentation] Certifies an ASDC Catalog Resource by its id and returns the new id
89 [Arguments] ${catalog_resource_id} ${user_id}=${ASDC_TESTER_USER_ID}
90 ${map}= Create Dictionary user_remarks=Robot remarks
kaihlavi22bc9232019-07-31 19:54:49 +030091 Templating.Create Environment sdc_user_remarks ${ASSETS_DIR}
92 ${data}= Templating.Apply Template sdc_user_remarks ${SDC_USER_REMARKS_TEMPLATE} ${map}
kaihlavid1a1fb72019-06-13 16:11:48 +030093 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_RESOURCES_PATH}/${catalog_resource_id}${ASDC_CATALOG_LIFECYCLE_PATH}/certify ${data} ${user_id}
94 Should Be Equal As Strings ${resp.status_code} 200
95 [Return] ${resp.json()['uniqueId']} ${resp.json()['uuid']}
96
97Add Catalog Service For Monitoring Template
98 [Documentation] Creates an ASDC Catalog Service for Monitoring Template with given name
99 [Arguments] ${service_name}
100 ${map}= Create Dictionary service_name=${service_name}
kaihlavi22bc9232019-07-31 19:54:49 +0300101 Templating.Create Environment sdc_catalog_service ${ASSETS_DIR}
102 ${data}= Templating.Apply Template sdc_catalog_service ${SDC_CATALOG_SERVICE_TEMPLATE} ${map}
kaihlavid1a1fb72019-06-13 16:11:48 +0300103 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH} ${data}
104 Should Be Equal As Strings ${resp.status_code} 201
105 [Return] ${resp.json()['uniqueId']} ${resp.json()['uuid']}
106
107# Based on testsuite/robot/resources/asdc_interface.robot's 'Add ASDC Resource Instance' keyword
108Add ASDC Resource Instance
109 [Documentation] Creates an ASDC Resource Instance and returns its id
110 [Arguments] ${catalog_service_id} ${catalog_resource_id} ${catalog_resource_name} ${xoffset}=${0} ${yoffset}=${0} ${resourceType}=VF
111 ${milli_timestamp}= Generate Timestamp
112 ${xoffset}= Set Variable ${xoffset+306}
113 ${yoffset}= Set Variable ${yoffset+248}
114 ${map}= Create Dictionary catalog_resource_id=${catalog_resource_id} catalog_resource_name=${catalog_resource_name} milli_timestamp=${milli_timestamp} posX=${xoffset} posY=${yoffset} originType=${resourceType}
kaihlavi22bc9232019-07-31 19:54:49 +0300115 Templating.Create Environment sdc_resource_instance ${ASSETS_DIR}
116 ${data}= Templating.Apply Template sdc_resource_instance ${SDC_RESOURCE_INSTANCE_TEMPLATE} ${map}
kaihlavid1a1fb72019-06-13 16:11:48 +0300117 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_SERVICE_RESOURCE_INSTANCE_PATH} ${data} ${ASDC_DESIGNER_USER_ID}
118 Should Be Equal As Strings ${resp.status_code} 201
119 [Return] ${resp.json()['uniqueId']} ${resp.json()['name']}
120
121# Adjusted from asdc_interface.robot
122
123Checkin ASDC Catalog Service
124 [Documentation] Checks in an ASDC Catalog Service by its id
125 [Arguments] ${catalog_service_id}
126 ${map}= Create Dictionary user_remarks=Robot remarks
kaihlavi22bc9232019-07-31 19:54:49 +0300127 Templating.Create Environment sdc_user_remarks ${ASSETS_DIR}
128 ${data}= Templating.Apply Template sdc_user_remarks ${SDC_USER_REMARKS_TEMPLATE} ${map}
kaihlavid1a1fb72019-06-13 16:11:48 +0300129 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_LIFECYCLE_PATH}/checkin ${data} ${ASDC_DESIGNER_USER_ID}
130 Should Be Equal As Strings ${resp.status_code} 200
131 [Return] ${resp.json()}
132
133Request Certify ASDC Catalog Service
134 [Documentation] Requests certification of an ASDC Catalog Service by its id
135 [Arguments] ${catalog_service_id}
136 ${map}= Create Dictionary user_remarks=Robot remarks
kaihlavi22bc9232019-07-31 19:54:49 +0300137 Templating.Create Environment sdc_user_remarks ${ASSETS_DIR}
138 ${data}= Templating.Apply Template sdc_user_remarks ${SDC_USER_REMARKS_TEMPLATE} ${map}
kaihlavid1a1fb72019-06-13 16:11:48 +0300139 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_LIFECYCLE_PATH}/certificationRequest ${data} ${ASDC_DESIGNER_USER_ID}
140 Should Be Equal As Strings ${resp.status_code} 200
141 [Return] ${resp.json()}
142
143Start Certify ASDC Catalog Service
144 [Documentation] Start certification of an ASDC Catalog Service by its id
145 [Arguments] ${catalog_service_id}
146 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_LIFECYCLE_PATH}/startCertification ${None} ${ASDC_TESTER_USER_ID}
147 Should Be Equal As Strings ${resp.status_code} 200
148 [Return] ${resp.json()}
149
150Certify ASDC Catalog Service
151 [Documentation] Certifies an ASDC Catalog Service by its id and returns the new id
152 [Arguments] ${catalog_service_id}
153 ${map}= Create Dictionary user_remarks=Robot remarks
kaihlavi22bc9232019-07-31 19:54:49 +0300154 Templating.Create Environment sdc_user_remarks ${ASSETS_DIR}
155 ${data}= Templating.Apply Template sdc_user_remarks ${SDC_USER_REMARKS_TEMPLATE} ${map}
kaihlavid1a1fb72019-06-13 16:11:48 +0300156 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_LIFECYCLE_PATH}/certify ${data} ${ASDC_TESTER_USER_ID}
157 Should Be Equal As Strings ${resp.status_code} 200
158 [Return] ${resp.json()['uniqueId']}
159
160Approve ASDC Catalog Service
161 [Documentation] Approves an ASDC Catalog Service by its id
162 [Arguments] ${catalog_service_id}
163 ${map}= Create Dictionary user_remarks=Robot remarks
kaihlavi22bc9232019-07-31 19:54:49 +0300164 Templating.Create Environment sdc_user_remarks ${ASSETS_DIR}
165 ${data}= Templating.Apply Template sdc_user_remarks ${SDC_USER_REMARKS_TEMPLATE} ${map}
kaihlavid1a1fb72019-06-13 16:11:48 +0300166 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_SERVICE_DISTRIBUTION_STATE_PATH}${ASDC_DISTRIBUTION_STATE_APPROVE_PATH} ${data} ${ASDC_GOVERNOR_USER_ID}
167 Should Be Equal As Strings ${resp.status_code} 200
168 [Return] ${resp.json()}
169