12-20-2021 04:14 AM
Hi there, I'm having problems with the genie parser library in robot framework. I'm basically copying the approach from the example in https://pubhub.devnetcloud.com/media/genie-docs/docs/userguide/robot/index.html
If I try this .robot file to parse the output of show version, store it in a variable, then query it with dq:
*** Settings *** Library unicon.robot.UniconRobot Library ats.robot.pyATSRobot Library genie.libs.robot.GenieRobot *** Variables *** ${testbed} testbed.yaml *** Test Cases *** Connect use genie testbed "${testbed}" connect to devices "leaf1" parser show version ${output}= parse "show version" on device "leaf1" Verify version dq query data=${output} filters=contains('9.3(8)').get_values('system_version') on device "leaf1" Disconnect from device disconnect from device "leaf1"
The parser passes, but the verify fails because the variable is not found:
------------------------------------------------------------------------------ parser show version | PASS | ------------------------------------------------------------------------------ Verify version | FAIL | Variable '${version}' not found. ------------------------------------------------------------------------------
If I do the same thing directly in python it does what I expect, e.g:
from pyats.async_ import pcall from genie.testbed import load from genie.utils import Dq from rich import print as rprint def get_version(hostname, dev): parsed = dev.parse("show version") get_version = (Dq(parsed).contains('9.3(8)').get_values('system_version')) rprint(get_version) testbed = load("leaf1.yaml") testbed.connect(log_stdout=False) results = pcall(get_version, hostname=testbed.devices.keys(), dev=testbed.devices.values())
Results in:
gdaly@pop-os:~/PycharmProjects/evpn/tests$ python3 verify_version.py ['9.3(8)']
Can anyone see where I'm going wrong here?
01-07-2022 07:44 AM
Hi @george_daly,
I'm not a Robot Genie expert but I found this:
"Variables can also be given from the command line which is useful if the tests need to be executed in different environments. For example this demo can be executed like:
robot --variable USERNAME:johndoe --variable PASSWORD:J0hnD0e QuickStart.rst
"
This could be useful in debugging, i.e. see if it passes with variable given through CLI.
Another thought, could you rename the 'data' variable as 'version'? Maybe that's what it's looking for.
Hope this helps!
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide