diff --git a/ovsdbapp/api.py b/ovsdbapp/api.py index ffe0cf1f..1c43cb34 100644 --- a/ovsdbapp/api.py +++ b/ovsdbapp/api.py @@ -14,17 +14,10 @@ import abc import contextlib - -import six -try: - # Python 3 no longer has thread module - import thread # noqa -except ImportError: - import threading as thread +import threading -@six.add_metaclass(abc.ABCMeta) -class Command(object): +class Command(object, metaclass=abc.ABCMeta): """An OVSDB command that can be executed in a transaction :attr result: The result of executing the command in a transaction @@ -41,8 +34,7 @@ class Command(object): """ -@six.add_metaclass(abc.ABCMeta) -class Transaction(object): +class Transaction(object, metaclass=abc.ABCMeta): @abc.abstractmethod def commit(self): """Commit the transaction to OVSDB""" @@ -69,8 +61,7 @@ class Transaction(object): self.result = self.commit() -@six.add_metaclass(abc.ABCMeta) -class API(object): +class API(object, metaclass=abc.ABCMeta): def __init__(self, nested_transactions=True): # Mapping between a (green)thread and its transaction. self._nested_txns = nested_transactions @@ -105,7 +96,7 @@ class API(object): # ojbect() is unique, so if we are not nested, this will always result # in a KeyError on lookup and so a unique Transaction nested = nested and self._nested_txns - cur_thread_id = thread.get_ident() if nested else object() + cur_thread_id = threading.get_ident() if nested else object() if cur_thread_id in self._nested_txns_map: yield self._nested_txns_map[cur_thread_id] diff --git a/ovsdbapp/backend/ovs_idl/command.py b/ovsdbapp/backend/ovs_idl/command.py index 12988b2c..6b9a940c 100644 --- a/ovsdbapp/backend/ovs_idl/command.py +++ b/ovsdbapp/backend/ovs_idl/command.py @@ -15,8 +15,6 @@ import collections import logging -import six - from ovsdbapp import api from ovsdbapp.backend.ovs_idl import idlutils from ovsdbapp.backend.ovs_idl import rowview @@ -162,7 +160,7 @@ class DbAddCommand(BaseCommand): # Since this operation depends on the previous value, verify() # must be called. field = getattr(record, self.column, {}) - for k, v in six.iteritems(value): + for k, v in value.items(): if k in field: continue field[k] = v diff --git a/ovsdbapp/backend/ovs_idl/connection.py b/ovsdbapp/backend/ovs_idl/connection.py index 347f95c9..3cc676fb 100644 --- a/ovsdbapp/backend/ovs_idl/connection.py +++ b/ovsdbapp/backend/ovs_idl/connection.py @@ -14,12 +14,12 @@ import logging import os +import queue import threading import traceback from ovs.db import idl from ovs import poller -from six.moves import queue as Queue from ovsdbapp.backend.ovs_idl import idlutils from ovsdbapp import exceptions @@ -32,7 +32,7 @@ else: LOG = logging.getLogger(__name__) -class TransactionQueue(Queue.Queue, object): +class TransactionQueue(queue.Queue, object): def __init__(self, *args, **kwargs): super(TransactionQueue, self).__init__(*args, **kwargs) self._wait_queue = connection_utils.WaitQueue( @@ -41,7 +41,7 @@ class TransactionQueue(Queue.Queue, object): def get_nowait(self, *args, **kwargs): try: result = super(TransactionQueue, self).get_nowait(*args, **kwargs) - except Queue.Empty: + except queue.Empty: return None self._wait_queue.alert_notification_consume() return result @@ -142,7 +142,7 @@ class Connection(object): # run when we are started try: self.txns.put(txn, timeout=self.timeout) - except Queue.Full: + except queue.Full: raise exceptions.TimeoutException(commands=txn.commands, timeout=self.timeout) diff --git a/ovsdbapp/backend/ovs_idl/idlutils.py b/ovsdbapp/backend/ovs_idl/idlutils.py index 505fa798..ab924b10 100644 --- a/ovsdbapp/backend/ovs_idl/idlutils.py +++ b/ovsdbapp/backend/ovs_idl/idlutils.py @@ -23,7 +23,6 @@ from ovs.db import idl from ovs import jsonrpc from ovs import poller from ovs import stream -import six from ovsdbapp import api from ovsdbapp import exceptions @@ -210,7 +209,7 @@ def condition_match(row, condition): # I haven't investigated the reason for the patch that # added this code, but for now I check string_types if type(match) is not type(val) and not all( - isinstance(x, six.string_types) for x in (match, val)): + isinstance(x, str) for x in (match, val)): # Types of 'val' and 'match' arguments MUST match in all cases with 2 # exceptions: # - 'match' is an empty list and column's type is optional; @@ -294,11 +293,11 @@ def db_replace_record(obj): api.Command object. """ if isinstance(obj, collections.Mapping): - for k, v in six.iteritems(obj): + for k, v in obj.items(): if isinstance(v, api.Command): obj[k] = v.result elif (isinstance(obj, collections.Sequence) and - not isinstance(obj, six.string_types)): + not isinstance(obj, str)): for i, v in enumerate(obj): if isinstance(v, api.Command): try: diff --git a/ovsdbapp/backend/ovs_idl/linux/connection_utils.py b/ovsdbapp/backend/ovs_idl/linux/connection_utils.py index fa8f480f..61616824 100644 --- a/ovsdbapp/backend/ovs_idl/linux/connection_utils.py +++ b/ovsdbapp/backend/ovs_idl/linux/connection_utils.py @@ -14,8 +14,6 @@ import os -import six - from ovsdbapp.backend.ovs_idl.common import base_connection_utils @@ -31,7 +29,7 @@ class WaitQueue(base_connection_utils.WaitQueue): self.alertin.read(1) def alert_notify(self): - self.alertout.write(six.b('X')) + self.alertout.write('X'.encode("latin-1")) self.alertout.flush() @property diff --git a/ovsdbapp/backend/ovs_idl/transaction.py b/ovsdbapp/backend/ovs_idl/transaction.py index 26308f68..74c12b09 100644 --- a/ovsdbapp/backend/ovs_idl/transaction.py +++ b/ovsdbapp/backend/ovs_idl/transaction.py @@ -13,10 +13,10 @@ # under the License. import logging +import queue import time from ovs.db import idl -from six.moves import queue as Queue from ovsdbapp import api from ovsdbapp.backend.ovs_idl import idlutils @@ -32,7 +32,7 @@ class Transaction(api.Transaction): self.check_error = check_error self.log_errors = log_errors self.commands = [] - self.results = Queue.Queue(1) + self.results = queue.Queue(1) self.ovsdb_connection = ovsdb_connection self.timeout = timeout or ovsdb_connection.timeout @@ -52,7 +52,7 @@ class Transaction(api.Transaction): self.ovsdb_connection.queue_txn(self) try: result = self.results.get(timeout=self.timeout) - except Queue.Empty: + except queue.Empty: raise exceptions.TimeoutException(commands=self.commands, timeout=self.timeout) if isinstance(result, idlutils.ExceptionResult): diff --git a/ovsdbapp/event.py b/ovsdbapp/event.py index 285fc896..963e6e1d 100644 --- a/ovsdbapp/event.py +++ b/ovsdbapp/event.py @@ -13,17 +13,14 @@ import abc import atexit import logging +import queue import threading -import six -from six.moves import queue as Queue - LOG = logging.getLogger(__name__) STOP_EVENT = ("STOP", None, None, None) -@six.add_metaclass(abc.ABCMeta) -class RowEvent(object): +class RowEvent(object, metaclass=abc.ABCMeta): ROW_CREATE = "create" ROW_UPDATE = "update" ROW_DELETE = "delete" @@ -98,7 +95,7 @@ class RowEventHandler(object): def __init__(self): self.__watched_events = set() self.__lock = threading.Lock() - self.notifications = Queue.Queue() + self.notifications = queue.Queue() self.notify_thread = threading.Thread(target=self.notify_loop) self.notify_thread.daemon = True atexit.register(self.shutdown) diff --git a/ovsdbapp/exceptions.py b/ovsdbapp/exceptions.py index 94de1ff9..f1f0f8c8 100644 --- a/ovsdbapp/exceptions.py +++ b/ovsdbapp/exceptions.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - class OvsdbAppException(RuntimeError): """Base OvsdbApp Exception. @@ -34,10 +32,6 @@ class OvsdbAppException(RuntimeError): # at least get the core message out if something happened super(OvsdbAppException, self).__init__(self.message) - if six.PY2: - def __unicode__(self): - return unicode(self.msg) # noqa pylint: disable=undefined-variable - def __str__(self): return self.msg diff --git a/ovsdbapp/schema/open_vswitch/api.py b/ovsdbapp/schema/open_vswitch/api.py index c12ce701..c9f499d3 100644 --- a/ovsdbapp/schema/open_vswitch/api.py +++ b/ovsdbapp/schema/open_vswitch/api.py @@ -14,13 +14,10 @@ import abc -import six - from ovsdbapp import api -@six.add_metaclass(abc.ABCMeta) -class API(api.API): +class API(api.API, metaclass=abc.ABCMeta): @abc.abstractmethod def add_manager(self, connection_uri): """Create a command to add a Manager to the OVS switch diff --git a/ovsdbapp/schema/ovn_northbound/api.py b/ovsdbapp/schema/ovn_northbound/api.py index 6b9c6a34..7e1d44da 100644 --- a/ovsdbapp/schema/ovn_northbound/api.py +++ b/ovsdbapp/schema/ovn_northbound/api.py @@ -12,14 +12,11 @@ import abc -import six - from ovsdbapp import api from ovsdbapp import constants as const -@six.add_metaclass(abc.ABCMeta) -class API(api.API): +class API(api.API, metaclass=abc.ABCMeta): """An API based off of the ovn-nbctl CLI interface This API basically mirrors the ovn-nbctl operations with these changes: diff --git a/ovsdbapp/schema/ovn_southbound/api.py b/ovsdbapp/schema/ovn_southbound/api.py index cc3106e8..74179f4b 100644 --- a/ovsdbapp/schema/ovn_southbound/api.py +++ b/ovsdbapp/schema/ovn_southbound/api.py @@ -12,13 +12,10 @@ import abc -import six - from ovsdbapp import api -@six.add_metaclass(abc.ABCMeta) -class API(api.API): +class API(api.API, metaclass=abc.ABCMeta): """An API based off of the ovn-sbctl CLI interface This API basically mirrors the ovn-nbctl operations with these changes: diff --git a/requirements.txt b/requirements.txt index ff6ceb46..153b5ff0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,3 @@ fixtures>=3.0.0 # Apache-2.0/BSD netaddr>=0.7.18 # BSD ovs>=2.8.0 # Apache-2.0 pbr!=2.1.0,>=2.0.0 # Apache-2.0 -six>=1.10.0 # MIT diff --git a/tools/debug_venv.py b/tools/debug_venv.py index 78d09003..cee9fb06 100755 --- a/tools/debug_venv.py +++ b/tools/debug_venv.py @@ -14,7 +14,6 @@ from __future__ import print_function import atexit import os -import six import subprocess import sys @@ -22,6 +21,19 @@ from fixtures import fixture from ovsdbapp import venv + +def reraise(tp, value, tb=None): + try: + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + finally: + value = None + tb = None + + if len(sys.argv) != 4: print("Requires three arguments: venvdir ovsdir ovndir", file=sys.stderr) sys.exit(1) @@ -40,7 +52,7 @@ try: atexit.register(v.cleanUp) v.setUp() except fixture.MultipleExceptions as e: - six.reraise(*e.args[0]) + reraise(*e.args[0]) try: print("*** Exit the shell when finished debugging ***") subprocess.call([os.getenv('SHELL'), '-i'], env=v.env) diff --git a/tox.ini b/tox.ini index 5b85469d..0803ce59 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,7 @@ skipsdist = True ignore_basepython_conflict = True [testenv] +basepython = python3 usedevelop = True setenv = VIRTUAL_ENV={envdir} @@ -18,7 +19,6 @@ deps = commands = stestr run --slowest {posargs} [testenv:pep8] -basepython= python3 commands = flake8 {toxinidir}/tools/coding-checks.sh --all '{posargs}'