X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ric_robot_suite%2Frobot%2Fresources%2Fric%2Fric_utils.robot;fp=ric_robot_suite%2Frobot%2Fresources%2Fric%2Fric_utils.robot;h=30ed937cd62e78bf7b9e1bc8c54941ab92e783d9;hb=3d053f85cc9c42c57850780a18afb0eef425303c;hp=0000000000000000000000000000000000000000;hpb=07d27778d0053beb672db05c58a8be00805c1567;p=it%2Ftest.git diff --git a/ric_robot_suite/robot/resources/ric/ric_utils.robot b/ric_robot_suite/robot/resources/ric/ric_utils.robot new file mode 100644 index 0000000..30ed937 --- /dev/null +++ b/ric_robot_suite/robot/resources/ric/ric_utils.robot @@ -0,0 +1,90 @@ +# Copyright (c) 2019 AT&T Intellectual Property. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +*** Settings *** +Documentation A library of utility keywords that may be useful +... in various test suites. + +Library Collections + +*** Keywords *** +# +# Kubernetes Utilities +Most Recent Availability Condition + # this makes the probably-unsafe assumption that the conditions are ordered + # temporally. + [Arguments] @{Conditions} + ${status} = Set Variable 'False' + :FOR ${Condition} IN @{Conditions} + \ ${status} = Set Variable If '${Condition.type}' == 'Available' ${Condition.status} ${status} + [Return] ${status} + +Most Recent Container Logs + [Arguments] ${deployment} ${container}=${EMPTY} ${regex}=${EMPTY} + ${pods} = Retrieve Pods For Deployment ${deployment} + ${logs} = Create List + :FOR ${pod} IN @{pods} + \ ${log} = Retrieve Log For Pod ${pod} ${container} + \ Should Not Be Empty ${log} No log entries for ${pod}/${container} + \ ${line} = Run Keyword If "${regex}" != "${EMPTY}" + ... Most Recent Match ${log} ${regex} + ... ELSE + ... Get From List ${log} -1 + \ Append To List ${logs} ${line} + [Return] ${logs} + +# +# Robot metatools +Run Keyword If Present + [Documentation] Run the given keyword, ignoring errors and returning status, if it exists. + ... Returns "PASS" if the keyword does not exist. + [Arguments] ${kw} + ${exists} ${u} = Run Keyword And Ignore Error + ... Keyword Should Exist ${kw} + ${status} ${u} = Run Keyword If '${exists}' == 'PASS' + ... Run Keyword And Ignore Error ${kw} + ... ELSE + ... Set Variable PASS unused + [Return] ${status} + +# +# Data manipulation +Toggle Flag + [Documentation] Apply "not" to a boolean flag + [Arguments] ${flag} + ${bFlag} = Convert To Boolean ${flag} + ${bFlag} = Set Variable If ${bFlag} ${false} ${true} + [Return] ${bFlag} + +Most Recent Match + [Arguments] ${list} ${regex} + ${matches} = Get Matches ${list} regexp=${regex} + Should Not Be Empty ${matches} No log entries matching ${regex} + ${match} = Get From List ${matches} -1 + [Return] ${match} + +Pluck + [Documentation] Get the values of a specific key from a list of dictionaries + [Arguments] ${k} ${l} + @{names} = Evaluate filter(lambda v: v != None, [i.get('${k}', None) for i in ${l}]) + [Return] ${names} + +Subtract From List + [Documentation] Remove the elements of the second argument from the first + [Arguments] ${x} ${y} + ${diff} = Run Keyword If ${y} + ... Evaluate filter(lambda v: v not in ${y}, ${x}) + ... ELSE + ... Set Variable ${x} + [Return] ${diff}