1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
package v2
import (
"testing"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharetypes"
)
// CreateShareType will create a share type with a random name. An
// error will be returned if the share type was unable to be created.
func CreateShareType(t *testing.T, client *gophercloud.ServiceClient) (*sharetypes.ShareType, error) {
if testing.Short() {
t.Skip("Skipping test that requires share type creation in short mode.")
}
shareTypeName := tools.RandomString("ACPTTEST", 16)
t.Logf("Attempting to create share type: %s", shareTypeName)
extraSpecsOps := sharetypes.ExtraSpecsOpts{
DriverHandlesShareServers: true,
}
createOpts := sharetypes.CreateOpts{
Name: shareTypeName,
IsPublic: false,
ExtraSpecs: extraSpecsOps,
}
shareType, err := sharetypes.Create(client, createOpts).Extract()
if err != nil {
return shareType, err
}
return shareType, nil
}
// DeleteShareType will delete a share type. An error will occur if
// the share type was unable to be deleted.
func DeleteShareType(t *testing.T, client *gophercloud.ServiceClient, shareType *sharetypes.ShareType) {
err := sharetypes.Delete(client, shareType.ID).ExtractErr()
if err != nil {
t.Fatalf("Failed to delete share type %s: %v", shareType.ID, err)
}
t.Logf("Deleted share type: %s", shareType.ID)
}
// PrintShareType will print a share type and all of its attributes.
func PrintShareType(t *testing.T, shareType *sharetypes.ShareType) {
t.Logf("Name: %s", shareType.Name)
t.Logf("ID: %s", shareType.ID)
t.Logf("OS share type access is public: %t", shareType.IsPublic)
t.Logf("Extra specs: %#v", shareType.ExtraSpecs)
}
|