update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / rwlaunchpad / plugins / rwvns / test / test_sdn_mock.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 from gi.repository import RwsdnalYang
26 import gi
27 gi.require_version('RwTypes', '1.0')
28 gi.require_version('RwSdnal', '1.0')
29 from gi.repository import RwcalYang
30 from gi.repository import IetfNetworkYang
31 from gi.repository.RwTypes import RwStatus
32
33
34 logger = logging.getLogger('mock')
35
36 def get_sdn_account():
37 """
38 Creates an object for class RwsdnalYang.YangData_RwProject_Project_SdnAccounts_SdnAccountList()
39 """
40 account = RwsdnalYang.YangData_RwProject_Project_SdnAccounts_SdnAccountList()
41 account.account_type = "mock"
42 account.mock.username = "rift"
43 account.mock.plugin_name = "rwsdn_mock"
44 return account
45
46 def get_sdn_plugin():
47 """
48 Loads rw.sdn plugin via libpeas
49 """
50 plugin = rw_peas.PeasPlugin('rwsdn_mock', '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 plugin instantiation failed. Aborting tests")
62 else:
63 logger.info("Mock SDN plugin successfully instantiated")
64 return sdn
65
66
67
68 class SdnMockTest(unittest.TestCase):
69 def setUp(self):
70 """
71 Initialize test plugins
72 """
73 self._acct = get_sdn_account()
74 logger.info("Mock-SDN-Test: setUp")
75 self.sdn = get_sdn_plugin()
76 logger.info("Mock-SDN-Test: setUpEND")
77
78 def tearDown(self):
79 logger.info("Mock-SDN-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-Mock-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 print(nw)
92
93
94
95 if __name__ == "__main__":
96 logging.basicConfig(level=logging.DEBUG)
97 unittest.main()
98
99
100
101