Skip to content

Commit

Permalink
Remove "six" library
Browse files Browse the repository at this point in the history
Last step to remove "six" library usage in Neutron.

Change-Id: Idd42e0c51c8c3bd598c9cf91602596be238bccae
  • Loading branch information
ralonsoh committed Jul 28, 2020
1 parent 69cac6c commit ddd5832
Show file tree
Hide file tree
Showing 59 changed files with 218 additions and 191 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ ignore-iface-methods=
deprecated-modules=
# should use oslo_serialization.jsonutils
json
six

[TYPECHECK]
# List of module names for which member attributes should not be checked
ignored-modules=six.moves,_MovedItems
ignored-modules=_MovedItems

[REPORTS]
# Tells whether to display a full report or only the messages
Expand Down
1 change: 1 addition & 0 deletions HACKING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Below you can find a list of checks specific to this repository.
with [obj for obj in data if test(obj)].
- [N346] Use neutron_lib.db.api.sqla_listen rather than sqlalchemy
- [N347] Test code must not import mock library
- [N348] Test code must not import six library

.. note::
When adding a new hacking check to this repository or ``neutron-lib``, make
Expand Down
1 change: 0 additions & 1 deletion lower-constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ requestsexceptions==1.2.0
rfc3986==0.3.1
Routes==2.3.1
simplejson==3.5.1
six==1.10.0
smmap==0.9.0
snowballstemmer==1.2.1
sqlalchemy-migrate==0.11.0
Expand Down
10 changes: 5 additions & 5 deletions neutron/agent/common/ovs_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# under the License.

import collections
import functools
import itertools
import operator
import random
Expand All @@ -30,7 +31,6 @@
from ovsdbapp.backend.ovs_idl import idlutils

import debtcollector
import six
import tenacity

from neutron._i18n import _
Expand Down Expand Up @@ -87,7 +87,7 @@ def _ovsdb_retry(fn):
The instance's ovsdb_timeout is used as the max waiting time. This relies
on the fact that instance methods receive self as the first argument.
"""
@six.wraps(fn)
@functools.wraps(fn)
def wrapped(*args, **kwargs):
self = args[0]
new_fn = tenacity.retry(
Expand Down Expand Up @@ -1041,11 +1041,11 @@ def _update_queue(self, port_id, queue_num, max_kbps=None,
max_burst_kbps=None, min_kbps=None):
other_config = {}
if max_kbps:
other_config[six.u('max-rate')] = six.u(str(max_kbps * 1000))
other_config['max-rate'] = str(max_kbps * 1000)
if max_burst_kbps:
other_config[six.u('burst')] = six.u(str(max_burst_kbps * 1000))
other_config['burst'] = str(max_burst_kbps * 1000)
if min_kbps:
other_config[six.u('min-rate')] = six.u(str(min_kbps * 1000))
other_config['min-rate'] = str(min_kbps * 1000)

queue = self._find_queue(port_id)
if queue and queue['_uuid']:
Expand Down
6 changes: 3 additions & 3 deletions neutron/agent/common/resource_processing_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#

import datetime
import queue
import time

from oslo_utils import timeutils
from oslo_utils import uuidutils
from six.moves import queue as Queue


class ResourceUpdate(object):
Expand Down Expand Up @@ -110,7 +110,7 @@ def __init__(self, id):

if id not in self._masters:
self._masters[id] = self
self._queue = Queue.PriorityQueue(-1)
self._queue = queue.PriorityQueue(-1)

self._master = self._masters[id]

Expand Down Expand Up @@ -162,7 +162,7 @@ def updates(self):
class ResourceProcessingQueue(object):
"""Manager of the queue of resources to process."""
def __init__(self):
self._queue = Queue.PriorityQueue()
self._queue = queue.PriorityQueue()

def add(self, update):
update.tries -= 1
Expand Down
6 changes: 3 additions & 3 deletions neutron/agent/dhcp/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# under the License.

import collections
import functools
import os
import threading

Expand All @@ -32,7 +33,6 @@
from oslo_utils import fileutils
from oslo_utils import importutils
from oslo_utils import timeutils
import six

from neutron._i18n import _
from neutron.agent.common import resource_processing_queue as queue
Expand All @@ -57,7 +57,7 @@

def _sync_lock(f):
"""Decorator to block all operations for a global sync call."""
@six.wraps(f)
@functools.wraps(f)
def wrapped(*args, **kwargs):
with _SYNC_STATE_LOCK.write_lock():
return f(*args, **kwargs)
Expand All @@ -66,7 +66,7 @@ def wrapped(*args, **kwargs):

def _wait_if_syncing(f):
"""Decorator to wait if any sync operations are in progress."""
@six.wraps(f)
@functools.wraps(f)
def wrapped(*args, **kwargs):
with _SYNC_STATE_LOCK.read_lock():
return f(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion neutron/agent/l3/keepalived_state_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# under the License.

import os
import queue
import sys
import threading

import httplib2
import netaddr
from oslo_config import cfg
from oslo_log import log as logging
from six.moves import queue

from neutron._i18n import _
from neutron.agent.l3 import ha
Expand Down
3 changes: 1 addition & 2 deletions neutron/agent/linux/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from neutron_lib import exceptions
from oslo_log import log as logging
import setproctitle
import six

from neutron._i18n import _

Expand Down Expand Up @@ -138,7 +137,7 @@ def unlock(self):

def write(self, pid):
os.ftruncate(self.fd, 0)
os.write(self.fd, six.b("%s" % pid))
os.write(self.fd, bytes("%s" % pid, 'utf-8'))
os.fsync(self.fd)

def read(self):
Expand Down
8 changes: 4 additions & 4 deletions neutron/agent/linux/dhcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import abc
import collections
import copy
import io
import itertools
import os
import re
Expand All @@ -33,7 +34,6 @@
from oslo_utils import fileutils
from oslo_utils import netutils
from oslo_utils import uuidutils
import six

from neutron._i18n import _
from neutron.agent.common import utils as agent_common_utils
Expand Down Expand Up @@ -765,7 +765,7 @@ def _output_init_lease_file(self):
epoch-timestamp mac_addr ip_addr hostname client-ID
"""
filename = self.get_conf_file_name('leases')
buf = six.StringIO()
buf = io.StringIO()

