github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/networking/v2/extensions/qos/policies/policies.go (about)

     1  package policies
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gophercloud/gophercloud"
     7  	"github.com/gophercloud/gophercloud/internal/acceptance/tools"
     8  	"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/qos/policies"
     9  	th "github.com/gophercloud/gophercloud/testhelper"
    10  )
    11  
    12  // CreateQoSPolicy will create a QoS policy. An error will be returned if the
    13  // QoS policy could not be created.
    14  func CreateQoSPolicy(t *testing.T, client *gophercloud.ServiceClient) (*policies.Policy, error) {
    15  	policyName := tools.RandomString("TESTACC-", 8)
    16  	policyDescription := tools.RandomString("TESTACC-DESC-", 8)
    17  
    18  	createOpts := policies.CreateOpts{
    19  		Name:        policyName,
    20  		Description: policyDescription,
    21  	}
    22  
    23  	t.Logf("Attempting to create a QoS policy: %s", policyName)
    24  
    25  	policy, err := policies.Create(client, createOpts).Extract()
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	t.Logf("Succesfully created a QoS policy")
    31  
    32  	th.AssertEquals(t, policyName, policy.Name)
    33  	th.AssertEquals(t, policyDescription, policy.Description)
    34  
    35  	return policy, nil
    36  }
    37  
    38  // DeleteQoSPolicy will delete a QoS policy with a specified ID.
    39  // A fatal error will occur if the delete was not successful.
    40  func DeleteQoSPolicy(t *testing.T, client *gophercloud.ServiceClient, policyID string) {
    41  	t.Logf("Attempting to delete the QoS policy: %s", policyID)
    42  
    43  	err := policies.Delete(client, policyID).ExtractErr()
    44  	if err != nil {
    45  		t.Fatalf("Unable to delete QoS policy %s: %v", policyID, err)
    46  	}
    47  
    48  	t.Logf("Deleted QoS policy: %s", policyID)
    49  }