github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/internal/acceptance/openstack/networking/v2/extensions/qos/rules/rules.go (about)

     1  package rules
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2"
     8  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/networking/v2/extensions/qos/rules"
     9  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    10  )
    11  
    12  // CreateBandwidthLimitRule will create a QoS BandwidthLimitRule associated with the provided QoS policy.
    13  // An error will be returned if the QoS rule could not be created.
    14  func CreateBandwidthLimitRule(t *testing.T, client *gophercloud.ServiceClient, policyID string) (*rules.BandwidthLimitRule, error) {
    15  	maxKBps := 3000
    16  	maxBurstKBps := 300
    17  
    18  	createOpts := rules.CreateBandwidthLimitRuleOpts{
    19  		MaxKBps:      maxKBps,
    20  		MaxBurstKBps: maxBurstKBps,
    21  	}
    22  
    23  	t.Logf("Attempting to create a QoS bandwidth limit rule with max_kbps: %d, max_burst_kbps: %d", maxKBps, maxBurstKBps)
    24  
    25  	rule, err := rules.CreateBandwidthLimitRule(context.TODO(), client, policyID, createOpts).ExtractBandwidthLimitRule()
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	t.Logf("Succesfully created a QoS bandwidth limit rule")
    31  
    32  	th.AssertEquals(t, maxKBps, rule.MaxKBps)
    33  	th.AssertEquals(t, maxBurstKBps, rule.MaxBurstKBps)
    34  
    35  	return rule, nil
    36  }
    37  
    38  // CreateDSCPMarkingRule will create a QoS DSCPMarkingRule associated with the provided QoS policy.
    39  // An error will be returned if the QoS rule could not be created.
    40  func CreateDSCPMarkingRule(t *testing.T, client *gophercloud.ServiceClient, policyID string) (*rules.DSCPMarkingRule, error) {
    41  	dscpMark := 26
    42  
    43  	createOpts := rules.CreateDSCPMarkingRuleOpts{
    44  		DSCPMark: dscpMark,
    45  	}
    46  
    47  	t.Logf("Attempting to create a QoS DSCP marking rule with dscp_mark: %d", dscpMark)
    48  
    49  	rule, err := rules.CreateDSCPMarkingRule(context.TODO(), client, policyID, createOpts).ExtractDSCPMarkingRule()
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	t.Logf("Succesfully created a QoS DSCP marking rule")
    55  
    56  	th.AssertEquals(t, dscpMark, rule.DSCPMark)
    57  
    58  	return rule, nil
    59  }
    60  
    61  // CreateMinimumBandwidthRule will create a QoS MinimumBandwidthRule associated with the provided QoS policy.
    62  // An error will be returned if the QoS rule could not be created.
    63  func CreateMinimumBandwidthRule(t *testing.T, client *gophercloud.ServiceClient, policyID string) (*rules.MinimumBandwidthRule, error) {
    64  	minKBps := 1000
    65  
    66  	createOpts := rules.CreateMinimumBandwidthRuleOpts{
    67  		MinKBps: minKBps,
    68  	}
    69  
    70  	t.Logf("Attempting to create a QoS minimum bandwidth rule with min_kbps: %d", minKBps)
    71  
    72  	rule, err := rules.CreateMinimumBandwidthRule(context.TODO(), client, policyID, createOpts).ExtractMinimumBandwidthRule()
    73  	if err != nil {
    74  		return nil, err
    75  	}
    76  
    77  	t.Logf("Succesfully created a QoS minimum bandwidth rule")
    78  
    79  	th.AssertEquals(t, minKBps, rule.MinKBps)
    80  
    81  	return rule, nil
    82  }