From ab466cb0f58d7fd575431263f3ff7802866117f5 Mon Sep 17 00:00:00 2001 From: Dmitry Tyzhnenko Date: Fri, 6 Nov 2015 19:33:32 +0200 Subject: [PATCH] Add decorator @action Use decorator @action for method which used as step. Prefix _action_ still work. Implements blueprint template-based-testcases Change-Id: I802d79071c313528a29d6f63abf2db5f6cebbe7f --- system_test/helpers/decorators.py | 5 ++ system_test/tests/actions_base.py | 60 ++++++++------ system_test/tests/base_actions_factory.py | 3 +- .../tests/strength/destroy_controllers.py | 79 ++++++++++--------- system_test/tests/strength/strenght_base.py | 16 ++-- system_test/tests/test_create_deploy_ostf.py | 20 ++--- system_test/tests/test_deploy_check_rados.py | 33 ++++---- 7 files changed, 125 insertions(+), 91 deletions(-) diff --git a/system_test/helpers/decorators.py b/system_test/helpers/decorators.py index d0f41e318..aad4b5f42 100644 --- a/system_test/helpers/decorators.py +++ b/system_test/helpers/decorators.py @@ -32,6 +32,11 @@ def deferred_decorator(decorator_list): return real_decorator +def action(method): + setattr(method, '_action_method_', True) + return method + + def step_start_stop(func): @functools.wraps(func) def wrapper(*args, **kwargs): diff --git a/system_test/tests/actions_base.py b/system_test/tests/actions_base.py index c965fd6ca..95b926afd 100644 --- a/system_test/tests/actions_base.py +++ b/system_test/tests/actions_base.py @@ -25,6 +25,7 @@ from system_test import logger from system_test.tests import base_actions_factory from system_test.helpers.decorators import make_snapshot_if_step_fail from system_test.helpers.decorators import deferred_decorator +from system_test.helpers.decorators import action class PrepareBase(base_actions_factory.BaseActionsFactory): @@ -70,7 +71,8 @@ class PrepareBase(base_actions_factory.BaseActionsFactory): logger.info("\n{footer}\n".format(footer=footer)) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_setup_master(self): + @action + def setup_master(self): """Setup master node""" self.check_run("empty") with timestat("setup_environment", is_uniq=True): @@ -79,7 +81,8 @@ class PrepareBase(base_actions_factory.BaseActionsFactory): self.env.make_snapshot("empty", is_make=True) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_config_release(self): + @action + def config_release(self): """Configuration releases""" self.check_run("ready") self.env.revert_snapshot("empty", skip_timesync=True) @@ -94,7 +97,8 @@ class PrepareBase(base_actions_factory.BaseActionsFactory): self.env.make_snapshot("ready", is_make=True) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_make_slaves(self): + @action + def make_slaves(self): """Bootstrap slave and make snapshot Use slaves parameter from case section @@ -109,7 +113,8 @@ class PrepareBase(base_actions_factory.BaseActionsFactory): self.env.make_snapshot(snapshot_name, is_make=True) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_revert_slaves(self): + @action + def revert_slaves(self): """Revert bootstraped nodes Skip if snapshot with cluster exists @@ -126,14 +131,15 @@ class ActionsBase(PrepareBase): For chousing action order use actions_order variable, set list of actions order - _action_create_env - create and configure environment - _action_add_nodes - add nodes to environment - _action_deploy_cluster - deploy en environment - _action_network_check - run network check - _action_health_check - run all ostf tests - _action_reset_cluster - reset an environment (NotImplemented) - _action_delete_cluster - delete en environment (NotImplemented) - _action_stop_deploy - stop deploying of environment (NotImplemented) + Actions: + create_env - create and configure environment + add_nodes - add nodes to environment + deploy_cluster - deploy en environment + network_check - run network check + health_check - run all ostf tests + reset_cluster - reset an environment (NotImplemented) + delete_cluster - delete en environment (NotImplemented) + stop_deploy - stop deploying of environment (NotImplemented) """ base_group = None @@ -148,7 +154,8 @@ class ActionsBase(PrepareBase): self.cluster_id = None @deferred_decorator([make_snapshot_if_step_fail]) - def _action_create_env(self): + @action + def create_env(self): """Create Fuel Environment For configure Environment use environment-config section in config file @@ -196,7 +203,8 @@ class ActionsBase(PrepareBase): logger.info("Cluster created with ID:{}".format(self.cluster_id)) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_add_nodes(self): + @action + def add_nodes(self): """Add nodes to environment Used sub-section nodes in environment-config section @@ -220,7 +228,8 @@ class ActionsBase(PrepareBase): self.fuel_web.update_nodes(self.cluster_id, nodes) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_deploy_cluster(self): + @action + def deploy_cluster(self): """Deploy environment Skip action if cluster doesn't exist @@ -231,7 +240,8 @@ class ActionsBase(PrepareBase): self.fuel_web.deploy_cluster_wait(self.cluster_id) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_network_check(self): + @action + def network_check(self): """Run network checker Skip action if cluster doesn't exist @@ -242,7 +252,8 @@ class ActionsBase(PrepareBase): self.fuel_web.verify_network(self.cluster_id) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_health_check(self): + @action + def health_check(self): """Run health checker Skip action if cluster doesn't exist @@ -255,7 +266,8 @@ class ActionsBase(PrepareBase): should_fail=getattr(self, 'ostf_tests_should_failed', 0)) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_save_load_environment(self): + @action + def save_load_environment(self): """Load existen environment from snapshot or save it""" env_name = self.env_config['name'] if self.cluster_id is None: @@ -272,7 +284,8 @@ class ActionsBase(PrepareBase): self.env.resume_environment() @deferred_decorator([make_snapshot_if_step_fail]) - def _action_check_haproxy(self): + @action + def check_haproxy(self): """HAProxy backend checking""" controller_nodes = self.fuel_web.get_nailgun_cluster_nodes_by_roles( self.cluster_id, ['controller']) @@ -288,16 +301,19 @@ class ActionsBase(PrepareBase): haproxy_status)) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_reset_cluster(self): + @action + def reset_cluster(self): """Reset environment""" raise NotImplementedError @deferred_decorator([make_snapshot_if_step_fail]) - def _action_delete_cluster(self): + @action + def delete_cluster(self): """Delete environment""" raise NotImplementedError @deferred_decorator([make_snapshot_if_step_fail]) - def _action_stop_deploy(self): + @action + def stop_deploy(self): """Deploy environment""" raise NotImplementedError diff --git a/system_test/tests/base_actions_factory.py b/system_test/tests/base_actions_factory.py index 09c163bc7..4d735c5bd 100644 --- a/system_test/tests/base_actions_factory.py +++ b/system_test/tests/base_actions_factory.py @@ -28,7 +28,8 @@ class BaseActionsFactory(base_test_case.TestBasic): def get_actions(cls): """Return all action methods""" return {m: getattr(cls, m) for m in - dir(cls) if m.startswith('_action_')} + dir(cls) if m.startswith('_action_') or + getattr(getattr(cls, m), '_action_method_', False)} @classmethod def get_actions_order(cls): diff --git a/system_test/tests/strength/destroy_controllers.py b/system_test/tests/strength/destroy_controllers.py index a7d3ac4dc..50c0990e4 100644 --- a/system_test/tests/strength/destroy_controllers.py +++ b/system_test/tests/strength/destroy_controllers.py @@ -18,6 +18,7 @@ from proboscis import factory from system_test.tests.strength import strenght_base from system_test.helpers.decorators import make_snapshot_if_step_fail from system_test.helpers.decorators import deferred_decorator +from system_test.helpers.decorators import action class StrenghtDestroyFirstContorller(strenght_base.StrenghtBaseActions): @@ -44,28 +45,29 @@ class StrenghtDestroyFirstContorller(strenght_base.StrenghtBaseActions): 'system_test.failover.destroy_controllers.second'] actions_order = [ - '_action_setup_master', - '_action_config_release', - '_action_make_slaves', - '_action_revert_slaves', - '_action_create_env', - '_action_add_nodes', - '_action_network_check', - '_action_deploy_cluster', - '_action_network_check', - '_action_health_check', - '_action_save_load_environment', - '_action_destory_first_controller', - '_action_check_pacemaker_status', - '_action_wait_offline_nodes', - '_action_check_ha_service_ready', - '_action_check_os_services_ready', - '_action_wait_galera_cluster', - '_action_health_check', + 'setup_master', + 'config_release', + 'make_slaves', + 'revert_slaves', + 'create_env', + 'add_nodes', + 'network_check', + 'deploy_cluster', + 'network_check', + 'health_check', + 'save_load_environment', + 'destory_first_controller', + 'check_pacemaker_status', + 'wait_offline_nodes', + 'check_ha_service_ready', + 'check_os_services_ready', + 'wait_galera_cluster', + 'health_check', ] @deferred_decorator([make_snapshot_if_step_fail]) - def _action_destory_first_controller(self): + @action + def destory_first_controller(self): """Destory first controller""" self._destory_controller('slave-01') @@ -94,28 +96,29 @@ class StrenghtDestroySecondContorller(strenght_base.StrenghtBaseActions): 'actions_tests.failover.destroy_controllers.second'] actions_order = [ - '_action_setup_master', - '_action_config_release', - '_action_make_slaves', - '_action_revert_slaves', - '_action_create_env', - '_action_add_nodes', - '_action_network_check', - '_action_deploy_cluster', - '_action_network_check', - '_action_health_check', - '_action_save_load_environment', - '_action_destory_second_controller', - '_action_check_pacemaker_status', - '_action_wait_offline_nodes', - '_action_check_ha_service_ready', - '_action_check_os_services_ready', - '_action_wait_galera_cluster', - '_action_health_check', + 'setup_master', + 'config_release', + 'make_slaves', + 'revert_slaves', + 'create_env', + 'add_nodes', + 'network_check', + 'deploy_cluster', + 'network_check', + 'health_check', + 'save_load_environment', + 'destory_second_controller', + 'check_pacemaker_status', + 'wait_offline_nodes', + 'check_ha_service_ready', + 'check_os_services_ready', + 'wait_galera_cluster', + 'health_check', ] @deferred_decorator([make_snapshot_if_step_fail]) - def _action_destory_second_controller(self): + @action + def destory_second_controller(self): """Destory second controller""" self._destory_controller('slave-02') diff --git a/system_test/tests/strength/strenght_base.py b/system_test/tests/strength/strenght_base.py index fd3203368..059ed722a 100644 --- a/system_test/tests/strength/strenght_base.py +++ b/system_test/tests/strength/strenght_base.py @@ -19,6 +19,7 @@ from devops.helpers.helpers import wait from system_test.tests import actions_base from system_test.helpers.decorators import make_snapshot_if_step_fail from system_test.helpers.decorators import deferred_decorator +from system_test.helpers.decorators import action from system_test import logger @@ -43,7 +44,8 @@ class StrenghtBaseActions(actions_base.ActionsBase): logger.warning("Try destory allready destoryed node") @deferred_decorator([make_snapshot_if_step_fail]) - def _action_wait_offline_nodes(self): + @action + def wait_offline_nodes(self): """Wait offline status of destroyed nodes""" assert_true(self.destroyed_devops_nodes, "No destoryed nodes in Environment") @@ -57,19 +59,22 @@ class StrenghtBaseActions(actions_base.ActionsBase): wait(wait_offline_nodes, timeout=60 * 5) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_check_ha_service_ready(self): + @action + def check_ha_service_ready(self): """Wait for HA services ready""" self.fuel_web.assert_ha_services_ready(self.cluster_id) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_check_os_services_ready(self): + @action + def check_os_services_ready(self): """Wait until OpenStack services are UP""" self.fuel_web.assert_os_services_ready( self.cluster_id, should_fail=self.os_service_should_failed) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_wait_galera_cluster(self): + @action + def wait_galera_cluster(self): """Wait until MySQL Galera is UP on online controllers""" n_ctrls = self.fuel_web.get_nailgun_cluster_nodes_by_roles( self.cluster_id, @@ -80,7 +85,8 @@ class StrenghtBaseActions(actions_base.ActionsBase): timeout=300) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_check_pacemaker_status(self): + @action + def check_pacemaker_status(self): """Check controllers status in pacemaker""" n_ctrls = self.fuel_web.get_nailgun_cluster_nodes_by_roles( self.cluster_id, diff --git a/system_test/tests/test_create_deploy_ostf.py b/system_test/tests/test_create_deploy_ostf.py index 5b48281da..81a40dc1b 100644 --- a/system_test/tests/test_create_deploy_ostf.py +++ b/system_test/tests/test_create_deploy_ostf.py @@ -31,16 +31,16 @@ class CreateDeployOstf(actions_base.ActionsBase): base_group = ['system_test', 'system_test.create_deploy_ostf'] actions_order = [ - '_action_setup_master', - '_action_config_release', - '_action_make_slaves', - '_action_revert_slaves', - '_action_create_env', - '_action_add_nodes', - '_action_network_check', - '_action_deploy_cluster', - '_action_network_check', - '_action_health_check', + 'setup_master', + 'config_release', + 'make_slaves', + 'revert_slaves', + 'create_env', + 'add_nodes', + 'network_check', + 'deploy_cluster', + 'network_check', + 'health_check', ] diff --git a/system_test/tests/test_deploy_check_rados.py b/system_test/tests/test_deploy_check_rados.py index b68c32c54..49fdf6bc0 100644 --- a/system_test/tests/test_deploy_check_rados.py +++ b/system_test/tests/test_deploy_check_rados.py @@ -19,6 +19,7 @@ from system_test.tests import actions_base from system_test.helpers.utils import case_factory from system_test.helpers.decorators import deferred_decorator from system_test.helpers.decorators import make_snapshot_if_step_fail +from system_test.helpers.decorators import action class DeployCheckRadosGW(actions_base.ActionsBase): @@ -41,28 +42,30 @@ class DeployCheckRadosGW(actions_base.ActionsBase): 'system_test.deploy_and_check_radosgw', 'system_test.bvt_2'] actions_order = [ - '_action_setup_master', - '_action_config_release', - '_action_make_slaves', - '_action_revert_slaves', - '_action_create_env', - '_action_add_nodes', - '_action_network_check', - '_action_deploy_cluster', - '_action_network_check', - '_action_check_haproxy', - '_action_check_ceph_status', - '_action_health_check', - '_action_check_rados_daemon' + 'setup_master', + 'config_release', + 'make_slaves', + 'revert_slaves', + 'create_env', + 'add_nodes', + 'network_check', + 'deploy_cluster', + 'network_check', + 'check_haproxy', + 'check_ceph_status', + 'health_check', + 'check_rados_daemon' ] @deferred_decorator([make_snapshot_if_step_fail]) - def _action_check_ceph_status(self): + @action + def check_ceph_status(self): """Check Ceph status in cluster""" self.fuel_web.check_ceph_status(self.cluster_id) @deferred_decorator([make_snapshot_if_step_fail]) - def _action_check_rados_daemon(self): + @action + def check_rados_daemon(self): """Check the radosqw daemon is started""" with self.fuel_web.get_ssh_for_node('slave-01') as remote: radosgw_started = lambda: len(remote.check_call(