Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 9c475f8

Browse files
author
Michael Smith
committed
Added setup routines to test suite
1 parent 75b6922 commit 9c475f8

2 files changed

Lines changed: 236 additions & 49 deletions

File tree

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
################################################################################
2+
# _ ____ ___ _____ _ _ _ _ #
3+
# / \ / ___|_ _| |_ _|__ ___ | | | _(_) |_ #
4+
# / _ \| | | | | |/ _ \ / _ \| | |/ / | __| #
5+
# / ___ \ |___ | | | | (_) | (_) | | <| | |_ #
6+
# ____ /_/ \_\____|___|___|_|\___/ \___/|_|_|\_\_|\__| #
7+
# / ___|___ __| | ___ / ___| __ _ _ __ ___ _ __ | | ___ ___ #
8+
# | | / _ \ / _` |/ _ \ \___ \ / _` | '_ ` _ \| '_ \| |/ _ \/ __| #
9+
# | |__| (_) | (_| | __/ ___) | (_| | | | | | | |_) | | __/\__ \ #
10+
# \____\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|\___||___/ #
11+
# |_| #
12+
################################################################################
13+
# #
14+
# Copyright (c) 2015 Cisco Systems #
15+
# All Rights Reserved. #
16+
# #
17+
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
18+
# not use this file except in compliance with the License. You may obtain #
19+
# a copy of the License at #
20+
# #
21+
# http://www.apache.org/licenses/LICENSE-2.0 #
22+
# #
23+
# Unless required by applicable law or agreed to in writing, software #
24+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
25+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #
26+
# License for the specific language governing permissions and limitations #
27+
# under the License. #
28+
# #
29+
################################################################################
30+
"""
31+
Configure the fabric to run the multisite test suite
32+
"""
33+
from acitoolkit.acitoolkit import *
34+
import argparse
35+
import json
36+
from multisite_credentials import *
37+
38+
39+
def setup_multisite_test(printonly=False, delete=False):
40+
# Create the Tenant
41+
tenant1 = Tenant('multisite')
42+
43+
# Create the Application Profile
44+
app = AppProfile('my-demo-app', tenant1)
45+
46+
# Create the EPGs
47+
web_epg = EPG('web-frontend', app)
48+
db_epg = EPG('database-backend', app)
49+
50+
# Create a Context and BridgeDomain
51+
# Place both EPGs in the Context and in the same BD
52+
context = Context('VRF-1', tenant1)
53+
bd = BridgeDomain('BD-1', tenant1)
54+
bd.add_context(context)
55+
web_epg.add_bd(bd)
56+
db_epg.add_bd(bd)
57+
58+
# Define a contract with a single entry
59+
contract = Contract('mysql-contract', tenant1)
60+
entry1 = FilterEntry('entry1',
61+
applyToFrag='no',
62+
arpOpc='unspecified',
63+
dFromPort='3306',
64+
dToPort='3306',
65+
etherT='ip',
66+
prot='tcp',
67+
sFromPort='1',
68+
sToPort='65535',
69+
tcpRules='unspecified',
70+
parent=contract)
71+
72+
# Provide the contract from 1 EPG and consume from the other
73+
db_epg.provide(contract)
74+
web_epg.consume(contract)
75+
76+
context = Context('ctx0', tenant1)
77+
#contract = Contract('contract', tenant)
78+
phyif = Interface('eth', '1', '102', '1', '25')
79+
l2if = L2Interface('eth 1/102/1/25', 'vlan', '500')
80+
l2if.attach(phyif)
81+
l3if = L3Interface('l3if')
82+
l3if.set_l3if_type('ext-svi')
83+
l3if.set_addr('20.0.0.1/16')
84+
l3if.add_context(context)
85+
l3if.attach(l2if)
86+
87+
#l3if.networks.append('1.1.1.1/32')
88+
#outside.provide(contract)
89+
l3if.attach(l2if)
90+
rtr = OSPFRouter('rtr-1')
91+
rtr.set_router_id('101.101.101.101')
92+
rtr.set_node_id('102')
93+
# net1 = OutsideNetwork('1.1.1.1/32')
94+
# net1.network = '1.1.1.1/32'
95+
# net1.provide(contract)
96+
ospfif = OSPFInterface('ospfif-1', router=rtr, area_id='0.0.0.1')
97+
ospfif.attach(l3if)
98+
# ospfif.networks.append(net1)
99+
outside = OutsideEPG('multisite-l3out', tenant1)
100+
outside.attach(ospfif)
101+
#outside.add_context(context)
102+
103+
# Create the Tenant
104+
tenant2 = Tenant('multisite')
105+
106+
# Create the Application Profile
107+
app = AppProfile('my-demo-app', tenant2)
108+
109+
# Create the EPGs
110+
web_epg = EPG('web-frontend', app)
111+
112+
# Create a Context and BridgeDomain
113+
# Place both EPGs in the Context and in the same BD
114+
context = Context('VRF-1', tenant2)
115+
bd = BridgeDomain('BD-1', tenant2)
116+
bd.add_context(context)
117+
web_epg.add_bd(bd)
118+
119+
context = Context('ctx0', tenant2)
120+
#contract = Contract('contract', tenant)
121+
phyif = Interface('eth', '1', '102', '1', '25')
122+
l2if = L2Interface('eth 1/102/1/25', 'vlan', '500')
123+
l2if.attach(phyif)
124+
l3if = L3Interface('l3if')
125+
l3if.set_l3if_type('ext-svi')
126+
l3if.set_addr('20.0.0.2/16')
127+
l3if.add_context(context)
128+
l3if.attach(l2if)
129+
#outside.provide(contract)
130+
l3if.attach(l2if)
131+
rtr = OSPFRouter('rtr-1')
132+
rtr.set_router_id('102.102.102.102')
133+
rtr.set_node_id('102')
134+
ospfif = OSPFInterface('ospfif-1', router=rtr, area_id='0.0.0.1')
135+
ospfif.attach(l3if)
136+
#ospfif.networks.append('1.1.1.1/32')
137+
#ospfif.networks.append('1.1.1.2/32')
138+
outside = OutsideEPG('multisite-l3out', tenant2)
139+
outside.attach(ospfif)
140+
141+
if not printonly:
142+
# Login to APIC and push the config
143+
session = Session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
144+
session.login()
145+
# Cleanup (uncomment the next line to delete the config)
146+
if delete:
147+
print 'Deleting...'
148+
tenant1.mark_as_deleted()
149+
resp = tenant1.push_to_apic(session)
150+
if resp.ok:
151+
# Print what was sent
152+
print('Pushed the following JSON to the APIC', resp.text)
153+
else:
154+
print resp, resp.text
155+
print('URL: ' + str(tenant1.get_url()))
156+
print('JSON:')
157+
print json.dumps(tenant1.get_json(), indent=4, separators=(',',':'))
158+
159+
160+
if not printonly:
161+
# Login to APIC and push the config
162+
session = Session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)
163+
session.login()
164+
# Cleanup (uncomment the next line to delete the config)
165+
if delete:
166+
tenant2.mark_as_deleted()
167+
resp = tenant2.push_to_apic(session)
168+
if resp.ok:
169+
# Print what was sent
170+
print('Pushed the following JSON to the APIC', resp.text)
171+
else:
172+
print resp, resp.text
173+
print('URL: ' + str(tenant2.get_url()))
174+
print('JSON:')
175+
print json.dumps(tenant2.get_json(), indent=4, separators=(',',':'))
176+
177+
if __name__ == '__main__':
178+
try:
179+
parser = argparse.ArgumentParser(description='')
180+
parser.add_argument('--delete', action='store_true')
181+
parser.add_argument('--printonly', action='store_true')
182+
args = parser.parse_args()
183+
setup_multisite_test(printonly=args.printonly, delete=args.delete)
184+
except KeyboardInterrupt:
185+
pass

