Commit 56df6ae0 authored by Michele Carignani's avatar Michele Carignani
Browse files

parse git reference from target folder

parent 8354bdc2
Loading
Loading
Loading
Loading
Loading

TODO

0 → 100644
+2 −0
Original line number Diff line number Diff line
* check number of files in the folders and number of lines in the index for that folder (no need to check tests)
* gitlab-ci script
+194 −0
Original line number Diff line number Diff line
*** Settings ***
Resource    environment/variables.txt 
Library    REST    ${EM-VNF_SCHEMA}://${EM-VNF_HOST}:${EM-VNF_PORT}    ssl_verify=false
Library    JSONLibrary
Library    JSONSchemaLibrary    schemas/
Library    OperatingSystem
Library    DependencyLibrary

*** Test Cases ***
Set new VNF Configuration
    [Documentation]    Test ID: 6.3.1.1.1
    ...    Test title: Set a new VNF Configuration
    ...    Test objective: The objective is to test the creation of a new VNF configuration and perform a JSON schema validation of the returned configuration data structure
    ...    Pre-conditions: A VNF instance is instantiated
    ...    Reference: Clause 9.4.2.3.4 - ETSI GS NFV-SOL 002 [2] v2.6.1
    ...    Config ID: Config_prod_VE
    ...    Applicability: The VNF supports the generation of HTTP Etag opaque identifiers
    ...    Post-Conditions: The configuration is successfully set in the VNF and it matches the issued configuration
    Send VNF configuration
    Check HTTP Response Status Code Is    200
    Check HTTP Response Header Contains    ETag
    Check HTTP Response Body Json Schema Is   vnfConfigModifications
    Check Postcondition VNF Is Configured

Get information about a VNF configuration
    [Tags]    no-etag
    [Documentation]    Test ID: 6.3.1.1.2
    ...    Test title: Get information about a VNF configuration
    ...    Test objective: The objective is to test the retrieval of an existing VNF instance configuration and perform a JSON schema validation of the collected configuration data structure
    ...    Pre-conditions: A VNF instance is instantiated. The VNF instance is already configured.
    ...    Reference: Clause 9.4.2.3.2 - ETSI GS NFV-SOL 002 [2] v2.6.1
    ...    Config ID: Config_prod_VE
    ...    Applicability: none
    ...    Post-Conditions: none
    Get VNF configuration
    Check HTTP Response Status Code Is    200
    Check HTTP Response Body Json Schema Is   vnfConfiguration

Get information about a VNF configuration with HTTP Etag
    [Tags]    etag
    [Documentation]    Test ID: 6.3.1.1.3
    ...    Test title: Get information about a VNF configuration with HTTP Etag
    ...    Test objective: The objective is to test the retrieval of an existing VNF instance configuration, check the generation by the VNF of an HTTP Etag opaque identifier, and perform a JSON schema validation of the collected configuration data structure
    ...    Pre-conditions:  A VNF instance is instantiated. The VNF instance is already configured
    ...    Reference: Clause 9.4.2.3.2 - ETSI GS NFV-SOL 002 [2] v2.6.1
    ...    Config ID: Config_prod_VE
    ...    Applicability: The VNF supports the generation of HTTP Etag opaque identifiers
    ...    Post-Conditions: none
    Get VNF configuration
    Check HTTP Response Status Code Is    200
    Check HTTP Response Header Contains    ETag
    Check HTTP Response Body Json Schema Is   vnfConfiguration

Set new VNF Configuration - HTTP Etag precondition unsuccessful
    [Tags]    etag
    [Documentation]    Test ID: 6.3.1.1.4
    ...    Test title: Set a new VNF Configuration - HTTP Etag precondition unsuccessful
    ...    Test objective: The objective is to test the unsuccess in setting a duplication of VNF configuration identified by an already used HTTP Etag identifier. The test also checks the JSON schema of the unsuccessful operation HTTP response.
    ...    Pre-conditions:  A VNF instance is instantiated. The VNF instance is already configured (Test ID 6.3.1.1.1) with a given HTTP Etag identifier.
    ...    Reference: Clause 9.4.2.3.4 - ETSI GS NFV-SOL 002 [2] v2.6.1
    ...    Config ID: Config_prod_VE
    ...    Applicability: The VNF supports the generation of HTTP Etag opaque identifiers
    ...    Post-Conditions:  The VNF configuration is not modified by the unsuccessful operation and it matches the configuration issued in Test ID 6.3.1.1.1
    Send Duplicated VNF configuration
    Check HTTP Response Status Code Is    412
    Check HTTP Response Body Json Schema Is   ProblemDetails
    Check Postcondition VNF Configuration Unmodified (Implicit)

POST VNF Configuration - Method not implemented
    [Documentation]    Test ID: 6.3.1.1.5
    ...    Test title: POST VNF Configuration - Method not implemented
    ...    Test objective: The objective is to test that POST method is not allowed to create a new VNF configuration
    ...    Pre-conditions: A VNF instance is instantiated. The VNF instance is alrseady configured
    ...    Reference: Clause 9.4.2.3.1 - ETSI GS NFV-SOL 002 [2] v2.6.1
    ...    Config ID: Config_prod_VE
    ...    Applicability: none
    ...    Post-Conditions: none
    Send POST Request for VNF Configuration
    Check HTTP Response Status Code Is    405 

PUT VNF Configuration - Method not implemented
    [Documentation]    Test ID: 6.3.1.1.6
    ...    Test title: PUT VNF Configuration - Method not implemented
    ...    Test objective: The objective is to test that PUT method is not allowed to modify an existing VNF configuration
    ...    Pre-conditions:  A VNF instance is instantiated. The VNF instance is already configured
    ...    Reference: Clause 9.4.2.3.3 - ETSI GS NFV-SOL 002 [2] v2.6.1
    ...    Config ID: Config_prod_VE
    ...    Applicability: none
    ...    Post-Conditions: none
    Send PUT Request for VNF Configuration
    Check HTTP Response Status Code Is    405

DELETE VNF Configuration - Method not implemented
    [Documentation]    Test ID: 6.3.1.1.7
    ...    Test title: Delete VNF Configuration - Method not implemented
    ...    Test objective: The objective is to test that DELETE method is not allowed to delete an existing VNF configuration
    ...    Pre-conditions:  A VNF instance is instantiated. The VNF instance is already configured
    ...    Reference: Clause 9.4.2.3.5 - ETSI GS NFV-SOL 002 [2] v2.6.1
    ...    Config ID: Config_prod_VE
    ...    Applicability: none
    ...    Post-Conditions: The VNF configuration is not deleted by the unsuccessful operation
    Send DELETE Request for VNF Configuration
    Check HTTP Response Status Code Is    405
    Check Postcondition VNF Configuration Exists
    
*** Keywords ***    
Get VNF configuration
    Log    Query VNF The GET method queries information about a configuration.
    Set Headers  {"Accept":"${ACCEPT}"}  
    Set Headers  {"Content-Type": "${CONTENT_TYPE}"}
    Run Keyword If    ${AUTH_USAGE} == 1    Set Headers    {"Authorization":"${AUTHORIZATION}"}
    Log    Execute Query and validate response
    Get    ${apiRoot}/${apiName}/${apiVersion}/configuration
    ${output}=    Output    response
    Set Suite Variable    ${response}    ${output}

Send VNF configuration
    log    Trying to perform a PATCH. This method modifies the configuration    
    Set Headers  {"Accept":"${ACCEPT}"} 
    Set Headers  {"Content-Type": "${CONTENT_TYPE}"} 
    Run Keyword If    ${AUTH_USAGE} == 1    Set Headers    {"Authorization":"${AUTHORIZATION}"}
    ${body}=    Get File    jsons/vnfConfigModifications.json
    Patch    ${apiRoot}/${apiName}/${apiVersion}/configuration    ${body}
    ${output}=    Output    response
    Set Suite Variable    ${response}    ${output}

