Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[v2] Improve support for network standard-attr-* extensions #3328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 internal/acceptance/clients/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func getReleaseFromEnv(t *testing.T) string {
// release. Releases are named such as 'stable/mitaka', master, etc.
func SkipRelease(t *testing.T, release string) {
current := getReleaseFromEnv(t)
if current == release {
if current == strings.TrimPrefix(release, "stable/") {
t.Skipf("this is not supported in %s", release)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package layer3

import (
"context"
"strings"
"testing"

"github.com/gophercloud/gophercloud/v2/internal/acceptance/clients"
Expand Down Expand Up @@ -203,3 +204,62 @@ func TestLayer3FloatingIPsCreateDeleteBySubnetID(t *testing.T) {

DeleteFloatingIP(t, client, fip.ID)
}

func TestLayer3FloatingIPsRevision(t *testing.T) {
client, err := clients.NewNetworkV2Client()
th.AssertNoErr(t, err)

choices, err := clients.AcceptanceTestChoicesFromEnv()
th.AssertNoErr(t, err)

fip, err := CreateFloatingIP(t, client, choices.ExternalNetworkID, "")
th.AssertNoErr(t, err)
defer DeleteFloatingIP(t, client, fip.ID)

tools.PrintResource(t, fip)

// Store the current revision number.
oldRevisionNumber := fip.RevisionNumber

// Update the fip without revision number.
// This should work.
newDescription := ""
updateOpts := &floatingips.UpdateOpts{
Description: &newDescription,
}
fip, err = floatingips.Update(context.TODO(), client, fip.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, fip)

// This should fail due to an old revision number.
newDescription = "new description"
updateOpts = &floatingips.UpdateOpts{
Description: &newDescription,
RevisionNumber: &oldRevisionNumber,
}
_, err = floatingips.Update(context.TODO(), client, fip.ID, updateOpts).Extract()
th.AssertErr(t, err)
if !strings.Contains(err.Error(), "RevisionNumberConstraintFailed") {
t.Fatalf("expected to see an error of type RevisionNumberConstraintFailed, but got the following error instead: %v", err)
}

// Reread the fip to show that it did not change.
fip, err = floatingips.Get(context.TODO(), client, fip.ID).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, fip)

// This should work because now we do provide a valid revision number.
newDescription = "new description"
updateOpts = &floatingips.UpdateOpts{
Description: &newDescription,
RevisionNumber: &fip.RevisionNumber,
}
fip, err = floatingips.Update(context.TODO(), client, fip.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, fip)

th.AssertEquals(t, fip.Description, newDescription)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package layer3

import (
"context"
"strings"
"testing"

"github.com/gophercloud/gophercloud/v2/internal/acceptance/clients"
Expand Down Expand Up @@ -213,3 +214,70 @@ func TestLayer3RouterAgents(t *testing.T) {

th.AssertEquals(t, found, true)
}

func TestLayer3RouterRevision(t *testing.T) {
// https://bugs.launchpad.net/neutron/+bug/2101871
clients.SkipRelease(t, "stable/2023.2")
client, err := clients.NewNetworkV2Client()
th.AssertNoErr(t, err)

network, err := networking.CreateNetwork(t, client)
th.AssertNoErr(t, err)
defer networking.DeleteNetwork(t, client, network.ID)

router, err := CreateRouter(t, client, network.ID)
th.AssertNoErr(t, err)
defer DeleteRouter(t, client, router.ID)

tools.PrintResource(t, router)

// Store the current revision number.
oldRevisionNumber := router.RevisionNumber

// Update the router without revision number.
// This should work.
newName := tools.RandomString("TESTACC-", 8)
newDescription := ""
updateOpts := &routers.UpdateOpts{
Name: newName,
Description: &newDescription,
}
router, err = routers.Update(context.TODO(), client, router.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, router)

// This should fail due to an old revision number.
newDescription = "new description"
updateOpts = &routers.UpdateOpts{
Name: newName,
Description: &newDescription,
RevisionNumber: &oldRevisionNumber,
}
_, err = routers.Update(context.TODO(), client, router.ID, updateOpts).Extract()
th.AssertErr(t, err)
if !strings.Contains(err.Error(), "RevisionNumberConstraintFailed") {
t.Fatalf("expected to see an error of type RevisionNumberConstraintFailed, but got the following error instead: %v", err)
}

// Reread the router to show that it did not change.
router, err = routers.Get(context.TODO(), client, router.ID).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, router)

// This should work because now we do provide a valid revision number.
newDescription = "new description"
updateOpts = &routers.UpdateOpts{
Name: newName,
Description: &newDescription,
RevisionNumber: &router.RevisionNumber,
}
router, err = routers.Update(context.TODO(), client, router.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, router)

th.AssertEquals(t, router.Name, newName)
th.AssertEquals(t, router.Description, newDescription)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package policies

import (
"context"
"strings"
"testing"

"github.com/gophercloud/gophercloud/v2/internal/acceptance/clients"
Expand Down Expand Up @@ -59,3 +60,68 @@ func TestPoliciesCRUD(t *testing.T) {

th.AssertEquals(t, found, true)
}

func TestPoliciesRevision(t *testing.T) {
client, err := clients.NewNetworkV2Client()
th.AssertNoErr(t, err)

// Skip these tests if we don't have the required extension
v2.RequireNeutronExtension(t, client, "qos")

// Create a policy
policy, err := CreateQoSPolicy(t, client)
th.AssertNoErr(t, err)
defer DeleteQoSPolicy(t, client, policy.ID)

tools.PrintResource(t, policy)

// Store the current revision number.
oldRevisionNumber := policy.RevisionNumber

// Update the policy without revision number.
// This should work.
newName := tools.RandomString("TESTACC-", 8)
newDescription := ""
updateOpts := &policies.UpdateOpts{
Name: newName,
Description: &newDescription,
}
policy, err = policies.Update(context.TODO(), client, policy.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, policy)

// This should fail due to an old revision number.
newDescription = "new description"
updateOpts = &policies.UpdateOpts{
Name: newName,
Description: &newDescription,
RevisionNumber: &oldRevisionNumber,
}
_, err = policies.Update(context.TODO(), client, policy.ID, updateOpts).Extract()
th.AssertErr(t, err)
if !strings.Contains(err.Error(), "RevisionNumberConstraintFailed") {
t.Fatalf("expected to see an error of type RevisionNumberConstraintFailed, but got the following error instead: %v", err)
}

// Reread the policy to show that it did not change.
policy, err = policies.Get(context.TODO(), client, policy.ID).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, policy)

// This should work because now we do provide a valid revision number.
newDescription = "new description"
updateOpts = &policies.UpdateOpts{
Name: newName,
Description: &newDescription,
RevisionNumber: &policy.RevisionNumber,
}
policy, err = policies.Update(context.TODO(), client, policy.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, policy)

th.AssertEquals(t, policy.Name, newName)
th.AssertEquals(t, policy.Description, newDescription)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package extensions

import (
"context"
"strings"
"testing"

"github.com/gophercloud/gophercloud/v2/internal/acceptance/clients"
Expand Down Expand Up @@ -93,3 +94,65 @@ func TestSecurityGroupsPort(t *testing.T) {

tools.PrintResource(t, port)
}

func TestSecurityGroupsRevision(t *testing.T) {
client, err := clients.NewNetworkV2Client()
th.AssertNoErr(t, err)

// Create a group
group, err := CreateSecurityGroup(t, client)
th.AssertNoErr(t, err)
defer DeleteSecurityGroup(t, client, group.ID)

tools.PrintResource(t, group)

// Store the current revision number.
oldRevisionNumber := group.RevisionNumber

// Update the group without revision number.
// This should work.
newName := tools.RandomString("TESTACC-", 8)
newDescription := ""
updateOpts := &groups.UpdateOpts{
Name: newName,
Description: &newDescription,
}
group, err = groups.Update(context.TODO(), client, group.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, group)

// This should fail due to an old revision number.
newDescription = "new description"
updateOpts = &groups.UpdateOpts{
Name: newName,
Description: &newDescription,
RevisionNumber: &oldRevisionNumber,
}
_, err = groups.Update(context.TODO(), client, group.ID, updateOpts).Extract()
th.AssertErr(t, err)
if !strings.Contains(err.Error(), "RevisionNumberConstraintFailed") {
t.Fatalf("expected to see an error of type RevisionNumberConstraintFailed, but got the following error instead: %v", err)
}

// Reread the group to show that it did not change.
group, err = groups.Get(context.TODO(), client, group.ID).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, group)

// This should work because now we do provide a valid revision number.
newDescription = "new description"
updateOpts = &groups.UpdateOpts{
Name: newName,
Description: &newDescription,
RevisionNumber: &group.RevisionNumber,
}
group, err = groups.Update(context.TODO(), client, group.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, group)

th.AssertEquals(t, group.Name, newName)
th.AssertEquals(t, group.Description, newDescription)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package v2

import (
"context"
"strings"
"testing"

"github.com/gophercloud/gophercloud/v2/internal/acceptance/clients"
Expand Down Expand Up @@ -55,3 +56,63 @@ func TestSubnetPoolsCRUD(t *testing.T) {

th.AssertEquals(t, found, true)
}

func TestSubnetPoolsRevision(t *testing.T) {
client, err := clients.NewNetworkV2Client()
th.AssertNoErr(t, err)

// Create a subnetpool
subnetPool, err := CreateSubnetPool(t, client)
th.AssertNoErr(t, err)
defer DeleteSubnetPool(t, client, subnetPool.ID)

// Store the current revision number.
oldRevisionNumber := subnetPool.RevisionNumber

// Update the subnet pool without revision number.
// This should work.
newName := tools.RandomString("TESTACC-", 8)
newDescription := ""
updateOpts := &subnetpools.UpdateOpts{
Name: newName,
Description: &newDescription,
}
subnetPool, err = subnetpools.Update(context.TODO(), client, subnetPool.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, subnetPool)

// This should fail due to an old revision number.
newDescription = "new description"
updateOpts = &subnetpools.UpdateOpts{
Name: newName,
Description: &newDescription,
RevisionNumber: &oldRevisionNumber,
}
_, err = subnetpools.Update(context.TODO(), client, subnetPool.ID, updateOpts).Extract()
th.AssertErr(t, err)
if !strings.Contains(err.Error(), "RevisionNumberConstraintFailed") {
t.Fatalf("expected to see an error of type RevisionNumberConstraintFailed, but got the following error instead: %v", err)
}

// Reread the subnet pool to show that it did not change.
subnetPool, err = subnetpools.Get(context.TODO(), client, subnetPool.ID).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, subnetPool)

// This should work because now we do provide a valid revision number.
newDescription = "new description"
updateOpts = &subnetpools.UpdateOpts{
Name: newName,
Description: &newDescription,
RevisionNumber: &subnetPool.RevisionNumber,
}
subnetPool, err = subnetpools.Update(context.TODO(), client, subnetPool.ID, updateOpts).Extract()
th.AssertNoErr(t, err)

tools.PrintResource(t, subnetPool)

th.AssertEquals(t, subnetPool.Name, newName)
th.AssertEquals(t, subnetPool.Description, newDescription)
}
Loading
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.