Merge "Added traffic update capability to Ixload TG"
[yardstick.git] / yardstick / benchmark / scenarios / lib / check_numa_info.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 CheckNumaInfo(base.Scenario):
21     """
22     Execute a live migration for two hosts
23
24     """
25
26     __scenario_type__ = "CheckNumaInfo"
27
28     def __init__(self, scenario_cfg, context_cfg):
29         self.scenario_cfg = scenario_cfg
30         self.context_cfg = context_cfg
31
32         self.options = self.scenario_cfg.get('options', {})
33
34         self.cpu_set = self.options.get('cpu_set', '1,2,3,4,5,6')
35
36     def run(self, result):
37         info1 = self.options.get('info1')
38         info2 = self.options.get('info2')
39         LOG.debug('Origin numa info: %s', info1)
40         LOG.debug('Current numa info: %s', info2)
41         status = self._check_vm2_status(info1, info2)
42
43         keys = self.scenario_cfg.get('output', '').split()
44         values = [status]
45         return self._push_to_outputs(keys, values)
46
47     def _check_vm2_status(self, info1, info2):
48         if len(info1['pinning']) != 1 or len(info2['pinning']) != 1:
49             return False
50
51         for i in info1['vcpupin']:
52             for j in i['cpuset'].split(','):
53                 if j not in self.cpu_set.split(','):
54                     return False
55
56         for i in info2['vcpupin']:
57             for j in i['cpuset'].split(','):
58                 if j not in self.cpu_set.split(','):
59                     return False
60
61         return True