applications/multisite/multisite_test.py

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import unittest
77
import os
88
import sys
9-
9+
from aci_multisite_config_test import setup_multisite_test
1010
try:
1111
from multisite_credentials import *
1212
except ImportError:
@@ -59,15 +59,11 @@ def setup_site(self, url, site1_local=True):
5959
driver.get(url)
6060
assert 'ACI Multisite' in driver.title
6161

62-
6362
driver.find_element_by_link_text('Site Credentials').click()
6463
assert 'Site Credentials' in driver.title
6564

66-
6765
driver.find_element_by_link_text('Create').click()
6866

69-
70-
7167
# Enter the Site 1 credentials
7268
typing = [('site_name', 'Site1'),
7369
('ip_address', SITE1_IP),
@@ -80,14 +76,10 @@ def setup_site(self, url, site1_local=True):
8076
input_elem = driver.find_element_by_id('local')
8177
input_elem.click()
8278

83-
84-
8579
# Save the credentials
8680
input_elem = driver.find_element_by_name('_add_another')
8781
input_elem.click()
8882

89-
90-
9183
# Enter the Site 2 credentials
9284
typing = [('site_name', 'Site2'),
9385
('ip_address', SITE2_IP),
@@ -100,14 +92,10 @@ def setup_site(self, url, site1_local=True):
10092
input_elem = driver.find_element_by_id('local')
10193
input_elem.click()
10294

103-
104-
10595
# Save the credentials
10696
input_elem = driver.find_element_by_name('_add_another')
10797
input_elem.click()
10898

109-
110-
11199
# Finished, click Cancel
112100
input_elem = driver.find_element_by_link_text('Cancel')
113101
input_elem.click()
@@ -122,8 +110,8 @@ def test_02_site2(self):
122110

123111
def test_03_export_contract(self):
124112
driver = self.__class__.driver
125-
# Switch to the second site tool
126-
driver.get('http://127.0.0.1:5001')
113+
# Switch to the site 1 tool
114+
driver.get('http://127.0.0.1:5000')
127115

128116
# Click on Site Contracts
129117
driver.find_element_by_link_text('Site Contracts').click()
@@ -145,19 +133,18 @@ def test_03_export_contract(self):
145133
# Export the contract
146134
driver.find_element_by_id('submit').click()
147135

136+
time.sleep(1)
148137
# Verify that the export to the other APIC was successful
149-
session = Session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
138+
session = Session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)
150139
resp = session.login()
151140
self.assertTrue(resp.ok)
152141
tenants = Tenant.get_deep(session, names=['multisite'], limit_to=['fvTenant', 'vzBrCP'])
153142
self.assertTrue(len(tenants) > 0)
154143
multisite_tenant = tenants[0]
155-
self.assertIsNotNone(multisite_tenant.get_child(Contract, 'Site2:mysql-contract'))
144+
self.assertIsNotNone(multisite_tenant.get_child(Contract, 'Site1:mysql-contract'))
156145

157146
def test_04_consume_exported_contract(self):
158-
time.sleep(1)
159-
160-
session = Session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
147+
session = Session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)
161148
resp = session.login()
162149
self.assertTrue(resp.ok)
163150

