From 505a95a354647010adbbe5e74c1e20f66d18d069 Mon Sep 17 00:00:00 2001 From: "Sergey Bubnov (omg)" Date: Thu, 18 Jul 2019 13:03:25 +0400 Subject: [PATCH] fixes to move to python3 --- library/proxmox_kvm.py | 4 ++-- nix/ansible/default.nix | 13 +++++++------ nix/glob2/default.nix | 10 ++++++---- nix/proxmoxer/default.nix | 12 +++++++----- nix/pytest-bdd/default.nix | 16 +++++++++------- plugins/filters.py | 4 ++-- roles/inventory/templates/ssh_config | 2 +- roles/inventory/templates/ssh_config-bootstrap | 2 +- shell.nix | 12 ++++++------ 9 files changed, 41 insertions(+), 34 deletions(-) diff --git a/library/proxmox_kvm.py b/library/proxmox_kvm.py index f7c5598..c071eb7 100644 --- a/library/proxmox_kvm.py +++ b/library/proxmox_kvm.py @@ -644,7 +644,7 @@ def get_vminfo(module, proxmox, node, vmid, **kwargs): kwargs = dict((k, v) for k, v in kwargs.items() if v is not None) # Convert all dict in kwargs to elements. For hostpci[n], ide[n], net[n], numa[n], parallel[n], sata[n], scsi[n], serial[n], virtio[n] - for k in kwargs.keys(): + for k in list(kwargs): if isinstance(kwargs[k], dict): kwargs.update(kwargs[k]) del kwargs[k] @@ -730,7 +730,7 @@ def create_vm(module, proxmox, vmid, newid, node, name, memory, cpu, cores, sock #kwargs['net'][n]['virtio'] = results['mac'][n] # Convert all dict in kwargs to elements. For hostpci[n], ide[n], net[n], numa[n], parallel[n], sata[n], scsi[n], serial[n], virtio[n] - for k in kwargs.keys(): + for k in list(kwargs): if isinstance(kwargs[k], dict): kwargs.update(kwargs[k]) del kwargs[k] diff --git a/nix/ansible/default.nix b/nix/ansible/default.nix index 883e4b6..07a2c03 100644 --- a/nix/ansible/default.nix +++ b/nix/ansible/default.nix @@ -1,15 +1,16 @@ { pkgs ? import {} , windowsSupport ? false +, pythonPackages }: -with pkgs; +with pythonPackages; -pythonPackages.buildPythonPackage rec { +buildPythonPackage rec { pname = "ansible"; version = "devel"; name = "${pname}-${version}"; - src = fetchFromGitHub { + src = pkgs.fetchFromGitHub { owner = "ansible"; repo = "ansible"; rev = "1724b633f2fdc4c8d49e634d44864ef5e2e2d4c6"; @@ -28,10 +29,10 @@ pythonPackages.buildPythonPackage rec { dontPatchShebangs = false; propagatedBuildInputs = with pythonPackages; [ - pycrypto paramiko jinja2 pyyaml httplib2 boto six netaddr dnspython - ] ++ stdenv.lib.optional windowsSupport pywinrm; + pycrypto paramiko jinja2 pyyaml httplib2 boto six netaddr dnspython cryptography + ] ++ pkgs.stdenv.lib.optional windowsSupport pywinrm; - meta = with stdenv.lib; { + meta = with pkgs.stdenv.lib; { homepage = http://www.ansible.com; description = "A simple automation tool"; license = with licenses; [ gpl3 ]; diff --git a/nix/glob2/default.nix b/nix/glob2/default.nix index 21b98fe..00bdaec 100644 --- a/nix/glob2/default.nix +++ b/nix/glob2/default.nix @@ -1,12 +1,14 @@ -{ pkgs ? import {} }: +{ pkgs ? import {} +, pythonPackages +}: -with pkgs; +with pythonPackages; -python27.pkgs.buildPythonPackage rec { +buildPythonPackage rec { pname = "glob2"; version = "0.6"; - src = python36.pkgs.fetchPypi { + src = fetchPypi { inherit pname version; sha256 = "1miyz0pjyji4gqrzl04xsxcylk3h2v9fvi7hsg221y11zy3adc7m"; }; diff --git a/nix/proxmoxer/default.nix b/nix/proxmoxer/default.nix index d312fdc..0a9940d 100644 --- a/nix/proxmoxer/default.nix +++ b/nix/proxmoxer/default.nix @@ -1,12 +1,14 @@ -{ pkgs ? import {} }: - -with pkgs; +{ pkgs ? import {} +, pythonPackages +}: -python27.pkgs.buildPythonPackage rec { +with pythonPackages; + +buildPythonPackage rec { pname = "proxmoxer"; version = "1.0.3"; - src = python36.pkgs.fetchPypi { + src = fetchPypi { inherit pname version; sha256 = "145hvphvlzvwq6sn31ldnin0ii50blsapxz0gv2zx3grzp6x9hvh"; }; diff --git a/nix/pytest-bdd/default.nix b/nix/pytest-bdd/default.nix index 87cc79b..2fdd87a 100644 --- a/nix/pytest-bdd/default.nix +++ b/nix/pytest-bdd/default.nix @@ -1,17 +1,19 @@ -{ pkgs ? import {} }: +{ pkgs ? import {} +, pythonPackages +}: -with pkgs; +with pythonPackages; -python27.pkgs.buildPythonPackage rec { +buildPythonPackage rec { pname = "pytest-bdd"; - version = "3.0.0"; + version = "3.1.1"; - src = python36.pkgs.fetchPypi { + src = fetchPypi { inherit pname version; - sha256 = "1np2qvfnhz3amd02f2y4shp4pracnfdkcdxkhkigv997iwc4sih0"; + sha256 = "0r5p9i0viqfm8l5336fpjjwad4z98077fgi3652qym75mmhirb2w"; }; - glob2 = callPackage ../glob2 {}; + glob2 = callPackage ../glob2 { inherit pythonPackages; }; nativeBuildInputs = with pythonPackages; [ setuptools_scm ]; propagatedBuildInputs = with pythonPackages; [ glob2 pytest pytest-forked mock pytest_xdist Mako parse-type ]; diff --git a/plugins/filters.py b/plugins/filters.py index 5298cfb..4a093d7 100644 --- a/plugins/filters.py +++ b/plugins/filters.py @@ -36,7 +36,7 @@ def dict_merge(dct, merge_dct): :param merge_dct: dct merged into dct :return: None """ - for k, v in merge_dct.iteritems(): + for k, v in merge_dct.items(): if (k in dct and isinstance(dct[k], dict) and isinstance(merge_dct[k], collections.Mapping)): dict_merge(dct[k], merge_dct[k]) @@ -115,7 +115,7 @@ def get_steps(node, steps_list): def filter_dict(src, pred): p = eval(pred) - return { k: v for k, v in src.iteritems() if p(v)} + return { k: v for k, v in src.items() if p(v)} def format2(what, fmt): return fmt % what diff --git a/roles/inventory/templates/ssh_config b/roles/inventory/templates/ssh_config index bea1f15..45d81a3 100644 --- a/roles/inventory/templates/ssh_config +++ b/roles/inventory/templates/ssh_config @@ -1,4 +1,4 @@ -{% for node_name, node in stack.nodes.iteritems() %} +{% for node_name, node in stack.nodes.items() %} Host {{node_name}}.{{stack.domain}} {{node_name}} HostName {{node.net.eth0.ipv4[0]|ipaddr('address')}} User root diff --git a/roles/inventory/templates/ssh_config-bootstrap b/roles/inventory/templates/ssh_config-bootstrap index ff3ff52..cf65e2a 100644 --- a/roles/inventory/templates/ssh_config-bootstrap +++ b/roles/inventory/templates/ssh_config-bootstrap @@ -1,4 +1,4 @@ -{% for node_name, node in stack.nodes.iteritems() %} +{% for node_name, node in stack.nodes.items() %} Host {{node_name}}.{{stack.domain}} {{node_name}} {% if node.nics is defined %} HostName {{node.nics.eth0.addrs[0]|ipaddr('address')}} diff --git a/shell.nix b/shell.nix index 88df1f1..36a3dd3 100644 --- a/shell.nix +++ b/shell.nix @@ -5,19 +5,19 @@ with pkgs; let - pytest-bdd = callPackage nix/pytest-bdd {}; - proxmoxer = callPackage nix/proxmoxer {}; - ansible = callPackage nix/ansible {}; + myPytest-bdd = callPackage nix/pytest-bdd { pythonPackages = python37Packages; }; + myProxmoxer = callPackage nix/proxmoxer { pythonPackages = python37Packages; }; + myAnsible = callPackage nix/ansible { pythonPackages = python37Packages; }; - myPython = python27.withPackages (ps: with ps; [ pytest-bdd proxmoxer jmespath virtualenv pip hypothesis pytest_xdist pytest ]); + env = python37.withPackages (ps: with ps; [ myPytest-bdd myProxmoxer jmespath virtualenv pip hypothesis pytest_xdist pytest ]); in stdenv.mkDerivation { name = "alt-infra-ansible"; buildInputs = [ + env openssh - ansible - myPython + myAnsible pass ]; }