tests: add extra_tests argument to scenario lib run_tests()

This commit is contained in:
Jonas Nick 2020-08-02 21:36:08 +00:00
parent 6f9349b0a4
commit 5fa0602a18
No known key found for this signature in database
GPG Key ID: 4861DBF262123605
3 changed files with 81 additions and 50 deletions

View File

@ -1,25 +1,36 @@
run_tests() def electrs():
machine.wait_for_open_port(4224) # prometeus metrics provider
## electrs
# the main test body stops electrs
succeed("systemctl start electrs")
machine.wait_for_open_port(4224) # prometeus metrics provider
## spark-wallet def spark_wallet():
machine.wait_for_open_port(9737) machine.wait_for_open_port(9737)
spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1] spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1]
assert_matches(f"curl -s {spark_auth}@localhost:9737", "Spark") assert_matches(f"curl -s {spark_auth}@localhost:9737", "Spark")
## lightning-charge
machine.wait_for_open_port(9112)
charge_auth = re.search("API_TOKEN=(.*)", succeed("cat /secrets/lightning-charge-env"))[1]
assert_matches(f"curl -s api-token:{charge_auth}@localhost:9112/info | jq", '"id"')
## nanopos def lightning_charge():
machine.wait_for_open_port(9116) machine.wait_for_open_port(9112)
assert_matches("curl localhost:9116", "tshirt") charge_auth = re.search("API_TOKEN=(.*)", succeed("cat /secrets/lightning-charge-env"))[1]
assert_matches(f"curl -s api-token:{charge_auth}@localhost:9112/info | jq", '"id"')
## web index
machine.wait_for_open_port(80) def nanopos():
assert_matches("curl localhost", "nix-bitcoin") machine.wait_for_open_port(9116)
assert_matches("curl -L localhost/store", "tshirt") assert_matches("curl localhost:9116", "tshirt")
def web_index():
machine.wait_for_open_port(80)
assert_matches("curl localhost", "nix-bitcoin")
assert_matches("curl -L localhost/store", "tshirt")
extra_tests = {
"electrs": electrs,
"spark-wallet": spark_wallet,
"lightning-charge": lightning_charge,
"nanopos": nanopos,
"web-index": web_index,
}
run_tests(extra_tests)

View File

@ -35,8 +35,9 @@ if "is_interactive" in vars():
### Tests ### Tests
# The argument extra_tests is a dictionary from strings to functions. The string
def run_tests(): # determines at which point of run_tests the corresponding function is executed.
def run_tests(extra_tests):
assert_running("setup-secrets") assert_running("setup-secrets")
# Unused secrets should be inaccessible # Unused secrets should be inaccessible
succeed('[[ $(stat -c "%U:%G %a" /secrets/dummy) = "root:root 440" ]]') succeed('[[ $(stat -c "%U:%G %a" /secrets/dummy) = "root:root 440" ]]')
@ -55,6 +56,7 @@ def run_tests():
) )
assert_running("electrs") assert_running("electrs")
extra_tests.pop("electrs")()
# Check RPC connection to bitcoind # Check RPC connection to bitcoind
machine.wait_until_succeeds(log_has_string("electrs", "NetworkInfo")) machine.wait_until_succeeds(log_has_string("electrs", "NetworkInfo"))
assert_running("nginx") assert_running("nginx")
@ -70,10 +72,13 @@ def run_tests():
assert_matches("su operator -c 'lightning-cli getinfo' | jq", '"id"') assert_matches("su operator -c 'lightning-cli getinfo' | jq", '"id"')
assert_running("spark-wallet") assert_running("spark-wallet")
extra_tests.pop("spark-wallet")()
assert_running("lightning-charge") assert_running("lightning-charge")
extra_tests.pop("lightning-charge")()
assert_running("nanopos") assert_running("nanopos")
extra_tests.pop("nanopos")()
assert_running("onion-chef") assert_running("onion-chef")
@ -81,6 +86,7 @@ def run_tests():
# to incomplete unit dependencies. # to incomplete unit dependencies.
# 'create-web-index' implicitly tests 'nodeinfo'. # 'create-web-index' implicitly tests 'nodeinfo'.
machine.wait_for_unit("create-web-index") machine.wait_for_unit("create-web-index")
extra_tests.pop("web-index")()
machine.wait_until_succeeds(log_has_string("bitcoind-import-banlist", "Importing node banlist")) machine.wait_until_succeeds(log_has_string("bitcoind-import-banlist", "Importing node banlist"))
assert_no_failure("bitcoind-import-banlist") assert_no_failure("bitcoind-import-banlist")
@ -128,3 +134,6 @@ def run_tests():
### Stop lnd and restart clightning ### Stop lnd and restart clightning
succeed("systemctl stop lnd") succeed("systemctl stop lnd")
succeed("systemctl start " + stopped_services) succeed("systemctl start " + stopped_services)
### Check that all extra_tests have been run
assert len(extra_tests) == 0

