Switch command server add volume to sdk.

File tests.unit.volume.v2.fakes is modified to provide sdk volume fakes.
File tests.unit.compute.v2.fakes is modified to provide sdk volume
attachment fakes. For test, setup_sdk_volumes_mock() method is created
so that volumes are created in similar way as servers are created.

Change-Id: I290ba83b6ba27a1377ab73fd0ae06ecced25efd1
This commit is contained in:
Diwei Zhu 2021-10-28 23:25:52 +00:00
parent 8b394e5641
commit 3078a0a121
5 changed files with 296 additions and 170 deletions

View File

@ -548,24 +548,25 @@ class AddServerVolume(command.ShowOne):
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute compute_client = self.app.client_manager.sdk_connection.compute
volume_client = self.app.client_manager.volume volume_client = self.app.client_manager.sdk_connection.volume
server = utils.find_resource( server = compute_client.find_server(
compute_client.servers,
parsed_args.server, parsed_args.server,
ignore_missing=False,
) )
volume = utils.find_resource( volume = volume_client.find_volume(
volume_client.volumes,
parsed_args.volume, parsed_args.volume,
ignore_missing=False,
) )
kwargs = { kwargs = {
"volumeId": volume.id,
"device": parsed_args.device "device": parsed_args.device
} }
if parsed_args.tag: if parsed_args.tag:
if compute_client.api_version < api_versions.APIVersion('2.49'): if not sdk_utils.supports_microversion(compute_client, '2.49'):
msg = _( msg = _(
'--os-compute-api-version 2.49 or greater is required to ' '--os-compute-api-version 2.49 or greater is required to '
'support the --tag option' 'support the --tag option'
@ -575,7 +576,7 @@ class AddServerVolume(command.ShowOne):
kwargs['tag'] = parsed_args.tag kwargs['tag'] = parsed_args.tag
if parsed_args.enable_delete_on_termination: if parsed_args.enable_delete_on_termination:
if compute_client.api_version < api_versions.APIVersion('2.79'): if not sdk_utils.supports_microversion(compute_client, '2.79'):
msg = _( msg = _(
'--os-compute-api-version 2.79 or greater is required to ' '--os-compute-api-version 2.79 or greater is required to '
'support the --enable-delete-on-termination option.' 'support the --enable-delete-on-termination option.'
@ -585,7 +586,7 @@ class AddServerVolume(command.ShowOne):
kwargs['delete_on_termination'] = True kwargs['delete_on_termination'] = True
if parsed_args.disable_delete_on_termination: if parsed_args.disable_delete_on_termination:
if compute_client.api_version < api_versions.APIVersion('2.79'): if not sdk_utils.supports_microversion(compute_client, '2.79'):
msg = _( msg = _(
'--os-compute-api-version 2.79 or greater is required to ' '--os-compute-api-version 2.79 or greater is required to '
'support the --disable-delete-on-termination option.' 'support the --disable-delete-on-termination option.'
@ -594,28 +595,23 @@ class AddServerVolume(command.ShowOne):
kwargs['delete_on_termination'] = False kwargs['delete_on_termination'] = False
volume_attachment = compute_client.volumes.create_server_volume( volume_attachment = compute_client.create_volume_attachment(
server.id, server,
volume.id, **kwargs,
**kwargs
) )
columns = ('id', 'serverId', 'volumeId', 'device') columns = ('id', 'server id', 'volume id', 'device')
column_headers = ('ID', 'Server ID', 'Volume ID', 'Device') column_headers = ('ID', 'Server ID', 'Volume ID', 'Device')
if compute_client.api_version >= api_versions.APIVersion('2.49'): if sdk_utils.supports_microversion(compute_client, '2.49'):
columns += ('tag',) columns += ('tag',)
column_headers += ('Tag',) column_headers += ('Tag',)
if compute_client.api_version >= api_versions.APIVersion('2.79'): if sdk_utils.supports_microversion(compute_client, '2.79'):
columns += ('delete_on_termination',) columns += ('delete_on_termination',)
column_headers += ('Delete On Termination',) column_headers += ('Delete On Termination',)
return ( return (
column_headers, column_headers,
utils.get_item_properties( utils.get_item_properties(volume_attachment, columns,)
volume_attachment,
columns,
mixed_case_fields=('serverId', 'volumeId'),
)
) )

View File

@ -21,6 +21,7 @@ import uuid
from novaclient import api_versions from novaclient import api_versions
from openstack.compute.v2 import flavor as _flavor from openstack.compute.v2 import flavor as _flavor
from openstack.compute.v2 import server from openstack.compute.v2 import server
from openstack.compute.v2 import volume_attachment
from openstackclient.api import compute_v2 from openstackclient.api import compute_v2
from openstackclient.tests.unit import fakes from openstackclient.tests.unit import fakes
@ -1803,3 +1804,58 @@ class FakeVolumeAttachment(object):
attrs, methods)) attrs, methods))
return volume_attachments return volume_attachments
@staticmethod
def create_one_sdk_volume_attachment(attrs=None, methods=None):
"""Create a fake sdk VolumeAttachment.
:param dict attrs:
A dictionary with all attributes
:param dict methods:
A dictionary with all methods
:return:
A fake VolumeAttachment object, with id, device, and so on
"""
attrs = attrs or {}
methods = methods or {}
# Set default attributes.
volume_attachment_info = {
"id": uuid.uuid4().hex,
"device": "/dev/sdb",
"server_id": uuid.uuid4().hex,
"volume_id": uuid.uuid4().hex,
# introduced in API microversion 2.70
"tag": "foo",
# introduced in API microversion 2.79
"delete_on_termination": True,
# introduced in API microversion 2.89
"attachment_id": uuid.uuid4().hex,
"bdm_uuid": uuid.uuid4().hex
}
# Overwrite default attributes.
volume_attachment_info.update(attrs)
return volume_attachment.VolumeAttachment(**volume_attachment_info)
@staticmethod
def create_sdk_volume_attachments(attrs=None, methods=None, count=2):
"""Create multiple fake VolumeAttachment objects (BDMs).
:param dict attrs:
A dictionary with all attributes
:param dict methods:
A dictionary with all methods
:param int count:
The number of volume attachments to fake
:return:
A list of VolumeAttachment objects faking the volume attachments.
"""
volume_attachments = []
for i in range(0, count):
volume_attachments.append(
FakeVolumeAttachment.create_one_sdk_volume_attachment(
attrs, methods))
return volume_attachments

View File

@ -105,6 +105,9 @@ class TestServer(compute_fakes.TestComputev2):
self.volumes_mock = self.app.client_manager.volume.volumes self.volumes_mock = self.app.client_manager.volume.volumes
self.volumes_mock.reset_mock() self.volumes_mock.reset_mock()
self.app.client_manager.sdk_connection.volume = mock.Mock()
self.sdk_volume_client = self.app.client_manager.sdk_connection.volume
# Get a shortcut to the volume client VolumeManager Mock # Get a shortcut to the volume client VolumeManager Mock
self.snapshots_mock = self.app.client_manager.volume.volume_snapshots self.snapshots_mock = self.app.client_manager.volume.volume_snapshots
self.snapshots_mock.reset_mock() self.snapshots_mock.reset_mock()
@ -146,13 +149,18 @@ class TestServer(compute_fakes.TestComputev2):
) )
# This is the return value for compute_client.find_server() # This is the return value for compute_client.find_server()
self.sdk_client.find_server = compute_fakes.FakeServer.get_servers( self.sdk_client.find_server.side_effect = servers
servers,
0,
)
return servers return servers
def setup_sdk_volumes_mock(self, count):
volumes = volume_fakes.FakeVolume.create_sdk_volumes(count=count)
# This is the return value for volume_client.find_volume()
self.sdk_volume_client.find_volume.side_effect = volumes
return volumes
def run_method_with_servers(self, method_name, server_count): def run_method_with_servers(self, method_name, server_count):
servers = self.setup_servers_mock(server_count) servers = self.setup_servers_mock(server_count)
@ -680,31 +688,38 @@ class TestServerVolume(TestServer):
def setUp(self): def setUp(self):
super(TestServerVolume, self).setUp() super(TestServerVolume, self).setUp()
self.volume = volume_fakes.FakeVolume.create_one_volume()
self.volumes_mock.get.return_value = self.volume
self.methods = { self.methods = {
'create_server_volume': None, 'create_volume_attachment': None,
} }
# Get the command object to test # Get the command object to test
self.cmd = server.AddServerVolume(self.app, None) self.cmd = server.AddServerVolume(self.app, None)
def test_server_add_volume(self): self.servers = self.setup_sdk_servers_mock(count=1)
servers = self.setup_servers_mock(count=1) self.volumes = self.setup_sdk_volumes_mock(count=1)
volume_attachment = \
compute_fakes.FakeVolumeAttachment.create_one_volume_attachment() attrs = {
self.servers_volumes_mock.create_server_volume.return_value = \ 'server_id': self.servers[0].id,
volume_attachment 'volume_id': self.volumes[0].id,
}
self.volume_attachment = \
compute_fakes.FakeVolumeAttachment.\
create_one_sdk_volume_attachment(attrs=attrs)
self.sdk_client.create_volume_attachment.return_value = \
self.volume_attachment
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
def test_server_add_volume(self, sm_mock):
arglist = [ arglist = [
'--device', '/dev/sdb', '--device', '/dev/sdb',
servers[0].id, self.servers[0].id,
self.volume.id, self.volumes[0].id,
] ]
verifylist = [ verifylist = [
('server', servers[0].id), ('server', self.servers[0].id),
('volume', self.volume.id), ('volume', self.volumes[0].id),
('device', '/dev/sdb'), ('device', '/dev/sdb'),
] ]
@ -712,39 +727,36 @@ class TestServerVolume(TestServer):
expected_columns = ('ID', 'Server ID', 'Volume ID', 'Device') expected_columns = ('ID', 'Server ID', 'Volume ID', 'Device')
expected_data = ( expected_data = (
volume_attachment.id, self.volume_attachment.id,
volume_attachment.serverId, self.volume_attachment.server_id,
volume_attachment.volumeId, self.volume_attachment.volume_id,
volume_attachment.device, '/dev/sdb',
) )
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.servers_volumes_mock.create_server_volume.assert_called_once_with(
servers[0].id, self.volume.id, device='/dev/sdb')
self.assertEqual(expected_columns, columns) self.assertEqual(expected_columns, columns)
self.assertEqual(expected_data, data) self.assertEqual(expected_data, data)
self.sdk_client.create_volume_attachment.assert_called_once_with(
self.servers[0], volumeId=self.volumes[0].id, device='/dev/sdb')
def test_server_add_volume_with_tag(self): @mock.patch.object(sdk_utils, 'supports_microversion')
# requires API 2.49 or later def test_server_add_volume_with_tag(self, sm_mock):
self.app.client_manager.compute.api_version = api_versions.APIVersion( def side_effect(compute_client, version):
'2.49') if version == '2.49':
return True
servers = self.setup_servers_mock(count=1) return False
volume_attachment = \ sm_mock.side_effect = side_effect
compute_fakes.FakeVolumeAttachment.create_one_volume_attachment()
self.servers_volumes_mock.create_server_volume.return_value = \
volume_attachment
arglist = [ arglist = [
'--device', '/dev/sdb', '--device', '/dev/sdb',
'--tag', 'foo', '--tag', 'foo',
servers[0].id, self.servers[0].id,
self.volume.id, self.volumes[0].id,
] ]
verifylist = [ verifylist = [
('server', servers[0].id), ('server', self.servers[0].id),
('volume', self.volume.id), ('volume', self.volumes[0].id),
('device', '/dev/sdb'), ('device', '/dev/sdb'),
('tag', 'foo'), ('tag', 'foo'),
] ]
@ -753,33 +765,33 @@ class TestServerVolume(TestServer):
expected_columns = ('ID', 'Server ID', 'Volume ID', 'Device', 'Tag') expected_columns = ('ID', 'Server ID', 'Volume ID', 'Device', 'Tag')
expected_data = ( expected_data = (
volume_attachment.id, self.volume_attachment.id,
volume_attachment.serverId, self.volume_attachment.server_id,
volume_attachment.volumeId, self.volume_attachment.volume_id,
volume_attachment.device, self.volume_attachment.device,
volume_attachment.tag, self.volume_attachment.tag,
) )
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.servers_volumes_mock.create_server_volume.assert_called_once_with(
servers[0].id, self.volume.id, device='/dev/sdb', tag='foo')
self.assertEqual(expected_columns, columns) self.assertEqual(expected_columns, columns)
self.assertEqual(expected_data, data) self.assertEqual(expected_data, data)
self.sdk_client.create_volume_attachment.assert_called_once_with(
self.servers[0],
volumeId=self.volumes[0].id,
device='/dev/sdb',
tag='foo')
def test_server_add_volume_with_tag_pre_v249(self): @mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
self.app.client_manager.compute.api_version = api_versions.APIVersion( def test_server_add_volume_with_tag_pre_v249(self, sm_mock):
'2.48')
servers = self.setup_servers_mock(count=1)
arglist = [ arglist = [
servers[0].id, self.servers[0].id,
self.volume.id, self.volumes[0].id,
'--tag', 'foo', '--tag', 'foo',
] ]
verifylist = [ verifylist = [
('server', servers[0].id), ('server', self.servers[0].id),
('volume', self.volume.id), ('volume', self.volumes[0].id),
('tag', 'foo'), ('tag', 'foo'),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -792,26 +804,22 @@ class TestServerVolume(TestServer):
'--os-compute-api-version 2.49 or greater is required', '--os-compute-api-version 2.49 or greater is required',
str(ex)) str(ex))
def test_server_add_volume_with_enable_delete_on_termination(self): @mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
self.app.client_manager.compute.api_version = api_versions.APIVersion( def test_server_add_volume_with_enable_delete_on_termination(
'2.79') self,
sm_mock,
servers = self.setup_servers_mock(count=1) ):
volume_attachment = \ self.volume_attachment.delete_on_termination = True
compute_fakes.FakeVolumeAttachment.create_one_volume_attachment()
self.servers_volumes_mock.create_server_volume.return_value = \
volume_attachment
arglist = [ arglist = [
'--enable-delete-on-termination', '--enable-delete-on-termination',
'--device', '/dev/sdb', '--device', '/dev/sdb',
servers[0].id, self.servers[0].id,
self.volume.id, self.volumes[0].id,
] ]
verifylist = [ verifylist = [
('server', servers[0].id), ('server', self.servers[0].id),
('volume', self.volume.id), ('volume', self.volumes[0].id),
('device', '/dev/sdb'), ('device', '/dev/sdb'),
('enable_delete_on_termination', True), ('enable_delete_on_termination', True),
] ]
@ -826,42 +834,40 @@ class TestServerVolume(TestServer):
'Delete On Termination', 'Delete On Termination',
) )
expected_data = ( expected_data = (
volume_attachment.id, self.volume_attachment.id,
volume_attachment.serverId, self.volume_attachment.server_id,
volume_attachment.volumeId, self.volume_attachment.volume_id,
volume_attachment.device, self.volume_attachment.device,
volume_attachment.tag, self.volume_attachment.tag,
volume_attachment.delete_on_termination, self.volume_attachment.delete_on_termination,
) )
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.servers_volumes_mock.create_server_volume.assert_called_once_with(
servers[0].id, self.volume.id,
device='/dev/sdb', delete_on_termination=True)
self.assertEqual(expected_columns, columns) self.assertEqual(expected_columns, columns)
self.assertEqual(expected_data, data) self.assertEqual(expected_data, data)
self.sdk_client.create_volume_attachment.assert_called_once_with(
self.servers[0],
volumeId=self.volumes[0].id,
device='/dev/sdb',
delete_on_termination=True)
def test_server_add_volume_with_disable_delete_on_termination(self): @mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
self.app.client_manager.compute.api_version = api_versions.APIVersion( def test_server_add_volume_with_disable_delete_on_termination(
'2.79') self,
sm_mock,
servers = self.setup_servers_mock(count=1) ):
volume_attachment = \ self.volume_attachment.delete_on_termination = False
compute_fakes.FakeVolumeAttachment.create_one_volume_attachment()
self.servers_volumes_mock.create_server_volume.return_value = \
volume_attachment
arglist = [ arglist = [
'--disable-delete-on-termination', '--disable-delete-on-termination',
'--device', '/dev/sdb', '--device', '/dev/sdb',
servers[0].id, self.servers[0].id,
self.volume.id, self.volumes[0].id,
] ]
verifylist = [ verifylist = [
('server', servers[0].id), ('server', self.servers[0].id),
('volume', self.volume.id), ('volume', self.volumes[0].id),
('device', '/dev/sdb'), ('device', '/dev/sdb'),
('disable_delete_on_termination', True), ('disable_delete_on_termination', True),
] ]
@ -876,37 +882,43 @@ class TestServerVolume(TestServer):
'Delete On Termination', 'Delete On Termination',
) )
expected_data = ( expected_data = (
volume_attachment.id, self.volume_attachment.id,
volume_attachment.serverId, self.volume_attachment.server_id,
volume_attachment.volumeId, self.volume_attachment.volume_id,
volume_attachment.device, self.volume_attachment.device,
volume_attachment.tag, self.volume_attachment.tag,
volume_attachment.delete_on_termination, self.volume_attachment.delete_on_termination,
) )
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.servers_volumes_mock.create_server_volume.assert_called_once_with(
servers[0].id, self.volume.id,
device='/dev/sdb', delete_on_termination=False)
self.assertEqual(expected_columns, columns) self.assertEqual(expected_columns, columns)
self.assertEqual(expected_data, data) self.assertEqual(expected_data, data)
self.sdk_client.create_volume_attachment.assert_called_once_with(
self.servers[0],
volumeId=self.volumes[0].id,
device='/dev/sdb',
delete_on_termination=False)
@mock.patch.object(sdk_utils, 'supports_microversion')
def test_server_add_volume_with_enable_delete_on_termination_pre_v279( def test_server_add_volume_with_enable_delete_on_termination_pre_v279(
self, self,
sm_mock,
): ):
self.app.client_manager.compute.api_version = api_versions.APIVersion( def side_effect(compute_client, version):
'2.78') if version == '2.79':
return False
return True
sm_mock.side_effect = side_effect
servers = self.setup_servers_mock(count=1)
arglist = [ arglist = [
servers[0].id, self.servers[0].id,
self.volume.id, self.volumes[0].id,
'--enable-delete-on-termination', '--enable-delete-on-termination',
] ]
verifylist = [ verifylist = [
('server', servers[0].id), ('server', self.servers[0].id),
('volume', self.volume.id), ('volume', self.volumes[0].id),
('enable_delete_on_termination', True), ('enable_delete_on_termination', True),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -917,21 +929,25 @@ class TestServerVolume(TestServer):
self.assertIn('--os-compute-api-version 2.79 or greater is required', self.assertIn('--os-compute-api-version 2.79 or greater is required',
str(ex)) str(ex))
@mock.patch.object(sdk_utils, 'supports_microversion')
def test_server_add_volume_with_disable_delete_on_termination_pre_v279( def test_server_add_volume_with_disable_delete_on_termination_pre_v279(
self, self,
sm_mock,
): ):
self.app.client_manager.compute.api_version = api_versions.APIVersion( def side_effect(compute_client, version):
'2.78') if version == '2.79':
return False
return True
sm_mock.side_effect = side_effect
servers = self.setup_servers_mock(count=1)
arglist = [ arglist = [
servers[0].id, self.servers[0].id,
self.volume.id, self.volumes[0].id,
'--disable-delete-on-termination', '--disable-delete-on-termination',
] ]
verifylist = [ verifylist = [
('server', servers[0].id), ('server', self.servers[0].id),
('volume', self.volume.id), ('volume', self.volumes[0].id),
('disable_delete_on_termination', True), ('disable_delete_on_termination', True),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -942,24 +958,22 @@ class TestServerVolume(TestServer):
self.assertIn('--os-compute-api-version 2.79 or greater is required', self.assertIn('--os-compute-api-version 2.79 or greater is required',
str(ex)) str(ex))
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
def test_server_add_volume_with_disable_and_enable_delete_on_termination( def test_server_add_volume_with_disable_and_enable_delete_on_termination(
self, self,
sm_mock,
): ):
self.app.client_manager.compute.api_version = api_versions.APIVersion(
'2.79')
servers = self.setup_servers_mock(count=1)
arglist = [ arglist = [
'--enable-delete-on-termination', '--enable-delete-on-termination',
'--disable-delete-on-termination', '--disable-delete-on-termination',
'--device', '/dev/sdb', '--device', '/dev/sdb',
servers[0].id, self.servers[0].id,
self.volume.id, self.volumes[0].id,
] ]
verifylist = [ verifylist = [
('server', servers[0].id), ('server', self.servers[0].id),
('volume', self.volume.id), ('volume', self.volumes[0].id),
('device', '/dev/sdb'), ('device', '/dev/sdb'),
('enable_delete_on_termination', True), ('enable_delete_on_termination', True),
('disable_delete_on_termination', True), ('disable_delete_on_termination', True),

View File

@ -18,6 +18,7 @@ from unittest import mock
import uuid import uuid
from cinderclient import api_versions from cinderclient import api_versions
from openstack.block_storage.v3 import volume
from osc_lib.cli import format_columns from osc_lib.cli import format_columns
from openstackclient.tests.unit import fakes from openstackclient.tests.unit import fakes
@ -46,7 +47,7 @@ class FakeTransfer(object):
def create_one_transfer(attrs=None): def create_one_transfer(attrs=None):
"""Create a fake transfer. """Create a fake transfer.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes of Transfer Request A dictionary with all attributes of Transfer Request
:return: :return:
A FakeResource object with volume_id, name, id. A FakeResource object with volume_id, name, id.
@ -75,7 +76,7 @@ class FakeTransfer(object):
def create_transfers(attrs=None, count=2): def create_transfers(attrs=None, count=2):
"""Create multiple fake transfers. """Create multiple fake transfers.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes of transfer A dictionary with all attributes of transfer
:param Integer count: :param Integer count:
The number of transfers to be faked The number of transfers to be faked
@ -116,7 +117,7 @@ class FakeTypeAccess(object):
def create_one_type_access(attrs=None): def create_one_type_access(attrs=None):
"""Create a fake volume type access for project. """Create a fake volume type access for project.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object, with Volume_type_ID and Project_ID. A FakeResource object, with Volume_type_ID and Project_ID.
@ -148,7 +149,7 @@ class FakeService(object):
def create_one_service(attrs=None): def create_one_service(attrs=None):
"""Create a fake service. """Create a fake service.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes of service A dictionary with all attributes of service
:return: :return:
A FakeResource object with host, status, etc. A FakeResource object with host, status, etc.
@ -180,7 +181,7 @@ class FakeService(object):
def create_services(attrs=None, count=2): def create_services(attrs=None, count=2):
"""Create multiple fake services. """Create multiple fake services.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes of service A dictionary with all attributes of service
:param Integer count: :param Integer count:
The number of services to be faked The number of services to be faked
@ -201,7 +202,7 @@ class FakeCapability(object):
def create_one_capability(attrs=None): def create_one_capability(attrs=None):
"""Create a fake volume backend capability. """Create a fake volume backend capability.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes of the Capabilities. A dictionary with all attributes of the Capabilities.
:return: :return:
A FakeResource object with capability name and attrs. A FakeResource object with capability name and attrs.
@ -260,7 +261,7 @@ class FakePool(object):
def create_one_pool(attrs=None): def create_one_pool(attrs=None):
"""Create a fake pool. """Create a fake pool.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes of the pool A dictionary with all attributes of the pool
:return: :return:
A FakeResource object with pool name and attrs. A FakeResource object with pool name and attrs.
@ -362,7 +363,7 @@ class FakeVolume(object):
def create_one_volume(attrs=None): def create_one_volume(attrs=None):
"""Create a fake volume. """Create a fake volume.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes of volume A dictionary with all attributes of volume
:return: :return:
A FakeResource object with id, name, status, etc. A FakeResource object with id, name, status, etc.
@ -405,7 +406,7 @@ class FakeVolume(object):
def create_volumes(attrs=None, count=2): def create_volumes(attrs=None, count=2):
"""Create multiple fake volumes. """Create multiple fake volumes.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes of volume A dictionary with all attributes of volume
:param Integer count: :param Integer count:
The number of volumes to be faked The number of volumes to be faked
@ -418,6 +419,61 @@ class FakeVolume(object):
return volumes return volumes
@staticmethod
def create_one_sdk_volume(attrs=None):
"""Create a fake volume.
:param dict attrs:
A dictionary with all attributes of volume
:return:
A FakeResource object with id, name, status, etc.
"""
attrs = attrs or {}
# Set default attribute
volume_info = {
'id': 'volume-id' + uuid.uuid4().hex,
'name': 'volume-name' + uuid.uuid4().hex,
'description': 'description' + uuid.uuid4().hex,
'status': random.choice(['available', 'in_use']),
'size': random.randint(1, 20),
'volume_type':
random.choice(['fake_lvmdriver-1', 'fake_lvmdriver-2']),
'bootable':
random.choice(['true', 'false']),
'metadata': {
'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex,
'key' + uuid.uuid4().hex: 'val' + uuid.uuid4().hex},
'snapshot_id': random.randint(1, 5),
'availability_zone': 'zone' + uuid.uuid4().hex,
'attachments': [{
'device': '/dev/' + uuid.uuid4().hex,
'server_id': uuid.uuid4().hex,
}, ],
}
# Overwrite default attributes if there are some attributes set
volume_info.update(attrs)
return volume.Volume(**volume_info)
@staticmethod
def create_sdk_volumes(attrs=None, count=2):
"""Create multiple fake volumes.
:param dict attrs:
A dictionary with all attributes of volume
:param Integer count:
The number of volumes to be faked
:return:
A list of FakeResource objects
"""
volumes = []
for n in range(0, count):
volumes.append(FakeVolume.create_one_sdk_volume(attrs))
return volumes
@staticmethod @staticmethod
def get_volumes(volumes=None, count=2): def get_volumes(volumes=None, count=2):
"""Get an iterable MagicMock object with a list of faked volumes. """Get an iterable MagicMock object with a list of faked volumes.
@ -484,7 +540,7 @@ class FakeAvailabilityZone(object):
def create_one_availability_zone(attrs=None): def create_one_availability_zone(attrs=None):
"""Create a fake AZ. """Create a fake AZ.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object with zoneName, zoneState, etc. A FakeResource object with zoneName, zoneState, etc.
@ -509,7 +565,7 @@ class FakeAvailabilityZone(object):
def create_availability_zones(attrs=None, count=2): def create_availability_zones(attrs=None, count=2):
"""Create multiple fake AZs. """Create multiple fake AZs.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:param int count: :param int count:
The number of AZs to fake The number of AZs to fake
@ -532,7 +588,7 @@ class FakeBackup(object):
def create_one_backup(attrs=None): def create_one_backup(attrs=None):
"""Create a fake backup. """Create a fake backup.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object with id, name, volume_id, etc. A FakeResource object with id, name, volume_id, etc.
@ -565,7 +621,7 @@ class FakeBackup(object):
def create_backups(attrs=None, count=2): def create_backups(attrs=None, count=2):
"""Create multiple fake backups. """Create multiple fake backups.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:param int count: :param int count:
The number of backups to fake The number of backups to fake
@ -636,7 +692,7 @@ class FakeConsistencyGroup(object):
def create_one_consistency_group(attrs=None): def create_one_consistency_group(attrs=None):
"""Create a fake consistency group. """Create a fake consistency group.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object with id, name, description, etc. A FakeResource object with id, name, description, etc.
@ -666,7 +722,7 @@ class FakeConsistencyGroup(object):
def create_consistency_groups(attrs=None, count=2): def create_consistency_groups(attrs=None, count=2):
"""Create multiple fake consistency groups. """Create multiple fake consistency groups.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:param int count: :param int count:
The number of consistency groups to fake The number of consistency groups to fake
@ -713,7 +769,7 @@ class FakeConsistencyGroupSnapshot(object):
def create_one_consistency_group_snapshot(attrs=None): def create_one_consistency_group_snapshot(attrs=None):
"""Create a fake consistency group snapshot. """Create a fake consistency group snapshot.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object with id, name, description, etc. A FakeResource object with id, name, description, etc.
@ -742,7 +798,7 @@ class FakeConsistencyGroupSnapshot(object):
def create_consistency_group_snapshots(attrs=None, count=2): def create_consistency_group_snapshots(attrs=None, count=2):
"""Create multiple fake consistency group snapshots. """Create multiple fake consistency group snapshots.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:param int count: :param int count:
The number of consistency group snapshots to fake The number of consistency group snapshots to fake
@ -789,7 +845,7 @@ class FakeExtension(object):
def create_one_extension(attrs=None): def create_one_extension(attrs=None):
"""Create a fake extension. """Create a fake extension.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object with name, namespace, etc. A FakeResource object with name, namespace, etc.
@ -825,7 +881,7 @@ class FakeQos(object):
def create_one_qos(attrs=None): def create_one_qos(attrs=None):
"""Create a fake Qos specification. """Create a fake Qos specification.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object with id, name, consumer, etc. A FakeResource object with id, name, consumer, etc.
@ -852,7 +908,7 @@ class FakeQos(object):
def create_one_qos_association(attrs=None): def create_one_qos_association(attrs=None):
"""Create a fake Qos specification association. """Create a fake Qos specification association.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object with id, name, association_type, etc. A FakeResource object with id, name, association_type, etc.
@ -878,7 +934,7 @@ class FakeQos(object):
def create_qoses(attrs=None, count=2): def create_qoses(attrs=None, count=2):
"""Create multiple fake Qos specifications. """Create multiple fake Qos specifications.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:param int count: :param int count:
The number of Qos specifications to fake The number of Qos specifications to fake
@ -920,7 +976,7 @@ class FakeSnapshot(object):
def create_one_snapshot(attrs=None): def create_one_snapshot(attrs=None):
"""Create a fake snapshot. """Create a fake snapshot.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object with id, name, description, etc. A FakeResource object with id, name, description, etc.
@ -951,7 +1007,7 @@ class FakeSnapshot(object):
def create_snapshots(attrs=None, count=2): def create_snapshots(attrs=None, count=2):
"""Create multiple fake snapshots. """Create multiple fake snapshots.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:param int count: :param int count:
The number of snapshots to fake The number of snapshots to fake
@ -993,9 +1049,9 @@ class FakeVolumeType(object):
def create_one_volume_type(attrs=None, methods=None): def create_one_volume_type(attrs=None, methods=None):
"""Create a fake volume type. """Create a fake volume type.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:param Dictionary methods: :param dict methods:
A dictionary with all methods A dictionary with all methods
:return: :return:
A FakeResource object with id, name, description, etc. A FakeResource object with id, name, description, etc.
@ -1025,7 +1081,7 @@ class FakeVolumeType(object):
def create_volume_types(attrs=None, count=2): def create_volume_types(attrs=None, count=2):
"""Create multiple fake volume_types. """Create multiple fake volume_types.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:param int count: :param int count:
The number of types to fake The number of types to fake
@ -1063,7 +1119,7 @@ class FakeVolumeType(object):
def create_one_encryption_volume_type(attrs=None): def create_one_encryption_volume_type(attrs=None):
"""Create a fake encryption volume type. """Create a fake encryption volume type.
:param Dictionary attrs: :param dict attrs:
A dictionary with all attributes A dictionary with all attributes
:return: :return:
A FakeResource object with volume_type_id etc. A FakeResource object with volume_type_id etc.

View File

@ -0,0 +1,4 @@
---
features:
- |
Migrate openstack server add volume to using sdk.