44e2f5c33b693d2ba898c59c307488905f50f57f
[osm/SO.git] / rwlaunchpad / plugins / rwvns / test / topmgr_module_test.py
1 #!/usr/bin/env python3
2
3 #
4 # Copyright 2016 RIFT.IO Inc
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18
19
20 import asyncio
21 import logging
22 import os
23 import sys
24 import types
25 import unittest
26 import uuid
27 import random
28
29 import xmlrunner
30
31 import gi
32 gi.require_version('CF', '1.0')
33 gi.require_version('RwDts', '1.0')
34 gi.require_version('RwMain', '1.0')
35 gi.require_version('RwManifestYang', '1.0')
36 gi.require_version('RwLaunchpadYang', '1.0')
37 gi.require_version('RwcalYang', '1.0')
38 gi.require_version('RwTypes', '1.0')
39 import gi.repository.CF as cf
40 import gi.repository.RwDts as rwdts
41 import gi.repository.RwMain as rwmain
42 import gi.repository.RwManifestYang as rwmanifest
43 import gi.repository.IetfL2TopologyYang as l2Tl
44 import gi.repository.RwTopologyYang as RwTl
45 import gi.repository.RwLaunchpadYang as launchpadyang
46 from gi.repository import RwsdnYang
47 from gi.repository.RwTypes import RwStatus
48
49 from create_stackedl2topology import MyL2Topology
50 from create_stackedProvNettopology import MyProvTopology
51 from create_stackedVMNettopology import MyVMTopology
52 from create_stackedSfctopology import MySfcTopology
53
54 import rw_peas
55 import rift.tasklets
56 import rift.test.dts
57
58 if sys.version_info < (3, 4, 4):
59 asyncio.ensure_future = asyncio.async
60
61
62 class TopMgrTestCase(rift.test.dts.AbstractDTSTest):
63
64 @classmethod
65 def configure_suite(cls, rwmain):
66 vns_mgr_dir = os.environ.get('VNS_MGR_DIR')
67
68 cls.rwmain.add_tasklet(vns_mgr_dir, 'rwvnstasklet')
69
70 @classmethod
71 def configure_schema(cls):
72 return RwTl.get_schema()
73
74 @asyncio.coroutine
75 def wait_tasklets(self):
76 yield from asyncio.sleep(1, loop=self.loop)
77
78 @classmethod
79 def configure_timeout(cls):
80 return 360
81
82
83 @asyncio.coroutine
84 def configure_l2_network(self, dts):
85 nwtop = RwTl.YangData_IetfNetwork()
86 l2top = MyL2Topology(nwtop, self.log)
87 l2top.setup_all()
88 nw_xpath = "C,/nd:network"
89 self.log.info("Configuring l2 network: %s",nwtop)
90 yield from dts.query_create(nw_xpath,
91 rwdts.XactFlag.ADVISE,
92 nwtop)
93
94 @asyncio.coroutine
95 def configure_prov_network(self, dts):
96 nwtop = RwTl.YangData_IetfNetwork()
97 l2top = MyL2Topology(nwtop, self.log)
98 l2top.setup_all()
99
100 provtop = MyProvTopology(nwtop, l2top, self.log)
101 provtop.setup_all()
102 nw_xpath = "C,/nd:network"
103 self.log.info("Configuring provider network: %s",nwtop)
104 yield from dts.query_create(nw_xpath,
105 rwdts.XactFlag.ADVISE,
106 nwtop)
107
108 @asyncio.coroutine
109 def configure_vm_network(self, dts):
110 nwtop = RwTl.YangData_IetfNetwork()
111 l2top = MyL2Topology(nwtop, self.log)
112 l2top.setup_all()
113
114 provtop = MyProvTopology(nwtop, l2top, self.log)
115 provtop.setup_all()
116
117 vmtop = MyVMTopology(nwtop, l2top, provtop, self.log)
118 vmtop.setup_all()
119 nw_xpath = "C,/nd:network"
120 self.log.info("Configuring VM network: %s",nwtop)
121 yield from dts.query_create(nw_xpath,
122 rwdts.XactFlag.ADVISE,
123 nwtop)
124
125 @asyncio.coroutine
126 def configure_sfc_network(self, dts):
127 nwtop = RwTl.YangData_IetfNetwork()
128 l2top = MyL2Topology(nwtop, self.log)
129 l2top.setup_all()
130
131 provtop = MyProvTopology(nwtop, l2top, self.log)
132 provtop.setup_all()
133
134 vmtop = MyVMTopology(nwtop, l2top, provtop, self.log)
135 vmtop.setup_all()
136
137 sfctop = MySfcTopology(nwtop, l2top, provtop, vmtop, self.log)
138 sfctop.setup_all()
139
140 nw_xpath = "C,/nd:network"
141 self.log.info("Configuring SFC network: %s",nwtop)
142 yield from dts.query_create(nw_xpath,
143 rwdts.XactFlag.ADVISE,
144 nwtop)
145
146
147 #@unittest.skip("Skipping test_network_config")
148 def test_network_config(self):
149 self.log.debug("STARTING - test_network_config")
150 tinfo = self.new_tinfo('static_network')
151 dts = rift.tasklets.DTS(tinfo, self.schema, self.loop)
152
153 @asyncio.coroutine
154 def run_test():
155 networks = []
156 computes = []
157
158 yield from asyncio.sleep(120, loop=self.loop)
159 yield from self.configure_l2_network(dts)
160 yield from self.configure_prov_network(dts)
161 yield from self.configure_vm_network(dts)
162 yield from self.configure_sfc_network(dts)
163
164 future = asyncio.ensure_future(run_test(), loop=self.loop)
165 self.run_until(future.done)
166 if future.exception() is not None:
167 self.log.error("Caught exception during test")
168 raise future.exception()
169
170 self.log.debug("DONE - test_network_config")
171
172 def main():
173 plugin_dir = os.path.join(os.environ["RIFT_INSTALL"], "usr/lib/rift/plugins")
174
175 if 'VNS_MGR_DIR' not in os.environ:
176 os.environ['VNS_MGR_DIR'] = os.path.join(plugin_dir, 'rwvns')
177
178 if 'MESSAGE_BROKER_DIR' not in os.environ:
179 os.environ['MESSAGE_BROKER_DIR'] = os.path.join(plugin_dir, 'rwmsgbroker-c')
180
181 if 'ROUTER_DIR' not in os.environ:
182 os.environ['ROUTER_DIR'] = os.path.join(plugin_dir, 'rwdtsrouter-c')
183
184 runner = xmlrunner.XMLTestRunner(output=os.environ["RIFT_MODULE_TEST"])
185 unittest.main(testRunner=runner)
186
187 if __name__ == '__main__':
188 main()
189