Merge "Switch command server add volume to sdk."
This commit is contained in:
commit
4b3cdaf8b1
openstackclient
releasenotes/notes
@ -548,24 +548,25 @@ class AddServerVolume(command.ShowOne):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
volume_client = self.app.client_manager.volume
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
volume_client = self.app.client_manager.sdk_connection.volume
|
||||
|
||||
server = utils.find_resource(
|
||||
compute_client.servers,
|
||||
server = compute_client.find_server(
|
||||
parsed_args.server,
|
||||
ignore_missing=False,
|
||||
)
|
||||
volume = utils.find_resource(
|
||||
volume_client.volumes,
|
||||
volume = volume_client.find_volume(
|
||||
parsed_args.volume,
|
||||
ignore_missing=False,
|
||||
)
|
||||
|
||||
kwargs = {
|
||||
"volumeId": volume.id,
|
||||
"device": parsed_args.device
|
||||
}
|
||||
|
||||
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 = _(
|
||||
'--os-compute-api-version 2.49 or greater is required to '
|
||||
'support the --tag option'
|
||||
@ -575,7 +576,7 @@ class AddServerVolume(command.ShowOne):
|
||||
kwargs['tag'] = parsed_args.tag
|
||||
|
||||
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 = _(
|
||||
'--os-compute-api-version 2.79 or greater is required to '
|
||||
'support the --enable-delete-on-termination option.'
|
||||
@ -585,7 +586,7 @@ class AddServerVolume(command.ShowOne):
|
||||
kwargs['delete_on_termination'] = True
|
||||
|
||||
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 = _(
|
||||
'--os-compute-api-version 2.79 or greater is required to '
|
||||
'support the --disable-delete-on-termination option.'
|
||||
@ -594,28 +595,23 @@ class AddServerVolume(command.ShowOne):
|
||||
|
||||
kwargs['delete_on_termination'] = False
|
||||
|
||||
volume_attachment = compute_client.volumes.create_server_volume(
|
||||
server.id,
|
||||
volume.id,
|
||||
**kwargs
|
||||
volume_attachment = compute_client.create_volume_attachment(
|
||||
server,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
columns = ('id', 'serverId', 'volumeId', 'device')
|
||||
columns = ('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',)
|
||||
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',)
|
||||
column_headers += ('Delete On Termination',)
|
||||
|
||||
return (
|
||||
column_headers,
|
||||
utils.get_item_properties(
|
||||
volume_attachment,
|
||||
columns,
|
||||
mixed_case_fields=('serverId', 'volumeId'),
|
||||
)
|
||||
utils.get_item_properties(volume_attachment, columns,)
|
||||
)
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@ import uuid
|
||||
from novaclient import api_versions
|
||||
from openstack.compute.v2 import flavor as _flavor
|
||||
from openstack.compute.v2 import server
|
||||
from openstack.compute.v2 import volume_attachment
|
||||
|
||||
from openstackclient.api import compute_v2
|
||||
from openstackclient.tests.unit import fakes
|
||||
@ -1803,3 +1804,58 @@ class FakeVolumeAttachment(object):
|
||||
attrs, methods))
|
||||
|
||||
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
|
||||
|
@ -105,6 +105,9 @@ class TestServer(compute_fakes.TestComputev2):
|
||||
self.volumes_mock = self.app.client_manager.volume.volumes
|
||||
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
|
||||
self.snapshots_mock = self.app.client_manager.volume.volume_snapshots
|
||||
self.snapshots_mock.reset_mock()
|
||||
@ -146,13 +149,18 @@ class TestServer(compute_fakes.TestComputev2):
|
||||
)
|
||||
|
||||
# This is the return value for compute_client.find_server()
|
||||
self.sdk_client.find_server = compute_fakes.FakeServer.get_servers(
|
||||
servers,
|
||||
0,
|
||||
)
|
||||
self.sdk_client.find_server.side_effect = 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):
|
||||
servers = self.setup_servers_mock(server_count)
|
||||
|
||||
@ -680,31 +688,38 @@ class TestServerVolume(TestServer):
|
||||
def setUp(self):
|
||||
super(TestServerVolume, self).setUp()
|
||||
|
||||
self.volume = volume_fakes.FakeVolume.create_one_volume()
|
||||
self.volumes_mock.get.return_value = self.volume
|
||||
|
||||
self.methods = {
|
||||
'create_server_volume': None,
|
||||
'create_volume_attachment': None,
|
||||
}
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = server.AddServerVolume(self.app, None)
|
||||
|
||||
def test_server_add_volume(self):
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
volume_attachment = \
|
||||
compute_fakes.FakeVolumeAttachment.create_one_volume_attachment()
|
||||
self.servers_volumes_mock.create_server_volume.return_value = \
|
||||
volume_attachment
|
||||
self.servers = self.setup_sdk_servers_mock(count=1)
|
||||
self.volumes = self.setup_sdk_volumes_mock(count=1)
|
||||
|
||||
attrs = {
|
||||
'server_id': self.servers[0].id,
|
||||
'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 = [
|
||||
'--device', '/dev/sdb',
|
||||
servers[0].id,
|
||||
self.volume.id,
|
||||
self.servers[0].id,
|
||||
self.volumes[0].id,
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('volume', self.volume.id),
|
||||
('server', self.servers[0].id),
|
||||
('volume', self.volumes[0].id),
|
||||
('device', '/dev/sdb'),
|
||||
]
|
||||
|
||||
@ -712,39 +727,36 @@ class TestServerVolume(TestServer):
|
||||
|
||||
expected_columns = ('ID', 'Server ID', 'Volume ID', 'Device')
|
||||
expected_data = (
|
||||
volume_attachment.id,
|
||||
volume_attachment.serverId,
|
||||
volume_attachment.volumeId,
|
||||
volume_attachment.device,
|
||||
self.volume_attachment.id,
|
||||
self.volume_attachment.server_id,
|
||||
self.volume_attachment.volume_id,
|
||||
'/dev/sdb',
|
||||
)
|
||||
|
||||
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_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):
|
||||
# requires API 2.49 or later
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.49')
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
volume_attachment = \
|
||||
compute_fakes.FakeVolumeAttachment.create_one_volume_attachment()
|
||||
self.servers_volumes_mock.create_server_volume.return_value = \
|
||||
volume_attachment
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
def test_server_add_volume_with_tag(self, sm_mock):
|
||||
def side_effect(compute_client, version):
|
||||
if version == '2.49':
|
||||
return True
|
||||
return False
|
||||
sm_mock.side_effect = side_effect
|
||||
|
||||
arglist = [
|
||||
'--device', '/dev/sdb',
|
||||
'--tag', 'foo',
|
||||
servers[0].id,
|
||||
self.volume.id,
|
||||
self.servers[0].id,
|
||||
self.volumes[0].id,
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('volume', self.volume.id),
|
||||
('server', self.servers[0].id),
|
||||
('volume', self.volumes[0].id),
|
||||
('device', '/dev/sdb'),
|
||||
('tag', 'foo'),
|
||||
]
|
||||
@ -753,33 +765,33 @@ class TestServerVolume(TestServer):
|
||||
|
||||
expected_columns = ('ID', 'Server ID', 'Volume ID', 'Device', 'Tag')
|
||||
expected_data = (
|
||||
volume_attachment.id,
|
||||
volume_attachment.serverId,
|
||||
volume_attachment.volumeId,
|
||||
volume_attachment.device,
|
||||
volume_attachment.tag,
|
||||
self.volume_attachment.id,
|
||||
self.volume_attachment.server_id,
|
||||
self.volume_attachment.volume_id,
|
||||
self.volume_attachment.device,
|
||||
self.volume_attachment.tag,
|
||||
)
|
||||
|
||||
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_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):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.48')
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=False)
|
||||
def test_server_add_volume_with_tag_pre_v249(self, sm_mock):
|
||||
arglist = [
|
||||
servers[0].id,
|
||||
self.volume.id,
|
||||
self.servers[0].id,
|
||||
self.volumes[0].id,
|
||||
'--tag', 'foo',
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('volume', self.volume.id),
|
||||
('server', self.servers[0].id),
|
||||
('volume', self.volumes[0].id),
|
||||
('tag', 'foo'),
|
||||
]
|
||||
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',
|
||||
str(ex))
|
||||
|
||||
def test_server_add_volume_with_enable_delete_on_termination(self):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.79')
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
volume_attachment = \
|
||||
compute_fakes.FakeVolumeAttachment.create_one_volume_attachment()
|
||||
self.servers_volumes_mock.create_server_volume.return_value = \
|
||||
volume_attachment
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_server_add_volume_with_enable_delete_on_termination(
|
||||
self,
|
||||
sm_mock,
|
||||
):
|
||||
self.volume_attachment.delete_on_termination = True
|
||||
arglist = [
|
||||
'--enable-delete-on-termination',
|
||||
'--device', '/dev/sdb',
|
||||
servers[0].id,
|
||||
self.volume.id,
|
||||
self.servers[0].id,
|
||||
self.volumes[0].id,
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('volume', self.volume.id),
|
||||
('server', self.servers[0].id),
|
||||
('volume', self.volumes[0].id),
|
||||
('device', '/dev/sdb'),
|
||||
('enable_delete_on_termination', True),
|
||||
]
|
||||
@ -826,42 +834,40 @@ class TestServerVolume(TestServer):
|
||||
'Delete On Termination',
|
||||
)
|
||||
expected_data = (
|
||||
volume_attachment.id,
|
||||
volume_attachment.serverId,
|
||||
volume_attachment.volumeId,
|
||||
volume_attachment.device,
|
||||
volume_attachment.tag,
|
||||
volume_attachment.delete_on_termination,
|
||||
self.volume_attachment.id,
|
||||
self.volume_attachment.server_id,
|
||||
self.volume_attachment.volume_id,
|
||||
self.volume_attachment.device,
|
||||
self.volume_attachment.tag,
|
||||
self.volume_attachment.delete_on_termination,
|
||||
)
|
||||
|
||||
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_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):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.79')
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
volume_attachment = \
|
||||
compute_fakes.FakeVolumeAttachment.create_one_volume_attachment()
|
||||
self.servers_volumes_mock.create_server_volume.return_value = \
|
||||
volume_attachment
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_server_add_volume_with_disable_delete_on_termination(
|
||||
self,
|
||||
sm_mock,
|
||||
):
|
||||
self.volume_attachment.delete_on_termination = False
|
||||
|
||||
arglist = [
|
||||
'--disable-delete-on-termination',
|
||||
'--device', '/dev/sdb',
|
||||
servers[0].id,
|
||||
self.volume.id,
|
||||
self.servers[0].id,
|
||||
self.volumes[0].id,
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('volume', self.volume.id),
|
||||
('server', self.servers[0].id),
|
||||
('volume', self.volumes[0].id),
|
||||
('device', '/dev/sdb'),
|
||||
('disable_delete_on_termination', True),
|
||||
]
|
||||
@ -876,37 +882,43 @@ class TestServerVolume(TestServer):
|
||||
'Delete On Termination',
|
||||
)
|
||||
expected_data = (
|
||||
volume_attachment.id,
|
||||
volume_attachment.serverId,
|
||||
volume_attachment.volumeId,
|
||||
volume_attachment.device,
|
||||
volume_attachment.tag,
|
||||
volume_attachment.delete_on_termination,
|
||||
self.volume_attachment.id,
|
||||
self.volume_attachment.server_id,
|
||||
self.volume_attachment.volume_id,
|
||||
self.volume_attachment.device,
|
||||
self.volume_attachment.tag,
|
||||
self.volume_attachment.delete_on_termination,
|
||||
)
|
||||
|
||||
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_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(
|
||||
self,
|
||||
sm_mock,
|
||||
):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.78')
|
||||
def side_effect(compute_client, version):
|
||||
if version == '2.79':
|
||||
return False
|
||||
return True
|
||||
sm_mock.side_effect = side_effect
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
arglist = [
|
||||
servers[0].id,
|
||||
self.volume.id,
|
||||
self.servers[0].id,
|
||||
self.volumes[0].id,
|
||||
'--enable-delete-on-termination',
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('volume', self.volume.id),
|
||||
('server', self.servers[0].id),
|
||||
('volume', self.volumes[0].id),
|
||||
('enable_delete_on_termination', True),
|
||||
]
|
||||
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',
|
||||
str(ex))
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion')
|
||||
def test_server_add_volume_with_disable_delete_on_termination_pre_v279(
|
||||
self,
|
||||
sm_mock,
|
||||
):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.78')
|
||||
def side_effect(compute_client, version):
|
||||
if version == '2.79':
|
||||
return False
|
||||
return True
|
||||
sm_mock.side_effect = side_effect
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
arglist = [
|
||||
servers[0].id,
|
||||
self.volume.id,
|
||||
self.servers[0].id,
|
||||
self.volumes[0].id,
|
||||
'--disable-delete-on-termination',
|
||||
]
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('volume', self.volume.id),
|
||||
('server', self.servers[0].id),
|
||||
('volume', self.volumes[0].id),
|
||||
('disable_delete_on_termination', True),
|
||||
]
|
||||
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',
|
||||
str(ex))
|
||||
|
||||
@mock.patch.object(sdk_utils, 'supports_microversion', return_value=True)
|
||||
def test_server_add_volume_with_disable_and_enable_delete_on_termination(
|
||||
self,
|
||||
sm_mock,
|
||||
):
|
||||
self.app.client_manager.compute.api_version = api_versions.APIVersion(
|
||||
'2.79')
|
||||
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
arglist = [
|
||||
'--enable-delete-on-termination',
|
||||
'--disable-delete-on-termination',
|
||||
'--device', '/dev/sdb',
|
||||
servers[0].id,
|
||||
self.volume.id,
|
||||
self.servers[0].id,
|
||||
self.volumes[0].id,
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
('server', servers[0].id),
|
||||
('volume', self.volume.id),
|
||||
('server', self.servers[0].id),
|
||||
('volume', self.volumes[0].id),
|
||||
('device', '/dev/sdb'),
|
||||
('enable_delete_on_termination', True),
|
||||
('disable_delete_on_termination', True),
|
||||
|
@ -18,6 +18,7 @@ from unittest import mock
|
||||
import uuid
|
||||
|
||||
from cinderclient import api_versions
|
||||
from openstack.block_storage.v3 import volume
|
||||
from osc_lib.cli import format_columns
|
||||
|
||||
from openstackclient.tests.unit import fakes
|
||||
@ -46,7 +47,7 @@ class FakeTransfer(object):
|
||||
def create_one_transfer(attrs=None):
|
||||
"""Create a fake transfer.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes of Transfer Request
|
||||
:return:
|
||||
A FakeResource object with volume_id, name, id.
|
||||
@ -75,7 +76,7 @@ class FakeTransfer(object):
|
||||
def create_transfers(attrs=None, count=2):
|
||||
"""Create multiple fake transfers.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes of transfer
|
||||
:param Integer count:
|
||||
The number of transfers to be faked
|
||||
@ -116,7 +117,7 @@ class FakeTypeAccess(object):
|
||||
def create_one_type_access(attrs=None):
|
||||
"""Create a fake volume type access for project.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object, with Volume_type_ID and Project_ID.
|
||||
@ -148,7 +149,7 @@ class FakeService(object):
|
||||
def create_one_service(attrs=None):
|
||||
"""Create a fake service.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes of service
|
||||
:return:
|
||||
A FakeResource object with host, status, etc.
|
||||
@ -180,7 +181,7 @@ class FakeService(object):
|
||||
def create_services(attrs=None, count=2):
|
||||
"""Create multiple fake services.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes of service
|
||||
:param Integer count:
|
||||
The number of services to be faked
|
||||
@ -201,7 +202,7 @@ class FakeCapability(object):
|
||||
def create_one_capability(attrs=None):
|
||||
"""Create a fake volume backend capability.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes of the Capabilities.
|
||||
:return:
|
||||
A FakeResource object with capability name and attrs.
|
||||
@ -260,7 +261,7 @@ class FakePool(object):
|
||||
def create_one_pool(attrs=None):
|
||||
"""Create a fake pool.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes of the pool
|
||||
:return:
|
||||
A FakeResource object with pool name and attrs.
|
||||
@ -362,7 +363,7 @@ class FakeVolume(object):
|
||||
def create_one_volume(attrs=None):
|
||||
"""Create a fake volume.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes of volume
|
||||
:return:
|
||||
A FakeResource object with id, name, status, etc.
|
||||
@ -405,7 +406,7 @@ class FakeVolume(object):
|
||||
def create_volumes(attrs=None, count=2):
|
||||
"""Create multiple fake volumes.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes of volume
|
||||
:param Integer count:
|
||||
The number of volumes to be faked
|
||||
@ -418,6 +419,61 @@ class FakeVolume(object):
|
||||
|
||||
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
|
||||
def get_volumes(volumes=None, count=2):
|
||||
"""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):
|
||||
"""Create a fake AZ.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with zoneName, zoneState, etc.
|
||||
@ -509,7 +565,7 @@ class FakeAvailabilityZone(object):
|
||||
def create_availability_zones(attrs=None, count=2):
|
||||
"""Create multiple fake AZs.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:param int count:
|
||||
The number of AZs to fake
|
||||
@ -532,7 +588,7 @@ class FakeBackup(object):
|
||||
def create_one_backup(attrs=None):
|
||||
"""Create a fake backup.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with id, name, volume_id, etc.
|
||||
@ -565,7 +621,7 @@ class FakeBackup(object):
|
||||
def create_backups(attrs=None, count=2):
|
||||
"""Create multiple fake backups.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:param int count:
|
||||
The number of backups to fake
|
||||
@ -636,7 +692,7 @@ class FakeConsistencyGroup(object):
|
||||
def create_one_consistency_group(attrs=None):
|
||||
"""Create a fake consistency group.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with id, name, description, etc.
|
||||
@ -666,7 +722,7 @@ class FakeConsistencyGroup(object):
|
||||
def create_consistency_groups(attrs=None, count=2):
|
||||
"""Create multiple fake consistency groups.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:param int count:
|
||||
The number of consistency groups to fake
|
||||
@ -713,7 +769,7 @@ class FakeConsistencyGroupSnapshot(object):
|
||||
def create_one_consistency_group_snapshot(attrs=None):
|
||||
"""Create a fake consistency group snapshot.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with id, name, description, etc.
|
||||
@ -742,7 +798,7 @@ class FakeConsistencyGroupSnapshot(object):
|
||||
def create_consistency_group_snapshots(attrs=None, count=2):
|
||||
"""Create multiple fake consistency group snapshots.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:param int count:
|
||||
The number of consistency group snapshots to fake
|
||||
@ -789,7 +845,7 @@ class FakeExtension(object):
|
||||
def create_one_extension(attrs=None):
|
||||
"""Create a fake extension.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with name, namespace, etc.
|
||||
@ -825,7 +881,7 @@ class FakeQos(object):
|
||||
def create_one_qos(attrs=None):
|
||||
"""Create a fake Qos specification.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with id, name, consumer, etc.
|
||||
@ -852,7 +908,7 @@ class FakeQos(object):
|
||||
def create_one_qos_association(attrs=None):
|
||||
"""Create a fake Qos specification association.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with id, name, association_type, etc.
|
||||
@ -878,7 +934,7 @@ class FakeQos(object):
|
||||
def create_qoses(attrs=None, count=2):
|
||||
"""Create multiple fake Qos specifications.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:param int count:
|
||||
The number of Qos specifications to fake
|
||||
@ -920,7 +976,7 @@ class FakeSnapshot(object):
|
||||
def create_one_snapshot(attrs=None):
|
||||
"""Create a fake snapshot.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with id, name, description, etc.
|
||||
@ -951,7 +1007,7 @@ class FakeSnapshot(object):
|
||||
def create_snapshots(attrs=None, count=2):
|
||||
"""Create multiple fake snapshots.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:param int count:
|
||||
The number of snapshots to fake
|
||||
@ -993,9 +1049,9 @@ class FakeVolumeType(object):
|
||||
def create_one_volume_type(attrs=None, methods=None):
|
||||
"""Create a fake volume type.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:param Dictionary methods:
|
||||
:param dict methods:
|
||||
A dictionary with all methods
|
||||
:return:
|
||||
A FakeResource object with id, name, description, etc.
|
||||
@ -1025,7 +1081,7 @@ class FakeVolumeType(object):
|
||||
def create_volume_types(attrs=None, count=2):
|
||||
"""Create multiple fake volume_types.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:param int count:
|
||||
The number of types to fake
|
||||
@ -1063,7 +1119,7 @@ class FakeVolumeType(object):
|
||||
def create_one_encryption_volume_type(attrs=None):
|
||||
"""Create a fake encryption volume type.
|
||||
|
||||
:param Dictionary attrs:
|
||||
:param dict attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with volume_type_id etc.
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Migrate openstack server add volume to using sdk.
|
Loading…
x
Reference in New Issue
Block a user