From 80fcf24d02cb16022f84edbd190bcb85a205f784 Mon Sep 17 00:00:00 2001 From: Rajiv Kumar Date: Sat, 14 Jan 2017 16:54:29 +0530 Subject: [PATCH] Switch to oslo_log vmware-nsx is currently using python logging module to implement logging functionality. This patch made a switch to oslo.log(logging for openstack projects) Reference:- http://docs.openstack.org/developer/oslo.log Change-Id: Ibdb4f6ea0abc56cb98bdc57547bc3b4370f9875b --- vmware_nsx/common/config.py | 3 +-- vmware_nsx/osc/plugin.py | 3 +-- vmware_nsx/shell/__init__.py | 17 ++++++++++++++--- .../shell/admin/plugins/common/formatters.py | 3 +-- vmware_nsx/shell/admin/plugins/common/utils.py | 2 +- .../plugins/nsxv/resources/backup_edges.py | 3 +-- .../plugins/nsxv/resources/dhcp_binding.py | 2 +- .../shell/admin/plugins/nsxv/resources/edges.py | 2 +- .../admin/plugins/nsxv/resources/metadata.py | 2 +- .../admin/plugins/nsxv/resources/networks.py | 2 +- .../admin/plugins/nsxv/resources/routers.py | 3 +-- .../plugins/nsxv/resources/securitygroups.py | 2 +- .../plugins/nsxv/resources/spoofguard_policy.py | 5 ++--- .../plugins/nsxv3/resources/dhcp_binding.py | 2 +- .../plugins/nsxv3/resources/dhcp_servers.py | 3 +-- .../plugins/nsxv3/resources/metadata_proxy.py | 3 +-- .../admin/plugins/nsxv3/resources/networks.py | 3 +-- .../admin/plugins/nsxv3/resources/ports.py | 3 +-- .../admin/plugins/nsxv3/resources/routers.py | 3 +-- .../plugins/nsxv3/resources/securitygroups.py | 3 +-- vmware_nsx/shell/nsxadmin.py | 2 +- vmware_nsx/shell/resources.py | 2 +- vmware_nsx/tests/unit/shell/test_admin_utils.py | 2 +- 23 files changed, 37 insertions(+), 38 deletions(-) diff --git a/vmware_nsx/common/config.py b/vmware_nsx/common/config.py index f8028746d6..df06361605 100644 --- a/vmware_nsx/common/config.py +++ b/vmware_nsx/common/config.py @@ -12,10 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg from oslo_config import types +from oslo_log import log as logging from neutron.db import l3_hamode_db diff --git a/vmware_nsx/osc/plugin.py b/vmware_nsx/osc/plugin.py index 64d29af03c..972a83531f 100644 --- a/vmware_nsx/osc/plugin.py +++ b/vmware_nsx/osc/plugin.py @@ -14,9 +14,8 @@ # under the License. -import logging - from osc_lib import utils +from oslo_log import log as logging LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/shell/__init__.py b/vmware_nsx/shell/__init__.py index 6146996a7e..7cfe483093 100644 --- a/vmware_nsx/shell/__init__.py +++ b/vmware_nsx/shell/__init__.py @@ -13,14 +13,25 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import logging import sys from neutronclient import shell +from oslo_config import cfg +from oslo_log import log as logging + from vmware_nsx.shell import commands as cmd -logging.basicConfig(format='%(message)s', level=logging.INFO) -logging.getLogger('requests').setLevel(logging.WARNING) +# Oslo Logging uses INFO as default +# Use a simple format for the output +logging_format_string = '%(message)s' +logging.register_options(cfg.CONF) +logging.setup(cfg.CONF, "vmware-nsx") +cfg.CONF.set_override('logging_context_format_string', + logging_format_string) +cfg.CONF.set_override('logging_default_format_string', + logging_format_string) +cfg.CONF.set_override('logging_exception_prefix', + '') class NsxManage(shell.NeutronShell): diff --git a/vmware_nsx/shell/admin/plugins/common/formatters.py b/vmware_nsx/shell/admin/plugins/common/formatters.py index 13873debb8..b06c4f3c37 100644 --- a/vmware_nsx/shell/admin/plugins/common/formatters.py +++ b/vmware_nsx/shell/admin/plugins/common/formatters.py @@ -12,9 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from oslo_config import cfg +from oslo_log import log as logging from oslo_serialization import jsonutils import prettytable diff --git a/vmware_nsx/shell/admin/plugins/common/utils.py b/vmware_nsx/shell/admin/plugins/common/utils.py index 7088984bac..19608fc6bf 100644 --- a/vmware_nsx/shell/admin/plugins/common/utils.py +++ b/vmware_nsx/shell/admin/plugins/common/utils.py @@ -12,13 +12,13 @@ # License for the specific language governing permissions and limitations # under the License. -import logging import six import sys from vmware_nsx._i18n import _LI, _ from neutron.callbacks import registry from neutron.common import profiler # noqa +from oslo_log import log as logging from vmware_nsx.shell import resources as nsxadmin LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/backup_edges.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/backup_edges.py index e5d6187458..9ef55fadeb 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/backup_edges.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/backup_edges.py @@ -13,11 +13,10 @@ # under the License. -import logging - from neutron.callbacks import registry from neutron.db import l3_db from neutron_lib import exceptions +from oslo_log import log as logging from oslo_utils import uuidutils from vmware_nsx._i18n import _LE, _LI diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/dhcp_binding.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/dhcp_binding.py index 38249ee272..4d1d752a34 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/dhcp_binding.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/dhcp_binding.py @@ -13,10 +13,10 @@ # under the License. -import logging import pprint from oslo_config import cfg +from oslo_log import log as logging from vmware_nsx.shell.admin.plugins.common import constants import vmware_nsx.shell.admin.plugins.common.utils as admin_utils diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py index 14ea968ada..813b7dc934 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/edges.py @@ -13,7 +13,6 @@ # under the License. -import logging import pprint import textwrap @@ -28,6 +27,7 @@ import vmware_nsx.shell.resources as shell from neutron.callbacks import registry from neutron_lib import exceptions +from oslo_log import log as logging from vmware_nsx._i18n import _LE, _LI from vmware_nsx.common import nsxv_constants diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/metadata.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/metadata.py index 981702a92a..97bc531a50 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/metadata.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/metadata.py @@ -15,11 +15,11 @@ import hashlib import hmac -import logging from neutron.callbacks import registry from neutron.db import models_v2 from oslo_config import cfg +from oslo_log import log as logging from vmware_nsx._i18n import _LE, _LI from vmware_nsx.common import config diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/networks.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/networks.py index 9ef32d54c6..8de7d0bf5d 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/networks.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/networks.py @@ -13,7 +13,7 @@ # under the License. -import logging +from oslo_log import log as logging from oslo_serialization import jsonutils import re import xml.etree.ElementTree as et diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/routers.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/routers.py index 9b5a71ef44..d23edcdfc6 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/routers.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/routers.py @@ -13,8 +13,6 @@ # under the License. -import logging - from vmware_nsx.shell.admin.plugins.common import constants import vmware_nsx.shell.admin.plugins.common.utils as admin_utils import vmware_nsx.shell.admin.plugins.nsxv.resources.utils as utils @@ -23,6 +21,7 @@ import vmware_nsx.shell.resources as shell from neutron.callbacks import registry from neutron import context as n_context from oslo_config import cfg +from oslo_log import log as logging from vmware_nsx._i18n import _LE, _LI, _LW from vmware_nsx.common import locking diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/securitygroups.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/securitygroups.py index 844ea52eef..4dd8d7dfd3 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/securitygroups.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/securitygroups.py @@ -13,7 +13,6 @@ # under the License. -import logging import xml.etree.ElementTree as et from neutron.callbacks import registry @@ -22,6 +21,7 @@ from neutron.db.models import securitygroup as sg_models from neutron.db import models_v2 from neutron.db import securitygroups_db from neutron.extensions import securitygroup as ext_sg +from oslo_log import log as logging from vmware_nsx._i18n import _LE, _LI, _LW from vmware_nsx.db import db as nsx_db diff --git a/vmware_nsx/shell/admin/plugins/nsxv/resources/spoofguard_policy.py b/vmware_nsx/shell/admin/plugins/nsxv/resources/spoofguard_policy.py index a0c3d1f4dd..83a7d7116f 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv/resources/spoofguard_policy.py +++ b/vmware_nsx/shell/admin/plugins/nsxv/resources/spoofguard_policy.py @@ -13,9 +13,6 @@ # under the License. -import logging - - from vmware_nsx.shell.admin.plugins.common import constants from vmware_nsx.shell.admin.plugins.common import formatters @@ -29,6 +26,8 @@ from neutron_lib import exceptions from vmware_nsx._i18n import _LE, _LI from vmware_nsx.db import nsxv_db +from oslo_log import log as logging + LOG = logging.getLogger(__name__) nsxv = utils.get_nsxv_client() diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py index 396ffb2ad6..b5b90cb97e 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_binding.py @@ -12,12 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import logging import netaddr from neutron.callbacks import registry from neutron_lib import constants as const from oslo_config import cfg +from oslo_log import log as logging from vmware_nsx._i18n import _LE, _LI from vmware_nsx.common import utils as nsx_utils diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_servers.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_servers.py index 2c0731ae56..4f82da7f37 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_servers.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/dhcp_servers.py @@ -12,11 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from neutron.callbacks import registry from neutron import context from oslo_config import cfg +from oslo_log import log as logging from vmware_nsx._i18n import _LE, _LI from vmware_nsx.common import utils as nsx_utils diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/metadata_proxy.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/metadata_proxy.py index fdc832db4d..836045ad64 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/metadata_proxy.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/metadata_proxy.py @@ -12,11 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from neutron.callbacks import registry from neutron_lib import constants as const from oslo_config import cfg +from oslo_log import log as logging from vmware_nsx._i18n import _LE, _LI from vmware_nsx.common import utils as nsx_utils diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/networks.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/networks.py index 4006af1e63..22f3a86c03 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/networks.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/networks.py @@ -13,8 +13,6 @@ # under the License. -import logging - from vmware_nsx._i18n import _LI from vmware_nsx.db import db as nsx_db from vmware_nsx.shell.admin.plugins.common import constants @@ -27,6 +25,7 @@ from vmware_nsxlib.v3 import exceptions as nsx_exc from neutron.callbacks import registry from neutron import context as neutron_context from neutron.db import db_base_plugin_v2 +from oslo_log import log as logging LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/ports.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/ports.py index 1ff08697a9..2bb36dd8e0 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/ports.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/ports.py @@ -13,9 +13,8 @@ # under the License. -import logging - from oslo_config import cfg +from oslo_log import log as logging from sqlalchemy.orm import exc from vmware_nsx._i18n import _LE, _LI, _LW diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/routers.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/routers.py index ed8a052a03..e49bcfa2d8 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/routers.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/routers.py @@ -13,8 +13,6 @@ # under the License. -import logging - from vmware_nsx._i18n import _LI from vmware_nsx.db import db as nsx_db from vmware_nsx.shell.admin.plugins.common import constants @@ -29,6 +27,7 @@ from neutron.callbacks import registry from neutron import context as neutron_context from neutron.db import db_base_plugin_v2 from neutron.db import l3_db +from oslo_log import log as logging LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py b/vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py index 4b09f14214..eb4b24e0f6 100644 --- a/vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py +++ b/vmware_nsx/shell/admin/plugins/nsxv3/resources/securitygroups.py @@ -12,13 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import logging - from neutron.callbacks import registry from neutron import context as neutron_context from neutron.db import common_db_mixin as common_db from neutron.db.models import securitygroup from neutron.db import securitygroups_db +from oslo_log import log as logging from vmware_nsx.common import utils from vmware_nsx.db import db as nsx_db diff --git a/vmware_nsx/shell/nsxadmin.py b/vmware_nsx/shell/nsxadmin.py index b698b3b83e..a138ed5cb3 100644 --- a/vmware_nsx/shell/nsxadmin.py +++ b/vmware_nsx/shell/nsxadmin.py @@ -24,7 +24,6 @@ TODO: Add support for other resources, ports, logical switches etc. TODO: Autocomplete command line args """ -import logging import requests import sys @@ -37,6 +36,7 @@ from vmware_nsx.common import config # noqa from oslo_config import cfg from oslo_log import _options +from oslo_log import log as logging from vmware_nsx.shell.admin.plugins.common import constants from vmware_nsx.shell.admin import version diff --git a/vmware_nsx/shell/resources.py b/vmware_nsx/shell/resources.py index 1d1e47467a..9f7804bde8 100644 --- a/vmware_nsx/shell/resources.py +++ b/vmware_nsx/shell/resources.py @@ -15,10 +15,10 @@ import enum import glob import importlib -import logging import os from oslo_config import cfg +from oslo_log import log as logging import requests from vmware_nsx.common import config # noqa diff --git a/vmware_nsx/tests/unit/shell/test_admin_utils.py b/vmware_nsx/tests/unit/shell/test_admin_utils.py index 80c1d40e5d..1e6a0934a2 100644 --- a/vmware_nsx/tests/unit/shell/test_admin_utils.py +++ b/vmware_nsx/tests/unit/shell/test_admin_utils.py @@ -14,12 +14,12 @@ # under the License. import abc -import logging import mock import six from oslo_config import cfg from oslo_log import _options +from oslo_log import log as logging from oslo_utils import uuidutils from neutron.callbacks import registry