Skip to content

Commit 7f63bf0

Browse files
committed
added ACI filter entry example
1 parent 15b4623 commit 7f63bf0

File tree

5 files changed

+198
-0
lines changed

5 files changed

+198
-0
lines changed

aci_filter/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Overview
2+
3+
Connect to API via Rest Connecor, and create filter entry, check the added filter entry (and delete the filter entry). This will check if the filter entry exists, or not to make sure REST API is properly done.
4+
5+
No python knowledge required. All is done in YAML by using `Blitz`(Quick Trigger).
6+
7+
# Steps
8+
9+
Please check `trigger_datafile.yaml`. The test is written in YAML. So, easy to find corresponding steps in the YAML.
10+
11+
1. Check Filter Entry doesn't exist
12+
2. Check Filter Entry doesn't exist under tenant
13+
3. Create Filter Entry under tenant
14+
4. Check Filter Entry exists
15+
5. Check Filter Entry exists under tenant
16+
6. Delete Filter Entry (Optional)
17+
18+
# Preparation
19+
20+
Install pyATS|Genie and Rest Connector.
21+
22+
```
23+
pip install 'pyats[full]' rest.connector
24+
```
25+
26+
# Running
27+
28+
By pyats run job command
29+
```
30+
pyats run job job.py --testbed-file aci_devnet_sandbox.yaml
31+
```
32+
33+
By pyats run genie command (without `job.py`)
34+
```
35+
pyats run genie --testbed-file aci_devnet_sandbox.yaml --trigger-datafile trigger_datafile.yaml --trigger-groups "And('tenant')" --subsection-datafile subsection_datafile.yaml
36+
```
37+
38+
# Try customization in YAML
39+
40+
### Try #1
41+
42+
Above example keeps the filter entry on APIC. So, let's enable `delete` section.
43+
44+
Please uncomment section `delete_filter_entry` in `trigger_datafile.yaml`.
45+
46+
```
47+
- delete_filter_entry:
48+
- api:
49+
device: uut
50+
function: apic_rest_post
51+
arguments:
52+
dn: "/api/node/mo/uni/tn-%{vars.tenant}/flt-%{vars.filter}/e-%{vars.filter_entry}.json"
53+
payload: |
54+
{
55+
"vzEntry": {
56+
"attributes": {
57+
"dn": "uni/tn-%{vars.tenant}/flt-%{vars.filter}/e-%{vars.filter_entry}",
58+
"status": "deleted"
59+
},
60+
"children": []
61+
}
62+
}
63+
include:
64+
- contains_key_value("totalCount", '0')
65+
```
66+
67+
The deletion can be checked on APIC.
68+
69+
70+

aci_filter/aci_devnet_sandbox.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
devices:
2+
APIC:
3+
os: apic
4+
alias: uut
5+
type: apic
6+
connections:
7+
defaults:
8+
via: rest
9+
rest:
10+
class: rest.connector.Rest
11+
host: sandboxapicdc.cisco.com
12+
ip: sandboxapicdc.cisco.com
13+
port: 443
14+
credentials:
15+
rest:
16+
username: admin
17+
password: ciscopsdt

aci_filter/job.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
import time
3+
4+
from pyats import aetest
5+
6+
# Needed for logic
7+
from pyats.datastructures.logic import And, Not, Or
8+
from genie.harness.main import gRun
9+
10+
def main():
11+
test_path = os.path.dirname(os.path.abspath(__file__))
12+
gRun(
13+
trigger_datafile=test_path+'/trigger_datafile.yaml',
14+
subsection_datafile=test_path+'/subsection_datafile.yaml',
15+
trigger_groups=And('filter'),
16+
)

aci_filter/subsection_datafile.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
setup:
2+
sections:
3+
connect:
4+
method: genie.harness.commons.connect
5+
order: ['connect']
6+
7+
cleanup:
8+
order: []

aci_filter/trigger_datafile.yaml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
vars:
2+
tenant: SnV
3+
filter: http
4+
filter_entry: pyats-tcp-443
5+
6+
Create_Filter:
7+
groups: ["filter"]
8+
source:
9+
pkg: genie.libs.sdk
10+
class: triggers.blitz.blitz.Blitz
11+
test_sections:
12+
- check_filter_entry_does_not_exist:
13+
- api:
14+
device: uut
15+
function: apic_rest_get
16+
arguments:
17+
dn: /api/node/class/vzEntry.json
18+
exclude:
19+
- contains('%{vars.filter_entry}')
20+
- check_filter_entry_does_not_exist_in_tenant:
21+
- api:
22+
device: uut
23+
function: apic_rest_get
24+
arguments:
25+
dn: /api/node/mo/uni/tn-%{vars.tenant}/flt-%{vars.filter}.json
26+
query_target: children
27+
exclude:
28+
- contains('%{vars.filter_entry}')
29+
- create_filter_entry_under_tenant:
30+
- api:
31+
device: uut
32+
function: apic_rest_post
33+
arguments:
34+
dn: "/api/node/mo/uni/tn-%{vars.tenant}/flt-%{vars.filter}/e-%{vars.filter_entry}.json"
35+
payload: |
36+
{
37+
"vzEntry": {
38+
"attributes": {
39+
"dn": "uni/tn-%{vars.tenant}/flt-%{vars.filter}/e-%{vars.filter_entry}",
40+
"name": "%{vars.filter_entry}",
41+
"etherT": "ip",
42+
"status": "created,modified",
43+
"prot": "tcp",
44+
"dFromPort": "https",
45+
"dToPort": "https",
46+
"rn": "e-%{vars.filter_entry}"
47+
},
48+
"children":[]
49+
}
50+
}
51+
include:
52+
- contains_key_value("totalCount", '0')
53+
- check_filter_entry_exists:
54+
- api:
55+
device: uut
56+
function: apic_rest_get
57+
arguments:
58+
dn: /api/node/class/vzEntry.json
59+
include:
60+
- contains('%{vars.filter_entry}')
61+
- check_filter_entry_exists_in_tenant:
62+
- api:
63+
device: uut
64+
function: apic_rest_get
65+
arguments:
66+
dn: /api/node/mo/uni/tn-%{vars.tenant}/flt-%{vars.filter}.json
67+
query_target: children
68+
include:
69+
- contains('%{vars.filter_entry}')
70+
# - delete_filter_entry:
71+
# - api:
72+
# device: uut
73+
# function: apic_rest_post
74+
# arguments:
75+
# dn: "/api/node/mo/uni/tn-%{vars.tenant}/flt-%{vars.filter}/e-%{vars.filter_entry}.json"
76+
# payload: |
77+
# {
78+
# "vzEntry": {
79+
# "attributes": {
80+
# "dn": "uni/tn-%{vars.tenant}/flt-%{vars.filter}/e-%{vars.filter_entry}",
81+
# "status": "deleted"
82+
# },
83+
# "children": []
84+
# }
85+
# }
86+
# include:
87+
# - contains_key_value("totalCount", '0')

0 commit comments

Comments
 (0)