SDN Accounts refactoring
[osm/SO.git] / rwlaunchpad / plugins / rwvns / test / test_sdn_odl.py
1
2 #
3 # Copyright 2017 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('sdnodl')
31
32 odl_info = {
33 'username' : 'admin',
34 'password' : 'admin',
35 'url' : 'http://10.66.4.27:8181',
36 }
37
38
39 def get_sdn_account():
40 """
41 Creates an object for class RwsdnalYang.SdnAccount()
42 """
43 account = RwsdnalYang.SDNAccount()
44 account.name = "grunt27"
45 account.account_type = "odl"
46 account.odl.plugin_name = "rwsdn_odl"
47 account.odl.username = odl_info['username']
48 account.odl.password = odl_info['password']
49 account.odl.url = odl_info['url']
50
51 return account
52
53 def get_sdn_plugin():
54 """
55 Loads rw.sdn plugin via libpeas
56 """
57 plugin = rw_peas.PeasPlugin('rwsdn_odl', 'RwSdn-1.0')
58 engine, info, extension = plugin()
59
60 # Get the RwLogger context
61 rwloggerctx = rwlogger.RwLog.Ctx.new("SDN-Log")
62
63 sdn = plugin.get_interface("Topology")
64 try:
65 rc = sdn.init(rwloggerctx)
66 assert rc == RwStatus.SUCCESS
67 except:
68 logger.error("ERROR:SDN ODL plugin instantiation failed. Aborting tests")
69 else:
70 logger.info("SDN ODL plugin successfully instantiated")
71 return sdn
72
73
74
75 class SdnOdlTest(unittest.TestCase):
76 def setUp(self):
77 """
78 Initialize test plugins
79 """
80 self._acct = get_sdn_account()
81 logger.info("SDN-Odl-Test: setUp")
82 self.sdn = get_sdn_plugin()
83 logger.info("SDN-Odl-Test: setUpEND")
84
85 def tearDown(self):
86 logger.info("SDN-Odl-Test: Done with tests")
87
88 def test_validate_sdn_creds(self):
89 """
90 First test case
91 """
92 logger.debug("SDN-Odl-Test: Starting validate creds ")
93 rc, status = self.sdn.validate_sdn_creds(self._acct)
94 logger.debug("SDN-Odl-Test: SDN return code %s resp %s", rc, status)
95 self.assertEqual(rc, RwStatus.SUCCESS)
96 logger.info("SDN-Odl-Test: Passed validate creds")
97
98 def test_get_network_list(self):
99 """
100 Get-network-list test case
101 """
102 logger.debug("SDN-Odl-Test: Getting network list ")
103 rc, status = self.sdn.get_network_list(self._acct)
104 logger.debug("SDN-Odl-Test: SDN return code %s resp %s", rc, status)
105 self.assertEqual(rc, RwStatus.SUCCESS)
106 logger.info("SDN-Odl-Test: Passed get network list")
107
108
109
110 if __name__ == "__main__":
111 logging.basicConfig(level=logging.DEBUG)
112 unittest.main()
113
114
115
116