Merge "Refactoring cinder create_volume_backup scenario"

This commit is contained in:
Jenkins 2015-08-04 12:26:09 +00:00 committed by Gerrit Code Review
commit 43aa8a53b3
8 changed files with 39 additions and 32 deletions

View File

@ -437,16 +437,22 @@ class CinderVolumes(utils.CinderScenario,
@validation.required_services(consts.Service.CINDER)
@validation.required_openstack(users=True)
@base.scenario(context={"cleanup": ["cinder"]})
def create_volume_backup(self, size, do_delete=True, **kwargs):
def create_volume_backup(self, size, do_delete=True,
create_volume_kwargs=None,
create_backup_kwargs=None):
"""Create a volume backup.
:param size: volume size in GB
:param do_delete: if True, a volume and a volume backup will
be deleted after creation.
:param kwargs: optional args to create a volume backup
:param create_volume_kwargs: optional args to create a volume
:param create_backup_kwargs: optional args to create a volume backup
"""
volume = self._create_volume(size, **kwargs)
backup = self._create_backup(volume.id, **kwargs)
create_volume_kwargs = create_volume_kwargs or {}
create_backup_kwargs = create_backup_kwargs or {}
volume = self._create_volume(size, **create_volume_kwargs)
backup = self._create_backup(volume.id, **create_backup_kwargs)
if do_delete:
self._delete_volume(volume)
@ -467,10 +473,8 @@ class CinderVolumes(utils.CinderScenario,
:param create_volume_kwargs: optional args to create a volume
:param create_backup_kwargs: optional args to create a volume backup
"""
if create_volume_kwargs is None:
create_volume_kwargs = {}
if create_backup_kwargs is None:
create_backup_kwargs = {}
create_volume_kwargs = create_volume_kwargs or {}
create_backup_kwargs = create_backup_kwargs or {}
volume = self._create_volume(size, **create_volume_kwargs)
backup = self._create_backup(volume.id, **create_backup_kwargs)
@ -490,7 +494,6 @@ class CinderVolumes(utils.CinderScenario,
create_backup_kwargs=None):
"""Create and then list a volume backup.
:param size: volume size in GB
:param detailed: True if detailed information about backup
should be listed

View File

@ -4,7 +4,9 @@
"args": {
"size": 1,
"detailed": true,
"do_delete": true
"do_delete": true,
"create_volume_kwargs": {},
"create_backup_kwargs": {}
},
"runner": {
"type": "constant",

View File

@ -5,6 +5,8 @@
size: 1
detailed: True
do_delete: True
create_volume_kwargs: {}
create_backup_kwargs: {}
runner:
type: "constant"
times: 2

View File

@ -3,7 +3,9 @@
{
"args": {
"size": 1,
"do_delete": true
"do_delete": true,
"create_volume_kwargs": {},
"create_backup_kwargs": {}
},
"runner": {
"type": "constant",

View File

@ -4,6 +4,8 @@
args:
size: 1
do_delete: True
create_volume_kwargs: {}
create_backup_kwargs: {}
runner:
type: "constant"
times: 2

View File

@ -3,7 +3,9 @@
{
"args": {
"size": 1,
"do_delete": true
"do_delete": true,
"create_volume_kwargs": {},
"create_backup_kwargs": {}
},
"runner": {
"type": "constant",

View File

@ -4,6 +4,8 @@
args:
size: 1
do_delete: True
create_volume_kwargs: {}
create_backup_kwargs: {}
runner:
type: "constant"
times: 2

View File

@ -377,34 +377,26 @@ class CinderServersTestCase(test.ScenarioTestCase):
def test_create_volume_backup(self):
fake_volume = mock.MagicMock()
fake_backup = mock.MagicMock()
scenario = volumes.CinderVolumes()
scenario = self._get_scenario(fake_volume, fake_backup)
scenario._create_volume = mock.MagicMock(return_value=fake_volume)
scenario._create_backup = mock.MagicMock(return_value=fake_backup)
scenario._delete_volume = mock.MagicMock()
scenario._delete_backup = mock.MagicMock()
scenario.create_volume_backup(1, do_delete=True, fakearg="f")
scenario._create_volume.assert_called_once_with(1, fakearg="f")
scenario._create_backup.assert_called_once_with(fake_volume.id,
fakearg="f")
volume_kwargs = {"some_var": "zaq"}
scenario.create_volume_backup(
1, do_delete=True, create_volume_kwargs=volume_kwargs)
scenario._create_volume.assert_called_once_with(1, **volume_kwargs)
scenario._create_backup.assert_called_once_with(fake_volume.id)
scenario._delete_volume.assert_called_once_with(fake_volume)
scenario._delete_backup.assert_called_once_with(fake_backup)
def test_create_volume_backup_no_delete(self):
fake_volume = mock.MagicMock()
fake_backup = mock.MagicMock()
scenario = volumes.CinderVolumes()
scenario = self._get_scenario(fake_volume, fake_backup)
scenario._create_volume = mock.MagicMock(return_value=fake_volume)
scenario._create_backup = mock.MagicMock(return_value=fake_backup)
scenario._delete_volume = mock.MagicMock()
scenario._delete_backup = mock.MagicMock()
scenario.create_volume_backup(1, do_delete=False, fakearg="f")
scenario._create_volume.assert_called_once_with(1, fakearg="f")
scenario._create_backup.assert_called_once_with(fake_volume.id,
fakearg="f")
volume_kwargs = {"some_var": "zaq"}
scenario.create_volume_backup(
1, do_delete=False, create_volume_kwargs=volume_kwargs)
scenario._create_volume.assert_called_once_with(1, **volume_kwargs)
scenario._create_backup.assert_called_once_with(fake_volume.id)
self.assertFalse(scenario._delete_volume.called)
self.assertFalse(scenario._delete_backup.called)