Skip to content

Commit 0a44990

Browse files
authored
Merge pull request #6 from tahigash/tahigash_aci_sample
Tahigash aci sample
2 parents ec91524 + bde106b commit 0a44990

File tree

5 files changed

+196
-0
lines changed

5 files changed

+196
-0
lines changed

aci_tenant/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Overview
2+
3+
Connect to API via Rest Connecor, and create tenant, check the tenant and delete the tenant. This will check if the tenant 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 Tenant doesn't exist
12+
2. Create Tenant
13+
3. Check Tenant exist
14+
4. Delete Tenant
15+
5. Check Tenant was deleted
16+
17+
# Preparation
18+
19+
Install pyATS|Genie and Rest Connector.
20+
21+
```
22+
pip install 'pyats[full]' rest.connector
23+
```
24+
25+
# Running
26+
27+
By pyats run job command
28+
```
29+
pyats run job job.py --testbed-file aci_devnet_sandbox.yaml
30+
```
31+
32+
By pyats run genie command (without `job.py`)
33+
```
34+
pyats run genie --testbed-file aci_devnet_sandbox.yaml --trigger-datafile trigger_datafile.yaml --trigger-groups "And('tenant')" --subsection-datafile subsection_datafile.yaml
35+
```
36+
37+
# Try customization in YAML
38+
39+
### Try #1
40+
As quick customize, change `tenant` name under `vars` at top of `trigger_datafile.yaml`.
41+
42+
```
43+
vars:
44+
tenant: new_tenant_by_pyATS
45+
(snip)
46+
```
47+
### Try #2
48+
49+
Comment whole step4(`delete_tenant`).
50+
51+
```
52+
(snip)
53+
- contains('.*%{vars.tenant}.*', regex=True)
54+
# - delete_tenant:
55+
# - api:
56+
# device: uut
57+
# function: apic_rest_post
58+
# arguments:
59+
# dn: "/api/node/mo/uni/tn-%{vars.tenant}.json"
60+
# payload: |
61+
# {
62+
# "fvTenant": {
63+
# "attributes": {
64+
# "dn": "uni/tn-%{vars.tenant}",
65+
# "status": "deleted"
66+
# },
67+
# "children": []
68+
# }
69+
# }
70+
# include:
71+
# - contains_key_value("totalCount", '0')
72+
- check_tenant_was_deleted:
73+
(snip)
74+
```
75+
76+
`check_tenant_was_deleted` step will be failed. but it's fine since we didn't delete. So, it's expected.
77+
78+
Go to https://sandboxapicdc.cisco.com (Check username/password from `aci_devnet_sandbox.yaml`).
79+
80+
After login to APIC, click `Tenants` tab. And then the created tenant should be there.
81+
82+
83+
84+
85+

aci_tenant/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_tenant/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('tenant'),
16+
)

aci_tenant/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_tenant/trigger_datafile.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
vars:
2+
tenant: pyATS_awesome
3+
4+
Create_Tenant:
5+
groups: ["tenant"]
6+
source:
7+
pkg: genie.libs.sdk
8+
class: triggers.blitz.blitz.Blitz
9+
test_sections:
10+
- check_tenant_does_not_exist:
11+
- api:
12+
device: uut
13+
function: apic_rest_get
14+
arguments:
15+
dn: /api/node/class/fvTenant.json
16+
exclude:
17+
- contains('.*%{vars.tenant}.*', regex=True)
18+
- create_tenant:
19+
- api:
20+
device: uut
21+
function: apic_rest_post
22+
arguments:
23+
dn: "/api/node/mo/uni/tn-%{vars.tenant}.json"
24+
payload: |
25+
{
26+
"fvTenant": {
27+
"attributes": {
28+
"descr": "Tenant Created Using pyATS",
29+
"dn": "uni/tn-%{vars.tenant}"
30+
"name": "%{vars.tenant}",
31+
"rn": "%{vars.tenant}",
32+
"status": "created"
33+
},
34+
"children": []
35+
}
36+
}
37+
- check_tenant_exists:
38+
- api:
39+
device: uut
40+
function: apic_rest_get
41+
arguments:
42+
dn: /api/node/class/fvTenant.json
43+
include:
44+
- contains('.*%{vars.tenant}.*', regex=True)
45+
- delete_tenant:
46+
- api:
47+
device: uut
48+
function: apic_rest_post
49+
arguments:
50+
dn: "/api/node/mo/uni/tn-%{vars.tenant}.json"
51+
payload: |
52+
{
53+
"fvTenant": {
54+
"attributes": {
55+
"dn": "uni/tn-%{vars.tenant}",
56+
"status": "deleted"
57+
},
58+
"children": []
59+
}
60+
}
61+
include:
62+
- contains_key_value("totalCount", '0')
63+
- check_tenant_was_deleted:
64+
- api:
65+
device: uut
66+
function: apic_rest_get
67+
arguments:
68+
dn: /api/node/class/fvTenant.json
69+
exclude:
70+
- contains('.*%{vars.tenant}.*', regex=True)

0 commit comments

Comments
 (0)