LOG.debug('Building initial lease file: %s', filename)
# we make up a lease time for the database entry
Expand Down Expand Up @@ -822,7 +822,7 @@ def _output_hosts_file(self):
should receive a dhcp lease, the hosts resolution in itself is
defined by the `_output_addn_hosts_file` method.
"""
buf = six.StringIO()
buf = io.StringIO()
filename = self.get_conf_file_name('host')

LOG.debug('Building host file: %s', filename)
Expand Down Expand Up @@ -1061,7 +1061,7 @@ def _output_addn_hosts_file(self):
Each line in this file is in the same form as a standard /etc/hosts
file.
"""
buf = six.StringIO()
buf = io.StringIO()
for host_tuple in self._iter_hosts():
port, alloc, hostname, fqdn, no_dhcp, no_opts, tag = host_tuple
# It is compulsory to write the `fqdn` before the `hostname` in
Expand Down
6 changes: 3 additions & 3 deletions neutron/agent/linux/dibbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import io
import os
import shutil

Expand All @@ -21,7 +22,6 @@
from neutron_lib.utils import file as file_utils
from oslo_config import cfg
from oslo_log import log as logging
import six

from neutron.agent.linux import external_process
from neutron.agent.linux import pd
Expand Down Expand Up @@ -86,15 +86,15 @@ def _is_dibbler_client_running(self):
def _generate_dibbler_conf(self, ex_gw_ifname, lla, hint_prefix):
dcwa = self.dibbler_client_working_area
script_path = utils.get_conf_file_name(dcwa, 'notify', 'sh', True)
buf = six.StringIO()
buf = io.StringIO()
buf.write('%s' % SCRIPT_TEMPLATE.render(
prefix_path=self.prefix_path,
l3_agent_pid=os.getpid()))
file_utils.replace_file(script_path, buf.getvalue())
os.chmod(script_path, 0o744)

