Skip to content

Commit

Permalink
tests: Update for scriptlet placement error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Oct 28, 2024
1 parent 8043469 commit ed4435f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 6 additions & 3 deletions test/suites/clustering_instance_placement_scriptlet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ EOF
! INCUS_DIR="${INCUS_ONE_DIR}" incus init testimage c1 || false

# Set instance placement scriptlet to one that sets an invalid cluster member target.
# Check that instance placement uses Incus's built in logic instead (as if setTarget hadn't been called at all).
# Confirm that we get a placement error.
cat << EOF | incus config set instances.placement.scriptlet=-
def instance_placement(request, candidate_members):
# Set invalid member target.
Expand All @@ -130,8 +130,11 @@ def instance_placement(request, candidate_members):
return
EOF

INCUS_DIR="${INCUS_ONE_DIR}" incus init testimage c1 -c cluster.evacuate=migrate
INCUS_DIR="${INCUS_ONE_DIR}" incus info c1 | grep -q "Location: node1"
! INCUS_DIR="${INCUS_ONE_DIR}" incus init testimage c1 -c cluster.evacuate=migrate || false

# Create an instance
incus config unset instances.placement.scriptlet
INCUS_DIR="${INCUS_ONE_DIR}" incus init testimage c1 -c cluster.evacuate=migrate --target node1

# Set basic instance placement scriptlet that statically targets to 3rd member.
cat << EOF | incus config set instances.placement.scriptlet=-
Expand Down
6 changes: 2 additions & 4 deletions test/suites/clustering_move.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ EOF
INCUS_DIR="${INCUS_ONE_DIR}" incus move c2 --target @foobar3
INCUS_DIR="${INCUS_ONE_DIR}" incus info c2 | grep -q "Location: node3"

# Ensure that setting an invalid target won't interrupt the move and fall back to the built in behavior.
# Equally distribute the instances beforehand so that node1 will get selected.
# Ensure that setting an invalid target causes the error to be raised.
INCUS_DIR="${INCUS_ONE_DIR}" incus move c2 --target node2

cat << EOF | INCUS_DIR="${INCUS_ONE_DIR}" incus config set instances.placement.scriptlet=-
Expand All @@ -134,8 +133,7 @@ def instance_placement(request, candidate_members):
return
EOF

INCUS_DIR="${INCUS_ONE_DIR}" incus move c1 --target @foobar1
INCUS_DIR="${INCUS_ONE_DIR}" incus info c1 | grep -q "Location: node1"
! INCUS_DIR="${INCUS_ONE_DIR}" incus move c1 --target @foobar1 || false

# If the scriptlet produces a runtime error, the move fails.
cat << EOF | INCUS_DIR="${INCUS_ONE_DIR}" incus config set instances.placement.scriptlet=-
Expand Down

0 comments on commit ed4435f

Please sign in to comment.