Move files to common lib(Part 1)
Move broker.py, fileutils.py, sshutils.py and version.py to common directory. Change-Id: Ic18dc90820a518828344db8891744d26173a9855
This commit is contained in:
parent
07bbc3094d
commit
9aec997bf7
@ -16,7 +16,7 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from rally.benchmark.context.cleanup import base
|
from rally.benchmark.context.cleanup import base
|
||||||
from rally import broker
|
from rally.common import broker
|
||||||
from rally.i18n import _
|
from rally.i18n import _
|
||||||
from rally import log as logging
|
from rally import log as logging
|
||||||
from rally import osclients
|
from rally import osclients
|
||||||
|
@ -21,7 +21,7 @@ from oslo.config import cfg
|
|||||||
from rally.benchmark.context import base
|
from rally.benchmark.context import base
|
||||||
from rally.benchmark import utils
|
from rally.benchmark import utils
|
||||||
from rally.benchmark.wrappers import keystone
|
from rally.benchmark.wrappers import keystone
|
||||||
from rally import broker
|
from rally.common import broker
|
||||||
from rally import consts
|
from rally import consts
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
from rally.i18n import _
|
from rally.i18n import _
|
||||||
|
@ -19,7 +19,7 @@ import sys
|
|||||||
|
|
||||||
from rally.benchmark.scenarios import base
|
from rally.benchmark.scenarios import base
|
||||||
from rally.benchmark import utils as bench_utils
|
from rally.benchmark import utils as bench_utils
|
||||||
from rally import sshutils
|
from rally.common import sshutils
|
||||||
|
|
||||||
|
|
||||||
class VMScenario(base.Scenario):
|
class VMScenario(base.Scenario):
|
||||||
|
@ -22,12 +22,12 @@ import sys
|
|||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
|
from rally.common import version
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
from rally.i18n import _
|
from rally.i18n import _
|
||||||
from rally import log as logging
|
from rally import log as logging
|
||||||
from rally.openstack.common import cliutils
|
from rally.openstack.common import cliutils
|
||||||
from rally import utils
|
from rally import utils
|
||||||
from rally import version
|
|
||||||
|
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from rally.cmd import cliutils
|
from rally.cmd import cliutils
|
||||||
|
from rally.common import fileutils
|
||||||
from rally import db
|
from rally import db
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
from rally import fileutils
|
|
||||||
|
|
||||||
|
|
||||||
class UseCommands(object):
|
class UseCommands(object):
|
||||||
|
@ -17,8 +17,8 @@ import os
|
|||||||
|
|
||||||
import decorator
|
import decorator
|
||||||
|
|
||||||
|
from rally.common import fileutils
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
from rally import fileutils
|
|
||||||
from rally.i18n import _
|
from rally.i18n import _
|
||||||
|
|
||||||
ENV_DEPLOYMENT = "RALLY_DEPLOYMENT"
|
ENV_DEPLOYMENT = "RALLY_DEPLOYMENT"
|
||||||
|
0
rally/common/__init__.py
Normal file
0
rally/common/__init__.py
Normal file
@ -18,8 +18,8 @@ import abc
|
|||||||
import jsonschema
|
import jsonschema
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from rally.common import sshutils
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
from rally import sshutils
|
|
||||||
from rally import utils
|
from rally import utils
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class VMScenarioTestCase(test.TestCase):
|
|||||||
|
|
||||||
@mock.patch(VMTASKS_UTILS + ".VMScenario.run_action")
|
@mock.patch(VMTASKS_UTILS + ".VMScenario.run_action")
|
||||||
@mock.patch(VMTASKS_UTILS + ".VMScenario.wait_for_ping")
|
@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,
|
def test_run_command(self, mock_ssh_class, mock_wait_ping,
|
||||||
mock_run_action):
|
mock_run_action):
|
||||||
mock_ssh_instance = mock.MagicMock()
|
mock_ssh_instance = mock.MagicMock()
|
||||||
|
0
tests/unit/common/__init__.py
Normal file
0
tests/unit/common/__init__.py
Normal file
@ -17,7 +17,7 @@ import collections
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from rally import broker
|
from rally.common import broker
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ import os
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from rally import fileutils
|
from rally.common import fileutils
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class FileUtilsTestCase(test.TestCase):
|
|||||||
@mock.patch.dict('os.environ', values={}, clear=True)
|
@mock.patch.dict('os.environ', values={}, clear=True)
|
||||||
def test_load_env_vile(self, mock_path):
|
def test_load_env_vile(self, mock_path):
|
||||||
file_data = ["FAKE_ENV=fake_env\n"]
|
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:
|
read_data=file_data), create=True) as mock_file:
|
||||||
mock_file.return_value.readlines.return_value = file_data
|
mock_file.return_value.readlines.return_value = file_data
|
||||||
fileutils.load_env_file('path_to_file')
|
fileutils.load_env_file('path_to_file')
|
||||||
@ -37,7 +37,7 @@ class FileUtilsTestCase(test.TestCase):
|
|||||||
@mock.patch('os.path.exists', return_value=True)
|
@mock.patch('os.path.exists', return_value=True)
|
||||||
def test_update_env_file(self, mock_path):
|
def test_update_env_file(self, mock_path):
|
||||||
file_data = ["FAKE_ENV=old_value\n", "FAKE_ENV2=any\n"]
|
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:
|
read_data=file_data), create=True) as mock_file:
|
||||||
mock_file.return_value.readlines.return_value = file_data
|
mock_file.return_value.readlines.return_value = file_data
|
||||||
fileutils.update_env_file('path_to_file', 'FAKE_ENV', 'new_value')
|
fileutils.update_env_file('path_to_file', 'FAKE_ENV', 'new_value')
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from rally import sshutils
|
from rally.common import sshutils
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ class SSHTestCase(test.TestCase):
|
|||||||
super(SSHTestCase, self).setUp()
|
super(SSHTestCase, self).setUp()
|
||||||
self.ssh = sshutils.SSH('root', 'example.net')
|
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):
|
def test_construct(self, m_pkey):
|
||||||
m_pkey.return_value = 'pkey'
|
m_pkey.return_value = 'pkey'
|
||||||
ssh = sshutils.SSH('root', 'example.net', port=33, pkey='key',
|
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.key_filename)
|
||||||
self.assertIsNone(self.ssh.password)
|
self.assertIsNone(self.ssh.password)
|
||||||
|
|
||||||
@mock.patch('rally.sshutils.paramiko')
|
@mock.patch('rally.common.sshutils.paramiko')
|
||||||
def test__get_pkey_invalid(self, m_paramiko):
|
def test__get_pkey_invalid(self, m_paramiko):
|
||||||
m_paramiko.SSHException = FakeParamikoException
|
m_paramiko.SSHException = FakeParamikoException
|
||||||
rsa = m_paramiko.rsakey.RSAKey
|
rsa = m_paramiko.rsakey.RSAKey
|
||||||
@ -60,8 +60,8 @@ class SSHTestCase(test.TestCase):
|
|||||||
dss.from_private_key.side_effect = m_paramiko.SSHException
|
dss.from_private_key.side_effect = m_paramiko.SSHException
|
||||||
self.assertRaises(sshutils.SSHError, self.ssh._get_pkey, 'key')
|
self.assertRaises(sshutils.SSHError, self.ssh._get_pkey, 'key')
|
||||||
|
|
||||||
@mock.patch('rally.sshutils.StringIO')
|
@mock.patch('rally.common.sshutils.StringIO')
|
||||||
@mock.patch('rally.sshutils.paramiko')
|
@mock.patch('rally.common.sshutils.paramiko')
|
||||||
def test__get_pkey_dss(self, m_paramiko, m_stringio):
|
def test__get_pkey_dss(self, m_paramiko, m_stringio):
|
||||||
m_paramiko.SSHException = FakeParamikoException
|
m_paramiko.SSHException = FakeParamikoException
|
||||||
m_stringio.StringIO.return_value = 'string_key'
|
m_stringio.StringIO.return_value = 'string_key'
|
||||||
@ -74,8 +74,8 @@ class SSHTestCase(test.TestCase):
|
|||||||
self.assertEqual(key, 'dss_key')
|
self.assertEqual(key, 'dss_key')
|
||||||
m_stringio.StringIO.assert_called_once_with('key')
|
m_stringio.StringIO.assert_called_once_with('key')
|
||||||
|
|
||||||
@mock.patch('rally.sshutils.StringIO')
|
@mock.patch('rally.common.sshutils.StringIO')
|
||||||
@mock.patch('rally.sshutils.paramiko')
|
@mock.patch('rally.common.sshutils.paramiko')
|
||||||
def test__get_pkey_rsa(self, m_paramiko, m_stringio):
|
def test__get_pkey_rsa(self, m_paramiko, m_stringio):
|
||||||
m_paramiko.SSHException = FakeParamikoException
|
m_paramiko.SSHException = FakeParamikoException
|
||||||
m_stringio.StringIO.return_value = 'string_key'
|
m_stringio.StringIO.return_value = 'string_key'
|
||||||
@ -88,8 +88,8 @@ class SSHTestCase(test.TestCase):
|
|||||||
self.assertEqual(key, 'rsa_key')
|
self.assertEqual(key, 'rsa_key')
|
||||||
m_stringio.StringIO.assert_called_once_with('key')
|
m_stringio.StringIO.assert_called_once_with('key')
|
||||||
|
|
||||||
@mock.patch('rally.sshutils.SSH._get_pkey')
|
@mock.patch('rally.common.sshutils.SSH._get_pkey')
|
||||||
@mock.patch('rally.sshutils.paramiko')
|
@mock.patch('rally.common.sshutils.paramiko')
|
||||||
def test__get_client(self, m_paramiko, m_pkey):
|
def test__get_client(self, m_paramiko, m_pkey):
|
||||||
m_pkey.return_value = 'key'
|
m_pkey.return_value = 'key'
|
||||||
fake_client = mock.Mock()
|
fake_client = mock.Mock()
|
||||||
@ -114,7 +114,7 @@ class SSHTestCase(test.TestCase):
|
|||||||
m_client.close.assert_called_once_with()
|
m_client.close.assert_called_once_with()
|
||||||
self.assertFalse(self.ssh._client)
|
self.assertFalse(self.ssh._client)
|
||||||
|
|
||||||
@mock.patch('rally.sshutils.StringIO')
|
@mock.patch('rally.common.sshutils.StringIO')
|
||||||
def test_execute(self, m_stringio):
|
def test_execute(self, m_stringio):
|
||||||
m_stringio.StringIO.side_effect = stdio = [mock.Mock(), mock.Mock()]
|
m_stringio.StringIO.side_effect = stdio = [mock.Mock(), mock.Mock()]
|
||||||
stdio[0].read.return_value = 'stdout fake data'
|
stdio[0].read.return_value = 'stdout fake data'
|
||||||
@ -131,7 +131,7 @@ class SSHTestCase(test.TestCase):
|
|||||||
self.assertEqual('stdout fake data', stdout)
|
self.assertEqual('stdout fake data', stdout)
|
||||||
self.assertEqual('stderr fake data', stderr)
|
self.assertEqual('stderr fake data', stderr)
|
||||||
|
|
||||||
@mock.patch('rally.sshutils.time')
|
@mock.patch('rally.common.sshutils.time')
|
||||||
def test_wait_timeout(self, m_time):
|
def test_wait_timeout(self, m_time):
|
||||||
m_time.time.side_effect = [1, 50, 150]
|
m_time.time.side_effect = [1, 50, 150]
|
||||||
self.ssh.execute = mock.Mock(side_effect=[sshutils.SSHError,
|
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.assertRaises(sshutils.SSHTimeout, self.ssh.wait)
|
||||||
self.assertEqual([mock.call('uname')] * 2, self.ssh.execute.mock_calls)
|
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):
|
def test_wait(self, m_time):
|
||||||
m_time.time.side_effect = [1, 50, 100]
|
m_time.time.side_effect = [1, 50, 100]
|
||||||
self.ssh.execute = mock.Mock(side_effect=[sshutils.SSHError,
|
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 = sshutils.SSH('admin', 'example.net')
|
||||||
self.ssh._get_client = mock.Mock(return_value=self.fake_client)
|
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):
|
def test_execute(self, m_select):
|
||||||
m_select.select.return_value = ([], [], [])
|
m_select.select.return_value = ([], [], [])
|
||||||
self.fake_session.recv_ready.side_effect = [1, 0, 0]
|
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.assertEqual((127, 'ok', 'error'), self.ssh.execute('cmd'))
|
||||||
self.fake_session.exec_command.assert_called_once_with('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):
|
def test_run(self, m_select):
|
||||||
m_select.select.return_value = ([], [], [])
|
m_select.select.return_value = ([], [], [])
|
||||||
self.assertEqual(0, self.ssh.run('cmd'))
|
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):
|
def test_run_nonzero_status(self, m_select):
|
||||||
m_select.select.return_value = ([], [], [])
|
m_select.select.return_value = ([], [], [])
|
||||||
self.fake_session.recv_exit_status.return_value = 1
|
self.fake_session.recv_exit_status.return_value = 1
|
||||||
self.assertRaises(sshutils.SSHError, self.ssh.run, 'cmd')
|
self.assertRaises(sshutils.SSHError, self.ssh.run, 'cmd')
|
||||||
self.assertEqual(1, self.ssh.run('cmd', raise_on_error=False))
|
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):
|
def test_run_stdout(self, m_select):
|
||||||
m_select.select.return_value = ([], [], [])
|
m_select.select.return_value = ([], [], [])
|
||||||
self.fake_session.recv_ready.side_effect = [True, True, False]
|
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')],
|
self.assertEqual([mock.call('ok1'), mock.call('ok2')],
|
||||||
stdout.write.mock_calls)
|
stdout.write.mock_calls)
|
||||||
|
|
||||||
@mock.patch('rally.sshutils.select')
|
@mock.patch('rally.common.sshutils.select')
|
||||||
def test_run_stderr(self, m_select):
|
def test_run_stderr(self, m_select):
|
||||||
m_select.select.return_value = ([], [], [])
|
m_select.select.return_value = ([], [], [])
|
||||||
self.fake_session.recv_stderr_ready.side_effect = [True, False]
|
self.fake_session.recv_stderr_ready.side_effect = [True, False]
|
||||||
@ -218,7 +218,7 @@ class SSHRunTestCase(test.TestCase):
|
|||||||
self.ssh.run('cmd', stderr=stderr)
|
self.ssh.run('cmd', stderr=stderr)
|
||||||
stderr.write.assert_called_once_with('error')
|
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):
|
def test_run_stdin(self, m_select):
|
||||||
"""Test run method with stdin.
|
"""Test run method with stdin.
|
||||||
|
|
||||||
@ -241,14 +241,14 @@ class SSHRunTestCase(test.TestCase):
|
|||||||
send_calls = [call('line1'), call('line2'), call('e2')]
|
send_calls = [call('line1'), call('line2'), call('e2')]
|
||||||
self.assertEqual(send_calls, self.fake_session.send.mock_calls)
|
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):
|
def test_run_select_error(self, m_select):
|
||||||
self.fake_session.exit_status_ready.return_value = False
|
self.fake_session.exit_status_ready.return_value = False
|
||||||
m_select.select.return_value = ([], [], [True])
|
m_select.select.return_value = ([], [], [True])
|
||||||
self.assertRaises(sshutils.SSHError, self.ssh.run, 'cmd')
|
self.assertRaises(sshutils.SSHError, self.ssh.run, 'cmd')
|
||||||
|
|
||||||
@mock.patch('rally.sshutils.time')
|
@mock.patch('rally.common.sshutils.time')
|
||||||
@mock.patch('rally.sshutils.select')
|
@mock.patch('rally.common.sshutils.select')
|
||||||
def test_run_timemout(self, m_select, m_time):
|
def test_run_timemout(self, m_select, m_time):
|
||||||
m_time.time.side_effect = [1, 3700]
|
m_time.time.side_effect = [1, 3700]
|
||||||
m_select.select.return_value = ([], [], [])
|
m_select.select.return_value = ([], [], [])
|
@ -17,9 +17,9 @@
|
|||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from rally.common import sshutils
|
||||||
from rally.deploy import serverprovider
|
from rally.deploy import serverprovider
|
||||||
from rally import exceptions
|
from rally import exceptions
|
||||||
from rally import sshutils
|
|
||||||
from tests.unit import test
|
from tests.unit import test
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,8 +128,8 @@ class IterSubclassesTestCase(test.TestCase):
|
|||||||
class ImportModulesTestCase(test.TestCase):
|
class ImportModulesTestCase(test.TestCase):
|
||||||
def test_try_append_module_into_sys_modules(self):
|
def test_try_append_module_into_sys_modules(self):
|
||||||
modules = {}
|
modules = {}
|
||||||
utils.try_append_module('rally.version', modules)
|
utils.try_append_module('rally.common.version', modules)
|
||||||
self.assertIn('rally.version', modules)
|
self.assertIn('rally.common.version', modules)
|
||||||
|
|
||||||
def test_try_append_broken_module(self):
|
def test_try_append_broken_module(self):
|
||||||
modules = {}
|
modules = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user