From f8bae083c41925842730ea8d2b15c4cb125558e0 Mon Sep 17 00:00:00 2001
From: Elian Kraja <e.kraja@nextworks.it>
Date: Tue, 18 Sep 2018 18:36:28 +0200
Subject: [PATCH] Progress on VNFPackageManagement

---
 .../SOL003-VNFPackageManagement.robot         | 125 ++++++++++++++++++
 .../SOL003-VNFPackageManagement_pending.robot |  14 ++
 SOL003/variables.txt                          |  21 +++
 3 files changed, 160 insertions(+)
 create mode 100644 SOL003/VNFPackageManagement-API_nxw/SOL003-VNFPackageManagement.robot
 create mode 100644 SOL003/VNFPackageManagement-API_nxw/SOL003-VNFPackageManagement_pending.robot
 create mode 100644 SOL003/variables.txt

diff --git a/SOL003/VNFPackageManagement-API_nxw/SOL003-VNFPackageManagement.robot b/SOL003/VNFPackageManagement-API_nxw/SOL003-VNFPackageManagement.robot
new file mode 100644
index 00000000..98c367b1
--- /dev/null
+++ b/SOL003/VNFPackageManagement-API_nxw/SOL003-VNFPackageManagement.robot
@@ -0,0 +1,125 @@
+*** Settings ***
+Library           HttpLibrary.HTTP
+Resource          ../variables.txt
+Library           JSONSchemaLibrary    schemas/
+
+*** Test Cases ***
+VNF packages
+    Log    Trying to get all VNF Packages present in the NFVO Catalogue
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Set Request Header    Accept    ${ACCEPT}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages
+    Response Status Code Should Equal    200
+    ${vnfPkgInfos}=    Get Response Body
+    Response Header Should Equal    Content-Type    ${CONTENT_TYPE}
+    Log    Trying to validate response
+    Validate Json    vnfPkgInfo.schema.json    ${vnfPkgInfos}
+    Log    Validation OK
+    Log    Trying to generate a invalid request using invalid attribute filter
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Set Request Header    Accept    ${ACCEPT}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages?fields=wrong_field
+    Response Status Code Should Equal    400
+    Log    Response code il 400 as expected
+    Log    Trying to generate an invalid request using an invalid token
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Set Request Header    Accept    ${ACCEPT}
+    Set Request Header    Authorization    ${WRONG_AUTHORIZATION}
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages
+    Response Status Code Should Equal    401
+    Log    Response code is 401 as expected
+
+Individual VNF package
+    Log    Trying to get a VNF Package present in the NFVO Catalogue
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Set Request Header    Accept    ${ACCEPT}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId}
+    Response Status Code Should Equal    200
+    ${vnfPkgInfo}=    Get Response Body
+    Response Header Should Equal    Content-Type    ${CONTENT_TYPE}
+    Log    Trying to validate response
+    Validate Json    vnfPkgInfo.schema.json    ${vnfPkgInfo}
+    Log    Validation OK
+
+VNFD of an individual VNF package
+    Log    Trying to get the content of a VNFD within a VNF Package present in the NFVO Catalogue
+    Log    Request to have a VNFD from a given VNF Package
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    Set Request Header    Accept    ${ACCEPT_PLAIN}
+    Set Request Header    Accept    ${ACCEPT_ZIP}
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId}/vnfd
+    Response Status Code Should Equal    200
+    ${vnfPkgInfo}=    Get Response Body
+    #Run Keyword If    ${SINGLE_FILE_VNFD} == 1    Response Header Should Equal    Content-Type    ${ACCEPT_PLAIN}
+    Run Keyword If    ${SINGLE_FILE_VNFD} == 0    Response Header Should Equal    Content-Type    ${ACCEPT_ZIP}
+    Log    How to handle validation here? Are we going to check some fields from the json?
+    Log    Request that will generate an error (406) using an Accept header as text/plain but the NFVO could not provide
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    Set Request Header    Accept    ${WRONG_ACCEPT}
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId}/vnfd
+    Response Status Code Should Equal    406
+    Log    Received 406 Not Applicable
+
+VNF package content
+    Log    Trying to fetch the content of a VNF package identified by the VNF package identifier allocated by the NFVO
+    Log    Request to have the whole VNF Package
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    Set Request Header    Accept    ${ACCEPT_ZIP}
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId}/package_content
+    Response Status Code Should Equal    200
+    ${vnfPkgInfo}=    Get Response Body
+    Response Header Should Equal    Content-Type    ${ACCEPT_ZIP}
+    Log    Request to have the VNF Package using partial download
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    Set Request Header    Accept    ${ACCEPT_ZIP}
+    Set Request Header    Range    bytes=0-1023
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId}/package_content
+    Response Header Should Equal    Content-Length    2048
+    Response Header Should Equal    Content-Range    bytes 0-1023/2048
+    Response Status Code Should Equal    206
+    Log    Received 206 Partial Content
+    Log    Request that will generate a 416 Error. Package length in bytes is 2048 and will be requested a range from 2048 to 2560
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    Set Request Header    Accept    ${ACCEPT_ZIP}
+    Set Request Header    Range    bytes=2048-2560
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId}/package_content
+    Response Status Code Should Equal    416
+    Log    Received 416 Range not satisfiable
+
+Individual VNF package artifact
+    Log    Trying to get an individual artifact contained in a VNF package
+    Log    Request to have the whole VNF Package
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    Set Request Header    Accept    ${ARTIFACT_TYPE}
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId}/artifacts/${ARTIFACT_ID}
+    Response Status Code Should Equal    200
+    ${vnfPkgInfo}=    Get Response Body
+    Response Header Should Equal    Content-Type    ${ARTIFACT_TYPE}
+    Log    How to handle validation here? The object returned is a zip file
+    Log    Trying to get \ with partial download an individual artifact contained in a VNF package
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    Set Request Header    Accept    ${ARTIFACT_TYPE}
+    Set Request Header    Range    bytes=0-1023
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId}/artifacts/${ARTIFACT_ID}
+    Response Header Should Equal    Content-Length    2048
+    Response Header Should Equal    Content-Range    bytes 0-1023/2048
+    Response Status Code Should Equal    206
+    Log    Received 206 Partial Content
+    Log    Request that will generate a 416 Error. Artifact length in bytes is 2048 and will be requested a range from 2048 to 2560
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    Set Request Header    Accept    ${ARTIFACT_TYPE}
+    Set Request Header    Range    bytes=2048-2560
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId}/artifacts/${ARTIFACT_ID}
+    Response Status Code Should Equal    416
+    Log    Received 416 Range not satisfiable
diff --git a/SOL003/VNFPackageManagement-API_nxw/SOL003-VNFPackageManagement_pending.robot b/SOL003/VNFPackageManagement-API_nxw/SOL003-VNFPackageManagement_pending.robot
new file mode 100644
index 00000000..aa627394
--- /dev/null
+++ b/SOL003/VNFPackageManagement-API_nxw/SOL003-VNFPackageManagement_pending.robot
@@ -0,0 +1,14 @@
+*** Settings ***
+Library           HttpLibrary.HTTP
+Resource          ../variables.txt
+Library           JSONSchemaLibrary    schemas/
+
+VNFD of an individual VNF package
+    Log    Request that will generate a 409 Error. As prerequisite is needed a VNF Package in PROCESSING onboardingState
+    Create HTTP Context    ${NFVO_HOST}:${NFVO_PORT}    ${NFVO_SCHEMA}
+    Run Keyword If    ${AUTH_USAGE} == 1    Set Request Header    Authorization    ${AUTHORIZATION}
+    Set Request Header    Accept    ${ACCEPT_PLAIN}
+    Set Request Header    Accept    ${ACCEPT_ZIP}
+    GET    ${apiRoot}/vnfpkgm/v1/vnf_packages/${vnfPkgId_processing}/vnfd
+    Response Status Code Should Equal    409
+    Log    Received 409 Conflict
\ No newline at end of file
diff --git a/SOL003/variables.txt b/SOL003/variables.txt
new file mode 100644
index 00000000..9fceaabb
--- /dev/null
+++ b/SOL003/variables.txt
@@ -0,0 +1,21 @@
+*** Variables ***
+${VNFM_HOST}      localhost    # Hostname of the VNFM
+${VNFM_PORT}      8080    # Listening port of the VNFM
+${NFVO_HOST}      localhost    # Hostname of the NFVO
+${NFVO_PORT}      8081    # Listening port of the NFVO
+${VNFM_SCHEMA}    https
+${NFVO_SCHEMA}    https
+${AUTHORIZATION}    Bearer    QWxhZGRpbjpvcGVuIHNlc2FtZQ==
+${CONTENT_TYPE}    application/json
+${ACCEPT}         application/json
+${apiRoot}        /
+${AUTH_USAGE}     1
+${WRONG_AUTHORIZATION}    Bearer    XXXXXWRONGXXXXX
+${vnfPkgId}       6fc3539c-e602-4afa-8e13-962fb5a7d81f
+${SINGLE_FILE_VNFD}    1    # If VNFD is PLAIN TEXT
+${ACCEPT_PLAIN}    text/plain
+${ACCEPT_ZIP}     application/zip
+${vnfPkgId_processing}    007c111c-38a1-42c0-a666-7475ecb1567c
+${ARTIFACT_TYPE}    application/octet-stream
+${ARTIFACT_ID}    artifactId
+${WRONG_ACCEPT}    application/json
-- 
GitLab