Replace ' with " in rally/benchmark and tests/unit

Partial bug: 1405884

Change-Id: I43cb7440b7b2a284ff08538860b1f85c1da0925d
This commit is contained in:
jacobliberman 2015-02-05 11:54:56 -06:00
parent cf26ba0cf0
commit d25fd5b447
17 changed files with 365 additions and 365 deletions

View File

@ -252,7 +252,7 @@ class Verification(object):
:param deployment: UUID or name of the deployment
:param source: Source to fetch Tempest from
"""
deployment_uuid = objects.Deployment.get(deployment)['uuid']
deployment_uuid = objects.Deployment.get(deployment)["uuid"]
verifier = tempest.Tempest(deployment_uuid, source=source)
verifier.install()

View File

@ -161,4 +161,4 @@ class DesignateBasic(utils.DesignateScenario):
with different level of load.
"""
server = self._create_server()
self._delete_server(server['id'])
self._delete_server(server["id"])

View File

@ -566,7 +566,7 @@ class NovaScenario(base.Scenario):
raise exceptions.InvalidHostException(
"No valid host found to migrate")
@base.atomic_action_timer('nova.migrate')
@base.atomic_action_timer("nova.migrate")
def _migrate(self, server, skip_host_check=False):
"""Run migration of the given server.

View File

@ -281,7 +281,7 @@ def get_method_class(func):
# this check works in Python 3
cls = getattr(
inspect.getmodule(func),
func.__qualname__.split('.<locals>.', 1)[0].rsplit('.', 1)[0])
func.__qualname__.split(".<locals>.", 1)[0].rsplit(".", 1)[0])
if isinstance(cls, type):
return cls
else:

View File

@ -61,7 +61,7 @@ def _parse_assert_mock_str(line):
point = line.find(".assert_")
if point != -1:
end_pos = line[point:].find('(') + point
end_pos = line[point:].find("(") + point
return point, line[point + 1: end_pos], line[: point]
else:
return None, None, None

View File

@ -23,7 +23,7 @@ from tests.unit import test
CONF = cfg.CONF
SAHARA_JOB = "rally.benchmark.scenarios.sahara.jobs.SaharaJob"
SAHARA_UTILS = 'rally.benchmark.scenarios.sahara.utils'
SAHARA_UTILS = "rally.benchmark.scenarios.sahara.utils"
class SaharaJobTestCase(test.TestCase):
@ -34,10 +34,10 @@ class SaharaJobTestCase(test.TestCase):
CONF.set_override("cluster_check_interval", 0, "benchmark")
CONF.set_override("job_check_interval", 0, "benchmark")
@mock.patch(SAHARA_UTILS + '.SaharaScenario._generate_random_name',
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
return_value="job_42")
@mock.patch(SAHARA_JOB + "._run_job_execution")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_create_launch_job_java(self, mock_osclients, mock_run_execution,
mock_random_name):
@ -77,12 +77,12 @@ class SaharaJobTestCase(test.TestCase):
job_idx=0
)
@mock.patch(SAHARA_UTILS + '.SaharaScenario._generate_random_name',
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
return_value="job_42")
@mock.patch(SAHARA_JOB + "._run_job_execution")
@mock.patch(SAHARA_JOB + "._create_output_ds",
return_value=mock.MagicMock(id="out_42"))
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_create_launch_job_pig(self, mock_osclients, mock_create_ds,
mock_run_execution, mock_random_name):
@ -122,10 +122,10 @@ class SaharaJobTestCase(test.TestCase):
job_idx=0
)
@mock.patch(SAHARA_UTILS + '.SaharaScenario._generate_random_name',
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
return_value="job_42")
@mock.patch(SAHARA_JOB + "._run_job_execution")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_create_launch_job_sequence(self, mock_osclients,
mock_run_execution, mock_random_name):
@ -180,11 +180,11 @@ class SaharaJobTestCase(test.TestCase):
job_idx=1)]
)
@mock.patch(SAHARA_UTILS + '.SaharaScenario._generate_random_name',
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
return_value="job_42")
@mock.patch(SAHARA_JOB + "._run_job_execution")
@mock.patch(SAHARA_JOB + "._scale_cluster")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_create_launch_job_sequence_with_scaling(self, mock_osclients,
mock_scale,
mock_run_execution,

View File

@ -41,7 +41,7 @@ class VMTasksTestCase(test.TestCase):
self.scenario._associate_floating_ip = mock.MagicMock()
self.scenario._delete_server = mock.MagicMock()
self.scenario.run_command = mock.MagicMock(
return_value=(0, '\"foo_out\"', "foo_err"))
return_value=(0, "\"foo_out\"", "foo_err"))
@mock.patch(VM + "vmtasks.network_wrapper")
def test_boot_runcommand_delete_missed_networks(self, mock_wrap):
@ -56,7 +56,7 @@ class VMTasksTestCase(test.TestCase):
@mock.patch(VM + "vmtasks.network_wrapper")
def test_boot_runcommand_delete_script_fails(self, mock_wrap):
self.scenario.run_command = mock.MagicMock(
return_value=(1, '\"foo_out\"', "foo_err"))
return_value=(1, "\"foo_out\"", "foo_err"))
self.assertRaises(exceptions.ScriptError,
self.scenario.boot_runcommand_delete,
"foo_image", "foo_flavor", "foo_script",

View File

@ -26,23 +26,23 @@ ProviderFactory = serverprovider.ProviderFactory
class ExistingServersTestCase(test.TestCase):
def setUp(self):
super(ExistingServersTestCase, self).setUp()
self.config = {'type': 'ExistingServers',
'credentials': [{'user': 'user', 'host': 'host1'},
{'user': 'user', 'host': 'host2'}]}
self.config = {"type": "ExistingServers",
"credentials": [{"user": "user", "host": "host1"},
{"user": "user", "host": "host2"}]}
def test_create_servers(self):
provider = serverprovider.ProviderFactory.get_provider(self.config,
None)
credentials = provider.create_servers()
self.assertEqual(['host1', 'host2'], [s.host for s in credentials])
self.assertEqual(['user', 'user'], [s.user for s in credentials])
self.assertEqual(["host1", "host2"], [s.host for s in credentials])
self.assertEqual(["user", "user"], [s.user for s in credentials])
def test_invalid_config(self):
self.config['type'] = 42
self.config["type"] = 42
self.assertRaises(jsonschema.ValidationError,
existing.ExistingServers, None, self.config)
def test_invalid_credentials(self):
self.config['credentials'] = ['user@host1', 'user@host2']
self.config["credentials"] = ["user@host1", "user@host2"]
self.assertRaises(jsonschema.ValidationError,
existing.ExistingServers, None, self.config)

View File

@ -22,30 +22,30 @@ from rally import exceptions
from tests.unit import test
MOD_NAME = 'rally.deploy.serverprovider.providers.lxc.'
MOD_NAME = "rally.deploy.serverprovider.providers.lxc."
class HelperFunctionsTestCase(test.TestCase):
@mock.patch(MOD_NAME + 'open', create=True, return_value='fake_script')
@mock.patch(MOD_NAME + "open", create=True, return_value="fake_script")
def test__get_script(self, m_open):
script = lxc._get_script('script.sh')
self.assertEqual('fake_script', script)
script = lxc._get_script("script.sh")
self.assertEqual("fake_script", script)
path = m_open.mock_calls[0][1][0]
mode = m_open.mock_calls[0][1][1]
self.assertTrue(path.endswith('rally/deploy/serverprovider/providers'
'/lxc/script.sh'))
self.assertEqual('rb', mode)
self.assertTrue(path.endswith("rally/deploy/serverprovider/providers"
"/lxc/script.sh"))
self.assertEqual("rb", mode)
@mock.patch(MOD_NAME + '_get_script', return_value='fake_script')
@mock.patch(MOD_NAME + 'moves.StringIO')
@mock.patch(MOD_NAME + "_get_script", return_value="fake_script")
@mock.patch(MOD_NAME + "moves.StringIO")
def test__get_script_from_template(self, m_sio, m_gs):
m_gs.return_value = fake_script = mock.Mock()
fake_script.read.return_value = 'fake_data {k1} {k2}'
m_sio.return_value = 'fake_formatted_script'
script = lxc._get_script_from_template('fake_tpl', k1='v1', k2='v2')
self.assertEqual('fake_formatted_script', script)
m_sio.assert_called_once_with('fake_data v1 v2')
fake_script.read.return_value = "fake_data {k1} {k2}"
m_sio.return_value = "fake_formatted_script"
script = lxc._get_script_from_template("fake_tpl", k1="v1", k2="v2")
self.assertEqual("fake_formatted_script", script)
m_sio.assert_called_once_with("fake_data v1 v2")
class LxcHostTestCase(test.TestCase):
@ -53,34 +53,34 @@ class LxcHostTestCase(test.TestCase):
def setUp(self):
super(LxcHostTestCase, self).setUp()
sample_config = {'network': '10.1.1.0/24',
'forward_ssh': True,
'tunnel_to': ['1.1.1.1', '2.2.2.2']}
sample_config = {"network": "10.1.1.0/24",
"forward_ssh": True,
"tunnel_to": ["1.1.1.1", "2.2.2.2"]}
self.server = mock.Mock()
self.server.host = 'fake_server_ip'
self.server.get_credentials.return_value = {'ip': '3.3.3.3'}
self.server.host = "fake_server_ip"
self.server.get_credentials.return_value = {"ip": "3.3.3.3"}
self.host = lxc.LxcHost(self.server, sample_config)
@mock.patch(MOD_NAME + 'provider.Server')
@mock.patch(MOD_NAME + "provider.Server")
def test__get_updated_server(self, m_Server):
server = self.host._get_updated_server(host='4.4.4.4')
new_server = m_Server.from_credentials({'host': '4.4.4.4'})
server = self.host._get_updated_server(host="4.4.4.4")
new_server = m_Server.from_credentials({"host": "4.4.4.4"})
self.assertEqual(new_server, server)
def test_backingstore_btrfs(self):
self.server.ssh.execute.return_value = [0, '', '']
self.assertEqual('btrfs', self.host.backingstore)
self.assertEqual('btrfs', self.host.backingstore)
self.server.ssh.execute.return_value = [0, "", ""]
self.assertEqual("btrfs", self.host.backingstore)
self.assertEqual("btrfs", self.host.backingstore)
# second call will return cached value
self.assertEqual([mock.call.ssh.execute('df -t btrfs /var/lib/lxc/')],
self.assertEqual([mock.call.ssh.execute("df -t btrfs /var/lib/lxc/")],
self.server.mock_calls)
def test_backingstore_none(self):
self.server.ssh.execute.return_value = [-1, '', '']
self.assertEqual('', self.host.backingstore)
self.server.ssh.execute.return_value = [-1, "", ""]
self.assertEqual("", self.host.backingstore)
@mock.patch(MOD_NAME + 'moves.StringIO')
@mock.patch(MOD_NAME + '_get_script', return_value='fake_script')
@mock.patch(MOD_NAME + "moves.StringIO")
@mock.patch(MOD_NAME + "_get_script", return_value="fake_script")
def test_prepare(self, m_gs, m_sio):
m_sio.return_value = fake_conf = mock.Mock()
self.host.create_local_tunnels = mock.Mock()
@ -89,46 +89,46 @@ class LxcHostTestCase(test.TestCase):
self.host.prepare()
write_calls = [
mock.call('LXC_DHCP_MAX="253"\n'),
mock.call('LXC_NETMASK="255.255.255.0"\n'),
mock.call('LXC_ADDR="10.1.1.1"\n'),
mock.call('LXC_DHCP_RANGE="10.1.1.2,10.1.1.254"\n'),
mock.call('LXC_NETWORK="10.1.1.0/24"\n'),
mock.call('LXC_BRIDGE="lxcbr0"\n'),
mock.call('USE_LXC_BRIDGE="true"\n')
mock.call("LXC_DHCP_MAX=\"253\"\n"),
mock.call("LXC_NETMASK=\"255.255.255.0\"\n"),
mock.call("LXC_ADDR=\"10.1.1.1\"\n"),
mock.call("LXC_DHCP_RANGE=\"10.1.1.2,10.1.1.254\"\n"),
mock.call("LXC_NETWORK=\"10.1.1.0/24\"\n"),
mock.call("LXC_BRIDGE=\"lxcbr0\"\n"),
mock.call("USE_LXC_BRIDGE=\"true\"\n")
]
for call in write_calls:
fake_conf.write.assert_has_calls(call)
ssh_calls = [mock.call.run('cat > /tmp/.lxc_default', stdin=fake_conf),
mock.call.run('/bin/sh', stdin='fake_script')]
ssh_calls = [mock.call.run("cat > /tmp/.lxc_default", stdin=fake_conf),
mock.call.run("/bin/sh", stdin="fake_script")]
self.assertEqual(ssh_calls, self.server.ssh.mock_calls)
self.host.create_local_tunnels.assert_called_once_with()
self.host.create_remote_tunnels.assert_called_once_with()
@mock.patch(MOD_NAME + 'os.unlink')
@mock.patch(MOD_NAME + '_get_script_from_template')
@mock.patch(MOD_NAME + "os.unlink")
@mock.patch(MOD_NAME + "_get_script_from_template")
def test_create_local_tunnels(self, m_gs, m_unlink):
m_gs.side_effect = ['s1', 's2']
m_gs.side_effect = ["s1", "s2"]
self.host.create_local_tunnels()
gs_calls = [
mock.call('tunnel-local.sh', local='fake_server_ip',
net=netaddr.IPNetwork('10.1.1.0/24'), remote='1.1.1.1'),
mock.call('tunnel-local.sh', local='fake_server_ip',
net=netaddr.IPNetwork('10.1.1.0/24'), remote='2.2.2.2'),
mock.call("tunnel-local.sh", local="fake_server_ip",
net=netaddr.IPNetwork("10.1.1.0/24"), remote="1.1.1.1"),
mock.call("tunnel-local.sh", local="fake_server_ip",
net=netaddr.IPNetwork("10.1.1.0/24"), remote="2.2.2.2"),
]
self.assertEqual(gs_calls, m_gs.mock_calls)
self.assertEqual([mock.call('/bin/sh', stdin='s1'),
mock.call('/bin/sh', stdin='s2')],
self.assertEqual([mock.call("/bin/sh", stdin="s1"),
mock.call("/bin/sh", stdin="s2")],
self.server.ssh.run.mock_calls)
@mock.patch(MOD_NAME + '_get_script_from_template')
@mock.patch(MOD_NAME + "_get_script_from_template")
def test_create_remote_tunnels(self, m_get_script):
m_get_script.side_effect = ['s1', 's2']
m_get_script.side_effect = ["s1", "s2"]
fake_server = mock.Mock()
self.host._get_updated_server = mock.Mock(return_value=fake_server)
self.host.create_remote_tunnels()
self.assertEqual([mock.call('/bin/sh', stdin='s1'),
mock.call('/bin/sh', stdin='s2')],
self.assertEqual([mock.call("/bin/sh", stdin="s1"),
mock.call("/bin/sh", stdin="s2")],
fake_server.ssh.run.mock_calls)
def test_delete_tunnels(self):
@ -137,116 +137,116 @@ class LxcHostTestCase(test.TestCase):
self.host._get_updated_server = mock.Mock(side_effect=[s1, s2])
self.host.delete_tunnels()
s1.ssh.execute.assert_called_once_with('ip tun del t10.1.1.0')
s2.ssh.execute.assert_called_once_with('ip tun del t10.1.1.0')
self.assertEqual([mock.call('ip tun del t1.1.1.1'),
mock.call('ip tun del t2.2.2.2')],
s1.ssh.execute.assert_called_once_with("ip tun del t10.1.1.0")
s2.ssh.execute.assert_called_once_with("ip tun del t10.1.1.0")
self.assertEqual([mock.call("ip tun del t1.1.1.1"),
mock.call("ip tun del t2.2.2.2")],
self.server.ssh.execute.mock_calls)
@mock.patch(MOD_NAME + 'time.sleep')
@mock.patch(MOD_NAME + "time.sleep")
def test_get_ip(self, m_sleep):
s1 = 'link/ether fe:54:00:d3:f5:98 brd ff:ff:ff:ff:ff:ff'
s2 = s1 + '\n inet 10.20.0.1/24 scope global br1'
self.host.server.ssh.execute.side_effect = [(0, s1, ''), (0, s2, '')]
ip = self.host.get_ip('name')
self.assertEqual('10.20.0.1', ip)
self.assertEqual([mock.call('lxc-attach -n name ip'
' addr list dev eth0')] * 2,
s1 = "link/ether fe:54:00:d3:f5:98 brd ff:ff:ff:ff:ff:ff"
s2 = s1 + "\n inet 10.20.0.1/24 scope global br1"
self.host.server.ssh.execute.side_effect = [(0, s1, ""), (0, s2, "")]
ip = self.host.get_ip("name")
self.assertEqual("10.20.0.1", ip)
self.assertEqual([mock.call("lxc-attach -n name ip"
" addr list dev eth0")] * 2,
self.host.server.ssh.execute.mock_calls)
def test_create_container(self):
self.host.configure_container = mock.Mock()
self.host._backingstore = 'btrfs'
self.host.create_container('name', 'dist')
self.host._backingstore = "btrfs"
self.host.create_container("name", "dist")
self.server.ssh.run.assert_called_once_with(
'lxc-create -B btrfs -n name -t dist')
self.assertEqual(['name'], self.host.containers)
self.host.configure_container.assert_called_once_with('name')
"lxc-create -B btrfs -n name -t dist")
self.assertEqual(["name"], self.host.containers)
self.host.configure_container.assert_called_once_with("name")
# check with no btrfs
self.host._backingstore = ''
self.host.create_container('name', 'dist')
self.assertEqual(mock.call('lxc-create -n name -t dist'),
self.host._backingstore = ""
self.host.create_container("name", "dist")
self.assertEqual(mock.call("lxc-create -n name -t dist"),
self.server.ssh.run.mock_calls[1])
# check release
self.host.create_container('name', 'ubuntu', 'raring')
self.host.create_container('name', 'debian', 'woody')
expected = [mock.call('lxc-create -n name -t ubuntu -- -r raring'),
mock.call('SUITE=woody lxc-create -n name -t debian')]
self.host.create_container("name", "ubuntu", "raring")
self.host.create_container("name", "debian", "woody")
expected = [mock.call("lxc-create -n name -t ubuntu -- -r raring"),
mock.call("SUITE=woody lxc-create -n name -t debian")]
self.assertEqual(expected, self.server.ssh.run.mock_calls[2:])
def test_create_clone(self):
self.host._backingstore = 'btrfs'
self.host._backingstore = "btrfs"
self.host.configure_container = mock.Mock()
self.host.create_clone('name', 'src')
self.server.ssh.execute.assert_called_once_with('lxc-clone --snapshot'
' -o src -n name')
self.assertEqual(['name'], self.host.containers)
self.host.create_clone("name", "src")
self.server.ssh.execute.assert_called_once_with("lxc-clone --snapshot"
" -o src -n name")
self.assertEqual(["name"], self.host.containers)
# check with no btrfs
self.host._backingstore = ''
self.host.create_clone('name', 'src')
self.assertEqual(mock.call('lxc-clone -o src -n name'),
self.host._backingstore = ""
self.host.create_clone("name", "src")
self.assertEqual(mock.call("lxc-clone -o src -n name"),
self.server.ssh.execute.mock_calls[1])
@mock.patch(MOD_NAME + 'os.path.join')
@mock.patch(MOD_NAME + '_get_script')
@mock.patch(MOD_NAME + "os.path.join")
@mock.patch(MOD_NAME + "_get_script")
def test_configure_container(self, m_gs, m_join):
m_gs.return_value = 'fake_script'
m_join.return_value = 'fake_path'
self.server.ssh.execute.return_value = 0, '', ''
self.host.configure_container('name')
m_gs.return_value = "fake_script"
m_join.return_value = "fake_path"
self.server.ssh.execute.return_value = 0, "", ""
self.host.configure_container("name")
self.server.ssh.run.assert_called_once_with(
'/bin/sh -e -s fake_path', stdin='fake_script')
"/bin/sh -e -s fake_path", stdin="fake_script")
def test_start_containers(self):
self.host.containers = ['c1', 'c2']
self.host.containers = ["c1", "c2"]
self.host.start_containers()
calls = [mock.call('lxc-start -d -n c1'),
mock.call('lxc-start -d -n c2')]
calls = [mock.call("lxc-start -d -n c1"),
mock.call("lxc-start -d -n c2")]
self.assertEqual(calls, self.server.ssh.run.mock_calls)
def test_stop_containers(self):
self.host.containers = ['c1', 'c2']
self.host.containers = ["c1", "c2"]
self.host.stop_containers()
calls = [
mock.call('lxc-stop -n c1'),
mock.call('lxc-stop -n c2'),
mock.call("lxc-stop -n c1"),
mock.call("lxc-stop -n c2"),
]
self.assertEqual(calls, self.server.ssh.run.mock_calls)
def test_destroy_containers(self):
self.host.containers = ['c1', 'c2']
self.host.containers = ["c1", "c2"]
self.host.destroy_containers()
calls = [
mock.call('lxc-stop -n c1'), mock.call('lxc-destroy -n c1'),
mock.call('lxc-stop -n c2'), mock.call('lxc-destroy -n c2'),
mock.call("lxc-stop -n c1"), mock.call("lxc-destroy -n c1"),
mock.call("lxc-stop -n c2"), mock.call("lxc-destroy -n c2"),
]
self.assertEqual(calls, self.server.ssh.run.mock_calls)
def test_get_server_object(self):
fake_server = mock.Mock()
self.host.get_ip = mock.Mock(return_value='ip')
self.host.get_ip = mock.Mock(return_value="ip")
self.host.get_port = mock.Mock(return_value=42)
self.host._get_updated_server = mock.Mock(return_value=fake_server)
so = self.host.get_server_object('c1', wait=False)
so = self.host.get_server_object("c1", wait=False)
self.assertEqual(fake_server, so)
self.host.get_port.assert_called_once_with('ip')
self.host.get_port.assert_called_once_with("ip")
self.host._get_updated_server.assert_called_once_with(port=42)
self.assertFalse(fake_server.ssh.wait.mock_calls)
so = self.host.get_server_object('c1', wait=True)
so = self.host.get_server_object("c1", wait=True)
fake_server.ssh.wait.assert_called_once_with(timeout=300)
@mock.patch(MOD_NAME + 'LxcHost.get_server_object')
@mock.patch(MOD_NAME + "LxcHost.get_server_object")
def test_get_server_objects(self, m_gso):
m_gso.side_effect = ['s1', 's2']
self.host.containers = ['c1', 'c2']
retval = list(self.host.get_server_objects(wait='wait'))
self.assertEqual(['s1', 's2'], retval)
self.assertEqual([mock.call('c1', 'wait'), mock.call('c2', 'wait')],
m_gso.side_effect = ["s1", "s2"]
self.host.containers = ["c1", "c2"]
retval = list(self.host.get_server_objects(wait="wait"))
self.assertEqual(["s1", "s2"], retval)
self.assertEqual([mock.call("c1", "wait"), mock.call("c2", "wait")],
m_gso.mock_calls)
@ -255,18 +255,18 @@ class LxcProviderTestCase(test.TestCase):
def setUp(self):
super(LxcProviderTestCase, self).setUp()
self.config = {
'type': 'LxcProvider',
'distribution': 'ubuntu',
'start_lxc_network': '10.1.1.0/29',
'containers_per_host': 2,
'tunnel_to': ['10.10.10.10', '20.20.20.20'],
'container_name_prefix': 'rally-lxc',
'host_provider': {
'name': 'ExistingServers',
'credentials': [{'user': 'root', 'host': 'host1.net'},
{'user': 'root', 'host': 'host2.net'}]}
"type": "LxcProvider",
"distribution": "ubuntu",
"start_lxc_network": "10.1.1.0/29",
"containers_per_host": 2,
"tunnel_to": ["10.10.10.10", "20.20.20.20"],
"container_name_prefix": "rally-lxc",
"host_provider": {
"name": "ExistingServers",
"credentials": [{"user": "root", "host": "host1.net"},
{"user": "root", "host": "host2.net"}]}
}
self.deployment = {'uuid': 'fake_uuid'}
self.deployment = {"uuid": "fake_uuid"}
self.provider = lxc.LxcProvider(self.deployment, self.config)
def test_validate(self):
@ -274,19 +274,19 @@ class LxcProviderTestCase(test.TestCase):
def test_validate_invalid_tunnel(self):
config = self.config.copy()
config['tunnel_to'] = 'ok'
config["tunnel_to"] = "ok"
self.assertRaises(jsonschema.ValidationError,
lxc.LxcProvider, self.deployment, config)
def test_validate_required_field(self):
config = self.config.copy()
del(config['host_provider'])
del(config["host_provider"])
self.assertRaises(jsonschema.ValidationError,
lxc.LxcProvider, self.deployment, config)
def test_validate_too_small_network(self):
config = self.config.copy()
config['containers_per_host'] = 42
config["containers_per_host"] = 42
self.assertRaises(exceptions.InvalidConfigException,
lxc.LxcProvider, self.deployment, config)
@ -361,28 +361,28 @@ class LxcProviderTestCase(test.TestCase):
self.assertEqual(host1_calls, fake_hosts[0].mock_calls)
self.assertEqual(host2_calls, fake_hosts[1].mock_calls)
@mock.patch(MOD_NAME + 'LxcHost')
@mock.patch(MOD_NAME + 'provider.Server.from_credentials')
@mock.patch(MOD_NAME + "LxcHost")
@mock.patch(MOD_NAME + "provider.Server.from_credentials")
def test_destroy_servers(self, m_fc, m_lxchost):
fake_resource = {'info': {'config': 'fake_config',
'host': 'fake_credentials',
'forwarded_ports': [1, 2],
'container_names': ['n1', 'n2']}}
fake_resource['id'] = 'fake_res_id'
fake_resource = {"info": {"config": "fake_config",
"host": "fake_credentials",
"forwarded_ports": [1, 2],
"container_names": ["n1", "n2"]}}
fake_resource["id"] = "fake_res_id"
fake_host = mock.Mock()
m_fc.return_value = 'fake_server'
m_fc.return_value = "fake_server"
m_lxchost.return_value = fake_host
self.provider.resources = mock.Mock()
self.provider.resources.get_all.return_value = [fake_resource]
with mock.patch.object(self.provider, 'get_host_provider') as ghp:
with mock.patch.object(self.provider, "get_host_provider") as ghp:
ghp.return_value = fake_host_provider = mock.Mock()
self.provider.destroy_servers()
m_lxchost.assert_called_once_with('fake_server', 'fake_config')
m_lxchost.assert_called_once_with("fake_server", "fake_config")
host_calls = [mock.call.destroy_containers(),
mock.call.destroy_ports([1, 2]),
mock.call.delete_tunnels()]
self.assertEqual(host_calls, fake_host.mock_calls)
self.provider.resources.delete.assert_called_once_with('fake_res_id')
self.provider.resources.delete.assert_called_once_with("fake_res_id")
fake_host_provider.destroy_servers.assert_called_once_with()

View File

@ -24,7 +24,7 @@ from rally import exceptions
from tests.unit import fakes
from tests.unit import test
MOD_NAME = 'rally.deploy.serverprovider.providers.openstack'
MOD_NAME = "rally.deploy.serverprovider.providers.openstack"
OSProvider = provider.OpenStackProvider
@ -41,31 +41,31 @@ class OpenStackProviderTestCase(test.TestCase):
def setUp(self):
super(OpenStackProviderTestCase, self).setUp()
self.useFixture(mockpatch.Patch('rally.deploy.serverprovider.provider.'
'ResourceManager'))
self.useFixture(mockpatch.Patch("rally.deploy.serverprovider.provider."
"ResourceManager"))
def _get_valid_config(self):
return {
'image': {
'url': 'http://example.net/img.qcow2',
'format': 'qcow2',
'name': 'Image',
'checksum': '0123456789abcdef',
"image": {
"url": "http://example.net/img.qcow2",
"format": "qcow2",
"name": "Image",
"checksum": "0123456789abcdef",
},
'deployment_name': 'rally-dep-1',
'auth_url': 'urlto',
'user': 'name',
'password': 'mypass',
'tenant': 'tenant',
'flavor_id': '22'}
"deployment_name": "rally-dep-1",
"auth_url": "urlto",
"user": "name",
"password": "mypass",
"tenant": "tenant",
"flavor_id": "22"}
def _init_mock_clients(self):
self.clients = mock.MagicMock()
self.image = mock.MagicMock()
self.image.checksum = '0123456789abcdef'
self.image.checksum = "0123456789abcdef"
self.image.get = mock.MagicMock(return_value=self.image)
self.image.id = 'fake-uuid'
self.image.id = "fake-uuid"
self.glance_client = mock.Mock(return_value=self.image)
self.glance_client.images.create = mock.Mock(return_value=self.image)
self.glance_client.images.list = mock.Mock(return_value=[self.image])
@ -85,12 +85,12 @@ class OpenStackProviderTestCase(test.TestCase):
cfg = self._get_valid_config()
os_cli.Clients = mock.MagicMock(return_value=FakeOSClients())
os_provider = OSProvider(mock.MagicMock(), cfg)
self.assertEqual('nova', os_provider.nova)
self.assertEqual('glance', os_provider.glance)
self.assertEqual("nova", os_provider.nova)
self.assertEqual("glance", os_provider.glance)
@mock.patch('rally.osclients.Clients')
@mock.patch("rally.osclients.Clients")
def test_init_no_glance(self, mock_clients):
mock_clients.return_value.glance.side_effect = KeyError('image')
mock_clients.return_value.glance.side_effect = KeyError("image")
cfg = self._get_valid_config()
provider = OSProvider(mock.MagicMock(), cfg)
self.assertIsNone(provider.glance)
@ -107,8 +107,8 @@ class OpenStackProviderTestCase(test.TestCase):
def test_openstack_provider_init_with_invalid_conf_no_url(self,
mock_osclient):
cfg = self._get_valid_config()
del cfg['image']['url']
del cfg['image']['checksum']
del cfg["image"]["url"]
del cfg["image"]["checksum"]
self.assertRaises(jsonschema.ValidationError, OSProvider,
mock.MagicMock(), cfg)
@ -136,63 +136,63 @@ class OpenStackProviderTestCase(test.TestCase):
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
def test_openstack_provider_with_valid_config_uuid(self, mock_osclient):
cfg = self._get_valid_config()
cfg['image'] = dict(uuid="289D7A51-1A0C-43C4-800D-706EA8A3CDF3")
cfg["image"] = dict(uuid="289D7A51-1A0C-43C4-800D-706EA8A3CDF3")
OSProvider(mock.MagicMock(), cfg)
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
def test_openstack_provider_with_valid_config_checksum(self,
mock_osclient):
cfg = self._get_valid_config()
cfg['image'] = dict(checksum="checksum")
cfg["image"] = dict(checksum="checksum")
OSProvider(mock.MagicMock(), cfg)
@mock.patch('time.sleep')
@mock.patch(MOD_NAME + '.provider.Server')
@mock.patch(MOD_NAME + '.osclients')
@mock.patch(MOD_NAME + '.benchmark_utils')
@mock.patch("time.sleep")
@mock.patch(MOD_NAME + ".provider.Server")
@mock.patch(MOD_NAME + ".osclients")
@mock.patch(MOD_NAME + ".benchmark_utils")
def test_create_servers(self, bmutils, oscl, m_Server, m_sleep):
fake_keypair = mock.Mock()
fake_keypair.name = 'fake_key_name'
fake_keypair.name = "fake_key_name"
provider = OSProvider(mock.Mock(), self._get_valid_config())
provider.nova = mock.Mock()
provider.get_image_uuid = mock.Mock(return_value='fake_image_uuid')
provider.get_userdata = mock.Mock(return_value='fake_userdata')
provider.get_nics = mock.Mock(return_value='fake_nics')
provider.get_image_uuid = mock.Mock(return_value="fake_image_uuid")
provider.get_userdata = mock.Mock(return_value="fake_userdata")
provider.get_nics = mock.Mock(return_value="fake_nics")
provider.create_keypair = mock.Mock(return_value=(fake_keypair,
'fake_path'))
"fake_path"))
m_Server.return_value = fake_server = mock.Mock()
provider.nova.servers.create.return_value = fake_instance = mock.Mock()
fake_instance.addresses.values = mock.Mock(
return_value=[[{'addr': '1.2.3.4'}]])
return_value=[[{"addr": "1.2.3.4"}]])
servers = provider.create_servers()
m_Server.assert_called_once_with(host='1.2.3.4', user='root',
key='fake_path')
m_Server.assert_called_once_with(host="1.2.3.4", user="root",
key="fake_path")
self.assertEqual([fake_server], servers)
fake_server.ssh.wait.assert_called_once_with(interval=5, timeout=120)
provider.nova.servers.create.assert_called_once_with(
'rally-dep-1-0', 'fake_image_uuid', '22', userdata='fake_userdata',
nics='fake_nics', key_name='fake_key_name')
"rally-dep-1-0", "fake_image_uuid", "22", userdata="fake_userdata",
nics="fake_nics", key_name="fake_key_name")
@mock.patch(MOD_NAME + '.osclients')
@mock.patch(MOD_NAME + ".osclients")
def test_get_image_found_by_checksum(self, oscl):
self._init_mock_clients()
oscl.Clients = mock.MagicMock(return_value=self.clients)
prov = OSProvider(mock.MagicMock(), self._get_valid_config())
image_uuid = prov.get_image_uuid()
self.assertEqual(image_uuid, 'fake-uuid')
self.assertEqual(image_uuid, "fake-uuid")
@mock.patch(MOD_NAME + '.osclients')
@mock.patch(MOD_NAME + ".osclients")
def test_get_image_download(self, oscl):
self._init_mock_clients()
self.glance_client.images.list = mock.Mock(return_value=[])
oscl.Clients = mock.MagicMock(return_value=self.clients)
prov = OSProvider(mock.MagicMock(), self._get_valid_config())
image_uuid = prov.get_image_uuid()
self.assertEqual(image_uuid, 'fake-uuid')
self.assertEqual(image_uuid, "fake-uuid")
@mock.patch(MOD_NAME + '.osclients')
@mock.patch(MOD_NAME + ".osclients")
def test_get_image_no_glance_exception(
self, mock_osclients):
prov = OSProvider(mock.MagicMock(), self._get_valid_config())
@ -200,35 +200,35 @@ class OpenStackProviderTestCase(test.TestCase):
self.assertRaises(exceptions.InvalidConfigException,
prov.get_image_uuid)
@mock.patch(MOD_NAME + '.osclients')
@mock.patch(MOD_NAME + ".osclients")
def test_get_image_from_uuid_no_glance(self, mock_osclients):
conf = self._get_valid_config()
conf['image']['uuid'] = "EC7A1DB7-C5BD-49A2-8066-613809CB22F5"
conf["image"]["uuid"] = "EC7A1DB7-C5BD-49A2-8066-613809CB22F5"
prov = OSProvider(mock.MagicMock(), conf)
prov.glance = True
self.assertEqual(conf['image']['uuid'], prov.get_image_uuid())
self.assertEqual(conf["image"]["uuid"], prov.get_image_uuid())
@mock.patch(MOD_NAME + '.osclients')
@mock.patch(MOD_NAME + ".osclients")
def test_destroy_servers(self, mock_osclients):
prov = OSProvider(mock.MagicMock(), self._get_valid_config())
prov.resources.get_all.side_effect = [
[fakes.FakeResource(
id=1,
items={'info': {'id': '35FC0503-FED6-419F-B6EE-B704198CE642'}}
items={"info": {"id": "35FC0503-FED6-419F-B6EE-B704198CE642"}}
)],
[fakes.FakeResource(
id=2,
items={'info': {'id': 'keypair_name'}}
items={"info": {"id": "keypair_name"}}
)],
]
prov.destroy_servers()
prov.resources.get_all.assert_has_calls([
mock.call(type='server'),
mock.call(type='keypair'),
mock.call(type="server"),
mock.call(type="keypair"),
])
prov.nova.servers.delete.assert_called_once_with(
'35FC0503-FED6-419F-B6EE-B704198CE642')
prov.nova.keypairs.delete.assert_called_once_with('keypair_name')
"35FC0503-FED6-419F-B6EE-B704198CE642")
prov.nova.keypairs.delete.assert_called_once_with("keypair_name")
prov.resources.delete.assert_has_calls([
mock.call(1),
mock.call(2),

View File

@ -29,104 +29,104 @@ class VirshProviderTestCase(test.TestCase):
super(VirshProviderTestCase, self).setUp()
self.deployment = mock.Mock()
self.config = {
'type': 'VirshProvider',
'connection': 'user@host',
'template_name': 'prefix',
'template_user': 'user',
'template_password': 'password',
"type": "VirshProvider",
"connection": "user@host",
"template_name": "prefix",
"template_user": "user",
"template_password": "password",
}
self.provider = virsh.VirshProvider(self.deployment, self.config)
self.useFixture(mockpatch.PatchObject(self.provider, 'resources'))
self.useFixture(mockpatch.PatchObject(self.provider, "resources"))
@mock.patch(
'rally.deploy.serverprovider.providers.virsh.netaddr.IPAddress')
@mock.patch('rally.deploy.serverprovider.providers.virsh.subprocess')
@mock.patch('time.sleep')
"rally.deploy.serverprovider.providers.virsh.netaddr.IPAddress")
@mock.patch("rally.deploy.serverprovider.providers.virsh.subprocess")
@mock.patch("time.sleep")
def test_create_vm(self, mock_sleep, mock_subp, mock_ipaddress):
mock_subp.check_output.return_value = '10.0.0.1'
mock_ipaddress.return_value = '10.0.0.2'
server = self.provider.create_vm('name')
script_path = '%(virsh_path)s/virsh/get_domain_ip.sh' % dict(
mock_subp.check_output.return_value = "10.0.0.1"
mock_ipaddress.return_value = "10.0.0.2"
server = self.provider.create_vm("name")
script_path = "%(virsh_path)s/virsh/get_domain_ip.sh" % dict(
virsh_path=os.path.split(virsh.__file__)[0])
mock_subp.assert_has_calls([
mock.call.check_call('virt-clone --connect=qemu+ssh://user@host/'
'system -o prefix -n name --auto-clone',
mock.call.check_call("virt-clone --connect=qemu+ssh://user@host/"
"system -o prefix -n name --auto-clone",
shell=True),
mock.call.check_call('virsh --connect=qemu+ssh://user@host/system '
'start name', shell=True),
mock.call.check_call('scp -o StrictHostKeyChecking=no %s u'
'ser@host:~/get_domain_ip.sh' % script_path,
mock.call.check_call("virsh --connect=qemu+ssh://user@host/system "
"start name", shell=True),
mock.call.check_call("scp -o StrictHostKeyChecking=no %s u"
"ser@host:~/get_domain_ip.sh" % script_path,
shell=True),
mock.call.check_output('ssh -o StrictHostKeyChecking=no user@host '
'./get_domain_ip.sh name', shell=True),
mock.call.check_output("ssh -o StrictHostKeyChecking=no user@host "
"./get_domain_ip.sh name", shell=True),
])
mock_ipaddress.assert_called_once_with('10.0.0.1')
self.assertEqual(server.host, '10.0.0.2')
self.assertEqual(server.user, 'user')
mock_ipaddress.assert_called_once_with("10.0.0.1")
self.assertEqual(server.host, "10.0.0.2")
self.assertEqual(server.user, "user")
self.assertIsNone(server.key)
self.assertEqual(server.password, 'password')
self.assertEqual(server.password, "password")
self.provider.resources.create.assert_called_once_with({
'name': 'name',
"name": "name",
})
@mock.patch(
'rally.deploy.serverprovider.providers.virsh.netaddr.IPAddress')
@mock.patch('rally.deploy.serverprovider.providers.virsh.subprocess')
@mock.patch('time.sleep')
"rally.deploy.serverprovider.providers.virsh.netaddr.IPAddress")
@mock.patch("rally.deploy.serverprovider.providers.virsh.subprocess")
@mock.patch("time.sleep")
def test_create_vm_ip_failed(self, mock_sleep, mock_subp, mock_ipaddress):
mock_ipaddress.side_effect = netaddr.core.AddrFormatError
server = self.provider.create_vm('name')
server = self.provider.create_vm("name")
mock_subp.assert_has_calls(3 * [
mock.call.check_output('ssh -o StrictHostKeyChecking=no user@host '
'./get_domain_ip.sh name', shell=True),
mock.call.check_output("ssh -o StrictHostKeyChecking=no user@host "
"./get_domain_ip.sh name", shell=True),
])
self.assertEqual(server.host, 'None')
self.assertEqual(server.host, "None")
@mock.patch('rally.deploy.serverprovider.providers.virsh.subprocess')
@mock.patch("rally.deploy.serverprovider.providers.virsh.subprocess")
def test_destroy_vm(self, mock_subp):
self.provider.destroy_vm('uuid')
self.provider.destroy_vm("uuid")
mock_subp.assert_has_calls([
mock.call.check_call('virsh --connect=qemu+ssh://user@host/system '
'destroy uuid', shell=True),
mock.call.check_call('virsh --connect=qemu+ssh://user@host/system '
'undefine uuid --remove-all-storage',
mock.call.check_call("virsh --connect=qemu+ssh://user@host/system "
"destroy uuid", shell=True),
mock.call.check_call("virsh --connect=qemu+ssh://user@host/system "
"undefine uuid --remove-all-storage",
shell=True),
])
@mock.patch('rally.deploy.serverprovider.providers.virsh.uuid')
@mock.patch.object(virsh.VirshProvider, 'create_vm')
@mock.patch("rally.deploy.serverprovider.providers.virsh.uuid")
@mock.patch.object(virsh.VirshProvider, "create_vm")
def test_create_servers(self, mock_create, mock_uuid):
mock_uuid.uuid4.side_effect = ['1', '2', '3']
mock_create.side_effect = ['s1', 's2', 's3']
mock_uuid.uuid4.side_effect = ["1", "2", "3"]
mock_create.side_effect = ["s1", "s2", "s3"]
servers = self.provider.create_servers(amount=3)
self.assertEqual(servers, ['s1', 's2', 's3'])
self.assertEqual(servers, ["s1", "s2", "s3"])
mock_create.assert_has_calls([
mock.call('1'),
mock.call('2'),
mock.call('3'),
mock.call("1"),
mock.call("2"),
mock.call("3"),
])
@mock.patch.object(virsh.VirshProvider, 'destroy_vm')
@mock.patch.object(virsh.VirshProvider, "destroy_vm")
def test_destroy_servers(self, mock_destroy):
self.provider.resources.get_all.return_value = [
{'info': {'name': '1'}},
{'info': {'name': '2'}},
{'info': {'name': '3'}},
{"info": {"name": "1"}},
{"info": {"name": "2"}},
{"info": {"name": "3"}},
]
self.provider.destroy_servers()
mock_destroy.assert_has_calls([
mock.call('1'),
mock.call('2'),
mock.call('3'),
mock.call("1"),
mock.call("2"),
mock.call("3"),
])
self.provider.resources.get_all.assert_called_once_with()
def test_invalid_config(self):
self.config['type'] = 42
self.config["type"] = 42
self.assertRaises(jsonschema.ValidationError, virsh.VirshProvider,
self.deployment, self.config)
def test_invalid_connection(self):
self.config['connection'] = 'user host'
self.config["connection"] = "user host"
self.assertRaises(jsonschema.ValidationError, virsh.VirshProvider,
self.deployment, self.config)

View File

@ -63,7 +63,7 @@ FAKE_PROVIDERS = [ProviderA, ProviderB, ProviderC]
class ProviderTestCase(test.TestCase):
@mock.patch.object(ProviderFactory, 'validate')
@mock.patch.object(ProviderFactory, "validate")
def test_init(self, fake_validate):
ProviderA(None, None)
fake_validate.assert_called_once_with()
@ -100,8 +100,8 @@ class ProviderTestCase(test.TestCase):
class ServerTestCase(test.TestCase):
def setUp(self):
super(ServerTestCase, self).setUp()
self.vals = ['192.168.1.1', 'admin', 'some_key', 'pwd']
self.keys = ['host', 'user', 'key', 'password']
self.vals = ["192.168.1.1", "admin", "some_key", "pwd"]
self.keys = ["host", "user", "key", "password"]
def test_init_server_dto(self):
server = serverprovider.Server(*self.vals)
@ -122,19 +122,19 @@ class ResourceManagerTestCase(test.TestCase):
super(ResourceManagerTestCase, self).setUp()
self.deployment = mock.Mock()
self.resources = serverprovider.ResourceManager(self.deployment,
'provider')
"provider")
def test_create(self):
self.resources.create('info', type='type')
self.deployment.add_resource.assert_called_once_with('provider',
type='type',
info='info')
self.resources.create("info", type="type")
self.deployment.add_resource.assert_called_once_with("provider",
type="type",
info="info")
def test_get_all(self):
self.resources.get_all(type='type')
self.resources.get_all(type="type")
self.deployment.get_resources.assert_called_once_with(
provider_name='provider', type='type')
provider_name="provider", type="type")
def test_delete(self):
self.resources.delete('resource_id')
self.deployment.delete_resource.assert_called_once_with('resource_id')
self.resources.delete("resource_id")
self.deployment.delete_resource.assert_called_once_with("resource_id")

View File

@ -25,11 +25,11 @@ from tests.unit import test
def make_fake_deployment(**kwargs):
values = dict({
'uuid': '1359befb-8737-4f4e-bea9-492416106977',
'config': {
'name': 'fake',
"uuid": "1359befb-8737-4f4e-bea9-492416106977",
"config": {
"name": "fake",
},
'status': consts.DeployStatus.DEPLOY_INIT,
"status": consts.DeployStatus.DEPLOY_INIT,
}, **kwargs)
return FakeDeployment(values=values)
@ -116,10 +116,10 @@ class EngineFactoryTestCase(test.TestCase):
deploy.EngineFactory.get_engine,
"non_existing_engine", deployment)
self.assertEqual(consts.DeployStatus.DEPLOY_FAILED,
deployment['status'])
deployment["status"])
@mock.patch.object(FakeDeployment, 'set_completed')
@mock.patch.object(FakeDeployment, 'set_started')
@mock.patch.object(FakeDeployment, "set_completed")
@mock.patch.object(FakeDeployment, "set_started")
def test_make_deploy(self, mock_set_started, mock_set_completed):
deployment = make_fake_deployment()
engine = FakeEngine(deployment)
@ -130,8 +130,8 @@ class EngineFactoryTestCase(test.TestCase):
mock_set_started.assert_called_once_with()
mock_set_completed.assert_called_once_with()
@mock.patch.object(FakeDeployment, 'set_started')
@mock.patch.object(FakeEngine, 'deploy')
@mock.patch.object(FakeDeployment, "set_started")
@mock.patch.object(FakeEngine, "deploy")
def test_make_deploy_failed(self, mock_deploy, mock_set_started):
class DeployFailed(Exception):
pass
@ -142,7 +142,7 @@ class EngineFactoryTestCase(test.TestCase):
self.assertRaises(DeployFailed, engine.make_deploy)
mock_set_started.assert_called_once_with()
@mock.patch.object(FakeDeployment, 'update_status')
@mock.patch.object(FakeDeployment, "update_status")
def test_make_cleanup(self, mock_update_status):
deployment = make_fake_deployment()
engine = FakeEngine(deployment)
@ -155,8 +155,8 @@ class EngineFactoryTestCase(test.TestCase):
])
self.assertTrue(engine.cleanuped)
@mock.patch.object(FakeDeployment, 'update_status')
@mock.patch.object(FakeEngine, 'cleanup')
@mock.patch.object(FakeDeployment, "update_status")
@mock.patch.object(FakeEngine, "cleanup")
def test_make_cleanup_failed(self, mock_cleanup, mock_update_status):
class CleanUpFailed(Exception):
pass
@ -170,7 +170,7 @@ class EngineFactoryTestCase(test.TestCase):
])
self.assertFalse(engine.cleanuped)
@mock.patch.object(FakeDeployment, 'update_status')
@mock.patch.object(FakeDeployment, "update_status")
def test_with_statement(self, mock_update_status):
deployment = make_fake_deployment()
engine = FakeEngine(deployment)
@ -200,7 +200,7 @@ class EngineFactoryTestCase(test.TestCase):
consts.DeployStatus.CLEANUP_STARTED,
consts.DeployStatus.CLEANUP_FAILED)
@mock.patch.object(FakeDeployment, 'update_status')
@mock.patch.object(FakeDeployment, "update_status")
def _assert_changed_status_on_error(self, initial, final,
mock_update_status):
# NOTE(akscram): The assertRaises of testtools can't be used as

View File

@ -19,7 +19,7 @@ from rally.deploy import engine
from rally import objects
from tests.unit import test
MOD = 'rally.deploy.engines.lxc.'
MOD = "rally.deploy.engines.lxc."
class LxcEngineTestCase(test.TestCase):
@ -27,35 +27,35 @@ class LxcEngineTestCase(test.TestCase):
def setUp(self):
super(LxcEngineTestCase, self).setUp()
self.config = {
'type': 'LxcEngine',
'container_name': 'rally',
'containers_per_host': 2,
'tunnel_to': ['1.1.1.1', '2.2.2.2'],
'distribution': 'ubuntu',
'start_lxc_network': '10.128.128.0/28',
'engine': {
'name': 'FakeEngine',
'config': {
'key': 'value',
"type": "LxcEngine",
"container_name": "rally",
"containers_per_host": 2,
"tunnel_to": ["1.1.1.1", "2.2.2.2"],
"distribution": "ubuntu",
"start_lxc_network": "10.128.128.0/28",
"engine": {
"name": "FakeEngine",
"config": {
"key": "value",
},
},
'provider': {
'type': 'DummyProvider',
'credentials': [{'user': 'root', 'host': 'host1.net'},
{'user': 'root', 'host': 'host2.net'}]
"provider": {
"type": "DummyProvider",
"credentials": [{"user": "root", "host": "host1.net"},
{"user": "root", "host": "host2.net"}]
}
}
self.deployment = {
'uuid': 'test-deployment-uuid',
'config': self.config,
"uuid": "test-deployment-uuid",
"config": self.config,
}
self.engine = engine.EngineFactory.get_engine('LxcEngine',
self.engine = engine.EngineFactory.get_engine("LxcEngine",
self.deployment)
@mock.patch(MOD + 'objects')
@mock.patch(MOD + 'engine')
@mock.patch(MOD + "objects")
@mock.patch(MOD + "engine")
def test__deploy_first(self, m_engine, m_objects):
fake_credentials = {'user': 'admin', 'host': 'host.net'}
fake_credentials = {"user": "admin", "host": "host.net"}
fake_deployment = mock.Mock()
fake_engine = mock.Mock()
m_objects.Deployment = mock.Mock(return_value=fake_deployment)
@ -65,29 +65,29 @@ class LxcEngineTestCase(test.TestCase):
fake_so = mock.Mock()
fake_so.get_credentials.return_value = fake_credentials
fake_host.get_server_object = mock.Mock(return_value=fake_so)
self.engine._deploy_first(fake_host, 'name', 'dist', 'release')
self.engine._deploy_first(fake_host, "name", "dist", "release")
host_calls = [
mock.call.prepare(),
mock.call.create_container('name', 'dist', 'release'),
mock.call.create_container("name", "dist", "release"),
mock.call.start_containers(),
mock.call.get_server_object('name'),
mock.call.get_server_object("name"),
mock.call.stop_containers()]
self.assertEqual(host_calls, fake_host.mock_calls)
fake_engine.deploy.assert_called_once_with()
m_engine.EngineFactory.get_engine.assert_called_once_with(
'FakeEngine', fake_deployment)
engine_config = self.config['engine'].copy()
engine_config['provider'] = {'credentials': [fake_credentials],
'type': 'DummyProvider'}
"FakeEngine", fake_deployment)
engine_config = self.config["engine"].copy()
engine_config["provider"] = {"credentials": [fake_credentials],
"type": "DummyProvider"}
m_objects.Deployment.assert_called_once_with(
config=engine_config, parent_uuid='test-deployment-uuid')
config=engine_config, parent_uuid="test-deployment-uuid")
@mock.patch(MOD + 'provider.ProviderFactory.get_provider')
@mock.patch(MOD + "provider.ProviderFactory.get_provider")
def test__get_provider(self, m_get_provider):
m_get_provider.return_value = 'fake_provider'
m_get_provider.return_value = "fake_provider"
provider = self.engine._get_provider()
self.assertEqual('fake_provider', provider)
m_get_provider.assert_called_once_with(self.config['provider'],
self.assertEqual("fake_provider", provider)
m_get_provider.assert_called_once_with(self.config["provider"],
self.deployment)
@mock.patch(MOD + "open", create=True)
@ -181,27 +181,27 @@ class LxcEngineTestCase(test.TestCase):
self.assertEqual([mock.call.ssh.run("/bin/sh -e", stdin="fs")],
container.mock_calls)
@mock.patch(MOD + 'LxcEngine._get_provider')
@mock.patch(MOD + 'lxc.LxcHost')
@mock.patch(MOD + 'provider.Server.from_credentials')
@mock.patch(MOD + "LxcEngine._get_provider")
@mock.patch(MOD + "lxc.LxcHost")
@mock.patch(MOD + "provider.Server.from_credentials")
def test_cleanup(self, m_from_c, m_lxc_host, m_get_provider):
m_get_provider.return_value = fake_provider = mock.Mock()
m_lxc_host.side_effect = fake_hosts = [mock.Mock(), mock.Mock()]
m_from_c.side_effect = ['s1', 's2']
m_from_c.side_effect = ["s1", "s2"]
fake_resources = []
for i in range(2):
res = mock.Mock()
res.info = {'host': 'host%d' % i,
'config': 'fake_config%d' % i,
'forwarded_ports': [(1, 2), (3, 4)],
'containers': 'fake_containers'}
res.info = {"host": "host%d" % i,
"config": "fake_config%d" % i,
"forwarded_ports": [(1, 2), (3, 4)],
"containers": "fake_containers"}
fake_resources.append(res)
with mock.patch.object(self.engine, 'deployment') as m_deployment:
with mock.patch.object(self.engine, "deployment") as m_deployment:
m_deployment.get_resources.return_value = fake_resources
self.engine.cleanup()
for host in fake_hosts:
self.assertEqual('fake_containers', host.containers)
self.assertEqual("fake_containers", host.containers)
self.assertEqual([mock.call.destroy_containers(),
mock.call.destroy_ports([(1, 2), (3, 4)]),
mock.call.delete_tunnels()], host.mock_calls)

View File

@ -21,7 +21,7 @@ from rally import deploy
from tests.unit import fakes
from tests.unit import test
MOD = 'rally.deploy.engines.multihost.'
MOD = "rally.deploy.engines.multihost."
class TestMultihostEngine(test.TestCase):
@ -31,29 +31,29 @@ class TestMultihostEngine(test.TestCase):
"type": "MultihostEngine",
"controller": {
"type": "DummyEngine",
"endpoint": {'auth_url': 'http://h1.net'}
"endpoint": {"auth_url": "http://h1.net"}
},
"nodes": [
{
"type": "DummyEngine",
"endpoint": {'auth_url': 'endpoint1'},
"endpoint": {"auth_url": "endpoint1"},
},
{
"type": "DummyEngine",
"endpoint": {'auth_url': 'endpoint2',
'cnt': '{controller_ip}'}
"endpoint": {"auth_url": "endpoint2",
"cnt": "{controller_ip}"}
}
]
}
self.deployment = fakes.FakeDeployment(
uuid='905b2f16-6453-4b86-8ba5-6d32025fcfa6',
uuid="905b2f16-6453-4b86-8ba5-6d32025fcfa6",
config=self.config,
)
self.engine = deploy.engine.EngineFactory.get_engine('MultihostEngine',
self.engine = deploy.engine.EngineFactory.get_engine("MultihostEngine",
self.deployment)
@mock.patch(MOD + 'objects.Deployment')
@mock.patch(MOD + 'engine.EngineFactory')
@mock.patch(MOD + "objects.Deployment")
@mock.patch(MOD + "engine.EngineFactory")
def test__deploy_node(self, fakeEngineFactory, fakeDeployment):
fake_endpoint = mock.Mock()
fake_deployment = mock.Mock()
@ -65,50 +65,50 @@ class TestMultihostEngine(test.TestCase):
fakeDeployment.return_value = fake_deployment
fakeEngineFactory.get_engine = mock.Mock(return_value=fake_engine)
engine, endpoint = self.engine._deploy_node(self.config['nodes'][0])
engine, endpoint = self.engine._deploy_node(self.config["nodes"][0])
self.assertEqual(fake_engine, engine)
self.assertEqual(fake_endpoint, endpoint)
fakeDeployment.assert_called_once_with(
config=self.config['nodes'][0],
parent_uuid=self.deployment['uuid'])
config=self.config["nodes"][0],
parent_uuid=self.deployment["uuid"])
fake_engine.__enter__.assert_called_once_with()
fake_engine.__exit__.assert_called_once_with(None, None, None)
def test__update_controller_ip(self):
self.engine.controller_ip = '1.2.3.4'
self.engine.controller_ip = "1.2.3.4"
self.engine._update_controller_ip(self.config)
expected = {'auth_url': 'endpoint2', 'cnt': '1.2.3.4'}
self.assertEqual(expected, self.config['nodes'][1]['endpoint'])
expected = {"auth_url": "endpoint2", "cnt": "1.2.3.4"}
self.assertEqual(expected, self.config["nodes"][1]["endpoint"])
@mock.patch(MOD + 'MultihostEngine._deploy_node')
@mock.patch(MOD + 'MultihostEngine._update_controller_ip')
@mock.patch(MOD + "MultihostEngine._deploy_node")
@mock.patch(MOD + "MultihostEngine._update_controller_ip")
def test_deploy(self, update_ip, deploy_node):
fake_endpoints = [mock.Mock()]
fake_endpoints[0].auth_url = 'http://h1.net'
fake_endpoints[0].auth_url = "http://h1.net"
deploy_node.return_value = [mock.Mock(), fake_endpoints]
endpoints = self.engine.deploy()
self.assertEqual(self.engine.controller_ip, 'h1.net')
self.assertEqual(self.engine.controller_ip, "h1.net")
self.assertEqual(fake_endpoints, endpoints)
expected = [
mock.call(self.config['nodes'][0]),
mock.call(self.config['nodes'][1]),
mock.call(self.config["nodes"][0]),
mock.call(self.config["nodes"][1]),
]
self.assertEqual(expected, update_ip.mock_calls)
self.deployment.update_status.assert_called_once_with(
consts._DeployStatus.DEPLOY_SUBDEPLOY)
@mock.patch('rally.api')
@mock.patch(MOD + 'db')
@mock.patch("rally.api")
@mock.patch(MOD + "db")
def test_cleanup(self, m_db, m_api):
m_db.deployment_list.return_value = [{'uuid': 'uuid1'},
{'uuid': 'uuid2'}]
m_db.deployment_list.return_value = [{"uuid": "uuid1"},
{"uuid": "uuid2"}]
self.engine.cleanup()
api_calls = [
mock.call.Deployment.destroy('uuid1'),
mock.call.Deployment.destroy('uuid2'),
mock.call.Deployment.destroy("uuid1"),
mock.call.Deployment.destroy("uuid2"),
]
self.assertEqual(api_calls, m_api.mock_calls)

View File

@ -150,5 +150,5 @@ class TaskTestCase(test.TestCase):
task.set_failed()
mock_update.assert_called_once_with(
self.task["uuid"],
{"status": consts.TaskStatus.FAILED, "verification_log": '""'},
{"status": consts.TaskStatus.FAILED, "verification_log": "\"\""},
)

View File

@ -41,7 +41,7 @@ downloadcache = ~/cache/pip
ignore = E126,H703
show-source = true
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,build,*rally/openstack*
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,build,*rally/openstack*,setup.py
[hacking]
import_exceptions = rally.common.i18n