blob: 88053e883fd7f97780466f93e3cbf6841627668f [file] [log] [blame]
kaihlavid1a1fb72019-06-13 16:11:48 +03001*** Settings ***
2Library Collections
3Library OperatingSystem
4Library RequestsLibrary
5Library ONAPLibrary.Utilities
6
7Resource 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
17${ASDC_CATALOG_RESOURCE_TEMPLATE} ${ASSETS_DIR}component_catalog_resource.template
18${ASDC_CATALOG_SERVICE_TEMPLATE} ${ASSETS_DIR}catalog_service.template
19${ASDC_ARTIFACT_UPLOAD_TEMPLATE} ${ASSETS_DIR}artifact_upload.template
20${ASDC_USER_REMARKS_TEMPLATE} ${ASSETS_DIR}user_remarks.template
21${DCAE_VFCMT_TEMPLATE} ${ASSETS_DIR}create_vfcmt.template
22${DCAE_COMPOSITION_TEMPLATE} ${ASSETS_DIR}dcae_composition.template
23${DCAE_MONITORING_CONFIGURATION_TEMPLATE} ${ASSETS_DIR}dcae_monitoring_configuration.template
24${ASDC_RESOURCE_INSTANCE_TEMPLATE} ${ASSETS_DIR}resource_instance.template
25
26${ASDC_BE_ENDPOINT} http://localhost:8080
27
28*** Keywords ***
29
30Create Catalog Resource Data
31 [Documentation] Creates and returns data for ASDC Catalog Resource
32 [Arguments] ${resource_name} ${vendor_name}
33 ${map}= Create Dictionary resource_name=${resource_name} vendor_name=${vendor_name}
34 ${data}= json_templater.Fill JSON Template File ${ASDC_CATALOG_RESOURCE_TEMPLATE} ${map}
35 [Return] ${data}
36
37# Based on testsuite/robot/resources/asdc_interface.robot's 'Post ASDC Resource Request' keyword
38Post ASDC Resource Request Unauthenticated
39 [Documentation] Makes unauthenticated Post request for ASDC Catalog resource and returns its unique id
40 [Arguments] ${data}
41 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_RESOURCES_PATH} ${data} ${ASDC_DESIGNER_USER_ID}
42 Should Be Equal As Strings ${resp.status_code} 201
43 [Return] ${resp.json()['uniqueId']}
44
45# Based on testsuite/robot/resources/asdc_interface.robot's 'Run ASDC Post Request' keyword
46Run ASDC Post Request Unauthenticated
47 [Documentation] Runs an ASDC Post request without authentication and returns the HTTP response
48 [Arguments] ${data_path} ${data} ${user}=${ASDC_DESIGNER_USER_ID} ${MY_ASDC_BE_ENDPOINT}=${ASDC_BE_ENDPOINT}
49 Log Creating session ${MY_ASDC_BE_ENDPOINT}
50 ${session}= Create Session asdc ${MY_ASDC_BE_ENDPOINT}
51 ${uuid}= Generate UUID4
52 ${headers}= Create Dictionary Accept=application/json Content-Type=application/json USER_ID=${user} X-TransactionId=${GLOBAL_APPLICATION_ID}-${uuid} X-FromAppId=${GLOBAL_APPLICATION_ID}
53 ${resp}= Post Request asdc ${data_path} data=${data} headers=${headers}
54 Log Received response from asdc ${resp.text}
55 [Return] ${resp}
56
57# Based on testsuite/robot/resources/asdc_interface.robot's 'Run ASDC MD5 Post Request' keyword
58Run ASDC MD5 Post Request Unauthenticated
59 [Documentation] Runs an ASDC post request with MD5 Checksum header without authentication and returns the HTTP response
60 [Arguments] ${data_path} ${data} ${user}=${ASDC_DESIGNER_USER_ID} ${MY_ASDC_BE_ENDPOINT}=${ASDC_BE_ENDPOINT}
61 Log Creating session ${MY_ASDC_BE_ENDPOINT}
62 ${session}= Create Session asdc ${MY_ASDC_BE_ENDPOINT}
63 ${uuid}= Generate UUID4
64 ${data_string}= Evaluate json.dumps(${data}) json
65 ${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}
68 ${resp}= Post Request asdc ${data_path} data=${data} headers=${headers}
69 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}
79 ${data}= Fill JSON Template File ${ASDC_ARTIFACT_UPLOAD_TEMPLATE} ${dict}
80 # POST artifactUpload to resource
81 ${resp}= Run ASDC MD5 Post Request Unauthenticated ${ASDC_CATALOG_RESOURCES_PATH}/${vf_id}/artifacts ${data} ${ASDC_DESIGNER_USER_ID}
82 Should Be Equal As Strings ${resp.status_code} 200
83 [Return] ${resp}
84
85# Directly copied from testsuite/robot/resources/asdc_interface.robot
86Certify ASDC Catalog Resource
87 [Documentation] Certifies an ASDC Catalog Resource by its id and returns the new id
88 [Arguments] ${catalog_resource_id} ${user_id}=${ASDC_TESTER_USER_ID}
89 ${map}= Create Dictionary user_remarks=Robot remarks
90 ${data}= Fill JSON Template File ${ASDC_USER_REMARKS_TEMPLATE} ${map}
91 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_RESOURCES_PATH}/${catalog_resource_id}${ASDC_CATALOG_LIFECYCLE_PATH}/certify ${data} ${user_id}
92 Should Be Equal As Strings ${resp.status_code} 200
93 [Return] ${resp.json()['uniqueId']} ${resp.json()['uuid']}
94
95Add Catalog Service For Monitoring Template
96 [Documentation] Creates an ASDC Catalog Service for Monitoring Template with given name
97 [Arguments] ${service_name}
98 ${map}= Create Dictionary service_name=${service_name}
99 ${data}= Fill JSON Template File ${ASDC_CATALOG_SERVICE_TEMPLATE} ${map}
100 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH} ${data}
101 Should Be Equal As Strings ${resp.status_code} 201
102 [Return] ${resp.json()['uniqueId']} ${resp.json()['uuid']}
103
104# Based on testsuite/robot/resources/asdc_interface.robot's 'Add ASDC Resource Instance' keyword
105Add ASDC Resource Instance
106 [Documentation] Creates an ASDC Resource Instance and returns its id
107 [Arguments] ${catalog_service_id} ${catalog_resource_id} ${catalog_resource_name} ${xoffset}=${0} ${yoffset}=${0} ${resourceType}=VF
108 ${milli_timestamp}= Generate Timestamp
109 ${xoffset}= Set Variable ${xoffset+306}
110 ${yoffset}= Set Variable ${yoffset+248}
111 ${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}
112 ${data}= Fill JSON Template File ${ASDC_RESOURCE_INSTANCE_TEMPLATE} ${map}
113 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_SERVICE_RESOURCE_INSTANCE_PATH} ${data} ${ASDC_DESIGNER_USER_ID}
114 Should Be Equal As Strings ${resp.status_code} 201
115 [Return] ${resp.json()['uniqueId']} ${resp.json()['name']}
116
117# Adjusted from asdc_interface.robot
118
119Checkin ASDC Catalog Service
120 [Documentation] Checks in an ASDC Catalog Service by its id
121 [Arguments] ${catalog_service_id}
122 ${map}= Create Dictionary user_remarks=Robot remarks
123 ${data}= Fill JSON Template File ${ASDC_USER_REMARKS_TEMPLATE} ${map}
124 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_LIFECYCLE_PATH}/checkin ${data} ${ASDC_DESIGNER_USER_ID}
125 Should Be Equal As Strings ${resp.status_code} 200
126 [Return] ${resp.json()}
127
128Request Certify ASDC Catalog Service
129 [Documentation] Requests certification of an ASDC Catalog Service by its id
130 [Arguments] ${catalog_service_id}
131 ${map}= Create Dictionary user_remarks=Robot remarks
132 ${data}= Fill JSON Template File ${ASDC_USER_REMARKS_TEMPLATE} ${map}
133 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_LIFECYCLE_PATH}/certificationRequest ${data} ${ASDC_DESIGNER_USER_ID}
134 Should Be Equal As Strings ${resp.status_code} 200
135 [Return] ${resp.json()}
136
137Start Certify ASDC Catalog Service
138 [Documentation] Start certification of an ASDC Catalog Service by its id
139 [Arguments] ${catalog_service_id}
140 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_LIFECYCLE_PATH}/startCertification ${None} ${ASDC_TESTER_USER_ID}
141 Should Be Equal As Strings ${resp.status_code} 200
142 [Return] ${resp.json()}
143
144Certify ASDC Catalog Service
145 [Documentation] Certifies an ASDC Catalog Service by its id and returns the new id
146 [Arguments] ${catalog_service_id}
147 ${map}= Create Dictionary user_remarks=Robot remarks
148 ${data}= Fill JSON Template File ${ASDC_USER_REMARKS_TEMPLATE} ${map}
149 ${resp}= Run ASDC Post Request Unauthenticated ${ASDC_CATALOG_SERVICES_PATH}/${catalog_service_id}${ASDC_CATALOG_LIFECYCLE_PATH}/certify ${data} ${ASDC_TESTER_USER_ID}
150 Should Be Equal As Strings ${resp.status_code} 200
151 [Return] ${resp.json()['uniqueId']}
152
153Approve ASDC Catalog Service
154 [Documentation] Approves an ASDC Catalog Service by its id
155 [Arguments] ${catalog_service_id}
156 ${map}= Create Dictionary user_remarks=Robot remarks
157 ${data}= Fill JSON Template File ${ASDC_USER_REMARKS_TEMPLATE} ${map}
158 ${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}
159 Should Be Equal As Strings ${resp.status_code} 200
160 [Return] ${resp.json()}
161