Replace nova attach volume to server with shade client.
[yardstick.git] / yardstick / benchmark / scenarios / lib / attach_volume.py
index 8812496..96dd130 100644 (file)
@@ -6,30 +6,31 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-
-from __future__ import print_function
-from __future__ import absolute_import
-
 import logging
 
 from yardstick.benchmark.scenarios import base
-import yardstick.common.openstack_utils as op_utils
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
 
 LOG = logging.getLogger(__name__)
 
 
 class AttachVolume(base.Scenario):
-    """Attach a volmeu to an instance"""
+    """Attach a volume to an instance"""
 
     __scenario_type__ = "AttachVolume"
 
     def __init__(self, scenario_cfg, context_cfg):
         self.scenario_cfg = scenario_cfg
         self.context_cfg = context_cfg
-        self.options = self.scenario_cfg['options']
+        self.options = self.scenario_cfg["options"]
 
-        self.server_id = self.options.get("server_id", "TestServer")
-        self.volume_id = self.options.get("volume_id", None)
+        self.server_name_or_id = self.options["server_name_or_id"]
+        self.volume_name_or_id = self.options["volume_name_or_id"]
+        self.device = self.options.get("device")
+        self.wait = self.options.get("wait", True)
+        self.timeout = self.options.get("timeout")
+        self.shade_client = openstack_utils.get_shade_client()
 
         self.setup_done = False
 
@@ -44,10 +45,14 @@ class AttachVolume(base.Scenario):
         if not self.setup_done:
             self.setup()
 
-        status = op_utils.attach_server_volume(self.server_id,
-                                               self.volume_id)
+        status = openstack_utils.attach_volume_to_server(
+            self.shade_client, self.server_name_or_id, self.volume_name_or_id,
+            device=self.device, wait=self.wait, timeout=self.timeout)
+
+        if not status:
+            result.update({"attach_volume": 0})
+            LOG.error("Attach volume to server failed!")
+            raise exceptions.ScenarioAttachVolumeError
 
-        if status:
-            LOG.info("Attach volume to server successful!")
-        else:
-            LOG.info("Attach volume to server failed!")
+        result.update({"attach_volume": 1})
+        LOG.info("Attach volume to server successful!")