@@ -167,7 +154,7 @@ def test_04_consume_exported_contract(self):
167154
app = AppProfile('my-demo-app', tenant)
168155
# Create the EPGs
169156
web_epg = EPG('web-frontend', app)
170-
contract = Contract('Site2:mysql-contract', tenant)
157+
contract = Contract('Site1:mysql-contract', tenant)
171158
web_epg.consume(contract)
172159
tenant.push_to_apic(session)
173160

@@ -180,12 +167,12 @@ def test_04_consume_exported_contract(self):
180167
self.assertIsNotNone(app)
181168
epg = app.get_child(EPG, 'web-frontend')
182169
self.assertIsNotNone(epg)
183-
contract = multisite_tenant.get_child(Contract, 'Site2:mysql-contract')
170+
contract = multisite_tenant.get_child(Contract, 'Site1:mysql-contract')
184171
self.assertIsNotNone(contract)
185172
self.assertTrue(epg.does_consume(contract))
186173

187174
def test_05_add_consuming_static_endpoint(self):
188-
session = Session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
175+
session = Session(SITE2_URL, SITE2_LOGIN, SITE2_PASSWORD)
189176
resp = session.login()
190177
self.assertTrue(resp.ok)
191178

@@ -220,39 +207,52 @@ def test_05_add_consuming_static_endpoint(self):
220207
ep = epg.get_child(Endpoint, '00:33:33:33:33:33')
221208
self.assertIsNotNone(ep)
222209

