Remove use of six library

It exists only for py2/py3 compat. We do not need it any more.

This will explicitly break Zuul v3 for python2, which is different than
simply ceasing to test it and no longer declaring we support it. Since
we're not testing it any longer, it's bound to degrade overtime without
us noticing, so hopefully a clean and explicit break will prevent people
from running under python2 and it working for a minute, then breaking
later.

Change-Id: Ia16bb399a2869ab37a183f3f2197275bb3acafee
This commit is contained in:
Monty Taylor 2017-06-16 19:31:47 -05:00
parent e7410af051
commit b934c1a052
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
22 changed files with 68 additions and 100 deletions

View File

@ -16,7 +16,6 @@ gear>=0.9.0,<1.0.0
apscheduler>=3.0 apscheduler>=3.0
PrettyTable>=0.6,<0.8 PrettyTable>=0.6,<0.8
babel>=1.0 babel>=1.0
six>=1.6.0
ansible>=2.0.0.1 ansible>=2.0.0.1
kazoo kazoo
sqlalchemy sqlalchemy

View File

@ -15,24 +15,20 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from six.moves import configparser as ConfigParser import configparser
import datetime import datetime
import gc import gc
import hashlib import hashlib
import importlib
from io import StringIO
import json import json
import logging import logging
import os import os
from six.moves import queue as Queue import queue
from six.moves import urllib
import random import random
import re import re
import select import select
import shutil import shutil
from six.moves import reload_module
try:
from cStringIO import StringIO
except Exception:
from six import StringIO
import socket import socket
import string import string
import subprocess import subprocess
@ -42,6 +38,7 @@ import threading
import traceback import traceback
import time import time
import uuid import uuid
import urllib
import git import git
@ -463,7 +460,7 @@ class FakeGerritConnection(gerritconnection.GerritConnection):
super(FakeGerritConnection, self).__init__(driver, connection_name, super(FakeGerritConnection, self).__init__(driver, connection_name,
connection_config) connection_config)
self.event_queue = Queue.Queue() self.event_queue = queue.Queue()
self.fixture_dir = os.path.join(FIXTURE_DIR, 'gerrit') self.fixture_dir = os.path.join(FIXTURE_DIR, 'gerrit')
self.change_number = 0 self.change_number = 0
self.changes = changes_db self.changes = changes_db
@ -1373,8 +1370,8 @@ class FakeGearmanServer(gear.Server):
ssl_ca=ssl_ca) ssl_ca=ssl_ca)
def getJobForConnection(self, connection, peek=False): def getJobForConnection(self, connection, peek=False):
for queue in [self.high_queue, self.normal_queue, self.low_queue]: for job_queue in [self.high_queue, self.normal_queue, self.low_queue]:
for job in queue: for job in job_queue:
if not hasattr(job, 'waiting'): if not hasattr(job, 'waiting'):
if job.name.startswith(b'executor:execute'): if job.name.startswith(b'executor:execute'):
job.waiting = self.hold_jobs_in_queue job.waiting = self.hold_jobs_in_queue
@ -1384,7 +1381,7 @@ class FakeGearmanServer(gear.Server):
continue continue
if job.name in connection.functions: if job.name in connection.functions:
if not peek: if not peek:
queue.remove(job) job_queue.remove(job)
connection.related_jobs[job.handle] = job connection.related_jobs[job.handle] = job
job.worker_connection = connection job.worker_connection = connection
job.running = True job.running = True
@ -1879,8 +1876,8 @@ class ZuulTestCase(BaseTestCase):
os.environ['STATSD_PORT'] = str(self.statsd.port) os.environ['STATSD_PORT'] = str(self.statsd.port)
self.statsd.start() self.statsd.start()
# the statsd client object is configured in the statsd module import # the statsd client object is configured in the statsd module import
reload_module(statsd) importlib.reload(statsd)
reload_module(zuul.scheduler) importlib.reload(zuul.scheduler)
self.gearman_server = FakeGearmanServer(self.use_ssl) self.gearman_server = FakeGearmanServer(self.use_ssl)
@ -2008,7 +2005,7 @@ class ZuulTestCase(BaseTestCase):
# This creates the per-test configuration object. It can be # This creates the per-test configuration object. It can be
# overriden by subclasses, but should not need to be since it # overriden by subclasses, but should not need to be since it
# obeys the config_file and tenant_config_file attributes. # obeys the config_file and tenant_config_file attributes.
self.config = ConfigParser.ConfigParser() self.config = configparser.ConfigParser()
self.config.read(os.path.join(FIXTURE_DIR, self.config_file)) self.config.read(os.path.join(FIXTURE_DIR, self.config_file))
if not self.setupSimpleLayout(): if not self.setupSimpleLayout():
@ -2383,12 +2380,12 @@ class ZuulTestCase(BaseTestCase):
return True return True
def eventQueuesEmpty(self): def eventQueuesEmpty(self):
for queue in self.event_queues: for event_queue in self.event_queues:
yield queue.empty() yield event_queue.empty()
def eventQueuesJoin(self): def eventQueuesJoin(self):
for queue in self.event_queues: for event_queue in self.event_queues:
queue.join() event_queue.join()
def waitUntilSettled(self): def waitUntilSettled(self):
self.log.debug("Waiting until settled...") self.log.debug("Waiting until settled...")
@ -2397,8 +2394,9 @@ class ZuulTestCase(BaseTestCase):
if time.time() - start > self.wait_timeout: if time.time() - start > self.wait_timeout:
self.log.error("Timeout waiting for Zuul to settle") self.log.error("Timeout waiting for Zuul to settle")
self.log.error("Queue status:") self.log.error("Queue status:")
for queue in self.event_queues: for event_queue in self.event_queues:
self.log.error(" %s: %s" % (queue, queue.empty())) self.log.error(" %s: %s" %
(event_queue, event_queue.empty()))
self.log.error("All builds waiting: %s" % self.log.error("All builds waiting: %s" %
(self.areAllBuildsWaiting(),)) (self.areAllBuildsWaiting(),))
self.log.error("All builds reported: %s" % self.log.error("All builds reported: %s" %
@ -2457,11 +2455,12 @@ class ZuulTestCase(BaseTestCase):
# Make sure there are no orphaned jobs # Make sure there are no orphaned jobs
for tenant in self.sched.abide.tenants.values(): for tenant in self.sched.abide.tenants.values():
for pipeline in tenant.layout.pipelines.values(): for pipeline in tenant.layout.pipelines.values():
for queue in pipeline.queues: for pipeline_queue in pipeline.queues:
if len(queue.queue) != 0: if len(pipeline_queue.queue) != 0:
print('pipeline %s queue %s contents %s' % ( print('pipeline %s queue %s contents %s' % (
pipeline.name, queue.name, queue.queue)) pipeline.name, pipeline_queue.name,
self.assertEqual(len(queue.queue), 0, pipeline_queue.queue))
self.assertEqual(len(pipeline_queue.queue), 0,
"Pipelines queues should be empty") "Pipelines queues should be empty")
def assertReportedStat(self, key, value=None, kind=None): def assertReportedStat(self, key, value=None, kind=None):

View File

@ -25,8 +25,8 @@ import time
from unittest import skip from unittest import skip
import git import git
from six.moves import urllib
import testtools import testtools
import urllib
import zuul.change_matcher import zuul.change_matcher
from zuul.driver.gerrit import gerritreporter from zuul.driver.gerrit import gerritreporter

View File

@ -17,8 +17,8 @@
import os import os
import json import json
import urllib
from six.moves import urllib
import webob import webob
from tests.base import ZuulTestCase, FIXTURE_DIR from tests.base import ZuulTestCase, FIXTURE_DIR

View File

@ -17,7 +17,7 @@ import os
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
from six.moves import urllib import urllib
DESCRIPTION = """Encrypt a secret for Zuul. DESCRIPTION = """Encrypt a secret for Zuul.

View File

@ -14,9 +14,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six import configparser
from six.moves import configparser as ConfigParser
import extras import extras
import io
import logging import logging
import logging.config import logging.config
import os import os
@ -48,7 +48,7 @@ def stack_dump_handler(signum, frame):
yappi.start() yappi.start()
else: else:
yappi.stop() yappi.stop()
yappi_out = six.BytesIO() yappi_out = io.BytesIO()
yappi.get_func_stats().print_all(out=yappi_out) yappi.get_func_stats().print_all(out=yappi_out)
yappi.get_thread_stats().print_all(out=yappi_out) yappi.get_thread_stats().print_all(out=yappi_out)
log.debug(yappi_out.getvalue()) log.debug(yappi_out.getvalue())
@ -69,7 +69,7 @@ class ZuulApp(object):
return "Zuul version: %s" % zuul_version_info.release_string() return "Zuul version: %s" % zuul_version_info.release_string()
def read_config(self): def read_config(self):
self.config = ConfigParser.ConfigParser() self.config = configparser.ConfigParser()
if self.args.config: if self.args.config:
locations = [self.args.config] locations = [self.args.config]
else: else:

View File

@ -15,7 +15,6 @@ from contextlib import contextmanager
import copy import copy
import os import os
import logging import logging
import six
import pprint import pprint
import textwrap import textwrap
@ -427,7 +426,7 @@ class JobParser(object):
setattr(job, a, conf[k]) setattr(job, a, conf[k])
if 'nodes' in conf: if 'nodes' in conf:
conf_nodes = conf['nodes'] conf_nodes = conf['nodes']
if isinstance(conf_nodes, six.string_types): if isinstance(conf_nodes, str):
# This references an existing named nodeset in the layout. # This references an existing named nodeset in the layout.
ns = layout.nodesets[conf_nodes] ns = layout.nodesets[conf_nodes]
else: else:
@ -576,7 +575,7 @@ class ProjectTemplateParser(object):
def _parseJobList(tenant, layout, conf, source_context, def _parseJobList(tenant, layout, conf, source_context,
start_mark, job_list): start_mark, job_list):
for conf_job in conf: for conf_job in conf:
if isinstance(conf_job, six.string_types): if isinstance(conf_job, str):
attrs = dict(name=conf_job) attrs = dict(name=conf_job)
elif isinstance(conf_job, dict): elif isinstance(conf_job, dict):
# A dictionary in a job tree may override params # A dictionary in a job tree may override params
@ -1007,7 +1006,7 @@ class TenantParser(object):
@staticmethod @staticmethod
def _getProject(source, conf, current_include): def _getProject(source, conf, current_include):
if isinstance(conf, six.string_types): if isinstance(conf, str):
# Return a project object whether conf is a dict or a str # Return a project object whether conf is a dict or a str
project = source.getProject(conf) project = source.getProject(conf)
project_include = current_include project_include = current_include
@ -1031,7 +1030,7 @@ class TenantParser(object):
def _getProjects(source, conf, current_include): def _getProjects(source, conf, current_include):
# Return a project object whether conf is a dict or a str # Return a project object whether conf is a dict or a str
projects = [] projects = []
if isinstance(conf, six.string_types): if isinstance(conf, str):
# A simple project name string # A simple project name string
projects.append(TenantParser._getProject( projects.append(TenantParser._getProject(
source, conf, current_include)) source, conf, current_include))

View File

@ -15,11 +15,9 @@
import abc import abc
import extras import extras
import six
@six.add_metaclass(abc.ABCMeta) class BaseConnection(object, metaclass=abc.ABCMeta):
class BaseConnection(object):
"""Base class for connections. """Base class for connections.
A connection is a shared object that sources, triggers and reporters can A connection is a shared object that sources, triggers and reporters can

View File

@ -14,11 +14,8 @@
import abc import abc
import six
class Driver(object, metaclass=abc.ABCMeta):
@six.add_metaclass(abc.ABCMeta)
class Driver(object):
"""A Driver is an extension component of Zuul that supports """A Driver is an extension component of Zuul that supports
interfacing with a remote system. It can support any of the following interfacing with a remote system. It can support any of the following
interfaces (but must support at least one to be useful): interfaces (but must support at least one to be useful):
@ -80,8 +77,7 @@ class Driver(object):
pass pass
@six.add_metaclass(abc.ABCMeta) class ConnectionInterface(object, metaclass=abc.ABCMeta):
class ConnectionInterface(object):
"""The Connection interface. """The Connection interface.
A driver which is able to supply a Connection should implement A driver which is able to supply a Connection should implement
@ -124,8 +120,7 @@ class ConnectionInterface(object):
pass pass
@six.add_metaclass(abc.ABCMeta) class TriggerInterface(object, metaclass=abc.ABCMeta):
class TriggerInterface(object):
"""The trigger interface. """The trigger interface.
A driver which is able to supply a trigger should implement this A driver which is able to supply a trigger should implement this
@ -167,8 +162,7 @@ class TriggerInterface(object):
pass pass
@six.add_metaclass(abc.ABCMeta) class SourceInterface(object, metaclass=abc.ABCMeta):
class SourceInterface(object):
"""The source interface to be implemented by a driver. """The source interface to be implemented by a driver.
A driver which is able to supply a Source should implement this A driver which is able to supply a Source should implement this
@ -216,8 +210,7 @@ class SourceInterface(object):
pass pass
@six.add_metaclass(abc.ABCMeta) class ReporterInterface(object, metaclass=abc.ABCMeta):
class ReporterInterface(object):
"""The reporter interface to be implemented by a driver. """The reporter interface to be implemented by a driver.
A driver which is able to supply a Reporter should implement this A driver which is able to supply a Reporter should implement this
@ -256,8 +249,7 @@ class ReporterInterface(object):
pass pass
@six.add_metaclass(abc.ABCMeta) class WrapperInterface(object, metaclass=abc.ABCMeta):
class WrapperInterface(object):
"""The wrapper interface to be implmeneted by a driver. """The wrapper interface to be implmeneted by a driver.
A driver which wraps execution of commands executed by Zuul should A driver which wraps execution of commands executed by Zuul should

View File

@ -19,11 +19,10 @@ import grp
import logging import logging
import os import os
import pwd import pwd
import shlex
import subprocess import subprocess
import sys import sys
from six.moves import shlex_quote
from zuul.driver import (Driver, WrapperInterface) from zuul.driver import (Driver, WrapperInterface)
@ -144,7 +143,7 @@ class BubblewrapDriver(Driver, WrapperInterface):
command = [x.format(**kwargs) for x in bwrap_command] command = [x.format(**kwargs) for x in bwrap_command]
self.log.debug("Bubblewrap command: %s", self.log.debug("Bubblewrap command: %s",
" ".join(shlex_quote(c) for c in command)) " ".join(shlex.quote(c) for c in command))
wrapped_popen = WrappedPopen(command, passwd_r, group_r) wrapped_popen = WrappedPopen(command, passwd_r, group_r)

View File

@ -18,11 +18,11 @@ import re
import select import select
import threading import threading
import time import time
from six.moves import queue as Queue
from six.moves import shlex_quote
import paramiko import paramiko
import logging import logging
import pprint import pprint
import shlex
import queue
import voluptuous as v import voluptuous as v
from zuul.connection import BaseConnection from zuul.connection import BaseConnection
@ -260,7 +260,7 @@ class GerritConnection(BaseConnection):
self.keyfile = self.connection_config.get('sshkey', None) self.keyfile = self.connection_config.get('sshkey', None)
self.keepalive = int(self.connection_config.get('keepalive', 60)) self.keepalive = int(self.connection_config.get('keepalive', 60))
self.watcher_thread = None self.watcher_thread = None
self.event_queue = Queue.Queue() self.event_queue = queue.Queue()
self.client = None self.client = None
self.baseurl = self.connection_config.get('baseurl', self.baseurl = self.connection_config.get('baseurl',
@ -606,7 +606,7 @@ class GerritConnection(BaseConnection):
def review(self, project, change, message, action={}): def review(self, project, change, message, action={}):
cmd = 'gerrit review --project %s' % project cmd = 'gerrit review --project %s' % project
if message: if message:
cmd += ' --message %s' % shlex_quote(message) cmd += ' --message %s' % shlex.quote(message)
for key, val in action.items(): for key, val in action.items():
if val is True: if val is True:
cmd += ' --%s' % key cmd += ' --%s' % key

View File

@ -14,7 +14,7 @@
# under the License. # under the License.
import logging import logging
from six.moves import urllib import urllib
import voluptuous as v import voluptuous as v

View File

@ -18,6 +18,7 @@ import logging
import os import os
import shutil import shutil
import signal import signal
import shlex
import socket import socket
import subprocess import subprocess
import tempfile import tempfile
@ -27,7 +28,6 @@ import traceback
from zuul.lib.yamlutil import yaml from zuul.lib.yamlutil import yaml
import gear import gear
from six.moves import shlex_quote
import zuul.merger.merger import zuul.merger.merger
import zuul.ansible import zuul.ansible
@ -1288,7 +1288,7 @@ class AnsibleJob(object):
if self.aborted: if self.aborted:
return (self.RESULT_ABORTED, None) return (self.RESULT_ABORTED, None)
self.log.debug("Ansible command: ANSIBLE_CONFIG=%s %s", self.log.debug("Ansible command: ANSIBLE_CONFIG=%s %s",
config_file, " ".join(shlex_quote(c) for c in cmd)) config_file, " ".join(shlex.quote(c) for c in cmd))
self.proc = popen( self.proc = popen(
cmd, cmd,
cwd=self.jobdir.work_root, cwd=self.jobdir.work_root,

View File

@ -19,8 +19,6 @@ import logging
import os import os
import re import re
import six
class CloneMapper(object): class CloneMapper(object):
log = logging.getLogger("zuul.CloneMapper") log = logging.getLogger("zuul.CloneMapper")
@ -58,17 +56,17 @@ class CloneMapper(object):
raise Exception("Expansion error. Check error messages above") raise Exception("Expansion error. Check error messages above")
self.log.info("Mapping projects to workspace...") self.log.info("Mapping projects to workspace...")
for project, dest in six.iteritems(ret): for project, dest in ret.items():
dest = os.path.normpath(os.path.join(workspace, dest[0])) dest = os.path.normpath(os.path.join(workspace, dest[0]))
ret[project] = dest ret[project] = dest
self.log.info(" %s -> %s", project, dest) self.log.info(" %s -> %s", project, dest)
self.log.debug("Checking overlap in destination directories...") self.log.debug("Checking overlap in destination directories...")
check = defaultdict(list) check = defaultdict(list)
for project, dest in six.iteritems(ret): for project, dest in ret.items():
check[dest].append(project) check[dest].append(project)
dupes = dict((d, p) for (d, p) in six.iteritems(check) if len(p) > 1) dupes = dict((d, p) for (d, p) in check.items() if len(p) > 1)
if dupes: if dupes:
raise Exception("Some projects share the same destination: %s", raise Exception("Some projects share the same destination: %s",
dupes) dupes)

View File

@ -18,8 +18,6 @@ import logging
import os import os
import re import re
import six
from git import GitCommandError from git import GitCommandError
from zuul import exceptions from zuul import exceptions
from zuul.lib.clonemapper import CloneMapper from zuul.lib.clonemapper import CloneMapper
@ -72,7 +70,7 @@ class Cloner(object):
dests = mapper.expand(workspace=self.workspace) dests = mapper.expand(workspace=self.workspace)
self.log.info("Preparing %s repositories", len(dests)) self.log.info("Preparing %s repositories", len(dests))
for project, dest in six.iteritems(dests): for project, dest in dests.items():
self.prepareRepo(project, dest) self.prepareRepo(project, dest)
self.log.info("Prepared all repositories") self.log.info("Prepared all repositories")

View File

@ -18,7 +18,7 @@ import logging
import os import os
import socket import socket
import threading import threading
from six.moves import queue import queue
class CommandSocket(object): class CommandSocket(object):

View File

@ -21,9 +21,6 @@ import struct
import time import time
from uuid import uuid4 from uuid import uuid4
import six
MERGER_MERGE = 1 # "git merge" MERGER_MERGE = 1 # "git merge"
MERGER_MERGE_RESOLVE = 2 # "git merge -s resolve" MERGER_MERGE_RESOLVE = 2 # "git merge -s resolve"
MERGER_CHERRY_PICK = 3 # "git cherry-pick" MERGER_CHERRY_PICK = 3 # "git cherry-pick"
@ -666,8 +663,7 @@ class PlaybookContext(object):
path=self.path) path=self.path)
@six.add_metaclass(abc.ABCMeta) class Role(object, metaclass=abc.ABCMeta):
class Role(object):
"""A reference to an ansible role.""" """A reference to an ansible role."""
def __init__(self, target_name): def __init__(self, target_name):

View File

@ -15,11 +15,8 @@
import abc import abc
import logging import logging
import six
class BaseReporter(object, metaclass=abc.ABCMeta):
@six.add_metaclass(abc.ABCMeta)
class BaseReporter(object):
"""Base class for reporters. """Base class for reporters.
Defines the exact public methods that must be supplied. Defines the exact public methods that must be supplied.

View File

@ -19,7 +19,6 @@ import threading
import traceback import traceback
import gear import gear
import six
from zuul import model from zuul import model
@ -179,8 +178,7 @@ class RPCListener(object):
# TODO: use args to filter by pipeline etc # TODO: use args to filter by pipeline etc
running_items = [] running_items = []
for tenant in self.sched.abide.tenants.values(): for tenant in self.sched.abide.tenants.values():
for pipeline_name, pipeline in six.iteritems( for pipeline_name, pipeline in tenant.layout.pipelines.items():
tenant.layout.pipelines):
for queue in pipeline.queues: for queue in pipeline.queues:
for item in queue.queue: for item in queue.queue:
running_items.append(item.formatJSON()) running_items.append(item.formatJSON())

View File

@ -20,8 +20,7 @@ import json
import logging import logging
import os import os
import pickle import pickle
import six import queue
from six.moves import queue as Queue
import socket import socket
import sys import sys
import threading import threading
@ -49,7 +48,9 @@ class ManagementEvent(object):
def wait(self, timeout=None): def wait(self, timeout=None):
self._wait_event.wait(timeout) self._wait_event.wait(timeout)
if self._exc_info: if self._exc_info:
six.reraise(*self._exc_info) # http://python3porting.com/differences.html#raise
e, v, t = self._exc_info
raise e(v).with_traceback(t)
return self._wait_event.is_set() return self._wait_event.is_set()
@ -217,9 +218,9 @@ class Scheduler(threading.Thread):
self.triggers = dict() self.triggers = dict()
self.config = config self.config = config
self.trigger_event_queue = Queue.Queue() self.trigger_event_queue = queue.Queue()
self.result_event_queue = Queue.Queue() self.result_event_queue = queue.Queue()
self.management_event_queue = Queue.Queue() self.management_event_queue = queue.Queue()
self.abide = model.Abide() self.abide = model.Abide()
if not testonly: if not testonly:

View File

@ -14,11 +14,8 @@
import abc import abc
import six
class BaseSource(object, metaclass=abc.ABCMeta):
@six.add_metaclass(abc.ABCMeta)
class BaseSource(object):
"""Base class for sources. """Base class for sources.
A source class gives methods for fetching and updating changes. Each A source class gives methods for fetching and updating changes. Each

View File

@ -14,11 +14,8 @@
import abc import abc
import six
class BaseTrigger(object, metaclass=abc.ABCMeta):
@six.add_metaclass(abc.ABCMeta)
class BaseTrigger(object):
"""Base class for triggers. """Base class for triggers.
Defines the exact public methods that must be supplied.""" Defines the exact public methods that must be supplied."""