Improve logging
This patch resolve following issues. - Debug logs had not been enough. - Error messages of update/delete operations had not been clearly. Change-Id: I988a6f35c5308ca5eab5cc537ee5334ada0cea2c Closes-Bug: #1656185
This commit is contained in:
parent
82cab8ee35
commit
fc32cb2dfc
|
@ -12,14 +12,19 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from openstack import exceptions as sdk_exc
|
from openstack import exceptions as sdk_exc
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
|
from osc_lib import exceptions
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
|
||||||
from masakariclient.common.i18n import _
|
from masakariclient.common.i18n import _
|
||||||
import masakariclient.common.utils as masakariclient_utils
|
import masakariclient.common.utils as masakariclient_utils
|
||||||
|
|
||||||
|
# Get the logger of this module
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ListHost(command.Lister):
|
class ListHost(command.Lister):
|
||||||
"""List Hosts."""
|
"""List Hosts."""
|
||||||
|
@ -152,8 +157,13 @@ class CreateHost(command.ShowOne):
|
||||||
# Remove not specified keys
|
# Remove not specified keys
|
||||||
attrs = masakariclient_utils.remove_unspecified_items(attrs)
|
attrs = masakariclient_utils.remove_unspecified_items(attrs)
|
||||||
|
|
||||||
host = masakari_client.create_host(segment_id=parsed_args.segment_id,
|
try:
|
||||||
**attrs)
|
host = masakari_client.create_host(
|
||||||
|
segment_id=parsed_args.segment_id,
|
||||||
|
**attrs)
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.debug(_("Failed to create segment host: %s"), parsed_args)
|
||||||
|
raise ex
|
||||||
return _show_host(masakari_client,
|
return _show_host(masakari_client,
|
||||||
parsed_args.segment_id,
|
parsed_args.segment_id,
|
||||||
host.uuid)
|
host.uuid)
|
||||||
|
@ -222,8 +232,12 @@ class UpdateHost(command.ShowOne):
|
||||||
segment_id=parsed_args.segment_id, host=uuid, **attrs)
|
segment_id=parsed_args.segment_id, host=uuid, **attrs)
|
||||||
except sdk_exc.NotFoundException:
|
except sdk_exc.NotFoundException:
|
||||||
# Reraise. To unify exceptions with other functions.
|
# Reraise. To unify exceptions with other functions.
|
||||||
|
LOG.debug(_("Segment host is not found: %s"), parsed_args)
|
||||||
raise sdk_exc.ResourceNotFound(
|
raise sdk_exc.ResourceNotFound(
|
||||||
_('No Host found for %s') % uuid)
|
_('No Host found for %s') % uuid)
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.debug(_("Failed to update segment host: %s"), parsed_args)
|
||||||
|
raise ex
|
||||||
|
|
||||||
return _show_host(masakari_client, parsed_args.segment_id, uuid)
|
return _show_host(masakari_client, parsed_args.segment_id, uuid)
|
||||||
|
|
||||||
|
@ -257,7 +271,11 @@ class DeleteHost(command.ShowOne):
|
||||||
|
|
||||||
|
|
||||||
def _show_host(masakari_client, segment_id, uuid):
|
def _show_host(masakari_client, segment_id, uuid):
|
||||||
host = masakari_client.get_host(segment_id, uuid)
|
try:
|
||||||
|
host = masakari_client.get_host(segment_id, uuid)
|
||||||
|
except sdk_exc.ResourceNotFound:
|
||||||
|
raise exceptions.CommandError(_('Segment host is not found: %s'
|
||||||
|
) % uuid)
|
||||||
|
|
||||||
formatters = {}
|
formatters = {}
|
||||||
columns = [
|
columns = [
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
from openstack import exceptions as sdk_exc
|
from openstack import exceptions as sdk_exc
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
|
|
|
@ -12,13 +12,19 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from openstack import exceptions as sdk_exc
|
from openstack import exceptions as sdk_exc
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
|
from osc_lib import exceptions
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
|
||||||
from masakariclient.common.i18n import _
|
from masakariclient.common.i18n import _
|
||||||
import masakariclient.common.utils as masakariclient_utils
|
import masakariclient.common.utils as masakariclient_utils
|
||||||
|
|
||||||
|
# Get the logger of this module
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ListSegment(command.Lister):
|
class ListSegment(command.Lister):
|
||||||
"""List segments."""
|
"""List segments."""
|
||||||
|
@ -128,7 +134,11 @@ class CreateSegment(command.ShowOne):
|
||||||
# Remove not specified keys
|
# Remove not specified keys
|
||||||
attrs = masakariclient_utils.remove_unspecified_items(attrs)
|
attrs = masakariclient_utils.remove_unspecified_items(attrs)
|
||||||
|
|
||||||
segment = masakari_client.create_segment(**attrs)
|
try:
|
||||||
|
segment = masakari_client.create_segment(**attrs)
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.debug(_("Failed to create segment: %s"), parsed_args)
|
||||||
|
raise ex
|
||||||
return _show_segment(masakari_client,
|
return _show_segment(masakari_client,
|
||||||
segment.uuid)
|
segment.uuid)
|
||||||
|
|
||||||
|
@ -184,8 +194,12 @@ class UpdateSegment(command.ShowOne):
|
||||||
masakari_client.update_segment(segment=uuid, **attrs)
|
masakari_client.update_segment(segment=uuid, **attrs)
|
||||||
# Reraise. To unify exceptions with other functions.
|
# Reraise. To unify exceptions with other functions.
|
||||||
except sdk_exc.NotFoundException:
|
except sdk_exc.NotFoundException:
|
||||||
|
LOG.debug(_("Segment is not found: %s"), parsed_args)
|
||||||
raise sdk_exc.ResourceNotFound(
|
raise sdk_exc.ResourceNotFound(
|
||||||
_('No Segment found for %s') % uuid)
|
_('No Segment found for %s') % uuid)
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.debug(_("Failed to update segment: %s"), parsed_args)
|
||||||
|
raise ex
|
||||||
return _show_segment(masakari_client, uuid)
|
return _show_segment(masakari_client, uuid)
|
||||||
|
|
||||||
|
|
||||||
|
@ -215,8 +229,11 @@ class DeleteSegment(command.Command):
|
||||||
|
|
||||||
|
|
||||||
def _show_segment(masakari_client, segment_uuid):
|
def _show_segment(masakari_client, segment_uuid):
|
||||||
|
try:
|
||||||
segment = masakari_client.get_segment(segment_uuid)
|
segment = masakari_client.get_segment(segment_uuid)
|
||||||
|
except sdk_exc.ResourceNotFound:
|
||||||
|
raise exceptions.CommandError(_('Segment is not found: %s'
|
||||||
|
) % segment_uuid)
|
||||||
|
|
||||||
formatters = {}
|
formatters = {}
|
||||||
columns = [
|
columns = [
|
||||||
|
|
|
@ -43,7 +43,7 @@ def make_client(instance):
|
||||||
cert=instance.session.cert,
|
cert=instance.session.cert,
|
||||||
profile=prof)
|
profile=prof)
|
||||||
LOG.debug('Connection: %s', conn)
|
LOG.debug('Connection: %s', conn)
|
||||||
LOG.debug('masakari client initialized: %s', conn.ha)
|
LOG.debug('masakari client initialized using OpenStack SDK: %s', conn.ha)
|
||||||
return conn.ha
|
return conn.ha
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,15 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from openstack import connection
|
from openstack import connection
|
||||||
from openstack import profile
|
from openstack import profile
|
||||||
|
|
||||||
from masakariclient.sdk.ha import ha_service
|
from masakariclient.sdk.ha import ha_service
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def create_connection(prof=None, user_agent=None, **kwargs):
|
def create_connection(prof=None, user_agent=None, **kwargs):
|
||||||
"""Create connection to masakari_api."""
|
"""Create connection to masakari_api."""
|
||||||
|
@ -35,8 +39,11 @@ def create_connection(prof=None, user_agent=None, **kwargs):
|
||||||
prof.set_api_version('ha', '1')
|
prof.set_api_version('ha', '1')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = connection.Connection(profile=prof, user_agent=user_agent,
|
conn = connection.Connection(profile=prof,
|
||||||
|
user_agent=user_agent,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
LOG.debug('Connection: %s', conn)
|
||||||
|
LOG.debug('masakari client initialized: %s', conn.ha)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue