Protect vs former interface format
[functest.git] / functest / tests / unit / odl / test_odl.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016 Orange and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 """Define the classes required to fully cover odl."""
11
12 import logging
13 import os
14 import unittest
15
16 import mock
17 import munch
18 from robot.errors import RobotError
19 import six
20 from six.moves import urllib
21 from xtesting.core import testcase
22
23 from functest.opnfv_tests.sdn.odl import odl
24
25 __author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
26
27
28 class ODLTesting(unittest.TestCase):
29
30     """The super class which testing classes could inherit."""
31     # pylint: disable=missing-docstring
32
33     logging.disable(logging.CRITICAL)
34
35     _keystone_ip = "127.0.0.1"
36     _neutron_url = u"https://127.0.0.1:9696"
37     _neutron_id = u"dummy"
38     _sdn_controller_ip = "127.0.0.3"
39     _os_auth_url = "http://{}:5000/v3".format(_keystone_ip)
40     _os_projectname = "admin"
41     _os_username = "admin"
42     _os_password = "admin"
43     _odl_webport = "8080"
44     _odl_restconfport = "8181"
45     _odl_username = "admin"
46     _odl_password = "admin"
47     _os_userdomainname = 'Default'
48     _os_projectdomainname = 'Default'
49     _os_interface = "public"
50
51     def setUp(self):
52         for var in ("INSTALLER_TYPE", "SDN_CONTROLLER", "SDN_CONTROLLER_IP"):
53             if var in os.environ:
54                 del os.environ[var]
55         os.environ["OS_AUTH_URL"] = self._os_auth_url
56         os.environ["OS_USERNAME"] = self._os_username
57         os.environ["OS_USER_DOMAIN_NAME"] = self._os_userdomainname
58         os.environ["OS_PASSWORD"] = self._os_password
59         os.environ["OS_PROJECT_NAME"] = self._os_projectname
60         os.environ["OS_PROJECT_DOMAIN_NAME"] = self._os_projectdomainname
61         os.environ["OS_PASSWORD"] = self._os_password
62         os.environ["OS_INTERFACE"] = self._os_interface
63         self.test = odl.ODLTests(case_name='odl', project_name='functest')
64         self.defaultargs = {'odlusername': self._odl_username,
65                             'odlpassword': self._odl_password,
66                             'neutronurl': "http://{}:9696".format(
67                                 self._keystone_ip),
68                             'osauthurl': self._os_auth_url,
69                             'osusername': self._os_username,
70                             'osuserdomainname': self._os_userdomainname,
71                             'osprojectname': self._os_projectname,
72                             'osprojectdomainname': self._os_projectdomainname,
73                             'ospassword': self._os_password,
74                             'odlip': self._keystone_ip,
75                             'odlwebport': self._odl_webport,
76                             'odlrestconfport': self._odl_restconfport,
77                             'pushtodb': False}
78
79
80 class ODLRobotTesting(ODLTesting):
81
82     """The class testing ODLTests.set_robotframework_vars()."""
83     # pylint: disable=missing-docstring
84
85     @mock.patch('fileinput.input', side_effect=Exception())
86     def test_set_vars_ko(self, mock_method):
87         self.assertFalse(self.test.set_robotframework_vars())
88         mock_method.assert_called_once_with(
89             os.path.join(odl.ODLTests.odl_test_repo,
90                          'csit/variables/Variables.robot'), inplace=True)
91
92     @mock.patch('fileinput.input', return_value=[])
93     def test_set_vars_empty(self, mock_method):
94         self.assertTrue(self.test.set_robotframework_vars())
95         mock_method.assert_called_once_with(
96             os.path.join(odl.ODLTests.odl_test_repo,
97                          'csit/variables/Variables.robot'), inplace=True)
98
99     @mock.patch('sys.stdout', new_callable=six.StringIO)
100     def _test_set_vars(self, msg1, msg2, *args):
101         line = mock.MagicMock()
102         line.__iter__.return_value = [msg1]
103         with mock.patch('fileinput.input', return_value=line) as mock_method:
104             self.assertTrue(self.test.set_robotframework_vars())
105             mock_method.assert_called_once_with(
106                 os.path.join(odl.ODLTests.odl_test_repo,
107                              'csit/variables/Variables.robot'), inplace=True)
108             self.assertEqual(args[0].getvalue(), "{}\n".format(msg2))
109
110     def test_set_vars_auth_default(self):
111         self._test_set_vars(
112             "@{AUTH} ",
113             "@{AUTH}           admin    admin")
114
115     def test_set_vars_auth1(self):
116         self._test_set_vars(
117             "@{AUTH1}           foo    bar",
118             "@{AUTH1}           foo    bar")
119
120     @mock.patch('sys.stdout', new_callable=six.StringIO)
121     def test_set_vars_auth_foo(self, *args):
122         line = mock.MagicMock()
123         line.__iter__.return_value = ["@{AUTH} "]
124         with mock.patch('fileinput.input', return_value=line) as mock_method:
125             self.assertTrue(self.test.set_robotframework_vars('foo', 'bar'))
126             mock_method.assert_called_once_with(
127                 os.path.join(odl.ODLTests.odl_test_repo,
128                              'csit/variables/Variables.robot'), inplace=True)
129             self.assertEqual(
130                 args[0].getvalue(),
131                 "@{AUTH}           foo    bar\n")
132
133
134 class ODLMainTesting(ODLTesting):
135
136     """The class testing ODLTests.run_suites()."""
137     # pylint: disable=missing-docstring
138
139     def _get_run_suites_kwargs(self, key=None):
140         kwargs = {'odlusername': self._odl_username,
141                   'odlpassword': self._odl_password,
142                   'neutronurl': self._neutron_url,
143                   'osauthurl': self._os_auth_url,
144                   'osusername': self._os_username,
145                   'osuserdomainname': self._os_userdomainname,
146                   'osprojectname': self._os_projectname,
147                   'osprojectdomainname': self._os_projectdomainname,
148                   'ospassword': self._os_password,
149                   'odlip': self._sdn_controller_ip,
150                   'odlwebport': self._odl_webport,
151                   'odlrestconfport': self._odl_restconfport}
152         if key:
153             del kwargs[key]
154         return kwargs
155
156     def _test_run_suites(self, status, *args):
157         kwargs = self._get_run_suites_kwargs()
158         self.assertEqual(self.test.run_suites(**kwargs), status)
159         if args:
160             args[0].assert_called_once_with(self.test.odl_variables_file)
161         if len(args) > 1:
162             variable = [
163                 'KEYSTONEURL:{}://{}'.format(
164                     urllib.parse.urlparse(self._os_auth_url).scheme,
165                     urllib.parse.urlparse(self._os_auth_url).netloc),
166                 'NEUTRONURL:{}'.format(self._neutron_url),
167                 'OS_AUTH_URL:"{}"'.format(self._os_auth_url),
168                 'OSUSERNAME:"{}"'.format(self._os_username),
169                 'OSUSERDOMAINNAME:"{}"'.format(self._os_userdomainname),
170                 'OSTENANTNAME:"{}"'.format(self._os_projectname),
171                 'OSPROJECTDOMAINNAME:"{}"'.format(self._os_projectdomainname),
172                 'OSPASSWORD:"{}"'.format(self._os_password),
173                 'ODL_SYSTEM_IP:{}'.format(self._sdn_controller_ip),
174                 'PORT:{}'.format(self._odl_webport),
175                 'RESTCONFPORT:{}'.format(self._odl_restconfport)]
176             args[1].assert_called_once_with(
177                 odl.ODLTests.basic_suite_dir, odl.ODLTests.neutron_suite_dir,
178                 include=[],
179                 log='NONE',
180                 output=os.path.join(self.test.res_dir, 'output.xml'),
181                 report='NONE', stdout=mock.ANY, variable=variable,
182                 variablefile=[])
183
184     def _test_no_keyword(self, key):
185         kwargs = self._get_run_suites_kwargs(key)
186         self.assertEqual(self.test.run_suites(**kwargs),
187                          testcase.TestCase.EX_RUN_ERROR)
188
189     def test_no_odlusername(self):
190         self._test_no_keyword('odlusername')
191
192     def test_no_odlpassword(self):
193         self._test_no_keyword('odlpassword')
194
195     def test_no_neutronurl(self):
196         self._test_no_keyword('neutronurl')
197
198     def test_no_osauthurl(self):
199         self._test_no_keyword('osauthurl')
200
201     def test_no_osusername(self):
202         self._test_no_keyword('osusername')
203
204     def test_no_osprojectname(self):
205         self._test_no_keyword('osprojectname')
206
207     def test_no_ospassword(self):
208         self._test_no_keyword('ospassword')
209
210     def test_no_odlip(self):
211         self._test_no_keyword('odlip')
212
213     def test_no_odlwebport(self):
214         self._test_no_keyword('odlwebport')
215
216     def test_no_odlrestconfport(self):
217         self._test_no_keyword('odlrestconfport')
218
219     @mock.patch('os.path.isfile', return_value=True)
220     def test_set_vars_ko(self, *args):
221         with mock.patch.object(self.test, 'set_robotframework_vars',
222                                return_value=False) as mock_object:
223             self._test_run_suites(testcase.TestCase.EX_RUN_ERROR)
224             mock_object.assert_called_once_with(
225                 self._odl_username, self._odl_password)
226         args[0].assert_called_once_with(self.test.odl_variables_file)
227
228     @mock.patch('os.makedirs')
229     @mock.patch('robot.run', side_effect=RobotError)
230     @mock.patch('os.path.isfile', return_value=True)
231     def test_run_ko(self, *args):
232         with mock.patch.object(self.test, 'set_robotframework_vars',
233                                return_value=True), \
234                 self.assertRaises(RobotError):
235             self._test_run_suites(testcase.TestCase.EX_RUN_ERROR, *args)
236
237     @mock.patch('os.makedirs')
238     @mock.patch('robot.run')
239     @mock.patch('os.path.isfile', return_value=True)
240     def test_parse_results_ko(self, *args):
241         with mock.patch.object(self.test, 'set_robotframework_vars',
242                                return_value=True), \
243                 mock.patch.object(self.test, 'parse_results',
244                                   side_effect=RobotError):
245             self._test_run_suites(testcase.TestCase.EX_RUN_ERROR, *args)
246
247     @mock.patch('os.makedirs')
248     @mock.patch('robot.run')
249     @mock.patch('os.path.isfile', return_value=True)
250     def test_ok(self, *args):
251         with mock.patch.object(self.test, 'set_robotframework_vars',
252                                return_value=True), \
253                 mock.patch.object(self.test, 'parse_results'):
254             self._test_run_suites(testcase.TestCase.EX_OK, *args)
255
256     @mock.patch('os.makedirs')
257     @mock.patch('robot.run')
258     @mock.patch('os.path.isfile', return_value=False)
259     def test_ok_no_creds(self, *args):
260         with mock.patch.object(self.test, 'set_robotframework_vars',
261                                return_value=True) as mock_method, \
262                 mock.patch.object(self.test, 'parse_results'):
263             self._test_run_suites(testcase.TestCase.EX_OK, *args)
264             mock_method.assert_not_called()
265
266     @mock.patch('os.makedirs')
267     @mock.patch('robot.run', return_value=1)
268     @mock.patch('os.path.isfile', return_value=True)
269     def test_testcases_in_failure(self, *args):
270         with mock.patch.object(self.test, 'set_robotframework_vars',
271                                return_value=True), \
272                 mock.patch.object(self.test, 'parse_results'):
273             self._test_run_suites(testcase.TestCase.EX_OK, *args)
274
275
276 class ODLRunTesting(ODLTesting):
277     """The class testing ODLTests.run()."""
278     # pylint: disable=too-many-public-methods,missing-docstring
279
280     @mock.patch('os_client_config.make_shade', side_effect=Exception)
281     def test_no_cloud(self, *args):
282         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
283         args[0].assert_called_once_with()
284
285     @mock.patch('os_client_config.make_shade')
286     def test_no_service1(self, *args):
287         args[0].return_value.search_services.return_value = None
288         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
289         args[0].return_value.search_services.assert_called_once_with('neutron')
290         args[0].return_value.search_endpoints.assert_not_called()
291
292     @mock.patch('os_client_config.make_shade')
293     def test_no_service2(self, *args):
294         args[0].return_value.search_services.return_value = []
295         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
296         args[0].return_value.search_services.assert_called_once_with('neutron')
297         args[0].return_value.search_endpoints.assert_not_called()
298
299     @mock.patch('os_client_config.make_shade')
300     def test_no_service3(self, *args):
301         args[0].return_value.search_services.return_value = [
302             munch.Munch()]
303         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
304         args[0].return_value.search_services.assert_called_once_with('neutron')
305         args[0].return_value.search_endpoints.assert_not_called()
306
307     @mock.patch('os_client_config.make_shade')
308     def test_no_endpoint1(self, *args):
309         args[0].return_value.search_services.return_value = [
310             munch.Munch(id=self._neutron_id)]
311         args[0].return_value.search_endpoints.return_value = None
312         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
313         args[0].return_value.search_services.assert_called_once_with('neutron')
314         args[0].return_value.search_endpoints.assert_called_once_with(
315             filters={'interface': self._os_interface,
316                      'service_id': self._neutron_id})
317
318     @mock.patch('os_client_config.make_shade')
319     def test_no_endpoint2(self, *args):
320         args[0].return_value.search_services.return_value = [
321             munch.Munch(id=self._neutron_id)]
322         args[0].return_value.search_endpoints.return_value = []
323         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
324         args[0].return_value.search_services.assert_called_once_with('neutron')
325         args[0].return_value.search_endpoints.assert_called_once_with(
326             filters={'interface': self._os_interface,
327                      'service_id': self._neutron_id})
328
329     @mock.patch('os_client_config.make_shade')
330     def test_no_endpoint3(self, *args):
331         args[0].return_value.search_services.return_value = [
332             munch.Munch(id=self._neutron_id)]
333         args[0].return_value.search_endpoints.return_value = [munch.Munch()]
334         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
335         args[0].return_value.search_services.assert_called_once_with('neutron')
336         args[0].return_value.search_endpoints.assert_called_once_with(
337             filters={'interface': self._os_interface,
338                      'service_id': self._neutron_id})
339
340     @mock.patch('os_client_config.make_shade')
341     def test_endpoint_interface(self, *args):
342         args[0].return_value.search_services.return_value = [
343             munch.Munch(id=self._neutron_id)]
344         args[0].return_value.search_endpoints.return_value = [munch.Munch()]
345         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
346         args[0].return_value.search_services.assert_called_once_with('neutron')
347         args[0].return_value.search_endpoints.assert_called_once_with(
348             filters={'interface': self._os_interface,
349                      'service_id': self._neutron_id})
350
351     @mock.patch('os_client_config.make_shade')
352     def _test_no_env_var(self, var, *args):
353         del os.environ[var]
354         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
355         args[0].assert_called_once_with()
356
357     @mock.patch('os_client_config.make_shade')
358     def _test_missing_value(self, *args):
359         self.assertEqual(self.test.run(), testcase.TestCase.EX_RUN_ERROR)
360         args[0].assert_called_once_with()
361
362     @mock.patch('os_client_config.make_shade')
363     def _test_run(self, status=testcase.TestCase.EX_OK,
364                   exception=None, *args, **kwargs):
365         # pylint: disable=keyword-arg-before-vararg
366         args[0].return_value.search_services.return_value = [
367             munch.Munch(id=self._neutron_id)]
368         args[0].return_value.search_endpoints.return_value = [
369             munch.Munch(url=self._neutron_url)]
370         odlip = kwargs['odlip'] if 'odlip' in kwargs else '127.0.0.3'
371         odlwebport = kwargs['odlwebport'] if 'odlwebport' in kwargs else '8080'
372         odlrestconfport = (kwargs['odlrestconfport']
373                            if 'odlrestconfport' in kwargs else '8181')
374         if exception:
375             self.test.run_suites = mock.Mock(side_effect=exception)
376         else:
377             self.test.run_suites = mock.Mock(return_value=status)
378         self.assertEqual(self.test.run(), status)
379         self.test.run_suites.assert_called_once_with(
380             odl.ODLTests.default_suites, neutronurl=self._neutron_url,
381             odlip=odlip, odlpassword=self._odl_password,
382             odlrestconfport=odlrestconfport, odlusername=self._odl_username,
383             odlwebport=odlwebport, osauthurl=self._os_auth_url,
384             ospassword=self._os_password, osprojectname=self._os_projectname,
385             osusername=self._os_username,
386             osprojectdomainname=self._os_projectdomainname,
387             osuserdomainname=self._os_userdomainname)
388         args[0].assert_called_once_with()
389         args[0].return_value.search_services.assert_called_once_with('neutron')
390         args[0].return_value.search_endpoints.assert_called_once_with(
391             filters={
392                 'interface': os.environ.get(
393                     "OS_INTERFACE", "public").replace('URL', ''),
394                 'service_id': self._neutron_id})
395
396     @mock.patch('os_client_config.make_shade')
397     def _test_multiple_suites(self, suites,
398                               status=testcase.TestCase.EX_OK, *args, **kwargs):
399         # pylint: disable=keyword-arg-before-vararg
400         args[0].return_value.search_endpoints.return_value = [
401             munch.Munch(url=self._neutron_url)]
402         args[0].return_value.search_services.return_value = [
403             munch.Munch(id=self._neutron_id)]
404         odlip = kwargs['odlip'] if 'odlip' in kwargs else '127.0.0.3'
405         odlwebport = kwargs['odlwebport'] if 'odlwebport' in kwargs else '8080'
406         odlrestconfport = (kwargs['odlrestconfport']
407                            if 'odlrestconfport' in kwargs else '8181')
408         self.test.run_suites = mock.Mock(return_value=status)
409         self.assertEqual(self.test.run(suites=suites), status)
410         self.test.run_suites.assert_called_once_with(
411             suites, neutronurl=self._neutron_url, odlip=odlip,
412             odlpassword=self._odl_password, odlrestconfport=odlrestconfport,
413             odlusername=self._odl_username, odlwebport=odlwebport,
414             osauthurl=self._os_auth_url, ospassword=self._os_password,
415             osprojectname=self._os_projectname, osusername=self._os_username,
416             osprojectdomainname=self._os_projectdomainname,
417             osuserdomainname=self._os_userdomainname)
418         args[0].assert_called_once_with()
419         args[0].return_value.search_services.assert_called_once_with('neutron')
420         args[0].return_value.search_endpoints.assert_called_once_with(
421             filters={'interface': os.environ.get("OS_INTERFACE", "public"),
422                      'service_id': self._neutron_id})
423
424     def test_exc(self):
425         with mock.patch('os_client_config.make_shade',
426                         side_effect=Exception()):
427             self.assertEqual(self.test.run(),
428                              testcase.TestCase.EX_RUN_ERROR)
429
430     def test_no_os_auth_url(self):
431         self._test_no_env_var("OS_AUTH_URL")
432
433     def test_no_os_username(self):
434         self._test_no_env_var("OS_USERNAME")
435
436     def test_no_os_password(self):
437         self._test_no_env_var("OS_PASSWORD")
438
439     def test_no_os__name(self):
440         self._test_no_env_var("OS_PROJECT_NAME")
441
442     def test_run_suites_false(self):
443         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
444         self._test_run(testcase.TestCase.EX_RUN_ERROR, None,
445                        odlip=self._sdn_controller_ip,
446                        odlwebport=self._odl_webport)
447
448     def test_run_suites_exc(self):
449         with self.assertRaises(Exception):
450             os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
451             self._test_run(testcase.TestCase.EX_RUN_ERROR,
452                            Exception(),
453                            odlip=self._sdn_controller_ip,
454                            odlwebport=self._odl_webport)
455
456     def test_no_sdn_controller_ip(self):
457         self._test_missing_value()
458
459     def test_without_installer_type(self):
460         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
461         self._test_run(testcase.TestCase.EX_OK, None,
462                        odlip=self._sdn_controller_ip,
463                        odlwebport=self._odl_webport)
464
465     def test_without_os_interface(self):
466         del os.environ["OS_INTERFACE"]
467         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
468         self._test_run(testcase.TestCase.EX_OK, None,
469                        odlip=self._sdn_controller_ip,
470                        odlwebport=self._odl_webport)
471
472     def test_os_interface_public(self):
473         os.environ["OS_INTERFACE"] = "public"
474         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
475         self._test_run(testcase.TestCase.EX_OK, None,
476                        odlip=self._sdn_controller_ip,
477                        odlwebport=self._odl_webport)
478
479     def test_os_interface_publicurl(self):
480         os.environ["OS_INTERFACE"] = "publicURL"
481         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
482         self._test_run(testcase.TestCase.EX_OK, None,
483                        odlip=self._sdn_controller_ip,
484                        odlwebport=self._odl_webport)
485
486     def test_os_interface_internal(self):
487         os.environ["OS_INTERFACE"] = "internal"
488         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
489         self._test_run(testcase.TestCase.EX_OK, None,
490                        odlip=self._sdn_controller_ip,
491                        odlwebport=self._odl_webport)
492
493     def test_os_interface_admin(self):
494         os.environ["OS_INTERFACE"] = "admin"
495         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
496         self._test_run(testcase.TestCase.EX_OK, None,
497                        odlip=self._sdn_controller_ip,
498                        odlwebport=self._odl_webport)
499
500     def test_suites(self):
501         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
502         self._test_multiple_suites(
503             [odl.ODLTests.basic_suite_dir],
504             testcase.TestCase.EX_OK,
505             odlip=self._sdn_controller_ip,
506             odlwebport=self._odl_webport)
507
508     def test_fuel_no_controller_ip(self):
509         os.environ["INSTALLER_TYPE"] = "fuel"
510         self._test_missing_value()
511
512     def test_fuel(self):
513         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
514         os.environ["INSTALLER_TYPE"] = "fuel"
515         self._test_run(testcase.TestCase.EX_OK, None,
516                        odlip=self._sdn_controller_ip,
517                        odlwebport='8282',
518                        odlrestconfport='8282')
519
520     def test_apex_no_controller_ip(self):
521         os.environ["INSTALLER_TYPE"] = "apex"
522         self._test_missing_value()
523
524     def test_apex(self):
525         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
526         os.environ["INSTALLER_TYPE"] = "apex"
527         self._test_run(testcase.TestCase.EX_OK, None,
528                        odlip=self._sdn_controller_ip, odlwebport='8081',
529                        odlrestconfport='8081')
530
531     def test_netvirt_no_controller_ip(self):
532         os.environ["INSTALLER_TYPE"] = "netvirt"
533         self._test_missing_value()
534
535     def test_netvirt(self):
536         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
537         os.environ["INSTALLER_TYPE"] = "netvirt"
538         self._test_run(testcase.TestCase.EX_OK, None,
539                        odlip=self._sdn_controller_ip, odlwebport='8081',
540                        odlrestconfport='8081')
541
542     def test_compass(self):
543         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
544         os.environ["INSTALLER_TYPE"] = "compass"
545         self._test_run(testcase.TestCase.EX_OK, None,
546                        odlip=self._sdn_controller_ip,
547                        odlrestconfport='8080')
548
549     def test_daisy_no_controller_ip(self):
550         os.environ["INSTALLER_TYPE"] = "daisy"
551         self._test_missing_value()
552
553     def test_daisy(self):
554         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
555         os.environ["INSTALLER_TYPE"] = "daisy"
556         self._test_run(testcase.TestCase.EX_OK, None,
557                        odlip=self._sdn_controller_ip, odlwebport='8181',
558                        odlrestconfport='8087')
559
560
561 class ODLArgParserTesting(ODLTesting):
562
563     """The class testing ODLParser."""
564     # pylint: disable=missing-docstring
565
566     def setUp(self):
567         self.parser = odl.ODLParser()
568         super(ODLArgParserTesting, self).setUp()
569
570     def test_default(self):
571         self.assertEqual(self.parser.parse_args(), self.defaultargs)
572
573     def test_basic(self):
574         self.defaultargs['neutronurl'] = self._neutron_url
575         self.defaultargs['odlip'] = self._sdn_controller_ip
576         self.assertEqual(
577             self.parser.parse_args(
578                 ["--neutronurl={}".format(self._neutron_url),
579                  "--odlip={}".format(self._sdn_controller_ip)]),
580             self.defaultargs)
581
582     @mock.patch('sys.stderr', new_callable=six.StringIO)
583     def test_fail(self, mock_method):
584         self.defaultargs['foo'] = 'bar'
585         with self.assertRaises(SystemExit):
586             self.parser.parse_args(["--foo=bar"])
587         self.assertTrue(mock_method.getvalue().startswith("usage:"))
588
589     def _test_arg(self, arg, value):
590         self.defaultargs[arg] = value
591         self.assertEqual(
592             self.parser.parse_args(["--{}={}".format(arg, value)]),
593             self.defaultargs)
594
595     def test_odlusername(self):
596         self._test_arg('odlusername', 'foo')
597
598     def test_odlpassword(self):
599         self._test_arg('odlpassword', 'foo')
600
601     def test_osauthurl(self):
602         self._test_arg('osauthurl', 'http://127.0.0.4:5000/v2')
603
604     def test_neutronurl(self):
605         self._test_arg('neutronurl', 'http://127.0.0.4:9696')
606
607     def test_osusername(self):
608         self._test_arg('osusername', 'foo')
609
610     def test_osuserdomainname(self):
611         self._test_arg('osuserdomainname', 'domain')
612
613     def test_osprojectname(self):
614         self._test_arg('osprojectname', 'foo')
615
616     def test_osprojectdomainname(self):
617         self._test_arg('osprojectdomainname', 'domain')
618
619     def test_ospassword(self):
620         self._test_arg('ospassword', 'foo')
621
622     def test_odlip(self):
623         self._test_arg('odlip', '127.0.0.4')
624
625     def test_odlwebport(self):
626         self._test_arg('odlwebport', '80')
627
628     def test_odlrestconfport(self):
629         self._test_arg('odlrestconfport', '80')
630
631     def test_pushtodb(self):
632         self.defaultargs['pushtodb'] = True
633         self.assertEqual(self.parser.parse_args(["--{}".format('pushtodb')]),
634                          self.defaultargs)
635
636     def test_multiple_args(self):
637         self.defaultargs['neutronurl'] = self._neutron_url
638         self.defaultargs['odlip'] = self._sdn_controller_ip
639         self.assertEqual(
640             self.parser.parse_args(
641                 ["--neutronurl={}".format(self._neutron_url),
642                  "--odlip={}".format(self._sdn_controller_ip)]),
643             self.defaultargs)
644
645
646 if __name__ == "__main__":
647     logging.disable(logging.CRITICAL)
648     unittest.main(verbosity=2)