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
15 import yardstick.ssh as ssh
16 from yardstick.benchmark.scenarios import base
18 LOG = logging.getLogger(__name__)
21 class AddMemoryLoad(base.Scenario):
22 """Add memory load in server
25 __scenario_type__ = "AddMemoryLoad"
27 def __init__(self, scenario_cfg, context_cfg):
28 self.scenario_cfg = scenario_cfg
29 self.context_cfg = context_cfg
31 self.options = scenario_cfg.get('options', {})
33 self.client = ssh.SSH.from_node(self.context_cfg['host'])
34 self.client.wait(timeout=600)
36 def run(self, result):
41 memory_load = self.options['memory_load']
43 LOG.error('memory_load parameter must be provided')
45 if float(memory_load) == 0:
47 cmd = 'free | awk "/Mem/ {print $2}"'
48 code, stdout, stderr = self.client.execute(cmd)
49 total = int(stdout.split()[1])
50 used = int(stdout.split()[2])
51 remain_memory = total * float(memory_load) - used
53 count = remain_memory / 1024 / 128
54 LOG.info('Add %s vm load', count)
56 cmd = 'stress -t 10 -m {} --vm-keep'.format(count)
57 self.client.execute(cmd)