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 2to3, too #1227

Closed
wants to merge 22 commits into from
Closed

Python 2to3, too #1227

wants to merge 22 commits into from

Conversation

grahamc
Copy link
Member

@grahamc grahamc commented Feb 21, 2020

Continues #1214 by @Taneb. The result of running 2to3 on the codebase, plus manual fixes when we're dealing with bytes and strings... plus a few minor 2-to-3 incompatibilities like Queue.Queue and output flushing.

I have tested this deploying to machines which are deployed without any plugin, as well as machines deployed with the nixops-packet plugin, using:

    (final: super: {
      nixopsBootstrap = (import "${../../../github.com/NixOS/nixops}/release.nix" {
        nixpkgs = final.path;
        p = (nixopsPlugins: [
        ]);
      }).build."${system}";

      nixops-packet = (import "${../../../github.com/input-output-hk/nixops-packet}/release.nix" {
        nixopsSrc = {
          outPath = ../../../github.com/NixOS/nixops;
          revCount = 0;
          shortRev = "abcdef";
          rev = "HEAD";
        };
        nixpkgs = final.path;
        nixops = final.nixopsBootstrap;
      });

      nixops = (import "${../../../github.com/NixOS/nixops}/release.nix" {
        nixpkgs = final.path;
        p = (nixopsPlugins: [
          final.nixops-packet
        ]);
      }).build."${system}";
    })

I have tested these things:

  • Creating a new system
  • Destroying an unneeded system
  • nixops ssh-for-each
  • nixops deploy
  • nixops deploy --force-reboot --exclude foo bar
  • nixops deploy -k
  • nixops deploy --include foo bar
  • nixops info
  • nixops list
  • nixops check
  • nixops send-keys
  • nixops show-arguments (but I had none)
  • nixops show-physical
  • nixops ssh (both to and from)
  • nixops dump-nix-paths
  • nixops export

I fixed many problems with combining bytes and strings in the logger, and bytes and strings when running remote commands. I fixed the stdout handler which had trouble with b"" != "" especially when detecting a remote SSH command was completed writing. I fixed the logger not flushing after each . write, and not flushing when asking if destroying things is okay.

IMO this is ready to go, and the upgrades to other plugins will need to be done after this merges.

@grahamc grahamc requested review from rbvermaa, edolstra and AmineChikhaoui and removed request for rbvermaa and edolstra February 21, 2020 15:18
@AmineChikhaoui
Copy link
Member

had to modify script/nixops to have python3 in the shebang.
And got this error later:

  File "/home/amine/src/nixops/nixops/deployment.py", line 741, in worker
    res = m.switch_to_configuration(switch_method, sync)
  File "/home/amine/src/nixops/nixops/backends/none.py", line 65, in switch_to_configuration
    res = super(NoneState, self).switch_to_configuration(method, sync, command)
  File "/home/amine/src/nixops/nixops/backends/__init__.py", line 351, in switch_to_configuration
    return self.run_command(cmd, check=False)
  File "/home/amine/src/nixops/nixops/backends/__init__.py", line 337, in run_command
    return self.ssh.run_command(command, self.get_ssh_flags(), **kwargs)
  File "/home/amine/src/nixops/nixops/ssh_util.py", line 290, in run_command
    return nixops.util.logged_exec(cmd, self._logger, **kwargs)
  File "/home/amine/src/nixops/nixops/util.py", line 136, in logged_exec
    logger.log_start(data[start:])
  File "/home/amine/src/nixops/nixops/logger.py", line 145, in log_start
    self.main_logger.log_start(self._log_prefix, msg)
  File "/home/amine/src/nixops/nixops/logger.py", line 40, in log_start
    self._log_file.write(msg)
  File "/home/amine/src/nixops/nixops/util.py", line 293, in write
    self.stderr.write(data)
TypeError: write() argument must be str, not bytes
```

@grahamc
Copy link
Member Author

grahamc commented Feb 21, 2020

🤡 I never ran it like that in dev mode, I used the nix-build't version 😬 I'll take another crack.

Copy link
Member

@multun multun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some nits

maintainers/dump-route53-hosted-zone.py Outdated Show resolved Hide resolved
nixops/backends/__init__.py Outdated Show resolved Hide resolved
nixops/diff.py Outdated Show resolved Hide resolved
nixops/nix_expr.py Outdated Show resolved Hide resolved
nixops/nix_expr.py Outdated Show resolved Hide resolved
nixops/deployment.py Outdated Show resolved Hide resolved
nixops/deployment.py Outdated Show resolved Hide resolved
nixops/deployment.py Outdated Show resolved Hide resolved
nixops/deployment.py Outdated Show resolved Hide resolved
nixops/deployment.py Outdated Show resolved Hide resolved
@grahamc
Copy link
Member Author

grahamc commented Feb 21, 2020

@multun all of those were added by 2to3. I'm a bit spooked about making those changes -- but trust your expertise. Would you mind sending my branch a PR?

@multun
Copy link
Member

multun commented Feb 21, 2020

yeah sure ! I should probably have figured that out instead of making way too many comments, sorry about that

@grahamc
Copy link
Member Author

grahamc commented Feb 21, 2020

No worries :D I appreciate you taking the time for it. Ping me here when you've opened that PR?

@grahamc
Copy link
Member Author

grahamc commented Feb 21, 2020

@AmineChikhaoui I had to change the release.nix to create a nixops without any plugins, pass that to the plugins for testing, and then create a nixops combining them all together. Then I updated scripts/nixops to use python3 and verified it works ... can you try again?

@AmineChikhaoui
Copy link
Member

@grahamc thanks seems to be working now !

@grahamc
Copy link
Member Author

grahamc commented Feb 22, 2020

I rebased this on to the reformatted master, since reformatting & a mechanical 2->3 operation is probably a good thing to bulk together.

Copy link
Contributor

@talyz talyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! Seems to be working well! I tried running without any plugins, only using deployment.targetHost and could run create, deploy, ssh, info and export without any issue.

@dhess
Copy link
Contributor

dhess commented Feb 26, 2020

I've tested this with 4 of my own deployments (mainly deploy) and it's working great for me.

@grahamc
Copy link
Member Author

grahamc commented Feb 27, 2020

Note, other people can test this PR too. If you only use the none backend, you can simply:

nix-build ./release.nix -A build.x86_64-linux

and use the resulting ./result/bin/nixops.

@grahamc
Copy link
Member Author

grahamc commented Feb 27, 2020

btw I'm planning on merging this tomorrow.

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not approving the code (which I haven't looked at), but I'm approving that my usual nixops workflow is fine with this build.

Thanks for your work @grahamc! 🎉

@elseym
Copy link
Member

elseym commented Feb 28, 2020

just tested this on darwin, got the following error:

building all machine configurations...
Traceback (most recent call last):
  File "/nix/store/3jp88jwfpy4nabx8fwh970mpdacihp0l-nixops-1.8pre0_abcdef/bin/.nixops-wrapped", line 251, in <module>
    args.op(args)
  File "/nix/store/3jp88jwfpy4nabx8fwh970mpdacihp0l-nixops-1.8pre0_abcdef/lib/python3.7/site-packages/nixops/script_defs.py", line 571, in op_deploy
    max_concurrent_activate=args.max_concurrent_activate,
  File "/nix/store/3jp88jwfpy4nabx8fwh970mpdacihp0l-nixops-1.8pre0_abcdef/lib/python3.7/site-packages/nixops/deployment.py", line 1347, in deploy
    self.run_with_notify("deploy", lambda: self._deploy(**kwargs))
  File "/nix/store/3jp88jwfpy4nabx8fwh970mpdacihp0l-nixops-1.8pre0_abcdef/lib/python3.7/site-packages/nixops/deployment.py", line 1336, in run_with_notify
    f()
  File "/nix/store/3jp88jwfpy4nabx8fwh970mpdacihp0l-nixops-1.8pre0_abcdef/lib/python3.7/site-packages/nixops/deployment.py", line 1347, in <lambda>
    self.run_with_notify("deploy", lambda: self._deploy(**kwargs))
  File "/nix/store/3jp88jwfpy4nabx8fwh970mpdacihp0l-nixops-1.8pre0_abcdef/lib/python3.7/site-packages/nixops/deployment.py", line 1267, in _deploy
    dry_run=dry_run, repair=repair, include=include, exclude=exclude
  File "/nix/store/3jp88jwfpy4nabx8fwh970mpdacihp0l-nixops-1.8pre0_abcdef/lib/python3.7/site-packages/nixops/deployment.py", line 772, in build_configs
    key_file = m.get_ssh_private_key_file()
  File "/nix/store/3jp88jwfpy4nabx8fwh970mpdacihp0l-nixops-1.8pre0_abcdef/lib/python3.7/site-packages/nixops/backends/none.py", line 93, in get_ssh_private_key_file
    return self.write_ssh_private_key(self._ssh_private_key)
  File "/nix/store/3jp88jwfpy4nabx8fwh970mpdacihp0l-nixops-1.8pre0_abcdef/lib/python3.7/site-packages/nixops/backends/__init__.py", line 375, in write_ssh_private_key
    f.write(private_key)
TypeError: write() argument must be str, not None

we suspect that this is because not all hosts in the deployment are in the state file yet.

/cc @lheckemann

@lheckemann
Copy link
Member

we suspect that this is because not all hosts in the deployment are in the state file yet.

we just realised: this is correct but has nothing to do with the python3 changes and happens with --build-only in the python2 version if the hosts have never been deployed before as well.

@grahamc grahamc closed this Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants