Examples: Tests
It is assumed here that Test Agents (as many as are required for the tests) have been created according to the section Creating and Deploying a New Test Agent.
YANG Model Paths for Tests
Item | YANG model path: /accounts/account/tests ... |
---|---|
tests | /. |
test[id] | /test |
id | /test/id |
name | /test/name |
status | /test/status |
start-time | /test/start-time |
end-time | /test/end-time |
report-url | /test/report-url |
steps | /test/steps |
step[id] | /test/steps/step |
name | /test/steps/step/name |
id | /test/steps/step/id |
start-time | /test/steps/step/start-time |
end-time | /test/steps/step/end-time |
status | /test/steps/step/status |
status-message | /test/steps/step/status-message |
templates | /templates |
template[name] | /templates/template |
name | /templates/template/name |
description | /templates/template/description |
parameters | /templates/template/parameters |
parameter[key] | /templates/template/parameters/parameter |
key | /templates/template/parameters/parameter/key |
type | /templates/template/parameters/parameter/type |
Prerequisites for Test Orchestration
- In order to start a test through NETCONF using ncclient, it is required to first
build a test template using the Control Center GUI as detailed in the in-app
help under "Tests and monitors" > "Creating templates". All fields specified
in that template as "Template input" will be required as parameters in the XML
when orchestrating the initiation of the test template.
- Running tests in Paragon Active Assurance is considered as "state" in the context of orchestration. State data is non-writable data that is not stored in the configuration database, as opposed to the configuration data mentioned in the section Overview of Test Agent Orchestration. This basically means that changes to tests or templates in the Control Center GUI will not cause any sync-related issues between Control Center and the configuration database.
- To get
report-url
right in test reports, you need to make sure the Control Center URL is correctly configured. This is done in the file/opt/netrounds-confd/settings.py
. By default the Control Center host name is retrieved usingsocket.gethostname()
: see below. If this does not yield the correct result, you need to set the host name (or the entire URL) manually in this file.
# URL of Control Center without trailing slash. # This is for example used in test report-url. HOSTNAME = socket.gethostname() NETROUNDS_URL = 'https://%s' % HOSTNAME
Starting a Test
As described in the section Creating and Deploying a New Test Agent, run the command
pyang -f tree netrounds-ncc.yang
from the directory /opt/netrounds-confd/
in order to output the YANG
model. In this model, the RPC for starting a test using ncclient looks as
follows:
+---x start-test | +---w input | | +---w name string | | +---w account -> /accounts/account/name | | +---w template string | | +---w parameters | | +---w parameter* [key] | | +---w key string | | +---w (value-type) | | +--:(integer) | | | +---w integer? int64 | | +--:(float) | | | +---w float? decimal64 | | +--:(string) | | | +---w string? string | | +--:(test-agent-interfaces) | | | +---w test-agent-interfaces | | | +---w test-agent-interface* [account test-agent interface] | | | +---w account -> ../../../../../account | | | +---w test-agent -> deref(../../../../../account)/../test-agents/test-agent/name | | | +---w interface -> deref(../test-agent)/../interfaces/interface/name | | | +---w ip-version? inet:ip-version | | +--:(twamp-reflectors) | | | +---w twamp-reflectors | | | +---w twamp-reflector* [name] | | | +---w name -> deref(../../../../../account)/../twamp-reflectors/twamp-reflector/name | | +--:(y1731-meps) | | | +---w y1731-meps | | | +---w y1731-mep* [name] | | | +---w name -> deref(../../../../../account)/../y1731-meps/y1731-mep/name | | +--:(iptv-channels) | | | +---w iptv-channels | | | +---w iptv-channel* [name] | | | +---w name -> deref(../../../../../account)/../iptv-channels/iptv-channel/name | | +--:(sip-accounts) | | +---w sip-accounts | | +---w sip-account* [account test-agent interface sip-address] | | +---w account -> ../../../../../account | | +---w test-agent -> deref(../../../../../account)/../test-agents/test-agent/name | | +---w interface -> deref(../test-agent)/../interfaces/interface/name | | +---w sip-address -> deref(../../../../../account)/../sip-accounts/sip-account/sip-address | +--ro output | +--ro result test-status-t | +--ro id? uint32 | +--ro error-text? string
For explanations, see the section Legend in the Appendix.
The following steps are shown below:
- Test Agents have been registered to the Paragon Active Assurance account, but no tests have yet been started.
- The required input parameters are identified in the test template that will be run.
- A 60 second HTTP test is started using ncclient.
Step 1: At the outset, no tests have been initiated in the Paragon Active Assurance account. See the screenshot below from the Control Center GUI.
Step 2: The template we will use to initiate the test in this example is an
HTTP test template. It has two mandatory input fields (Clients
and
URL
) which we have specified as such when building the template
in the Control Center GUI.
We will define these parameters (among others) in the XML configuration communicated to the configuration database by our NETCONF manager (ncclient).
Step 3: The HTTP test is initiated using ncclient.
Below is example code where the required configuration information and parameters are specified for the HTTP test template. Depending on how the template has been built, the details here may vary.
For each parameter, the <key>
attribute needs to be supplied.
The key is identical to the parameter's Variable name
in Control
Center. You can inspect variable names as follows:
- Click Tests on the side bar and select New Test Sequence.
- Click My Templates.
- Click the Edit link below the template of interest.
- Click the Edit input button in the top right corner.
In our example, and by default, the variable names are simply lowercase versions of the display names seen in Control Center ("url" vs. "URL", etc.). However, in the Control Center GUI, you can rename the variables to whatever you like.
Besides the key, each parameter needs to have its type specified: for example,
<string>
for the URL. Please note that you need to review
the complete YANG model in order to obtain full information on types. For Test Agent
interfaces the type has a more complex structure, as evidenced under
<clients>
in the code below.
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: # Run RPC "start-test" # A template named "HTTP_test" and having two inputs is assumed to exist xml = """<start-test xmlns="http://ncc.netrounds.com"> <name>Netconf Initiated HTTP test</name> <account>{account}</account> <template>HTTP_test</template> <parameters> <parameter> <key>clients</key> <test-agent-interfaces> <test-agent-interface> <account>{account}</account> <test-agent>TA1</test-agent> <interface>eth0</interface> </test-agent-interface> </test-agent-interfaces> </parameter> <parameter> <key>url</key> <string>http://www.google.se</string> </parameter> </parameters> </start-test>""".format(account=args.netrounds_account) # Convert to ElementTree element elem = to_ele(xml) print m.dispatch(elem)
We can now run the script using ncclient. Assuming all is correct, the test will be initiated and its execution displayed in Control Center:
If the test is successfully started, Control Center will respond with the test ID. In this example, the test ID is 3:
<?xml version="1.0" encoding="UTF-8"?> <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:f08efc54-2086-4d09-af71-5b65fcecabe1" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><id xmlns='http://ncc.netrounds.com'>3</id> </rpc-reply>
The test ID can also be found in the URL for the test in the Control Center GUI. In
this example, that URL is https://host/demo/testing/3/
.
Retrieving Test Results
The most straightforward way to retrieve test results is by pointing to the test ID.
Below is Python code for getting the results from the above HTTP test with ID = 3:
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: # Get results from test in account xml = """<accounts xmlns="http://ncc.netrounds.com"> <account> <name>{account}</name> <tests> <test> <id>{id}</id> </test> </tests> </account> </accounts>""".format(account=args.netrounds_account, id=3) # Convert to ElementTree object ele = to_ele(m.get(filter=('subtree', xml)).data_xml) # Convert back to XML string and print print to_xml(ele, encoding='UTF-8', pretty_print=True)
The output will look something like this:
<?xml version="1.0" ?> <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> <accounts xmlns="http://ncc.netrounds.com"> <account> <name xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">demo</name> <tests> <test> <id xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">3</id> <name>HTTP</name> <status>passed</status> <end-time>2017-01-26T22:23:53+00:00</end-time> <report-url>https://localhost//demo/testing/3/</report-url> <steps> <step> <id>4</id> <name>Step 1</name> <start-time>2017-01-26T22:22:51+00:00</start-time> <end-time>2017-01-26T22:23:51+00:00</end-time> <status>passed</status> <status-message/> </step> </steps> </test> </tests> </account> </accounts> </data>
Exporting and Importing Test Templates
Test templates can be exported in JSON format and reimported in that format into Control Center. This is useful if you want to use test templates in a different installation of Control Center. (The initial creation of the templates is best handled through the Control Center GUI.)
Below is code for performing the export and import.
Exporting Test Templates
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: # Export selected templates from Control Center # In order to export all templates, remove the <templates></templates> node export_xml = """ <export-test-templates xmlns="http://ncc.netrounds.com"> <account>{account}</account> <templates> <template> <name>template_udp</name> </template> <template> <name>template_tcp</name> </template> </templates> </export-test-templates>""".format(account=args.netrounds_account) elem = to_ele(export_xml) response = m.dispatch(elem) # Get json config from response root = ET.fromstring(response._raw) json_config = root[0].text print json_config
The template is contained in the json_config
object.
Importing Test Templates
A JSON config object holding test templates can be reimported into Control Center as follows.
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: json_string = """ { "templates":[ { "input":[ { "require_bridge":false, # ... # Insert rest of JSON string here # ... } ], "version": "2.29", "export_date": "2019-05-29T12:39:31.172594Z" } """ # Import templates back into Control Center import_xml = """ <import-test-templates xmlns="http://ncc.netrounds.com"> <account>{account}</account> <overwrite>false</overwrite> <data>{data}</data> </import-test-templates>""".format( account=args.netrounds_account, data=json_string) elem = to_ele(import_xml) response = m.dispatch(elem) print response