Check HTTP Response Status Code Is
    [Arguments]    ${expected_status}    
    Should Be Equal As Strings    ${response['status']}    ${expected_status}
    Log    Status code validated

Check HTTP Response Header Contains
    [Arguments]    ${CONTENT_TYPE}
    Log    ${response['headers']}
    Should Contain    ${response['headers']}    ${CONTENT_TYPE}
    Log    Header is present
    
Check HTTP Response Body Json Schema Is
    [Arguments]    ${input}
    Should Contain    ${response['headers']['Content-Type']}    application/problem+json
    ${schema}=    Catenate    SEPARATOR=    ${input}    .schema.json
    Validate Json    ${schema}    ${response['body']}
    Log    Json Schema Validation OK
      
Check Postcondition VNF Configuration Unmodified (Implicit)
    Log    Check Implicit Postcondition
    Check Postcondition VNF Is Configured

Check Postcondition VNF Configuration Exists
    Log    Check Postcondition VNF exists
    Check Postcondition VNF Is Configured
    
Check Postcondition VNF Is Configured
    Log    Check Postcondition for VNF Configuration
    Get VNF configuration
    ${input_file}=    Get File    jsons/vnfConfigModifications.json
    ${input}=    evaluate    json.loads('''${input_file}''')    json
    Should Be Equal As Strings  ${response['body']}    ${input} 

Send Duplicated VNF configuration
    Depends On Test    Send VNF configuration    # If the previous test scceeded, it means that Etag has been modified
    log    Trying to perform a PATCH. This method modifies an individual alarm resource
    Set Headers  {"Accept":"${ACCEPT}"}
    Set Headers  {"Content-Type": "${CONTENT_TYPE}"}
    Set Headers    {"If-Match": "${etag}"}
    Run Keyword If    ${AUTH_USAGE} == 1    Set Headers    {"Authorization":"${AUTHORIZATION}"}
    ${body}=    Get File    jsons/vnfConfigModifications.json
    Patch    ${apiRoot}/${apiName}/${apiVersion}/configuration    ${body}
    ${output}=    Output    response
    Set Suite Variable    ${response}    ${output}

Send POST Request for VNF Configuration
    log    Trying to perform a POST. This method should not be implemented
    Set Headers  {"Accept":"${ACCEPT}"}  
    Run Keyword If    ${AUTH_USAGE} == 1    Set Headers    {"Authorization":"${AUTHORIZATION}"}
    Post    ${apiRoot}/${apiName}/${apiVersion}/configuration
    ${output}=    Output    response
    Set Suite Variable    ${response}    ${output}
    
Send PUT Request for VNF Configuration
    log    Trying to perform a POST. This method should not be implemented
    Set Headers  {"Accept":"${ACCEPT}"}  
    Run Keyword If    ${AUTH_USAGE} == 1    Set Headers    {"Authorization":"${AUTHORIZATION}"}
    Put    ${apiRoot}/${apiName}/${apiVersion}/configuration
    ${output}=    Output    response
    Set Suite Variable    ${response}    ${output}
    
Send DELETE Request for VNF Configuration
    log    Trying to perform a POST. This method should not be implemented
    Set Headers  {"Accept":"${ACCEPT}"}  
    Run Keyword If    ${AUTH_USAGE} == 1    Set Headers    {"Authorization":"${AUTHORIZATION}"}
    Delete    ${apiRoot}/${apiName}/${apiVersion}/configuration
    ${output}=    Output    response
    Set Suite Variable    ${response}    ${output}
 No newline at end of file
+66 −1
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ Generates attachement for TST 010 based on index files in the api-tests reposito
import os
import sys
import csv
import re

import subprocess

from robot.api import TestSuiteBuilder

