the recovery action of "baremetal down" should be triggered mandatory 41/61141/1
authorrexlee8776 <limingjiang@huawei.com>
Tue, 24 Jul 2018 04:17:45 +0000 (04:17 +0000)
committerRex Lee <limingjiang@huawei.com>
Tue, 21 Aug 2018 01:57:37 +0000 (01:57 +0000)
YARDSTICK-1222 has made attacker recover only when the sla not pass.
But for baremetal down test case, the node need to power on even the sla pass.

TODO:
Make attacker can support mandatory recover in some situation.

JIRA: YARDSTICK-1337

Change-Id: Ib567b9b9025e5ee421ea47140c468537ad16f090
Signed-off-by: rexlee8776 <limingjiang@huawei.com>
(cherry picked from commit 5f11cb9f55aa0529fddfe916a2976a9aa5b4c08f)

yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py
yardstick/benchmark/scenarios/availability/attacker/baseattacker.py
yardstick/benchmark/scenarios/availability/serviceha.py
yardstick/tests/unit/benchmark/scenarios/availability/test_baseattacker.py [new file with mode: 0644]
yardstick/tests/unit/benchmark/scenarios/availability/test_serviceha.py

index 979e3ab..77efe0d 100644 (file)
@@ -23,7 +23,7 @@ def _execute_shell_command(command, stdin=None):
     output = []
     try:
         output = subprocess.check_output(command, stdin=stdin, shell=True)
-    except Exception:
+    except Exception:  # pylint: disable=broad-except
         exitcode = -1
         LOG.error("exec command '%s' error:\n ", command, exc_info=True)
 
@@ -34,6 +34,8 @@ class BaremetalAttacker(BaseAttacker):
     __attacker_type__ = 'bare-metal-down'
 
     def setup(self):
+        # baremetal down need to recover even sla pass
+        self.mandatory = True
         LOG.debug("config:%s context:%s", self._config, self._context)
         host = self._context.get(self._config['host'], None)
 
index d67a16b..7871cc9 100644 (file)
@@ -63,6 +63,7 @@ class BaseAttacker(object):
         self.data = {}
         self.setup_done = False
         self.intermediate_variables = {}
+        self.mandatory = False
 
     @staticmethod
     def get_attacker_cls(attacker_cfg):
index 31caf50..a0e63e0 100755 (executable)
@@ -87,9 +87,9 @@ class ServiceHA(base.Scenario):
 
     def teardown(self):
         """scenario teardown"""
-        # only recover when sla not pass
-        if not self.sla_pass:
-            for attacker in self.attackers:
+        # recover when mandatory or sla not pass
+        for attacker in self.attackers:
+            if attacker.mandatory or not self.sla_pass:
                 attacker.recover()
 
 
diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_baseattacker.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_baseattacker.py
new file mode 100644 (file)
index 0000000..74f8698
--- /dev/null
@@ -0,0 +1,36 @@
+##############################################################################
+# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import unittest
+
+from yardstick.benchmark.scenarios.availability.attacker import baseattacker
+
+
+class BaseAttackerTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.attacker_cfg = {
+            'fault_type': 'test-attacker',
+            'action_parameter': {'process_name': 'nova_api'},
+            'rollback_parameter': {'process_name': 'nova_api'},
+            'key': 'stop-service',
+            'attack_key': 'stop-service',
+            'host': 'node1',
+        }
+        self.base_attacker = baseattacker.BaseAttacker({}, {})
+
+    def test__init__(self):
+        self.assertEqual(self.base_attacker.data, {})
+        self.assertFalse(self.base_attacker.mandatory)
+        self.assertEqual(self.base_attacker.intermediate_variables, {})
+        self.assertFalse(self.base_attacker.mandatory)
+
+    def test_get_attacker_cls(self):
+        with self.assertRaises(RuntimeError):
+            baseattacker.BaseAttacker.get_attacker_cls(self.attacker_cfg)
index ec0e597..d61fa67 100644 (file)
@@ -109,6 +109,23 @@ class ServicehaTestCase(unittest.TestCase):
         ret = {}
         p.run(ret)
         attacker = mock.Mock()
+        attacker.mandatory = False
         p.attackers = [attacker]
         p.teardown()
         attacker.recover.assert_not_called()
+
+    @mock.patch.object(serviceha, 'baseattacker')
+    @mock.patch.object(serviceha, 'basemonitor')
+    def test__serviceha_teardown_when_mandatory(self, mock_monitor,
+                                                *args):
+        p = serviceha.ServiceHA(self.args, self.ctx)
+        p.setup()
+        self.assertTrue(p.setup_done)
+        mock_monitor.MonitorMgr().verify_SLA.return_value = True
+        ret = {}
+        p.run(ret)
+        attacker = mock.Mock()
+        attacker.mandatory = True
+        p.attackers = [attacker]
+        p.teardown()
+        attacker.recover.assert_called_once()