223-
@classmethod
224-
def tearDownClass(cls):
225-
driver = cls.driver
226-
driver.get('http://127.0.0.1:5000/shutdown')
227-
driver.get('http://127.0.0.1:5001/shutdown')
228-
driver.close()
210+
def test_06_add_providing_static_endpoint(self):
211+
session = Session(SITE1_URL, SITE1_LOGIN, SITE1_PASSWORD)
212+
resp = session.login()
213+
self.assertTrue(resp.ok)
229214

215+
tenant = Tenant('multisite')
216+
app = AppProfile('my-demo-app', tenant)
217+
web_epg = EPG('database-backend', app)
230218

219+
# Create the Endpoint
220+
ep = Endpoint('00:44:44:44:44:44', web_epg)
221+
ep.mac = '00:44:44:44:44:44'
222+
ep.ip = '7.8.9.10'
231223

224+
intf = Interface('eth', '1', '101', '1', '38')
225+
# Create a VLAN interface and attach to the physical interface
226+
vlan_intf = L2Interface('vlan-5', 'vlan', '5')
227+
vlan_intf.attach(intf)
228+
# Attach the EPG to the VLAN interface
229+
web_epg.attach(vlan_intf)
230+
# Assign Endpoint to the L2Interface
231+
ep.attach(vlan_intf)
232232

233-
def test_add_providing_static_endpoint(session):
234-
tenant = Tenant('multisite')
235-
app = AppProfile('my-demo-app', tenant)
236-
web_epg = EPG('database-backend', app)
233+
print 'Pushing json to tenant', tenant.get_json()
234+
resp = tenant.push_to_apic(session)
235+
if not resp.ok:
236+
print resp, resp.text
237237

238-
# Create the Endpoint
239-
ep = Endpoint('00:44:44:44:44:44', web_epg)
240-
ep.mac = '00:44:44:44:44:44'
241-
ep.ip = '7.8.9.10'
238+
time.sleep(1)
239+
# Verify that the Endpoint was pushed successfully
240+
tenants = Tenant.get_deep(session, names=['multisite'])
241+
multisite_tenant = tenants[0]
242+
app = multisite_tenant.get_child(AppProfile, 'my-demo-app')
243+
self.assertIsNotNone(app)
244+
epg = app.get_child(EPG, 'database-backend')
245+
self.assertIsNotNone(epg)
246+
ep = epg.get_child(Endpoint, '00:44:44:44:44:44')
247+
self.assertIsNotNone(ep)
242248

243-
intf = Interface('eth', '1', '101', '1', '38')
244-
# Create a VLAN interface and attach to the physical interface
245-
vlan_intf = L2Interface('vlan-5', 'vlan', '5')
246-
vlan_intf.attach(intf)
247-
# Attach the EPG to the VLAN interface
248-
web_epg.attach(vlan_intf)
249-
# Assign Endpoint to the L2Interface
250-
ep.attach(vlan_intf)
249+
@classmethod
250+
def tearDownClass(cls):
251+
driver = cls.driver
252+
driver.get('http://127.0.0.1:5000/shutdown')
253+
driver.get('http://127.0.0.1:5001/shutdown')
254+
driver.close()
251255

252-
print 'Pushing json to tenant', tenant.get_json()
253-
resp = tenant.push_to_apic(session)
254-
if not resp.ok:
255-
print resp, resp.text
256256

257257
def verify_remote_l3extsubnet(session, mac):
258258
class_query_url = ('/api/mo/uni/tn-multisite/out-multisite-l3out.json?'
@@ -279,6 +279,8 @@ def verify_remote_l3extsubnet(session, mac):
279279
#
280280
# time.sleep(2)
281281

282+
setup_multisite_test(delete=True)
283+
setup_multisite_test()
282284
live = unittest.TestSuite()
283285
live.addTest(unittest.makeSuite(TestBasicExport))
284286
unittest.main(defaultTest='live')

0 commit comments

Comments
 (0)