Skip to content

Commit

Permalink
Migrate nixops-aws to python3
Browse files Browse the repository at this point in the history
This does a 1-way migration to python3, and fully resolves #29.

Aside from the `release.nix`, there are no manual changes in this PR. It was
generated with:

    2to3 -n -w nixopsaws/**/*.py -x dict -x print
    black .

We have already fixed the `print` function in a previous PR, as well as all of
the dictionary iterators. `2to3` is not particularly smart about this and will
add a `list()` cast just about everywhere otherwise.
  • Loading branch information
bhipple committed Mar 22, 2020
1 parent de811d8 commit c2b988a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 17 deletions.
1 change: 0 additions & 1 deletion nixopsaws/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from . import aws_vpn_connection
from . import aws_vpn_connection_route
from . import aws_vpn_gateway
Expand Down
2 changes: 1 addition & 1 deletion nixopsaws/resources/ebs_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Automatic provisioning of AWS EBS volumes.

from __future__ import absolute_import

import boto.ec2
import nixops.util
import nixopsaws.ec2_utils
Expand Down
6 changes: 3 additions & 3 deletions nixopsaws/resources/ec2_placement_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
self.state = self.UP
self.placement_group_strategy = grp.strategy
except boto.exception.EC2ResponseError as e:
if e.error_code == u"InvalidGroup.NotFound":
if e.error_code == "InvalidGroup.NotFound":
self.state = self.Missing
else:
raise
Expand All @@ -129,7 +129,7 @@ def create(self, defn, check, allow_reboot, allow_recreate):
except boto.exception.EC2ResponseError as e:
if (
self.state != self.UNKNOWN
or e.error_code != u"InvalidGroup.Duplicate"
or e.error_code != "InvalidGroup.Duplicate"
):
raise

Expand All @@ -146,7 +146,7 @@ def after_activation(self, defn):
try:
conn.delete_placement_group(group["name"])
except boto.exception.EC2ResponseError as e:
if e.error_code != u"InvalidGroup.NotFound":
if e.error_code != "InvalidGroup.NotFound":
raise
self.old_placement_groups = []

Expand Down
4 changes: 2 additions & 2 deletions nixopsaws/resources/ec2_rds_dbinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _try_fetch_dbinstance(self, instance_id):
try:
dbinstance = self._conn.get_all_dbinstances(instance_id=instance_id)[0]
except boto.exception.BotoServerError as bse:
if bse.error_code == u"DBInstanceNotFound":
if bse.error_code == "DBInstanceNotFound":
dbinstance = None
else:
raise
Expand Down Expand Up @@ -275,7 +275,7 @@ def _to_boto_kwargs(self, attrs):

def _compare_instance_id(self, instance_id):
# take care when comparing instance ids, as aws lowercases and converts to unicode
return unicode(self.rds_dbinstance_id).lower() == unicode(instance_id).lower()
return str(self.rds_dbinstance_id).lower() == str(instance_id).lower()

def fetch_security_group_resources(self, config):
security_groups = []
Expand Down
10 changes: 5 additions & 5 deletions nixopsaws/resources/ec2_security_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def retry_notfound(f):
rules.append(new_rule)
self.security_group_rules = rules
except boto.exception.EC2ResponseError as e:
if e.error_code == u"InvalidGroup.NotFound":
if e.error_code == "InvalidGroup.NotFound":
self.state = self.MISSING
else:
raise
Expand Down Expand Up @@ -228,7 +228,7 @@ def retry_notfound(f):
except boto.exception.EC2ResponseError as e:
if (
self.state != self.UNKNOWN
or e.error_code != u"InvalidGroup.Duplicate"
or e.error_code != "InvalidGroup.Duplicate"
):
raise
self.state = self.STARTING # ugh
Expand Down Expand Up @@ -284,7 +284,7 @@ def retry_notfound(f):
)
)
except boto.exception.EC2ResponseError as e:
if e.error_code != u"InvalidPermission.Duplicate":
if e.error_code != "InvalidPermission.Duplicate":
raise

if old_rules:
Expand Down Expand Up @@ -345,7 +345,7 @@ def after_activation(self, defn):
try:
conn.delete_security_group(group["name"])
except boto.exception.EC2ResponseError as e:
if e.error_code != u"InvalidGroup.NotFound":
if e.error_code != "InvalidGroup.NotFound":
raise
self.old_security_groups = []

Expand All @@ -365,7 +365,7 @@ def destroy(self, wipe=False):
error_codes=["DependencyViolation"],
)
except boto.exception.EC2ResponseError as e:
if e.error_code != u"InvalidGroup.NotFound":
if e.error_code != "InvalidGroup.NotFound":
raise

self.state = self.MISSING
Expand Down
2 changes: 1 addition & 1 deletion nixopsaws/resources/elastic_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# AWS Elastic File Systems.

from __future__ import absolute_import

import uuid
import boto3
import botocore
Expand Down
2 changes: 1 addition & 1 deletion nixopsaws/resources/elastic_file_system_mount_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# AWS Elastic File System mount targets.

from __future__ import absolute_import

import boto3
import botocore
import nixops.util
Expand Down
6 changes: 3 additions & 3 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rec {
build = pkgs.lib.genAttrs [ "x86_64-linux" "i686-linux" "x86_64-darwin" ] (system:
with import nixpkgs { inherit system; };

python2Packages.buildPythonApplication rec {
python3Packages.buildPythonApplication rec {
pname = "nixops-aws";
inherit version;
namePrefix = "";
Expand All @@ -26,8 +26,8 @@ rec {
substituteAllInPlace setup.py
'';

buildInputs = with python2Packages; [ nose coverage ];
propagatedBuildInputs = with python2Packages; [ boto boto3 ];
buildInputs = with python3Packages; [ nose coverage ];
propagatedBuildInputs = with python3Packages; [ boto boto3 ];

# For "nix-build --run-env".
shellHook = ''
Expand Down

0 comments on commit c2b988a

Please sign in to comment.