d216f0d10cdca2063dbaee01ef8143381a155875
[osm/SO.git] / rwlaunchpad / plugins / rwvns / test / test_sdn_sim.py
1
2 #
3 # Copyright 2016 RIFT.IO Inc
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 import datetime
19 import logging
20 import unittest
21
22 import rw_peas
23 import rwlogger
24
25 import gi
26 gi.require_version('RwTypes', '1.0')
27 gi.require_version('RwSdn', '1.0')
28 from gi.repository import RwsdnYang
29 from gi.repository import IetfNetworkYang
30 from gi.repository.RwTypes import RwStatus
31 from gi.repository import RwSdn
32
33
34 logger = logging.getLogger('sdnsim')
35
36 def get_sdn_account():
37 """
38 Creates an object for class RwsdnYang.SdnAccount()
39 """
40 account = RwsdnYang.SDNAccount()
41 account.account_type = "sdnsim"
42 account.sdnsim.username = "rift"
43 account.sdnsim.plugin_name = "rwsdn_sim"
44 return account
45
46 def get_sdn_plugin():
47 """
48 Loads rw.sdn plugin via libpeas
49 """
50 plugin = rw_peas.PeasPlugin('rwsdn_sim', 'RwSdn-1.0')
51 engine, info, extension = plugin()
52
53 # Get the RwLogger context
54 rwloggerctx = rwlogger.RwLog.Ctx.new("SDN-Log")
55
56 sdn = plugin.get_interface("Topology")
57 try:
58 rc = sdn.init(rwloggerctx)
59 assert rc == RwStatus.SUCCESS
60 except:
61 logger.error("ERROR:SDN sim plugin instantiation failed. Aborting tests")
62 else:
63 logger.info("SDN sim plugin successfully instantiated")
64 return sdn
65
66
67
68 class SdnSimTest(unittest.TestCase):
69 def setUp(self):
70 """
71 Initialize test plugins
72 """
73 self._acct = get_sdn_account()
74 logger.info("SDN-Sim-Test: setUp")
75 self.sdn = get_sdn_plugin()
76 logger.info("SDN-Sim-Test: setUpEND")
77
78 def tearDown(self):
79 logger.info("SDN-Sim-Test: Done with tests")
80
81 def test_get_network_list(self):
82 """
83 First test case
84 """
85 rc, nwtop = self.sdn.get_network_list(self._acct)
86 self.assertEqual(rc, RwStatus.SUCCESS)
87 logger.debug("SDN-Sim-Test: Retrieved network attributes ")
88 for nw in nwtop.network:
89 logger.debug("...Network id %s", nw.network_id)
90 logger.debug("...Network name %s", nw.l2_network_attributes.name)
91
92
93 if __name__ == "__main__":
94 logging.basicConfig(level=logging.DEBUG)
95 unittest.main()
96
97
98
99