Commit a56be61a authored by Eisha Ayaz's avatar Eisha Ayaz
Browse files

[test-upd][SOL003][VNF-LCM][v5.3.1][7.3.1.34.1,2...

[test-upd][SOL003][VNF-LCM][v5.3.1][7.3.1.34.1,2 Test-IDs][NFVSOL(26)000019r3​] Add support of received notification validation
parent 74cc0614
Loading
Loading
Loading
Loading
+149 −12
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ Library MockServerLibrary
Library    Process
Library    OperatingSystem
Library    Collections
Library    REST    http://${VNFM_HOST}:${VNFM_PORT}    ssl_verify=false

*** Test Cases ***
VNF LCM Operation Occurrence Start Notification
@@ -20,7 +21,7 @@ VNF LCM Operation Occurrence Start Notification
    Trigger a VNF LCM operation (external action) 
    Check VNF LCM Operation Occurrence Start Notification Http POST Request Body Json Schema Is    VnfLcmOperationOccurrenceNotification
    Check VNF LCM Operation Occurrence Start Notification Http POST Request Body notificationType attribute Is    VnfLcmOperationOccurrenceNotification
    Check VNF LCM Operation Occurrence Start Notification Http POST Request Body notificationStatus attribute Is    START
    Check VNF LCM Operation Occurrence Start Notification And LCM State    START
    
VNF LCM Operation Occurrence Result Notification
    [Documentation]    Test ID: 7.3.1.34.2
@@ -34,7 +35,7 @@ VNF LCM Operation Occurrence Result Notification
    Trigger the completion of an VNF LCM operation (external action)
    Check VNF LCM Operation Occurrence Result Notification Http POST Request Body Json Schema Is    VnfLcmOperationOccurrenceNotification
    Check VNF LCM Operation Occurrence Result Notification Http POST Request Body notificationType attribute Is    VnfLcmOperationOccurrenceNotification
    Check VNF LCM Operation Occurrence Start Notification Http POST Request Body notificationStatus attribute Is    RESULT
    Check VNF LCM Operation Occurrence Result Notification And LCM State    RESULT
    
VNF Identifier Creation Notification
    [Documentation]    Test ID: 7.3.1.34.3
@@ -81,20 +82,20 @@ Trigger the deletion of a VNF instance resource (external action)
    
Check VNF LCM Operation Occurrence Start Notification Http POST Request Body Json Schema Is  
    [Arguments]    ${element}
    ${schema}=	Get File	schemas/${element}.schema.json
    ${schema}=	Get File	SOL003/VNFLifecycleManagement-API/schemas/${element}.schema.json
    Configure Notification Forward    ${schema}    ${callback_endpoint}    ${callback_endpoint_fwd}

Check VNF LCM Operation Occurrence Start Notification Http POST Request Body notificationType attribute Is
    [Arguments]    ${type}
    Configure Notification VNF LCM Operation Occurrence Start Handler    ${callback_endpoint_fwd}    ${type}    START
    Wait Until Keyword Succeeds    2 min   10 sec   Verify Mock Expectation    ${notification_request}
    Clear Requests    ${callback_endpoint}
    Clear Requests    ${callback_endpoint_fwd}
    # Clear Requests    ${callback_endpoint}
    # Clear Requests    ${callback_endpoint_fwd}
    
Configure Notification VNF LCM Operation Occurrence Start Handler
    [Arguments]    ${endpoint}    ${type}    ${status}
    ${json}=    evaluate    {}
    set to dictionary   ${json}    notificationType    ${type}    changeType    ${status}
    set to dictionary   ${json}    notificationType    ${type}    notificationStatus    ${status}
    ${BODY}=    evaluate    json.dumps(${json})    json
    Log  Creating mock request and response to handle status notification
    &{req}=  Create Mock Request Matcher	POST  ${endpoint}  body_type="JSON"    body=${BODY}
@@ -111,13 +112,13 @@ Check VNF LCM Operation Occurrence Result Notification Http POST Request Body no
    [Arguments]    ${type}
    Configure Notification VNF LCM Operation Occurrence Result Handler    ${callback_endpoint_fwd}    ${type}    RESULT
    Wait Until Keyword Succeeds    2 min   10 sec   Verify Mock Expectation    ${notification_request}
    Clear Requests    ${callback_endpoint}
    Clear Requests    ${callback_endpoint_fwd}
    # Clear Requests    ${callback_endpoint}
    # Clear Requests    ${callback_endpoint_fwd}

Configure Notification VNF LCM Operation Occurrence Result Handler
    [Arguments]    ${endpoint}    ${type}    ${status}
    ${json}=    evaluate    {}
    set to dictionary   ${json}    notificationType    ${type}    changeType    ${status}
    set to dictionary   ${json}    notificationType    ${type}    notificationStatus    ${status}
    ${BODY}=    evaluate    json.dumps(${json})    json
    Log  Creating mock request and response to handle status notification
    &{req}=  Create Mock Request Matcher	POST  ${endpoint}  body_type="JSON"    body=${BODY}
@@ -134,8 +135,8 @@ Check VNF Identifier Creation Notification Http POST Request Body notificationTy
    [Arguments]    ${type}
    Configure Notification VNF Identifier Creation Handler    ${callback_endpoint_fwd}    ${type}
    Wait Until Keyword Succeeds    2 min   10 sec   Verify Mock Expectation    ${notification_request}
    Clear Requests    ${callback_endpoint}
    Clear Requests    ${callback_endpoint_fwd}
    # Clear Requests    ${callback_endpoint}
    # Clear Requests    ${callback_endpoint_fwd}

Configure Notification VNF Identifier Creation Handler
    [Arguments]    ${endpoint}    ${type}
@@ -189,7 +190,143 @@ Configure Notification Forward
    Create Mock Expectation With Http Forward  ${notification_tmp}  ${notification_fwd}

Create Sessions
    Start Process  python3  ${CURDIR}/../../vnfm_stub.py  --port  ${VNFM_PORT}  alias=vnfmStub
    Wait For Process  handle=vnfmStub  timeout=5s  on_timeout=continue
    Start Process  java  -jar  ${MOCK_SERVER_JAR}  -serverPort  ${callback_port}  alias=mockInstance
    Wait For Process  handle=mockInstance  timeout=5s  on_timeout=continue
    Create Mock Session  ${callback_uri}:${callback_port}

Check VNF LCM Operation Occurrence Start Notification And LCM State
    Log    CALLBACK_FWD = ${callback_endpoint_fwd}
    Log    CALLBACK = ${callback_endpoint}
    [Arguments]    ${expected_status}
    ${requests}=    Retrieve Requests    ${callback_endpoint_fwd}
    Should Not Be Empty    ${requests}    msg=No notification received at callback endpoint!

    ${request_type}=    Evaluate    type(${requests})
    Log    Request type: ${request_type}

    ${last_request}=    Run Keyword If    "${request_type}" == "<class 'list'>"
    ...    Get From List    ${requests}    -1
    ...    ELSE
    ...    Set Variable    ${requests}

    ${body}=    Get From Dictionary    ${last_request}    body
    ${body_text}=    Get From Dictionary    ${body}    string
    Log    Raw body: ${body_text}

    ${notification}=    Evaluate    json.loads(r'''${body_text}''')    json

    Log    Parsed notification: ${notification}
    Should Not Be Empty    ${notification}
    # Validate notification content
    Dictionary Should Contain Key    ${notification}    notificationType
    Dictionary Should Contain Key    ${notification}    notificationStatus
    Dictionary Should Contain Key    ${notification}    vnfInstanceId
    Dictionary Should Contain Key    ${notification}    vnfLcmOpOccId

    Should Be Equal As Strings
    ...    ${notification['notificationType']}
    ...    VnfLcmOperationOccurrenceNotification

    Should Be Equal As Strings
    ...    ${notification['notificationStatus']}
    ...    ${expected_status}

    ${vnfInstanceId}=    Get From Dictionary    ${notification}    vnfInstanceId
    ${vnfLcmOpOccId}=    Get From Dictionary    ${notification}    vnfLcmOpOccId

    Set Headers    {"Accept": "${ACCEPT_JSON}"}

    Run Keyword If    ${AUTH_USAGE} == 1
    ...    Set Headers    {"${AUTHORIZATION_HEADER}":"${AUTHORIZATION_TOKEN}"}

    # Validate VNF Instance
    GET    ${apiRoot}/${apiName}/${apiMajorVersion}/vnf_instances/${vnfInstanceId}
    Integer    response status    200

    # Validate LCM operation occurrence
    GET    ${apiRoot}/${apiName}/${apiMajorVersion}/vnf_lcm_op_occs/${vnfLcmOpOccId}
    Integer    response status    200

    ${response_body}=    Output    response body

    ${lcm_state}=    Get From Dictionary    ${response_body}    operationState
    ${returned_id}=    Get From Dictionary    ${response_body}    id

    Should Be Equal As Strings    ${returned_id}    ${vnfLcmOpOccId}

    @{allowed_states}=    Create List    STARTING    PROCESSING

    List Should Contain Value
    ...    ${allowed_states}
    ...    ${lcm_state}
Check VNF LCM Operation Occurrence Result Notification And LCM State
    [Arguments]    ${expected_status}
    # 1. Retrieve the latest notification
    ${requests}=    Retrieve Requests    ${callback_endpoint_fwd}
    Should Not Be Empty    ${requests}    msg=No notification received at callback endpoint!
    
    ${request_type}=    Evaluate    type(${requests})
    Log    Request type: ${request_type}
    
    # Handle both single request and list of requests
    ${last_request}=    Run Keyword If    "${request_type}" == "<class 'list'>"
    ...    Get From List    ${requests}    -1
    ...    ELSE
    ...    Set Variable    ${requests}

    ${body}=    Get From Dictionary    ${last_request}    body
    ${body_text}=    Get From Dictionary    ${body}    string
    Log    Raw body: ${body_text}

    ${notification}=    Evaluate    json.loads(r'''${body_text}''')    json

    Log    [NOTIFICATION] Received Result Notification: ${notification}

    # 2. Content Validation of Notification
    Dictionary Should Contain Key    ${notification}    notificationType
    Dictionary Should Contain Key    ${notification}    notificationStatus
    Dictionary Should Contain Key    ${notification}    vnfInstanceId
    Dictionary Should Contain Key    ${notification}    vnfLcmOpOccId

    Should Be Equal As Strings    ${notification['notificationType']}      VnfLcmOperationOccurrenceNotification
    Should Be Equal As Strings    ${notification['notificationStatus']}    ${expected_status}
    ...    msg=Expected notificationStatus=RESULT but got ${notification['notificationStatus']}

    ${vnfInstanceId}=    Get From Dictionary    ${notification}    vnfInstanceId
    ${vnfLcmOpOccId}=    Get From Dictionary    ${notification}    vnfLcmOpOccId

    #  Post-condition Verification
    Set Headers    {"Accept": "${ACCEPT_JSON}"}
    Run Keyword If    ${AUTH_USAGE} == 1
    ...    Set Headers    {"${AUTHORIZATION_HEADER}":"${AUTHORIZATION_TOKEN}"}

    # Validate VNF Instance
    GET    ${apiRoot}/${apiName}/${apiMajorVersion}/vnf_instances/${vnfInstanceId}
    Integer    response status    200
    Log    VNF Instance ${vnfInstanceId} validated successfully

    # Validate LCM Operation Occurrence
    GET    ${apiRoot}/${apiName}/${apiMajorVersion}/vnf_lcm_op_occs/${vnfLcmOpOccId}
    Integer    response status    200

    ${outputResponse}=    Output    response
    Set Global Variable    ${response}    ${outputResponse}
    ${lcm_state}=   Get From Dictionary    ${response['body']}    operationState

    # ID Consistency Check
    ${returned_id}=    Get From Dictionary    ${response['body']}    id
    Should Be Equal As Strings    ${returned_id}    ${vnfLcmOpOccId}
    ...    msg=ID mismatch! LCM Op Occ ID in notification (${vnfLcmOpOccId}) does not match resource ID (${returned_id})

    Log    LCM operationState = ${lcm_state}

    # Allowed states for RESULT notification
    @{allowed_states}=    Create List    COMPLETED    FAILED    FAILED_TEMP    ROLLING_BACK    ROLLED_BACK
    List Should Contain Value    ${allowed_states}    ${lcm_state}
    ...    msg=Unexpected operationState '${lcm_state}' after RESULT notification

    Clear Requests    ${callback_endpoint}
    Clear Requests    ${callback_endpoint_fwd}