3 # jose.lausuch@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # pylint: disable=missing-docstring
17 from functest.cli.commands import cli_os
20 class CliOpenStackTesting(unittest.TestCase):
23 self.endpoint_ip = 'test_ip'
24 self.os_auth_url = 'http://test_ip:test_port/v2.0'
25 self.installer_type = 'test_installer_type'
26 self.openstack_creds = 'test_env_file'
27 self.snapshot_file = 'test_snapshot_file'
28 os.environ["OS_AUTH_URL"] = ''
29 self.cli_os = cli_os.CliOpenStack()
31 def test_ping_endpoint_default(self):
32 self.cli_os.os_auth_url = self.os_auth_url
33 self.cli_os.endpoint_ip = self.endpoint_ip
34 with mock.patch('functest.cli.commands.cli_os.os.system',
36 self.assertEqual(self.cli_os.ping_endpoint(), 0)
38 @mock.patch('functest.cli.commands.cli_os.exit', side_effect=Exception)
39 @mock.patch('functest.cli.commands.cli_os.click.echo')
40 def test_ping_endpoint_auth_url_ko(self, mock_click_echo, mock_exit):
41 with self.assertRaises(Exception):
42 self.cli_os.os_auth_url = None
43 self.cli_os.ping_endpoint()
44 mock_click_echo.assert_called_once_with(
45 "Source the OpenStack credentials first")
46 mock_exit.assert_called_once_with(0)
48 @mock.patch('functest.cli.commands.cli_os.exit')
49 @mock.patch('functest.cli.commands.cli_os.click.echo')
50 def test_ping_endpoint_system_fails(self, mock_click_echo, mock_exit):
51 self.cli_os.os_auth_url = self.os_auth_url
52 self.cli_os.endpoint_ip = self.endpoint_ip
53 with mock.patch('functest.cli.commands.cli_os.os.system',
55 self.cli_os.ping_endpoint()
56 mock_click_echo.assert_called_once_with(
57 "Cannot talk to the endpoint %s\n" % self.endpoint_ip)
58 mock_exit.assert_called_once_with(0)
61 with mock.patch.object(self.cli_os, 'ping_endpoint'), \
62 mock.patch('functest.cli.commands.cli_os.check_deployment.'
63 'CheckDeployment') as mock_check_deployment:
65 self.assertTrue(mock_check_deployment.called)
67 @mock.patch('functest.cli.commands.cli_os.click.echo')
68 def test_show_credentials(self, mock_click_echo):
71 with mock.patch.dict(os.environ, {key: value}):
72 self.cli_os.show_credentials()
73 mock_click_echo.assert_any_call("{}={}".format(key, value))
76 if __name__ == "__main__":
77 logging.disable(logging.CRITICAL)
78 unittest.main(verbosity=2)