|
437 | 437 | run_podman volume rm $volume_name
|
438 | 438 | }
|
439 | 439 |
|
| 440 | +# A quadlet container template depends on a quadlet volume and network templates |
| 441 | +@test "quadlet - template dependency" { |
| 442 | + # Save the unit name to use as the volume template for the container template |
| 443 | + local quadlet_vol_unit=dep_$(safename)@.volume |
| 444 | + local quadlet_vol_file=$PODMAN_TMPDIR/${quadlet_vol_unit} |
| 445 | + cat > $quadlet_vol_file <<EOF |
| 446 | +[Volume] |
| 447 | +EOF |
| 448 | + |
| 449 | + local quadlet_tmpdir=$(mktemp -d --tmpdir=$PODMAN_TMPDIR quadlet.XXXXXX) |
| 450 | + # Have quadlet create the systemd unit file for the volume template unit |
| 451 | + run_quadlet "$quadlet_vol_file" "$quadlet_tmpdir" |
| 452 | + |
| 453 | + # Save the volume service name since the variable will be overwritten |
| 454 | + local vol_service=$QUADLET_SERVICE_NAME |
| 455 | + local volume_name=systemd-$(basename $quadlet_vol_file .volume) |
| 456 | + # For template units, the volume name should have -%i appended |
| 457 | + volume_name=${volume_name%@}-%i |
| 458 | + |
| 459 | + # Save the unit name to use as the volume template for the container template |
| 460 | + local quadlet_net_unit=dep_$(safename)@.network |
| 461 | + local quadlet_net_file=$PODMAN_TMPDIR/${quadlet_net_unit} |
| 462 | + cat > $quadlet_net_file <<EOF |
| 463 | +[Network] |
| 464 | +EOF |
| 465 | + |
| 466 | + # Have quadlet create the systemd unit file for the network template unit |
| 467 | + run_quadlet "$quadlet_net_file" "$quadlet_tmpdir" |
| 468 | + |
| 469 | + # Save the network service name since the variable will be overwritten |
| 470 | + local net_service=$QUADLET_SERVICE_NAME |
| 471 | + local network_name=systemd-$(basename $quadlet_net_file .network) |
| 472 | + # For template units, the network name should have -%i appended |
| 473 | + network_name=${network_name%@}-%i |
| 474 | + |
| 475 | + local quadlet_file=$PODMAN_TMPDIR/user_$(safename)@.container |
| 476 | + cat > $quadlet_file <<EOF |
| 477 | +[Container] |
| 478 | +Image=$IMAGE |
| 479 | +Exec=top |
| 480 | +Volume=$quadlet_vol_unit:/tmp |
| 481 | +Network=$quadlet_net_unit |
| 482 | +EOF |
| 483 | + |
| 484 | + # Have quadlet create the systemd unit file for the container template unit |
| 485 | + run_quadlet "$quadlet_file" "$quadlet_tmpdir" |
| 486 | + |
| 487 | + # Save the container service name for readability |
| 488 | + local container_service=$QUADLET_SERVICE_NAME |
| 489 | + |
| 490 | + # Create instance names for the template units |
| 491 | + local instance_name="test" |
| 492 | + local vol_service_instance="${vol_service%@*}@${instance_name}.service" |
| 493 | + local net_service_instance="${net_service%@*}@${instance_name}.service" |
| 494 | + local container_service_instance="${container_service%@*}@${instance_name}.service" |
| 495 | + local volume_name_instance="systemd-dep_$(safename)-${instance_name}" |
| 496 | + local network_name_instance="systemd-dep_$(safename)-${instance_name}" |
| 497 | + |
| 498 | + # Volume should not exist |
| 499 | + run_podman 1 volume exists ${volume_name_instance} |
| 500 | + # Network should not exist |
| 501 | + run_podman 1 network exists ${network_name_instance} |
| 502 | + |
| 503 | + # Start the container service instance which should also trigger the start of the volume service instance |
| 504 | + service_setup $container_service_instance |
| 505 | + |
| 506 | + # Volume system unit instance should be active |
| 507 | + run systemctl show --property=ActiveState "$vol_service_instance" |
| 508 | + assert "$output" = "ActiveState=active" \ |
| 509 | + "volume template instance should be active via dependency" |
| 510 | + |
| 511 | + # Network system unit instance should be active |
| 512 | + run systemctl show --property=ActiveState "$net_service_instance" |
| 513 | + assert "$output" = "ActiveState=active" \ |
| 514 | + "network template instance should be active via dependency" |
| 515 | + |
| 516 | + # Volume should exist |
| 517 | + run_podman volume exists ${volume_name_instance} |
| 518 | + |
| 519 | + # Network should exist |
| 520 | + run_podman network exists ${network_name_instance} |
| 521 | + |
| 522 | + # Shutdown the service and remove the volume and network |
| 523 | + service_cleanup $container_service_instance failed |
| 524 | + run_podman volume rm $volume_name_instance |
| 525 | + run_podman network rm $network_name_instance |
| 526 | + for UNIT_FILE in ${UNIT_FILES[@]}; do |
| 527 | + rm $UNIT_FILE |
| 528 | + done |
| 529 | + UNIT_FILES=() |
| 530 | +} |
| 531 | + |
440 | 532 | # A quadlet container depends on a named quadlet volume
|
441 | 533 | @test "quadlet - named volume dependency" {
|
442 | 534 | local volume_name="v-$(safename)"
|
|
0 commit comments