Vous êtes sur la page 1sur 19

JT With Advanced Perl

JUNOS Automation Training for JUNOSe Engineers

JUNOS Environment
JUNOSe Infrastructure SQATS JUNOS JT

Test Specification
Regression Harness

AMT/ATT
JustBig

JT::Test Library
jbatch/Regression Manager

Hardware Selection
Test Storage Reservations

manually: .conf or command line


ClearCase

params
cvs

Res Web Page or Systray Tool

res (and sometimes JT)

Res

The res command line program works just like the systray program and resource browser page, and works from same db
$ res --help-list-cmd Usage: res [res-options] command [command-options-and-arguments] res commands are: co | checkout Checkout resources ci | checkin Checkin resources sh | show Show resources status up | update update existing reservations pm | preempt preempt existing reservations

Use man res for more details

Params

Params is a standalone system that finds hardware (routers, RouterTesters, etc.) that fits your testing needs

You define a list of constraints (e.g. a GE port on router1 should connect to a GE port on router2) and params will fill in the blanks The configuration file uses a c-like syntax of stanzas delimited with braces.

Params Expansion
.params File
r0 { system { model "m20"; } interfaces { r0-r1 { type "ether"; } } } r1 { system { model "m20"; } interfaces { r0-r1 { type "ether"; } } }
r0 { system { name "asahi"; cube "cube3"; make "juniper"; model "m20"; os "JunOS"; os-ver "5.1"; mgtaddr "10.255.14.218"; isoaddr "47.0005.80ff.f800.0000.0108.0001.0102.5501.4218.00"; } interfaces { r0-r1 { name "fe-0/1/0.0"; pic "fe-0/1/0"; unit 0; type "ether"; speed 100; ipaddr "192.168.199.130"; } } } r1 { system { name "redhook"; cube "cube3"; make "juniper"; model "m20"; os "JunOS"; os-ver "5.1"; mgtaddr "10.255.14.222"; isoaddr "47.0005.80ff.f800.0000.0108.0001.0102.5501.4222.00"; } interfaces { r0-r1 { name "fe-0/1/0.0"; pic "fe-0/1/0"; unit 0; type "ether"; speed 100; ipaddr "192.168.199.129"; } } }

.params dump

Params

Params Operation

Use params-find <options> <params file>


> params-find -g protocols-e-elements benstest.pl.params Params server for this session: golf.englab.juniper.net Importing benstest.pl.params R0 -> hydrogen R0:R0-R1-1 -> fe-0/0/0.0 R1 -> helium R1:R0-R1-1 -> fe-0/0/0.0 setenv PARAMS_MACHINES hydrogen:helium

res co hydrogen helium

If the -g option is not used then params will use the TE_TOPOLGY environment variable for the testbed name. Use -d to dump the entire filled params form Constraints that begin with x- are ignored by params but stay in form Use params-find help or man params-find for command usage

Params Data

Lab-trolls maintain params data params-info returns data from the params system for a given device
> params-info helium Params server for this session: moon.englab.juniper.net Current information for helium: Make..................juniper Model.................m10i Cube..................protocols-e-elements ISO address...........N/A Host re0 Loopback IP...........N/A Management IP.........10.5.11.43/16 Console IP............10.5.11.10 Default OS............JunOS 7.6 Update time...........#<LOCAL-TIME: 2006-07-12 13:38:37-07>

fe-0/0/0

hydrogen fe-0/0/0

Use man params-info for command usage Complete params info at http://params.englab.juniper.net:8000/params/index.html

JT

JT is the JUNOS Test System An object oriented interface written in Perl

JT is actually just a very large perl module (JT.pm) that provides many of the essential functions for testing.
Each router is an object in JT that tracks connections and receives commands Docs: http://wwwsystest.juniper.net/twiki/bin/view/Main/JTDoc umentation

Using JT

A simple JT test might:

JT provides primitives Other JT libraries support:


disconnect and cleanup

connect to a router execute commands check the results

e.g. $r[0]->chk_version or $r[1]->chk_bgp_peer(peer=>'10.102.255.10', timeout=> 120); RouterTester (RT.pm), other libraries upcoming JUNOSe Routers (ERX.pm), Cisco (IOS.pm) Protocol Libraries (e.g. BGP, MPLS, Firewall, Scaling, SNMP, etc.)

JT::Test

Standardizes and simplifies automation


