Olivia.Zhan | 280a868 | 2019-07-13 13:52:28 +0800 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Resource ../../common.robot |
| 3 | Library Collections |
| 4 | Library RequestsLibrary |
| 5 | Library OperatingSystem |
| 6 | Library json |
| 7 | Library HttpLibrary.HTTP |
| 8 | |
| 9 | *** Variables *** |
| 10 | ${catalog_port} 8806 |
| 11 | ${vnf_packages_url} /api/vnfpkgm/v1/vnf_packages |
| 12 | ${ns_descriptors_url} /api/nsd/v1/ns_descriptors |
| 13 | |
| 14 | #json files |
| 15 | ${request_json} ${SCRIPTS}/../tests/vfc/nfvo-catalog/jsons/CreateNsdInfoRequest.json |
| 16 | ${request_csar} ${SCRIPTS}/../tests/vfc/nfvo-catalog/files/ns_vgw.csar |
| 17 | |
| 18 | #global variables |
| 19 | ${nsdId} |
| 20 | |
| 21 | *** Test Cases *** |
| 22 | Create new Network Service Descriptor Resource for pre-condition |
| 23 | Log Create new Network Service Descriptor Resource for pre-condition |
| 24 | ${json_value}= json_from_file ${request_json} |
| 25 | ${json_string}= string_from_json ${json_value} |
| 26 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 27 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 28 | Set Request Body ${json_string} |
| 29 | ${resp}= Post Request web_session ${ns_descriptors_url} ${json_string} |
| 30 | Should Be Equal As Strings 201 ${resp.status_code} |
| 31 | ${response_json} json.loads ${resp.content} |
| 32 | Should Be Equal As Strings CREATED ${response_json['nsdOnboardingState']} |
| 33 | ${nsdId}= Convert To String ${response_json['id']} |
| 34 | Set Global Variable ${nsdId} |
| 35 | |
| 36 | Check Precondition |
| 37 | Log Check Precondition |
| 38 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 39 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 40 | ${resp}= Get Request web_session ${vnf_packages_url} |
| 41 | Should Be Equal As Strings 200 ${resp.status_code} |
| 42 | ${response_json} json.loads ${resp.content} |
| 43 | Should Be Equal As Strings ONBOARDED ${response_json[0]['onboardingState']} |
| 44 | |
| 45 | Upload NSD Content as Zip file |
| 46 | Log Upload NSD Content as Zip file |
| 47 | [Documentation] The objective is to test the upload of an NSD Content in Zip format |
| 48 | Create Session web_session http://${CATALOG_IP}:${catalog_port} |
| 49 | ${headers} Create Dictionary Accept=application/json |
| 50 | &{fileParts}= Create Dictionary |
| 51 | Create Multi Part ${fileParts} file ${request_csar} |
| 52 | Log ${fileParts} |
| 53 | ${resp}= Put Request web_session ${ns_descriptors_url}/${nsdId}/nsd_content files=${fileParts} headers=${headers} |
| 54 | Log ${resp.status_code} |
| 55 | Should Be Equal As Strings 204 ${resp.status_code} |
| 56 | Log Received 204 Accepted as expected |
| 57 | |
| 58 | GET NSD Content |
| 59 | Log GET NSD Content |
| 60 | [Documentation] The objective is to test the retrieval of the NSD Content |
| 61 | ${headers} Create Dictionary Content-Type=application/json |
| 62 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 63 | ${resp}= Get Request web_session ${ns_descriptors_url}/${nsdId}/nsd_content |
| 64 | Should Be Equal As Strings 200 ${resp.status_code} |
| 65 | |
| 66 | Check Postcondition |
| 67 | Log Check Postcondition |
| 68 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 69 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 70 | ${resp}= Get Request web_session ${ns_descriptors_url}/${nsdId} |
| 71 | Should Be Equal As Strings 200 ${resp.status_code} |
| 72 | ${response_json} json.loads ${resp.content} |
| 73 | Should Be Equal As Strings ONBOARDED ${response_json['nsdOnboardingState']} |
| 74 | |
| 75 | POST NSD Content - Method not implemented |
| 76 | Log POST NSD Content - Method not implemented |
| 77 | [Documentation] The objective is to test that POST method is not allowed to create new Network Service Descriptor content |
| 78 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 79 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 80 | ${resp}= Post Request web_session ${ns_descriptors_url}/${nsdId}/nsd_content |
| 81 | Should Be Equal As Strings 405 ${resp.status_code} |
| 82 | |
| 83 | PATCH NSD Content - Method not implemented |
| 84 | Log PATCH NSD Content - Method not implemented |
| 85 | [Documentation] The objective is to test that PATCH method is not allowed to update a Network Service Descriptor content |
| 86 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 87 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 88 | ${resp}= Patch Request web_session ${ns_descriptors_url}/${nsdId}/nsd_content |
| 89 | Should Be Equal As Strings 405 ${resp.status_code} |
| 90 | |
| 91 | DELETE NSD Content - Method not implemented |
| 92 | Log DELETE NSD Content - Method not implemented |
| 93 | [Documentation] The objective is to test that DELETE method is not allowed to delete a Network Service Descriptor content |
| 94 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 95 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 96 | ${resp}= Delete Request web_session ${ns_descriptors_url}/${nsdId}/nsd_content |
| 97 | Should Be Equal As Strings 405 ${resp.status_code} |
| 98 | |
| 99 | *** Keywords *** |
| 100 | Create Multi Part |
| 101 | [Arguments] ${addTo} ${partName} ${filePath} ${contentType}=${None} ${content}=${None} |
| 102 | ${fileData}= Run Keyword If '''${content}''' != '''${None}''' Set Variable ${content} |
| 103 | ... ELSE Get Binary File ${filePath} |
| 104 | ${fileDir} ${fileName}= Split Path ${filePath} |
| 105 | ${partData}= Create List ${fileName} ${fileData} ${contentType} |
| 106 | Set To Dictionary ${addTo} ${partName}=${partData} |