Merge "Check open args in test_odl"
[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 errno
13 import logging
14 import os
15 import StringIO
16 import unittest
17
18 from keystoneauth1.exceptions import auth_plugins
19 import mock
20 from robot.errors import DataError, RobotError
21 from robot.result import testcase as result_testcase
22 from robot.utils.robottime import timestamp_to_secs
23
24 from functest.core import testcase
25 from functest.opnfv_tests.sdn.odl import odl
26
27 __author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
28
29
30 class ODLVisitorTesting(unittest.TestCase):
31
32     """The class testing ODLResultVisitor."""
33     # pylint: disable=missing-docstring
34
35     logging.disable(logging.CRITICAL)
36
37     def setUp(self):
38         self.visitor = odl.ODLResultVisitor()
39
40     def test_empty(self):
41         self.assertFalse(self.visitor.get_data())
42
43     def test_ok(self):
44         data = {'name': 'foo',
45                 'parent': 'bar',
46                 'status': 'PASS',
47                 'starttime': "20161216 16:00:00.000",
48                 'endtime': "20161216 16:00:01.000",
49                 'elapsedtime': 1000,
50                 'text': 'Hello, World!',
51                 'critical': True}
52         test = result_testcase.TestCase(name=data['name'],
53                                         status=data['status'],
54                                         message=data['text'],
55                                         starttime=data['starttime'],
56                                         endtime=data['endtime'])
57         test.parent = mock.Mock()
58         config = {'name': data['parent'],
59                   'criticality.test_is_critical.return_value': data[
60                       'critical']}
61         test.parent.configure_mock(**config)
62         self.visitor.visit_test(test)
63         self.assertEqual(self.visitor.get_data(), [data])
64
65
66 class ODLTesting(unittest.TestCase):
67
68     """The super class which testing classes could inherit."""
69     # pylint: disable=missing-docstring
70
71     logging.disable(logging.CRITICAL)
72
73     _keystone_ip = "127.0.0.1"
74     _neutron_ip = "127.0.0.2"
75     _sdn_controller_ip = "127.0.0.3"
76     _os_auth_url = "http://{}:5000/v2.0".format(_keystone_ip)
77     _os_tenantname = "admin"
78     _os_username = "admin"
79     _os_password = "admin"
80     _odl_webport = "8080"
81     _odl_restconfport = "8181"
82     _odl_username = "admin"
83     _odl_password = "admin"
84
85     def setUp(self):
86         for var in ("INSTALLER_TYPE", "SDN_CONTROLLER", "SDN_CONTROLLER_IP"):
87             if var in os.environ:
88                 del os.environ[var]
89         os.environ["OS_AUTH_URL"] = self._os_auth_url
90         os.environ["OS_USERNAME"] = self._os_username
91         os.environ["OS_PASSWORD"] = self._os_password
92         os.environ["OS_TENANT_NAME"] = self._os_tenantname
93         self.test = odl.ODLTests(case_name='odl', project_name='functest')
94         self.defaultargs = {'odlusername': self._odl_username,
95                             'odlpassword': self._odl_password,
96                             'neutronip': self._keystone_ip,
97                             'osauthurl': self._os_auth_url,
98                             'osusername': self._os_username,
99                             'ostenantname': self._os_tenantname,
100                             'ospassword': self._os_password,
101                             'odlip': self._keystone_ip,
102                             'odlwebport': self._odl_webport,
103                             'odlrestconfport': self._odl_restconfport,
104                             'pushtodb': False}
105
106
107 class ODLParseResultTesting(ODLTesting):
108
109     """The class testing ODLTests.parse_results()."""
110     # pylint: disable=missing-docstring
111
112     @mock.patch('robot.api.ExecutionResult', side_effect=DataError)
113     def test_raises_exc(self, mock_method):
114         with self.assertRaises(DataError):
115             self.test.parse_results()
116         mock_method.assert_called_once_with(
117             os.path.join(odl.ODLTests.res_dir, 'output.xml'))
118
119     def test_ok(self):
120         config = {'name': 'dummy', 'starttime': '20161216 16:00:00.000',
121                   'endtime': '20161216 16:00:01.000', 'status': 'PASS'}
122         suite = mock.Mock()
123         suite.configure_mock(**config)
124         with mock.patch('robot.api.ExecutionResult',
125                         return_value=mock.Mock(suite=suite)):
126             self.test.parse_results()
127             self.assertEqual(self.test.result, config['status'])
128             self.assertEqual(self.test.start_time,
129                              timestamp_to_secs(config['starttime']))
130             self.assertEqual(self.test.stop_time,
131                              timestamp_to_secs(config['endtime']))
132             self.assertEqual(self.test.details,
133                              {'description': config['name'], 'tests': []})
134
135
136 class ODLRobotTesting(ODLTesting):
137
138     """The class testing ODLTests.set_robotframework_vars()."""
139     # pylint: disable=missing-docstring
140
141     @mock.patch('fileinput.input', side_effect=Exception())
142     def test_set_vars_ko(self, mock_method):
143         self.assertFalse(self.test.set_robotframework_vars())
144         mock_method.assert_called_once_with(
145             os.path.join(odl.ODLTests.odl_test_repo,
146                          'csit/variables/Variables.py'), inplace=True)
147
148     @mock.patch('fileinput.input', return_value=[])
149     def test_set_vars_empty(self, mock_method):
150         self.assertTrue(self.test.set_robotframework_vars())
151         mock_method.assert_called_once_with(
152             os.path.join(odl.ODLTests.odl_test_repo,
153                          'csit/variables/Variables.py'), inplace=True)
154
155     @mock.patch('sys.stdout', new_callable=StringIO.StringIO)
156     def _test_set_vars(self, msg1, msg2, *args):
157         line = mock.MagicMock()
158         line.__iter__.return_value = [msg1]
159         with mock.patch('fileinput.input', return_value=line) as mock_method:
160             self.assertTrue(self.test.set_robotframework_vars())
161             mock_method.assert_called_once_with(
162                 os.path.join(odl.ODLTests.odl_test_repo,
163                              'csit/variables/Variables.py'), inplace=True)
164             self.assertEqual(args[0].getvalue(), "{}\n".format(msg2))
165
166     def test_set_vars_auth_default(self):
167         self._test_set_vars("AUTH = []",
168                             "AUTH = [u'admin', u'admin']")
169
170     def test_set_vars_auth1(self):
171         self._test_set_vars("AUTH1 = []", "AUTH1 = []")
172
173     @mock.patch('sys.stdout', new_callable=StringIO.StringIO)
174     def test_set_vars_auth_foo(self, *args):
175         line = mock.MagicMock()
176         line.__iter__.return_value = ["AUTH = []"]
177         with mock.patch('fileinput.input', return_value=line) as mock_method:
178             self.assertTrue(self.test.set_robotframework_vars('foo', 'bar'))
179             mock_method.assert_called_once_with(
180                 os.path.join(odl.ODLTests.odl_test_repo,
181                              'csit/variables/Variables.py'), inplace=True)
182             self.assertEqual(args[0].getvalue(),
183                              "AUTH = [u'{}', u'{}']\n".format('foo', 'bar'))
184
185
186 class ODLMainTesting(ODLTesting):
187
188     """The class testing ODLTests.main()."""
189     # pylint: disable=missing-docstring
190
191     def _get_main_kwargs(self, key=None):
192         kwargs = {'odlusername': self._odl_username,
193                   'odlpassword': self._odl_password,
194                   'neutronip': self._neutron_ip,
195                   'osauthurl': self._os_auth_url,
196                   'osusername': self._os_username,
197                   'ostenantname': self._os_tenantname,
198                   'ospassword': self._os_password,
199                   'odlip': self._sdn_controller_ip,
200                   'odlwebport': self._odl_webport,
201                   'odlrestconfport': self._odl_restconfport}
202         if key:
203             del kwargs[key]
204         return kwargs
205
206     def _test_main(self, status, *args):
207         kwargs = self._get_main_kwargs()
208         self.assertEqual(self.test.main(**kwargs), status)
209         if len(args) > 0:
210             args[0].assert_called_once_with(
211                 odl.ODLTests.res_dir)
212         if len(args) > 1:
213             variable = ['KEYSTONE:{}'.format(self._keystone_ip),
214                         'NEUTRON:{}'.format(self._neutron_ip),
215                         'OS_AUTH_URL:"{}"'.format(self._os_auth_url),
216                         'OSUSERNAME:"{}"'.format(self._os_username),
217                         'OSTENANTNAME:"{}"'.format(self._os_tenantname),
218                         'OSPASSWORD:"{}"'.format(self._os_password),
219                         'ODL_SYSTEM_IP:{}'.format(self._sdn_controller_ip),
220                         'PORT:{}'.format(self._odl_webport),
221                         'RESTCONFPORT:{}'.format(self._odl_restconfport)]
222             args[1].assert_called_once_with(
223                 odl.ODLTests.basic_suite_dir,
224                 odl.ODLTests.neutron_suite_dir,
225                 log='NONE',
226                 output=os.path.join(odl.ODLTests.res_dir, 'output.xml'),
227                 report='NONE',
228                 stdout=mock.ANY,
229                 variable=variable)
230         if len(args) > 2:
231             args[2].assert_called_with(
232                 os.path.join(odl.ODLTests.res_dir, 'stdout.txt'))
233
234     def _test_no_keyword(self, key):
235         kwargs = self._get_main_kwargs(key)
236         self.assertEqual(self.test.main(**kwargs),
237                          testcase.TestCase.EX_RUN_ERROR)
238
239     def test_no_odlusername(self):
240         self._test_no_keyword('odlusername')
241
242     def test_no_odlpassword(self):
243         self._test_no_keyword('odlpassword')
244
245     def test_no_neutronip(self):
246         self._test_no_keyword('neutronip')
247
248     def test_no_osauthurl(self):
249         self._test_no_keyword('osauthurl')
250
251     def test_no_osusername(self):
252         self._test_no_keyword('osusername')
253
254     def test_no_ostenantname(self):
255         self._test_no_keyword('ostenantname')
256
257     def test_no_ospassword(self):
258         self._test_no_keyword('ospassword')
259
260     def test_no_odlip(self):
261         self._test_no_keyword('odlip')
262
263     def test_no_odlwebport(self):
264         self._test_no_keyword('odlwebport')
265
266     def test_no_odlrestconfport(self):
267         self._test_no_keyword('odlrestconfport')
268
269     def test_set_vars_ko(self):
270         with mock.patch.object(self.test, 'set_robotframework_vars',
271                                return_value=False) as mock_object:
272             self._test_main(testcase.TestCase.EX_RUN_ERROR)
273             mock_object.assert_called_once_with(
274                 self._odl_username, self._odl_password)
275
276     @mock.patch('os.makedirs', side_effect=Exception)
277     def test_makedirs_exc(self, mock_method):
278         with mock.patch.object(self.test, 'set_robotframework_vars',
279                                return_value=True), \
280                 self.assertRaises(Exception):
281             self._test_main(testcase.TestCase.EX_RUN_ERROR,
282                             mock_method)
283
284     @mock.patch('os.makedirs', side_effect=OSError)
285     def test_makedirs_oserror(self, mock_method):
286         with mock.patch.object(self.test, 'set_robotframework_vars',
287                                return_value=True):
288             self._test_main(testcase.TestCase.EX_RUN_ERROR,
289                             mock_method)
290
291     @mock.patch('robot.run', side_effect=RobotError)
292     @mock.patch('os.makedirs')
293     def test_run_ko(self, *args):
294         with mock.patch.object(self.test, 'set_robotframework_vars',
295                                return_value=True), \
296                 mock.patch.object(odl, 'open', mock.mock_open(),
297                                   create=True), \
298                 self.assertRaises(RobotError):
299             self._test_main(testcase.TestCase.EX_RUN_ERROR, *args)
300
301     @mock.patch('robot.run')
302     @mock.patch('os.makedirs')
303     def test_parse_results_ko(self, *args):
304         with mock.patch.object(self.test, 'set_robotframework_vars',
305                                return_value=True), \
306                 mock.patch.object(odl, 'open', mock.mock_open(),
307                                   create=True), \
308                 mock.patch.object(self.test, 'parse_results',
309                                   side_effect=RobotError):
310             self._test_main(testcase.TestCase.EX_RUN_ERROR, *args)
311
312     @mock.patch('os.remove', side_effect=Exception)
313     @mock.patch('robot.run')
314     @mock.patch('os.makedirs')
315     def test_remove_exc(self, *args):
316         with mock.patch.object(self.test, 'set_robotframework_vars',
317                                return_value=True), \
318                 mock.patch.object(self.test, 'parse_results'), \
319                 self.assertRaises(Exception):
320             self._test_main(testcase.TestCase.EX_OK, *args)
321
322     @mock.patch('os.remove')
323     @mock.patch('robot.run')
324     @mock.patch('os.makedirs')
325     def test_ok(self, *args):
326         with mock.patch.object(self.test, 'set_robotframework_vars',
327                                return_value=True), \
328                 mock.patch.object(odl, 'open', mock.mock_open(),
329                                   create=True), \
330                 mock.patch.object(self.test, 'parse_results'):
331             self._test_main(testcase.TestCase.EX_OK, *args)
332
333     @mock.patch('os.remove')
334     @mock.patch('robot.run')
335     @mock.patch('os.makedirs', side_effect=OSError(errno.EEXIST, ''))
336     def test_makedirs_oserror17(self, *args):
337         with mock.patch.object(self.test, 'set_robotframework_vars',
338                                return_value=True), \
339                 mock.patch.object(odl, 'open', mock.mock_open(),
340                                   create=True) as mock_open, \
341                 mock.patch.object(self.test, 'parse_results'):
342             self._test_main(testcase.TestCase.EX_OK, *args)
343         mock_open.assert_called_once_with(
344             os.path.join(odl.ODLTests.res_dir, 'stdout.txt'), 'w+')
345
346     @mock.patch('os.remove')
347     @mock.patch('robot.run', return_value=1)
348     @mock.patch('os.makedirs')
349     def test_testcases_in_failure(self, *args):
350         with mock.patch.object(self.test, 'set_robotframework_vars',
351                                return_value=True), \
352                 mock.patch.object(odl, 'open', mock.mock_open(),
353                                   create=True) as mock_open, \
354                 mock.patch.object(self.test, 'parse_results'):
355             self._test_main(testcase.TestCase.EX_OK, *args)
356         mock_open.assert_called_once_with(
357             os.path.join(odl.ODLTests.res_dir, 'stdout.txt'), 'w+')
358
359     @mock.patch('os.remove', side_effect=OSError)
360     @mock.patch('robot.run')
361     @mock.patch('os.makedirs')
362     def test_remove_oserror(self, *args):
363         with mock.patch.object(self.test, 'set_robotframework_vars',
364                                return_value=True), \
365                 mock.patch.object(odl, 'open', mock.mock_open(),
366                                   create=True) as mock_open, \
367                 mock.patch.object(self.test, 'parse_results'):
368             self._test_main(testcase.TestCase.EX_OK, *args)
369         mock_open.assert_called_once_with(
370             os.path.join(odl.ODLTests.res_dir, 'stdout.txt'), 'w+')
371
372
373 class ODLRunTesting(ODLTesting):
374
375     """The class testing ODLTests.run()."""
376     # pylint: disable=missing-docstring
377
378     def _test_no_env_var(self, var):
379         with mock.patch('functest.utils.openstack_utils.get_endpoint',
380                         return_value="http://{}:9696".format(
381                             ODLTesting._neutron_ip)):
382             del os.environ[var]
383             self.assertEqual(self.test.run(),
384                              testcase.TestCase.EX_RUN_ERROR)
385
386     def _test_run(self, status=testcase.TestCase.EX_OK,
387                   exception=None, **kwargs):
388         odlip = kwargs['odlip'] if 'odlip' in kwargs else '127.0.0.3'
389         odlwebport = kwargs['odlwebport'] if 'odlwebport' in kwargs else '8080'
390         odlrestconfport = (kwargs['odlrestconfport']
391                            if 'odlrestconfport' in kwargs else '8181')
392
393         with mock.patch('functest.utils.openstack_utils.get_endpoint',
394                         return_value="http://{}:9696".format(
395                             ODLTesting._neutron_ip)):
396             if exception:
397                 self.test.main = mock.Mock(side_effect=exception)
398             else:
399                 self.test.main = mock.Mock(return_value=status)
400             self.assertEqual(self.test.run(), status)
401             self.test.main.assert_called_once_with(
402                 odl.ODLTests.default_suites,
403                 neutronip=self._neutron_ip,
404                 odlip=odlip, odlpassword=self._odl_password,
405                 odlrestconfport=odlrestconfport,
406                 odlusername=self._odl_username, odlwebport=odlwebport,
407                 osauthurl=self._os_auth_url,
408                 ospassword=self._os_password, ostenantname=self._os_tenantname,
409                 osusername=self._os_username)
410
411     def _test_multiple_suites(self, suites,
412                               status=testcase.TestCase.EX_OK, **kwargs):
413         odlip = kwargs['odlip'] if 'odlip' in kwargs else '127.0.0.3'
414         odlwebport = kwargs['odlwebport'] if 'odlwebport' in kwargs else '8080'
415         odlrestconfport = (kwargs['odlrestconfport']
416                            if 'odlrestconfport' in kwargs else '8181')
417         with mock.patch('functest.utils.openstack_utils.get_endpoint',
418                         return_value="http://{}:9696".format(
419                             ODLTesting._neutron_ip)):
420             self.test.main = mock.Mock(return_value=status)
421             self.assertEqual(self.test.run(suites=suites), status)
422             self.test.main.assert_called_once_with(
423                 suites,
424                 neutronip=self._neutron_ip,
425                 odlip=odlip, odlpassword=self._odl_password,
426                 odlrestconfport=odlrestconfport,
427                 odlusername=self._odl_username, odlwebport=odlwebport,
428                 osauthurl=self._os_auth_url,
429                 ospassword=self._os_password, ostenantname=self._os_tenantname,
430                 osusername=self._os_username)
431
432     def test_exc(self):
433         with mock.patch('functest.utils.openstack_utils.get_endpoint',
434                         side_effect=auth_plugins.MissingAuthPlugin()):
435             self.assertEqual(self.test.run(),
436                              testcase.TestCase.EX_RUN_ERROR)
437
438     def test_no_os_auth_url(self):
439         self._test_no_env_var("OS_AUTH_URL")
440
441     def test_no_os_username(self):
442         self._test_no_env_var("OS_USERNAME")
443
444     def test_no_os_password(self):
445         self._test_no_env_var("OS_PASSWORD")
446
447     def test_no_os_tenant_name(self):
448         self._test_no_env_var("OS_TENANT_NAME")
449
450     def test_main_false(self):
451         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
452         self._test_run(testcase.TestCase.EX_RUN_ERROR,
453                        odlip=self._sdn_controller_ip,
454                        odlwebport=self._odl_webport)
455
456     def test_main_exc(self):
457         with self.assertRaises(Exception):
458             os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
459             self._test_run(status=testcase.TestCase.EX_RUN_ERROR,
460                            exception=Exception(),
461                            odlip=self._sdn_controller_ip,
462                            odlwebport=self._odl_webport)
463
464     def test_no_sdn_controller_ip(self):
465         with mock.patch('functest.utils.openstack_utils.get_endpoint',
466                         return_value="http://{}:9696".format(
467                             ODLTesting._neutron_ip)):
468             self.assertEqual(self.test.run(),
469                              testcase.TestCase.EX_RUN_ERROR)
470
471     def test_without_installer_type(self):
472         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
473         self._test_run(testcase.TestCase.EX_OK,
474                        odlip=self._sdn_controller_ip,
475                        odlwebport=self._odl_webport)
476
477     def test_suites(self):
478         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
479         self._test_multiple_suites(
480             [odl.ODLTests.basic_suite_dir],
481             testcase.TestCase.EX_OK,
482             odlip=self._sdn_controller_ip,
483             odlwebport=self._odl_webport)
484
485     def test_fuel(self):
486         os.environ["INSTALLER_TYPE"] = "fuel"
487         self._test_run(testcase.TestCase.EX_OK,
488                        odlip=self._neutron_ip, odlwebport='8282')
489
490     def test_apex_no_controller_ip(self):
491         with mock.patch('functest.utils.openstack_utils.get_endpoint',
492                         return_value="http://{}:9696".format(
493                             ODLTesting._neutron_ip)):
494             os.environ["INSTALLER_TYPE"] = "apex"
495             self.assertEqual(self.test.run(),
496                              testcase.TestCase.EX_RUN_ERROR)
497
498     def test_apex(self):
499         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
500         os.environ["INSTALLER_TYPE"] = "apex"
501         self._test_run(testcase.TestCase.EX_OK,
502                        odlip=self._sdn_controller_ip, odlwebport='8081',
503                        odlrestconfport='8081')
504
505     def test_netvirt_no_controller_ip(self):
506         with mock.patch('functest.utils.openstack_utils.get_endpoint',
507                         return_value="http://{}:9696".format(
508                             ODLTesting._neutron_ip)):
509             os.environ["INSTALLER_TYPE"] = "netvirt"
510             self.assertEqual(self.test.run(),
511                              testcase.TestCase.EX_RUN_ERROR)
512
513     def test_netvirt(self):
514         os.environ["SDN_CONTROLLER_IP"] = self._sdn_controller_ip
515         os.environ["INSTALLER_TYPE"] = "netvirt"
516         self._test_run(testcase.TestCase.EX_OK,
517                        odlip=self._sdn_controller_ip, odlwebport='8081',
518                        odlrestconfport='8081')
519
520     def test_joid_no_controller_ip(self):
521         with mock.patch('functest.utils.openstack_utils.get_endpoint',
522                         return_value="http://{}:9696".format(
523                             ODLTesting._neutron_ip)):
524             os.environ["INSTALLER_TYPE"] = "joid"
525             self.assertEqual(self.test.run(),
526                              testcase.TestCase.EX_RUN_ERROR)
527
528     def test_joid(self):
529         os.environ["SDN_CONTROLLER"] = self._sdn_controller_ip
530         os.environ["INSTALLER_TYPE"] = "joid"
531         self._test_run(testcase.TestCase.EX_OK,
532                        odlip=self._sdn_controller_ip, odlwebport='8080')
533
534     def test_compass(self):
535         os.environ["INSTALLER_TYPE"] = "compass"
536         self._test_run(testcase.TestCase.EX_OK,
537                        odlip=self._neutron_ip, odlwebport='8181')
538
539
540 class ODLArgParserTesting(ODLTesting):
541
542     """The class testing ODLParser."""
543     # pylint: disable=missing-docstring
544
545     def setUp(self):
546         self.parser = odl.ODLParser()
547         super(ODLArgParserTesting, self).setUp()
548
549     def test_default(self):
550         self.assertEqual(self.parser.parse_args(), self.defaultargs)
551
552     def test_basic(self):
553         self.defaultargs['neutronip'] = self._neutron_ip
554         self.defaultargs['odlip'] = self._sdn_controller_ip
555         self.assertEqual(
556             self.parser.parse_args(
557                 ["--neutronip={}".format(self._neutron_ip),
558                  "--odlip={}".format(self._sdn_controller_ip)]),
559             self.defaultargs)
560
561     @mock.patch('sys.stderr', new_callable=StringIO.StringIO)
562     def test_fail(self, mock_method):
563         self.defaultargs['foo'] = 'bar'
564         with self.assertRaises(SystemExit):
565             self.parser.parse_args(["--foo=bar"])
566         self.assertTrue(mock_method.getvalue().startswith("usage:"))
567
568     def _test_arg(self, arg, value):
569         self.defaultargs[arg] = value
570         self.assertEqual(
571             self.parser.parse_args(["--{}={}".format(arg, value)]),
572             self.defaultargs)
573
574     def test_odlusername(self):
575         self._test_arg('odlusername', 'foo')
576
577     def test_odlpassword(self):
578         self._test_arg('odlpassword', 'foo')
579
580     def test_osauthurl(self):
581         self._test_arg('osauthurl', 'http://127.0.0.4:5000/v2')
582
583     def test_neutronip(self):
584         self._test_arg('neutronip', '127.0.0.4')
585
586     def test_osusername(self):
587         self._test_arg('osusername', 'foo')
588
589     def test_ostenantname(self):
590         self._test_arg('ostenantname', 'foo')
591
592     def test_ospassword(self):
593         self._test_arg('ospassword', 'foo')
594
595     def test_odlip(self):
596         self._test_arg('odlip', '127.0.0.4')
597
598     def test_odlwebport(self):
599         self._test_arg('odlwebport', '80')
600
601     def test_odlrestconfport(self):
602         self._test_arg('odlrestconfport', '80')
603
604     def test_pushtodb(self):
605         self.defaultargs['pushtodb'] = True
606         self.assertEqual(self.parser.parse_args(["--{}".format('pushtodb')]),
607                          self.defaultargs)
608
609     def test_multiple_args(self):
610         self.defaultargs['neutronip'] = self._neutron_ip
611         self.defaultargs['odlip'] = self._sdn_controller_ip
612         self.assertEqual(
613             self.parser.parse_args(
614                 ["--neutronip={}".format(self._neutron_ip),
615                  "--odlip={}".format(self._sdn_controller_ip)]),
616             self.defaultargs)
617
618
619 if __name__ == "__main__":
620     unittest.main(verbosity=2)