Update _usage_from_backup() method with versionedobjects
The versionedobjects for cinder backup is already there, somehow the _usage_from_backup() method in cinder/volume/utils.py is not changed accordingly. The patch updates the method for this. Partial-Implements: blueprint cinder-objects Change-Id: If4ffeabf0d9b6c34cc1a675185019aeb5504ee4d
This commit is contained in:
parent
281ddeb03f
commit
002c247957
|
@ -27,6 +27,7 @@ from oslo_config import cfg
|
|||
from cinder import context
|
||||
from cinder import exception
|
||||
from cinder import test
|
||||
from cinder.tests.unit import fake_backup
|
||||
from cinder.tests.unit import fake_constants as fake
|
||||
from cinder.tests.unit import fake_snapshot
|
||||
from cinder.tests.unit import fake_volume
|
||||
|
@ -289,31 +290,36 @@ class NotifyUsageTestCase(test.TestCase):
|
|||
|
||||
def test_usage_from_backup(self):
|
||||
raw_backup = {
|
||||
'project_id': '12b0330ec2584a',
|
||||
'user_id': '158cba1b8c2bb6008e',
|
||||
'project_id': fake.project_id,
|
||||
'user_id': fake.user_id,
|
||||
'availability_zone': 'nova',
|
||||
'id': 'fake_id',
|
||||
'id': fake.backup_id,
|
||||
'host': 'fake_host',
|
||||
'display_name': 'test_backup',
|
||||
'created_at': '2014-12-11T10:10:00',
|
||||
'created_at': datetime.datetime(2015, 1, 1, 1, 1, 1),
|
||||
'status': 'available',
|
||||
'volume_id': 'fake_volume_id',
|
||||
'volume_id': fake.volume_id,
|
||||
'size': 1,
|
||||
'service_metadata': None,
|
||||
'service': 'cinder.backup.drivers.swift',
|
||||
'fail_reason': None,
|
||||
'parent_id': 'fake_parent_id',
|
||||
'parent_id': fake.backup2_id,
|
||||
'num_dependent_backups': 0,
|
||||
'snapshot_id': None,
|
||||
}
|
||||
|
||||
ctxt = context.get_admin_context()
|
||||
backup_obj = fake_backup.fake_backup_obj(ctxt, **raw_backup)
|
||||
|
||||
# Make it easier to find out differences between raw and expected.
|
||||
expected_backup = raw_backup.copy()
|
||||
expected_backup['tenant_id'] = expected_backup.pop('project_id')
|
||||
expected_backup['backup_id'] = expected_backup.pop('id')
|
||||
expected_backup['created_at'] = (
|
||||
six.text_type(expected_backup['created_at']) + '+00:00')
|
||||
|
||||
usage_info = volume_utils._usage_from_backup(raw_backup)
|
||||
self.assertEqual(expected_backup, usage_info)
|
||||
usage_info = volume_utils._usage_from_backup(backup_obj)
|
||||
self.assertDictMatch(expected_backup, usage_info)
|
||||
|
||||
|
||||
class LVMVolumeDriverTestCase(test.TestCase):
|
||||
|
|
|
@ -91,24 +91,24 @@ def _usage_from_volume(context, volume_ref, **kw):
|
|||
return usage_info
|
||||
|
||||
|
||||
def _usage_from_backup(backup_ref, **kw):
|
||||
num_dependent_backups = backup_ref['num_dependent_backups']
|
||||
usage_info = dict(tenant_id=backup_ref['project_id'],
|
||||
user_id=backup_ref['user_id'],
|
||||
availability_zone=backup_ref['availability_zone'],
|
||||
backup_id=backup_ref['id'],
|
||||
host=backup_ref['host'],
|
||||
display_name=backup_ref['display_name'],
|
||||
created_at=str(backup_ref['created_at']),
|
||||
status=backup_ref['status'],
|
||||
volume_id=backup_ref['volume_id'],
|
||||
size=backup_ref['size'],
|
||||
service_metadata=backup_ref['service_metadata'],
|
||||
service=backup_ref['service'],
|
||||
fail_reason=backup_ref['fail_reason'],
|
||||
parent_id=backup_ref['parent_id'],
|
||||
def _usage_from_backup(backup, **kw):
|
||||
num_dependent_backups = backup.num_dependent_backups
|
||||
usage_info = dict(tenant_id=backup.project_id,
|
||||
user_id=backup.user_id,
|
||||
availability_zone=backup.availability_zone,
|
||||
backup_id=backup.id,
|
||||
host=backup.host,
|
||||
display_name=backup.display_name,
|
||||
created_at=str(backup.created_at),
|
||||
status=backup.status,
|
||||
volume_id=backup.volume_id,
|
||||
size=backup.size,
|
||||
service_metadata=backup.service_metadata,
|
||||
service=backup.service,
|
||||
fail_reason=backup.fail_reason,
|
||||
parent_id=backup.parent_id,
|
||||
num_dependent_backups=num_dependent_backups,
|
||||
snapshot_id=backup_ref['snapshot_id'],
|
||||
snapshot_id=backup.snapshot_id,
|
||||
)
|
||||
|
||||
usage_info.update(kw)
|
||||
|
|
Loading…
Reference in New Issue