summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/volume
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests/unit/volume')
-rw-r--r--openstackclient/tests/unit/volume/v1/test_snapshot.py96
-rw-r--r--openstackclient/tests/unit/volume/v2/fakes.py6
-rw-r--r--openstackclient/tests/unit/volume/v2/test_consistency_group.py39
-rw-r--r--openstackclient/tests/unit/volume/v2/test_snapshot.py103
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_host.py86
5 files changed, 320 insertions, 10 deletions
diff --git a/openstackclient/tests/unit/volume/v1/test_snapshot.py b/openstackclient/tests/unit/volume/v1/test_snapshot.py
index 8e30d6a9..fd878f45 100644
--- a/openstackclient/tests/unit/volume/v1/test_snapshot.py
+++ b/openstackclient/tests/unit/volume/v1/test_snapshot.py
@@ -268,6 +268,7 @@ class TestSnapshotList(TestSnapshot):
super(TestSnapshotList, self).setUp()
self.volumes_mock.list.return_value = [self.volume]
+ self.volumes_mock.get.return_value = self.volume
self.snapshots_mock.list.return_value = self.snapshots
# Get the command to test
self.cmd = volume_snapshot.ListVolumeSnapshot(self.app, None)
@@ -283,7 +284,13 @@ class TestSnapshotList(TestSnapshot):
columns, data = self.cmd.take_action(parsed_args)
self.snapshots_mock.list.assert_called_once_with(
- search_opts={'all_tenants': False})
+ search_opts={
+ 'all_tenants': False,
+ 'display_name': None,
+ 'status': None,
+ 'volume_id': None
+ }
+ )
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
@@ -300,11 +307,88 @@ class TestSnapshotList(TestSnapshot):
columns, data = self.cmd.take_action(parsed_args)
self.snapshots_mock.list.assert_called_once_with(
- search_opts={'all_tenants': False}
+ search_opts={
+ 'all_tenants': False,
+ 'display_name': None,
+ 'status': None,
+ 'volume_id': None
+ }
)
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))
+ def test_snapshot_list_name_option(self):
+ arglist = [
+ '--name', self.snapshots[0].display_name,
+ ]
+ verifylist = [
+ ('all_projects', False),
+ ('long', False),
+ ('name', self.snapshots[0].display_name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.snapshots_mock.list.assert_called_once_with(
+ search_opts={
+ 'all_tenants': False,
+ 'display_name': self.snapshots[0].display_name,
+ 'status': None,
+ 'volume_id': None
+ }
+ )
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
+ def test_snapshot_list_status_option(self):
+ arglist = [
+ '--status', self.snapshots[0].status,
+ ]
+ verifylist = [
+ ('all_projects', False),
+ ('long', False),
+ ('status', self.snapshots[0].status),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.snapshots_mock.list.assert_called_once_with(
+ search_opts={
+ 'all_tenants': False,
+ 'display_name': None,
+ 'status': self.snapshots[0].status,
+ 'volume_id': None
+ }
+ )
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
+ def test_snapshot_list_volumeid_option(self):
+ arglist = [
+ '--volume', self.volume.id,
+ ]
+ verifylist = [
+ ('all_projects', False),
+ ('long', False),
+ ('volume', self.volume.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.snapshots_mock.list.assert_called_once_with(
+ search_opts={
+ 'all_tenants': False,
+ 'display_name': None,
+ 'status': None,
+ 'volume_id': self.volume.id
+ }
+ )
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
def test_snapshot_list_all_projects(self):
arglist = [
'--all-projects',
@@ -318,7 +402,13 @@ class TestSnapshotList(TestSnapshot):
columns, data = self.cmd.take_action(parsed_args)
self.snapshots_mock.list.assert_called_once_with(
- search_opts={'all_tenants': True})
+ search_opts={
+ 'all_tenants': True,
+ 'display_name': None,
+ 'status': None,
+ 'volume_id': None
+ }
+ )
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
diff --git a/openstackclient/tests/unit/volume/v2/fakes.py b/openstackclient/tests/unit/volume/v2/fakes.py
index 3137bfb0..d5cd72ec 100644
--- a/openstackclient/tests/unit/volume/v2/fakes.py
+++ b/openstackclient/tests/unit/volume/v2/fakes.py
@@ -480,7 +480,7 @@ class FakeBackup(object):
If backups list is provided, then initialize the Mock object with the
list. Otherwise create one.
- :param List volumes:
+ :param List backups:
A list of FakeResource objects faking backups
:param Integer count:
The number of backups to be faked
@@ -764,7 +764,7 @@ class FakeQos(object):
If qoses list is provided, then initialize the Mock object with the
list. Otherwise create one.
- :param List volumes:
+ :param List qoses:
A list of FakeResource objects faking qoses
:param Integer count:
The number of qoses to be faked
@@ -837,7 +837,7 @@ class FakeSnapshot(object):
If snapshots list is provided, then initialize the Mock object with the
list. Otherwise create one.
- :param List volumes:
+ :param List snapshots:
A list of FakeResource objects faking snapshots
:param Integer count:
The number of snapshots to be faked
diff --git a/openstackclient/tests/unit/volume/v2/test_consistency_group.py b/openstackclient/tests/unit/volume/v2/test_consistency_group.py
index 8a997e18..bc99ca8d 100644
--- a/openstackclient/tests/unit/volume/v2/test_consistency_group.py
+++ b/openstackclient/tests/unit/volume/v2/test_consistency_group.py
@@ -32,6 +32,10 @@ class TestConsistencyGroup(volume_fakes.TestVolume):
self.app.client_manager.volume.consistencygroups)
self.consistencygroups_mock.reset_mock()
+ self.cgsnapshots_mock = (
+ self.app.client_manager.volume.cgsnapshots)
+ self.cgsnapshots_mock.reset_mock()
+
self.types_mock = self.app.client_manager.volume.volume_types
self.types_mock.reset_mock()
@@ -41,6 +45,11 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
volume_type = volume_fakes.FakeType.create_one_type()
new_consistency_group = (
volume_fakes.FakeConsistencyGroup.create_one_consistency_group())
+ consistency_group_snapshot = (
+ volume_fakes.
+ FakeConsistencyGroupSnapshot.
+ create_one_consistency_group_snapshot()
+ )
columns = (
'availability_zone',
@@ -70,6 +79,8 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
self.consistencygroups_mock.get.return_value = (
self.new_consistency_group)
self.types_mock.get.return_value = self.volume_type
+ self.cgsnapshots_mock.get.return_value = (
+ self.consistency_group_snapshot)
# Get the command object to test
self.cmd = consistency_group.CreateConsistencyGroup(self.app, None)
@@ -164,6 +175,34 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
+ def test_consistency_group_create_from_snapshot(self):
+ arglist = [
+ '--consistency-group-snapshot', self.consistency_group_snapshot.id,
+ '--description', self.new_consistency_group.description,
+ self.new_consistency_group.name,
+ ]
+ verifylist = [
+ ('consistency_group_snapshot', self.consistency_group_snapshot.id),
+ ('description', self.new_consistency_group.description),
+ ('name', self.new_consistency_group.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.types_mock.get.assert_not_called()
+ self.cgsnapshots_mock.get.assert_called_once_with(
+ self.consistency_group_snapshot.id)
+ self.consistencygroups_mock.create_from_src.assert_called_with(
+ self.consistency_group_snapshot.id,
+ None,
+ name=self.new_consistency_group.name,
+ description=self.new_consistency_group.description,
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
class TestConsistencyGroupDelete(TestConsistencyGroup):
diff --git a/openstackclient/tests/unit/volume/v2/test_snapshot.py b/openstackclient/tests/unit/volume/v2/test_snapshot.py
index b67dd6eb..bb238135 100644
--- a/openstackclient/tests/unit/volume/v2/test_snapshot.py
+++ b/openstackclient/tests/unit/volume/v2/test_snapshot.py
@@ -275,6 +275,7 @@ class TestSnapshotList(TestSnapshot):
super(TestSnapshotList, self).setUp()
self.volumes_mock.list.return_value = [self.volume]
+ self.volumes_mock.get.return_value = self.volume
self.snapshots_mock.list.return_value = self.snapshots
# Get the command to test
self.cmd = volume_snapshot.ListVolumeSnapshot(self.app, None)
@@ -283,14 +284,21 @@ class TestSnapshotList(TestSnapshot):
arglist = []
verifylist = [
('all_projects', False),
- ("long", False)
+ ('long', False)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.snapshots_mock.list.assert_called_once_with(
- limit=None, marker=None, search_opts={'all_tenants': False})
+ limit=None, marker=None,
+ search_opts={
+ 'all_tenants': False,
+ 'name': None,
+ 'status': None,
+ 'volume_id': None
+ }
+ )
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
@@ -313,7 +321,12 @@ class TestSnapshotList(TestSnapshot):
self.snapshots_mock.list.assert_called_once_with(
limit=2,
marker=self.snapshots[0].id,
- search_opts={'all_tenants': False}
+ search_opts={
+ 'all_tenants': False,
+ 'name': None,
+ 'status': None,
+ 'volume_id': None
+ }
)
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))
@@ -331,7 +344,89 @@ class TestSnapshotList(TestSnapshot):
columns, data = self.cmd.take_action(parsed_args)
self.snapshots_mock.list.assert_called_once_with(
- limit=None, marker=None, search_opts={'all_tenants': True})
+ limit=None, marker=None,
+ search_opts={
+ 'all_tenants': True,
+ 'name': None,
+ 'status': None,
+ 'volume_id': None
+ }
+ )
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
+ def test_snapshot_list_name_option(self):
+ arglist = [
+ '--name', self.snapshots[0].name,
+ ]
+ verifylist = [
+ ('all_projects', False),
+ ('long', False),
+ ('name', self.snapshots[0].name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.snapshots_mock.list.assert_called_once_with(
+ limit=None, marker=None,
+ search_opts={
+ 'all_tenants': False,
+ 'name': self.snapshots[0].name,
+ 'status': None,
+ 'volume_id': None
+ }
+ )
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
+ def test_snapshot_list_status_option(self):
+ arglist = [
+ '--status', self.snapshots[0].status,
+ ]
+ verifylist = [
+ ('all_projects', False),
+ ('long', False),
+ ('status', self.snapshots[0].status),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.snapshots_mock.list.assert_called_once_with(
+ limit=None, marker=None,
+ search_opts={
+ 'all_tenants': False,
+ 'name': None,
+ 'status': self.snapshots[0].status,
+ 'volume_id': None
+ }
+ )
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
+ def test_snapshot_list_volumeid_option(self):
+ arglist = [
+ '--volume', self.volume.id,
+ ]
+ verifylist = [
+ ('all_projects', False),
+ ('long', False),
+ ('volume', self.volume.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.snapshots_mock.list.assert_called_once_with(
+ limit=None, marker=None,
+ search_opts={
+ 'all_tenants': False,
+ 'name': None,
+ 'status': None,
+ 'volume_id': self.volume.id
+ }
+ )
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
diff --git a/openstackclient/tests/unit/volume/v2/test_volume_host.py b/openstackclient/tests/unit/volume/v2/test_volume_host.py
new file mode 100644
index 00000000..aad7bb0b
--- /dev/null
+++ b/openstackclient/tests/unit/volume/v2/test_volume_host.py
@@ -0,0 +1,86 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+
+from openstackclient.tests.unit.volume.v2 import fakes as host_fakes
+from openstackclient.volume.v2 import volume_host
+
+
+class TestVolumeHost(host_fakes.TestVolume):
+
+ def setUp(self):
+ super(TestVolumeHost, self).setUp()
+
+ self.host_mock = self.app.client_manager.volume.services
+ self.host_mock.reset_mock()
+
+
+class TestVolumeHostSet(TestVolumeHost):
+
+ service = host_fakes.FakeService.create_one_service()
+
+ def setUp(self):
+ super(TestVolumeHostSet, self).setUp()
+
+ self.host_mock.freeze_host.return_value = None
+ self.host_mock.thaw_host.return_value = None
+
+ self.cmd = volume_host.SetVolumeHost(self.app, None)
+
+ def test_volume_host_set_nothing(self):
+ arglist = [
+ self.service.host,
+ ]
+ verifylist = [
+ ('host', self.service.host),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+
+ self.host_mock.freeze_host.assert_not_called()
+ self.host_mock.thaw_host.assert_not_called()
+ self.assertIsNone(result)
+
+ def test_volume_host_set_enable(self):
+ arglist = [
+ '--enable',
+ self.service.host,
+ ]
+ verifylist = [
+ ('enable', True),
+ ('host', self.service.host),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.host_mock.thaw_host.assert_called_with(self.service.host)
+ self.host_mock.freeze_host.assert_not_called()
+ self.assertIsNone(result)
+
+ def test_volume_host_set_disable(self):
+ arglist = [
+ '--disable',
+ self.service.host,
+ ]
+ verifylist = [
+ ('disable', True),
+ ('host', self.service.host),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.host_mock.freeze_host.assert_called_with(self.service.host)
+ self.host_mock.thaw_host.assert_not_called()
+ self.assertIsNone(result)