Test that we move files correctly on regtest upgrade
(node_factory)
| 2729 | |
| 2730 | @unittest.skipIf(env('COMPAT') != 1, "Upgrade code requires COMPAT_V073") |
| 2731 | def test_regtest_upgrade(node_factory): |
| 2732 | """Test that we move files correctly on regtest upgrade""" |
| 2733 | l1 = node_factory.get_node(start=False) |
| 2734 | |
| 2735 | basedir = l1.daemon.opts.get("lightning-dir") |
| 2736 | netdir = os.path.join(basedir, TEST_NETWORK) |
| 2737 | |
| 2738 | # Make it old-style |
| 2739 | os.rename(os.path.join(basedir, TEST_NETWORK, 'hsm_secret'), |
| 2740 | os.path.join(basedir, 'hsm_secret')) |
| 2741 | shutil.rmtree(os.path.join(basedir, TEST_NETWORK)) |
| 2742 | # Add config file which tells us it's regtest; it should be left in place. |
| 2743 | with open(os.path.join(basedir, 'config'), 'wb') as f: |
| 2744 | f.write(bytes("network={}".format(TEST_NETWORK), "utf-8")) |
| 2745 | with open(os.path.join(basedir, 'another_file'), 'wb') as f: |
| 2746 | pass |
| 2747 | |
| 2748 | # We need to allow this, otherwise no upgrade! |
| 2749 | del l1.daemon.opts['allow-deprecated-apis'] |
| 2750 | # It should get this from the config file. |
| 2751 | del l1.daemon.opts['network'] |
| 2752 | |
| 2753 | l1.start() |
| 2754 | |
| 2755 | assert l1.daemon.is_in_log("Moving hsm_secret into {}/".format(netdir)) |
| 2756 | assert l1.daemon.is_in_log("Moving another_file into {}/".format(netdir)) |
| 2757 | assert not l1.daemon.is_in_log("Moving config into {}/".format(netdir)) |
| 2758 | assert not l1.daemon.is_in_log("Moving lightningd-testnet.pid into {}/" |
| 2759 | .format(netdir)) |
| 2760 | |
| 2761 | # Should move these |
| 2762 | assert os.path.isfile(os.path.join(netdir, "hsm_secret")) |
| 2763 | assert not os.path.isfile(os.path.join(basedir, "hsm_secret")) |
| 2764 | assert os.path.isfile(os.path.join(netdir, "another_file")) |
| 2765 | assert not os.path.isfile(os.path.join(basedir, "another_file")) |
| 2766 | |
| 2767 | # Should NOT move these |
| 2768 | assert not os.path.isfile(os.path.join(netdir, "lightningd-{}.pid".format(TEST_NETWORK))) |
| 2769 | assert os.path.isfile(os.path.join(basedir, "lightningd-{}.pid".format(TEST_NETWORK))) |
| 2770 | assert not os.path.isfile(os.path.join(netdir, "config")) |
| 2771 | assert os.path.isfile(os.path.join(basedir, "config")) |
| 2772 | |
| 2773 | # Should restart fine |
| 2774 | l1.restart() |
| 2775 | |
| 2776 | restore_valgrind(l1, netdir) |
| 2777 | |
| 2778 | |
| 2779 | @unittest.skipIf(VALGRIND, "valgrind files can't be written since we rmdir") |