1

I need your help with the following problem:

As part of my robot framework test I have to execute some verification via Linux CLI too. I have imported the SSHLibrary and I can connect properly to my Linux box:

*** Keywords ***
Verify Service On All Nodes
    Open Connection  ${host}  prompt=REGEXP:[$|#]
    login   ${user}     ${user_pass}
    SSHLibrary.Read Until Prompt
    write   su - \n
    Read Until  Password:
    Write   ${root_pass}\n
    BuiltIn.sleep  10
    SSHLibrary.Set Client Configuration  prompt=~]
    Read Until Prompt
    Write   verify  #this stepp calls a shell script which does the required check
    BuiltIn.sleep  90
    SSHLibrary.Read Until Prompt
    ${output}  SSHLibrary.Read Until Prompt
    Log     ${output}

The above snippet logs the output of my verify script into the report properly, but I'd like to go a step further.

I've written a Python function which validates the output of the above script.

def verify_service_state(ab11, ab12, s):
    import re
    servers = [ab11, ab12]
    for i in servers:
        r1 = re.search(r"^Checking listening ports on " + (i) + " for roles: \(AB\)" + "\nThere were no errors reported.", s, re.MULTILINE)
        if (r1):
            print("Listening ports are open " + (i))
        else:
            print("Not all listening ports are open on " + (i))
        r2 = re.search(r"^Checking process counts on " + (i) + " for roles: \(AB\)" + "\nThere were no errors reported.", s, re.MULTILINE)
        if (r2):
            print("There were no errors reported on " + (i))
        else:
            print("Not all services are working as expected on " + (i))

I've created a RF library based on this post: Creating a robot framework library from existing python package However, it's not clear how can I pass the attributes to my function.

martineau
  • 119,623
  • 25
  • 170
  • 301
János
  • 133
  • 1
  • 11

1 Answers1

1

It should be simple: You import your function/library inside RF by using Library \the\path\to\your\library\file.py, or add your file (or folder) in PYTHONPATH and import the class that wraps the functions. For example: Library ValidationLibrary.

Then, in your test, you use your function as any other keyword (see the documentation for other examples):

Verify Service State      server1      server2     string

or, if there are optional parameters:

Verify Service State      ab11=server1      ab12=server2      s=string
Nomce
  • 738
  • 1
  • 6
  • 18