Clean imports in code
This patch set modifies lines which are importing objects instead of modules. As per openstack import guide lines, user should import modules in a file not objects. Also, imports was regrouped and placed in alphabetical order. http://docs.openstack.org/developer/hacking/#imports Change-Id: I192b8bf6f50a85e19640975f0902a014c4ba0878 Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
This commit is contained in:
parent
85ab97121e
commit
61ee6a331a
|
@ -18,15 +18,15 @@ limitations under the License.
|
|||
import abc
|
||||
import json
|
||||
import multiprocessing
|
||||
from multiprocessing.queues import SimpleQueue
|
||||
from multiprocessing import queues
|
||||
import shutil
|
||||
import six
|
||||
# PyCharm will not recognize queue. Puts red squiggle line under it. That's OK.
|
||||
from six.moves import queue
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from oslo_log import log
|
||||
import six
|
||||
# PyCharm will not recognize queue. Puts red squiggle line under it. That's OK.
|
||||
from six.moves import queue
|
||||
|
||||
from freezer.exceptions import engine as engine_exceptions
|
||||
from freezer.storage import base
|
||||
|
@ -179,8 +179,7 @@ class BackupEngine(object):
|
|||
|
||||
if got_exception:
|
||||
raise engine_exceptions.EngineException(
|
||||
"Engine error. Failed to backup."
|
||||
)
|
||||
"Engine error. Failed to backup.")
|
||||
|
||||
with open(freezer_meta, mode='wb') as b_file:
|
||||
b_file.write(json.dumps(self.metadata()))
|
||||
|
@ -242,7 +241,7 @@ class BackupEngine(object):
|
|||
max_level = max(backups.keys())
|
||||
|
||||
# Use SimpleQueue because Queue does not work on Mac OS X.
|
||||
read_except_queue = SimpleQueue()
|
||||
read_except_queue = queues.SimpleQueue()
|
||||
|
||||
for level in range(0, max_level + 1):
|
||||
backup = backups[level]
|
||||
|
@ -259,7 +258,7 @@ class BackupEngine(object):
|
|||
# Start the tar pipe consumer process
|
||||
|
||||
# Use SimpleQueue because Queue does not work on Mac OS X.
|
||||
write_except_queue = SimpleQueue()
|
||||
write_except_queue = queues.SimpleQueue()
|
||||
|
||||
tar_stream = multiprocessing.Process(
|
||||
target=self.restore_level,
|
||||
|
@ -290,8 +289,7 @@ class BackupEngine(object):
|
|||
|
||||
if tar_stream.exitcode or got_exception:
|
||||
raise engine_exceptions.EngineException(
|
||||
"Engine error. Failed to restore."
|
||||
)
|
||||
"Engine error. Failed to restore.")
|
||||
|
||||
LOG.info(
|
||||
'Restore completed successfully for backup name '
|
||||
|
|
|
@ -15,23 +15,24 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
|
||||
"""
|
||||
|
||||
import abc
|
||||
import datetime
|
||||
import os
|
||||
import six
|
||||
import sys
|
||||
import time
|
||||
|
||||
from freezer.openstack import backup
|
||||
from freezer.openstack import restore
|
||||
from freezer.snapshot import snapshot
|
||||
from freezer.utils.checksum import CheckSum
|
||||
from freezer.utils import exec_cmd
|
||||
from freezer.utils import utils
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import importutils
|
||||
import six
|
||||
|
||||
from freezer.openstack import backup
|
||||
from freezer.openstack import restore
|
||||
from freezer.snapshot import snapshot
|
||||
from freezer.utils import checksum
|
||||
from freezer.utils import exec_cmd
|
||||
from freezer.utils import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
@ -196,7 +197,7 @@ class BackupJob(Job):
|
|||
if self.conf.consistency_check:
|
||||
ignorelinks = (self.conf.dereference_symlink == 'none' or
|
||||
self.conf.dereference_symlink == 'hard')
|
||||
consistency_checksum = CheckSum(
|
||||
consistency_checksum = checksum.CheckSum(
|
||||
filepath, ignorelinks=ignorelinks).compute()
|
||||
LOG.info('Computed checksum for consistency {0}'.
|
||||
format(consistency_checksum))
|
||||
|
@ -274,8 +275,8 @@ class RestoreJob(Job):
|
|||
try:
|
||||
if conf.consistency_checksum:
|
||||
backup_checksum = conf.consistency_checksum
|
||||
restore_checksum = CheckSum(restore_abs_path,
|
||||
ignorelinks=True)
|
||||
restore_checksum = checksum.CheckSum(restore_abs_path,
|
||||
ignorelinks=True)
|
||||
if restore_checksum.compare(backup_checksum):
|
||||
LOG.info('Consistency check success.')
|
||||
else:
|
||||
|
|
|
@ -14,16 +14,16 @@
|
|||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import swiftclient
|
||||
import time
|
||||
|
||||
from cinderclient.client import Client as cinder_client
|
||||
from glanceclient.client import Client as glance_client
|
||||
from cinderclient import client as cinder_client
|
||||
from glanceclient import client as glance_client
|
||||
from keystoneauth1 import loading
|
||||
from keystoneauth1 import session
|
||||
from novaclient.client import Client as nova_client
|
||||
from novaclient import client as nova_client
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import swiftclient
|
||||
|
||||
from freezer.utils import utils
|
||||
|
||||
|
@ -78,8 +78,8 @@ class OSClientManager(object):
|
|||
Use pre-initialized session to create an instance of nova client.
|
||||
:return: novaclient instance
|
||||
"""
|
||||
self.nova = nova_client(self.compute_version, session=self.sess,
|
||||
**self.client_kwargs)
|
||||
self.nova = nova_client.Client(self.compute_version, session=self.sess,
|
||||
**self.client_kwargs)
|
||||
return self.nova
|
||||
|
||||
def create_glance(self):
|
||||
|
@ -92,8 +92,9 @@ class OSClientManager(object):
|
|||
if 'insecure' in self.client_kwargs.keys():
|
||||
self.client_kwargs.pop('insecure')
|
||||
|
||||
self.glance = glance_client(self.image_version, session=self.sess,
|
||||
**self.client_kwargs)
|
||||
self.glance = glance_client.Client(self.image_version,
|
||||
session=self.sess,
|
||||
**self.client_kwargs)
|
||||
return self.glance
|
||||
|
||||
def create_cinder(self):
|
||||
|
@ -101,8 +102,9 @@ class OSClientManager(object):
|
|||
Use pre-initialized session to create an instance of cinder client.
|
||||
:return: cinderclient instance
|
||||
"""
|
||||
self.cinder = cinder_client(self.volume_version, session=self.sess,
|
||||
**self.client_kwargs)
|
||||
self.cinder = cinder_client.Client(self.volume_version,
|
||||
session=self.sess,
|
||||
**self.client_kwargs)
|
||||
return self.cinder
|
||||
|
||||
def create_swift(self):
|
||||
|
|
|
@ -15,15 +15,16 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
|
||||
"""
|
||||
import six
|
||||
|
||||
from distutils import spawn
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from distutils import spawn
|
||||
from apscheduler.schedulers import background
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import six
|
||||
|
||||
from freezer.apiclient import client
|
||||
from freezer.scheduler import arguments
|
||||
|
@ -32,7 +33,6 @@ from freezer.scheduler import shell
|
|||
from freezer.scheduler import utils
|
||||
from freezer.utils import winutils
|
||||
|
||||
|
||||
if winutils.is_windows():
|
||||
from win_daemon import Daemon
|
||||
from win_daemon import NoDaemon
|
||||
|
@ -67,8 +67,10 @@ class FreezerScheduler(object):
|
|||
'default': {'type': 'threadpool', 'max_workers': 1},
|
||||
'threadpool': {'type': 'threadpool', 'max_workers': 10}
|
||||
}
|
||||
self.scheduler = BackgroundScheduler(job_defaults=job_defaults,
|
||||
executors=executors)
|
||||
self.scheduler = background.BackgroundScheduler(
|
||||
job_defaults=job_defaults,
|
||||
executors=executors)
|
||||
|
||||
if self.client:
|
||||
self.scheduler.add_job(self.poll, 'interval',
|
||||
seconds=interval, id='api_poll',
|
||||
|
|
|
@ -18,21 +18,19 @@ limitations under the License.
|
|||
|
||||
import json
|
||||
import os
|
||||
|
||||
import prettytable
|
||||
import six
|
||||
|
||||
from freezer.utils import utils as freezer_utils
|
||||
import utils
|
||||
|
||||
from freezer.utils.utils import DateTime
|
||||
|
||||
from prettytable import PrettyTable
|
||||
|
||||
try:
|
||||
from betterprint import pprint
|
||||
except Exception:
|
||||
def pprint(doc):
|
||||
print(json.dumps(doc, indent=4))
|
||||
|
||||
from freezer.utils import utils as freezer_utils
|
||||
|
||||
|
||||
def do_session_remove_job(client, args):
|
||||
"""
|
||||
|
@ -70,7 +68,8 @@ def do_session_list_job(client, args):
|
|||
raise Exception("Parameter --session required")
|
||||
session_doc = client.sessions.get(args.session_id)
|
||||
jobs = session_doc.get('jobs', {})
|
||||
table = PrettyTable(["job_id", "status", "result", "client_id"])
|
||||
table = prettytable.PrettyTable(["job_id", "status", "result",
|
||||
"client_id"])
|
||||
for job_id, job_data in six.iteritems(jobs):
|
||||
table.add_row([job_id,
|
||||
job_data['status'],
|
||||
|
@ -120,8 +119,8 @@ def do_session_list(client, args):
|
|||
|
||||
:return: None
|
||||
"""
|
||||
table = PrettyTable(["session_id", "tag", "status",
|
||||
"description", "jobs", "last_start"])
|
||||
table = prettytable.PrettyTable(["session_id", "tag", "status",
|
||||
"description", "jobs", "last_start"])
|
||||
session_docs = client.sessions.list()
|
||||
offset = 0
|
||||
while session_docs:
|
||||
|
@ -208,8 +207,9 @@ def _job_list(client, args):
|
|||
|
||||
|
||||
def do_job_list(client, args):
|
||||
table = PrettyTable(["job_id", "client-id", "description", "# actions",
|
||||
"status", "event", "result", "session_id"])
|
||||
table = prettytable.PrettyTable(["job_id", "client-id", "description",
|
||||
"# actions", "status", "event",
|
||||
"result", "session_id"])
|
||||
for doc in _job_list(client, args):
|
||||
job_scheduling = doc.get('job_schedule', {})
|
||||
job_status = job_scheduling.get('status', '')
|
||||
|
@ -227,7 +227,7 @@ def do_job_list(client, args):
|
|||
|
||||
|
||||
def do_client_list(client, args):
|
||||
table = PrettyTable(["client_id", "hostname", "description"])
|
||||
table = prettytable.PrettyTable(["client_id", "hostname", "description"])
|
||||
l = client.registration.list()
|
||||
offset = 0
|
||||
while l:
|
||||
|
@ -249,7 +249,7 @@ def do_backup_list(client, args):
|
|||
else:
|
||||
fields = ["backup uuid", "container", "backup name", "timestamp",
|
||||
"level", "path"]
|
||||
table = PrettyTable(fields)
|
||||
table = prettytable.PrettyTable(fields)
|
||||
l = list_func()
|
||||
offset = 0
|
||||
while l:
|
||||
|
@ -264,14 +264,14 @@ def do_backup_list(client, args):
|
|||
metadata_doc.get('container', ''),
|
||||
metadata_doc.get('hostname', ''),
|
||||
metadata_doc.get('backup_name', ''),
|
||||
str(DateTime(timestamp)),
|
||||
str(freezer_utils.DateTime(timestamp)),
|
||||
metadata_doc.get('curr_backup_level', ''),
|
||||
metadata_doc.get('fs_real_path', '')]
|
||||
else:
|
||||
row = [doc['backup_uuid'],
|
||||
metadata_doc.get('container', ''),
|
||||
metadata_doc.get('backup_name', ''),
|
||||
str(DateTime(timestamp)),
|
||||
str(freezer_utils.DateTime(timestamp)),
|
||||
metadata_doc.get('curr_backup_level', ''),
|
||||
metadata_doc.get('fs_real_path', '')]
|
||||
table.add_row(row)
|
||||
|
|
|
@ -12,13 +12,12 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo_log import log
|
||||
# PyCharm will not recognize queue. Puts red squiggle line under it. That's OK.
|
||||
from six.moves import queue
|
||||
|
||||
from oslo_log import log
|
||||
|
||||
from freezer.storage import base
|
||||
from freezer.storage.exceptions import StorageException
|
||||
from freezer.storage import exceptions
|
||||
from freezer.utils import streaming
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
@ -62,7 +61,8 @@ class MultipleStorage(base.Storage):
|
|||
got_exception)
|
||||
|
||||
if (got_exception):
|
||||
raise StorageException("Storage error. Failed to backup.")
|
||||
raise exceptions.StorageException(
|
||||
"Storage error. Failed to backup.")
|
||||
|
||||
def get_level_zero(self,
|
||||
engine,
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
import hashlib
|
||||
import os
|
||||
|
||||
from six.moves import StringIO
|
||||
from six import PY2 # True if running on Python 2
|
||||
import six
|
||||
from six import moves
|
||||
|
||||
from freezer.utils import utils
|
||||
|
||||
|
@ -119,7 +119,7 @@ class CheckSum(object):
|
|||
# Need to use string-escape for Python 2 non-unicode strings. For
|
||||
# Python 2 unicode strings and all Python 3 strings, we need to use
|
||||
# unicode-escape. The effect of them is the same.
|
||||
if PY2 and isinstance(buf, str):
|
||||
if six.PY2 and isinstance(buf, str):
|
||||
buf = buf.encode('string-escape')
|
||||
else:
|
||||
buf = buf.encode('unicode-escape')
|
||||
|
@ -132,7 +132,7 @@ class CheckSum(object):
|
|||
"""
|
||||
:return: the hash for a given string
|
||||
"""
|
||||
fd = StringIO(string)
|
||||
fd = moves.StringIO(string)
|
||||
return self.hashfile(fd)
|
||||
|
||||
def compute(self):
|
||||
|
|
Loading…
Reference in New Issue