Merge "Standardize logger usage in volume"
This commit is contained in:
commit
968d8bb662
@ -14,6 +14,7 @@
|
||||
#
|
||||
|
||||
import copy
|
||||
import mock
|
||||
|
||||
from openstackclient.tests import fakes
|
||||
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
|
||||
@ -656,7 +657,8 @@ class TestVolumeSet(TestVolume):
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_volume_set_size_smaller(self):
|
||||
@mock.patch.object(volume.LOG, 'error')
|
||||
def test_volume_set_size_smaller(self, mock_log_error):
|
||||
arglist = [
|
||||
'--size', '100',
|
||||
volume_fakes.volume_name,
|
||||
@ -672,12 +674,13 @@ class TestVolumeSet(TestVolume):
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertEqual("New size must be greater than %s GB" %
|
||||
volume_fakes.volume_size,
|
||||
self.app.log.messages.get('error'))
|
||||
mock_log_error.assert_called_with("New size must be greater "
|
||||
"than %s GB",
|
||||
volume_fakes.volume_size)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_volume_set_size_not_available(self):
|
||||
@mock.patch.object(volume.LOG, 'error')
|
||||
def test_volume_set_size_not_available(self, mock_log_error):
|
||||
self.volumes_mock.get.return_value.status = 'error'
|
||||
arglist = [
|
||||
'--size', '130',
|
||||
@ -694,9 +697,9 @@ class TestVolumeSet(TestVolume):
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertEqual("Volume is in %s state, it must be available before "
|
||||
"size can be extended" % 'error',
|
||||
self.app.log.messages.get('error'))
|
||||
mock_log_error.assert_called_with("Volume is in %s state, it must be "
|
||||
"available before size can be "
|
||||
"extended", 'error')
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_volume_set_property(self):
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""Volume v1 Volume action implementations"""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
from osc_lib.cli import parseractions
|
||||
from osc_lib.command import command
|
||||
@ -25,6 +26,9 @@ import six
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CreateVolume(command.ShowOne):
|
||||
"""Create new volume"""
|
||||
|
||||
@ -343,13 +347,12 @@ class SetVolume(command.Command):
|
||||
|
||||
if parsed_args.size:
|
||||
if volume.status != 'available':
|
||||
self.app.log.error(_("Volume is in %s state, it must be "
|
||||
"available before size can be extended") %
|
||||
volume.status)
|
||||
LOG.error(_("Volume is in %s state, it must be available "
|
||||
"before size can be extended"), volume.status)
|
||||
return
|
||||
if parsed_args.size <= volume.size:
|
||||
self.app.log.error(_("New size must be greater than %s GB") %
|
||||
volume.size)
|
||||
LOG.error(_("New size must be greater than %s GB"),
|
||||
volume.size)
|
||||
return
|
||||
volume_client.volumes.extend(volume.id, parsed_args.size)
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
"""Volume V2 Volume action implementations"""
|
||||
|
||||
import copy
|
||||
import logging
|
||||
|
||||
from osc_lib.cli import parseractions
|
||||
from osc_lib.command import command
|
||||
@ -25,6 +26,9 @@ from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CreateVolume(command.ShowOne):
|
||||
"""Create new volume"""
|
||||
|
||||
@ -361,13 +365,12 @@ class SetVolume(command.Command):
|
||||
|
||||
if parsed_args.size:
|
||||
if volume.status != 'available':
|
||||
self.app.log.error(_("Volume is in %s state, it must be "
|
||||
"available before size can be extended") %
|
||||
volume.status)
|
||||
LOG.error(_("Volume is in %s state, it must be available "
|
||||
"before size can be extended"), volume.status)
|
||||
return
|
||||
if parsed_args.size <= volume.size:
|
||||
self.app.log.error(_("New size must be greater than %s GB") %
|
||||
volume.size)
|
||||
LOG.error(_("New size must be greater than %s GB"),
|
||||
volume.size)
|
||||
return
|
||||
volume_client.volumes.extend(volume.id, parsed_args.size)
|
||||
|
||||
@ -456,4 +459,4 @@ class UnsetVolume(command.Command):
|
||||
volume.id, parsed_args.image_property)
|
||||
|
||||
if (not parsed_args.image_property and not parsed_args.property):
|
||||
self.app.log.error(_("No changes requested\n"))
|
||||
LOG.error(_("No changes requested"))
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
"""Volume v2 Type action implementations"""
|
||||
|
||||
import logging
|
||||
|
||||
from osc_lib.cli import parseractions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
@ -24,6 +26,9 @@ from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CreateVolumeType(command.ShowOne):
|
||||
"""Create new volume type"""
|
||||
|
||||
@ -190,16 +195,15 @@ class SetVolumeType(command.Command):
|
||||
**kwargs
|
||||
)
|
||||
except Exception as e:
|
||||
self.app.log.error(_("Failed to update volume type name or"
|
||||
" description: %s") % str(e))
|
||||
LOG.error(_("Failed to update volume type name or"
|
||||
" description: %s"), e)
|
||||
result += 1
|
||||
|
||||
if parsed_args.property:
|
||||
try:
|
||||
volume_type.set_keys(parsed_args.property)
|
||||
except Exception as e:
|
||||
self.app.log.error(_("Failed to set volume type"
|
||||
" property: %s") % str(e))
|
||||
LOG.error(_("Failed to set volume type property: %s"), e)
|
||||
result += 1
|
||||
|
||||
if parsed_args.project:
|
||||
@ -213,13 +217,13 @@ class SetVolumeType(command.Command):
|
||||
volume_client.volume_type_access.add_project_access(
|
||||
volume_type.id, project_info.id)
|
||||
except Exception as e:
|
||||
self.app.log.error(_("Failed to set volume type access to"
|
||||
" project: %s") % str(e))
|
||||
LOG.error(_("Failed to set volume type access to "
|
||||
"project: %s"), e)
|
||||
result += 1
|
||||
|
||||
if result > 0:
|
||||
raise exceptions.CommandError(_("Command Failed: One or more of"
|
||||
" the operations failed"))
|
||||
" the operations failed"))
|
||||
|
||||
|
||||
class ShowVolumeType(command.ShowOne):
|
||||
@ -284,8 +288,7 @@ class UnsetVolumeType(command.Command):
|
||||
try:
|
||||
volume_type.unset_keys(parsed_args.property)
|
||||
except Exception as e:
|
||||
self.app.log.error(_("Failed to unset volume type property: %s"
|
||||
) % str(e))
|
||||
LOG.error(_("Failed to unset volume type property: %s"), e)
|
||||
result += 1
|
||||
|
||||
if parsed_args.project:
|
||||
@ -299,8 +302,8 @@ class UnsetVolumeType(command.Command):
|
||||
volume_client.volume_type_access.remove_project_access(
|
||||
volume_type.id, project_info.id)
|
||||
except Exception as e:
|
||||
self.app.log.error(_("Failed to remove volume type access from"
|
||||
" project: %s") % str(e))
|
||||
LOG.error(_("Failed to remove volume type access from "
|
||||
"project: %s"), e)
|
||||
result += 1
|
||||
|
||||
if result > 0:
|
||||
|
Loading…
Reference in New Issue
Block a user