Skip to content

Commit

Permalink
Add bgp for 3-manual
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaubin committed Dec 22, 2020
1 parent ae171d7 commit e485f74
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 30 deletions.
58 changes: 58 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Python compiled files
*.pyc
*.pyo
__pycache__/
*.log

# Cython files
*.c
*.so

# Developer files
.project
.pydevproject

# Pycharm files
.idea

# Rope files
.ropeproject

# Swap files (VI)
*.sw*

# backup files
*.bak

# rope project files
*.ropeproject

# temp files
*~

# build folder
__build__/
build/

# Artifacts caused by "make develop"
*.egg-info

# coverage.py artifacts
htmlcov/
.coverage*

# filesystem stuff on Mac
.DS_Store

# unicon log file
uni.log

# Extra files placed by cisco_shared into examples
*dyntopo/src/dyntopo/laas/examples/dyntopo_laas
*dyntopo/src/dyntopo/xrut/examples/dyntopo_xrut

# Files resulting from a git meld merge
*.orig

# VSCode
.vscode
34 changes: 24 additions & 10 deletions 3-Automate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,12 @@ That's it! Our re-usable testcase is now running. With the ``--liveview`` field,

Right now our trigger verify only what is expected. The next step is - how do we verify also the unexpected as we've seen in the previous manual step?

Try this by uncommenting the comments in the trigger code.
Try this by uncommenting the comments in the trigger code. Once uncommented, rerun the above command.

And this is also a perfect place to introduce our Verification concept:

```python
# in job file
gRun(verification_uids=['Verify_BgpProcessVrfAll.uut'],
trigger_uids=['TriggerDemoShutNoShutBgp'],
trigger_datafile='trigger_datafile.yaml')
```
## Verifications

And this is also a perfect place to introduce our Verification concept:

The code that was uncommented works, instead of just verifying the shut/no shut
of Bgp it will verify the other keys in that same show command, to make sure
Expand All @@ -110,10 +106,26 @@ They are to be added dynamically either a Global Verification or Local verificat
- Global: Run before and after every Trigger
- Local: Run before and after specific Trigger

Let's modify our job file to now call Verify_Bgp

| Note: Any of the verification defined on this page can be used: https://pubhub.devnetcloud.com/media/testing-feature-browser/docs/#/verifications


```python
# in job file Use the second block of gRun, command out the first one.
gRun(verification_uids=['Verify_BgpProcessVrfAll.uut'],
trigger_uids=['TriggerDemoShutNoShutBgp'],
trigger_datafile='trigger_datafile.yaml')
```

```bash
pyats run job job.py --testbed-file ../../tb.yaml --liveview --replay $VIRTUAL_ENV/testing-bootcamp/mocked_devices/3-automate/two/
```

# Models Verification

Lastly, we can use Ops

Let's modify our job file to now call Verify_Bgp (Last block). This will use the bgp model feature, which will learn all commands relatives to Bgp and learn it and use it as comparison.

```python
# in job file
gRun(verification_uids=['Verify_Bgp.uut'],
Expand All @@ -126,6 +138,8 @@ gRun(verification_uids=['Verify_Bgp.uut'],
pyats run job job.py --testbed-file ../../tb.yaml --replay $VIRTUAL_ENV/testing-bootcamp/mocked_devices/3-automate/three/
```

| Note: Any of the models defined on this page can be used: https://pubhub.devnetcloud.com/media/testing-feature-browser/docs/#/models

We've seen a few ways to run this trigger, all are accomplished using only libraries:
- pick and choose what we need
- and create test suite using `gRun()`
Expand Down
18 changes: 9 additions & 9 deletions 3-Automate/run/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
def main():
test_path = os.path.dirname(os.path.abspath(__file__))

gRun(trigger_uids=['TriggerDemoShutNoShutBgp'],
trigger_datafile='trigger_datafile.yaml')
#gRun(trigger_uids=['TriggerDemoShutNoShutBgp'],
# trigger_datafile='trigger_datafile.yaml')

