From 073c37e57daae26fc99eb410a7d0b8f479ee4822 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 9 Apr 2024 18:55:26 +0800 Subject: [PATCH] Problem: upgrade test nix package is incorrect (#1384) --- flake.nix | 10 +++++++ .../configs/upgrade-test-package.nix | 11 ++++--- integration_tests/test_upgrade.py | 30 ++++++++----------- nix/build_overlay.nix | 17 ----------- 4 files changed, 28 insertions(+), 40 deletions(-) diff --git a/flake.nix b/flake.nix index f324f12962..b27e354e0c 100644 --- a/flake.nix +++ b/flake.nix @@ -81,6 +81,16 @@ go = super.go_1_22; test-env = final.callPackage ./nix/testenv.nix { }; bundle-exe = final.pkgsBuildBuild.callPackage nix-bundle-exe { }; + # make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references. + # reset the ownership and permissions to make the extract result more normal. + make-tarball = drv: final.runCommand "tarball-${drv.name}" + { + nativeBuildInputs = with final.buildPackages; [ gnutar gzip ]; + } '' + tar cfv - -C "${drv}" \ + --owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \ + | gzip -9 > $out + ''; bundle-win-exe = drv: final.callPackage ./nix/bundle-win-exe.nix { cronosd = drv; }; } // (with final; let diff --git a/integration_tests/configs/upgrade-test-package.nix b/integration_tests/configs/upgrade-test-package.nix index 438599719e..2d06b77080 100644 --- a/integration_tests/configs/upgrade-test-package.nix +++ b/integration_tests/configs/upgrade-test-package.nix @@ -19,10 +19,9 @@ let # v1.1.1 released = (fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default; current = pkgs.callPackage ../../. { }; - farm = pkgs.linkFarm "upgrade-test-package" [ - { name = "genesis/bin"; path = "${released0}/bin"; } - { name = "v1.1.0/bin"; path = "${released}/bin"; } - { name = "v1.2/bin"; path = "${current}/bin"; } - ]; in -pkgs.make-tarball farm +pkgs.linkFarm "upgrade-test-package" [ + { name = "genesis"; path = released0; } + { name = "v1.1.0"; path = released; } + { name = "v1.2"; path = current; } +] diff --git a/integration_tests/test_upgrade.py b/integration_tests/test_upgrade.py index a430883f6b..e77b80fa0b 100644 --- a/integration_tests/test_upgrade.py +++ b/integration_tests/test_upgrade.py @@ -1,4 +1,6 @@ import json +import shutil +import stat import subprocess from contextlib import contextmanager from datetime import datetime, timedelta @@ -72,35 +74,29 @@ def setup_cronos_test(tmp_path_factory): port = 26200 nix_name = "upgrade-test-package" cfg_name = "cosmovisor" + configdir = Path(__file__).parent cmd = [ "nix-build", - Path(__file__).parent / f"configs/{nix_name}.nix", - "-o", - path / "upgrades.tar.gz", + configdir / f"configs/{nix_name}.nix", ] print(*cmd) subprocess.run(cmd, check=True) - # extract the tarball so the directory is writable. - (path / "upgrades").mkdir() - subprocess.run( - [ - "tar", - "xfz", - path / "upgrades.tar.gz", - "-C", - path / "upgrades", - ], - check=True, - ) + # copy the content so the new directory is writable. + upgrades = path / "upgrades" + shutil.copytree("./result", upgrades) + mod = stat.S_IRWXU + upgrades.chmod(mod) + for d in upgrades.iterdir(): + d.chmod(mod) # init with genesis binary with contextmanager(setup_custom_cronos)( path, port, - Path(__file__).parent / f"configs/{cfg_name}.jsonnet", + configdir / f"configs/{cfg_name}.jsonnet", post_init=post_init, - chain_binary=str(path / "upgrades/genesis/bin/cronosd"), + chain_binary=str(upgrades / "genesis/bin/cronosd"), ) as cronos: yield cronos diff --git a/nix/build_overlay.nix b/nix/build_overlay.nix index 749d3e9e03..476654e669 100644 --- a/nix/build_overlay.nix +++ b/nix/build_overlay.nix @@ -1,21 +1,4 @@ # some basic overlays nessesary for the build final: super: { rocksdb = final.callPackage ./rocksdb.nix { }; - - # make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references. - # reset the ownership and permissions to make the extract result more normal. - make-tarball = final.callPackage - ({ buildPackages - , runCommand - }: drv: runCommand "tarball-${drv.name}" - { - nativeBuildInputs = with buildPackages; [ gnutar gzip ]; - } - '' - tar cfv - -C "${drv}" \ - --owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \ - | gzip -9 > $out - '' - ) - { }; }