1 # ############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
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 # ############################################################################
10 from __future__ import print_function
11 from __future__ import absolute_import
17 from xml.etree import ElementTree as ET
19 from yardstick import ssh
20 from yardstick.benchmark.scenarios import base
21 from yardstick.common import constants as consts
22 from yardstick.common.utils import change_obj_to_dict
23 from yardstick.common.openstack_utils import get_nova_client
24 from yardstick.common.task_template import TaskTemplate
26 LOG = logging.getLogger(__name__)
29 class GetNumaInfo(base.Scenario):
31 Execute a live migration for two hosts
35 __scenario_type__ = "GetNumaInfo"
37 def __init__(self, scenario_cfg, context_cfg):
38 self.scenario_cfg = scenario_cfg
39 self.context_cfg = context_cfg
40 self.options = self.scenario_cfg.get('options', {})
42 server = self.options['server']
43 self.server_id = server['id']
44 self.host = self._get_current_host_name(self.server_id)
46 node_file = os.path.join(consts.YARDSTICK_ROOT_PATH,
47 self.options.get('file'))
49 with open(node_file) as f:
50 nodes = yaml.safe_load(TaskTemplate.render(f.read()))
51 self.nodes = {a['host_name']: a for a in nodes['nodes']}
53 def run(self, result):
54 numa_info = self._check_numa_node(self.server_id, self.host)
56 keys = self.scenario_cfg.get('output', '').split()
58 return self._push_to_outputs(keys, values)
60 def _get_current_host_name(self, server_id):
62 return change_obj_to_dict(get_nova_client().servers.get(server_id))['OS-EXT-SRV-ATTR:host']
64 def _get_host_client(self, node_name):
65 self.host_client = ssh.SSH.from_node(self.nodes.get(node_name))
66 self.host_client.wait(timeout=600)
68 def _check_numa_node(self, server_id, host):
69 self._get_host_client(host)
71 cmd = "sudo virsh dumpxml %s" % server_id
72 LOG.debug("Executing command: %s", cmd)
73 status, stdout, stderr = self.host_client.execute(cmd)
75 raise RuntimeError(stderr)
76 root = ET.fromstring(stdout)
77 vcpupin = [a.attrib for a in root.iter('vcpupin')]
78 pinning = [a.attrib for a in root.iter('memnode')]
79 return {"pinning": pinning, 'vcpupin': vcpupin}