Merge "Adding Grafana dashboard for visualizing the vEPC default bearer metrics."
[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 from yardstick.common import exceptions as y_exc
17
18 LOG = logging.getLogger(__name__)
19
20
21 class CheckValue(base.Scenario):
22     """Check values between value1 and value2
23
24     options:
25         operator: equal(eq) and not equal(ne)
26         value1:
27         value2:
28     output: check_result
29     """
30
31     __scenario_type__ = "CheckValue"
32
33     def __init__(self, scenario_cfg, context_cfg):
34         self.scenario_cfg = scenario_cfg
35         self.context_cfg = context_cfg
36         self.options = self.scenario_cfg['options']
37
38     def run(self, _):
39         """execute the test"""
40
41         op = self.options.get("operator")
42         LOG.debug("options=%s", self.options)
43         value1 = str(self.options.get("value1"))
44         value2 = str(self.options.get("value2"))
45         if (op == "eq" and value1 != value2) or (op == "ne" and
46                                                  value1 == value2):
47             raise y_exc.ValueCheckError(
48                 value1=value1, operator=op, value2=value2)
49         check_result = "PASS"
50         LOG.info("Check result is %s", check_result)
51         keys = self.scenario_cfg.get('output', '').split()
52         values = [check_result]
53         return self._push_to_outputs(keys, values)