From 9aec997bf7e770c30e04d55adfab95d4df21139a Mon Sep 17 00:00:00 2001 From: liyingjun Date: Mon, 22 Dec 2014 14:50:38 +0800 Subject: [PATCH] Move files to common lib(Part 1) Move broker.py, fileutils.py, sshutils.py and version.py to common directory. Change-Id: Ic18dc90820a518828344db8891744d26173a9855 --- rally/benchmark/context/cleanup/manager.py | 2 +- rally/benchmark/context/users.py | 2 +- rally/benchmark/scenarios/vm/utils.py | 2 +- rally/cmd/cliutils.py | 2 +- rally/cmd/commands/use.py | 2 +- rally/cmd/envutils.py | 2 +- rally/common/__init__.py | 0 rally/{ => common}/broker.py | 0 rally/{ => common}/fileutils.py | 0 rally/{ => common}/sshutils.py | 0 rally/{ => common}/version.py | 0 rally/deploy/serverprovider/provider.py | 2 +- .../unit/benchmark/scenarios/vm/test_utils.py | 2 +- tests/unit/common/__init__.py | 0 tests/unit/{ => common}/test_broker.py | 2 +- tests/unit/{ => common}/test_fileutils.py | 6 +-- tests/unit/{ => common}/test_sshutils.py | 42 +++++++++---------- .../deploy/serverprovider/test_provider.py | 2 +- tests/unit/test_utils.py | 4 +- 19 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 rally/common/__init__.py rename rally/{ => common}/broker.py (100%) rename rally/{ => common}/fileutils.py (100%) rename rally/{ => common}/sshutils.py (100%) rename rally/{ => common}/version.py (100%) create mode 100644 tests/unit/common/__init__.py rename tests/unit/{ => common}/test_broker.py (98%) rename tests/unit/{ => common}/test_fileutils.py (91%) rename tests/unit/{ => common}/test_sshutils.py (90%) diff --git a/rally/benchmark/context/cleanup/manager.py b/rally/benchmark/context/cleanup/manager.py index 8e5c16e5cc..6323eeed48 100644 --- a/rally/benchmark/context/cleanup/manager.py +++ b/rally/benchmark/context/cleanup/manager.py @@ -16,7 +16,7 @@ import time from rally.benchmark.context.cleanup import base -from rally import broker +from rally.common import broker from rally.i18n import _ from rally import log as logging from rally import osclients diff --git a/rally/benchmark/context/users.py b/rally/benchmark/context/users.py index a5e9e7b392..f868c0121e 100644 --- a/rally/benchmark/context/users.py +++ b/rally/benchmark/context/users.py @@ -21,7 +21,7 @@ from oslo.config import cfg from rally.benchmark.context import base from rally.benchmark import utils from rally.benchmark.wrappers import keystone -from rally import broker +from rally.common import broker from rally import consts from rally import exceptions from rally.i18n import _ diff --git a/rally/benchmark/scenarios/vm/utils.py b/rally/benchmark/scenarios/vm/utils.py index d526274c41..559e64e09d 100644 --- a/rally/benchmark/scenarios/vm/utils.py +++ b/rally/benchmark/scenarios/vm/utils.py @@ -19,7 +19,7 @@ import sys from rally.benchmark.scenarios import base from rally.benchmark import utils as bench_utils -from rally import sshutils +from rally.common import sshutils class VMScenario(base.Scenario): diff --git a/rally/cmd/cliutils.py b/rally/cmd/cliutils.py index 74d9465251..2e032c1181 100644 --- a/rally/cmd/cliutils.py +++ b/rally/cmd/cliutils.py @@ -22,12 +22,12 @@ import sys from oslo.config import cfg +from rally.common import version from rally import exceptions from rally.i18n import _ from rally import log as logging from rally.openstack.common import cliutils from rally import utils -from rally import version CONF = cfg.CONF diff --git a/rally/cmd/commands/use.py b/rally/cmd/commands/use.py index ec89c71292..f16ae59034 100644 --- a/rally/cmd/commands/use.py +++ b/rally/cmd/commands/use.py @@ -18,9 +18,9 @@ import os from rally.cmd import cliutils +from rally.common import fileutils from rally import db from rally import exceptions -from rally import fileutils class UseCommands(object): diff --git a/rally/cmd/envutils.py b/rally/cmd/envutils.py index 0c7f513564..8c8493602a 100644 --- a/rally/cmd/envutils.py +++ b/rally/cmd/envutils.py @@ -17,8 +17,8 @@ import os import decorator +from rally.common import fileutils from rally import exceptions -from rally import fileutils from rally.i18n import _ ENV_DEPLOYMENT = "RALLY_DEPLOYMENT" diff --git a/rally/common/__init__.py b/rally/common/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/rally/broker.py b/rally/common/broker.py similarity index 100% rename from rally/broker.py rename to rally/common/broker.py diff --git a/rally/fileutils.py b/rally/common/fileutils.py similarity index 100% rename from rally/fileutils.py rename to rally/common/fileutils.py diff --git a/rally/sshutils.py b/rally/common/sshutils.py similarity index 100% rename from rally/sshutils.py rename to rally/common/sshutils.py diff --git a/rally/version.py b/rally/common/version.py similarity index 100% rename from rally/version.py rename to rally/common/version.py diff --git a/rally/deploy/serverprovider/provider.py b/rally/deploy/serverprovider/provider.py index d55321714e..cc851c1f27 100644 --- a/rally/deploy/serverprovider/provider.py +++ b/rally/deploy/serverprovider/provider.py @@ -18,8 +18,8 @@ import abc import jsonschema import six +from rally.common import sshutils from rally import exceptions -from rally import sshutils from rally import utils diff --git a/tests/unit/benchmark/scenarios/vm/test_utils.py b/tests/unit/benchmark/scenarios/vm/test_utils.py index 6ae36bf9a1..6bb45d1c4a 100644 --- a/tests/unit/benchmark/scenarios/vm/test_utils.py +++ b/tests/unit/benchmark/scenarios/vm/test_utils.py @@ -62,7 +62,7 @@ class VMScenarioTestCase(test.TestCase): @mock.patch(VMTASKS_UTILS + ".VMScenario.run_action") @mock.patch(VMTASKS_UTILS + ".VMScenario.wait_for_ping") - @mock.patch("rally.sshutils.SSH") + @mock.patch("rally.common.sshutils.SSH") def test_run_command(self, mock_ssh_class, mock_wait_ping, mock_run_action): mock_ssh_instance = mock.MagicMock() diff --git a/tests/unit/common/__init__.py b/tests/unit/common/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit/test_broker.py b/tests/unit/common/test_broker.py similarity index 98% rename from tests/unit/test_broker.py rename to tests/unit/common/test_broker.py index 16e715e356..6e61e64520 100644 --- a/tests/unit/test_broker.py +++ b/tests/unit/common/test_broker.py @@ -17,7 +17,7 @@ import collections import mock -from rally import broker +from rally.common import broker from tests.unit import test diff --git a/tests/unit/test_fileutils.py b/tests/unit/common/test_fileutils.py similarity index 91% rename from tests/unit/test_fileutils.py rename to tests/unit/common/test_fileutils.py index fe86f99aed..8970deb284 100644 --- a/tests/unit/test_fileutils.py +++ b/tests/unit/common/test_fileutils.py @@ -17,7 +17,7 @@ import os import mock -from rally import fileutils +from rally.common import fileutils from tests.unit import test @@ -27,7 +27,7 @@ class FileUtilsTestCase(test.TestCase): @mock.patch.dict('os.environ', values={}, clear=True) def test_load_env_vile(self, mock_path): file_data = ["FAKE_ENV=fake_env\n"] - with mock.patch('rally.fileutils.open', mock.mock_open( + with mock.patch('rally.common.fileutils.open', mock.mock_open( read_data=file_data), create=True) as mock_file: mock_file.return_value.readlines.return_value = file_data fileutils.load_env_file('path_to_file') @@ -37,7 +37,7 @@ class FileUtilsTestCase(test.TestCase): @mock.patch('os.path.exists', return_value=True) def test_update_env_file(self, mock_path): file_data = ["FAKE_ENV=old_value\n", "FAKE_ENV2=any\n"] - with mock.patch('rally.fileutils.open', mock.mock_open( + with mock.patch('rally.common.fileutils.open', mock.mock_open( read_data=file_data), create=True) as mock_file: mock_file.return_value.readlines.return_value = file_data fileutils.update_env_file('path_to_file', 'FAKE_ENV', 'new_value') diff --git a/tests/unit/test_sshutils.py b/tests/unit/common/test_sshutils.py similarity index 90% rename from tests/unit/test_sshutils.py rename to tests/unit/common/test_sshutils.py index 44f72334db..d1e1617bd0 100644 --- a/tests/unit/test_sshutils.py +++ b/tests/unit/common/test_sshutils.py @@ -15,7 +15,7 @@ import mock -from rally import sshutils +from rally.common import sshutils from tests.unit import test @@ -30,7 +30,7 @@ class SSHTestCase(test.TestCase): super(SSHTestCase, self).setUp() self.ssh = sshutils.SSH('root', 'example.net') - @mock.patch('rally.sshutils.SSH._get_pkey') + @mock.patch('rally.common.sshutils.SSH._get_pkey') def test_construct(self, m_pkey): m_pkey.return_value = 'pkey' ssh = sshutils.SSH('root', 'example.net', port=33, pkey='key', @@ -51,7 +51,7 @@ class SSHTestCase(test.TestCase): self.assertIsNone(self.ssh.key_filename) self.assertIsNone(self.ssh.password) - @mock.patch('rally.sshutils.paramiko') + @mock.patch('rally.common.sshutils.paramiko') def test__get_pkey_invalid(self, m_paramiko): m_paramiko.SSHException = FakeParamikoException rsa = m_paramiko.rsakey.RSAKey @@ -60,8 +60,8 @@ class SSHTestCase(test.TestCase): dss.from_private_key.side_effect = m_paramiko.SSHException self.assertRaises(sshutils.SSHError, self.ssh._get_pkey, 'key') - @mock.patch('rally.sshutils.StringIO') - @mock.patch('rally.sshutils.paramiko') + @mock.patch('rally.common.sshutils.StringIO') + @mock.patch('rally.common.sshutils.paramiko') def test__get_pkey_dss(self, m_paramiko, m_stringio): m_paramiko.SSHException = FakeParamikoException m_stringio.StringIO.return_value = 'string_key' @@ -74,8 +74,8 @@ class SSHTestCase(test.TestCase): self.assertEqual(key, 'dss_key') m_stringio.StringIO.assert_called_once_with('key') - @mock.patch('rally.sshutils.StringIO') - @mock.patch('rally.sshutils.paramiko') + @mock.patch('rally.common.sshutils.StringIO') + @mock.patch('rally.common.sshutils.paramiko') def test__get_pkey_rsa(self, m_paramiko, m_stringio): m_paramiko.SSHException = FakeParamikoException m_stringio.StringIO.return_value = 'string_key' @@ -88,8 +88,8 @@ class SSHTestCase(test.TestCase): self.assertEqual(key, 'rsa_key') m_stringio.StringIO.assert_called_once_with('key') - @mock.patch('rally.sshutils.SSH._get_pkey') - @mock.patch('rally.sshutils.paramiko') + @mock.patch('rally.common.sshutils.SSH._get_pkey') + @mock.patch('rally.common.sshutils.paramiko') def test__get_client(self, m_paramiko, m_pkey): m_pkey.return_value = 'key' fake_client = mock.Mock() @@ -114,7 +114,7 @@ class SSHTestCase(test.TestCase): m_client.close.assert_called_once_with() self.assertFalse(self.ssh._client) - @mock.patch('rally.sshutils.StringIO') + @mock.patch('rally.common.sshutils.StringIO') def test_execute(self, m_stringio): m_stringio.StringIO.side_effect = stdio = [mock.Mock(), mock.Mock()] stdio[0].read.return_value = 'stdout fake data' @@ -131,7 +131,7 @@ class SSHTestCase(test.TestCase): self.assertEqual('stdout fake data', stdout) self.assertEqual('stderr fake data', stderr) - @mock.patch('rally.sshutils.time') + @mock.patch('rally.common.sshutils.time') def test_wait_timeout(self, m_time): m_time.time.side_effect = [1, 50, 150] self.ssh.execute = mock.Mock(side_effect=[sshutils.SSHError, @@ -140,7 +140,7 @@ class SSHTestCase(test.TestCase): self.assertRaises(sshutils.SSHTimeout, self.ssh.wait) self.assertEqual([mock.call('uname')] * 2, self.ssh.execute.mock_calls) - @mock.patch('rally.sshutils.time') + @mock.patch('rally.common.sshutils.time') def test_wait(self, m_time): m_time.time.side_effect = [1, 50, 100] self.ssh.execute = mock.Mock(side_effect=[sshutils.SSHError, @@ -175,7 +175,7 @@ class SSHRunTestCase(test.TestCase): self.ssh = sshutils.SSH('admin', 'example.net') self.ssh._get_client = mock.Mock(return_value=self.fake_client) - @mock.patch('rally.sshutils.select') + @mock.patch('rally.common.sshutils.select') def test_execute(self, m_select): m_select.select.return_value = ([], [], []) self.fake_session.recv_ready.side_effect = [1, 0, 0] @@ -187,19 +187,19 @@ class SSHRunTestCase(test.TestCase): self.assertEqual((127, 'ok', 'error'), self.ssh.execute('cmd')) self.fake_session.exec_command.assert_called_once_with('cmd') - @mock.patch('rally.sshutils.select') + @mock.patch('rally.common.sshutils.select') def test_run(self, m_select): m_select.select.return_value = ([], [], []) self.assertEqual(0, self.ssh.run('cmd')) - @mock.patch('rally.sshutils.select') + @mock.patch('rally.common.sshutils.select') def test_run_nonzero_status(self, m_select): m_select.select.return_value = ([], [], []) self.fake_session.recv_exit_status.return_value = 1 self.assertRaises(sshutils.SSHError, self.ssh.run, 'cmd') self.assertEqual(1, self.ssh.run('cmd', raise_on_error=False)) - @mock.patch('rally.sshutils.select') + @mock.patch('rally.common.sshutils.select') def test_run_stdout(self, m_select): m_select.select.return_value = ([], [], []) self.fake_session.recv_ready.side_effect = [True, True, False] @@ -209,7 +209,7 @@ class SSHRunTestCase(test.TestCase): self.assertEqual([mock.call('ok1'), mock.call('ok2')], stdout.write.mock_calls) - @mock.patch('rally.sshutils.select') + @mock.patch('rally.common.sshutils.select') def test_run_stderr(self, m_select): m_select.select.return_value = ([], [], []) self.fake_session.recv_stderr_ready.side_effect = [True, False] @@ -218,7 +218,7 @@ class SSHRunTestCase(test.TestCase): self.ssh.run('cmd', stderr=stderr) stderr.write.assert_called_once_with('error') - @mock.patch('rally.sshutils.select') + @mock.patch('rally.common.sshutils.select') def test_run_stdin(self, m_select): """Test run method with stdin. @@ -241,14 +241,14 @@ class SSHRunTestCase(test.TestCase): send_calls = [call('line1'), call('line2'), call('e2')] self.assertEqual(send_calls, self.fake_session.send.mock_calls) - @mock.patch('rally.sshutils.select') + @mock.patch('rally.common.sshutils.select') def test_run_select_error(self, m_select): self.fake_session.exit_status_ready.return_value = False m_select.select.return_value = ([], [], [True]) self.assertRaises(sshutils.SSHError, self.ssh.run, 'cmd') - @mock.patch('rally.sshutils.time') - @mock.patch('rally.sshutils.select') + @mock.patch('rally.common.sshutils.time') + @mock.patch('rally.common.sshutils.select') def test_run_timemout(self, m_select, m_time): m_time.time.side_effect = [1, 3700] m_select.select.return_value = ([], [], []) diff --git a/tests/unit/deploy/serverprovider/test_provider.py b/tests/unit/deploy/serverprovider/test_provider.py index d4c92a7ac3..12ddac0692 100644 --- a/tests/unit/deploy/serverprovider/test_provider.py +++ b/tests/unit/deploy/serverprovider/test_provider.py @@ -17,9 +17,9 @@ import mock import six +from rally.common import sshutils from rally.deploy import serverprovider from rally import exceptions -from rally import sshutils from tests.unit import test diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index b65f456da1..57b426a407 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -128,8 +128,8 @@ class IterSubclassesTestCase(test.TestCase): class ImportModulesTestCase(test.TestCase): def test_try_append_module_into_sys_modules(self): modules = {} - utils.try_append_module('rally.version', modules) - self.assertIn('rally.version', modules) + utils.try_append_module('rally.common.version', modules) + self.assertIn('rally.common.version', modules) def test_try_append_broken_module(self): modules = {}