Merge "Fix EC2 utils and tests"
This commit is contained in:
commit
044d6f34b1
@ -44,12 +44,6 @@ benchmark_group = cfg.OptGroup(name="benchmark",
|
||||
CONF.register_opts(EC2_BENCHMARK_OPTS, group=benchmark_group)
|
||||
|
||||
|
||||
def ec2_resource_is(status):
|
||||
"""Check status for EC2."""
|
||||
|
||||
return lambda resource: resource.state.upper() == status.upper()
|
||||
|
||||
|
||||
class EC2Scenario(base.Scenario):
|
||||
"""Base class for EC2 scenarios with basic atomic actions."""
|
||||
|
||||
@ -74,7 +68,7 @@ class EC2Scenario(base.Scenario):
|
||||
time.sleep(CONF.benchmark.ec2_server_boot_prepoll_delay)
|
||||
server = utils.wait_for(
|
||||
server,
|
||||
is_ready=ec2_resource_is("RUNNING"),
|
||||
is_ready=utils.resource_is("RUNNING"),
|
||||
update_resource=self._update_resource,
|
||||
timeout=CONF.benchmark.ec2_server_boot_timeout,
|
||||
check_interval=CONF.benchmark.ec2_server_boot_poll_interval
|
||||
|
@ -18,28 +18,11 @@ from rally.plugins.openstack.scenarios.ec2 import servers
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
UTILS = "rally.plugins.openstack.scenarios.ec2.utils."
|
||||
|
||||
|
||||
class EC2ServersTestCase(test.ScenarioTestCase):
|
||||
|
||||
@mock.patch(UTILS + "ec2_resource_is", return_value="foo_state")
|
||||
@mock.patch(UTILS + "CONF")
|
||||
def test_boot_server(self, mock_conf, mock_ec2_resource_is):
|
||||
mock_conf.benchmark.ec2_server_boot_prepoll_delay = "foo_delay"
|
||||
mock_conf.benchmark.ec2_server_boot_timeout = "foo_timeout"
|
||||
mock_conf.benchmark.ec2_server_boot_poll_interval = "foo_interval"
|
||||
|
||||
def test_boot_server(self):
|
||||
scenario = servers.EC2Servers()
|
||||
scenario._update_resource = "foo_update"
|
||||
mock_instances = mock.Mock(instances=["foo_inst"])
|
||||
self.clients("ec2").run_instances.return_value = mock_instances
|
||||
server = scenario._boot_server("foo_image", "foo_flavor", foo="bar")
|
||||
|
||||
self.mock_wait_for.mock.assert_called_once_with(
|
||||
"foo_inst", is_ready="foo_state",
|
||||
update_resource="foo_update",
|
||||
timeout="foo_timeout",
|
||||
check_interval="foo_interval")
|
||||
self.mock_sleep.mock.assert_called_once_with("foo_delay")
|
||||
self.assertEqual(server, self.mock_wait_for.mock.return_value)
|
||||
scenario._boot_server = mock.Mock()
|
||||
scenario.boot_server("foo_image", "foo_flavor", foo="bar")
|
||||
scenario._boot_server.assert_called_once_with(
|
||||
"foo_image", "foo_flavor", foo="bar")
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslotest import mockpatch
|
||||
|
||||
from rally.plugins.openstack.scenarios.ec2 import utils
|
||||
from tests.unit import test
|
||||
@ -23,44 +22,31 @@ EC2_UTILS = "rally.plugins.openstack.scenarios.ec2.utils"
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class EC2UtilsTestCase(test.TestCase):
|
||||
|
||||
def test_ec2_resource_is(self):
|
||||
resource = mock.MagicMock(state="RUNNING")
|
||||
resource_is = utils.ec2_resource_is("RUNNING")
|
||||
self.assertTrue(resource_is(resource))
|
||||
resource.state = "PENDING"
|
||||
self.assertFalse(resource_is(resource))
|
||||
|
||||
def test__update_resource(self):
|
||||
resource = mock.MagicMock()
|
||||
utils.EC2Scenario()._update_resource(resource)
|
||||
resource.update.assert_called_once_with()
|
||||
|
||||
|
||||
class EC2ScenarioTestCase(test.ScenarioTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(EC2ScenarioTestCase, self).setUp()
|
||||
self.server = mock.MagicMock()
|
||||
self.reservation = mock.MagicMock(instances=[self.server])
|
||||
self.mock_resource_is = mockpatch.Patch(EC2_UTILS + ".ec2_resource_is")
|
||||
self.mock_update_resource = mockpatch.Patch(
|
||||
EC2_UTILS + ".EC2Scenario._update_resource")
|
||||
self.useFixture(self.mock_resource_is)
|
||||
self.useFixture(self.mock_update_resource)
|
||||
|
||||
def test__boot_server(self):
|
||||
self.clients("ec2").run_instances.return_value = self.reservation
|
||||
ec2_scenario = utils.EC2Scenario(context={})
|
||||
ec2_scenario._update_resource = mock.Mock()
|
||||
return_server = ec2_scenario._boot_server("image", "flavor")
|
||||
self.mock_wait_for.mock.assert_called_once_with(
|
||||
self.server,
|
||||
is_ready=self.mock_resource_is.mock.return_value,
|
||||
update_resource=self.mock_update_resource.mock,
|
||||
update_resource=ec2_scenario._update_resource,
|
||||
check_interval=CONF.benchmark.ec2_server_boot_poll_interval,
|
||||
timeout=CONF.benchmark.ec2_server_boot_timeout)
|
||||
self.mock_resource_is.mock.assert_called_once_with("RUNNING")
|
||||
self.assertEqual(self.mock_wait_for.mock.return_value, return_server)
|
||||
self._test_atomic_action_timer(ec2_scenario.atomic_actions(),
|
||||
"ec2.boot_server")
|
||||
|
||||
def test__update_resource(self):
|
||||
resource = mock.MagicMock()
|
||||
scenario = utils.EC2Scenario()
|
||||
self.assertEqual(scenario._update_resource(resource), resource)
|
||||
resource.update.assert_called_once_with()
|
||||
|
Loading…
Reference in New Issue
Block a user