diff options
author | Shobhi Jain <shobhi.jain@intel.com> | 2018-03-28 12:19:35 +0100 |
---|---|---|
committer | Emma Foley <emma.l.foley@intel.com> | 2018-06-27 17:13:09 +0100 |
commit | 8442ad76bb4f93eeb87f5bbf0f2292bb2400ea2d (patch) | |
tree | 81d23d7b0c93ce903c6dcdef16d1fd2244e3cc67 /yardstick/common | |
parent | 0222fb329f4e68321adba807fb1fbe79c38c5650 (diff) |
Replace nova attach volume to server with shade client.
Function attach_volume_to_server now uses shade client
instead of nova client.
JIRA: YARDSTICK-1088
Change-Id: Id00df672c2c195b5c338cbbc30ddf2742a4e4d29
Signed-off-by: Shobhi Jain <shobhi.jain@intel.com>
(cherry picked from commit 8fd82cd8d0146d8cebbc32ed7cbb6fb9d1861297)
Diffstat (limited to 'yardstick/common')
-rw-r--r-- | yardstick/common/exceptions.py | 4 | ||||
-rw-r--r-- | yardstick/common/openstack_utils.py | 37 |
2 files changed, 32 insertions, 9 deletions
diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py index 3af46a857..3a51892cc 100644 --- a/yardstick/common/exceptions.py +++ b/yardstick/common/exceptions.py @@ -234,6 +234,10 @@ class ScenarioDeleteKeypairError(YardstickException): message = 'Nova Delete Keypair Scenario failed' +class ScenarioAttachVolumeError(YardstickException): + message = 'Nova Attach Volume Scenario failed' + + class ApiServerError(YardstickException): message = 'An unkown exception happened to Api Server!' diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py index 0902d29e1..0a3cfb5fc 100644 --- a/yardstick/common/openstack_utils.py +++ b/yardstick/common/openstack_utils.py @@ -264,17 +264,36 @@ def create_instance_and_wait_for_active(shade_client, name, image, "Exception message, '%s'", o_exc.orig_message) -def attach_server_volume(server_id, volume_id, - device=None): # pragma: no cover +def attach_volume_to_server(shade_client, server_name_or_id, volume_name_or_id, + device=None, wait=True, timeout=None): + """Attach a volume to a server. + + This will attach a volume, described by the passed in volume + dict, to the server described by the passed in server dict on the named + device on the server. + + If the volume is already attached to the server, or generally not + available, then an exception is raised. To re-attach to a server, + but under a different device, the user must detach it first. + + :param server_name_or_id:(string) The server name or id to attach to. + :param volume_name_or_id:(string) The volume name or id to attach. + :param device:(string) The device name where the volume will attach. + :param wait:(bool) If true, waits for volume to be attached. + :param timeout: Seconds to wait for volume attachment. None is forever. + + :returns: True if attached successful, False otherwise. + """ try: - get_nova_client().volumes.create_server_volume(server_id, - volume_id, device) - except Exception: # pylint: disable=broad-except - log.exception("Error [attach_server_volume(nova_client, '%s', '%s')]", - server_id, volume_id) - return False - else: + server = shade_client.get_server(name_or_id=server_name_or_id) + volume = shade_client.get_volume(volume_name_or_id) + shade_client.attach_volume( + server, volume, device=device, wait=wait, timeout=timeout) return True + except exc.OpenStackCloudException as o_exc: + log.error("Error [attach_volume_to_server(shade_client)]. " + "Exception message: %s", o_exc.orig_message) + return False def delete_instance(shade_client, name_or_id, wait=False, timeout=180, |