test_section

The test_section command creates a new Blitz test section in LAMP.

Purpose of test sections

All Blitz action snippets within a trigger are organized under test sections. Each section can represent a specific task or logical grouping, making the trigger easier to read and debug. The use of test sections does not affect the actual operations performed on network devices.

Basic usage

By default, LAMP adds autogenerated action snippets to a test section named ‘default’. When the command test_section <SECTION_NAME> is invoked, LAMP creates a new test section with the specified name. Newly generated Blitz snippets are then added to this new section.

The following example demonstrates how autogenerated Blitz action snippets fall under the default test section & the newly created test sections:

(lamp-host1) configure no logging console
2024-07-29 20:14:51: %LAMP-INFO: +..............................................................................+
2024-07-29 20:14:51: %LAMP-INFO: :                  Configure 'no logging console' on 'host1'                   :
2024-07-29 20:14:51: %LAMP-INFO: +..............................................................................+

2024-07-29 20:14:51,825: %UNICON-INFO: +++ host1 with via 'a': configure +++
config term
Enter configuration commands, one per line.  End with CNTL/Z.
host1(config)#no logging console
host1(config)#end
host1#
(lamp-host1) test_section new_1
(lamp-host1)
(lamp-host1) execute show ip route -i
2024-07-29 20:15:08: %LAMP-INFO: +..............................................................................+
2024-07-29 20:15:08: %LAMP-INFO: :                      Execute 'show ip route' on 'host1'                      :
2024-07-29 20:15:08: %LAMP-INFO: +..............................................................................+

2024-07-29 20:15:08,160: %UNICON-INFO: +++ host1 with via 'a': executing command 'show ip route' +++
show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, m - OMP
       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       H - NHRP, G - NHRP registered, g - NHRP registration summary
       o - ODR, P - periodic downloaded static route, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR
       & - replicated local route overrides by connected

Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
C        1.1.1.1 is directly connected, Loopback30
host1#
2024-07-29 20:15:08: %LAMP-INFO: +..............................................................................+
2024-07-29 20:15:08: %LAMP-INFO: :                                   INCLUDE                                    :
2024-07-29 20:15:08: %LAMP-INFO: +..............................................................................+
Enter pattern to INCLUDE (Press enter for multiple patterns): 1.1.1.1
(lamp-host1)
(lamp-host1) test_section new_2
(lamp-host1)
(lamp-host1) sleep 5
2024-07-29 20:15:16: %LAMP-INFO: +------------------------------------------------------------------------------+
2024-07-29 20:15:16: %LAMP-INFO: :                             Sleep for 5 seconds                              :
2024-07-29 20:15:16: %LAMP-INFO: +------------------------------------------------------------------------------+
(lamp-host1)

When the trigger gets saved, the execute and sleep actions appear under the ‘new_1’ and ‘new_2’ test sections, respectively. The initial configure action, performed before any new test section was created, is placed under the ‘default’ section. The resulting YAML file is shown below:

# sample.yaml
# 29 July 2024
# LAMP Generated testcase
sample:
  source:
    pkg: genie.libs.sdk
    class: triggers.blitz.blitz.Blitz
  devices:
    - host1
  test_sections:
    - default:
        - configure:
            device: host1
            command: no logging console
    - new_1:
        - execute:
            device: host1
            command: show ip route
            include:
              - 1.1.1.1
    - new_2:
        - sleep:
            sleep_time: 5