summaryrefslogtreecommitdiff
path: root/openstackclient/tests/test_shell.py
diff options
context:
space:
mode:
authorDaisuke Fujita <fuzita.daisuke@jp.fujitsu.com>2015-05-29 20:39:24 +0900
committerTerryHowe <terrylhowe@gmail.com>2015-08-08 10:02:46 -0600
commite23dd6de5854fcc8ff76fe1b51eb46162770d9cc (patch)
treefc82a71a3226d3032eb2a380fef1984bcffc45fb /openstackclient/tests/test_shell.py
parent46cc7d12ad202184917822dfa16dc66d066c8538 (diff)
downloadpython-openstackclient-e23dd6de5854fcc8ff76fe1b51eb46162770d9cc.tar.gz
Set up every time record log in file
This will allow users to record logs of all their commands into a predefined log file, in clouds.yaml. The log should have a format similar to that of oslo.log. Change-Id: I1b334bf429d575fc25809c9706fc0b11116be3f1 Implements: blueprint every-time-record-log-in-file
Diffstat (limited to 'openstackclient/tests/test_shell.py')
-rw-r--r--openstackclient/tests/test_shell.py96
1 files changed, 92 insertions, 4 deletions
diff --git a/openstackclient/tests/test_shell.py b/openstackclient/tests/test_shell.py
index e2f0580b..5b844753 100644
--- a/openstackclient/tests/test_shell.py
+++ b/openstackclient/tests/test_shell.py
@@ -77,6 +77,8 @@ CLOUD_2 = {
'username': 'zaphod',
},
'region_name': 'occ-cloud',
+ 'log_file': '/tmp/test_log_file',
+ 'log_level': 'debug',
}
}
}
@@ -621,9 +623,12 @@ class TestShellCli(TestShell):
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
- def test_shell_args_cloud_public(self, config_mock, public_mock):
+ @mock.patch("openstackclient.common.context._setup_handler_for_logging")
+ def test_shell_args_cloud_public(self, setup_handler, config_mock,
+ public_mock):
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
public_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
+ setup_handler.return_value = mock.MagicMock()
_shell = make_shell()
fake_execute(
@@ -661,9 +666,12 @@ class TestShellCli(TestShell):
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
- def test_shell_args_precedence(self, config_mock, vendor_mock):
+ @mock.patch("openstackclient.common.context._setup_handler_for_logging")
+ def test_shell_args_precedence(self, setup_handler, config_mock,
+ vendor_mock):
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
+ setup_handler.return_value = mock.MagicMock()
_shell = make_shell()
# Test command option overriding config file value
@@ -715,9 +723,12 @@ class TestShellCliEnv(TestShell):
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
- def test_shell_args_precedence_1(self, config_mock, vendor_mock):
+ @mock.patch("openstackclient.common.context._setup_handler_for_logging")
+ def test_shell_args_precedence_1(self, setup_handler, config_mock,
+ vendor_mock):
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
+ setup_handler.return_value = mock.MagicMock()
_shell = make_shell()
# Test env var
@@ -756,9 +767,12 @@ class TestShellCliEnv(TestShell):
@mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
@mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
- def test_shell_args_precedence_2(self, config_mock, vendor_mock):
+ @mock.patch("openstackclient.common.context._setup_handler_for_logging")
+ def test_shell_args_precedence_2(self, setup_handler, config_mock,
+ vendor_mock):
config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
+ setup_handler.return_value = mock.MagicMock()
_shell = make_shell()
# Test command option overriding config file value
@@ -796,3 +810,77 @@ class TestShellCliEnv(TestShell):
'krikkit',
_shell.cloud.config['region_name'],
)
+
+
+class TestShellCliLogging(TestShell):
+ def setUp(self):
+ super(TestShellCliLogging, self).setUp()
+
+ def tearDown(self):
+ super(TestShellCliLogging, self).tearDown()
+
+ @mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
+ @mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
+ @mock.patch("openstackclient.common.context._setup_handler_for_logging")
+ def test_shell_args_precedence_1(self, setup_handler, config_mock,
+ vendor_mock):
+ config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
+ vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
+ setup_handler.return_value = mock.MagicMock()
+ _shell = make_shell()
+
+ # These come from clouds.yaml
+ fake_execute(
+ _shell,
+ "--os-cloud megacloud list user",
+ )
+ self.assertEqual(
+ 'megacloud',
+ _shell.cloud.name,
+ )
+
+ self.assertEqual(
+ '/tmp/test_log_file',
+ _shell.cloud.config['log_file'],
+ )
+ self.assertEqual(
+ 'debug',
+ _shell.cloud.config['log_level'],
+ )
+
+ @mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
+ @mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
+ def test_shell_args_precedence_2(self, config_mock, vendor_mock):
+ config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_1))
+ vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
+ _shell = make_shell()
+
+ # Test operation_log_file not set
+ fake_execute(
+ _shell,
+ "--os-cloud scc list user",
+ )
+ self.assertEqual(
+ False,
+ _shell.enable_operation_logging,
+ )
+
+ @mock.patch("os_client_config.config.OpenStackConfig._load_vendor_file")
+ @mock.patch("os_client_config.config.OpenStackConfig._load_config_file")
+ @mock.patch("openstackclient.common.context._setup_handler_for_logging")
+ def test_shell_args_precedence_3(self, setup_handler, config_mock,
+ vendor_mock):
+ config_mock.return_value = ('file.yaml', copy.deepcopy(CLOUD_2))
+ vendor_mock.return_value = ('file.yaml', copy.deepcopy(PUBLIC_1))
+ setup_handler.return_value = mock.MagicMock()
+ _shell = make_shell()
+
+ # Test enable_operation_logging set
+ fake_execute(
+ _shell,
+ "--os-cloud megacloud list user",
+ )
+ self.assertEqual(
+ True,
+ _shell.enable_operation_logging,
+ )