Test coverage improvement
Change-Id: Icc4c4abc7229dda4541b8fccaeb9399a2a05eca3
This commit is contained in:
parent
f191cceded
commit
4094093c7d
119
README.rst
119
README.rst
@ -328,7 +328,7 @@ adminui.git::
|
||||
|
||||
$ sudo freezerc --action restore --container freezer_foobar-container-2
|
||||
--backup-name adminui.git
|
||||
--restore-from-host git-HP-DL380-host-001 --restore-abs-path
|
||||
--hostname git-HP-DL380-host-001 --restore-abs-path
|
||||
/home/git/repositories/adminui.git/
|
||||
--restore-from-date "2014-05-23T23:23:23"
|
||||
|
||||
@ -342,7 +342,7 @@ Let's stop mysql service first::
|
||||
Execute Restore::
|
||||
|
||||
$ sudo freezerc --action restore --container freezer_foobar-container-2
|
||||
--backup-name mysq-prod --restore-from-host db-HP-DL380-host-001
|
||||
--backup-name mysq-prod --hostname db-HP-DL380-host-001
|
||||
--restore-abs-path /var/lib/mysql --restore-from-date "2014-05-23T23:23:23"
|
||||
|
||||
And finally restart mysql::
|
||||
@ -352,7 +352,7 @@ And finally restart mysql::
|
||||
Execute a MongoDB restore of the backup name mongobigdata::
|
||||
|
||||
$ sudo freezerc --action restore --container freezer_foobar-container-2
|
||||
--backup-name mongobigdata --restore-from-host db-HP-DL380-host-001
|
||||
--backup-name mongobigdata --hostname db-HP-DL380-host-001
|
||||
--restore-abs-path /var/lib/mongo --restore-from-date "2014-05-23T23:23:23"
|
||||
|
||||
|
||||
@ -391,7 +391,7 @@ Local storage restore execution:
|
||||
|
||||
$ sudo freezerc --action restore --container /local_backup_storage/
|
||||
--backup-name adminui.git
|
||||
--restore-from-host git-HP-DL380-host-001 --restore-abs-path
|
||||
--hostname git-HP-DL380-host-001 --restore-abs-path
|
||||
/home/git/repositories/adminui.git/
|
||||
--restore-from-date "2014-05-23T23:23:23"
|
||||
--storage local
|
||||
@ -688,42 +688,47 @@ Please check the FAQ to: FAQ.rst
|
||||
|
||||
Available options::
|
||||
|
||||
$ freezerc
|
||||
|
||||
usage: freezerc [-h] [--config CONFIG] [--action {backup,restore,info,admin}]
|
||||
[-F PATH_TO_BACKUP] [-N BACKUP_NAME] [-m MODE] [-C CONTAINER]
|
||||
[-L] [-l] [-o GET_OBJECT] [-d DST_FILE]
|
||||
[--lvm-auto-snap LVM_AUTO_SNAP] [--lvm-srcvol LVM_SRCVOL]
|
||||
[--lvm-snapname LVM_SNAPNAME] [--lvm-snapsize LVM_SNAPSIZE]
|
||||
[--lvm-dirmount LVM_DIRMOUNT] [--lvm-volgroup LVM_VOLGROUP]
|
||||
[--max-level MAX_LEVEL] [--always-level ALWAYS_LEVEL]
|
||||
[--restart-always-level RESTART_ALWAYS_LEVEL]
|
||||
[-R REMOVE_OLDER_THAN] [--remove-from-date REMOVE_FROM_DATE]
|
||||
[--no-incremental] [--hostname HOSTNAME]
|
||||
[--mysql-conf MYSQL_CONF] [--log-file LOG_FILE]
|
||||
[--exclude EXCLUDE]
|
||||
[--dereference-symlink {none,soft,hard,all}] [-U]
|
||||
[--encrypt-pass-file ENCRYPT_PASS_FILE] [-M MAX_SEGMENT_SIZE]
|
||||
[--restore-abs-path RESTORE_ABS_PATH]
|
||||
[--restore-from-host RESTORE_FROM_HOST]
|
||||
[--restore-from-date RESTORE_FROM_DATE] [--max-priority] [-V]
|
||||
[-q] [--insecure] [--os-auth-ver {1,2,3}] [--proxy PROXY]
|
||||
[--dry-run] [--upload-limit UPLOAD_LIMIT]
|
||||
[--cinder-vol-id CINDER_VOL_ID] [--nova-inst-id NOVA_INST_ID]
|
||||
[--cindernative-vol-id CINDERNATIVE_VOL_ID]
|
||||
[--download-limit DOWNLOAD_LIMIT]
|
||||
[--sql-server-conf SQL_SERVER_CONF] [--vssadmin VSSADMIN]
|
||||
usage: freezerc [-h] [--config CONFIG]
|
||||
[--action {backup,restore,info,admin,exec}]
|
||||
[-F PATH_TO_BACKUP] [-N BACKUP_NAME] [-m MODE] [-C CONTAINER]
|
||||
[-L] [-l] [-o GET_OBJECT] [-d DST_FILE] [-s]
|
||||
[--lvm-auto-snap LVM_AUTO_SNAP] [--lvm-srcvol LVM_SRCVOL]
|
||||
[--lvm-snapname LVM_SNAPNAME] [--lvm-snap-perm {ro,rw}]
|
||||
[--lvm-snapsize LVM_SNAPSIZE] [--lvm-dirmount LVM_DIRMOUNT]
|
||||
[--lvm-volgroup LVM_VOLGROUP] [--max-level MAX_LEVEL]
|
||||
[--always-level ALWAYS_LEVEL]
|
||||
[--restart-always-level RESTART_ALWAYS_LEVEL]
|
||||
[-R REMOVE_OLDER_THAN] [--remove-from-date REMOVE_FROM_DATE]
|
||||
[--no-incremental] [--hostname HOSTNAME]
|
||||
[--mysql-conf MYSQL_CONF] [--metadata-out METADATA_OUT]
|
||||
[--log-file LOG_FILE] [--exclude EXCLUDE]
|
||||
[--dereference-symlink {none,soft,hard,all}] [-U]
|
||||
[--encrypt-pass-file ENCRYPT_PASS_FILE] [-M MAX_SEGMENT_SIZE]
|
||||
[--restore-abs-path RESTORE_ABS_PATH]
|
||||
[--restore-from-host HOSTNAME]
|
||||
[--restore-from-date RESTORE_FROM_DATE] [--max-priority] [-V]
|
||||
[-q] [--insecure] [--os-auth-ver {1,2,2.0,3}] [--proxy PROXY]
|
||||
[--dry-run] [--upload-limit UPLOAD_LIMIT]
|
||||
[--cinder-vol-id CINDER_VOL_ID] [--nova-inst-id NOVA_INST_ID]
|
||||
[--cindernative-vol-id CINDERNATIVE_VOL_ID]
|
||||
[--download-limit DOWNLOAD_LIMIT]
|
||||
[--sql-server-conf SQL_SERVER_CONF] [--vssadmin VSSADMIN]
|
||||
[--command COMMAND] [--compression {gzip,bzip2,xz}]
|
||||
[--storage {local,swift,ssh}] [--ssh-key SSH_KEY]
|
||||
[--ssh-username SSH_USERNAME] [--ssh-host SSH_HOST]
|
||||
[--ssh-port SSH_PORT]
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
--config CONFIG Config file abs path. Option arguments are provided
|
||||
from config file. When config file is used any option
|
||||
from command line provided take precedence.
|
||||
--action {backup,restore,info,admin}
|
||||
--action {backup,restore,info,admin,exec}
|
||||
Set the action to be taken. backup and restore are
|
||||
self explanatory, info is used to retrieve info from
|
||||
the storage media, while admin is used to delete old
|
||||
backups and other admin actions. Default backup.
|
||||
the storage media, exec is used to execute a script,
|
||||
while admin is used to delete old backups and other
|
||||
admin actions. Default backup.
|
||||
-F PATH_TO_BACKUP, --path-to-backup PATH_TO_BACKUP, --file-to-backup PATH_TO_BACKUP
|
||||
The file or directory you want to back up to Swift
|
||||
-N BACKUP_NAME, --backup-name BACKUP_NAME
|
||||
@ -733,7 +738,8 @@ Available options::
|
||||
(filesystem), mongo (MongoDB), mysql (MySQL),
|
||||
sqlserver (SQL Server) Default set to fs
|
||||
-C CONTAINER, --container CONTAINER
|
||||
The Swift container used to upload files to
|
||||
The Swift container (or path to local storage) used to
|
||||
upload files to
|
||||
-L, --list-containers
|
||||
List the Swift containers on remote Object Storage
|
||||
Server
|
||||
@ -745,6 +751,9 @@ Available options::
|
||||
-d DST_FILE, --dst-file DST_FILE
|
||||
The file name used to save the object on your local
|
||||
disk and upload file in swift
|
||||
-s, --snapshot Create a snapshot of the fs containing the resource to
|
||||
backup. When used, the lvm parameters will be guessed
|
||||
and/or the default values will be used
|
||||
--lvm-auto-snap LVM_AUTO_SNAP
|
||||
Automatically guess the volume group and volume name
|
||||
for given PATH.
|
||||
@ -755,13 +764,18 @@ Available options::
|
||||
Set the lvm snapshot name to use. If the snapshot name
|
||||
already exists, the old one will be used a no new one
|
||||
will be created. Default freezer_backup_snap.
|
||||
--lvm-snap-perm {ro,rw}
|
||||
Set the lvm snapshot permission to use. If the
|
||||
permission is set to ro The snapshot will be immutable
|
||||
- read only -. If the permission is set to rw it will
|
||||
be mutable
|
||||
--lvm-snapsize LVM_SNAPSIZE
|
||||
Set the lvm snapshot size when creating a new
|
||||
snapshot. Please add G for Gigabytes or M for
|
||||
Megabytes, i.e. 500M or 8G. Default 5G.
|
||||
Megabytes, i.e. 500M or 8G. Default 1G.
|
||||
--lvm-dirmount LVM_DIRMOUNT
|
||||
Set the directory you want to mount the lvm snapshot
|
||||
to. Default not set
|
||||
to. Default to /var/lib/freezer
|
||||
--lvm-volgroup LVM_VOLGROUP
|
||||
Specify the volume group of your logical volume. This
|
||||
is important to mount your snapshot volume. Default
|
||||
@ -810,9 +824,12 @@ Available options::
|
||||
Set the MySQL configuration file where freezer
|
||||
retrieve important information as db_name, user,
|
||||
password, host, port. Following is an example of
|
||||
config file: # cat ~/.freezer/backup_mysql_conf host =
|
||||
<db-host> user = <mysqluser> password = <mysqlpass>
|
||||
port = <db-port>
|
||||
config file: # backup_mysql_conf host = <db-host> user
|
||||
= <mysqluser> password = <mysqlpass> port = <db-port>
|
||||
--metadata-out METADATA_OUT
|
||||
Set the filename to which write the metadata regarding
|
||||
the backup metrics. Use "-" to output to standard
|
||||
output.
|
||||
--log-file LOG_FILE Set log file. By default logs to
|
||||
/var/log/freezer.logIf that file is not writable,
|
||||
freezer tries to logto ~/.freezer/freezer.log
|
||||
@ -834,18 +851,19 @@ Available options::
|
||||
--restore-abs-path RESTORE_ABS_PATH
|
||||
Set the absolute path where you want your data
|
||||
restored. Default False.
|
||||
--restore-from-host RESTORE_FROM_HOST
|
||||
--restore-from-host HOSTNAME
|
||||
Set the hostname used to identify the data you want to
|
||||
restore from. If you want to restore data in the same
|
||||
host where the backup was executed just type from your
|
||||
shell: "$ hostname" and the output is the value that
|
||||
needs to be passed to this option. Mandatory with
|
||||
Restore Default False.
|
||||
Restore Default False. (Deprecated use "hostname"
|
||||
instead)
|
||||
--restore-from-date RESTORE_FROM_DATE
|
||||
Set the absolute path where you want your data
|
||||
restored. Please provide datetime in format "YYYY-MM-
|
||||
DDThh:mm:ss" i.e. "1979-10-03T23:23:23". Make sure the
|
||||
"T" is between date and time Default False.
|
||||
"T" is between date and time Default None.
|
||||
--max-priority Set the cpu process to the highest priority (i.e. -20
|
||||
on Linux) and real-time for I/O. The process priority
|
||||
will be set only if nice and ionice are installed
|
||||
@ -854,8 +872,8 @@ Available options::
|
||||
-q, --quiet Suppress error messages
|
||||
--insecure Allow to access swift servers without checking SSL
|
||||
certs.
|
||||
--os-auth-ver {1,2,3}
|
||||
Swift auth version, could be 1, 2 or 3
|
||||
--os-auth-ver {1,2,2.0,3}, --os-identity-api-version {1,2,2.0,3}
|
||||
Openstack identity api version, can be 1, 2, 2.0 or 3
|
||||
--proxy PROXY Enforce proxy that alters system HTTP_PROXY and
|
||||
HTTPS_PROXY, use '' to eliminate all system proxies
|
||||
--dry-run Do everything except writing or removing objects
|
||||
@ -877,4 +895,17 @@ Available options::
|
||||
example of config file: instance = <db-instance>
|
||||
--vssadmin VSSADMIN Create a backup using a snapshot on windows using
|
||||
vssadmin. Options are: True and False, default is True
|
||||
|
||||
--command COMMAND Command executed by exec action
|
||||
--compression {gzip,bzip2,xz}
|
||||
compression algorithm to use. gzip is default
|
||||
algorithm
|
||||
--storage {local,swift,ssh}
|
||||
Storage for backups. Can be Swift or Local now. Swift
|
||||
is defaultstorage now. Local stores backups on the
|
||||
same defined path andswift will store files in
|
||||
container.
|
||||
--ssh-key SSH_KEY Path to ssh-key for ssh storage only
|
||||
--ssh-username SSH_USERNAME
|
||||
Remote username for ssh storage only
|
||||
--ssh-host SSH_HOST Remote host for ssh storage only
|
||||
--ssh-port SSH_PORT Remote port for ssh storage only (default 22)
|
||||
|
@ -322,7 +322,8 @@ def backup_arguments(args_dict={}):
|
||||
from. If you want to restore data in the same host where the backup
|
||||
was executed just type from your shell: "$ hostname" and the output is
|
||||
the value that needs to be passed to this option. Mandatory with
|
||||
Restore Default False.''', dest='restore_from_host', default=False)
|
||||
Restore Default False. (Deprecated use "hostname" instead) ''',
|
||||
dest='hostname', default=False)
|
||||
arg_parser.add_argument(
|
||||
'--restore-from-date', action='store',
|
||||
help='''Set the absolute path where you want your data restored.
|
||||
|
@ -42,11 +42,7 @@ class StopState(object):
|
||||
|
||||
@staticmethod
|
||||
def abort(job, doc):
|
||||
job.job_doc = doc
|
||||
job.event = Job.NO_EVENT
|
||||
job.job_doc_status = Job.STOP_STATUS
|
||||
job.scheduler.update_job(job.id, job.job_doc)
|
||||
return Job.NO_EVENT
|
||||
return StopState.stop(job, doc)
|
||||
|
||||
@staticmethod
|
||||
def start(job, doc):
|
||||
|
220
tests/commons.py
220
tests/commons.py
@ -1,13 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
from mock import MagicMock
|
||||
import sys
|
||||
|
||||
import swiftclient
|
||||
import multiprocessing
|
||||
import subprocess
|
||||
import time
|
||||
import os
|
||||
import pymysql as MySQLdb
|
||||
import pymongo
|
||||
import re
|
||||
from glanceclient.common.utils import IterableWithLength
|
||||
@ -23,46 +21,10 @@ os.environ['OS_USERNAME'] = 'testusername'
|
||||
os.environ['OS_TENANT_NAME'] = 'testtenantename'
|
||||
|
||||
|
||||
class FakeLogging:
|
||||
|
||||
def __init__(self):
|
||||
return None
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def logging(cls, opt1=True):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def info(cls, opt1=True):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def warning(cls, opt1=True):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def critical(cls, opt1=True):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def exception(cls, opt1=True):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def error(cls, opt1=True):
|
||||
return True
|
||||
|
||||
|
||||
class FakeBackup:
|
||||
def __init__(self):
|
||||
return None
|
||||
|
||||
def fake_backup_mode_fs(self, *args, **kwargs):
|
||||
return True
|
||||
|
||||
def fake_backup_mode_mongo(self, *args, **kwargs):
|
||||
return True
|
||||
|
||||
@ -317,7 +279,6 @@ class BackupOpt1:
|
||||
self.dereference_symlink = 'none'
|
||||
self.mysql_conf = '/tmp/freezer-test-conf-file'
|
||||
self.backup_media = 'fs'
|
||||
self.mysql_db_inst = FakeMySQLdb()
|
||||
self.lvm_auto_snap = '/dev/null'
|
||||
self.lvm_volgroup = 'testgroup'
|
||||
self.lvm_srcvol = 'testvol'
|
||||
@ -355,23 +316,7 @@ class BackupOpt1:
|
||||
self.always_level = '20'
|
||||
self.remove_from_date = '2014-12-03T23:23:23'
|
||||
self.restart_always_level = 100000
|
||||
self.remote_match_backup = [
|
||||
'test-hostname_test-backup-name_1234567_0',
|
||||
'test-hostname_test-backup-name_1234568_1',
|
||||
'test-hostname_test-backup-name_1234569_2',
|
||||
'test-hostname_test-backup-name_1234570_3',
|
||||
'test-hostname_test-backup-name_1234571_4',
|
||||
'test-hostname_test-backup-name_1234572_5',
|
||||
'tar_metadata_test-hostname_test-backup-name_1234572_5',
|
||||
'tar_metadata_test-hostname_test-backup-name_1234571_4',
|
||||
'tar_metadata_test-hostname_test-backup-name_1234570_3',
|
||||
'tar_metadata_test-hostname_test-backup-name_1234569_2',
|
||||
'tar_metadata_test-hostname_test-backup-name_1234568_1',
|
||||
'tar_metadata_test-hostname_test-backup-name_1234567_0']
|
||||
self.restore_abs_path = '/tmp'
|
||||
self.containers_list = [
|
||||
{'name' : 'testcontainer1', 'bytes' : 123423, 'count' : 10}
|
||||
]
|
||||
self.list_containers = False
|
||||
self.list_objects = False
|
||||
self.restore_from_date = '2014-12-03T23:23:23'
|
||||
@ -413,39 +358,6 @@ class BackupOpt1:
|
||||
self.command = None
|
||||
|
||||
|
||||
class FakeMySQLdb:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self
|
||||
|
||||
@classmethod
|
||||
def connect(cls, host=True, user=True, passwd=True, port=True):
|
||||
return cls
|
||||
|
||||
@classmethod
|
||||
def cursor(cls):
|
||||
return cls
|
||||
|
||||
@classmethod
|
||||
def execute(cls, string=str):
|
||||
return cls
|
||||
|
||||
@classmethod
|
||||
def close(cls):
|
||||
return cls
|
||||
|
||||
@classmethod
|
||||
def commit(cls):
|
||||
return cls
|
||||
|
||||
@classmethod
|
||||
def close(cls):
|
||||
return True
|
||||
|
||||
|
||||
class Os:
|
||||
def __init__(self, directory=True):
|
||||
return None
|
||||
@ -555,75 +467,6 @@ class Os:
|
||||
raise Exception
|
||||
|
||||
|
||||
def fake_get_match_backup(self, backup_opt):
|
||||
#backup_opt = BackupOpt1()
|
||||
backup_opt.remote_match_backup = None
|
||||
return backup_opt
|
||||
|
||||
|
||||
class FakeSwift:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def fake_show_containers(self, backup_opt):
|
||||
return True
|
||||
|
||||
def fake_show_objects(self, backup_opt):
|
||||
return True
|
||||
|
||||
def fake_check_container_existance(self, *args, **kwargs):
|
||||
return {'main_container': True, 'container_segments': True}
|
||||
|
||||
def fake_check_container_existance1(self, *args, **kwargs):
|
||||
return {'main_container': False, 'container_segments': False}
|
||||
|
||||
def fake_get_container_content(self, backup_opt):
|
||||
return backup_opt
|
||||
|
||||
def remove_obj_older_than(self, backup_opt):
|
||||
return backup_opt
|
||||
|
||||
|
||||
class FakeUtils:
|
||||
|
||||
def __init__(self):
|
||||
return None
|
||||
|
||||
def fake_set_backup_level(self,backup_opt, manifest_meta):
|
||||
return backup_opt, manifest_meta
|
||||
|
||||
def fake_set_backup_level_fs(self, backup_opt, manifest_meta):
|
||||
#backup_opt = BackupOpt1()
|
||||
manifest_meta = {}
|
||||
backup_opt.mode = 'fs'
|
||||
return backup_opt, manifest_meta
|
||||
|
||||
def fake_set_backup_level_mongo(self, backup_opt, manifest_meta):
|
||||
#backup_opt = BackupOpt1()
|
||||
manifest_meta = {}
|
||||
backup_opt.mode = 'mongo'
|
||||
return backup_opt, manifest_meta
|
||||
|
||||
def fake_set_backup_level_mysql(self, backup_opt, manifest_meta):
|
||||
#backup_opt = BackupOpt1()
|
||||
manifest_meta = {}
|
||||
backup_opt.mode = 'mysql'
|
||||
return backup_opt, manifest_meta
|
||||
|
||||
def fake_set_backup_level_none(self, backup_opt, manifest_meta):
|
||||
#backup_opt = BackupOpt1()
|
||||
manifest_meta = {}
|
||||
backup_opt.mode = None
|
||||
return backup_opt, manifest_meta
|
||||
|
||||
def fake_create_subprocess_err(self, cmd):
|
||||
return ['','some err']
|
||||
|
||||
def fake_create_subprocess_raise(self, cmd):
|
||||
raise Exception('')
|
||||
|
||||
|
||||
class FakeSocket:
|
||||
def __init__(self):
|
||||
pass
|
||||
@ -635,48 +478,6 @@ class FakeSocket:
|
||||
raise Exception("fake send")
|
||||
|
||||
|
||||
class FakeJob:
|
||||
def __init__(self, conf_dict):
|
||||
self.conf = conf_dict
|
||||
|
||||
def execute(self):
|
||||
return
|
||||
|
||||
|
||||
def fake_create_job(conf):
|
||||
return FakeJob(conf)
|
||||
|
||||
|
||||
class FakeVss:
|
||||
|
||||
def __init__(self):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def vss_create_shadow_copy(self, volume):
|
||||
return 'ShadowID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
|
||||
|
||||
@classmethod
|
||||
def vss_create_shadow_copy_error(self, volume):
|
||||
return 'ShadowID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', 'error'
|
||||
|
||||
@classmethod
|
||||
def vss_get_shadow_copy(self, shadow_id):
|
||||
return 'Shadow Copy Volume: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
|
||||
|
||||
@classmethod
|
||||
def vss_get_shadow_copy_error(self, shadow_id):
|
||||
return 'Shadow Copy Volume: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', ''
|
||||
|
||||
@classmethod
|
||||
def vss_delete_shadow_copy(self, shadow_id):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def vss_delete_shadow_copy_error(self, shadow_id):
|
||||
return '', 'error'
|
||||
|
||||
|
||||
class FakeDisableFileSystemRedirection:
|
||||
success = True
|
||||
|
||||
@ -686,24 +487,3 @@ class FakeDisableFileSystemRedirection:
|
||||
def __exit__(self, type, value, traceback):
|
||||
if self.success:
|
||||
return True
|
||||
|
||||
|
||||
def fake_create_subprocess(cmd):
|
||||
return True, ''
|
||||
|
||||
|
||||
def fake_create_subprocess2(cmd):
|
||||
return True, 'Error'
|
||||
|
||||
class FakeSys:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def fake_sys_argv():
|
||||
return ['', '', '']
|
||||
|
||||
# @staticmethod
|
||||
def fake_sys_exit(self, status_code):
|
||||
raise SystemExit(status_code)
|
||||
|
@ -62,9 +62,9 @@ def execute(cmd, must_fail=False, merge_stderr=False):
|
||||
result, result_err = proc.communicate()
|
||||
|
||||
if not must_fail and proc.returncode != 0:
|
||||
raise CommandFailed(proc.returncode, cmd_freezer, result, result_err)
|
||||
raise CommandFailed(proc.returncode, cmd, result, result_err)
|
||||
if must_fail and proc.returncode == 0:
|
||||
raise CommandFailed(proc.returncode, cmd_freezer, result, result_err)
|
||||
raise CommandFailed(proc.returncode, cmd, result, result_err)
|
||||
return result
|
||||
|
||||
|
||||
|
0
tests/scheduler/__init__.py
Normal file
0
tests/scheduler/__init__.py
Normal file
10
tests/scheduler/test_scheduler_job.py
Normal file
10
tests/scheduler/test_scheduler_job.py
Normal file
@ -0,0 +1,10 @@
|
||||
import unittest
|
||||
|
||||
from freezer.scheduler import scheduler_job
|
||||
|
||||
class TestSchedulerJob(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.job = scheduler_job.Job(None, None, {"job_schedule": {}})
|
||||
|
||||
def test(self):
|
||||
scheduler_job.RunningState.stop(self.job, {})
|
@ -35,16 +35,8 @@ import unittest
|
||||
|
||||
class TestJob:
|
||||
|
||||
|
||||
def do_monkeypatch(self, monkeypatch):
|
||||
fakelogging = FakeLogging()
|
||||
self.fakeswift = fakeswift = FakeSwift()
|
||||
self.fakeutils = FakeUtils()
|
||||
self.fakebackup = FakeBackup()
|
||||
monkeypatch.setattr(logging, 'critical', fakelogging.critical)
|
||||
monkeypatch.setattr(logging, 'warning', fakelogging.warning)
|
||||
monkeypatch.setattr(logging, 'exception', fakelogging.exception)
|
||||
monkeypatch.setattr(logging, 'error', fakelogging.error)
|
||||
|
||||
def test_execute(self, monkeypatch):
|
||||
self.do_monkeypatch(monkeypatch)
|
||||
@ -123,18 +115,15 @@ class TestExecJob(TestJob):
|
||||
self.mock_popen.return_value.communicate = Mock()
|
||||
self.mock_popen.return_value.communicate.return_value = ['some stderr']
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
self.popen.stop()
|
||||
|
||||
|
||||
def test_execute_nothing_to_do(self, monkeypatch):
|
||||
self.do_monkeypatch(monkeypatch)
|
||||
backup_opt = BackupOpt1()
|
||||
job = ExecJob(backup_opt)
|
||||
assert job.execute() is False
|
||||
|
||||
|
||||
def test_execute_script(self, monkeypatch):
|
||||
self.setUp()
|
||||
self.do_monkeypatch(monkeypatch)
|
||||
@ -145,7 +134,6 @@ class TestExecJob(TestJob):
|
||||
assert job.execute() is True
|
||||
self.tearDown()
|
||||
|
||||
|
||||
def test_execute_raise(self, monkeypatch):
|
||||
self.setUp()
|
||||
self.do_monkeypatch(monkeypatch)
|
||||
|
@ -1,42 +0,0 @@
|
||||
"""Freezer main.py related tests
|
||||
|
||||
(c) Copyright 2014,2015 Hewlett-Packard Development Company, L.P.
|
||||
|
||||
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.
|
||||
|
||||
This product includes cryptographic software written by Eric Young
|
||||
(eay@cryptsoft.com). This product includes software written by Tim
|
||||
Hudson (tjh@cryptsoft.com).
|
||||
"""
|
||||
|
||||
from commons import fake_create_job
|
||||
from commons import FakeSys
|
||||
|
||||
from freezer import job
|
||||
from freezer.main import freezer_main
|
||||
import sys
|
||||
|
||||
'''
|
||||
def test_freezer_main(monkeypatch):
|
||||
fake_sys = FakeSys()
|
||||
monkeypatch.setattr(job, 'create_job', fake_create_job)
|
||||
monkeypatch.setattr(sys, 'exit', fake_sys.fake_sys_exit)
|
||||
with pytest.raises(SystemExit):
|
||||
freezer_main()
|
||||
|
||||
monkeypatch.setattr(job, 'create_job', fake_create_job)
|
||||
monkeypatch.setattr(sys, 'argv', FakeSys.fake_sys_argv())
|
||||
# assert freezer_main() is not None
|
||||
with pytest.raises(SystemExit):
|
||||
freezer_main()
|
||||
'''
|
@ -13,21 +13,16 @@
|
||||
# limitations under the License.
|
||||
|
||||
from commons import (FakeDisableFileSystemRedirection, FakeSubProcess,
|
||||
FakeLogging, BackupOpt1, Os, FakeSubProcess3, FakeSubProcess6,
|
||||
fake_create_subprocess, fake_create_subprocess2)
|
||||
FakeSubProcess3, FakeSubProcess6)
|
||||
from freezer import vss
|
||||
from freezer import winutils
|
||||
from freezer import utils
|
||||
import subprocess
|
||||
import os
|
||||
import logging
|
||||
|
||||
|
||||
class TestVss:
|
||||
|
||||
def test_vss_create_shadow_copy(self, monkeypatch):
|
||||
fake_disable_redirection = FakeDisableFileSystemRedirection()
|
||||
fakelogging = FakeLogging()
|
||||
fakesubprocess = FakeSubProcess()
|
||||
fakesubprocesspopen = fakesubprocess.Popen()
|
||||
|
||||
@ -44,8 +39,6 @@ class TestVss:
|
||||
winutils.DisableFileSystemRedirection, '__exit__',
|
||||
fake_disable_redirection.__exit__)
|
||||
|
||||
monkeypatch.setattr(logging, 'info', fakelogging.info)
|
||||
|
||||
assert vss.vss_create_shadow_copy('C:\\') is not False
|
||||
|
||||
fakesubprocess = FakeSubProcess3()
|
||||
@ -60,9 +53,6 @@ class TestVss:
|
||||
pytest.raises(Exception, vss.vss_create_shadow_copy('C:\\'))
|
||||
|
||||
def test_vss_delete_shadow_copy(self, monkeypatch):
|
||||
fakelogging = FakeLogging()
|
||||
monkeypatch.setattr(logging, 'info', fakelogging.info)
|
||||
|
||||
fake_disable_redirection = FakeDisableFileSystemRedirection()
|
||||
monkeypatch.setattr(
|
||||
winutils.DisableFileSystemRedirection, '__enter__',
|
||||
|
@ -71,7 +71,6 @@ class TestWinutils:
|
||||
def test_start_sql_server(self, monkeypatch):
|
||||
fake_disable_redirection = FakeDisableFileSystemRedirection()
|
||||
backup_opt = BackupOpt1()
|
||||
fakelogging = FakeLogging()
|
||||
fakesubprocess = FakeSubProcess()
|
||||
fakesubprocesspopen = fakesubprocess.Popen()
|
||||
|
||||
@ -87,8 +86,6 @@ class TestWinutils:
|
||||
winutils.DisableFileSystemRedirection, '__exit__',
|
||||
fake_disable_redirection.__exit__)
|
||||
|
||||
monkeypatch.setattr(logging, 'info', fakelogging.info)
|
||||
|
||||
assert winutils.start_sql_server(backup_opt) is not False
|
||||
|
||||
fakesubprocess = FakeSubProcess3()
|
||||
@ -107,7 +104,6 @@ class TestWinutils:
|
||||
def test_stop_sql_server(self, monkeypatch):
|
||||
fake_disable_redirection = FakeDisableFileSystemRedirection()
|
||||
backup_opt = BackupOpt1()
|
||||
fakelogging = FakeLogging()
|
||||
fakesubprocess = FakeSubProcess()
|
||||
fakesubprocesspopen = fakesubprocess.Popen()
|
||||
|
||||
@ -123,8 +119,6 @@ class TestWinutils:
|
||||
winutils.DisableFileSystemRedirection, '__exit__',
|
||||
fake_disable_redirection.__exit__)
|
||||
|
||||
monkeypatch.setattr(logging, 'info', fakelogging.info)
|
||||
|
||||
assert winutils.start_sql_server(
|
||||
backup_opt.sql_server_instance) is not False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user