Merge "add unit test case of admin.py and backup.py"
This commit is contained in:
commit
17e04f02bd
@ -113,6 +113,8 @@ class FakeIdObject(object):
|
||||
self.size = 10
|
||||
self.min_disk = 10
|
||||
self.created_at = '2016-05-12T02:00:22.000000'
|
||||
self.is_incremental = False
|
||||
self.name = None
|
||||
|
||||
|
||||
class FakeCinderClient(object):
|
||||
@ -124,13 +126,27 @@ class FakeCinderClient(object):
|
||||
|
||||
class Backups(object):
|
||||
def __init__(self):
|
||||
self.del_flag = False
|
||||
|
||||
def _set_del_flag(self, value):
|
||||
self.del_flag = value
|
||||
|
||||
def create(self, id, container, name, desription,
|
||||
incremental=None, force=True,
|
||||
snapshot_id=None):
|
||||
pass
|
||||
|
||||
def create(self, id, container, name, desription):
|
||||
pass
|
||||
def list(self, search_opts=None, **kwargs):
|
||||
if 'parent_id' in search_opts:
|
||||
return []
|
||||
if self.del_flag:
|
||||
self._set_del_flag(False)
|
||||
return []
|
||||
return [FakeIdObject(4), FakeIdObject(5)]
|
||||
|
||||
def list(self, **kwargs):
|
||||
return [FakeIdObject(4)]
|
||||
def delete(self, id):
|
||||
self._set_del_flag(True)
|
||||
return
|
||||
|
||||
class Volumes(object):
|
||||
def __init__(self):
|
||||
@ -138,7 +154,11 @@ class FakeCinderClient(object):
|
||||
|
||||
@staticmethod
|
||||
def get(id):
|
||||
return FakeIdObject("5")
|
||||
volume = FakeIdObject("5")
|
||||
setattr(volume, 'availability_zone', 'nova')
|
||||
volume._info = {'id': volume.id, 'name': None, 'size': 10,
|
||||
'attachments': []}
|
||||
return volume
|
||||
|
||||
@staticmethod
|
||||
def create(size, snapshot_id=None, imageRef=None):
|
||||
@ -147,7 +167,10 @@ class FakeCinderClient(object):
|
||||
@staticmethod
|
||||
def upload_to_image(volume, force, image_name,
|
||||
container_format, disk_format):
|
||||
pass
|
||||
return ({}, {
|
||||
"os-volume_upload_image": {
|
||||
"status": "uploading",
|
||||
"image_id": "image_1"}})
|
||||
|
||||
@staticmethod
|
||||
def delete(volume):
|
||||
@ -165,6 +188,10 @@ class FakeCinderClient(object):
|
||||
def delete(snapshot):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def get(snapshot_id):
|
||||
return FakeIdObject("2")
|
||||
|
||||
class Restores(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
@ -190,6 +217,12 @@ class FakeGlanceClient(object):
|
||||
def delete(image):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def get(image_id):
|
||||
image = FakeIdObject("5")
|
||||
setattr(image, 'status', 'active')
|
||||
return image
|
||||
|
||||
@staticmethod
|
||||
def create(data, container_format, disk_format):
|
||||
return FakeIdObject("10")
|
||||
|
33
freezer/tests/unit/openstack/test_admin.py
Normal file
33
freezer/tests/unit/openstack/test_admin.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""Freezer admin.py related tests
|
||||
|
||||
(c) Copyright 2018 ZTE Corporation.
|
||||
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 freezer.openstack import admin
|
||||
from freezer.tests import commons
|
||||
|
||||
|
||||
class TestAdmin(commons.FreezerBaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestAdmin, self).setUp()
|
||||
self.backup_opt = commons.BackupOpt1()
|
||||
self.admin_os = admin.AdminOs(self.backup_opt.client_manager)
|
||||
self.client_manager = self.backup_opt.client_manager
|
||||
|
||||
def test_del_off_limit_fullbackup_keep(self):
|
||||
self.admin_os.del_off_limit_fullbackup('2', 1)
|
||||
|
||||
def test_del_off_limit_fullbackup_keep_two(self):
|
||||
self.admin_os.del_off_limit_fullbackup('2', 2)
|
43
freezer/tests/unit/openstack/test_backup.py
Normal file
43
freezer/tests/unit/openstack/test_backup.py
Normal file
@ -0,0 +1,43 @@
|
||||
"""Freezer backup.py related tests
|
||||
|
||||
(c) Copyright 2018 ZTE Corporation.
|
||||
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.
|
||||
|
||||
"""
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from freezer.openstack import backup
|
||||
from freezer.tests import commons
|
||||
|
||||
|
||||
class TestBackup(commons.FreezerBaseTestCase):
|
||||
def setUp(self):
|
||||
super(TestBackup, self).setUp()
|
||||
self.backup_opt = commons.BackupOpt1()
|
||||
self.bakup_os = backup.BackupOs(self.backup_opt.client_manager,
|
||||
self.backup_opt.container,
|
||||
self.backup_opt.storage)
|
||||
self.client_manager = self.backup_opt.client_manager
|
||||
self.storage = self.backup_opt.storage
|
||||
|
||||
@unittest.skipIf(sys.version_info.major == 3,
|
||||
'Not supported on python v 3.x')
|
||||
def test_backup_cinder_by_glance(self):
|
||||
self.bakup_os.backup_cinder_by_glance(35)
|
||||
|
||||
def test_backup_cinder_with_incremental(self):
|
||||
self.bakup_os.backup_cinder(35, incremental=True)
|
||||
|
||||
def test_backup_cinder_without_incremental(self):
|
||||
self.bakup_os.backup_cinder(35, incremental=False)
|
Loading…
Reference in New Issue
Block a user