From ce0e9696811f5ff041760667e3f1dcdffe14df7c Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Mon, 16 Mar 2015 07:43:58 -0700 Subject: [PATCH] Adopt oslo incubator This patch removes usage of incubated libraries from neutron.openstack.common and starts "copying" such libraries from the oslo incubator as any other project. As vmware-nsx currently only uses i18n, and loopingcall, these are the only modules added to openstack-common.conf All the imports pointing out to neutron.i18n or neutron.openstack.common.loopingcall are amended in this patch. Closes-Bug: #1432783 Change-Id: I6b9d576bad33310598139c7169627c44014301af --- openstack-common.conf | 6 + tox.ini | 2 +- .../neutron/plugins/vmware/api_client/base.py | 2 +- .../plugins/vmware/api_client/client.py | 2 +- .../vmware/api_client/eventlet_client.py | 2 +- .../vmware/api_client/eventlet_request.py | 2 +- .../plugins/vmware/api_client/request.py | 2 +- .../plugins/vmware/api_client/version.py | 4 +- .../neutron/plugins/vmware/common/config.py | 2 +- .../plugins/vmware/common/nsx_utils.py | 2 +- .../neutron/plugins/vmware/common/sync.py | 5 +- .../neutron/plugins/vmware/dbexts/nsxv_db.py | 3 +- .../neutron/plugins/vmware/dbexts/qos_db.py | 3 +- .../plugins/vmware/dhcp_meta/lsnmanager.py | 4 +- .../plugins/vmware/dhcp_meta/migration.py | 2 +- .../neutron/plugins/vmware/dhcp_meta/nsx.py | 2 +- .../neutron/plugins/vmware/dhcp_meta/rpc.py | 2 +- .../neutron/plugins/vmware/dhcpmeta_modes.py | 2 +- vmware_nsx/neutron/plugins/vmware/dvs/dvs.py | 6 +- .../neutron/plugins/vmware/nsx_cluster.py | 2 +- .../neutron/plugins/vmware/nsxlib/router.py | 3 +- .../neutron/plugins/vmware/nsxlib/secgroup.py | 3 +- .../neutron/plugins/vmware/nsxlib/switch.py | 3 +- .../neutron/plugins/vmware/plugins/base.py | 2 +- .../neutron/plugins/vmware/plugins/dvs.py | 3 +- .../plugins/vmware/plugins/managers.py | 3 +- .../neutron/plugins/vmware/plugins/nsx_v.py | 3 +- .../plugins/vmware/plugins/nsx_v_md_proxy.py | 8 +- .../vmware/vshield/edge_appliance_driver.py | 2 +- .../vmware/vshield/edge_firewall_driver.py | 6 +- .../vmware/vshield/edge_ipsecvpn_driver.py | 4 +- .../vshield/edge_loadbalancer_driver.py | 4 +- .../plugins/vmware/vshield/edge_utils.py | 4 +- .../plugins/vmware/vshield/tasks/tasks.py | 4 +- .../apiclient/test_api_eventlet_request.py | 5 +- vmware_nsx/openstack/__init__.py | 0 vmware_nsx/openstack/common/__init__.py | 0 vmware_nsx/openstack/common/_i18n.py | 45 ++++++ vmware_nsx/openstack/common/loopingcall.py | 147 ++++++++++++++++++ 39 files changed, 257 insertions(+), 49 deletions(-) create mode 100644 openstack-common.conf create mode 100644 vmware_nsx/openstack/__init__.py create mode 100644 vmware_nsx/openstack/common/__init__.py create mode 100644 vmware_nsx/openstack/common/_i18n.py create mode 100644 vmware_nsx/openstack/common/loopingcall.py diff --git a/openstack-common.conf b/openstack-common.conf new file mode 100644 index 0000000000..dfe79b7d2b --- /dev/null +++ b/openstack-common.conf @@ -0,0 +1,6 @@ +[DEFAULT] +# The list of modules to copy from oslo-incubator.git +module=loopingcall + +# The base module to hold the copy of openstack.common +base=vmware_nsx diff --git a/tox.ini b/tox.ini index 8dbcfdbdb6..ce205a3364 100644 --- a/tox.ini +++ b/tox.ini @@ -81,5 +81,5 @@ commands = pylint --rcfile=.pylintrc --output-format=colorized {posargs:vmware_nsx/neutron} [hacking] -import_exceptions = neutron.i18n +import_exceptions = vmware_nsx.openstack.common._i18n local-check-factory = neutron.hacking.checks.factory diff --git a/vmware_nsx/neutron/plugins/vmware/api_client/base.py b/vmware_nsx/neutron/plugins/vmware/api_client/base.py index 8399ce97c4..53a653be1e 100644 --- a/vmware_nsx/neutron/plugins/vmware/api_client/base.py +++ b/vmware_nsx/neutron/plugins/vmware/api_client/base.py @@ -22,8 +22,8 @@ import time from oslo_config import cfg from oslo_log import log as logging -from neutron.i18n import _LE, _LI, _LW from vmware_nsx.neutron.plugins.vmware import api_client +from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/api_client/client.py b/vmware_nsx/neutron/plugins/vmware/api_client/client.py index c6ac8edbbe..715b777c4a 100644 --- a/vmware_nsx/neutron/plugins/vmware/api_client/client.py +++ b/vmware_nsx/neutron/plugins/vmware/api_client/client.py @@ -17,7 +17,6 @@ import httplib -from neutron.i18n import _LE from oslo_log import log as logging from vmware_nsx.neutron.plugins.vmware.api_client import base @@ -25,6 +24,7 @@ from vmware_nsx.neutron.plugins.vmware.api_client import eventlet_client from vmware_nsx.neutron.plugins.vmware.api_client import eventlet_request from vmware_nsx.neutron.plugins.vmware.api_client import exception from vmware_nsx.neutron.plugins.vmware.api_client import version +from vmware_nsx.openstack.common._i18n import _LE LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/api_client/eventlet_client.py b/vmware_nsx/neutron/plugins/vmware/api_client/eventlet_client.py index e2d284fa37..1d01b03b47 100644 --- a/vmware_nsx/neutron/plugins/vmware/api_client/eventlet_client.py +++ b/vmware_nsx/neutron/plugins/vmware/api_client/eventlet_client.py @@ -21,9 +21,9 @@ import eventlet eventlet.monkey_patch() from oslo_log import log as logging -from neutron.i18n import _LE from vmware_nsx.neutron.plugins.vmware.api_client import base from vmware_nsx.neutron.plugins.vmware.api_client import eventlet_request +from vmware_nsx.openstack.common._i18n import _LE LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/api_client/eventlet_request.py b/vmware_nsx/neutron/plugins/vmware/api_client/eventlet_request.py index d839c56111..c488dc523e 100644 --- a/vmware_nsx/neutron/plugins/vmware/api_client/eventlet_request.py +++ b/vmware_nsx/neutron/plugins/vmware/api_client/eventlet_request.py @@ -21,8 +21,8 @@ import eventlet from oslo_log import log as logging from oslo_serialization import jsonutils -from neutron.i18n import _LI, _LW from vmware_nsx.neutron.plugins.vmware.api_client import request +from vmware_nsx.openstack.common._i18n import _LI, _LW LOG = logging.getLogger(__name__) USER_AGENT = "Neutron eventlet client/2.0" diff --git a/vmware_nsx/neutron/plugins/vmware/api_client/request.py b/vmware_nsx/neutron/plugins/vmware/api_client/request.py index d68accdc3b..a61326ddb0 100644 --- a/vmware_nsx/neutron/plugins/vmware/api_client/request.py +++ b/vmware_nsx/neutron/plugins/vmware/api_client/request.py @@ -26,8 +26,8 @@ from oslo_utils import excutils import six import six.moves.urllib.parse as urlparse -from neutron.i18n import _LI, _LW from vmware_nsx.neutron.plugins.vmware import api_client +from vmware_nsx.openstack.common._i18n import _LI, _LW LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/api_client/version.py b/vmware_nsx/neutron/plugins/vmware/api_client/version.py index 499e5ef8f2..3451e4a697 100644 --- a/vmware_nsx/neutron/plugins/vmware/api_client/version.py +++ b/vmware_nsx/neutron/plugins/vmware/api_client/version.py @@ -15,9 +15,11 @@ # under the License. # -from neutron.i18n import _LW from oslo_log import log as logging +from vmware_nsx.openstack.common._i18n import _LW + + LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/common/config.py b/vmware_nsx/neutron/plugins/vmware/common/config.py index 829511774c..547dab013a 100644 --- a/vmware_nsx/neutron/plugins/vmware/common/config.py +++ b/vmware_nsx/neutron/plugins/vmware/common/config.py @@ -16,8 +16,8 @@ import logging from oslo_config import cfg -from neutron.i18n import _LW from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc +from vmware_nsx.openstack.common._i18n import _LW LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/common/nsx_utils.py b/vmware_nsx/neutron/plugins/vmware/common/nsx_utils.py index dd315c1782..242ae70d71 100644 --- a/vmware_nsx/neutron/plugins/vmware/common/nsx_utils.py +++ b/vmware_nsx/neutron/plugins/vmware/common/nsx_utils.py @@ -17,7 +17,6 @@ from neutron.api.v2 import attributes as attr from neutron.common import exceptions as n_exc from neutron.extensions import multiprovidernet as mpnet from neutron.extensions import providernet as pnet -from neutron.i18n import _LW from oslo_log import log from vmware_nsx.neutron.plugins.vmware.api_client import client @@ -30,6 +29,7 @@ from vmware_nsx.neutron.plugins.vmware.nsxlib import l2gateway as l2gwlib from vmware_nsx.neutron.plugins.vmware.nsxlib import router as routerlib from vmware_nsx.neutron.plugins.vmware.nsxlib import secgroup as secgrouplib from vmware_nsx.neutron.plugins.vmware.nsxlib import switch as switchlib +from vmware_nsx.openstack.common._i18n import _LW LOG = log.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/common/sync.py b/vmware_nsx/neutron/plugins/vmware/common/sync.py index dbb44229eb..6135c37403 100644 --- a/vmware_nsx/neutron/plugins/vmware/common/sync.py +++ b/vmware_nsx/neutron/plugins/vmware/common/sync.py @@ -26,14 +26,15 @@ from neutron.db import external_net_db from neutron.db import l3_db from neutron.db import models_v2 from neutron.extensions import l3 -from neutron.i18n import _LE, _LI, _LW -from neutron.openstack.common import loopingcall + from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc from vmware_nsx.neutron.plugins.vmware.common import nsx_utils from vmware_nsx.neutron.plugins.vmware import nsxlib from vmware_nsx.neutron.plugins.vmware.nsxlib import router as routerlib from vmware_nsx.neutron.plugins.vmware.nsxlib import switch as switchlib +from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW +from vmware_nsx.openstack.common import loopingcall # Maximum page size for a single request # NOTE(salv-orlando): This might become a version-dependent map should the diff --git a/vmware_nsx/neutron/plugins/vmware/dbexts/nsxv_db.py b/vmware_nsx/neutron/plugins/vmware/dbexts/nsxv_db.py index 308d6e2a29..19c4dcae21 100644 --- a/vmware_nsx/neutron/plugins/vmware/dbexts/nsxv_db.py +++ b/vmware_nsx/neutron/plugins/vmware/dbexts/nsxv_db.py @@ -21,13 +21,12 @@ from sqlalchemy.orm import exc from sqlalchemy.sql import expression as expr import neutron.db.api as db -from neutron.i18n import _, _LE from neutron.plugins.vmware.dbexts import nsxv_models from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc from vmware_nsx.neutron.plugins.vmware.common import nsxv_constants from vmware_nsx.neutron.plugins.vmware.vshield.common import constants - +from vmware_nsx.openstack.common._i18n import _, _LE LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/dbexts/qos_db.py b/vmware_nsx/neutron/plugins/vmware/dbexts/qos_db.py index 3c971e09ba..8a8544586d 100644 --- a/vmware_nsx/neutron/plugins/vmware/dbexts/qos_db.py +++ b/vmware_nsx/neutron/plugins/vmware/dbexts/qos_db.py @@ -18,12 +18,13 @@ from sqlalchemy.orm import exc from neutron.api.v2 import attributes as attr from neutron.db import db_base_plugin_v2 from neutron.db import models_v2 -from neutron.i18n import _LI from neutron.plugins.vmware.dbexts import nsx_models from neutron.plugins.vmware.extensions import qos from oslo_log import log from oslo_utils import uuidutils +from vmware_nsx.openstack.common._i18n import _LI + LOG = log.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/dhcp_meta/lsnmanager.py b/vmware_nsx/neutron/plugins/vmware/dhcp_meta/lsnmanager.py index 9ca10b6f45..d6d0899efb 100644 --- a/vmware_nsx/neutron/plugins/vmware/dhcp_meta/lsnmanager.py +++ b/vmware_nsx/neutron/plugins/vmware/dhcp_meta/lsnmanager.py @@ -15,13 +15,12 @@ # under the License. # +from neutron.common import exceptions as n_exc from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging from oslo_utils import excutils -from neutron.common import exceptions as n_exc -from neutron.i18n import _LE, _LW from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc from vmware_nsx.neutron.plugins.vmware.common import exceptions as p_exc from vmware_nsx.neutron.plugins.vmware.common import nsx_utils @@ -29,6 +28,7 @@ from vmware_nsx.neutron.plugins.vmware.dbexts import lsn_db from vmware_nsx.neutron.plugins.vmware.dhcp_meta import constants as const from vmware_nsx.neutron.plugins.vmware.nsxlib import lsn as lsn_api from vmware_nsx.neutron.plugins.vmware.nsxlib import switch as switch_api +from vmware_nsx.openstack.common._i18n import _LE, _LW LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/dhcp_meta/migration.py b/vmware_nsx/neutron/plugins/vmware/dhcp_meta/migration.py index 3817cb3f41..8418f3d4c9 100644 --- a/vmware_nsx/neutron/plugins/vmware/dhcp_meta/migration.py +++ b/vmware_nsx/neutron/plugins/vmware/dhcp_meta/migration.py @@ -18,12 +18,12 @@ from neutron.common import constants as const from neutron.common import exceptions as n_exc from neutron.extensions import external_net -from neutron.i18n import _LE from oslo_log import log as logging from vmware_nsx.neutron.plugins.vmware.common import exceptions as p_exc from vmware_nsx.neutron.plugins.vmware.dhcp_meta import nsx from vmware_nsx.neutron.plugins.vmware.dhcp_meta import rpc +from vmware_nsx.openstack.common._i18n import _LE LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/dhcp_meta/nsx.py b/vmware_nsx/neutron/plugins/vmware/dhcp_meta/nsx.py index 91ff9d715c..02876fd06a 100644 --- a/vmware_nsx/neutron/plugins/vmware/dhcp_meta/nsx.py +++ b/vmware_nsx/neutron/plugins/vmware/dhcp_meta/nsx.py @@ -25,7 +25,7 @@ from neutron.common import exceptions as n_exc from neutron.db import db_base_plugin_v2 from neutron.db import l3_db from neutron.extensions import external_net -from neutron.i18n import _LE, _LI +from vmware_nsx.openstack.common._i18n import _LE, _LI from vmware_nsx.neutron.plugins.vmware.common import exceptions as p_exc from vmware_nsx.neutron.plugins.vmware.dhcp_meta import constants as d_const from vmware_nsx.neutron.plugins.vmware.nsxlib import lsn as lsn_api diff --git a/vmware_nsx/neutron/plugins/vmware/dhcp_meta/rpc.py b/vmware_nsx/neutron/plugins/vmware/dhcp_meta/rpc.py index c093f18d09..cb83feace1 100644 --- a/vmware_nsx/neutron/plugins/vmware/dhcp_meta/rpc.py +++ b/vmware_nsx/neutron/plugins/vmware/dhcp_meta/rpc.py @@ -25,7 +25,7 @@ from neutron.common import constants as const from neutron.common import exceptions as ntn_exc from neutron.db import db_base_plugin_v2 from neutron.db import models_v2 -from neutron.i18n import _LE, _LI, _LW +from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc from vmware_nsx.neutron.plugins.vmware.common import config from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc diff --git a/vmware_nsx/neutron/plugins/vmware/dhcpmeta_modes.py b/vmware_nsx/neutron/plugins/vmware/dhcpmeta_modes.py index 2270319b99..208ae86b15 100644 --- a/vmware_nsx/neutron/plugins/vmware/dhcpmeta_modes.py +++ b/vmware_nsx/neutron/plugins/vmware/dhcpmeta_modes.py @@ -27,7 +27,6 @@ from neutron.common import constants as const from neutron.common import rpc as n_rpc from neutron.common import topics from neutron.db import agents_db -from neutron.i18n import _LW from neutron.plugins.vmware.extensions import lsn from vmware_nsx.neutron.plugins.vmware.common import config @@ -37,6 +36,7 @@ from vmware_nsx.neutron.plugins.vmware.dhcp_meta import lsnmanager from vmware_nsx.neutron.plugins.vmware.dhcp_meta import migration from vmware_nsx.neutron.plugins.vmware.dhcp_meta import nsx as nsx_svc from vmware_nsx.neutron.plugins.vmware.dhcp_meta import rpc as nsx_rpc +from vmware_nsx.openstack.common._i18n import _LW LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/dvs/dvs.py b/vmware_nsx/neutron/plugins/vmware/dvs/dvs.py index ad8ae9346f..d60cf8f09d 100644 --- a/vmware_nsx/neutron/plugins/vmware/dvs/dvs.py +++ b/vmware_nsx/neutron/plugins/vmware/dvs/dvs.py @@ -12,14 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron.common import exceptions +from oslo_log import log as logging from oslo_utils import excutils from oslo_vmware import vim_util -from neutron.common import exceptions -from neutron.i18n import _LE, _LI -from oslo_log import log as logging from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc from vmware_nsx.neutron.plugins.vmware.dvs import dvs_utils +from vmware_nsx.openstack.common._i18n import _LE, _LI LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/nsx_cluster.py b/vmware_nsx/neutron/plugins/vmware/nsx_cluster.py index f7cee35b30..382fe83d2d 100644 --- a/vmware_nsx/neutron/plugins/vmware/nsx_cluster.py +++ b/vmware_nsx/neutron/plugins/vmware/nsx_cluster.py @@ -16,8 +16,8 @@ from oslo_config import cfg from oslo_log import log as logging -from neutron.i18n import _LI from vmware_nsx.neutron.plugins.vmware.common import exceptions +from vmware_nsx.openstack.common._i18n import _LI LOG = logging.getLogger(__name__) DEFAULT_PORT = 443 diff --git a/vmware_nsx/neutron/plugins/vmware/nsxlib/router.py b/vmware_nsx/neutron/plugins/vmware/nsxlib/router.py index eed214df07..f1a17e7d57 100644 --- a/vmware_nsx/neutron/plugins/vmware/nsxlib/router.py +++ b/vmware_nsx/neutron/plugins/vmware/nsxlib/router.py @@ -19,13 +19,14 @@ from oslo_serialization import jsonutils from oslo_utils import excutils from neutron.common import exceptions as exception -from neutron.i18n import _LE, _LI, _LW + from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc from vmware_nsx.neutron.plugins.vmware.common import utils from vmware_nsx.neutron.plugins.vmware import nsxlib from vmware_nsx.neutron.plugins.vmware.nsxlib import switch from vmware_nsx.neutron.plugins.vmware.nsxlib import versioning +from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW # @versioning.versioned decorator makes the apparent function body # totally unrelated to the real function. This confuses pylint :( diff --git a/vmware_nsx/neutron/plugins/vmware/nsxlib/secgroup.py b/vmware_nsx/neutron/plugins/vmware/nsxlib/secgroup.py index a0bcc97642..aa3f8bda1f 100644 --- a/vmware_nsx/neutron/plugins/vmware/nsxlib/secgroup.py +++ b/vmware_nsx/neutron/plugins/vmware/nsxlib/secgroup.py @@ -19,9 +19,10 @@ from oslo_utils import excutils from neutron.common import constants from neutron.common import exceptions -from neutron.i18n import _LW + from vmware_nsx.neutron.plugins.vmware.common import utils from vmware_nsx.neutron.plugins.vmware import nsxlib +from vmware_nsx.openstack.common._i18n import _LW HTTP_GET = "GET" HTTP_POST = "POST" diff --git a/vmware_nsx/neutron/plugins/vmware/nsxlib/switch.py b/vmware_nsx/neutron/plugins/vmware/nsxlib/switch.py index ed2d843334..327670cd63 100644 --- a/vmware_nsx/neutron/plugins/vmware/nsxlib/switch.py +++ b/vmware_nsx/neutron/plugins/vmware/nsxlib/switch.py @@ -20,11 +20,12 @@ from oslo_serialization import jsonutils from neutron.common import constants from neutron.common import exceptions as exception -from neutron.i18n import _LE, _LI, _LW + from vmware_nsx.neutron.plugins.vmware.api_client import exception as api_exc from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc from vmware_nsx.neutron.plugins.vmware.common import utils from vmware_nsx.neutron.plugins.vmware import nsxlib +from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW HTTP_GET = "GET" HTTP_POST = "POST" diff --git a/vmware_nsx/neutron/plugins/vmware/plugins/base.py b/vmware_nsx/neutron/plugins/vmware/plugins/base.py index ad57a2a15b..49ca362239 100644 --- a/vmware_nsx/neutron/plugins/vmware/plugins/base.py +++ b/vmware_nsx/neutron/plugins/vmware/plugins/base.py @@ -53,7 +53,6 @@ from neutron.extensions import portbindings as pbin from neutron.extensions import portsecurity as psec from neutron.extensions import providernet as pnet from neutron.extensions import securitygroup as ext_sg -from neutron.i18n import _LE, _LI, _LW from neutron.plugins.common import constants as plugin_const from neutron.plugins.vmware.dbexts import nsx_models from neutron.plugins.vmware.extensions import maclearning as mac_ext @@ -78,6 +77,7 @@ from vmware_nsx.neutron.plugins.vmware.nsxlib import queue as queuelib from vmware_nsx.neutron.plugins.vmware.nsxlib import router as routerlib from vmware_nsx.neutron.plugins.vmware.nsxlib import secgroup as secgrouplib from vmware_nsx.neutron.plugins.vmware.nsxlib import switch as switchlib +from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/plugins/dvs.py b/vmware_nsx/neutron/plugins/vmware/plugins/dvs.py index 4b160a002f..e7a48b68b6 100644 --- a/vmware_nsx/neutron/plugins/vmware/plugins/dvs.py +++ b/vmware_nsx/neutron/plugins/vmware/plugins/dvs.py @@ -35,7 +35,7 @@ from neutron.extensions import multiprovidernet as mpnet from neutron.extensions import portbindings as pbin from neutron.extensions import portsecurity as psec from neutron.extensions import providernet as pnet -from neutron.i18n import _LE, _LW + from vmware_nsx.neutron.plugins import vmware from vmware_nsx.neutron.plugins.vmware.common import config # noqa from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc @@ -44,6 +44,7 @@ from vmware_nsx.neutron.plugins.vmware.dbexts import db as nsx_db from vmware_nsx.neutron.plugins.vmware import dhcpmeta_modes from vmware_nsx.neutron.plugins.vmware.dvs import dvs from vmware_nsx.neutron.plugins.vmware.dvs import dvs_utils +from vmware_nsx.openstack.common._i18n import _LE, _LW LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/plugins/managers.py b/vmware_nsx/neutron/plugins/vmware/plugins/managers.py index 8e5a544297..7cdb91d8e0 100644 --- a/vmware_nsx/neutron/plugins/vmware/plugins/managers.py +++ b/vmware_nsx/neutron/plugins/vmware/plugins/managers.py @@ -18,9 +18,8 @@ import stevedore from oslo_log import log -from neutron.i18n import _LE, _LI from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc - +from vmware_nsx.openstack.common._i18n import _LE, _LI LOG = log.getLogger(__name__) ROUTER_TYPE_DRIVERS = ["distributed", "exclusive", "shared"] diff --git a/vmware_nsx/neutron/plugins/vmware/plugins/nsx_v.py b/vmware_nsx/neutron/plugins/vmware/plugins/nsx_v.py index 901f45ae9c..e7f51975ae 100644 --- a/vmware_nsx/neutron/plugins/vmware/plugins/nsx_v.py +++ b/vmware_nsx/neutron/plugins/vmware/plugins/nsx_v.py @@ -47,11 +47,11 @@ from neutron.extensions import portbindings as pbin from neutron.extensions import portsecurity as psec from neutron.extensions import providernet as pnet from neutron.extensions import securitygroup as ext_sg -from neutron.i18n import _LE, _LI, _LW from neutron.plugins.vmware.extensions import ( advancedserviceproviders as as_providers) from neutron.plugins.vmware.extensions import ( vnicindex as ext_vnic_idx) + from vmware_nsx.neutron.plugins import vmware from vmware_nsx.neutron.plugins.vmware.common import config # noqa from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsx_exc @@ -70,6 +70,7 @@ from vmware_nsx.neutron.plugins.vmware.vshield.common import ( from vmware_nsx.neutron.plugins.vmware.vshield import edge_utils from vmware_nsx.neutron.plugins.vmware.vshield import securitygroup_utils from vmware_nsx.neutron.plugins.vmware.vshield import vcns_driver +from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW LOG = logging.getLogger(__name__) PORTGROUP_PREFIX = 'dvportgroup' diff --git a/vmware_nsx/neutron/plugins/vmware/plugins/nsx_v_md_proxy.py b/vmware_nsx/neutron/plugins/vmware/plugins/nsx_v_md_proxy.py index 0a07656a6b..2c0ef11a97 100644 --- a/vmware_nsx/neutron/plugins/vmware/plugins/nsx_v_md_proxy.py +++ b/vmware_nsx/neutron/plugins/vmware/plugins/nsx_v_md_proxy.py @@ -19,15 +19,14 @@ import hmac import time import netaddr +from neutron.api.v2 import attributes as attr +from neutron.common import constants +from neutron import context as neutron_context from oslo_config import cfg from oslo_db import exception as db_exc from oslo_log import log as logging from oslo_utils import excutils -from neutron.api.v2 import attributes as attr -from neutron.common import constants -from neutron import context as neutron_context -from neutron.i18n import _LE from vmware_nsx.neutron.plugins.vmware.common import exceptions as nsxv_exc from vmware_nsx.neutron.plugins.vmware.common import nsxv_constants from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_db @@ -36,6 +35,7 @@ from vmware_nsx.neutron.plugins.vmware.vshield import ( from vmware_nsx.neutron.plugins.vmware.vshield.common import ( constants as vcns_const) from vmware_nsx.neutron.plugins.vmware.vshield import edge_utils +from vmware_nsx.openstack.common._i18n import _LE METADATA_IP_ADDR = '169.254.169.254' METADATA_TCP_PORT = 80 diff --git a/vmware_nsx/neutron/plugins/vmware/vshield/edge_appliance_driver.py b/vmware_nsx/neutron/plugins/vmware/vshield/edge_appliance_driver.py index 7792223d16..af1e35aadc 100644 --- a/vmware_nsx/neutron/plugins/vmware/vshield/edge_appliance_driver.py +++ b/vmware_nsx/neutron/plugins/vmware/vshield/edge_appliance_driver.py @@ -21,7 +21,6 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import excutils -from neutron.i18n import _LE, _LI, _LW from vmware_nsx.neutron.plugins.vmware.common import nsxv_constants from vmware_nsx.neutron.plugins.vmware.common import utils from vmware_nsx.neutron.plugins.vmware.vshield.common import constants @@ -29,6 +28,7 @@ from vmware_nsx.neutron.plugins.vmware.vshield.common import exceptions from vmware_nsx.neutron.plugins.vmware.vshield.tasks import ( constants as task_constants) from vmware_nsx.neutron.plugins.vmware.vshield.tasks import tasks +from vmware_nsx.openstack.common._i18n import _LE, _LI, _LW LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/vshield/edge_firewall_driver.py b/vmware_nsx/neutron/plugins/vmware/vshield/edge_firewall_driver.py index 529c0c3322..73c6516d1a 100644 --- a/vmware_nsx/neutron/plugins/vmware/vshield/edge_firewall_driver.py +++ b/vmware_nsx/neutron/plugins/vmware/vshield/edge_firewall_driver.py @@ -12,18 +12,18 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron.db import db_base_plugin_v2 +from neutron.plugins.common import constants from oslo_log import log as logging from oslo_utils import excutils -from neutron.db import db_base_plugin_v2 -from neutron.i18n import _, _LE -from neutron.plugins.common import constants from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_db from vmware_nsx.neutron.plugins.vmware.vshield.common import ( exceptions as vcns_exc) from vmware_nsx.neutron.plugins.vmware.vshield.tasks import ( constants as task_const) from vmware_nsx.neutron.plugins.vmware.vshield.tasks import tasks +from vmware_nsx.openstack.common._i18n import _, _LE LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/vshield/edge_ipsecvpn_driver.py b/vmware_nsx/neutron/plugins/vmware/vshield/edge_ipsecvpn_driver.py index d7fd00bb49..fe315992e5 100644 --- a/vmware_nsx/neutron/plugins/vmware/vshield/edge_ipsecvpn_driver.py +++ b/vmware_nsx/neutron/plugins/vmware/vshield/edge_ipsecvpn_driver.py @@ -12,12 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. +from oslo_log import log as logging from oslo_utils import excutils -from neutron.i18n import _LE, _LW -from oslo_log import log as logging from vmware_nsx.neutron.plugins.vmware.vshield.common import ( exceptions as vcns_exc) +from vmware_nsx.openstack.common._i18n import _LE, _LW LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/vshield/edge_loadbalancer_driver.py b/vmware_nsx/neutron/plugins/vmware/vshield/edge_loadbalancer_driver.py index 6bb69d2e41..2074cf6e0e 100644 --- a/vmware_nsx/neutron/plugins/vmware/vshield/edge_loadbalancer_driver.py +++ b/vmware_nsx/neutron/plugins/vmware/vshield/edge_loadbalancer_driver.py @@ -14,13 +14,15 @@ from oslo_utils import excutils -from neutron.i18n import _LE from oslo_log import log as logging + from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_db from vmware_nsx.neutron.plugins.vmware.vshield.common import ( constants as vcns_const) from vmware_nsx.neutron.plugins.vmware.vshield.common import ( exceptions as vcns_exc) +from vmware_nsx.openstack.common._i18n import _LE + try: from neutron_lbaas.services.loadbalancer import constants as lb_constants except Exception: diff --git a/vmware_nsx/neutron/plugins/vmware/vshield/edge_utils.py b/vmware_nsx/neutron/plugins/vmware/vshield/edge_utils.py index 60c9b413be..7086ab754e 100644 --- a/vmware_nsx/neutron/plugins/vmware/vshield/edge_utils.py +++ b/vmware_nsx/neutron/plugins/vmware/vshield/edge_utils.py @@ -26,8 +26,8 @@ from sqlalchemy.orm import exc as sa_exc from neutron.common import exceptions as n_exc from neutron import context as q_context from neutron.extensions import l3 -from neutron.i18n import _LE, _LW from neutron.plugins.common import constants as plugin_const + from vmware_nsx.neutron.plugins.vmware.common import nsxv_constants from vmware_nsx.neutron.plugins.vmware.dbexts import db as nsx_db from vmware_nsx.neutron.plugins.vmware.dbexts import nsxv_db @@ -36,7 +36,7 @@ from vmware_nsx.neutron.plugins.vmware.vshield.common import ( from vmware_nsx.neutron.plugins.vmware.vshield.tasks import ( constants as task_const) from vmware_nsx.neutron.plugins.vmware.vshield.tasks import tasks - +from vmware_nsx.openstack.common._i18n import _LE, _LW WORKER_POOL_SIZE = 8 LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/neutron/plugins/vmware/vshield/tasks/tasks.py b/vmware_nsx/neutron/plugins/vmware/vshield/tasks/tasks.py index 999a7a6081..b0f7c2ba72 100644 --- a/vmware_nsx/neutron/plugins/vmware/vshield/tasks/tasks.py +++ b/vmware_nsx/neutron/plugins/vmware/vshield/tasks/tasks.py @@ -19,11 +19,11 @@ import uuid from eventlet import event from eventlet import greenthread from neutron.common import exceptions -from neutron.i18n import _LE, _LI -from neutron.openstack.common import loopingcall from oslo_log import log as logging from vmware_nsx.neutron.plugins.vmware.vshield.tasks import constants +from vmware_nsx.openstack.common._i18n import _LE, _LI +from vmware_nsx.openstack.common import loopingcall DEFAULT_INTERVAL = 1000 diff --git a/vmware_nsx/neutron/tests/unit/vmware/apiclient/test_api_eventlet_request.py b/vmware_nsx/neutron/tests/unit/vmware/apiclient/test_api_eventlet_request.py index 89fd6318d6..27efabe7b4 100644 --- a/vmware_nsx/neutron/tests/unit/vmware/apiclient/test_api_eventlet_request.py +++ b/vmware_nsx/neutron/tests/unit/vmware/apiclient/test_api_eventlet_request.py @@ -18,15 +18,16 @@ import random import eventlet from eventlet.green import urllib2 import mock -from neutron.i18n import _LI from neutron.tests import base from oslo_log import log as logging + + from vmware_nsx.neutron.plugins.vmware.api_client import ( eventlet_client as client) from vmware_nsx.neutron.plugins.vmware.api_client import ( eventlet_request as request) from vmware_nsx.neutron.tests.unit import vmware - +from vmware_nsx.openstack.common._i18n import _LI LOG = logging.getLogger(__name__) diff --git a/vmware_nsx/openstack/__init__.py b/vmware_nsx/openstack/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vmware_nsx/openstack/common/__init__.py b/vmware_nsx/openstack/common/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vmware_nsx/openstack/common/_i18n.py b/vmware_nsx/openstack/common/_i18n.py new file mode 100644 index 0000000000..b78e57a267 --- /dev/null +++ b/vmware_nsx/openstack/common/_i18n.py @@ -0,0 +1,45 @@ +# 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='vmware_nsx') + + # 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/vmware_nsx/openstack/common/loopingcall.py b/vmware_nsx/openstack/common/loopingcall.py new file mode 100644 index 0000000000..c7377fd625 --- /dev/null +++ b/vmware_nsx/openstack/common/loopingcall.py @@ -0,0 +1,147 @@ +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# Copyright 2011 Justin Santa Barbara +# All Rights Reserved. +# +# 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. + +import logging +import sys +import time + +from eventlet import event +from eventlet import greenthread + +from vmware_nsx.openstack.common._i18n import _LE, _LW + +LOG = logging.getLogger(__name__) + +# NOTE(zyluo): This lambda function was declared to avoid mocking collisions +# with time.time() called in the standard logging module +# during unittests. +_ts = lambda: time.time() + + +class LoopingCallDone(Exception): + """Exception to break out and stop a LoopingCallBase. + + The poll-function passed to LoopingCallBase can raise this exception to + break out of the loop normally. This is somewhat analogous to + StopIteration. + + An optional return-value can be included as the argument to the exception; + this return-value will be returned by LoopingCallBase.wait() + + """ + + def __init__(self, retvalue=True): + """:param retvalue: Value that LoopingCallBase.wait() should return.""" + self.retvalue = retvalue + + +class LoopingCallBase(object): + def __init__(self, f=None, *args, **kw): + self.args = args + self.kw = kw + self.f = f + self._running = False + self.done = None + + def stop(self): + self._running = False + + def wait(self): + return self.done.wait() + + +class FixedIntervalLoopingCall(LoopingCallBase): + """A fixed interval looping call.""" + + def start(self, interval, initial_delay=None): + self._running = True + done = event.Event() + + def _inner(): + if initial_delay: + greenthread.sleep(initial_delay) + + try: + while self._running: + start = _ts() + self.f(*self.args, **self.kw) + end = _ts() + if not self._running: + break + delay = end - start - interval + if delay > 0: + LOG.warn(_LW('task %(func_name)r run outlasted ' + 'interval by %(delay).2f sec'), + {'func_name': self.f, 'delay': delay}) + greenthread.sleep(-delay if delay < 0 else 0) + except LoopingCallDone as e: + self.stop() + done.send(e.retvalue) + except Exception: + LOG.exception(_LE('in fixed duration looping call')) + done.send_exception(*sys.exc_info()) + return + else: + done.send(True) + + self.done = done + + greenthread.spawn_n(_inner) + return self.done + + +class DynamicLoopingCall(LoopingCallBase): + """A looping call which sleeps until the next known event. + + The function called should return how long to sleep for before being + called again. + """ + + def start(self, initial_delay=None, periodic_interval_max=None): + self._running = True + done = event.Event() + + def _inner(): + if initial_delay: + greenthread.sleep(initial_delay) + + try: + while self._running: + idle = self.f(*self.args, **self.kw) + if not self._running: + break + + if periodic_interval_max is not None: + idle = min(idle, periodic_interval_max) + LOG.debug('Dynamic looping call %(func_name)r sleeping ' + 'for %(idle).02f seconds', + {'func_name': self.f, 'idle': idle}) + greenthread.sleep(idle) + except LoopingCallDone as e: + self.stop() + done.send(e.retvalue) + except Exception: + LOG.exception(_LE('in dynamic looping call')) + done.send_exception(*sys.exc_info()) + return + else: + done.send(True) + + self.done = done + + greenthread.spawn(_inner) + return self.done