3 # Copyright 2016 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 from gi
.repository
import RwsdnalYang
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
34 logger
= logging
.getLogger('mock')
36 def get_sdn_account():
38 Creates an object for class RwsdnalYang.SdnAccount()
40 account
= RwsdnalYang
.SDNAccount()
41 account
.account_type
= "mock"
42 account
.mock
.username
= "rift"
43 account
.mock
.plugin_name
= "rwsdn_mock"
48 Loads rw.sdn plugin via libpeas
50 plugin
= rw_peas
.PeasPlugin('rwsdn_mock', 'RwSdn-1.0')
51 engine
, info
, extension
= plugin()
53 # Get the RwLogger context
54 rwloggerctx
= rwlogger
.RwLog
.Ctx
.new("SDN-Log")
56 sdn
= plugin
.get_interface("Topology")
58 rc
= sdn
.init(rwloggerctx
)
59 assert rc
== RwStatus
.SUCCESS
61 logger
.error("ERROR:SDN plugin instantiation failed. Aborting tests")
63 logger
.info("Mock SDN plugin successfully instantiated")
68 class SdnMockTest(unittest
.TestCase
):
71 Initialize test plugins
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")
79 logger
.info("Mock-SDN-Test: Done with tests")
81 def test_get_network_list(self
):
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
)
95 if __name__
== "__main__":
96 logging
.basicConfig(level
=logging
.DEBUG
)