Commit 28aa9a7d authored by Stavros Sachtouris's avatar Stavros Sachtouris Committed by Giorgos Korfiatis

Adjust Block Storage client to Synnefo 0.16next

parent a03b7734
# Copyright 2014 GRNET S.A. All rights reserved.
# Copyright 2014-2015 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -115,9 +115,6 @@ class volume_create(_BlockStorageInit, OptionalOutput, _VolumeWait):
server_id=argument.ValueArgument(
'The server for the new volume', '--server-id'),
name=argument.ValueArgument('Display name', '--name'),
# src_volume_id=argument.ValueArgument(
# 'Associate another volume to the new volume',
# '--source-volume-id'),
description=argument.ValueArgument(
'Volume description', '--description'),
snapshot_id=argument.ValueArgument(
......@@ -137,8 +134,7 @@ class volume_create(_BlockStorageInit, OptionalOutput, _VolumeWait):
@errors.Generic.all
def _run(self, size, server_id, name):
r = self.client.create_volume(
size, server_id, name,
# source_volid=self['src_volume_id'],
size, name, server_id,
display_description=self['description'],
snapshot_id=self['snapshot_id'],
imageRef=self['image_id'],
......
......@@ -359,7 +359,8 @@ class CycladesBlockStorageClient(CycladesBlockStorageRestClient):
"""Cyclades Block Storage REST API Client"""
def create_volume(
self, size, server_id, display_name,
self, size, display_name,
server_id=None,
display_description=None,
snapshot_id=None,
imageRef=None,
......@@ -368,7 +369,8 @@ class CycladesBlockStorageClient(CycladesBlockStorageRestClient):
project=None):
""":returns: (dict) new volumes' details"""
r = self.volumes_post(
size, server_id, display_name,
size, display_name,
server_id=server_id,
display_description=display_description,
snapshot_id=snapshot_id,
imageRef=imageRef,
......@@ -381,10 +383,9 @@ class CycladesBlockStorageClient(CycladesBlockStorageRestClient):
self.volumes_action_post(volume_id, {"reassign": {"project": project}})
def create_snapshot(
self, volume_id, display_name,
force=None, display_description=None):
self, volume_id, display_name=None, display_description=None):
""":returns: (dict) new snapshots' details"""
return super(CycladesBlockStorageClient, self).create_snapshot(
volume_id,
display_name=display_name,
force=force,
display_description=display_description)
......@@ -77,7 +77,8 @@ class CycladesBlockStorageRestClient(BlockStorageClient):
"""Synnefo Cyclades Block Storage REST API Client"""
def volumes_post(
self, size, server_id, display_name,
self, size, display_name,
server_id=None,
display_description=None,
snapshot_id=None,
imageRef=None,
......@@ -87,8 +88,9 @@ class CycladesBlockStorageRestClient(BlockStorageClient):
success=202,
**kwargs):
path = path4url('volumes')
volume = dict(
size=int(size), server_id=server_id, display_name=display_name)
volume = dict(size=int(size), display_name=display_name)
if server_id is not None:
volume['server_id'] = server_id
if display_description is not None:
volume['display_description'] = display_description
if snapshot_id is not None:
......
......@@ -326,23 +326,21 @@ class CycladesBlockStorageRestClient(TestCase):
@patch('%s.post' % clients_pkg)
def test_volumes_post(self, post):
keys = (
'display_description', 'snapshot_id', 'imageRef',
'server_id', 'display_description', 'snapshot_id', 'imageRef',
'volume_type', 'metadata', 'project')
for args in product(
('dd', None), ('sn', None), ('ir', None),
('sid', None), ('dd', None), ('sn', None), ('ir', None),
('vt', None), ({'mk': 'mv'}, None), ('pid', None),
({'k1': 'v1', 'k2': 'v2'}, {'success': 1000}, {})):
kwargs, server_id, display_name = args[-1], 'sid', 'dn'
kwargs, display_name = args[-1], 'dn'
args = args[:-1]
for err, size in ((TypeError, None), (ValueError, 'size')):
self.assertRaises(
err, self.client.volumes_post,
size, server_id, display_name, *args, **kwargs)
size, display_name, *args, **kwargs)
size = 42
self.client.volumes_post(
size, server_id, display_name, *args, **kwargs)
volume = dict(
size=int(size), server_id=server_id, display_name=display_name)
self.client.volumes_post(size, display_name, *args, **kwargs)
volume = dict(size=int(size), display_name=display_name)
for k, v in zip(keys, args):
if v:
volume[k] = v
......@@ -375,19 +373,19 @@ class CycladesBlockStorageClient(TestCase):
@patch('%s.volumes_post' % bsrest_pkg, return_value=FR())
def test_create_volume(self, volumes_post):
keys = (
'display_description', 'snapshot_id', 'imageRef',
'server_id', 'display_description', 'snapshot_id', 'imageRef',
'volume_type', 'metadata', 'project')
FR.json, server_id, display_name = dict(volume='ret'), 'vid', 'dn'
FR.json = dict(volume='ret')
display_name = 'display name'
for args in product(
('dd', None), ('sn', None), ('ir', None),
('si', None), ('dd', None), ('sn', None), ('ir', None),
('vt', None), ({'mk': 'mv'}, None), ('pid', None)):
self.assertEqual(
self.client.create_volume(42, server_id, display_name, *args),
'ret')
self.client.create_volume(42, display_name, *args), 'ret')
kwargs = dict(zip(keys, args))
self.assertEqual(
volumes_post.mock_calls[-1],
call(42, server_id, display_name, **kwargs))
call(42, display_name, **kwargs))
@patch('%s.volumes_action_post' % bsrest_pkg, return_value=FR())
def test_reassign_volume(self, volumes_action_post):
......@@ -398,16 +396,14 @@ class CycladesBlockStorageClient(TestCase):
@patch('%s.create_snapshot' % bsrest_pkg, return_value='ret')
def test_create_snapshot(self, create_snapshot):
keys = ('force', 'display_description')
volume_id, display_name = 'vid', 'dn'
for args in product((True, False, None), ('dd', None)):
keys = ('display_name', 'display_description')
volume_id = 'vid'
for args in product(('dn', None), ('dd', None)):
self.assertEqual(
self.client.create_snapshot(volume_id, display_name, *args),
'ret')
self.client.create_snapshot(volume_id, *args), 'ret')
kwargs = dict(zip(keys, args))
self.assertEqual(
create_snapshot.mock_calls[-1],
call(volume_id, display_name=display_name, **kwargs))
create_snapshot.mock_calls[-1], call(volume_id, **kwargs))
if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment