From 5f11cb9f55aa0529fddfe916a2976a9aa5b4c08f Mon Sep 17 00:00:00 2001 From: rexlee8776 Date: Tue, 24 Jul 2018 04:17:45 +0000 Subject: the recovery action of "baremetal down" should be triggered mandatory 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 --- .../scenarios/availability/test_baseattacker.py | 36 ++++++++++++++++++++++ .../scenarios/availability/test_serviceha.py | 17 ++++++++++ 2 files changed, 53 insertions(+) create mode 100644 yardstick/tests/unit/benchmark/scenarios/availability/test_baseattacker.py (limited to 'yardstick/tests/unit') 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 index 000000000..74f86983b --- /dev/null +++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_baseattacker.py @@ -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) diff --git a/yardstick/tests/unit/benchmark/scenarios/availability/test_serviceha.py b/yardstick/tests/unit/benchmark/scenarios/availability/test_serviceha.py index ec0e5973c..d61fa67c7 100644 --- a/yardstick/tests/unit/benchmark/scenarios/availability/test_serviceha.py +++ b/yardstick/tests/unit/benchmark/scenarios/availability/test_serviceha.py @@ -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() -- cgit 1.2.3-korg