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 gi
.require_version('RwTypes', '1.0')
26 from gi
.repository
import RwsdnalYang
27 from gi
.repository
.RwTypes
import RwStatus
30 logger
= logging
.getLogger('sdnsim')
32 def get_sdn_account():
34 Creates an object for class RwsdnalYang.YangData_RwProject_Project_SdnAccounts_SdnAccountList()
36 account
= RwsdnalYang
.YangData_RwProject_Project_SdnAccounts_SdnAccountList()
37 account
.account_type
= "sdnsim"
38 account
.sdnsim
.username
= "rift"
39 account
.sdnsim
.plugin_name
= "rwsdn_sim"
44 Loads rw.sdn plugin via libpeas
46 plugin
= rw_peas
.PeasPlugin('rwsdn_sim', 'RwSdn-1.0')
47 engine
, info
, extension
= plugin()
49 # Get the RwLogger context
50 rwloggerctx
= rwlogger
.RwLog
.Ctx
.new("SDN-Log")
52 sdn
= plugin
.get_interface("Topology")
54 rc
= sdn
.init(rwloggerctx
)
55 assert rc
== RwStatus
.SUCCESS
57 logger
.error("ERROR:SDN sim plugin instantiation failed. Aborting tests")
59 logger
.info("SDN sim plugin successfully instantiated")
64 class SdnSimTest(unittest
.TestCase
):
67 Initialize test plugins
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")
75 logger
.info("SDN-Sim-Test: Done with tests")
77 def test_get_network_list(self
):
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
)
89 if __name__
== "__main__":
90 logging
.basicConfig(level
=logging
.DEBUG
)