View File

@ -1,5 +1,3 @@
run_tests()
# netns IP addresses # netns IP addresses
bitcoind_ip = "169.254.1.12" bitcoind_ip = "169.254.1.12"
clightning_ip = "169.254.1.13" clightning_ip = "169.254.1.13"
@ -13,38 +11,51 @@ recurringdonations_ip = "169.254.1.20"
nginx_ip = "169.254.1.21" nginx_ip = "169.254.1.21"
## electrs ## electrs
# the main test body stops electrs def electrs():
succeed("systemctl start electrs") machine.wait_until_succeeds(
machine.wait_until_succeeds(
"ip netns exec nb-electrs nc -z localhost 4224" "ip netns exec nb-electrs nc -z localhost 4224"
) # prometeus metrics provider ) # prometeus metrics provider
## spark-wallet
machine.wait_until_succeeds("ip netns exec nb-spark-wallet nc -z %s 9737" % sparkwallet_ip) def spark_wallet():
spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1] machine.wait_until_succeeds("ip netns exec nb-spark-wallet nc -z %s 9737" % sparkwallet_ip)
assert_matches( spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1]
assert_matches(
f"ip netns exec nb-spark-wallet curl -s {spark_auth}@%s:9737" % sparkwallet_ip, "Spark" f"ip netns exec nb-spark-wallet curl -s {spark_auth}@%s:9737" % sparkwallet_ip, "Spark"
) )
## lightning-charge
machine.wait_until_succeeds("ip netns exec nb-nanopos nc -z %s 9112" % lightningcharge_ip) def lightning_charge():
charge_auth = re.search("API_TOKEN=(.*)", succeed("cat /secrets/lightning-charge-env"))[1] machine.wait_until_succeeds("ip netns exec nb-nanopos nc -z %s 9112" % lightningcharge_ip)
assert_matches( charge_auth = re.search("API_TOKEN=(.*)", succeed("cat /secrets/lightning-charge-env"))[1]
assert_matches(
f"ip netns exec nb-nanopos curl -s api-token:{charge_auth}@%s:9112/info | jq" f"ip netns exec nb-nanopos curl -s api-token:{charge_auth}@%s:9112/info | jq"
% lightningcharge_ip, % lightningcharge_ip,
'"id"', '"id"',
) )
## nanopos
machine.wait_until_succeeds("ip netns exec nb-lightning-charge nc -z %s 9116" % nanopos_ip)
assert_matches("ip netns exec nb-lightning-charge curl %s:9116" % nanopos_ip, "tshirt")
## webindex def nanopos():
machine.wait_until_succeeds("ip netns exec nb-nginx nc -z localhost 80") machine.wait_until_succeeds("ip netns exec nb-lightning-charge nc -z %s 9116" % nanopos_ip)
assert_matches("ip netns exec nb-nginx curl localhost", "nix-bitcoin") assert_matches("ip netns exec nb-lightning-charge curl %s:9116" % nanopos_ip, "tshirt")
assert_matches("ip netns exec nb-nginx curl -L localhost/store", "tshirt")
def web_index():
machine.wait_until_succeeds("ip netns exec nb-nginx nc -z localhost 80")
assert_matches("ip netns exec nb-nginx curl localhost", "nix-bitcoin")
assert_matches("ip netns exec nb-nginx curl -L localhost/store", "tshirt")
extra_tests = {
"electrs": electrs,
"spark-wallet": spark_wallet,
"lightning-charge": lightning_charge,
"nanopos": nanopos,
"web-index": web_index,
}
run_tests(extra_tests)
### Security tests ### Security tests
ping_bitcoind = "ip netns exec nb-bitcoind ping -c 1 -w 1" ping_bitcoind = "ip netns exec nb-bitcoind ping -c 1 -w 1"