@@ -115,10 +118,64 @@ def create_test_for_sol(basedoc, spec_idx, all_tests_root, commit_id, output_dir
    print("Writing {} definitions to: {}, ({})".format(basedoc, outfn, os.path.realpath(outfn)))
    spec.save(os.path.realpath(outfn))

def get_git_log(folder: str):
    '''
    Reads the oneline decorate log of the last commit of the HEAD in `folder`
    '''

    current_dir = os.path.realpath(os.curdir)
    os.chdir(folder)
    gitcmd = ['git', 'log', '-n', '1', '--oneline', '--decorate']
    
    gitlog = subprocess.run(gitcmd, check=True, stdout=subprocess.PIPE, text=True).stdout
    
    os.chdir(current_dir)

    return gitlog 

def parse_tag_from_log(gitlog):
    '''
    Returns the current git tag or None if the last commit is not tagged
    '''
    tag = re.search(r"(tag: )([^,]+)(,)", gitlog)

    return tag.group(2) if bool(tag) else None

def parse_commit_from_log(gitlog):
    '''
    Returns the current git tag or None if the last commit is not parsed
    '''
    commit = re.search(r"^([^\s]+)( )", gitlog)

    return commit.group(1) if bool(commit) else None

def get_git_reference(folder):
    '''
    Reads the tag or commit reference. Returns a couple (ref, reftype) where
    reftype is "tag" or "commit". If none can be parse, returns (None, None)
    '''

    git_log = get_git_log(folder) 
    tag = parse_tag_from_log(git_log)
    commit = parse_commit_from_log(git_log)

    if tag is not None:
        return (tag, "tag")
    
    if commit is not None:
        return (commit, "commit")

    print("Could not parse tag or commit locally. (Git log: '{}')".format(git_log))

    return (None, None)

if __name__ == "__main__":

    if len(sys.argv) < 2:
        print("Usage: robot2doc <sol_robot_root_dir> <commit-id> [<build-dir>]")
        print()
        print("       if <commit-id> is 'local', than attempts \n\
                      to read the reference from the git repository in the root dir")
        sys.exit(-1)

    ROOT = sys.argv[1]
@@ -127,11 +184,19 @@ if __name__ == "__main__":

    print("Received arguments: ", sys.argv)

    if COMMIT_ID == "local":
        (REF, REF_TYPE) = get_git_reference(ROOT)

        if REF is None:
            sys.exit(-1)
        COMMIT_ID = REF
        print("Using git ref: {} ({})".format(COMMIT_ID, REF_TYPE))


    print("Generating entire SOL tests")

    sol_specs = ["SOL002", "SOL003", "SOL005"]


    for solspec in sol_specs:
        spec_index = load_spec_index(ROOT, solspec)
        create_test_for_sol(solspec, spec_index, ROOT, COMMIT_ID, OUTDIR)
+27 −0
Original line number Diff line number Diff line
'''
Tests for NFV TST 010 attachments generation script
'''

import create_sols as crs

def test_parse_tag_from_log():
    '''Test usage of parse_tag_from_log'''

    with_tag = "231f303 (HEAD, tag: 2.7.1.0.0.2, origin/2.7.1-dev) updated indexes"
    without_tag = "023ca44 (mybranch) Merge branch '2.7.1-dev-SOL002-branch' into '2.7.1-dev'"

    assert crs.parse_tag_from_log(with_tag) == "2.7.1.0.0.2"
    assert crs.parse_tag_from_log(without_tag) is None

def test_parse_commit_from_log():
    '''Test usage of parse_tag_from_log'''

    with_tag = "231f303 (HEAD, tag: 2.7.1.0.0.2, origin/2.7.1-dev) updated indexes"
    without_tag = "023ca44 (mybranch) Merge branch '2.7.1-dev-SOL002-branch' into '2.7.1-dev'"
    wrong = ""

    assert crs.parse_commit_from_log(with_tag) == "231f303"
    assert crs.parse_commit_from_log(without_tag) == "023ca44"
    assert crs.parse_commit_from_log(wrong) is None

+4 −1
Original line number Diff line number Diff line
@@ -24,6 +24,9 @@ class TP():
    '''
    def __init__(self, text: str):
        # t = text.encode('ascii')
        if "\\n" in text:
            self.lines = text.split("\\n")
        else:
            self.lines = text.splitlines()
        self.tp_fields = [TpField(l) for l in self.lines]
        self.tp_id = None