Home > Articles > pyATS Triggers and Verifications

pyATS Triggers and Verifications

Contents

  1. Genie Objects
  2. Genie Harness
  3. Verifications
  4. Triggers
  5. Trigger and Verification Example
  6. Summary

Chapter Description

The pyATS library (Genie) provides the Genie Harness to execute network tests with dynamic and robust capabilities. The Genie Harness can be daunting for new users of the pyATS library (Genie), as there are many configuration options and parameters. By the end of the chapter, you'll understand the powerful capabilities of Genie Harness and how to write and execute triggers and verifications.

Trigger and Verification Example

Now it’s time to combine the triggers and verifications into one complete example. In the example, we will build on previous examples where we flap (shut/unshut) the OSPF process on two IOSv routers. The trigger has local verifications that will confirm OSPF is indeed shut down and confirm that it comes up after being unshut. In addition to the local verifications defined in the trigger, the job will also introduce a global verification to check the router link states (LSA Type 1) in the OSPF LSDB (link state database). This global verification will run before and after the trigger. This allows us to confirm that LSA Type 1 packets are being exchanged before and after testing and that the router link types have not changed during testing.

Let’s see how this example can be implemented and executed using Genie Harness and also within a pyATS testscript.

Genie Harness (gRun)

This whole chapter has been focused on Genie Harness, so let’s not rehash the details. Example 9-16 shows an example of the job file, trigger datafile, and verification datafile used to execute the job. Figure 9-4 shows the associated test results.

Example 9-16 Trigger and Verification Example – ex0917_complete_example.py

# Job file - ex0917_complete_example.py
from genie.harness.main import gRun

def main():
gRun(
         trigger_uids=["TriggerShutNoShutOspf"],
         trigger_datafile="ex0917_trigger_datafile.yaml",
         verification_uids=["Verify_IpOspfDatabaseRouter"],
         verification_datafile="ex0917_verification_datafile.yaml"
         )



# Trigger datafile – ex0917_trigger_datafile.yaml
extends: "%CALLABLE{genie.libs.sdk.genie_yamls.datafile(trigger)}"

# Custom trigger - created before Example 9-14
TriggerShutNoShutOspf:
# source imports the custom trigger, just as you would any other Python class
  source:
    class: ex0915_custom_trigger.MyShutNoShutOspf
  devices: ["iosv-0", "iosv-1"]





# Verification datafile - ex0917_verification_datafile.yaml
extends: "%CALLABLE{genie.libs.sdk.genie_yamls.datafile(verification)}"


Verify_IpOspfDatabaseRouter:
  devices: ["iosv-0", "iosv-1"]
FIGURE 9.4

Figure 9.4 Trigger and Verification Example Results

pyATS

Triggers and verifications can be run in a pyATS testscript as a testcase or within a test section. Custom trigger and verification datafiles can be provided using the --trigger-datafile and --verification-datafile arguments when calling a pyATS job.

To run it as its own testcase, you’ll just need to create a class that inherits from GenieStandalone, which inherits from the pyATS Testcase class. The inherited class you create will provide a list of triggers and verifications. The same trigger and verification datafiles will be included as options when running the pyATS job via the command line.

The second way to include triggers and verifications in a pyATS testscript is by including them in an individual test section, as part of a pyATS testcase. The run_genie_sdk function allows you to run triggers or verifications as steps within a section.

Example 9-17 shows how to include triggers and verifications as their own testcase and within an existing subsection in a pyATS testscript. To run the testscript, you’ll need to add the --trigger-datafile and --verification-datafile arguments with the appropriate datafiles to map the custom trigger and verifications to the additional devices. These datafiles are not included in the example. Figure 9-5 shows the testscript results.

Example 9-17 Triggers and Verifications in pyATS Testscript

from pyats import aetest
import genie
from genie.harness.standalone import GenieStandalone, run_genie_sdk


class CommonSetup(aetest.CommonSetup):
""" Common Setup section """

       @aetest.subsection
       def connect(self, testbed):
       """Connect to each device in the testbed."""

               genie_testbed = genie.testbed.load(testbed)
               self.parent.parameters["testbed"] = genie_testbed
               genie_testbed.connect()


# Call Triggers and Verifications as independent pyATS testcase
class GenieOspfTriggerVerification(GenieStandalone):
"""Shut/unshut the OSPF process and verify LSA Type 1 packets are still being
exchanged before and after testing."""


         # Must specify 'uut'
         # If other devices are included in the datafile(s), they will be tested
         uut = "iosv-0"
         triggers = ["TriggerShutNoShutOspf"]
         verifications = ["Verify_IpOspfDatabaseRouter"]




# Calling Triggers and Verifications within a pyATS section
class tc_pyats_genie(aetest.Testcase):
         """Testcase with triggers and verifications."""
         # First test section
         @aetest.test
         def simple_test_1(self, steps):
         """Sample test section."""

         # Run Genie triggers and verifications
         # Note that you must specify the order of each trigger and verification
         run_genie_sdk(self,
                          steps,
                          ["Verify_IpOspfDatabaseRouter",                            "TriggerShutNoShutOspf",                            "Verify_IpOspfDatabaseRouter"],
                          uut="iosv-0"
                          )


class CommonCleanup(aetest.CommonCleanup):
"""Common Cleanup section"""

@aetest.subsection
def disconnect_from_devices(self, testbed):
         """Disconnect from each device in the testbed."""
         testbed.disconnect()
FIGURE 9.5

Figure 9.5 Triggers and Verifications in pyATS Testscript Results

Cisco Press Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Cisco Press and its family of brands. I can unsubscribe at any time.