Test that we move files correctly on regtest upgrade
(node_factory)
| 2759 | |
| 2760 | @unittest.skipIf(env('COMPAT') != 1, "Upgrade code requires COMPAT_V073") |
| 2761 | def test_regtest_upgrade(node_factory): |
| 2762 | """Test that we move files correctly on regtest upgrade""" |
| 2763 | l1 = node_factory.get_node(start=False) |
| 2764 | |
| 2765 | basedir = l1.daemon.opts.get("lightning-dir") |
| 2766 | netdir = os.path.join(basedir, TEST_NETWORK) |
| 2767 | |
| 2768 | # Make it old-style |
| 2769 | os.rename(os.path.join(basedir, TEST_NETWORK, 'hsm_secret'), |
| 2770 | os.path.join(basedir, 'hsm_secret')) |
| 2771 | shutil.rmtree(os.path.join(basedir, TEST_NETWORK)) |
| 2772 | # Add config file which tells us it's regtest; it should be left in place. |
| 2773 | with open(os.path.join(basedir, 'config'), 'wb') as f: |
| 2774 | f.write(bytes("network={}".format(TEST_NETWORK), "utf-8")) |
| 2775 | with open(os.path.join(basedir, 'another_file'), 'wb') as f: |
| 2776 | pass |
| 2777 | |
| 2778 | # We need to allow this, otherwise no upgrade! |
| 2779 | del l1.daemon.opts['allow-deprecated-apis'] |
| 2780 | # It should get this from the config file. |
| 2781 | del l1.daemon.opts['network'] |
| 2782 | |
| 2783 | l1.start() |
| 2784 | |
| 2785 | assert l1.daemon.is_in_log("Moving hsm_secret into {}/".format(netdir)) |
| 2786 | assert l1.daemon.is_in_log("Moving another_file into {}/".format(netdir)) |
| 2787 | assert not l1.daemon.is_in_log("Moving config into {}/".format(netdir)) |
| 2788 | assert not l1.daemon.is_in_log("Moving lightningd-testnet.pid into {}/" |
| 2789 | .format(netdir)) |
| 2790 | |
| 2791 | # Should move these |
| 2792 | assert os.path.isfile(os.path.join(netdir, "hsm_secret")) |
| 2793 | assert not os.path.isfile(os.path.join(basedir, "hsm_secret")) |
| 2794 | assert os.path.isfile(os.path.join(netdir, "another_file")) |
| 2795 | assert not os.path.isfile(os.path.join(basedir, "another_file")) |
| 2796 | |
| 2797 | # Should NOT move these |
| 2798 | assert not os.path.isfile(os.path.join(netdir, "lightningd-{}.pid".format(TEST_NETWORK))) |
| 2799 | assert os.path.isfile(os.path.join(basedir, "lightningd-{}.pid".format(TEST_NETWORK))) |
| 2800 | assert not os.path.isfile(os.path.join(netdir, "config")) |
| 2801 | assert os.path.isfile(os.path.join(basedir, "config")) |
| 2802 | |
| 2803 | # Should restart fine |
| 2804 | l1.restart() |
| 2805 | |
| 2806 | restore_valgrind(l1, netdir) |
| 2807 | |
| 2808 | |
| 2809 | @unittest.skipIf(VALGRIND, "valgrind files can't be written since we rmdir") |