Skip to content

Commit

Permalink
tests: Add tests for --description flag on create commands
Browse files Browse the repository at this point in the history
Signed-off-by: Luís Simas <[email protected]>
  • Loading branch information
luissimas committed Dec 13, 2024
1 parent d6d6ed2 commit 47db142
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 17 deletions.
7 changes: 6 additions & 1 deletion test/suites/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ test_basic_usage() {
incus image alias list | grep -qv foo # the old name is gone
incus image alias delete bar

# Test an alias with description
incus image alias create baz "${sum}" --description "Test description"
incus image alias list | grep -q 'Test description'
incus image delete baz

# Test image list output formats (table & json)
incus image list --format table | grep -q testimage
incus image list --format json \
Expand Down Expand Up @@ -373,7 +378,7 @@ test_basic_usage() {
kill_incus "${INCUS_ACTIVATION_DIR}"

# Create and start a container
incus launch testimage foo
incus launch testimage foo --description "Test container"
incus list | grep foo | grep RUNNING
incus stop foo --force

Expand Down
3 changes: 2 additions & 1 deletion test/suites/clustering.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3449,8 +3449,9 @@ test_clustering_groups() {
! incus cluster group remove cluster:node1 default || false

# Create new cluster group which should be empty
incus cluster group create cluster:foobar
incus cluster group create cluster:foobar --description "Test description"
[ "$(incus query cluster:/1.0/cluster/groups/foobar | jq '.members | length')" -eq 0 ]
[ "$(incus query cluster:/1.0/cluster/groups/foobar | jq '.description == "Test description"')" = "true" ]

# Copy both description and members from default group
incus cluster group show cluster:default | incus cluster group edit cluster:foobar
Expand Down
5 changes: 5 additions & 0 deletions test/suites/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ test_config_profiles() {
incus profile remove foo one
[ "$(incus list -f json foo | jq -r '.[0].profiles | join(" ")')" = "" ]

# check that we can create a profile with a description
incus profile create foo --description bar
incus profile ls | grep -q bar
incus profile delete foo

incus profile create stdintest
echo "BADCONF" | incus profile set stdintest user.user_data -
incus profile show stdintest | grep BADCONF
Expand Down
5 changes: 4 additions & 1 deletion test/suites/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ test_network() {
incus network delete inct$$

# edit network description
incus network create inct$$
incus network create inct$$ --description "Test description"
incus network list | grep -q 'Test description'
incus network show inct$$ | grep -q 'description: Test description'
incus network show inct$$ | sed 's/^description:.*/description: foo/' | incus network edit inct$$
incus network list | grep -q 'foo'
incus network show inct$$ | grep -q 'description: foo'
incus network delete inct$$

Expand Down
7 changes: 6 additions & 1 deletion test/suites/network_acl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ test_network_acl() {
! incus network acl ls | grep testacl || false
! incus network acl ls --project testproj | grep testacl || false
incus project delete testproj
incus network acl create testacl --description "Test description"
incus network acl list | grep -q -F 'Test description'
incus netwrok acl show testacl | grep -q -F 'description: Test description'
incus network acl delete testacl

# ACL creation from stdin.
cat <<EOF | incus network acl create testacl
Expand Down Expand Up @@ -88,10 +92,11 @@ EOF
! incus network acl rule add testacl ingress action=allow protocol=icmp4 icmp_code=256 || false # Invalid icmp combination
! incus network acl rule add testacl ingress action=allow protocol=icmp6 icmp_type=-1 || false # Invalid icmp combination

incus network acl rule add testacl ingress action=allow source=192.168.1.2/32 protocol=tcp destination=192.168.1.1-192.168.1.3 destination_port="22, 2222-2223"
incus network acl rule add testacl ingress action=allow source=192.168.1.2/32 protocol=tcp destination=192.168.1.1-192.168.1.3 destination_port="22, 2222-2223" --description "Test ACL rule description"
! incus network acl rule add testacl ingress action=allow source=192.168.1.2/32 protocol=tcp destination=192.168.1.1-192.168.1.3 destination_port=22,2222-2223 || false # Dupe rule detection
incus network acl show testacl | grep "destination: 192.168.1.1-192.168.1.3"
incus network acl show testacl | grep -c2 'state: enabled' # Default state enabled for new rules.
incus network acl show testacl | grep "description: Test ACL rule description"

# ACL rule removal.
incus network acl rule add testacl ingress action=allow source=192.168.1.3/32 protocol=tcp destination=192.168.1.1-192.168.1.3 destination_port=22,2222-2223 description="removal rule test"
Expand Down
11 changes: 9 additions & 2 deletions test/suites/network_forward.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_network_forward() {
! incus network forward create "${netName}" :: || false

# Check creating empty forward doesn't create any firewall rules.
incus network forward create "${netName}" 198.51.100.1
incus network forward create "${netName}" 198.51.100.1 --description "Test network forward"
if [ "$firewallDriver" = "xtables" ]; then
! iptables -w -t nat -S | grep -c "generated for Incus network-forward ${netName}" || false
else
Expand All @@ -25,6 +25,10 @@ test_network_forward() {
! nft -nn list chain inet incus "fwdpstrt.${netName}" || false
fi

# Check that description is set
incus network forward list "${netName}" | grep -q -F "Test network forward"
incus network forward show "${netName}" 198.51.100.1 | grep -q -F "description: Test network forward"

# Check forward is exported via BGP prefixes.
incus query /internal/testing/bgp | grep "198.51.100.1/32"

Expand Down Expand Up @@ -63,7 +67,7 @@ test_network_forward() {
! incus network forward port add "${netName}" 198.51.100.1 tcp 80 192.0.2.3 80-81 || false

# Check can add a port with a listener range and no target port (so it uses same range for target ports).
incus network forward port add "${netName}" 198.51.100.1 tcp 80-81 192.0.2.3
incus network forward port add "${netName}" 198.51.100.1 tcp 80-81 192.0.2.3 --description "Test network forward port"
if [ "$firewallDriver" = "xtables" ]; then
iptables -w -t nat -S | grep -- "-A PREROUTING -d 198.51.100.1/32 -p tcp -m tcp --dport 80:81 -m comment --comment \"generated for Incus network-forward ${netName}\" -j DNAT --to-destination 192.0.2.3"
iptables -w -t nat -S | grep -- "-A OUTPUT -d 198.51.100.1/32 -p tcp -m tcp --dport 80:81 -m comment --comment \"generated for Incus network-forward ${netName}\" -j DNAT --to-destination 192.0.2.3"
Expand All @@ -74,6 +78,9 @@ test_network_forward() {
nft -nn list chain inet incus "fwdpstrt.${netName}" | grep "ip saddr 192.0.2.3 ip daddr 192.0.2.3 tcp dport 80-81 masquerade"
fi

# Check that description is set
incus network forward show "${netName}" 198.51.100.1 | grep -q -F 'description: Test network forward port'

# Check can't add port with duplicate listen port.
! incus network forward port add "${netName}" 198.51.100.1 tcp 80 192.0.2.3 90 || false

Expand Down
10 changes: 8 additions & 2 deletions test/suites/network_zone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ test_network_zone() {
! incus network zone create /incus.example.net || false
incus network zone create incus.example.net/withslash
incus network zone delete incus.example.net/withslash
incus network zone create incus.example.net
incus network zone create incus.example.net --description "Test network zone"
incus network zone create 2.0.192.in-addr.arpa
incus network zone create 0.1.0.1.2.4.2.4.2.4.2.4.2.4.d.f.ip6.arpa

# Check that the description is set
incus network zone list | grep -q -F 'Test network zone'
incus network zone show incus.example.net | grep -q -F 'description: Test network zone'

# Create project and forward zone in project.
incus project create foo \
-c features.images=false \
Expand Down Expand Up @@ -117,7 +121,7 @@ test_network_zone() {
dig "@${DNS_ADDR}" -p "${DNS_PORT}" axfr 0.1.0.1.2.4.2.4.2.4.2.4.2.4.d.f.ip6.arpa | grep "300\s\+IN\s\+PTR\s\+c2.incus-foo.example.net."

# Test extra records
incus network zone record create incus.example.net demo user.foo=bar
incus network zone record create incus.example.net demo user.foo=bar --description "Test network zone record"
! incus network zone record create incus.example.net demo user.foo=bar || false
incus network zone record entry add incus.example.net demo A 1.1.1.1 --ttl 900
incus network zone record entry add incus.example.net demo A 2.2.2.2
Expand All @@ -128,6 +132,8 @@ test_network_zone() {
incus network zone record list incus.example.net
dig "@${DNS_ADDR}" -p "${DNS_PORT}" axfr incus.example.net | grep -Fc demo.incus.example.net | grep -Fx 6
incus network zone record entry remove incus.example.net demo A 1.1.1.1
incus network zone record list incus.example.net | grep -q -F "Test network zone record"
incus network zone record show incus.example.net demo | grep -q -F "description: Test network zone record"

incus admin sql global 'select * from networks_zones_records'
incus network zone record create incus-foo.example.net demo user.foo=bar --project foo
Expand Down
6 changes: 6 additions & 0 deletions test/suites/projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ test_projects_crud() {

incus project switch default

# Create a project with a description
incus project create baz --description "Test description"
incus project list | grep -q -F 'Test description'
incus project show baz | grep -q -F 'description: Test description'

# Delete the projects
incus project delete foo
incus project delete bar
incus project delete baz

# We're back to the default project
[ "$(incus project get-current)" = "default" ]
Expand Down
4 changes: 3 additions & 1 deletion test/suites/snapshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ snapshots() {
[ -d "${INCUS_DIR}/containers-snapshots/foo/snap1" ]
fi

incus snapshot create foo tester
incus snapshot create foo tester --description "Test description"
# FIXME: make this backend agnostic
if [ "$incus_backend" = "dir" ]; then
[ -d "${INCUS_DIR}/containers-snapshots/foo/tester" ]
fi
incus snapshot list foo | grep -q 'tester' | grep -q 'Test description'
incus info foo | grep -q 'tester.*Test description'

incus copy foo/tester foosnap1
# FIXME: make this backend agnostic
Expand Down
9 changes: 6 additions & 3 deletions test/suites/storage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ test_storage() {
local storage_pool storage_volume
storage_pool="incustest-$(basename "${INCUS_DIR}")-pool"
storage_volume="${storage_pool}-vol"
incus storage create "$storage_pool" "$incus_backend"
incus storage show "$storage_pool" | sed 's/^description:.*/description: foo/' | incus storage edit "$storage_pool"
incus storage create "$storage_pool" "$incus_backend" --description foo
incus storage show "$storage_pool" | grep -q 'description: foo'
incus storage show "$storage_pool" | sed 's/^description:.*/description: bar/' | incus storage edit "$storage_pool"
incus storage show "$storage_pool" | grep -q 'description: bar'

incus storage volume create "$storage_pool" "$storage_volume"
# Create a storage volume with a description
incus storage volume create "$storage_pool" "$storage_volume" --description foo
incus storage volume show "$storage_pool" "$storage_volume" | grep -q 'description: foo'

# Test setting description on a storage volume
incus storage volume show "$storage_pool" "$storage_volume" | sed 's/^description:.*/description: bar/' | incus storage volume edit "$storage_pool" "$storage_volume"
Expand Down
6 changes: 4 additions & 2 deletions test/suites/storage_buckets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,19 @@ test_storage_buckets() {
! incus storage bucket create "${poolName}" "foo bar" || false

# Create bucket.
initCreds=$(incus storage bucket create "${poolName}" "${bucketPrefix}.foo" user.foo=comment)
initCreds=$(incus storage bucket create "${poolName}" "${bucketPrefix}.foo" user.foo=comment --description "Test description")
initAccessKey=$(echo "${initCreds}" | awk '{ if ($2 == "access" && $3 == "key:") {print $4}}')
initSecretKey=$(echo "${initCreds}" | awk '{ if ($2 == "secret" && $3 == "key:") {print $4}}')
s3cmdrun "${incus_backend}" "${initAccessKey}" "${initSecretKey}" ls | grep -F "${bucketPrefix}.foo"

incus storage bucket list "${poolName}" | grep -F "${bucketPrefix}.foo"
incus storage bucket list "${poolName}" | grep -F "Test description"
incus storage bucket show "${poolName}" "${bucketPrefix}.foo"

# Create bucket keys.

# Create admin key with randomly generated credentials.
creds=$(incus storage bucket key create "${poolName}" "${bucketPrefix}.foo" admin-key --role=admin)
creds=$(incus storage bucket key create "${poolName}" "${bucketPrefix}.foo" admin-key --role=admin --description "Test description")
adAccessKey=$(echo "${creds}" | awk '{ if ($1 == "Access" && $2 == "key:") {print $3}}')
adSecretKey=$(echo "${creds}" | awk '{ if ($1 == "Secret" && $2 == "key:") {print $3}}')

Expand All @@ -102,6 +103,7 @@ test_storage_buckets() {

incus storage bucket key list "${poolName}" "${bucketPrefix}.foo" | grep -F "admin-key"
incus storage bucket key list "${poolName}" "${bucketPrefix}.foo" | grep -F "ro-key"
incus storage bucket key list "${poolName}" "${bucketPrefix}.foo" | grep -F "Test description"
incus storage bucket key show "${poolName}" "${bucketPrefix}.foo" admin-key
incus storage bucket key show "${poolName}" "${bucketPrefix}.foo" ro-key

Expand Down
7 changes: 4 additions & 3 deletions test/suites/storage_snapshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ test_storage_volume_snapshots() {
[ "$(incus exec c1 -- cat /mnt/testfile)" = 'foobar' ]

incus storage volume detach "${storage_pool}" "${storage_volume}" c1
# This will create a snapshot named 'snap0'
incus storage volume snapshot create "${storage_pool}" "${storage_volume}"
incus storage volume list "${storage_pool}" | grep "${storage_volume}/snap0"
# This will create a snapshot named 'snap0' with description 'Test description'
incus storage volume snapshot create "${storage_pool}" "${storage_volume}" --description "Test description"
incus storage volume list "${storage_pool}" | grep "${storage_volume}/snap0" | grep -F "Test description"
incus storage volume snapshot show "${storage_pool}" "${storage_volume}/snap0" | grep 'name: snap0'
incus storage volume snapshot show "${storage_pool}" "${storage_volume}/snap0" | grep 'expires_at: 0001-01-01T00:00:00Z'
incus storage volume snapshot show "${storage_pool}" "${storage_volume}/snap0" | grep 'description: Test description'

# edit volume snapshot description
incus storage volume snapshot show "${storage_pool}" "${storage_volume}/snap0" | sed 's/^description:.*/description: foo/' | incus storage volume edit "${storage_pool}" "${storage_volume}/snap0"
Expand Down

0 comments on commit 47db142

Please sign in to comment.