SDN Accounts refactoring
[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 logging
19 import unittest
20
21 import rw_peas
22 import rwlogger
23
24 import gi
25 gi.require_version('RwTypes', '1.0')
26 from gi.repository import RwsdnalYang
27 from gi.repository.RwTypes import RwStatus
28
29
30 logger = logging.getLogger('sdnsim')
31
32 def get_sdn_account():
33 """
34 Creates an object for class RwsdnalYang.SdnAccount()
35 """
36 account = RwsdnalYang.SDNAccount()
37 account.account_type = "sdnsim"
38 account.sdnsim.username = "rift"
39 account.sdnsim.plugin_name = "rwsdn_sim"
40 return account
41
42 def get_sdn_plugin():
43 """
44 Loads rw.sdn plugin via libpeas
45 """
46 plugin = rw_peas.PeasPlugin('rwsdn_sim', 'RwSdn-1.0')
47 engine, info, extension = plugin()
48
49 # Get the RwLogger context
50 rwloggerctx = rwlogger.RwLog.Ctx.new("SDN-Log")
51
52 sdn = plugin.get_interface("Topology")
53 try:
54 rc = sdn.init(rwloggerctx)
55 assert rc == RwStatus.SUCCESS
56 except:
57 logger.error("ERROR:SDN sim plugin instantiation failed. Aborting tests")
58 else:
59 logger.info("SDN sim plugin successfully instantiated")
60 return sdn
61
62
63
64 class SdnSimTest(unittest.TestCase):
65 def setUp(self):
66 """
67 Initialize test plugins
68 """
69 self._acct = get_sdn_account()
70 logger.info("SDN-Sim-Test: setUp")
71 self.sdn = get_sdn_plugin()
72 logger.info("SDN-Sim-Test: setUpEND")
73
74 def tearDown(self):
75 logger.info("SDN-Sim-Test: Done with tests")
76
77 def test_get_network_list(self):
78 """
79 First test case
80 """
81 rc, nwtop = self.sdn.get_network_list(self._acct)
82 self.assertEqual(rc, RwStatus.SUCCESS)
83 logger.debug("SDN-Sim-Test: Retrieved network attributes ")
84 for nw in nwtop.network:
85 logger.debug("...Network id %s", nw.network_id)
86 logger.debug("...Network name %s", nw.l2_network_attributes.name)
87
88
89 if __name__ == "__main__":
90 logging.basicConfig(level=logging.DEBUG)
91 unittest.main()
92
93
94
95