Automatic set up of the test topology as defined in your Params file (connect to routers, save configs, configure interfaces, check link status, check connectivities (via ping), plus much much more). Automatic clean up before exit (restore router configs, perform postmortem if there's a test failure, close router connections on exit, etc). Option to reserve machines for use by test script. Tracking of individual test cases (successes, failures, etc). Default behaviors can be changed using Params tokens.

Docs: http://wwwsystest.juniper.net/pub/doc/JT/Test/docs/

JT::Tests Role
Typical JT::Test flow:


Calls params with your .params file to determine what hardware to use.
Connects to routers (uses info from fulfilled params request). Saves router base configs; Cleans routers in preparation for testing. Configures interfaces (with params info) and (optionally) calls your userspecified test configs.

Commits routers.
Executes your test cases. Tracks test successes and failures. Upon failure, does postmortem (i.e., gather router information for troubleshooting purposes). Optionally does your postmortem routine. Restores router configs; exits routers.

Exits program with the appropriate error code.

Running a JT::Test Test



Demo is Bens sampleART test

Command line switches for JT::Test tests:


-cr: Check out machines, then continue running script. -ci: Check in machines, then exit script. -sr: Skip check for proper res reservations -so: Setup only; run configs, then exit test before testcases are run

Env variables:
PATH=/volume/perl/bin:/bin:/sbin:/usr/bin:/usr/sbin:/volume/labtools/bin:/usr/local/bin CVSROOT=cvs:/cvs/juniper CVS_RSH=ssh TE_DATA_TMPDIR=~/TE/regress/scripts/results TE_TOPOLOGY=protocols-e-elements PARAMS_VERSION=2

Test Structure

A JT::Test based script is separated into three files:


A script file test.pl A params file test.pl.params A perl module test.pm

The .pl file


The script (.pl) file typically is a short stub file that serves to launch the test, and not much more. Makes calls to JT::Test, which, in turn, calls your routines
See ~rdonle/sample/sampleART.pl for a sample
use warnings; use strict; use vars qw($VERSION); # NOTE: Scripts submitted to TI must use production libraries. use lib qw(/volume/labtools/lib); use JT::Test; use sampleART; $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; main: { my $t = JT::Test->init; $t->setup; $t->run_testcases; $t->close; }

The .params File


A .params file thats part of a JT::Test contains:

General JT settings (global x- parameters) e.g. x-log-level "TRACE"; x-set-user- parameters that define config/chkstatus/postmortem/etc e.g. x-set-user-configs "&sampleART::config"; x-testcase testcase definitions x-testcase-001 ( "x-is-run" 1 "Sample test case" e.g."x-descr"
"x-cmd" "x-args" "x-loop" "x-reset-config" ); "sampleART::TC1" "ENV" 1 0

params constraints to define devices to be used (not x- parameters)

See ~rdonle/sample/sampleART.pl.params

The .pm File

The .pm file for your test is a library of functions


Exported functions will include all functions named in your .params file You can also include internal service functions

In theory, a .pm can be shared between tests


But in practice, theres a separate .pm for each test

.pm File Walkthrough

Sample file is Bens sampleART.pm (~rdonle/sample/sampleART.pm)


$t->get_handles(params=>\$p, rtrs=>\@r, vars=>\$v, rt=>\$rt, hosts=>\@hosts) sets these helpful variables

$p contains the complete params dump, including all x- parameters e.g. $p->{R0}->{SYSTEM}->{MODEL} == m20 See a complete dump at ~rdonle/sample/p-handle.txt e.g. $r[0]->{MODEL} == m20 See a complete dump at ~rdonle/sample/r-handle.txt

@r contains an array of router objects

$v contains all JT variables, like global x- parameters, and some shortcuts

e.g. $v->{R0_MODEL} == m20


See a complete dump at ~rdonle/sample/v-handle.txt

File Locations
.pl and .params files (the test itself) belong: .pm file (the tests library) belongs:
cvs/system-test/scripts/<group>

cvs/system-test/source/Testsuites/<group>

JT libraries are in Beta JT libraries are in


/volume/labtools/lib

/volume/labtools/lib/JT/devel

Other Tools

RSU - Router Setup Utility

Restores base config on router rsu -c <router name(s)> RSU with the -c option, will take the config file from /volume/labtools/lab-cvs/system-test/machine/<machinename>/config and place it on the router along with the default systest package. clean_config: very similar to rsu but runs in parallel for multiple routers

Autoupd - upgrade one or many routers

Typically, run: autoupd -j 8.2 -d --no-validate <router name(s)> If no specific version is specified the latest daily build will be installed. If you wanted a specific build autoupd would look like: autoupd -j 8.1B3.2 -d --no-validate <router name(s)>

Vous aimerez peut-être aussi