3 # Copyright 2017 RIFT.IO Inc
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
25 gi
.require_version('RwTypes', '1.0')
26 from gi
.repository
import RwsdnalYang
27 from gi
.repository
.RwTypes
import RwStatus
30 logger
= logging
.getLogger('sdnodl')
35 'url' : 'http://10.66.4.27:8181',
39 def get_sdn_account():
41 Creates an object for class RwsdnalYang.SdnAccount()
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']
55 Loads rw.sdn plugin via libpeas
57 plugin
= rw_peas
.PeasPlugin('rwsdn_odl', 'RwSdn-1.0')
58 engine
, info
, extension
= plugin()
60 # Get the RwLogger context
61 rwloggerctx
= rwlogger
.RwLog
.Ctx
.new("SDN-Log")
63 sdn
= plugin
.get_interface("Topology")
65 rc
= sdn
.init(rwloggerctx
)
66 assert rc
== RwStatus
.SUCCESS
68 logger
.error("ERROR:SDN ODL plugin instantiation failed. Aborting tests")
70 logger
.info("SDN ODL plugin successfully instantiated")
75 class SdnOdlTest(unittest
.TestCase
):
78 Initialize test plugins
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")
86 logger
.info("SDN-Odl-Test: Done with tests")
88 def test_validate_sdn_creds(self
):
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")
98 def test_get_network_list(self
):
100 Get-network-list test case
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")
110 if __name__
== "__main__":
111 logging
.basicConfig(level
=logging
.DEBUG
)