summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/compute/v2/test_server_volume.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests/unit/compute/v2/test_server_volume.py')
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server_volume.py186
1 files changed, 103 insertions, 83 deletions
diff --git a/openstackclient/tests/unit/compute/v2/test_server_volume.py b/openstackclient/tests/unit/compute/v2/test_server_volume.py
index 02d378f8..f86bc7dd 100644
--- a/openstackclient/tests/unit/compute/v2/test_server_volume.py
+++ b/openstackclient/tests/unit/compute/v2/test_server_volume.py
@@ -11,11 +11,15 @@
# under the License.
#
+from unittest import mock
+
from novaclient import api_versions
+from openstack import utils as sdk_utils
from osc_lib import exceptions
from openstackclient.compute.v2 import server_volume
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
+from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
class TestServerVolume(compute_fakes.TestComputev2):
@@ -23,13 +27,11 @@ class TestServerVolume(compute_fakes.TestComputev2):
def setUp(self):
super().setUp()
- # Get a shortcut to the compute client ServerManager Mock
- self.servers_mock = self.app.client_manager.compute.servers
- self.servers_mock.reset_mock()
-
- # Get a shortcut to the compute client VolumeManager mock
- self.servers_volumes_mock = self.app.client_manager.compute.volumes
- self.servers_volumes_mock.reset_mock()
+ self.app.client_manager.sdk_connection = mock.Mock()
+ self.app.client_manager.sdk_connection.compute = mock.Mock()
+ self.app.client_manager.sdk_connection.volume = mock.Mock()
+ self.compute_client = self.app.client_manager.sdk_connection.compute
+ self.volume_client = self.app.client_manager.sdk_connection.volume
class TestServerVolumeList(TestServerVolume):
@@ -37,20 +39,21 @@ class TestServerVolumeList(TestServerVolume):
def setUp(self):
super().setUp()
- self.server = compute_fakes.FakeServer.create_one_server()
- self.volume_attachments = (
- compute_fakes.FakeVolumeAttachment.create_volume_attachments())
+ self.server = compute_fakes.FakeServer.create_one_sdk_server()
+ self.volume_attachments = compute_fakes.create_volume_attachments()
- self.servers_mock.get.return_value = self.server
- self.servers_volumes_mock.get_server_volumes.return_value = (
+ self.compute_client.find_server.return_value = self.server
+ self.compute_client.volume_attachments.return_value = (
self.volume_attachments)
# Get the command object to test
self.cmd = server_volume.ListServerVolume(self.app, None)
- def test_server_volume_list(self):
+ @mock.patch.object(sdk_utils, 'supports_microversion')
+ def test_server_volume_list(self, sm_mock):
self.app.client_manager.compute.api_version = \
api_versions.APIVersion('2.1')
+ sm_mock.side_effect = [False, False, False, False]
arglist = [
self.server.id,
@@ -68,24 +71,25 @@ class TestServerVolumeList(TestServerVolume):
(
self.volume_attachments[0].id,
self.volume_attachments[0].device,
- self.volume_attachments[0].serverId,
- self.volume_attachments[0].volumeId,
+ self.volume_attachments[0].server_id,
+ self.volume_attachments[0].volume_id,
),
(
self.volume_attachments[1].id,
self.volume_attachments[1].device,
- self.volume_attachments[1].serverId,
- self.volume_attachments[1].volumeId,
+ self.volume_attachments[1].server_id,
+ self.volume_attachments[1].volume_id,
),
),
tuple(data),
)
- self.servers_volumes_mock.get_server_volumes.assert_called_once_with(
- self.server.id)
+ self.compute_client.volume_attachments.assert_called_once_with(
+ self.server,
+ )
- def test_server_volume_list_with_tags(self):
- self.app.client_manager.compute.api_version = \
- api_versions.APIVersion('2.70')
+ @mock.patch.object(sdk_utils, 'supports_microversion')
+ def test_server_volume_list_with_tags(self, sm_mock):
+ sm_mock.side_effect = [False, True, False, False]
arglist = [
self.server.id,
@@ -105,27 +109,27 @@ class TestServerVolumeList(TestServerVolume):
(
self.volume_attachments[0].id,
self.volume_attachments[0].device,
- self.volume_attachments[0].serverId,
- self.volume_attachments[0].volumeId,
+ self.volume_attachments[0].server_id,
+ self.volume_attachments[0].volume_id,
self.volume_attachments[0].tag,
),
(
self.volume_attachments[1].id,
self.volume_attachments[1].device,
- self.volume_attachments[1].serverId,
- self.volume_attachments[1].volumeId,
+ self.volume_attachments[1].server_id,
+ self.volume_attachments[1].volume_id,
self.volume_attachments[1].tag,
),
),
tuple(data),
)
- self.servers_volumes_mock.get_server_volumes.assert_called_once_with(
- self.server.id)
-
- def test_server_volume_list_with_delete_on_attachment(self):
- self.app.client_manager.compute.api_version = \
- api_versions.APIVersion('2.79')
+ self.compute_client.volume_attachments.assert_called_once_with(
+ self.server,
+ )
+ @mock.patch.object(sdk_utils, 'supports_microversion')
+ def test_server_volume_list_with_delete_on_attachment(self, sm_mock):
+ sm_mock.side_effect = [False, True, True, False]
arglist = [
self.server.id,
]
@@ -148,29 +152,30 @@ class TestServerVolumeList(TestServerVolume):
(
self.volume_attachments[0].id,
self.volume_attachments[0].device,
- self.volume_attachments[0].serverId,
- self.volume_attachments[0].volumeId,
+ self.volume_attachments[0].server_id,
+ self.volume_attachments[0].volume_id,
self.volume_attachments[0].tag,
self.volume_attachments[0].delete_on_termination,
),
(
self.volume_attachments[1].id,
self.volume_attachments[1].device,
- self.volume_attachments[1].serverId,
- self.volume_attachments[1].volumeId,
+ self.volume_attachments[1].server_id,
+ self.volume_attachments[1].volume_id,
self.volume_attachments[1].tag,
self.volume_attachments[1].delete_on_termination,
),
),
tuple(data),
)
- self.servers_volumes_mock.get_server_volumes.assert_called_once_with(
- self.server.id)
+ self.compute_client.volume_attachments.assert_called_once_with(
+ self.server,
+ )
- def test_server_volume_list_with_attachment_ids(self):
- self.app.client_manager.compute.api_version = \
- api_versions.APIVersion('2.89')
+ @mock.patch.object(sdk_utils, 'supports_microversion')
+ def test_server_volume_list_with_attachment_ids(self, sm_mock):
+ sm_mock.side_effect = [True, True, True, True]
arglist = [
self.server.id,
]
@@ -193,28 +198,29 @@ class TestServerVolumeList(TestServerVolume):
(
(
self.volume_attachments[0].device,
- self.volume_attachments[0].serverId,
- self.volume_attachments[0].volumeId,
+ self.volume_attachments[0].server_id,
+ self.volume_attachments[0].volume_id,
self.volume_attachments[0].tag,
self.volume_attachments[0].delete_on_termination,
self.volume_attachments[0].attachment_id,
- self.volume_attachments[0].bdm_uuid
+ self.volume_attachments[0].bdm_id
),
(
self.volume_attachments[1].device,
- self.volume_attachments[1].serverId,
- self.volume_attachments[1].volumeId,
+ self.volume_attachments[1].server_id,
+ self.volume_attachments[1].volume_id,
self.volume_attachments[1].tag,
self.volume_attachments[1].delete_on_termination,
self.volume_attachments[1].attachment_id,
- self.volume_attachments[1].bdm_uuid
+ self.volume_attachments[1].bdm_id
),
),
tuple(data),
)
- self.servers_volumes_mock.get_server_volumes.assert_called_once_with(
- self.server.id)
+ self.compute_client.volume_attachments.assert_called_once_with(
+ self.server,
+ )
class TestServerVolumeUpdate(TestServerVolume):
@@ -222,21 +228,23 @@ class TestServerVolumeUpdate(TestServerVolume):
def setUp(self):
super().setUp()
- self.server = compute_fakes.FakeServer.create_one_server()
- self.servers_mock.get.return_value = self.server
+ self.server = compute_fakes.FakeServer.create_one_sdk_server()
+ self.compute_client.find_server.return_value = self.server
+
+ self.volume = volume_fakes.create_one_sdk_volume()
+ self.volume_client.find_volume.return_value = self.volume
# Get the command object to test
self.cmd = server_volume.UpdateServerVolume(self.app, None)
def test_server_volume_update(self):
-
arglist = [
self.server.id,
- 'foo',
+ self.volume.id,
]
verifylist = [
('server', self.server.id),
- ('volume', 'foo'),
+ ('volume', self.volume.id),
('delete_on_termination', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -244,67 +252,73 @@ class TestServerVolumeUpdate(TestServerVolume):
result = self.cmd.take_action(parsed_args)
# This is a no-op
- self.servers_volumes_mock.update_server_volume.assert_not_called()
+ self.compute_client.update_volume_attachment.assert_not_called()
self.assertIsNone(result)
- def test_server_volume_update_with_delete_on_termination(self):
- self.app.client_manager.compute.api_version = \
- api_versions.APIVersion('2.85')
+ @mock.patch.object(sdk_utils, 'supports_microversion')
+ def test_server_volume_update_with_delete_on_termination(self, sm_mock):
+ sm_mock.return_value = True
arglist = [
self.server.id,
- 'foo',
+ self.volume.id,
'--delete-on-termination',
]
verifylist = [
('server', self.server.id),
- ('volume', 'foo'),
+ ('volume', self.volume.id),
('delete_on_termination', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
- self.servers_volumes_mock.update_server_volume.assert_called_once_with(
- self.server.id, 'foo', 'foo',
- delete_on_termination=True)
+ self.compute_client.update_volume_attachment.assert_called_once_with(
+ self.server,
+ self.volume,
+ delete_on_termination=True,
+ )
self.assertIsNone(result)
- def test_server_volume_update_with_preserve_on_termination(self):
- self.app.client_manager.compute.api_version = \
- api_versions.APIVersion('2.85')
+ @mock.patch.object(sdk_utils, 'supports_microversion')
+ def test_server_volume_update_with_preserve_on_termination(self, sm_mock):
+ sm_mock.return_value = True
arglist = [
self.server.id,
- 'foo',
+ self.volume.id,
'--preserve-on-termination',
]
verifylist = [
('server', self.server.id),
- ('volume', 'foo'),
+ ('volume', self.volume.id),
('delete_on_termination', False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
- self.servers_volumes_mock.update_server_volume.assert_called_once_with(
- self.server.id, 'foo', 'foo',
- delete_on_termination=False)
+ self.compute_client.update_volume_attachment.assert_called_once_with(
+ self.server,
+ self.volume,
+ delete_on_termination=False
+ )
self.assertIsNone(result)
- def test_server_volume_update_with_delete_on_termination_pre_v285(self):
- self.app.client_manager.compute.api_version = \
- api_versions.APIVersion('2.84')
+ @mock.patch.object(sdk_utils, 'supports_microversion')
+ def test_server_volume_update_with_delete_on_termination_pre_v285(
+ self, sm_mock,
+ ):
+ sm_mock.return_value = False
arglist = [
self.server.id,
- 'foo',
+ self.volume.id,
'--delete-on-termination',
]
verifylist = [
('server', self.server.id),
- ('volume', 'foo'),
+ ('volume', self.volume.id),
('delete_on_termination', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -312,20 +326,24 @@ class TestServerVolumeUpdate(TestServerVolume):
self.assertRaises(
exceptions.CommandError,
self.cmd.take_action,
- parsed_args)
+ parsed_args,
+ )
+ self.compute_client.update_volume_attachment.assert_not_called()
- def test_server_volume_update_with_preserve_on_termination_pre_v285(self):
- self.app.client_manager.compute.api_version = \
- api_versions.APIVersion('2.84')
+ @mock.patch.object(sdk_utils, 'supports_microversion')
+ def test_server_volume_update_with_preserve_on_termination_pre_v285(
+ self, sm_mock,
+ ):
+ sm_mock.return_value = False
arglist = [
self.server.id,
- 'foo',
+ self.volume.id,
'--preserve-on-termination',
]
verifylist = [
('server', self.server.id),
- ('volume', 'foo'),
+ ('volume', self.volume.id),
('delete_on_termination', False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -333,4 +351,6 @@ class TestServerVolumeUpdate(TestServerVolume):
self.assertRaises(
exceptions.CommandError,
self.cmd.take_action,
- parsed_args)
+ parsed_args,
+ )
+ self.compute_client.update_volume_attachment.assert_not_called()