use CONF in glance benchmark

Using CONF instead of hard codes is a more consistent way in
benchmark scenarios.

Change-Id: I4fa5566b7698b6a9285f01fa47a2fd1f179a7502
This commit is contained in:
Kun Huang 2014-03-06 01:47:11 +08:00
parent 7c1507940f
commit 1a0f3f1ca8
3 changed files with 45 additions and 12 deletions

1
.gitignore vendored
View File

@ -37,3 +37,4 @@ cover
.mr.developer.cfg
.project
.pydevproject
*.swp

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo.config import cfg
import random
import string
import time
@ -23,6 +24,33 @@ from rally.benchmark import utils as bench_utils
from rally import utils
glance_benchmark_opts = [
cfg.FloatOpt('glance_image_create_prepoll_delay',
default=2,
help='Time to sleep after creating a resource before '
'polling for it status'),
cfg.FloatOpt('glance_image_create_timeout',
default=120,
help='Time to wait for glance image to be created.'),
cfg.FloatOpt('glance_image_create_poll_interval',
default=1,
help='Interval between checks when waiting for image '
'creation.'),
cfg.FloatOpt('glance_image_delete_timeout',
default=120,
help='Time to wait for glance image to be deleted.'),
cfg.FloatOpt('glance_image_delete_poll_interval',
default=1,
help='Interval between checks when waiting for image '
'deletion.')
]
CONF = cfg.CONF
benchmark_group = cfg.OptGroup(name='benchmark', title='benchmark options')
CONF.register_opts(glance_benchmark_opts, group=benchmark_group)
class GlanceScenario(base.Scenario):
@scenario_utils.atomic_action_timer('glance.create_image')
@ -46,11 +74,13 @@ class GlanceScenario(base.Scenario):
container_format=container_format,
disk_format=disk_format,
**kwargs)
time.sleep(5)
image = utils.wait_for(image,
is_ready=bench_utils.resource_is("active"),
update_resource=bench_utils.get_from_manager(),
timeout=120, check_interval=3)
time.sleep(CONF.benchmark.glance_image_create_prepoll_delay)
image = utils.wait_for(
image,
is_ready=bench_utils.resource_is("active"),
update_resource=bench_utils.get_from_manager(),
timeout=CONF.benchmark.glance_image_create_timeout,
check_interval=CONF.benchmark.glance_image_create_poll_interval)
return image
@scenario_utils.atomic_action_timer('glance.delete_image')
@ -62,9 +92,11 @@ class GlanceScenario(base.Scenario):
:param image: Image object
"""
image.delete()
utils.wait_for_delete(image,
update_resource=bench_utils.get_from_manager(),
timeout=120, check_interval=3)
utils.wait_for_delete(
image,
update_resource=bench_utils.get_from_manager(),
timeout=CONF.benchmark.glance_image_delete_timeout,
check_interval=CONF.benchmark.glance_image_delete_poll_interval)
def _generate_random_name(self, length):
name = ''.join(random.choice(string.lowercase) for i in range(length))

View File

@ -64,7 +64,7 @@ class GlanceScenarioTestCase(test.TestCase):
self.assertIsInstance(action_duration, float)
@mock.patch(GLANCE_UTILS + '.GlanceScenario.clients')
def test__create_image(self, mock_clients):
def test_create_image(self, mock_clients):
mock_clients("glance").images.create.return_value = self.image
scenario = utils.GlanceScenario()
return_image = scenario._create_image('image_name',
@ -74,21 +74,21 @@ class GlanceScenarioTestCase(test.TestCase):
self.wait_for.mock.assert_called_once_with(self.image,
update_resource=self.gfm(),
is_ready=self.res_is.mock(),
check_interval=3,
check_interval=1,
timeout=120)
self.res_is.mock.assert_has_calls(mock.call('active'))
self.assertEqual(self.wait_for.mock(), return_image)
self._test_atomic_action_timer(scenario.atomic_actions_time(),
'glance.create_image')
def test__delete_image(self):
def test_delete_image(self):
scenario = utils.GlanceScenario()
scenario._delete_image(self.image)
self.image.delete.assert_called_once_with()
self.wait_for_delete.\
mock.assert_called_once_with(self.image,
update_resource=self.gfm(),
check_interval=3,
check_interval=1,
timeout=120)
self._test_atomic_action_timer(scenario.atomic_actions_time(),
'glance.delete_image')