Skip to content

Commit

Permalink
nixos/octoprint: add tests for reachability over IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDaG committed Dec 19, 2024
1 parent 4b57ad7 commit e655521
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions nixos/tests/octoprint.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,40 @@ import ./make-test-python.nix (
};

testScript = ''
import json
import json
@polling_condition
def octoprint_running():
machine.succeed("pgrep octoprint")
@polling_condition
def octoprint_running():
machine.succeed("pgrep octoprint")
with subtest("Wait for octoprint service to start"):
machine.wait_for_unit("octoprint.service")
machine.wait_until_succeeds("pgrep octoprint")
with subtest("Wait for octoprint service to start"):
machine.wait_for_unit("octoprint.service")
machine.wait_until_succeeds("pgrep octoprint")
with subtest("Wait for final boot"):
# this appears whe octoprint is almost finished starting
machine.wait_for_file("/var/lib/octoprint/uploads")
with subtest("Wait for final boot"):
# this appears whe octoprint is almost finished starting
machine.wait_for_file("/var/lib/octoprint/uploads")
# octoprint takes some time to start. This makes sure we'll retry just in case it takes longer
# retry-all-errors in necessary, since octoprint will report a 404 error when not yet ready
curl_cmd = "curl --retry-all-errors --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 0 \
--retry-max-time 40 -X GET --header 'X-API-Key: ${apikey}' "
# octoprint takes some time to start. This makes sure we'll retry just in case it takes longer
# retry-all-errors in necessary, since octoprint will report a 404 error when not yet ready
curl_cmd = "curl --retry-all-errors --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 0 \
--retry-max-time 40 -X GET --header 'X-API-Key: ${apikey}' "
# used to fail early, in case octoprint first starts and then crashes
with octoprint_running: # type: ignore[union-attr]
with subtest("Check for web interface"):
machine.wait_until_succeeds("curl -s localhost:5000")
machine.wait_until_succeeds("curl -s -4 localhost:5000")
machine.wait_until_succeeds("curl -s -6 localhost:5000")
with subtest("Check API"):
version = json.loads(machine.succeed(curl_cmd + "localhost:5000/api/version"))
server = json.loads(machine.succeed(curl_cmd + "localhost:5000/api/server"))
with subtest("Check API IPv4"):
version = json.loads(machine.succeed(curl_cmd + "-4 localhost:5000/api/version"))
server = json.loads(machine.succeed(curl_cmd + "-4 localhost:5000/api/server"))
assert version["server"] == str("${pkgs.octoprint.version}")
assert server["safemode"] == None
with subtest("Check API IPv6"):
version = json.loads(machine.succeed(curl_cmd + "-6 localhost:5000/api/version"))
server = json.loads(machine.succeed(curl_cmd + "-6 localhost:5000/api/server"))
assert version["server"] == str("${pkgs.octoprint.version}")
assert server["safemode"] == None
'';
Expand Down

0 comments on commit e655521

Please sign in to comment.