Migration to oslo.utils
Common code from sahara.openstack.common.db was replaced by usage of oslo.utils library. sahara/openstack/common/network_utils.py module was removed. excutils.py, importutils.py, timeutils.py and importutils.py modules are waiting for migration to oslo.utils in other oslo-incubator modules and still exist. Change-Id: I6a82a9dfdf704da16ed709c650fa68f9527fd668
This commit is contained in:
parent
543c9df504
commit
9885a98d06
|
@ -8,7 +8,6 @@ module=jsonutils
|
|||
module=lockutils
|
||||
module=log
|
||||
module=middleware.base
|
||||
module=network_utils
|
||||
module=periodic_task
|
||||
module=processutils
|
||||
module=strutils
|
||||
|
|
|
@ -9,6 +9,7 @@ oslo.config>=1.4.0.0a3
|
|||
oslo.db>=0.2.0 # Apache-2.0
|
||||
oslo.i18n>=0.1.0 # Apache-2.0
|
||||
oslo.messaging>=1.4.0.0a3
|
||||
oslo.utils>=0.1.1
|
||||
paramiko>=1.13.0
|
||||
pbr>=0.6,!=0.7,<1.0
|
||||
posix_ipc
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
"""Base class for classes that need modular database access."""
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from sahara.openstack.common import importutils
|
||||
from oslo.utils import importutils
|
||||
|
||||
|
||||
db_driver_opt = cfg.StrOpt('db_driver',
|
||||
|
@ -32,4 +31,4 @@ class Base(object):
|
|||
"""DB driver is injected in the init method."""
|
||||
|
||||
def __init__(self):
|
||||
self.db = importutils.import_module(CONF.db_driver)
|
||||
self.db = importutils.try_import(CONF.db_driver)
|
||||
|
|
|
@ -19,14 +19,14 @@ from __future__ import with_statement
|
|||
from logging import config as c
|
||||
|
||||
from alembic import context
|
||||
from oslo.utils import importutils
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import pool
|
||||
|
||||
from sahara.db.sqlalchemy import model_base
|
||||
from sahara.openstack.common import importutils
|
||||
|
||||
|
||||
importutils.import_module('sahara.db.sqlalchemy.models')
|
||||
importutils.try_import('sahara.db.sqlalchemy.models')
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
|
|
|
@ -1,163 +0,0 @@
|
|||
# Copyright 2012 OpenStack Foundation.
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Network-related utilities and helper functions.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import socket
|
||||
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from sahara.openstack.common.gettextutils import _LW
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def parse_host_port(address, default_port=None):
|
||||
"""Interpret a string as a host:port pair.
|
||||
|
||||
An IPv6 address MUST be escaped if accompanied by a port,
|
||||
because otherwise ambiguity ensues: 2001:db8:85a3::8a2e:370:7334
|
||||
means both [2001:db8:85a3::8a2e:370:7334] and
|
||||
[2001:db8:85a3::8a2e:370]:7334.
|
||||
|
||||
>>> parse_host_port('server01:80')
|
||||
('server01', 80)
|
||||
>>> parse_host_port('server01')
|
||||
('server01', None)
|
||||
>>> parse_host_port('server01', default_port=1234)
|
||||
('server01', 1234)
|
||||
>>> parse_host_port('[::1]:80')
|
||||
('::1', 80)
|
||||
>>> parse_host_port('[::1]')
|
||||
('::1', None)
|
||||
>>> parse_host_port('[::1]', default_port=1234)
|
||||
('::1', 1234)
|
||||
>>> parse_host_port('2001:db8:85a3::8a2e:370:7334', default_port=1234)
|
||||
('2001:db8:85a3::8a2e:370:7334', 1234)
|
||||
>>> parse_host_port(None)
|
||||
(None, None)
|
||||
"""
|
||||
if not address:
|
||||
return (None, None)
|
||||
|
||||
if address[0] == '[':
|
||||
# Escaped ipv6
|
||||
_host, _port = address[1:].split(']')
|
||||
host = _host
|
||||
if ':' in _port:
|
||||
port = _port.split(':')[1]
|
||||
else:
|
||||
port = default_port
|
||||
else:
|
||||
if address.count(':') == 1:
|
||||
host, port = address.split(':')
|
||||
else:
|
||||
# 0 means ipv4, >1 means ipv6.
|
||||
# We prohibit unescaped ipv6 addresses with port.
|
||||
host = address
|
||||
port = default_port
|
||||
|
||||
return (host, None if port is None else int(port))
|
||||
|
||||
|
||||
class ModifiedSplitResult(parse.SplitResult):
|
||||
"""Split results class for urlsplit."""
|
||||
|
||||
# NOTE(dims): The functions below are needed for Python 2.6.x.
|
||||
# We can remove these when we drop support for 2.6.x.
|
||||
@property
|
||||
def hostname(self):
|
||||
netloc = self.netloc.split('@', 1)[-1]
|
||||
host, port = parse_host_port(netloc)
|
||||
return host
|
||||
|
||||
@property
|
||||
def port(self):
|
||||
netloc = self.netloc.split('@', 1)[-1]
|
||||
host, port = parse_host_port(netloc)
|
||||
return port
|
||||
|
||||
|
||||
def urlsplit(url, scheme='', allow_fragments=True):
|
||||
"""Parse a URL using urlparse.urlsplit(), splitting query and fragments.
|
||||
This function papers over Python issue9374 when needed.
|
||||
|
||||
The parameters are the same as urlparse.urlsplit.
|
||||
"""
|
||||
scheme, netloc, path, query, fragment = parse.urlsplit(
|
||||
url, scheme, allow_fragments)
|
||||
if allow_fragments and '#' in path:
|
||||
path, fragment = path.split('#', 1)
|
||||
if '?' in path:
|
||||
path, query = path.split('?', 1)
|
||||
return ModifiedSplitResult(scheme, netloc,
|
||||
path, query, fragment)
|
||||
|
||||
|
||||
def set_tcp_keepalive(sock, tcp_keepalive=True,
|
||||
tcp_keepidle=None,
|
||||
tcp_keepalive_interval=None,
|
||||
tcp_keepalive_count=None):
|
||||
"""Set values for tcp keepalive parameters
|
||||
|
||||
This function configures tcp keepalive parameters if users wish to do
|
||||
so.
|
||||
|
||||
:param tcp_keepalive: Boolean, turn on or off tcp_keepalive. If users are
|
||||
not sure, this should be True, and default values will be used.
|
||||
|
||||
:param tcp_keepidle: time to wait before starting to send keepalive probes
|
||||
:param tcp_keepalive_interval: time between successive probes, once the
|
||||
initial wait time is over
|
||||
:param tcp_keepalive_count: number of probes to send before the connection
|
||||
is killed
|
||||
"""
|
||||
|
||||
# NOTE(praneshp): Despite keepalive being a tcp concept, the level is
|
||||
# still SOL_SOCKET. This is a quirk.
|
||||
if isinstance(tcp_keepalive, bool):
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, tcp_keepalive)
|
||||
else:
|
||||
raise TypeError("tcp_keepalive must be a boolean")
|
||||
|
||||
if not tcp_keepalive:
|
||||
return
|
||||
|
||||
# These options aren't available in the OS X version of eventlet,
|
||||
# Idle + Count * Interval effectively gives you the total timeout.
|
||||
if tcp_keepidle is not None:
|
||||
if hasattr(socket, 'TCP_KEEPIDLE'):
|
||||
sock.setsockopt(socket.IPPROTO_TCP,
|
||||
socket.TCP_KEEPIDLE,
|
||||
tcp_keepidle)
|
||||
else:
|
||||
LOG.warning(_LW('tcp_keepidle not available on your system'))
|
||||
if tcp_keepalive_interval is not None:
|
||||
if hasattr(socket, 'TCP_KEEPINTVL'):
|
||||
sock.setsockopt(socket.IPPROTO_TCP,
|
||||
socket.TCP_KEEPINTVL,
|
||||
tcp_keepalive_interval)
|
||||
else:
|
||||
LOG.warning(_LW('tcp_keepintvl not available on your system'))
|
||||
if tcp_keepalive_count is not None:
|
||||
if hasattr(socket, 'TCP_KEEPCNT'):
|
||||
sock.setsockopt(socket.IPPROTO_TCP,
|
||||
socket.TCP_KEEPCNT,
|
||||
tcp_keepalive_count)
|
||||
else:
|
||||
LOG.warning(_LW('tcp_keepknt not available on your system'))
|
|
@ -13,9 +13,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo.utils import netutils
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
from sahara.openstack.common import network_utils
|
||||
from sahara.plugins.general import exceptions as ex
|
||||
|
||||
|
||||
|
@ -53,9 +53,9 @@ def generate_fqdn_host_names(nodes):
|
|||
def get_port_from_address(address):
|
||||
parse_result = urlparse.urlparse(address)
|
||||
# urlparse do not parse values like 0.0.0.0:8000,
|
||||
# network_utils do not parse values like http://localhost:8000,
|
||||
# netutils do not parse values like http://localhost:8000,
|
||||
# so combine approach is using
|
||||
if parse_result.port:
|
||||
return parse_result.port
|
||||
else:
|
||||
return network_utils.parse_host_port(address)[1]
|
||||
return netutils.parse_host_port(address)[1]
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
import os
|
||||
|
||||
from oslo.utils import timeutils
|
||||
import six
|
||||
|
||||
from sahara import context
|
||||
from sahara.openstack.common import timeutils
|
||||
from sahara.plugins.general import exceptions as ex
|
||||
from sahara.plugins.general import utils
|
||||
from sahara.plugins.spark import config_helper as c_helper
|
||||
|
|
|
@ -13,8 +13,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo.utils import timeutils
|
||||
|
||||
from sahara import context
|
||||
from sahara.openstack.common import timeutils
|
||||
from sahara.plugins.general import exceptions as ex
|
||||
from sahara.plugins.general import utils as u
|
||||
from sahara.plugins.vanilla.hadoop2 import config
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
import os
|
||||
|
||||
from oslo.utils import timeutils
|
||||
import six
|
||||
|
||||
from sahara import context
|
||||
from sahara.openstack.common import timeutils
|
||||
from sahara.plugins.general import exceptions as ex
|
||||
from sahara.plugins.general import utils
|
||||
from sahara.plugins.vanilla.v1_2_1 import config_helper
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
# limitations under the License.
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo.utils import excutils
|
||||
import six
|
||||
from six.moves.urllib import parse as urlparse
|
||||
|
||||
from sahara import conductor as c
|
||||
from sahara import context
|
||||
from sahara.openstack.common import excutils
|
||||
from sahara.openstack.common import log as logging
|
||||
from sahara.plugins import base as plugin_base
|
||||
from sahara.plugins import provisioning
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
from novaclient import exceptions as nova_exceptions
|
||||
from oslo.config import cfg
|
||||
from oslo.utils import excutils
|
||||
import six
|
||||
|
||||
from sahara import conductor as c
|
||||
|
@ -23,7 +24,6 @@ from sahara import exceptions as exc
|
|||
from sahara.i18n import _
|
||||
from sahara.i18n import _LI
|
||||
from sahara.i18n import _LW
|
||||
from sahara.openstack.common import excutils
|
||||
from sahara.openstack.common import log as logging
|
||||
from sahara.service import engine as e
|
||||
from sahara.service import networks
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
from heatclient import exc as heat_exc
|
||||
from oslo.config import cfg
|
||||
from oslo.utils import excutils
|
||||
import six
|
||||
|
||||
from sahara import conductor as c
|
||||
|
@ -22,7 +23,6 @@ from sahara import context
|
|||
from sahara.i18n import _LE
|
||||
from sahara.i18n import _LI
|
||||
from sahara.i18n import _LW
|
||||
from sahara.openstack.common import excutils
|
||||
from sahara.openstack.common import log as logging
|
||||
from sahara.service import engine as e
|
||||
from sahara.service import volumes
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
import random
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo.utils import timeutils
|
||||
import six
|
||||
|
||||
from sahara import conductor as c
|
||||
|
@ -24,7 +25,6 @@ from sahara.i18n import _LI
|
|||
from sahara.openstack.common import log
|
||||
from sahara.openstack.common import periodic_task
|
||||
from sahara.openstack.common import threadgroup
|
||||
from sahara.openstack.common import timeutils
|
||||
from sahara.service import api
|
||||
from sahara.service.edp import job_manager
|
||||
from sahara.service import trusts
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
from oslo.config import cfg
|
||||
from oslo.utils import timeutils as tu
|
||||
|
||||
from sahara import conductor as c
|
||||
from sahara import context
|
||||
|
@ -22,7 +23,6 @@ from sahara.i18n import _
|
|||
from sahara.i18n import _LE
|
||||
from sahara.i18n import _LW
|
||||
from sahara.openstack.common import log as logging
|
||||
from sahara.openstack.common import timeutils as tu
|
||||
from sahara.utils.openstack import cinder
|
||||
from sahara.utils.openstack import nova
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import fixtures
|
|||
from keystoneclient.v2_0 import client as keystone_client
|
||||
from neutronclient.v2_0 import client as neutron_client
|
||||
from novaclient.v1_1 import client as nova_client
|
||||
from oslo.utils import excutils
|
||||
from oslotest import base
|
||||
from saharaclient.api import base as client_base
|
||||
import saharaclient.client as sahara_client
|
||||
|
@ -29,7 +30,6 @@ import six
|
|||
from swiftclient import client as swift_client
|
||||
from testtools import testcase
|
||||
|
||||
from sahara.openstack.common import excutils
|
||||
from sahara.tests.integration.configs import config as cfg
|
||||
import sahara.utils.openstack.images as imgs
|
||||
from sahara.utils import ssh_remote
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from sahara.openstack.common import excutils
|
||||
from oslo.utils import excutils
|
||||
|
||||
from sahara.tests.integration.tests import base
|
||||
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ import time
|
|||
import uuid
|
||||
|
||||
import fixtures
|
||||
from oslo.utils import excutils
|
||||
|
||||
from sahara.openstack.common import excutils
|
||||
from sahara.swift import swift_helper as sw
|
||||
from sahara.tests.integration.tests import base
|
||||
from sahara.utils import edp
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo.utils import excutils
|
||||
from testtools import testcase
|
||||
|
||||
from sahara.openstack.common import excutils
|
||||
from sahara.tests.integration.configs import config as cfg
|
||||
from sahara.tests.integration.tests import cinder
|
||||
from sahara.tests.integration.tests import edp
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo.utils import excutils
|
||||
from testtools import testcase
|
||||
|
||||
from sahara.openstack.common import excutils
|
||||
from sahara.tests.integration.configs import config as cfg
|
||||
from sahara.tests.integration.tests import cinder
|
||||
from sahara.tests.integration.tests import cluster_configs
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from sahara.openstack.common import excutils
|
||||
from oslo.utils import excutils
|
||||
|
||||
from sahara.tests.integration.tests import base
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from sahara.openstack.common import excutils
|
||||
from oslo.utils import excutils
|
||||
|
||||
from sahara.tests.integration.tests import base
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
|
||||
import uuid
|
||||
|
||||
from sahara.openstack.common import excutils
|
||||
from oslo.utils import excutils
|
||||
|
||||
from sahara.tests.integration.tests import base
|
||||
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
import time
|
||||
|
||||
from oslo.utils import timeutils
|
||||
import saharaclient.api.base as sab
|
||||
|
||||
from sahara.openstack.common import timeutils
|
||||
from sahara.tests.integration.tests import base
|
||||
from sahara.tests.integration.tests import edp
|
||||
from sahara.utils import edp as utils_edp
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
import datetime
|
||||
|
||||
import mock
|
||||
from oslo.utils import timeutils
|
||||
|
||||
from sahara.conductor import manager
|
||||
from sahara import context
|
||||
from sahara.openstack.common import timeutils
|
||||
import sahara.service.periodic as p
|
||||
import sahara.tests.unit.base as base
|
||||
from sahara.tests.unit.conductor.manager import test_clusters as tc
|
||||
|
@ -51,7 +51,7 @@ class TestPeriodicBack(base.SaharaWithDbTestCase):
|
|||
get_job_status.assert_has_calls([mock.call(u'2'),
|
||||
mock.call(u'3')])
|
||||
|
||||
@mock.patch('sahara.openstack.common.timeutils.utcnow')
|
||||
@mock.patch('oslo.utils.timeutils.utcnow')
|
||||
@mock.patch('sahara.service.api.terminate_cluster')
|
||||
def test_cluster_terminate(self, terminate_cluster, utcnow):
|
||||
|
||||
|
@ -83,7 +83,7 @@ class TestPeriodicBack(base.SaharaWithDbTestCase):
|
|||
self.assertEqual(terminate_cluster.call_count, 1)
|
||||
terminate_cluster.assert_has_calls([mock.call(u'1')])
|
||||
|
||||
@mock.patch('sahara.openstack.common.timeutils.utcnow')
|
||||
@mock.patch('oslo.utils.timeutils.utcnow')
|
||||
@mock.patch('sahara.service.api.terminate_cluster')
|
||||
def test_cluster_not_killed_too_early(self, terminate_cluster, utcnow):
|
||||
|
||||
|
@ -96,7 +96,7 @@ class TestPeriodicBack(base.SaharaWithDbTestCase):
|
|||
p.SaharaPeriodicTasks().terminate_unneeded_clusters(None)
|
||||
self.assertEqual(terminate_cluster.call_count, 0)
|
||||
|
||||
@mock.patch('sahara.openstack.common.timeutils.utcnow')
|
||||
@mock.patch('oslo.utils.timeutils.utcnow')
|
||||
@mock.patch('sahara.service.api.terminate_cluster')
|
||||
def test_cluster_killed_in_time(self, terminate_cluster, utcnow):
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ import uuid
|
|||
from eventlet import semaphore
|
||||
from eventlet import timeout as e_timeout
|
||||
from oslo.config import cfg
|
||||
from oslo.utils import excutils
|
||||
import paramiko
|
||||
import requests
|
||||
import six
|
||||
|
@ -46,7 +47,6 @@ from sahara import context
|
|||
from sahara import exceptions as ex
|
||||
from sahara.i18n import _
|
||||
from sahara.i18n import _LE
|
||||
from sahara.openstack.common import excutils
|
||||
from sahara.utils import crypto
|
||||
from sahara.utils import hashabledict as h
|
||||
from sahara.utils.openstack import base
|
||||
|
|
Loading…
Reference in New Issue