Merge "Add test case file, document and related scripts of yardstick tc058(HA_TC015)"
[yardstick.git] / yardstick / benchmark / scenarios / lib / attach_volume.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 import yardstick.common.openstack_utils as op_utils
17
18 LOG = logging.getLogger(__name__)
19
20
21 class AttachVolume(base.Scenario):
22     """Attach a volmeu to an instance"""
23
24     __scenario_type__ = "AttachVolume"
25
26     def __init__(self, scenario_cfg, context_cfg):
27         self.scenario_cfg = scenario_cfg
28         self.context_cfg = context_cfg
29         self.options = self.scenario_cfg['options']
30
31         self.server_id = self.options.get("server_id", "TestServer")
32         self.volume_id = self.options.get("volume_id", None)
33
34         self.setup_done = False
35
36     def setup(self):
37         """scenario setup"""
38
39         self.setup_done = True
40
41     def run(self, result):
42         """execute the test"""
43
44         if not self.setup_done:
45             self.setup()
46
47         status = op_utils.attach_server_volume(self.server_id,
48                                                self.volume_id)
49
50         if status:
51             LOG.info("Attach volume to server successful!")
52         else:
53             LOG.info("Attach volume to server failed!")