Add common openstack opertation scenarios: flavor & server
[yardstick.git] / yardstick / benchmark / scenarios / lib / check_value.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 from __future__ import print_function
11 from __future__ import absolute_import
12
13 import logging
14
15 from yardstick.benchmark.scenarios import base
16
17 LOG = logging.getLogger(__name__)
18
19
20 class CheckValue(base.Scenario):
21     """Check values between value1 and value2
22
23     options:
24         operator: equal(eq) and not equal(ne)
25         value1:
26         value2:
27     output: check_result
28     """
29
30     __scenario_type__ = "CheckValue"
31
32     def __init__(self, scenario_cfg, context_cfg):
33         self.scenario_cfg = scenario_cfg
34         self.context_cfg = context_cfg
35         self.options = self.scenario_cfg['options']
36
37     def run(self, result):
38         """execute the test"""
39
40         op = self.options.get("operator")
41         LOG.debug("options=%s", self.options)
42         value1 = str(self.options.get("value1"))
43         value2 = str(self.options.get("value2"))
44         check_result = "PASS"
45         if op == "eq" and value1 != value2:
46             LOG.info("value1=%s, value2=%s, error: should equal!!!", value1,
47                      value2)
48             check_result = "FAIL"
49             assert value1 == value2, "Error %s!=%s" % (value1, value2)
50         elif op == "ne" and value1 == value2:
51             LOG.info("value1=%s, value2=%s, error: should not equal!!!",
52                      value1, value2)
53             check_result = "FAIL"
54             assert value1 != value2, "Error %s==%s" % (value1, value2)
55         LOG.info("Check result is %s", check_result)
56         keys = self.scenario_cfg.get('output', '').split()
57         values = [check_result]
58         return self._push_to_outputs(keys, values)