aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py72
-rw-r--r--functest/opnfv_tests/openstack/rally/scenario/opnfv-vm.yaml42
-rw-r--r--functest/opnfv_tests/openstack/rally/scenario/support/instance_dd_test.sh13
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py59
-rw-r--r--tox.ini1
5 files changed, 69 insertions, 118 deletions
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index afaed4c65..a91059a2b 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -38,7 +38,7 @@ class RallyBase(singlevm.VmReady2):
# pylint: disable=too-many-instance-attributes
TESTS = ['authenticate', 'glance', 'cinder', 'gnocchi', 'heat',
- 'keystone', 'neutron', 'nova', 'quotas', 'vm', 'all']
+ 'keystone', 'neutron', 'nova', 'quotas']
RALLY_DIR = pkg_resources.resource_filename(
'functest', 'opnfv_tests/openstack/rally')
@@ -75,7 +75,6 @@ class RallyBase(singlevm.VmReady2):
project=self.project.project.id,
domain=self.project.domain.id)
self.creators = []
- self.mode = ''
self.summary = []
self.scenario_dir = ''
self.smoke = None
@@ -85,6 +84,9 @@ class RallyBase(singlevm.VmReady2):
self.details = None
self.compute_cnt = 0
self.flavor_alt = None
+ self.tests = []
+ self.task_file = ''
+ self.run_cmd = ''
def _build_task_args(self, test_file_name):
"""Build arguments for the Rally task."""
@@ -328,25 +330,11 @@ class RallyBase(singlevm.VmReady2):
else:
LOGGER.info('Test scenario: "%s" Failed.', test_name)
- def _run_task(self, test_name):
+ def run_task(self, test_name):
"""Run a task."""
LOGGER.info('Starting test scenario "%s" ...', test_name)
-
- task_file = os.path.join(self.RALLY_DIR, 'task.yaml')
- if not os.path.exists(task_file):
- LOGGER.error("Task file '%s' does not exist.", task_file)
- raise Exception("Task file '{}' does not exist.".format(task_file))
-
- file_name = self._prepare_test_list(test_name)
- if self.file_is_empty(file_name):
- LOGGER.info('No tests for scenario "%s"', test_name)
- return
-
- cmd = (["rally", "task", "start", "--abort-on-sla-failure", "--task",
- task_file, "--task-args",
- str(self._build_task_args(test_name))])
- LOGGER.debug('running command: %s', cmd)
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ LOGGER.debug('running command: %s', self.run_cmd)
+ proc = subprocess.Popen(self.run_cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output = proc.communicate()[0]
@@ -356,7 +344,6 @@ class RallyBase(singlevm.VmReady2):
LOGGER.error("Failed to retrieve task_id")
LOGGER.error("Result:\n%s", output)
raise Exception("Failed to retrieve task id")
-
self._save_results(test_name, task_id)
def _append_summary(self, json_raw, test_name):
@@ -386,26 +373,43 @@ class RallyBase(singlevm.VmReady2):
'task_status': self.task_succeed(json_raw)}
self.summary.append(scenario_summary)
- def _prepare_env(self):
- """Create resources needed by test scenarios."""
+ def prepare_run(self):
+ """Prepare resources needed by test scenarios."""
assert self.cloud
LOGGER.debug('Validating the test name...')
- if self.test_name not in self.TESTS:
+ if self.test_name == 'all':
+ self.tests = self.TESTS
+ elif self.test_name in self.TESTS:
+ self.tests = [self.test_name]
+ else:
raise Exception("Test name '%s' is invalid" % self.test_name)
+ self.task_file = os.path.join(self.RALLY_DIR, 'task.yaml')
+ if not os.path.exists(self.task_file):
+ LOGGER.error("Task file '%s' does not exist.", self.task_file)
+ raise Exception("Task file '{}' does not exist.".
+ format(self.task_file))
+
self.compute_cnt = len(self.cloud.list_hypervisors())
self.flavor_alt = self.create_flavor_alt()
LOGGER.debug("flavor: %s", self.flavor_alt)
- def _run_tests(self):
+ def prepare_task(self, test_name):
+ """Prepare resources for test run."""
+ file_name = self._prepare_test_list(test_name)
+ if self.file_is_empty(file_name):
+ LOGGER.info('No tests for scenario "%s"', test_name)
+ return False
+ self.run_cmd = (["rally", "task", "start", "--abort-on-sla-failure",
+ "--task", self.task_file, "--task-args",
+ str(self._build_task_args(test_name))])
+ return True
+
+ def run_tests(self):
"""Execute tests."""
- if self.test_name == 'all':
- for test in self.TESTS:
- if test == 'all' or test == 'vm':
- continue
- self._run_task(test)
- else:
- self._run_task(self.test_name)
+ for test in self.tests:
+ if self.prepare_task(test):
+ self.run_task(test)
def _generate_report(self):
"""Generate test execution summary report."""
@@ -492,8 +496,8 @@ class RallyBase(singlevm.VmReady2):
OS_PROJECT_ID=self.project.project.id,
OS_PASSWORD=self.project.password)
conf_utils.create_rally_deployment(environ=environ)
- self._prepare_env()
- self._run_tests()
+ self.prepare_run()
+ self.run_tests()
self._generate_report()
res = testcase.TestCase.EX_OK
except Exception as exc: # pylint: disable=broad-except
@@ -512,7 +516,6 @@ class RallySanity(RallyBase):
if "case_name" not in kwargs:
kwargs["case_name"] = "rally_sanity"
super(RallySanity, self).__init__(**kwargs)
- self.mode = 'sanity'
self.test_name = 'all'
self.smoke = True
self.scenario_dir = os.path.join(self.RALLY_SCENARIO_DIR, 'sanity')
@@ -526,7 +529,6 @@ class RallyFull(RallyBase):
if "case_name" not in kwargs:
kwargs["case_name"] = "rally_full"
super(RallyFull, self).__init__(**kwargs)
- self.mode = 'full'
self.test_name = 'all'
self.smoke = False
self.scenario_dir = os.path.join(self.RALLY_SCENARIO_DIR, 'full')
diff --git a/functest/opnfv_tests/openstack/rally/scenario/opnfv-vm.yaml b/functest/opnfv_tests/openstack/rally/scenario/opnfv-vm.yaml
deleted file mode 100644
index 74f509925..000000000
--- a/functest/opnfv_tests/openstack/rally/scenario/opnfv-vm.yaml
+++ /dev/null
@@ -1,42 +0,0 @@
- VMTasks.boot_runcommand_delete:
- -
- args:
- {{ vm_params(image_name, flavor_name) }}
- floating_network: {{ floating_network }}
- force_delete: false
- command:
- interpreter: /bin/sh
- script_file: {{ sup_dir }}/instance_dd_test.sh
- username: cirros
- nics:
- - net-id: {{ netid }}
- context:
- {% call user_context(tenants_amount, users_amount, use_existing_users) %}
- network: {}
- {% endcall %}
- runner:
- {{ constant_runner(concurrency=concurrency, times=iterations, is_smoke=smoke) }}
- sla:
- {{ no_failures_sla() }}
-
- -
- args:
- {{ vm_params(image_name, flavor_name) }}
- fixed_network: private
- floating_network: {{ floating_network }}
- force_delete: false
- command:
- interpreter: /bin/sh
- script_file: {{ sup_dir }}/instance_dd_test.sh
- use_floatingip: true
- username: cirros
- nics:
- - net-id: {{ netid }}
- volume_args:
- size: 2
- context:
- {{ user_context(tenants_amount, users_amount, use_existing_users) }}
- runner:
- {{ constant_runner(concurrency=concurrency, times=iterations, is_smoke=smoke) }}
- sla:
- {{ no_failures_sla() }}
diff --git a/functest/opnfv_tests/openstack/rally/scenario/support/instance_dd_test.sh b/functest/opnfv_tests/openstack/rally/scenario/support/instance_dd_test.sh
deleted file mode 100644
index e3bf23405..000000000
--- a/functest/opnfv_tests/openstack/rally/scenario/support/instance_dd_test.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-time_seconds(){ (time -p $1 ) 2>&1 |awk '/real/{print $2}'; }
-file=/tmp/test.img
-c=${1:-$SIZE}
-c=${c:-1000} #default is 1GB
-write_seq=$(time_seconds "dd if=/dev/zero of=$file bs=1M count=$c")
-read_seq=$(time_seconds "dd if=$file of=/dev/null bs=1M count=$c")
-[ -f $file ] && rm $file
-
-echo "{
- \"write_seq_${c}m\": $write_seq,
- \"read_seq_${c}m\": $read_seq
- }"
diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py
index 401f043aa..d89ebd634 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -30,6 +30,7 @@ class OSRallyTesting(unittest.TestCase):
self.rally_base.image = munch.Munch(name='foo')
self.rally_base.flavor = munch.Munch(name='foo')
self.rally_base.flavor_alt = munch.Munch(name='bar')
+ self.rally_base.test_name = 'all'
self.assertTrue(mock_get_config.called)
self.assertTrue(mock_shade.called)
self.assertTrue(mock_new_project.called)
@@ -181,25 +182,21 @@ class OSRallyTesting(unittest.TestCase):
return_value=False)
def test_run_task_missing_task_file(self, mock_path_exists):
with self.assertRaises(Exception):
- self.rally_base._run_task('test_name')
+ self.rally_base.prepare_run()
mock_path_exists.assert_called()
- @mock.patch('functest.opnfv_tests.openstack.rally.rally.os.path.exists',
- return_value=True)
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_prepare_test_list', return_value='test_file_name')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'file_is_empty', return_value=True)
@mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.info')
- def test_run_task_no_tests_for_scenario(self, mock_logger_info,
- mock_file_empty, mock_prep_list,
- mock_path_exists):
- self.rally_base._run_task('test_name')
+ def test_prepare_task_no_tests_for_scenario(
+ self, mock_logger_info, mock_file_empty, mock_prep_list):
+ self.rally_base.prepare_task('test_name')
mock_logger_info.assert_any_call('No tests for scenario \"%s\"',
'test_name')
mock_file_empty.assert_called()
mock_prep_list.assert_called()
- mock_path_exists.assert_called()
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_prepare_test_list', return_value='test_file_name')
@@ -216,7 +213,7 @@ class OSRallyTesting(unittest.TestCase):
def test_run_task_taskid_missing(self, mock_logger_error, *args):
# pylint: disable=unused-argument
with self.assertRaises(Exception):
- self.rally_base._run_task('test_name')
+ self.rally_base.run_task('test_name')
text = 'Failed to retrieve task_id'
mock_logger_error.assert_any_call(text)
@@ -241,7 +238,7 @@ class OSRallyTesting(unittest.TestCase):
'_save_results')
def test_run_task_default(self, mock_save_res, *args):
# pylint: disable=unused-argument
- self.rally_base._run_task('test_name')
+ self.rally_base.run_task('test_name')
mock_save_res.assert_called()
@mock.patch('six.moves.builtins.open', mock.mock_open())
@@ -260,15 +257,15 @@ class OSRallyTesting(unittest.TestCase):
self.rally_base._save_results('test_name', '1234')
mock_summary.assert_called()
- def test_prepare_env_testname_invalid(self):
+ def test_prepare_run_testname_invalid(self):
self.rally_base.TESTS = ['test1', 'test2']
self.rally_base.test_name = 'test'
with self.assertRaises(Exception):
- self.rally_base._prepare_env()
+ self.rally_base.prepare_run()
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'get_external_network')
- def test_prepare_env_flavor_alt_creation_failed(self, *args):
+ def test_prepare_run_flavor_alt_creation_failed(self, *args):
# pylint: disable=unused-argument
self.rally_base.TESTS = ['test1', 'test2']
self.rally_base.test_name = 'test1'
@@ -278,26 +275,34 @@ class OSRallyTesting(unittest.TestCase):
side_effect=Exception) \
as mock_create_flavor:
with self.assertRaises(Exception):
- self.rally_base._prepare_env()
+ self.rally_base.prepare_run()
mock_list_hyperv.assert_called_once()
mock_create_flavor.assert_called_once()
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
- '_run_task')
- def test_run_tests_all(self, mock_run_task):
- self.rally_base.TESTS = ['test1', 'test2']
+ 'prepare_task', return_value=True)
+ @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
+ 'run_task')
+ def test_run_tests_all(self, mock_run_task, mock_prepare_task):
+ self.rally_base.tests = ['test1', 'test2']
self.rally_base.test_name = 'all'
- self.rally_base._run_tests()
+ self.rally_base.run_tests()
+ mock_prepare_task.assert_any_call('test1')
+ mock_prepare_task.assert_any_call('test2')
mock_run_task.assert_any_call('test1')
mock_run_task.assert_any_call('test2')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
- '_run_task')
- def test_run_tests_default(self, mock_run_task):
- self.rally_base.TESTS = ['test1', 'test2']
- self.rally_base.test_name = 'test1'
- self.rally_base._run_tests()
+ 'prepare_task', return_value=True)
+ @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
+ 'run_task')
+ def test_run_tests_default(self, mock_run_task, mock_prepare_task):
+ self.rally_base.tests = ['test1', 'test2']
+ self.rally_base.run_tests()
+ mock_prepare_task.assert_any_call('test1')
+ mock_prepare_task.assert_any_call('test2')
mock_run_task.assert_any_call('test1')
+ mock_run_task.assert_any_call('test2')
def test_clean_up_default(self):
with mock.patch.object(self.rally_base.orig_cloud,
@@ -309,9 +314,9 @@ class OSRallyTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
'create_rally_deployment')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
- '_prepare_env')
+ 'prepare_run')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
- '_run_tests')
+ 'run_tests')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_generate_report')
def test_run_default(self, *args):
@@ -328,8 +333,8 @@ class OSRallyTesting(unittest.TestCase):
@mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
'create_rally_deployment', return_value=mock.Mock())
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
- '_prepare_env', side_effect=Exception)
- def test_run_exception_prepare_env(self, mock_prep_env, *args):
+ 'prepare_run', side_effect=Exception)
+ def test_run_exception_prepare_run(self, mock_prep_env, *args):
# pylint: disable=unused-argument
self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_RUN_ERROR)
mock_prep_env.assert_called()
diff --git a/tox.ini b/tox.ini
index 92a027104..b83cd61ff 100644
--- a/tox.ini
+++ b/tox.ini
@@ -111,7 +111,6 @@ basepython = python2.7
files =
functest/opnfv_tests/openstack/cinder/write_data.sh
functest/opnfv_tests/openstack/cinder/read_data.sh
- functest/opnfv_tests/openstack/rally/scenario/support/instance_dd_test.sh
functest/ci/convert_images.sh
functest/ci/download_images.sh
build.sh