Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 compatibility #800

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lago/brctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
# Refer to the README and COPYING files for full details of the license
#
import utils
from . import utils

_BRCTL = ['sudo', 'brctl']
_IP = ['sudo', 'ip']
Expand Down
2 changes: 1 addition & 1 deletion lago/log_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def close_children_tasks(self, parent_task_name):
return

while self.tasks:
next_task = reversed(self.tasks.keys()).next()
next_task = next(reversed(self.tasks.keys()))
if next_task == parent_task_name:
break
del self.tasks[next_task]
Expand Down
35 changes: 17 additions & 18 deletions lago/prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@
import warnings
import pkg_resources
from os.path import join
from plugins.output import YAMLOutFormatPlugin
from .plugins.output import YAMLOutFormatPlugin

import xmltodict

import paths
import subnet_lease
import utils
from utils import LagoInitException, LagoException
import virt
import log_utils
import build
import sdk_utils
from . import paths
from . import subnet_lease
from . import utils
from . import virt
from . import log_utils
from . import build
from . import sdk_utils

LOGGER = logging.getLogger(__name__)
LogTask = functools.partial(log_utils.LogTask, logger=LOGGER)
Expand Down Expand Up @@ -283,7 +282,7 @@ def _allocate_subnets(self, conf):
allocated_subnet = self._subnet_store.acquire(
self.paths.uuid()
)
net_spec['gw'] = str(allocated_subnet.iter_hosts().next())
net_spec['gw'] = str(next(allocated_subnet.iter_hosts()))

allocated_subnets.append(allocated_subnet)
except:
Expand Down Expand Up @@ -463,7 +462,7 @@ def _get_net(self, conf, dom_name, nic):
try:
net = conf['nets'][nic['net']]
except KeyError:
raise LagoInitException(
raise utils.LagoInitException(
dedent(
"""
Unrecognized network in {0}: {1},
Expand Down Expand Up @@ -591,15 +590,15 @@ def _validate_netconfig(self, conf):
nets = conf.get('nets', {})
if len(nets) == 0:
# TO-DO: add default networking if no network is configured
raise LagoInitException('No networks configured.')
raise utils.LagoInitException('No networks configured.')

no_mgmt_dns = [
name for name, net in nets.iteritems()
if net.get('management', None) is None and
(net.get('main_dns') or net.get('dns_domain_name'))
]
if len(no_mgmt_dns) > 0 and len(nets.keys()) > 1:
raise LagoInitException(
raise utils.LagoInitException(
(
'Networks: {0}, misconfigured, they '
'are not marked as management, but have '
Expand All @@ -615,7 +614,7 @@ def _validate_netconfig(self, conf):
if net.get('management', False) is True:
mgmts.append(nic['net'])
if len(mgmts) == 0:
raise LagoInitException(
raise utils.LagoInitException(
(
'VM {0} has no management network, '
'please connect it to '
Expand All @@ -624,7 +623,7 @@ def _validate_netconfig(self, conf):
)

if len(mgmts) > 1:
raise LagoInitException(
raise utils.LagoInitException(
(
'VM {0} has more than one management '
'network: {1}. It should have exactly '
Expand Down Expand Up @@ -870,7 +869,7 @@ def resolve_parent(self, disk_path, template_store, template_repo):
os.path.realpath(parent),
os.path.realpath(os.path.expandvars(disk_path))
):
raise LagoInitException(
raise utils.LagoInitException(
dedent(
"""
Disk {} and its backing file are the same file.
Expand All @@ -884,7 +883,7 @@ def resolve_parent(self, disk_path, template_store, template_repo):
try:
name, version = os.path.basename(parent).split(':', 1)
except ValueError:
raise LagoInitException(
raise utils.LagoInitException(
dedent(
"""
Backing file resolution of disk {} failed.
Expand Down Expand Up @@ -1672,5 +1671,5 @@ def deploy(self):
)


class LagoDeployError(LagoException):
class LagoDeployError(utils.LagoException):
pass
2 changes: 1 addition & 1 deletion lago/sysprep.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#
import os

import utils
from . import utils
import logging
import tempfile
from jinja2 import Environment, PackageLoader
Expand Down
2 changes: 1 addition & 1 deletion lago/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import urllib
import sys

import utils
from . import utils
from . import log_utils
from .config import config

Expand Down
2 changes: 1 addition & 1 deletion lago/workdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def load(self):
return

try:
basepath, dirs, _ = os.walk(self.path).next()
basepath, dirs, _ = next(os.walk(self.path))
except StopIteration:
raise MalformedWorkdir('Empty dir %s' % self.path)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lago/test_subnet_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_take_random_lease(self, subnet_store, subnet, prefix):
path_to_lease = os.path.join(
subnet_store.path, '{}.lease'.format(third_octet)
)
_, dirnames, filenames = os.walk(subnet_store.path).next()
_, dirnames, filenames = next(os.walk(subnet_store.path))

try:
# Don't count the lockfile
Expand Down