SDN Accounts refactoring
[osm/SO.git] / rwlaunchpad / plugins / rwvns / test / test_sdn_openstack.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('sdnopenstack')
31
32 openstack_info = {
33 'username' : 'pluto',
34 'password' : 'mypasswd',
35 'auth_url' : 'http://10.66.4.17:5000/v2.0/',
36 'project_name' : 'demo',
37 'user_domain_name' : 'default',
38 'project_domain_name': 'default'
39 }
40
41
42 def get_sdn_account():
43 """
44 Creates an object for class RwsdnalYang.SdnAccount()
45 """
46 account = RwsdnalYang.SDNAccount()
47 account.name = "grunt17"
48 account.account_type = "openstack"
49 account.openstack.plugin_name = "rwsdn_openstack"
50 account.openstack.key = openstack_info['username']
51 account.openstack.secret = openstack_info['password']
52 account.openstack.auth_url = openstack_info['auth_url']
53 account.openstack.tenant = openstack_info['project_name']
54 account.openstack.user_domain = openstack_info['user_domain_name']
55 account.openstack.project_domain = openstack_info['project_domain_name']
56
57 return account
58
59 def get_sdn_plugin():
60 """
61 Loads rw.sdn plugin via libpeas
62 """
63 plugin = rw_peas.PeasPlugin('rwsdn_openstack', 'RwSdn-1.0')
64 engine, info, extension = plugin()
65
66 # Get the RwLogger context
67 rwloggerctx = rwlogger.RwLog.Ctx.new("SDN-Log")
68
69 sdn = plugin.get_interface("Topology")
70 try:
71 rc = sdn.init(rwloggerctx)
72 assert rc == RwStatus.SUCCESS
73 except:
74 logger.error("ERROR:SDN openstack plugin instantiation failed. Aborting tests")
75 else:
76 logger.info("SDN openstack plugin successfully instantiated")
77 return sdn
78
79
80
81 class SdnOpenstackTest(unittest.TestCase):
82 def setUp(self):
83 """
84 Initialize test plugins
85 """
86 self._acct = get_sdn_account()
87 logger.info("SDN-Openstack-Test: setUp")
88 self.sdn = get_sdn_plugin()
89 logger.info("SDN-Openstack-Test: setUpEND")
90
91 def tearDown(self):
92 logger.info("SDN-Openstack-Test: Done with tests")
93
94 def test_validate_sdn_creds(self):
95 """
96 First test case
97 """
98 logger.debug("SDN-Openstack-Test: Starting validate creds ")
99 rc, status = self.sdn.validate_sdn_creds(self._acct)
100 logger.debug("SDN-Openstack-Test: SDN return code %s resp %s", rc, status)
101 self.assertEqual(rc, RwStatus.SUCCESS)
102 logger.info("SDN-Openstack-Test: Passed validate creds")
103
104
105 if __name__ == "__main__":
106 logging.basicConfig(level=logging.DEBUG)
107 unittest.main()
108
109
110
111