Commit 71b2882b authored by Michele Carignani's avatar Michele Carignani
Browse files

first version of create sol exec

parent 2d57405c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -3,9 +3,9 @@
VERSION = "0.0.4"

DOC_CLAUSE_LVL_1 = "6"
DOC_CLAUSE_LVL_2 = 8
DOC_CLAUSE_LVL_3 = 7
DOC_CLAUSE_LVL_4 = 6
DOC_CLAUSE_LVL_2 = 3
DOC_CLAUSE_LVL_3 = 1
DOC_CLAUSE_LVL_4 = 1

ANNEX_TITLE_LEVEL = 1
DOC_SUITE_LEVEL = 4
+70 −0
Original line number Diff line number Diff line
#!/env/python3
#
#  Usage: python main.py <FILE_OR_FOLDER> [OUTPUT_FILENAME [MAIN_TITLE]]
#

import os
import sys
import csv

from robot.api import TestSuiteBuilder

import testspec
import config
import lib


def is_interface_heading(ref):
    return ref.lvl() == 3


def is_endpoint_heading(ref):
    return ref.lvl() == 4

def create_sol_002(sol_002_root, commit_id, output_dir):

    sol002_index = None

    myf = open('sol_002_tree_ok.csv', 'r')
    sol002_index = csv.reader(myf)

    if sol002_index is None:
        print("ERROR OPENING SOL002 INDEX")
        return

    spec = testspec.TestSpec()
    current_folder = None

    for row in sol002_index:
        if len(row) < 3:
            continue

        ref = lib.DocReference.from_str(row[0].strip())

        if is_interface_heading(ref):
            spec.add_heading_from_ref(row[1].strip(), ref)
            current_folder = row[2].strip()

        elif is_endpoint_heading(ref):
            suite = TestSuiteBuilder().build(os.path.join(sol_002_root, current_folder, row[2].strip()))
            lib.gen_api_suite(ref, suite, spec, current_folder, commit_id, "SOL002")

    outfn = os.path.join(output_dir,"SOL002_attachment.docx")
    print("Writing SOL 002 definitions to: ", outfn)
    spec.save(outfn)


if __name__ == "__main__":

    if len(sys.argv) < 2:
        print("Usage: robot2doc <sol_robot_root_dir> commit-id")
        sys.exit(-1)

    ROOT = sys.argv[1]
    COMMIT_ID = sys.argv[2] if len(sys.argv) > 2 else None

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

    print("Generating entire SOL tests")

    create_sol_002(os.path.join(ROOT, "SOL002"), COMMIT_ID, "..")
 No newline at end of file
+59 −29
Original line number Diff line number Diff line
@@ -28,6 +28,34 @@ class TestDoc():
        self.sol = sol
        self.api = api

class DocReference():

    def __init__(self, sec_num_list=[1]):
        self._lvl = len(sec_num_list)
        self._nums = [int(i) for i in sec_num_list]

    def lvl(self):
        return self._lvl

    def __str__(self):
        return ".".join([str(x) for x in self._nums])

    def next_ref(self):
        nums_cpy = self._nums.copy()
        nums_cpy[self._lvl - 1] = self._nums[self._lvl - 1] + 1
        return DocReference(nums_cpy)

    def sub_ref(self):
        nums_cpy = self._nums.copy()
        nums_cpy.append(1)
        return DocReference(nums_cpy)

    @staticmethod
    def from_str(string):
        return DocReference(string.split("."))



def keyword_to_line(k):
    '''
    Takes a Robot Framework keyword object and returns
@@ -41,30 +69,24 @@ def keywords_to_text(kws):
    '''
    return "\n".join(map(keyword_to_line, kws))

