X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ric_robot_suite%2Fhelm%2Fnanobot%2Fconfigmap-src%2Fpublic%2Fresources%2Fric_utils.robot;fp=ric_robot_suite%2Fhelm%2Fnanobot%2Fconfigmap-src%2Fpublic%2Fresources%2Fric_utils.robot;h=e7041505f0f84fbaba370b4b0ab243e4495126c5;hb=029cc1f45c4c40e0867104b730495d4d2fe468b8;hp=0000000000000000000000000000000000000000;hpb=0d26f300d5f9da0aa23612b8a4a9e863423d598b;p=it%2Ftest.git diff --git a/ric_robot_suite/helm/nanobot/configmap-src/public/resources/ric_utils.robot b/ric_robot_suite/helm/nanobot/configmap-src/public/resources/ric_utils.robot new file mode 100644 index 0000000..e704150 --- /dev/null +++ b/ric_robot_suite/helm/nanobot/configmap-src/public/resources/ric_utils.robot @@ -0,0 +1,115 @@ +# Copyright (c) 2019 AT&T Intellectual Property. +# Copyright (c) 2020 HCL Technologies. +# 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} + END + [Return] ${status} + +Replica Availability + # this makes the probably-unsafe assumption that the conditions are ordered + # temporally. + [Arguments] ${Replica} + ${status} = Set Variable If ${Replica} >= 1 'True' 'False' + [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} + END + [Return] ${logs} + +Component Should Be Ready + [Documentation] Given a Kubernetes controller object as returned from the KubernetesEntity + ... library routines (such as 'Deployment' or Statefulset'), check whether the + ... entity is ready + [Arguments] ${entity} + Should Be Equal ${entity.status.replicas} ${entity.status.ready_replicas} + # This doesn't seem to make sense for statefulsets + ${status} = Run Keyword If '${entity.kind}' == 'Deployment' + ... Most Recent Availability Condition @{entity.status.conditions} + ... ELSE + ... Set Variable True + Should Be Equal As Strings ${status} True ignore_case=True + [Return] ${status} + +# +# 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} + +