#gRun(verification_uids=['Verify_BgpProcessVrfAll.uut'],
# trigger_uids=['TriggerDemoShutNoShutBgp'],
# trigger_datafile='trigger_datafile.yaml')
#gRun(verification_uids=['Verify_BgpProcessVrfAll'],
# trigger_uids=['TriggerDemoShutNoShutBgp'],
# trigger_datafile='trigger_datafile.yaml')

#gRun(verification_uids=['Verify_Bgp.uut'],
# trigger_uids=['TriggerDemoShutNoShutBgp'],
# verification_datafile='verification_datafile.yaml',
# trigger_datafile='trigger_datafile.yaml')
gRun(verification_uids=['Verify_Bgp'],
trigger_uids=['TriggerDemoShutNoShutBgp'],
verification_datafile='verification_datafile.yaml',
trigger_datafile='trigger_datafile.yaml')
4 changes: 2 additions & 2 deletions 3-Automate/run/trigger_datafile.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
TriggerDemoShutNoShutBgp:
source:
class: genie-bootcamp.3-Automate.triggers.shutnoshut.bgp.nxos.shutnoshut.ShutNoShutBgp
class: testing-bootcamp.3-Automate.triggers.shutnoshut.bgp.nxos.shutnoshut.ShutNoShutBgp
devices: ['uut']

#TriggerDemoShutNoShutBgpV2:
# source:
# class: genie-bootcamp.3-Automate.triggers.shutnoshut.bgp.nxos.shutnoshutv2.ShutNoShutBgp
# class: testing-bootcamp.3-Automate.triggers.shutnoshut.bgp.nxos.shutnoshutv2.ShutNoShutBgp
# devices: ['uut']
18 changes: 9 additions & 9 deletions 3-Automate/triggers/shutnoshut/bgp/nxos/shutnoshut.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Code replaced by using Verification!
## Uncomment me
#from genie.utils.diff import Diff
from genie.utils.diff import Diff
###
from genie.harness.base import Trigger

Expand Down Expand Up @@ -37,7 +37,7 @@ def prerequisites(self, uut):
self.bgp_id = output['bgp_tag']
### Code replaced by using Verification!
# Uncomment me
#self.initial_output = output
self.initial_output = output
###

@aetest.test
Expand Down Expand Up @@ -74,8 +74,8 @@ def unshut(self, uut):
def verify_recover(self, uut, wait_time=20):
'''Figure out if bgp is configured and up'''
### Code replaced by using Verification!
#log.info('Sleeping for {w}'.format(w=wait_time))
#time.sleep(wait_time)
log.info('Sleeping for {w}'.format(w=wait_time))
time.sleep(wait_time)
###

# Check if there is a bgp_id
Expand All @@ -93,9 +93,9 @@ def verify_recover(self, uut, wait_time=20):

### Code replaced by using Verification!
# Uncomment me
#diff = Diff(self.initial_output, output)
#diff.findDiff()
#if diff.diffs:
# self.failed('Unexpected change has happened to our device state '
# '\n{d}'.format(d=diff))
diff = Diff(self.initial_output, output)
diff.findDiff()
if diff.diffs:
self.failed('Unexpected change has happened to our device state '
'\n{d}'.format(d=diff))
###
Binary file removed __pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified mocked_devices/3-automate/one/csr1000v-1
Binary file not shown.
Binary file added mocked_devices/3-automate/one/jump_host
Binary file not shown.
Binary file modified mocked_devices/3-automate/one/nx-osv-1
Binary file not shown.
Binary file modified mocked_devices/3-automate/three/csr1000v-1
Binary file not shown.
Binary file added mocked_devices/3-automate/three/jump_host
Binary file not shown.
Binary file modified mocked_devices/3-automate/three/nx-osv-1
Binary file not shown.
Binary file modified mocked_devices/3-automate/two/csr1000v-1
Binary file not shown.
Binary file added mocked_devices/3-automate/two/jump_host
Binary file not shown.
Binary file modified mocked_devices/3-automate/two/nx-osv-1
Binary file not shown.

0 comments on commit e485f74

Please sign in to comment.