Convert project tests into mock: cgroups/cg_snapshots
test_update_cgroup_add_vol/remove_vol tests were completely broken as add/remove_vol operation is not a part of cgroup_update. These tests are fixed to pass tests after mock migration. I don't know why they passes before. test_create_cgroup_from_snapshot* in CG snapshot tests was also broken (redirect destination and method signature were wrong). They are fixed as well though I am not sure why they passed. Partially-Implements: blueprint mock-framework-in-unit-tests Change-Id: I8fe53390da2f7c35a31e339306e7d1394bb36218
This commit is contained in:
parent
d4c1c29cbb
commit
f8150ab4cc
@ -10,9 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django import http
|
||||
from django.urls import reverse
|
||||
from mox3.mox import IsA
|
||||
import mock
|
||||
|
||||
from openstack_dashboard.api import cinder
|
||||
from openstack_dashboard.test import helpers as test
|
||||
@ -22,7 +21,7 @@ INDEX_URL = reverse('horizon:project:cg_snapshots:index')
|
||||
|
||||
|
||||
class CGroupSnapshotTests(test.TestCase):
|
||||
@test.create_stubs({cinder: ('volume_cg_snapshot_get',
|
||||
@test.create_mocks({cinder: ('volume_cg_snapshot_get',
|
||||
'volume_cgroup_create_from_source',)})
|
||||
def test_create_cgroup_from_snapshot(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
@ -31,23 +30,25 @@ class CGroupSnapshotTests(test.TestCase):
|
||||
'name': 'test CG SS Create',
|
||||
'description': 'test desc'}
|
||||
|
||||
cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
|
||||
AndReturn(cg_snapshot)
|
||||
cinder.volume_cgroup_create_from_source(
|
||||
IsA(http.HttpRequest),
|
||||
formData['name'],
|
||||
source_cgroup_id=formData['cg_snapshot_id'],
|
||||
description=formData['description'])\
|
||||
.AndReturn(cgroup)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cg_snapshot_get.return_value = cg_snapshot
|
||||
self.mock_volume_cgroup_create_from_source.return_value = cgroup
|
||||
|
||||
url = reverse('horizon:project:cg_snapshots:create_cgroup',
|
||||
args=[cg_snapshot.id])
|
||||
res = self.client.post(url, formData)
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
self.assertRedirectsNoFollow(
|
||||
res, reverse('horizon:project:cgroups:index'))
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cg_snapshot_get',
|
||||
self.mock_volume_cg_snapshot_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cg_snapshot.id)
|
||||
self.mock_volume_cgroup_create_from_source.assert_called_once_with(
|
||||
test.IsHttpRequest(),
|
||||
formData['name'],
|
||||
cg_snapshot_id=formData['cg_snapshot_id'],
|
||||
description=formData['description'])
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cg_snapshot_get',
|
||||
'volume_cgroup_create_from_source',)})
|
||||
def test_create_cgroup_from_snapshot_exception(self):
|
||||
cg_snapshot = self.cinder_cg_snapshots.first()
|
||||
@ -56,15 +57,9 @@ class CGroupSnapshotTests(test.TestCase):
|
||||
'name': new_cg_name,
|
||||
'description': 'test desc'}
|
||||
|
||||
cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
|
||||
AndReturn(cg_snapshot)
|
||||
cinder.volume_cgroup_create_from_source(
|
||||
IsA(http.HttpRequest),
|
||||
formData['name'],
|
||||
source_cgroup_id=formData['cg_snapshot_id'],
|
||||
description=formData['description'])\
|
||||
.AndRaise(self.exceptions.cinder)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cg_snapshot_get.return_value = cg_snapshot
|
||||
self.mock_volume_cgroup_create_from_source.side_effect = \
|
||||
self.exceptions.cinder
|
||||
|
||||
url = reverse('horizon:project:cg_snapshots:create_cgroup',
|
||||
args=[cg_snapshot.id])
|
||||
@ -77,16 +72,22 @@ class CGroupSnapshotTests(test.TestCase):
|
||||
res.cookies.output().replace('\\', ''))
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cg_snapshot_list',
|
||||
self.mock_volume_cg_snapshot_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cg_snapshot.id)
|
||||
self.mock_volume_cgroup_create_from_source.assert_called_once_with(
|
||||
test.IsHttpRequest(),
|
||||
formData['name'],
|
||||
cg_snapshot_id=formData['cg_snapshot_id'],
|
||||
description=formData['description'])
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cg_snapshot_list',
|
||||
'volume_cg_snapshot_delete',)})
|
||||
def test_delete_cgroup_snapshot(self):
|
||||
cg_snapshots = self.cinder_cg_snapshots.list()
|
||||
cg_snapshot = self.cinder_cg_snapshots.first()
|
||||
|
||||
cinder.volume_cg_snapshot_list(IsA(http.HttpRequest)).\
|
||||
AndReturn(cg_snapshots)
|
||||
cinder.volume_cg_snapshot_delete(IsA(http.HttpRequest), cg_snapshot.id)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cg_snapshot_list.return_value = cg_snapshots
|
||||
self.mock_volume_cg_snapshot_delete.return_value = None
|
||||
|
||||
form_data = {'action': 'volume_cg_snapshots__delete_cg_snapshot__%s'
|
||||
% cg_snapshot.id}
|
||||
@ -95,18 +96,21 @@ class CGroupSnapshotTests(test.TestCase):
|
||||
self.assertIn("Scheduled deletion of Snapshot: %s" % cg_snapshot.name,
|
||||
[m.message for m in res.context['messages']])
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cg_snapshot_list',
|
||||
self.assert_mock_multiple_calls_with_same_arguments(
|
||||
self.mock_volume_cg_snapshot_list, 2,
|
||||
mock.call(test.IsHttpRequest()))
|
||||
self.mock_volume_cg_snapshot_delete.assert_called_once_with(
|
||||
test.IsHttpRequest(), cg_snapshot.id)
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cg_snapshot_list',
|
||||
'volume_cg_snapshot_delete',)})
|
||||
def test_delete_cgroup_snapshot_exception(self):
|
||||
cg_snapshots = self.cinder_cg_snapshots.list()
|
||||
cg_snapshot = self.cinder_cg_snapshots.first()
|
||||
|
||||
cinder.volume_cg_snapshot_list(IsA(http.HttpRequest)).\
|
||||
AndReturn(cg_snapshots)
|
||||
cinder.volume_cg_snapshot_delete(IsA(http.HttpRequest),
|
||||
cg_snapshot.id).\
|
||||
AndRaise(self.exceptions.cinder)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cg_snapshot_list.return_value = cg_snapshots
|
||||
self.mock_volume_cg_snapshot_delete.side_effect = \
|
||||
self.exceptions.cinder
|
||||
|
||||
form_data = {'action': 'volume_cg_snapshots__delete_cg_snapshot__%s'
|
||||
% cg_snapshot.id}
|
||||
@ -115,7 +119,13 @@ class CGroupSnapshotTests(test.TestCase):
|
||||
self.assertIn("Unable to delete snapshot: %s" % cg_snapshot.name,
|
||||
[m.message for m in res.context['messages']])
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cg_snapshot_get',
|
||||
self.assert_mock_multiple_calls_with_same_arguments(
|
||||
self.mock_volume_cg_snapshot_list, 2,
|
||||
mock.call(test.IsHttpRequest()))
|
||||
self.mock_volume_cg_snapshot_delete.assert_called_once_with(
|
||||
test.IsHttpRequest(), cg_snapshot.id)
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cg_snapshot_get',
|
||||
'volume_cgroup_get',
|
||||
'volume_type_get',
|
||||
'volume_list',)})
|
||||
@ -125,17 +135,10 @@ class CGroupSnapshotTests(test.TestCase):
|
||||
volume_type = self.cinder_volume_types.first()
|
||||
volumes = self.cinder_volumes.list()
|
||||
|
||||
cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
|
||||
AndReturn(cg_snapshot)
|
||||
cinder.volume_cgroup_get(IsA(http.HttpRequest), cgroup.id).\
|
||||
AndReturn(cgroup)
|
||||
cinder.volume_type_get(IsA(http.HttpRequest), volume_type.id).\
|
||||
MultipleTimes().AndReturn(volume_type)
|
||||
search_opts = {'consistencygroup_id': cgroup.id}
|
||||
cinder.volume_list(IsA(http.HttpRequest), search_opts=search_opts).\
|
||||
AndReturn(volumes)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cg_snapshot_get.return_value = cg_snapshot
|
||||
self.mock_volume_cgroup_get.return_value = cgroup
|
||||
self.mock_volume_type_get.return_value = volume_type
|
||||
self.mock_volume_list.return_value = volumes
|
||||
|
||||
url = reverse(
|
||||
'horizon:project:cg_snapshots:cg_snapshot_detail',
|
||||
@ -144,14 +147,21 @@ class CGroupSnapshotTests(test.TestCase):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertEqual(res.status_code, 200)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cg_snapshot_get',)})
|
||||
self.mock_volume_cg_snapshot_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cg_snapshot.id)
|
||||
self.mock_volume_cgroup_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id)
|
||||
self.mock_volume_type_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), volume_type.id)
|
||||
search_opts = {'consistencygroup_id': cgroup.id}
|
||||
self.mock_volume_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), search_opts=search_opts)
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cg_snapshot_get',)})
|
||||
def test_detail_view_with_exception(self):
|
||||
cg_snapshot = self.cinder_cg_snapshots.first()
|
||||
|
||||
cinder.volume_cg_snapshot_get(IsA(http.HttpRequest), cg_snapshot.id).\
|
||||
AndRaise(self.exceptions.cinder)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cg_snapshot_get.side_effect = self.exceptions.cinder
|
||||
|
||||
url = reverse(
|
||||
'horizon:project:cg_snapshots:cg_snapshot_detail',
|
||||
@ -159,3 +169,6 @@ class CGroupSnapshotTests(test.TestCase):
|
||||
res = self.client.get(url)
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
self.mock_volume_cg_snapshot_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cg_snapshot.id)
|
||||
|
@ -10,10 +10,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django import http
|
||||
from django.urls import reverse
|
||||
from django.utils.http import urlunquote
|
||||
from mox3.mox import IsA
|
||||
import mock
|
||||
|
||||
from openstack_dashboard.api import cinder
|
||||
from openstack_dashboard.test import helpers as test
|
||||
@ -25,7 +24,7 @@ VOLUME_CGROUPS_SNAP_INDEX_URL = urlunquote(reverse(
|
||||
|
||||
|
||||
class ConsistencyGroupTests(test.TestCase):
|
||||
@test.create_stubs({cinder: ('extension_supported',
|
||||
@test.create_mocks({cinder: ('extension_supported',
|
||||
'availability_zone_list',
|
||||
'volume_type_list',
|
||||
'volume_type_list_with_qos_associations',
|
||||
@ -42,30 +41,39 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
'availability_zone': az,
|
||||
'add_vtypes_to_cgroup_role_member': [volume_type_id]}
|
||||
|
||||
cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
|
||||
.AndReturn(True)
|
||||
cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
|
||||
self.cinder_availability_zones.list())
|
||||
cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(volume_types)
|
||||
cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\
|
||||
AndReturn(volume_types)
|
||||
cinder.volume_cgroup_list(IsA(http.HttpRequest)).\
|
||||
AndReturn(self.cinder_consistencygroups.list())
|
||||
cinder.volume_cgroup_create(
|
||||
IsA(http.HttpRequest),
|
||||
formData['volume_types'],
|
||||
formData['name'],
|
||||
formData['description'],
|
||||
availability_zone=formData['availability_zone'])\
|
||||
.AndReturn(cgroup)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_extension_supported.return_value = True
|
||||
self.mock_availability_zone_list.return_value = \
|
||||
self.cinder_availability_zones.list()
|
||||
self.mock_volume_type_list.return_value = volume_types
|
||||
self.mock_volume_type_list_with_qos_associations.return_value = \
|
||||
volume_types
|
||||
self.mock_volume_cgroup_list.return_value = \
|
||||
self.cinder_consistencygroups.list()
|
||||
self.mock_volume_cgroup_create.return_value = cgroup
|
||||
|
||||
url = reverse('horizon:project:cgroups:create')
|
||||
res = self.client.post(url, formData)
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('extension_supported',
|
||||
self.mock_extension_supported.assert_called_once_with(
|
||||
test.IsHttpRequest(), 'AvailabilityZones')
|
||||
self.mock_availability_zone_list.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_volume_type_list.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_volume_type_list_with_qos_associations \
|
||||
.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_volume_cgroup_list.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_volume_cgroup_create.assert_called_once_with(
|
||||
test.IsHttpRequest(),
|
||||
formData['volume_types'],
|
||||
formData['name'],
|
||||
description=formData['description'],
|
||||
availability_zone=formData['availability_zone'])
|
||||
|
||||
@test.create_mocks({cinder: ('extension_supported',
|
||||
'availability_zone_list',
|
||||
'volume_type_list',
|
||||
'volume_type_list_with_qos_associations',
|
||||
@ -81,23 +89,15 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
'availability_zone': az,
|
||||
'add_vtypes_to_cgroup_role_member': [volume_type_id]}
|
||||
|
||||
cinder.extension_supported(IsA(http.HttpRequest), 'AvailabilityZones')\
|
||||
.AndReturn(True)
|
||||
cinder.availability_zone_list(IsA(http.HttpRequest)).AndReturn(
|
||||
self.cinder_availability_zones.list())
|
||||
cinder.volume_type_list(IsA(http.HttpRequest)).AndReturn(volume_types)
|
||||
cinder.volume_type_list_with_qos_associations(IsA(http.HttpRequest)).\
|
||||
AndReturn(volume_types)
|
||||
cinder.volume_cgroup_list(IsA(http.HttpRequest)).\
|
||||
AndReturn(self.cinder_consistencygroups.list())
|
||||
cinder.volume_cgroup_create(
|
||||
IsA(http.HttpRequest),
|
||||
formData['volume_types'],
|
||||
formData['name'],
|
||||
formData['description'],
|
||||
availability_zone=formData['availability_zone'])\
|
||||
.AndRaise(self.exceptions.cinder)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_extension_supported.return_value = True
|
||||
self.mock_availability_zone_list.return_value = \
|
||||
self.cinder_availability_zones.list()
|
||||
self.mock_volume_type_list.return_value = volume_types
|
||||
self.mock_volume_type_list_with_qos_associations.return_value = \
|
||||
volume_types
|
||||
self.mock_volume_cgroup_list.return_value = \
|
||||
self.cinder_consistencygroups.list()
|
||||
self.mock_volume_cgroup_create.side_effect = self.exceptions.cinder
|
||||
|
||||
url = reverse('horizon:project:cgroups:create')
|
||||
res = self.client.post(url, formData)
|
||||
@ -106,16 +106,30 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
self.assertIn("Unable to create consistency group.",
|
||||
res.cookies.output())
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cgroup_get',
|
||||
self.mock_extension_supported.assert_called_once_with(
|
||||
test.IsHttpRequest(), 'AvailabilityZones')
|
||||
self.mock_availability_zone_list.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_volume_type_list.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_volume_type_list_with_qos_associations \
|
||||
.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_volume_cgroup_list.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_volume_cgroup_create.assert_called_once_with(
|
||||
test.IsHttpRequest(),
|
||||
formData['volume_types'],
|
||||
formData['name'],
|
||||
description=formData['description'],
|
||||
availability_zone=formData['availability_zone'])
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cgroup_get',
|
||||
'volume_cgroup_delete')})
|
||||
def test_delete_cgroup(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
|
||||
cinder.volume_cgroup_get(IsA(http.HttpRequest), cgroup.id).\
|
||||
AndReturn(cgroup)
|
||||
cinder.volume_cgroup_delete(IsA(http.HttpRequest), cgroup.id,
|
||||
force=False)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cgroup_get.return_value = cgroup
|
||||
self.mock_volume_cgroup_delete.return_value = None
|
||||
|
||||
url = reverse('horizon:project:cgroups:delete',
|
||||
args=[cgroup.id])
|
||||
@ -123,17 +137,19 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cgroup_get',
|
||||
self.mock_volume_cgroup_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id)
|
||||
self.mock_volume_cgroup_delete.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id, force=False)
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cgroup_get',
|
||||
'volume_cgroup_delete')})
|
||||
def test_delete_cgroup_force_flag(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
formData = {'delete_volumes': True}
|
||||
|
||||
cinder.volume_cgroup_get(IsA(http.HttpRequest), cgroup.id).\
|
||||
AndReturn(cgroup)
|
||||
cinder.volume_cgroup_delete(IsA(http.HttpRequest), cgroup.id,
|
||||
force=True)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cgroup_get.return_value = cgroup
|
||||
self.mock_volume_cgroup_delete.return_value = None
|
||||
|
||||
url = reverse('horizon:project:cgroups:delete',
|
||||
args=[cgroup.id])
|
||||
@ -141,19 +157,19 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cgroup_get',
|
||||
self.mock_volume_cgroup_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id)
|
||||
self.mock_volume_cgroup_delete.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id, force=True)
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cgroup_get',
|
||||
'volume_cgroup_delete')})
|
||||
def test_delete_cgroup_exception(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
formData = {'delete_volumes': False}
|
||||
|
||||
cinder.volume_cgroup_get(IsA(http.HttpRequest), cgroup.id).\
|
||||
AndReturn(cgroup)
|
||||
cinder.volume_cgroup_delete(IsA(http.HttpRequest),
|
||||
cgroup.id,
|
||||
force=False).\
|
||||
AndRaise(self.exceptions.cinder)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cgroup_get.return_value = cgroup
|
||||
self.mock_volume_cgroup_delete.side_effect = self.exceptions.cinder
|
||||
|
||||
url = reverse('horizon:project:cgroups:delete',
|
||||
args=[cgroup.id])
|
||||
@ -161,75 +177,84 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cgroup_update',
|
||||
'volume_cgroup_get')})
|
||||
self.mock_volume_cgroup_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id)
|
||||
self.mock_volume_cgroup_delete.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id, force=False)
|
||||
|
||||
def test_update_cgroup_add_vol(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
volume = self.cinder_volumes.first()
|
||||
formData = {'volume_types': '1',
|
||||
'name': 'test CG',
|
||||
'description': 'test desc'}
|
||||
self._test_update_cgroup_add_remove_vol(add=True)
|
||||
|
||||
cinder.volume_cgroup_get(IsA(
|
||||
http.HttpRequest), cgroup.id).\
|
||||
AndReturn(cgroup)
|
||||
cinder.volume_cgroup_update(
|
||||
IsA(http.HttpRequest),
|
||||
formData['name'],
|
||||
formData['description'],
|
||||
add_vols=volume)\
|
||||
.AndReturn(cgroup)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:project:cgroups:update',
|
||||
args=[cgroup.id])
|
||||
res = self.client.post(url, formData)
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cgroup_update',
|
||||
'volume_cgroup_get')})
|
||||
def test_update_cgroup_remove_vol(self):
|
||||
self._test_update_cgroup_add_remove_vol(add=False)
|
||||
|
||||
@test.create_mocks({cinder: ('volume_list',
|
||||
'volume_type_list',
|
||||
'volume_cgroup_get',
|
||||
'volume_cgroup_update')})
|
||||
def _test_update_cgroup_add_remove_vol(self, add=True):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
volume = self.cinder_volumes.first()
|
||||
formData = {'volume_types': '1',
|
||||
'name': 'test CG',
|
||||
'description': 'test desc'}
|
||||
volume_types = self.cinder_volume_types.list()
|
||||
volumes = (self.cinder_volumes.list() +
|
||||
self.cinder_cgroup_volumes.list())
|
||||
|
||||
cinder.volume_cgroup_get(IsA(
|
||||
http.HttpRequest), cgroup.id).\
|
||||
AndReturn(cgroup)
|
||||
cinder.volume_cgroup_update(
|
||||
IsA(http.HttpRequest),
|
||||
formData['name'],
|
||||
formData['description'],
|
||||
remove_vols=volume)\
|
||||
.AndReturn(cgroup)
|
||||
self.mox.ReplayAll()
|
||||
cgroup_voltype_names = [t.name for t in volume_types
|
||||
if t.id in cgroup.volume_types]
|
||||
compat_volumes = [v for v in volumes
|
||||
if v.volume_type in cgroup_voltype_names]
|
||||
compat_volume_ids = [v.id for v in compat_volumes]
|
||||
assigned_volume_ids = [v.id for v in compat_volumes
|
||||
if getattr(v, 'consistencygroup_id', None)]
|
||||
add_volume_ids = [v.id for v in compat_volumes
|
||||
if v.id not in assigned_volume_ids]
|
||||
|
||||
url = reverse('horizon:project:cgroups:update',
|
||||
new_volums = compat_volume_ids if add else []
|
||||
formData = {
|
||||
'default_add_volumes_to_cgroup_role': 'member',
|
||||
'add_volumes_to_cgroup_role_member': new_volums,
|
||||
}
|
||||
|
||||
self.mock_volume_list.return_value = volumes
|
||||
self.mock_volume_type_list.return_value = volume_types
|
||||
self.mock_volume_cgroup_get.return_value = cgroup
|
||||
self.mock_volume_cgroup_update.return_value = cgroup
|
||||
|
||||
url = reverse('horizon:project:cgroups:manage',
|
||||
args=[cgroup.id])
|
||||
res = self.client.post(url, formData)
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cgroup_update',
|
||||
'volume_cgroup_get')})
|
||||
self.assert_mock_multiple_calls_with_same_arguments(
|
||||
self.mock_volume_list, 2,
|
||||
mock.call(test.IsHttpRequest()))
|
||||
self.mock_volume_type_list.assert_called_once_with(
|
||||
test.IsHttpRequest())
|
||||
self.mock_volume_cgroup_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id)
|
||||
if add:
|
||||
self.mock_volume_cgroup_update.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id,
|
||||
name=cgroup.name,
|
||||
add_vols=','.join(add_volume_ids),
|
||||
remove_vols='')
|
||||
else:
|
||||
self.mock_volume_cgroup_update.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id,
|
||||
name=cgroup.name,
|
||||
add_vols='',
|
||||
remove_vols=','.join(assigned_volume_ids))
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cgroup_get',
|
||||
'volume_cgroup_update')})
|
||||
def test_update_cgroup_name_and_description(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
formData = {'volume_types': '1',
|
||||
'name': 'test CG-new',
|
||||
'description': 'test desc-new'}
|
||||
|
||||
cinder.volume_cgroup_get(IsA(
|
||||
http.HttpRequest), cgroup.id).\
|
||||
AndReturn(cgroup)
|
||||
cinder.volume_cgroup_update(
|
||||
IsA(http.HttpRequest),
|
||||
formData['name'],
|
||||
formData['description'])\
|
||||
.AndReturn(cgroup)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cgroup_get.return_value = cgroup
|
||||
self.mock_volume_cgroup_update.return_value = cgroup
|
||||
|
||||
url = reverse('horizon:project:cgroups:update',
|
||||
args=[cgroup.id])
|
||||
@ -237,23 +262,23 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cgroup_update',
|
||||
'volume_cgroup_get')})
|
||||
self.mock_volume_cgroup_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id)
|
||||
self.mock_volume_cgroup_update.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id,
|
||||
formData['name'],
|
||||
formData['description'])
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cgroup_get',
|
||||
'volume_cgroup_update')})
|
||||
def test_update_cgroup_with_exception(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
formData = {'volume_types': '1',
|
||||
'name': 'test CG-new',
|
||||
'description': 'test desc-new'}
|
||||
|
||||
cinder.volume_cgroup_get(IsA(
|
||||
http.HttpRequest), cgroup.id).\
|
||||
AndReturn(cgroup)
|
||||
cinder.volume_cgroup_update(
|
||||
IsA(http.HttpRequest),
|
||||
formData['name'],
|
||||
formData['description'])\
|
||||
.AndRaise(self.exceptions.cinder)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cgroup_get.return_value = cgroup
|
||||
self.mock_volume_cgroup_update.side_effect = self.exceptions.cinder
|
||||
|
||||
url = reverse('horizon:project:cgroups:update',
|
||||
args=[cgroup.id])
|
||||
@ -261,14 +286,18 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cgroup_get',)})
|
||||
self.mock_volume_cgroup_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id)
|
||||
self.mock_volume_cgroup_update.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id,
|
||||
formData['name'],
|
||||
formData['description'])
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cgroup_get',)})
|
||||
def test_detail_view_with_exception(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
|
||||
cinder.volume_cgroup_get(IsA(http.HttpRequest), cgroup.id).\
|
||||
AndRaise(self.exceptions.cinder)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cgroup_get.side_effect = self.exceptions.cinder
|
||||
|
||||
url = reverse('horizon:project:cgroups:detail',
|
||||
args=[cgroup.id])
|
||||
@ -276,7 +305,10 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cg_snapshot_create',)})
|
||||
self.mock_volume_cgroup_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id)
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cg_snapshot_create',)})
|
||||
def test_create_snapshot(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
cg_snapshot = self.cinder_cg_snapshots.first()
|
||||
@ -284,13 +316,7 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
'name': 'test CG Snapshot',
|
||||
'description': 'test desc'}
|
||||
|
||||
cinder.volume_cg_snapshot_create(
|
||||
IsA(http.HttpRequest),
|
||||
formData['cgroup_id'],
|
||||
formData['name'],
|
||||
formData['description'])\
|
||||
.AndReturn(cg_snapshot)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cg_snapshot_create.return_value = cg_snapshot
|
||||
|
||||
url = reverse('horizon:project:cgroups:create_snapshot',
|
||||
args=[cgroup.id])
|
||||
@ -298,23 +324,32 @@ class ConsistencyGroupTests(test.TestCase):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, VOLUME_CGROUPS_SNAP_INDEX_URL)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_cgroup_get',
|
||||
'volume_cgroup_create_from_source',)})
|
||||
self.mock_volume_cg_snapshot_create.assert_called_once_with(
|
||||
test.IsHttpRequest(),
|
||||
formData['cgroup_id'],
|
||||
formData['name'],
|
||||
formData['description'])
|
||||
|
||||
@test.create_mocks({cinder: ('volume_cgroup_get',
|
||||
'volume_cgroup_create_from_source')})
|
||||
def test_create_clone(self):
|
||||
cgroup = self.cinder_consistencygroups.first()
|
||||
formData = {'cgroup_id': cgroup.id,
|
||||
'name': 'test CG Clone',
|
||||
'description': 'test desc'}
|
||||
cinder.volume_cgroup_create_from_source(
|
||||
IsA(http.HttpRequest),
|
||||
formData['name'],
|
||||
source_cgroup_id=formData['cgroup_id'],
|
||||
description=formData['description'])\
|
||||
.AndReturn(cgroup)
|
||||
self.mox.ReplayAll()
|
||||
self.mock_volume_cgroup_get.return_value = cgroup
|
||||
self.mock_volume_cgroup_create_from_source.return_value = cgroup
|
||||
|
||||
url = reverse('horizon:project:cgroups:clone_cgroup',
|
||||
args=[cgroup.id])
|
||||
res = self.client.post(url, formData)
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
self.mock_volume_cgroup_get.assert_called_once_with(
|
||||
test.IsHttpRequest(), cgroup.id)
|
||||
self.mock_volume_cgroup_create_from_source.assert_called_once_with(
|
||||
test.IsHttpRequest(),
|
||||
formData['name'],
|
||||
source_cgroup_id=formData['cgroup_id'],
|
||||
description=formData['description'])
|
||||
|
@ -424,7 +424,7 @@ def data(TEST):
|
||||
{'id': u'1',
|
||||
'name': u'cg_1',
|
||||
'description': 'cg 1 description',
|
||||
'volume_types': u'1',
|
||||
'volume_types': ['1'],
|
||||
'volume_type_names': []})
|
||||
|
||||
cgroup_2 = consistencygroups.Consistencygroup(
|
||||
@ -432,7 +432,7 @@ def data(TEST):
|
||||
{'id': u'2',
|
||||
'name': u'cg_2',
|
||||
'description': 'cg 2 description',
|
||||
'volume_types': u'1',
|
||||
'volume_types': ['1'],
|
||||
'volume_type_names': []})
|
||||
|
||||
TEST.cinder_consistencygroups.add(cgroup_1)
|
||||
@ -446,7 +446,7 @@ def data(TEST):
|
||||
'display_name': 'Volume name',
|
||||
'display_description': 'Volume description',
|
||||
'created_at': '2014-01-27 10:30:00',
|
||||
'volume_type': None,
|
||||
'volume_type': 'vol_type_1',
|
||||
'attachments': [],
|
||||
'consistencygroup_id': u'1'})
|
||||
TEST.cinder_cgroup_volumes.add(api.cinder.Volume(
|
||||
|
Loading…
x
Reference in New Issue
Block a user