diff --git a/cinder/image/image_utils.py b/cinder/image/image_utils.py index cb637b995..a11549674 100644 --- a/cinder/image/image_utils.py +++ b/cinder/image/image_utils.py @@ -34,12 +34,12 @@ from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log as logging from oslo_utils import fileutils +from oslo_utils import imageutils from oslo_utils import timeutils from oslo_utils import units from cinder import exception from cinder.i18n import _, _LI, _LW -from cinder.openstack.common import imageutils from cinder import utils from cinder.volume import throttling from cinder.volume import utils as volume_utils diff --git a/cinder/openstack/__init__.py b/cinder/openstack/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/cinder/openstack/common/README b/cinder/openstack/common/README deleted file mode 100644 index 04a616648..000000000 --- a/cinder/openstack/common/README +++ /dev/null @@ -1,16 +0,0 @@ -oslo-incubator --------------- - -A number of modules from oslo-incubator are imported into this project. -You can clone the oslo-incubator repository using the following url: - - git://git.openstack.org/openstack/oslo-incubator - -These modules are "incubating" in oslo-incubator and are kept in sync -with the help of oslo-incubator's update.py script. See: - - https://wiki.openstack.org/wiki/Oslo#Syncing_Code_from_Incubator - -The copy of the code should never be directly modified here. Please -always update oslo-incubator first and then run the script to copy -the changes across. diff --git a/cinder/openstack/common/__init__.py b/cinder/openstack/common/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/cinder/openstack/common/_i18n.py b/cinder/openstack/common/_i18n.py deleted file mode 100644 index 46eb21446..000000000 --- a/cinder/openstack/common/_i18n.py +++ /dev/null @@ -1,45 +0,0 @@ -# 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. - -"""oslo.i18n integration module. - -See http://docs.openstack.org/developer/oslo.i18n/usage.html - -""" - -try: - import oslo_i18n - - # NOTE(dhellmann): This reference to o-s-l-o will be replaced by the - # application name when this module is synced into the separate - # repository. It is OK to have more than one translation function - # using the same domain, since there will still only be one message - # catalog. - _translators = oslo_i18n.TranslatorFactory(domain='cinder') - - # The primary translation function using the well-known name "_" - _ = _translators.primary - - # Translators for log levels. - # - # The abbreviated names are meant to reflect the usual use of a short - # name like '_'. The "L" is for "log" and the other letter comes from - # the level. - _LI = _translators.log_info - _LW = _translators.log_warning - _LE = _translators.log_error - _LC = _translators.log_critical -except ImportError: - # NOTE(dims): Support for cases where a project wants to use - # code from oslo-incubator, but is not ready to be internationalized - # (like tempest) - _ = _LI = _LW = _LE = _LC = lambda x: x diff --git a/cinder/openstack/common/imageutils.py b/cinder/openstack/common/imageutils.py deleted file mode 100644 index c41d896e8..000000000 --- a/cinder/openstack/common/imageutils.py +++ /dev/null @@ -1,152 +0,0 @@ -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -# Copyright (c) 2010 Citrix Systems, Inc. -# -# 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. - -""" -Helper methods to deal with images. -""" - -import re - -from oslo_utils import strutils - -from cinder.openstack.common._i18n import _ - - -class QemuImgInfo(object): - BACKING_FILE_RE = re.compile((r"^(.*?)\s*\(actual\s+path\s*:" - r"\s+(.*?)\)\s*$"), re.I) - TOP_LEVEL_RE = re.compile(r"^([\w\d\s\_\-]+):(.*)$") - SIZE_RE = re.compile(r"(\d*\.?\d+)(\w+)?(\s*\(\s*(\d+)\s+bytes\s*\))?", - re.I) - - def __init__(self, cmd_output=None): - details = self._parse(cmd_output or '') - self.image = details.get('image') - self.backing_file = details.get('backing_file') - self.file_format = details.get('file_format') - self.virtual_size = details.get('virtual_size') - self.cluster_size = details.get('cluster_size') - self.disk_size = details.get('disk_size') - self.snapshots = details.get('snapshot_list', []) - self.encrypted = details.get('encrypted') - - def __str__(self): - lines = [ - 'image: %s' % self.image, - 'file_format: %s' % self.file_format, - 'virtual_size: %s' % self.virtual_size, - 'disk_size: %s' % self.disk_size, - 'cluster_size: %s' % self.cluster_size, - 'backing_file: %s' % self.backing_file, - ] - if self.snapshots: - lines.append("snapshots: %s" % self.snapshots) - if self.encrypted: - lines.append("encrypted: %s" % self.encrypted) - return "\n".join(lines) - - def _canonicalize(self, field): - # Standardize on underscores/lc/no dash and no spaces - # since qemu seems to have mixed outputs here... and - # this format allows for better integration with python - # - i.e. for usage in kwargs and such... - field = field.lower().strip() - for c in (" ", "-"): - field = field.replace(c, '_') - return field - - def _extract_bytes(self, details): - # Replace it with the byte amount - real_size = self.SIZE_RE.search(details) - if not real_size: - raise ValueError(_('Invalid input value "%s".') % details) - magnitude = real_size.group(1) - unit_of_measure = real_size.group(2) - bytes_info = real_size.group(3) - if bytes_info: - return int(real_size.group(4)) - elif not unit_of_measure: - return int(magnitude) - return strutils.string_to_bytes('%s%sB' % (magnitude, unit_of_measure), - return_int=True) - - def _extract_details(self, root_cmd, root_details, lines_after): - real_details = root_details - if root_cmd == 'backing_file': - # Replace it with the real backing file - backing_match = self.BACKING_FILE_RE.match(root_details) - if backing_match: - real_details = backing_match.group(2).strip() - elif root_cmd in ['virtual_size', 'cluster_size', 'disk_size']: - # Replace it with the byte amount (if we can convert it) - if root_details in ('None', 'unavailable'): - real_details = 0 - else: - real_details = self._extract_bytes(root_details) - elif root_cmd == 'file_format': - real_details = real_details.strip().lower() - elif root_cmd == 'snapshot_list': - # Next line should be a header, starting with 'ID' - if not lines_after or not lines_after.pop(0).startswith("ID"): - msg = _("Snapshot list encountered but no header found!") - raise ValueError(msg) - real_details = [] - # This is the sprintf pattern we will try to match - # "%-10s%-20s%7s%20s%15s" - # ID TAG VM SIZE DATE VM CLOCK (current header) - while lines_after: - line = lines_after[0] - line_pieces = line.split() - if len(line_pieces) != 6: - break - # Check against this pattern in the final position - # "%02d:%02d:%02d.%03d" - date_pieces = line_pieces[5].split(":") - if len(date_pieces) != 3: - break - lines_after.pop(0) - real_details.append({ - 'id': line_pieces[0], - 'tag': line_pieces[1], - 'vm_size': line_pieces[2], - 'date': line_pieces[3], - 'vm_clock': line_pieces[4] + " " + line_pieces[5], - }) - return real_details - - def _parse(self, cmd_output): - # Analysis done of qemu-img.c to figure out what is going on here - # Find all points start with some chars and then a ':' then a newline - # and then handle the results of those 'top level' items in a separate - # function. - # - # TODO(harlowja): newer versions might have a json output format - # we should switch to that whenever possible. - # see: http://bit.ly/XLJXDX - contents = {} - lines = [x for x in cmd_output.splitlines() if x.strip()] - while lines: - line = lines.pop(0) - top_level = self.TOP_LEVEL_RE.match(line) - if top_level: - root = self._canonicalize(top_level.group(1)) - if not root: - continue - root_details = top_level.group(2).strip() - details = self._extract_details(root, root_details, lines) - contents[root] = details - return contents diff --git a/cinder/scheduler/base_filter.py b/cinder/scheduler/base_filter.py index c0351daa5..92f1b5c00 100644 --- a/cinder/scheduler/base_filter.py +++ b/cinder/scheduler/base_filter.py @@ -18,7 +18,7 @@ Filter support """ from oslo_log import log as logging -from cinder.openstack.common._i18n import _LI +from cinder.i18n import _LI from cinder.scheduler import base_handler LOG = logging.getLogger(__name__) diff --git a/cinder/tests/unit/test_glusterfs.py b/cinder/tests/unit/test_glusterfs.py index 8d6da6840..8f11757f6 100644 --- a/cinder/tests/unit/test_glusterfs.py +++ b/cinder/tests/unit/test_glusterfs.py @@ -25,6 +25,7 @@ import mock import os_brick from oslo_concurrency import processutils as putils from oslo_config import cfg +from oslo_utils import imageutils from oslo_utils import units from cinder import compute @@ -33,7 +34,6 @@ from cinder import db from cinder import exception from cinder.i18n import _ from cinder.image import image_utils -from cinder.openstack.common import imageutils from cinder import test from cinder import utils from cinder.volume import driver as base_driver diff --git a/cinder/tests/unit/test_image_utils.py b/cinder/tests/unit/test_image_utils.py index 492ebc85f..18b6334e7 100644 --- a/cinder/tests/unit/test_image_utils.py +++ b/cinder/tests/unit/test_image_utils.py @@ -28,7 +28,7 @@ from cinder.volume import throttling class TestQemuImgInfo(test.TestCase): - @mock.patch('cinder.openstack.common.imageutils.QemuImgInfo') + @mock.patch('oslo_utils.imageutils.QemuImgInfo') @mock.patch('cinder.utils.execute') def test_qemu_img_info(self, mock_exec, mock_info): mock_out = mock.sentinel.out @@ -41,7 +41,7 @@ class TestQemuImgInfo(test.TestCase): 'info', test_path, run_as_root=True) self.assertEqual(mock_info.return_value, output) - @mock.patch('cinder.openstack.common.imageutils.QemuImgInfo') + @mock.patch('oslo_utils.imageutils.QemuImgInfo') @mock.patch('cinder.utils.execute') def test_qemu_img_info_not_root(self, mock_exec, mock_info): mock_out = mock.sentinel.out @@ -55,7 +55,7 @@ class TestQemuImgInfo(test.TestCase): self.assertEqual(mock_info.return_value, output) @mock.patch('cinder.image.image_utils.os') - @mock.patch('cinder.openstack.common.imageutils.QemuImgInfo') + @mock.patch('oslo_utils.imageutils.QemuImgInfo') @mock.patch('cinder.utils.execute') def test_qemu_img_info_on_nt(self, mock_exec, mock_info, mock_os): mock_out = mock.sentinel.out diff --git a/cinder/tests/unit/test_quobyte.py b/cinder/tests/unit/test_quobyte.py index 16afbbd94..c35880471 100644 --- a/cinder/tests/unit/test_quobyte.py +++ b/cinder/tests/unit/test_quobyte.py @@ -23,12 +23,12 @@ import traceback import mock from oslo_concurrency import processutils as putils from oslo_config import cfg +from oslo_utils import imageutils from oslo_utils import units from cinder import context from cinder import exception from cinder.image import image_utils -from cinder.openstack.common import imageutils from cinder import test from cinder.volume import configuration as conf from cinder.volume.drivers import quobyte diff --git a/cinder/tests/unit/test_scality.py b/cinder/tests/unit/test_scality.py index 59787d755..198823031 100644 --- a/cinder/tests/unit/test_scality.py +++ b/cinder/tests/unit/test_scality.py @@ -20,11 +20,11 @@ import errno import os import mock +from oslo_utils import imageutils from six.moves import urllib from cinder import context from cinder import exception -from cinder.openstack.common import imageutils from cinder import test from cinder.volume import configuration as conf import cinder.volume.drivers.scality as driver diff --git a/cinder/tests/unit/volume/flows/test_create_volume_flow.py b/cinder/tests/unit/volume/flows/test_create_volume_flow.py index 93461ce0c..7f6cc0375 100644 --- a/cinder/tests/unit/volume/flows/test_create_volume_flow.py +++ b/cinder/tests/unit/volume/flows/test_create_volume_flow.py @@ -17,9 +17,10 @@ import ddt import mock +from oslo_utils import imageutils + from cinder import context from cinder import exception -from cinder.openstack.common import imageutils from cinder import test from cinder.tests.unit import fake_consistencygroup from cinder.tests.unit import fake_snapshot diff --git a/openstack-common.conf b/openstack-common.conf deleted file mode 100644 index 4c4d23365..000000000 --- a/openstack-common.conf +++ /dev/null @@ -1,7 +0,0 @@ -[DEFAULT] - -# The list of modules to copy from oslo-incubator -module=imageutils - -# The base module to hold the copy of openstack.common -base=cinder diff --git a/run_tests.sh b/run_tests.sh index db32c57eb..6b308a32f 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -160,7 +160,7 @@ function run_tests { echo "Generating coverage report in covhtml/" # Don't compute coverage for common code, which is tested elsewhere ${wrapper} coverage combine - ${wrapper} coverage html --include='cinder/*' --omit='cinder/openstack/common/*' -d covhtml -i + ${wrapper} coverage html --include='cinder/*' -d covhtml -i fi return $RESULT diff --git a/tools/lintstack.py b/tools/lintstack.py index 1901169fa..065743e7f 100755 --- a/tools/lintstack.py +++ b/tools/lintstack.py @@ -45,10 +45,9 @@ ignore_messages = ["An attribute affected in cinder.tests", "Module 'hashlib' has no 'sha256' member", "Module 'hashlib' has no 'sha224' member", "Instance of 'Table' has no 'rename' member"] -# Note(maoy): we ignore all errors in openstack.common because it should be -# checked elsewhere. We also ignore cinder.tests for now due to high false +# Note(maoy): We ignore cinder.tests for now due to high false # positive rate. -ignore_modules = ["cinder/openstack/common/", "cinder/tests/"] +ignore_modules = ["cinder/tests/"] # Note(thangp): E0213, E1101, and E1102 should be ignored for only # cinder.object modules. E0213 and E1102 are error codes related to