beef up the AI/ML framework tests by adding InfluxDB as data source and populate...
[it/test.git] / ric_robot_suite / robot / testsuites / mcxapp.robot
1 #   Copyright (c) 2019 AT&T Intellectual Property.
2 #
3 #   Licensed under the Apache License, Version 2.0 (the "License");
4 #   you may not use this file except in compliance with the License.
5 #   You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #   Unless required by applicable law or agreed to in writing, software
10 #   distributed under the License is distributed on an "AS IS" BASIS,
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #   See the License for the specific language governing permissions and
13 #   limitations under the License.
14
15 *** Settings ***
16 Documentation  Tests for the Measurement Campaign XApp
17
18 Resource       ../resources/xapps/mcxapp_properties.robot
19 Resource       ../resources/global_properties.robot
20
21 Library        Collections
22 Library        KubernetesEntity          ${GLOBAL_XAPP_NAMESPACE}
23
24 *** Variables ***
25 ${deploymentName} =         ${GLOBAL_XAPP_NAMESPACE}-mcxapp
26 ${listenerContainerName} =  mc-xapp-listener
27 ${listenerStatRegex} =      ^[0-9]+\\s*\\[STAT\\]\\s*\\(mcl\\)
28 ${recentListenerDrops} =    last 60s.*drops\\s*=\\s*[1-9]
29 ${recentListenerErrors} =   last 60s.*errs\\s*=\\s*[1-9]
30
31 *** Test Cases ***
32 MC XApp Should Be Available
33   [Tags]  etetests  xapptests  mcxapptests
34   ${deploy} =          Deployment           ${deploymentName}
35   ${status} =          Most Recent Availability Condition           @{deploy.status.conditions}
36   Should Be Equal As Strings   ${status}  True  ignore_case=True
37
38 MC XApp Listener Should Not Be Dropping Messages
39   [Tags]  etetests  xapptests  mcxapptests
40   ${log} =  Most Recent Container Log  ${listenerContainerName}  ${listenerStatRegex}
41   Should Not Contain Match             ${log}                    ${recentListenerDrops}
42   
43 MC XApp Listener Should Not Be Producing Errors
44   [Tags]  etetests  xapptests  mcxapptests
45   ${log} =  Most Recent Container Log  ${listenerContainerName}  ${listenerStatRegex}
46   Should Not Contain Match             ${log}                    ${recentListenerErrors}
47
48 Writer Should Be Successfully Sending Statistics
49   [Tags]  etetests  xapptests  mcxapptests
50   Set Test Variable  ${finalStatus}  PASS
51   FOR  ${stat}  IN  @{GLOBAL_MCXAPP_WRITER_STATISTICS}
52      ${statRE} =        Regexp Escape  ${stat}
53      ${log} =           Most Recent Container Log
54      ...                ${GLOBAL_MCXAPP_WRITER_NAME}
55      ...                ^${statRE}:\\s+successful\\s+ves\\s+posts\\.*
56      ${status}  ${u} =  Run Keyword And Ignore Error
57      ...                Should Contain Match  ${log}  regexp=${writerVesSuccesses}
58      ${finalStatus} =   Set Variable If  "${status}" == "FAIL"
59      ...                FAIL
60      ...                ${finalStatus}
61      Run Keyword If     "${status}" == "FAIL"
62      ...                Log  No messages have been sent to VES for ${stat}
63      ${status}  ${u} =  Run Keyword And Ignore Error
64      ...                Should Not Contain Match  ${log}  regexp=${writerVesErrors}
65      ${finalStatus} =   Set Variable If  "${status}" == "FAIL"
66      ...                FAIL
67      ...                ${finalStatus}
68      Run Keyword If     "${status}" == "FAIL"
69      ...                Log  ${stat} is producing errors logging to VES
70   END   
71   Run Keyword If        "${finalStatus}" == "FAIL"
72   ...                   Fail  One or more statistics is not being succesfully logged
73
74 *** Keywords ***
75 Most Recent Availability Condition
76   # this makes the probably-unsafe assumption that the conditions are ordered
77   # temporally.
78   [Arguments]  @{Conditions}
79   ${status} =  Set Variable  'False'
80   FOR  ${Condition}  IN  @{Conditions}
81      ${status} =  Set Variable If  '${Condition.type}' == 'Available'  ${Condition.status}  ${status}
82   END   
83   [Return]  ${status}
84
85 Most Recent Match
86   [Arguments]    ${list}        ${regex}
87   ${matches} =   Get Matches    ${list}     regexp=${regex}
88   Should Not Be Empty           ${matches}  No log entries matching ${regex}
89   ${match} =     Get From List  ${matches}  -1
90   [Return]       ${match}
91   
92 Most Recent Container Log
93   [Arguments]   ${container}=${EMPTY}  ${regex}=${EMPTY}
94   ${pods} =            Retrieve Pods For Deployment  ${deploymentName}
95   ${logs} =            Create List
96   FOR  ${pod}  IN  @{pods}
97      ${log} =   Retrieve Log For Pod     ${pod}             ${container}
98      Should Not Be Empty        ${log}   No log entries for ${pod}/${container}
99      ${line} =  Run Keyword If           "${regex}" != "${EMPTY}"
100      ...                                 Most Recent Match  ${log}  ${regex}
101      ...        ELSE
102      ...                                 Get From List      ${log}  -1
103      Append To List             ${logs}  ${line}
104   END   
105   [Return]                      ${logs}
106