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 ##############################################################################
11 from yardstick.common import openstack_utils
12 from yardstick.common import exceptions
13 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
19 class DetachVolume(base.Scenario):
20 """Detach a volume from an instance"""
22 __scenario_type__ = "DetachVolume"
24 def __init__(self, scenario_cfg, context_cfg):
25 self.scenario_cfg = scenario_cfg
26 self.context_cfg = context_cfg
27 self.options = self.scenario_cfg["options"]
29 self.server = self.options["server_name_or_id"]
30 self.volume = self.options["volume_name_or_id"]
31 self.wait = self.options.get("wait", True)
32 self.timeout = self.options.get("timeout")
34 self.shade_client = openstack_utils.get_shade_client()
36 self.setup_done = False
41 self.setup_done = True
43 def run(self, result):
44 """execute the test"""
46 if not self.setup_done:
49 status = openstack_utils.detach_volume(
50 self.shade_client, self.server, self.volume,
51 wait=self.wait, timeout=self.timeout)
54 result.update({"detach_volume": 0})
55 LOG.error("Detach volume from server failed!")
56 raise exceptions.ScenarioDetachVolumeError
58 result.update({"detach_volume": 1})
59 LOG.info("Detach volume from server successful!")