def gen_test(suite, this_test, spec, sec, subsec, workspace, commit_id, sol, api):
def gen_test(suite, this_test, spec, sec_ref, API, commit_id, sol):
    '''
    Generate the Docx part for an individual test
    '''

    ntp = TP(this_test.doc)

    log_line = ["TD", str(workspace), str(suite), str(this_test), ntp.tp_id or "No ID"]
    not QUIET and print(",".join(log_line))
    log_line = ["TD", API, suite, this_test, ntp.tp_id or "No ID"]
    not QUIET and print(",".join([str(x) for x in log_line]))

    if DRY_RUN:
        return
    if ntp.tp_id is not None:
        spec.add_heading(str(this_test), DOC_TC_LEVEL, ntp.tp_id)
    else:
        subsec = subsec + 1
        spec.add_heading(
            str(this_test), 
            DOC_TC_LEVEL, 
            DOC_CLAUSE_LVL_1, 
            sec, 
            DOC_CLAUSE_LVL_3, 
            subsec
        )
        print("WARNING: Missing TP ID for test {}".format(this_test) )
        new_ref = sec_ref.next_ref()
        spec.add_heading_from_ref(str(this_test), new_ref)
    
    ntp.add_to_spec(
        spec, 
@@ -72,17 +94,15 @@ def gen_test(suite, this_test, spec, sec, subsec, workspace, commit_id, sol, api
        str(suite)+".robot", 
        commit_id, 
        sol, 
        api
        API
    )


def gen_api_suite(sec, suite, spec, workspace, commit_id, sol, api):
    sec = sec + 1
    subsec = DOC_CLAUSE_LVL_4
    print("  Generating test suite: " + str(suite))
    spec.add_sub_heading(str(suite), DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec)
def gen_api_suite(sec_ref, suite, spec, workspace, commit_id, sol):
    print("  Generating test suite: {} {}".format(sec_ref, suite))
    spec.add_sub_heading_from_ref(str(suite), sec_ref, config.DOC_SUITE_LEVEL)
    for i in suite.tests:
        gen_test(suite, i, spec, sec, subsec, workspace, commit_id, sol, api)
        gen_test(suite, i, spec, sec_ref, workspace, commit_id, sol)

def gen_doc(src, doc_fn, doc_main_tit, commit_id, sol, api):
    '''
@@ -109,6 +129,8 @@ def gen_doc(src, doc_fn, doc_main_tit, commit_id, sol, api):
    finally:
        os.chdir(cwd)

    spec = TestSpec()

    print("Loading tests from: " + str(src))
    workspace = []
    try:
@@ -126,22 +148,30 @@ def gen_doc(src, doc_fn, doc_main_tit, commit_id, sol, api):

    not QUIET and print("Loaded "+ str(tot_suites) + " test suites.")
    not QUIET and print("Loaded "+ str(tot_tests) + " tests.")
    sec = DOC_CLAUSE_LVL_2 - 1
    
    for api_dir in workspace:
    api_dir_num = DOC_CLAUSE_LVL_1
    sec = DOC_CLAUSE_LVL_2
    subsec = DOC_CLAUSE_LVL_3

        spec.add_main_heading(DOC_CLAUSE_LVL_1 + "\t" + str(api_dir))
    sec_ref = DocReference([api_dir_num, sec, subsec])

        # TODO
        # spec.add_main_heading(doc_main_tit)
    for api_dir in workspace:

        spec.add_main_heading("{} \t {}".format(sec_ref, api_dir), config.ANNEX_TITLE_LEVEL)

        print("-----> ", sec_ref, api_dir)
        file_ref = sec_ref.sub_ref()
        for test_file in api_dir.suites:
            print("------> ", api_dir, test_file)
            gen_api_suite(sec, test_file, spec, api_dir, commit_id, sol, str(api_dir))
            print("-------> ", sec_ref, api_dir, file_ref, test_file)
            gen_api_suite(file_ref, test_file, spec, api_dir, commit_id, sol)
            file_ref = file_ref.next_ref()
            
        if len(api_dir.suites) == 0:
            suite = str(api_dir)
            gen_api_suite(sec, suite, spec, workspace, commit_id, sol, api_dir)
            gen_api_suite(sec, suite, spec, api_dir, commit_id, sol)
        
        sec_ref = sec_ref.next_ref()
        
            
    not QUIET and print("Saving to: " + doc_fn)
    not DRY_RUN and spec.save(doc_fn)
+2 −1
Original line number Diff line number Diff line
@@ -22,11 +22,12 @@ if __name__ == "__main__":
    SOL = sys.argv[5] if len(sys.argv) > 5 else None
    API = sys.argv[6] if len(sys.argv) > 6 else None

    print("Received arguments: ", sys.argv[1:])
    print("Received arguments: ", sys.argv)

    tstdoc = lib.TestDoc(FILE, DOC_FILENAME, DOC_MAIN_TITLE, COMMIT_ID, SOL, API)

    if FILE.split("/")[-1].startswith("SOL0"):
        print("Generating entire SOL tests")
        sol = FILE.split("/")[-1]
        apis = [
            os.path.realpath(os.path.join(FILE, item.name)) 
+46 −0
Original line number Diff line number Diff line
6,	Ve-Vnfm Reference Point, SOL002 
6.3.1,	VNF Configuration Interface	, VNFConfiguration-API    
6.3.1.1,	Configuration Resource Endpoint	, Configuration.robot
6.3.2,	VNF Indicator Interface	, VNFIndicator-API
6.3.2.1,	VNF Indicators Resource Endpoint	, VNFIndicators.robot
6.3.2.2,	VNF Indicators related to a VNF Instance Resource Endpoint	, VnfIndicatorsInVnfInstanceId.robot 
6.3.2.3,	Individual VNF Indicator Resource Endpoint	, IndividualSubscription.robot
6.3.2.4,	Subscriptions Resource Endpoint	, Subscriptions.robot
6.3.2.5,	Individual Subscription Resource Endpoint	, IndividualSubscription.robot
6.3.2.6,	Notification Endpoint	, ../VNFIndicatorNotification-API/VnfIndicatorNotification.robot
6.3.3,	VNF Performance Management Interface	, VNFPerformanceManagement-API
6.3.3.1,	PM Jobs Resource Endpoint	, PMJobs.robot   
6.3.3.2,	Individual PM Job Resource Endpoint	, IndividualPmJob.robot 
6.3.3.3,	Individual Performance Report Resource Endpoint	, IndividualReport.robot
6.3.3.4,	Thresholds Resource Endpoint	, Thresholds.robot
6.3.3.5,	Individual Threshold Resource Endpoint	, IndividualThreshold.robot  
6.3.3.6,	Subscriptions Resource Endpoint	, Subscriptions.robot  
6.3.3.7,	Individual Subscription Resource Endpoint	, IndividualSubscription.robot 
6.3.3.8,	Notification Endpoint	, ../VNFPerformanceManagementNotification-API/PerformanceManagementNotification.robot    
6.3.4,	VNF Fault Management interface	, VNFFaultManagement-API
6.3.4.1,	Alarms	, Alarms.robot  
6.3.4.2,	Individual Alarm	, IndividualAlarm.robot
6.3.4.3,	Escalate the perceived severity	, EscalatePerceivedSeverityTask.robot
6.3.4.4,	Subscriptions	, Subscriptions.robot
6.3.4.5,	Individual Subscription	, IndividualSubscription.robot
6.3.4.6,	Notification Endpoint	, NotificationEndpoint.robot
6.3.5,	VNF Lifecycle Management interface	, VNFLifecycleManagement-API
6.3.5.1,	VNF Instances	, VNFInstances.robot
6.3.5.2,	Individual VNFInstance	, IndividualVNFInstance.robot 
6.3.5.3,	Instantiate VNF Task	, InstantiateVNFTask.robot
6.3.5.4,	Scale VNF Task	, ScaleVNFTask.robot  
6.3.5.5,	Scale a VNF to level Task	, ScaleVNFToLevelTask.robot    
6.3.5.6,	Change VNF deployment flavour Task	, ChangeVNFFlavourTask.robot 
6.3.5.7,	Terminate VNF Task	, TerminateVNFTask.robot
6.3.5.8,	Heal VNF Task	, HealVNFTask.robot 
6.3.5.9,	Operate VNF Task	, OperateVNFTask.robot
6.3.5.10,	Change external VNF connectivity	, ChangeExternalVNFConnectivityTask.robot  
6.3.5.11,	VNF LCM OP occurrences	, VnfLcmOperationOccurences.robot
6.3.5.12,	Individual VNF LCM OP occurrence	, IndividualVnfLcmOperationOccurence.robot  
6.3.5.13,	Retry operation task	, RetryOperationTask.robot
6.3.5.14,	Rollback operation task	, RollbackOperationTask.robot  
6.3.5.15,	Fail operation task	, FailOperationTask.robot 
6.3.5.16,	Cancel operation task	, CancelOperationTask.robot
6.3.5.17,	Subscriptions	, Subscriptions.robot
6.3.5.18,	Individual Subscription	, IndividualSubscription.robot
6.3.5.19,	Notification Endpoint	, NotificationEndpoint.robot
Loading