Fixing Python 3.x issues introduced with eventlet update
Closes-Bug: #1792671 Change-Id: Iecef0977a1e4c102bd85b0d9c27a8d37dcd3ee17
This commit is contained in:
parent
74509a3a6d
commit
1836c221fa
|
@ -30,6 +30,7 @@ import dns.rcode
|
|||
import dns.message
|
||||
import dns.flags
|
||||
import dns.opcode
|
||||
import six
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
|
@ -104,7 +105,9 @@ class RequestHandler(object):
|
|||
|
||||
question = request.question[0]
|
||||
requester = request.environ['addr'][0]
|
||||
zone_name = question.name.to_text().decode('utf-8')
|
||||
zone_name = question.name.to_text()
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
|
||||
if not self._allowed(request, requester, "CREATE", zone_name):
|
||||
response.set_rcode(dns.rcode.from_text("REFUSED"))
|
||||
|
@ -155,7 +158,9 @@ class RequestHandler(object):
|
|||
|
||||
question = request.question[0]
|
||||
requester = request.environ['addr'][0]
|
||||
zone_name = question.name.to_text().decode('utf-8')
|
||||
zone_name = question.name.to_text()
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
|
||||
if not self._allowed(request, requester, "NOTIFY", zone_name):
|
||||
response.set_rcode(dns.rcode.from_text("REFUSED"))
|
||||
|
@ -206,7 +211,9 @@ class RequestHandler(object):
|
|||
|
||||
question = request.question[0]
|
||||
requester = request.environ['addr'][0]
|
||||
zone_name = question.name.to_text().decode('utf-8')
|
||||
zone_name = question.name.to_text()
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
|
||||
if not self._allowed(request, requester, "DELETE", zone_name):
|
||||
response.set_rcode(dns.rcode.from_text("REFUSED"))
|
||||
|
|
|
@ -17,6 +17,7 @@ import os
|
|||
|
||||
import dns
|
||||
import dns.resolver
|
||||
import six
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
@ -111,7 +112,9 @@ class Bind9Backend(base.AgentBackend):
|
|||
|
||||
# NOTE: Different versions of BIND9 behave differently with a trailing
|
||||
# dot, so we're just going to take it off.
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
|
||||
# NOTE: Only one thread should be working with the Zonefile at a given
|
||||
# time. The sleep(1) below introduces a not insignificant risk
|
||||
|
|
|
@ -18,6 +18,7 @@ import itertools
|
|||
import dns.rdata
|
||||
import dns.rdatatype
|
||||
import dns.rdataclass
|
||||
import six
|
||||
from oslo_config import cfg
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_log import log as logging
|
||||
|
@ -139,7 +140,9 @@ class DenominatorBackend(base.AgentBackend):
|
|||
|
||||
def create_zone(self, zone):
|
||||
LOG.debug("Creating %s", zone.origin.to_text())
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
|
||||
# Use SOA TTL as zone default TTL
|
||||
soa_record = zone.find_rrset(zone.origin, dns.rdatatype.SOA)
|
||||
|
@ -171,7 +174,9 @@ class DenominatorBackend(base.AgentBackend):
|
|||
|
||||
def update_zone(self, zone):
|
||||
LOG.debug("Updating %s", zone.origin)
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
|
||||
soa_record = zone.find_rrset(zone.origin, dns.rdatatype.SOA)
|
||||
rname = soa_record.items[0].rname.derelativize(origin=zone.origin)
|
||||
|
@ -239,7 +244,9 @@ class DenominatorBackend(base.AgentBackend):
|
|||
def _iterate_records(self, zone):
|
||||
for rname, ttl, rdata in zone.iterate_rdatas():
|
||||
name = rname.derelativize(origin=zone.origin)
|
||||
name = name.to_text(omit_final_dot=True).decode('utf-8')
|
||||
name = name.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(name, bytes):
|
||||
name = name.decode('utf-8')
|
||||
|
||||
data = rdata.to_text(origin=zone.origin, relativize=False)
|
||||
yield name, ttl, dns.rdatatype.to_text(rdata.rdtype), data
|
||||
|
|
|
@ -46,6 +46,7 @@ import tempfile
|
|||
|
||||
import dns
|
||||
import dns.resolver
|
||||
import six
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_concurrency.processutils import ProcessExecutionError
|
||||
from oslo_config import cfg
|
||||
|
@ -310,7 +311,9 @@ class DjbdnsBackend(base.AgentBackend):
|
|||
:type zone: raw pythondns Zone
|
||||
:raises: exceptions.Backend on error
|
||||
"""
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
LOG.debug("Creating %s", zone_name)
|
||||
# The zone might be already in place due to a race condition between
|
||||
# checking if the zone is there and creating it across different
|
||||
|
@ -329,7 +332,9 @@ class DjbdnsBackend(base.AgentBackend):
|
|||
:type zone: raw pythondns Zone
|
||||
:raises: exceptions.Backend on error
|
||||
"""
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
LOG.debug("Triggering AXFR from MiniDNS to Djbdns for %s", zone_name)
|
||||
self._perform_axfr_from_minidns(zone_name)
|
||||
self._rebuild_data_cdb()
|
||||
|
|
|
@ -45,6 +45,7 @@ import string
|
|||
|
||||
import dns
|
||||
import dns.resolver
|
||||
import six
|
||||
from oslo_concurrency.processutils import ProcessExecutionError
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
@ -185,7 +186,9 @@ class GdnsdBackend(base.AgentBackend):
|
|||
"""Create or update a zone file atomically.
|
||||
The zone file is written to a unique temp file and then renamed
|
||||
"""
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
zone_base_fname = self._generate_zone_filename(zone_name)
|
||||
zone_fname = os.path.join(self._zonedir_path, zone_base_fname)
|
||||
try:
|
||||
|
|
|
@ -37,6 +37,7 @@ Supported Knot versions: >= 2.1, < 3
|
|||
|
||||
Configured in [service:agent:knot2]
|
||||
"""
|
||||
import six
|
||||
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_concurrency.processutils import ProcessExecutionError
|
||||
|
@ -199,7 +200,9 @@ class Knot2Backend(base.AgentBackend):
|
|||
:param zone: zone to be created
|
||||
:type zone: raw pythondns Zone
|
||||
"""
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
LOG.debug("Creating %s", zone_name)
|
||||
# The zone might be already in place due to a race condition between
|
||||
# checking if the zone is there and creating it across different
|
||||
|
@ -217,7 +220,9 @@ class Knot2Backend(base.AgentBackend):
|
|||
:param zone: zone to be created
|
||||
:type zone: raw pythondns Zone
|
||||
"""
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
LOG.debug("Triggering AXFR from MiniDNS to Knot for %s", zone_name)
|
||||
self._start_minidns_to_knot_axfr(zone_name)
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# 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 six
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
@ -79,7 +80,9 @@ class MSDNSBackend(base.AgentBackend):
|
|||
|
||||
def create_zone(self, zone):
|
||||
"""Create a new DNS Zone"""
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
LOG.debug("Creating zone: %s", zone_name)
|
||||
try:
|
||||
self._dnsutils.zone_create(
|
||||
|
@ -104,7 +107,9 @@ class MSDNSBackend(base.AgentBackend):
|
|||
def update_zone(self, zone):
|
||||
"""Instruct MSDNS to request an AXFR from MiniDNS.
|
||||
"""
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True).decode('utf-8')
|
||||
zone_name = zone.origin.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
LOG.debug("Updating zone: %s", zone_name)
|
||||
self._dnsutils.zone_update(zone_name)
|
||||
|
||||
|
|
|
@ -156,7 +156,10 @@ class TsigInfoMiddleware(DNSMiddleware):
|
|||
return None
|
||||
|
||||
try:
|
||||
criterion = {'name': request.keyname.to_text(True).decode('utf-8')}
|
||||
name = request.keyname.to_text(True)
|
||||
if six.PY3 and isinstance(name, bytes):
|
||||
name = name.decode('utf-8')
|
||||
criterion = {'name': name}
|
||||
tsigkey = self.storage.find_tsigkey(
|
||||
context.get_current(), criterion)
|
||||
|
||||
|
@ -182,7 +185,10 @@ class TsigKeyring(object):
|
|||
|
||||
def get(self, key, default=None):
|
||||
try:
|
||||
criterion = {'name': key.to_text(True).decode('utf-8')}
|
||||
name = key.to_text(True)
|
||||
if six.PY3 and isinstance(name, bytes):
|
||||
name = name.decode('utf-8')
|
||||
criterion = {'name': name}
|
||||
tsigkey = self.storage.find_tsigkey(
|
||||
context.get_current(), criterion)
|
||||
|
||||
|
@ -249,7 +255,9 @@ class LimitNotifyMiddleware(DNSMiddleware):
|
|||
if opcode != dns.opcode.NOTIFY:
|
||||
return None
|
||||
|
||||
zone_name = request.question[0].name.to_text().decode('utf-8')
|
||||
zone_name = request.question[0].name.to_text()
|
||||
if six.PY3 and isinstance(zone_name, bytes):
|
||||
zone_name = zone_name.decode('utf-8')
|
||||
|
||||
if self.locker.acquire(zone_name):
|
||||
time.sleep(self.delay)
|
||||
|
@ -272,10 +280,17 @@ def from_dnspython_zone(dnspython_zone):
|
|||
raise exceptions.BadRequest('An SOA record is required')
|
||||
if soa.ttl == 0:
|
||||
soa.ttl = cfg.CONF['service:central'].min_ttl
|
||||
email = soa[0].rname.to_text(omit_final_dot=True).decode('utf-8')
|
||||
email = soa[0].rname.to_text(omit_final_dot=True)
|
||||
if six.PY3 and isinstance(email, bytes):
|
||||
email = email.decode('utf-8')
|
||||
email = email.replace('.', '@', 1)
|
||||
|
||||
name = dnspython_zone.origin.to_text()
|
||||
if six.PY3 and isinstance(name, bytes):
|
||||
name = name.decode('utf-8')
|
||||
|
||||
values = {
|
||||
'name': dnspython_zone.origin.to_text().decode('utf-8'),
|
||||
'name': name,
|
||||
'email': email,
|
||||
'ttl': soa.ttl,
|
||||
'serial': soa[0].serial,
|
||||
|
@ -307,12 +322,16 @@ def dnspyrecords_to_recordsetlist(dnspython_records):
|
|||
def dnspythonrecord_to_recordset(rname, rdataset):
|
||||
record_type = rdatatype.to_text(rdataset.rdtype)
|
||||
|
||||
name = rname.to_text()
|
||||
if six.PY3 and isinstance(name, bytes):
|
||||
name = name.decode('utf-8')
|
||||
|
||||
# Create the other recordsets
|
||||
|
||||
values = {
|
||||
'name': rname.to_text().decode('utf-8'),
|
||||
'name': name,
|
||||
'type': record_type
|
||||
}
|
||||
|
||||
if rdataset.ttl != 0:
|
||||
values['ttl'] = rdataset.ttl
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import dns.rcode
|
|||
import dns.rdataclass
|
||||
import dns.rdatatype
|
||||
import dns.message
|
||||
import six
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
|
@ -110,8 +111,12 @@ class RequestHandler(xfr.XFRMixin):
|
|||
else:
|
||||
question = request.question[0]
|
||||
|
||||
name = question.name.to_text()
|
||||
if six.PY3 and isinstance(name, bytes):
|
||||
name = name.decode('utf-8')
|
||||
|
||||
criterion = {
|
||||
'name': question.name.to_text().decode('utf-8'),
|
||||
'name': name,
|
||||
'type': 'SECONDARY',
|
||||
'deleted': False
|
||||
}
|
||||
|
@ -223,8 +228,11 @@ class RequestHandler(xfr.XFRMixin):
|
|||
# TODO(vinod) once validation is separated from the api,
|
||||
# validate the parameters
|
||||
try:
|
||||
name = q_rrset.name.to_text()
|
||||
if six.PY3 and isinstance(name, bytes):
|
||||
name = name.decode('utf-8')
|
||||
criterion = self._zone_criterion_from_request(
|
||||
request, {'name': q_rrset.name.to_text().decode('utf-8')})
|
||||
request, {'name': name})
|
||||
zone = self.storage.find_zone(context, criterion)
|
||||
|
||||
except exceptions.ZoneNotFound:
|
||||
|
@ -340,10 +348,13 @@ class RequestHandler(xfr.XFRMixin):
|
|||
|
||||
try:
|
||||
q_rrset = request.question[0]
|
||||
name = q_rrset.name.to_text()
|
||||
if six.PY3 and isinstance(name, bytes):
|
||||
name = name.decode('utf-8')
|
||||
# TODO(vinod) once validation is separated from the api,
|
||||
# validate the parameters
|
||||
criterion = {
|
||||
'name': q_rrset.name.to_text().decode('utf-8'),
|
||||
'name': name,
|
||||
'type': dns.rdatatype.to_text(q_rrset.rdtype),
|
||||
'zones_deleted': False
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import eventlet.patcher
|
||||
import six
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
|
@ -108,4 +109,7 @@ class NetworkAPI(DriverPlugin):
|
|||
"""
|
||||
Get the name for the address
|
||||
"""
|
||||
return reversename.from_address(address).to_text().decode('utf-8')
|
||||
name = reversename.from_address(address).to_text()
|
||||
if six.PY3 and isinstance(name, bytes):
|
||||
name = name.decode('utf-8')
|
||||
return name
|
||||
|
|
Loading…
Reference in New Issue