dibbler_conf = utils.get_conf_file_name(dcwa, 'client', 'conf', False)
buf = six.StringIO()
buf = io.StringIO()
buf.write('%s' % CONFIG_TEMPLATE.render(
enterprise_number=cfg.CONF.vendor_pen,
va_id='0x%s' % self.converted_subnet_id,
Expand Down
11 changes: 5 additions & 6 deletions neutron/agent/linux/pd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from neutron_lib.utils import runtime
from oslo_log import log as logging
from oslo_utils import netutils
import six
from stevedore import driver

from neutron.common import utils
Expand Down Expand Up @@ -121,7 +120,7 @@ def add_gw_interface(self, router_id, gw_ifname):
if not self._is_pd_master_router(router):
return
prefix_update = {}
for pd_info in six.itervalues(router['subnets']):
for pd_info in router['subnets'].values():
# gateway is added after internal router ports.
# If a PD is being synced, and if the prefix is available,
# send update if prefix out of sync; If not available,
Expand Down Expand Up @@ -169,7 +168,7 @@ def get_preserve_ips(self, router_id):
preserve_ips = []
router = self.routers.get(router_id)
if router is not None:
for pd_info in six.itervalues(router['subnets']):
for pd_info in router['subnets'].values():
preserve_ips.append(pd_info.get_bind_lla_with_mask())
return preserve_ips

Expand All @@ -184,7 +183,7 @@ def remove_stale_ri_ifname(self, router_id, stale_ifname):
router = self.routers.get(router_id)
if router is not None:
subnet_to_delete = None
for subnet_id, pd_info in six.iteritems(router['subnets']):
for subnet_id, pd_info in router['subnets'].items():
if pd_info.ri_ifname == stale_ifname:
self._delete_pd(router, pd_info)
subnet_to_delete = subnet_id
Expand Down Expand Up @@ -268,11 +267,11 @@ def process_ha_state(self, router_id, master):

router['master'] = master
if master:
for pd_info in six.itervalues(router['subnets']):
for pd_info in router['subnets'].values():
bind_lla_with_mask = pd_info.get_bind_lla_with_mask()
self._add_lla(router, bind_lla_with_mask)
else:
for pd_info in six.itervalues(router['subnets']):
for pd_info in router['subnets'].values():
self._delete_lla(router, pd_info.get_bind_lla_with_mask())
if pd_info.client_started:
pd_info.driver.disable(self.pmon,
Expand Down
4 changes: 2 additions & 2 deletions neutron/agent/linux/ra.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import io
import os
import pwd

Expand All @@ -23,7 +24,6 @@
from neutron_lib import constants
from neutron_lib.utils import file as file_utils
from oslo_log import log as logging
import six

from neutron.agent.linux import external_process
from neutron.agent.linux import utils
Expand Down Expand Up @@ -93,7 +93,7 @@ def _generate_radvd_conf(self, router_ports):
self._router_id,
'radvd.conf',
True)
buf = six.StringIO()
buf = io.StringIO()
for p in router_ports:
subnets = p.get('subnets', [])
v6_subnets = [subnet for subnet in subnets if
Expand Down
2 changes: 1 addition & 1 deletion neutron/agent/linux/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import glob
import grp
from http import client as httplib
import os
import pwd
import shlex
Expand All @@ -32,7 +33,6 @@
from oslo_utils import encodeutils
from oslo_utils import excutils
from oslo_utils import fileutils
from six.moves import http_client as httplib

from neutron._i18n import _
from neutron.agent.linux import xenapi_root_helper
Expand Down
2 changes: 1 addition & 1 deletion neutron/agent/metadata/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import hashlib
import hmac
import urllib

from neutron_lib.agent import topics
from neutron_lib import constants
Expand All @@ -25,7 +26,6 @@
from oslo_service import loopingcall
from oslo_utils import encodeutils
import requests
from six.moves import urllib
import webob

from neutron._i18n import _
Expand Down
4 changes: 2 additions & 2 deletions neutron/agent/ovn/metadata/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import collections
import functools
import re

from neutron.agent.linux import external_process
Expand All @@ -29,7 +30,6 @@
from oslo_utils import uuidutils
from ovsdbapp.backend.ovs_idl import event as row_event
from ovsdbapp.backend.ovs_idl import vlog
import six


LOG = log.getLogger(__name__)
Expand All @@ -46,7 +46,7 @@

def _sync_lock(f):
"""Decorator to block all operations for a global sync call."""
@six.wraps(f)
@functools.wraps(f)
def wrapped(*args, **kwargs):
with _SYNC_STATE_LOCK.write_lock():
return f(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion neutron/agent/ovn/metadata/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import hashlib
import hmac
import urllib

from neutron._i18n import _
from neutron.agent.linux import utils as agent_utils
Expand All @@ -28,7 +29,6 @@
from oslo_log import log as logging
from oslo_utils import encodeutils
import requests
from six.moves import urllib
import webob


Expand Down
Loading

0 comments on commit ddd5832

Please sign in to comment.