Skip to content

Commit

Permalink
Merge 726cc62 into 280727e
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenfin committed Apr 15, 2024
2 parents 280727e + 726cc62 commit 1505427
Show file tree
Hide file tree
Showing 146 changed files with 634 additions and 321 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea
.vscode
testing_*.coverprofile
/cover.out
19 changes: 19 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
linters:
disable-all: true
enable:
- errcheck
- gofmt
- goimports
- govet
- staticcheck
- unparam
- unused

issues:
exclude:
- SA1006 # printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
exclude-rules:
- linters:
- staticcheck
text: 'SA1019: (x509.EncryptPEMBlock|strings.Title)'
113 changes: 113 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
undefine GOFLAGS

GOLANGCI_LINT_VERSION?=v1.57.1

ifeq ($(shell command -v podman 2> /dev/null),)
RUNNER=docker
else
RUNNER=podman
endif

# if the golangci-lint steps fails with the following error message:
#
# directory prefix . does not contain main module or its selected dependencies
#
# you probably have to fix the SELinux security context for root directory plus your cache
#
# chcon -Rt svirt_sandbox_file_t .
# chcon -Rt svirt_sandbox_file_t ~/.cache/golangci-lint
lint:
$(RUNNER) run -t --rm \
-v $(shell pwd):/app \
-v ~/.cache/golangci-lint/$(GOLANGCI_LINT_VERSION):/root/.cache \
-w /app \
-e GOFLAGS="-tags=acceptance" \
golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) golangci-lint run -v
.PHONY: lint

unit:
go test ./...
.PHONY: unit

coverage:
go test -covermode count -coverprofile cover.out -coverpkg=./... ./...
.PHONY: coverage

acceptance: acceptance-baremetal acceptance-blockstorage acceptance-clustering acceptance-compute acceptance-container acceptance-containerinfra acceptance-db acceptance-dns acceptance-identity acceptance-imageservice acceptance-keymanager acceptance-loadbalancer acceptance-messaging acceptance-networking acceptance-objectstorage acceptance-orchestration acceptance-placement acceptance-sharedfilesystems acceptance-workflow
.PHONY: acceptance

acceptance-baremetal:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/baremetal/...
.PHONY: acceptance-baremetal

acceptance-blockstorage:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/blockstorage/...
.PHONY: acceptance-blockstorage

acceptance-clustering:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/clustering/...
.PHONY: acceptance-clustering

acceptance-compute:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/compute/...
.PHONY: acceptance-compute

acceptance-container:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/container/...
.PHONY: acceptance-container

acceptance-containerinfra:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/containerinfra/...
.PHONY: acceptance-containerinfra

acceptance-db:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/db/...
.PHONY: acceptance-db

acceptance-dns:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/dns/...
.PHONY: acceptance-dns

acceptance-identity:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/identity/...
.PHONY: acceptance-identity

acceptance-image:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/imageservice/...
.PHONY: acceptance-image

acceptance-keymanager:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/keymanager/...
.PHONY: acceptance-keymanager

acceptance-loadbalancer:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/loadbalancer/...
.PHONY: acceptance-loadbalancer

acceptance-messaging:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/messaging/...
.PHONY: acceptance-messaging

acceptance-networking:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/networking/...
.PHONY: acceptance-networking

acceptance-objectstorage:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/objectstorage/...
.PHONY: acceptance-objectstorage

acceptance-orchestration:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/orchestration/...
.PHONY: acceptance-orchestration

acceptance-placement:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/placement/...
.PHONY: acceptance-placement

acceptance-sharedfilesystems:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/sharedfilesystems/...
.PHONY: acceptance-sharefilesystems

acceptance-workflow:
go test -tags "fixtures acceptance" ./internal/acceptance/openstack/workflow/...
.PHONY: acceptance-workflow
6 changes: 0 additions & 6 deletions auth_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,6 @@ func (opts *AuthOptions) ToTokenV3CreateMap(scope map[string]interface{}) (map[s
Name *string `json:"name,omitempty"`
}

type projectReq struct {
Domain *domainReq `json:"domain,omitempty"`
Name *string `json:"name,omitempty"`
ID *string `json:"id,omitempty"`
}

type userReq struct {
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion internal/acceptance/clients/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func redactHeaders(headers http.Header) (processedHeaders []string) {
var sensitive bool

for _, redact_header := range REDACT_HEADERS {
if strings.ToLower(name) == strings.ToLower(redact_header) {
if strings.EqualFold(name, redact_header) {
sensitive = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestPortsCreateDestroy(t *testing.T) {
client.Microversion = "1.53"

node, err := v1.CreateFakeNode(t, client)
th.AssertNoErr(t, err)
port, err := v1.CreatePort(t, client, node)
th.AssertNoErr(t, err)
defer v1.DeleteNode(t, client, node)
Expand Down Expand Up @@ -58,6 +59,7 @@ func TestPortsUpdate(t *testing.T) {
client.Microversion = "1.53"

node, err := v1.CreateFakeNode(t, client)
th.AssertNoErr(t, err)
port, err := v1.CreatePort(t, client, node)
th.AssertNoErr(t, err)
defer v1.DeleteNode(t, client, node)
Expand Down
2 changes: 2 additions & 0 deletions internal/acceptance/openstack/baremetal/noauth/ports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestPortsCreateDestroy(t *testing.T) {
client.Microversion = "1.53"

node, err := v1.CreateFakeNode(t, client)
th.AssertNoErr(t, err)
port, err := v1.CreatePort(t, client, node)
th.AssertNoErr(t, err)
defer v1.DeleteNode(t, client, node)
Expand Down Expand Up @@ -56,6 +57,7 @@ func TestPortsUpdate(t *testing.T) {
client.Microversion = "1.53"

node, err := v1.CreateFakeNode(t, client)
th.AssertNoErr(t, err)
port, err := v1.CreatePort(t, client, node)
th.AssertNoErr(t, err)
defer v1.DeleteNode(t, client, node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,8 @@ func TestSnapshotsForceDelete(t *testing.T) {

err = tools.WaitFor(func(ctx context.Context) (bool, error) {
_, err := snapshots.Get(ctx, client, snapshot.ID).Extract()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return true, nil
}
if _, ok := err.(gophercloud.ErrDefault404); ok {
return true, nil
}

return false, nil
Expand Down
3 changes: 1 addition & 2 deletions internal/acceptance/openstack/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ func TestEC2AuthMethod(t *testing.T) {
newClient, err := clients.NewIdentityV3UnauthenticatedClient()
th.AssertNoErr(t, err)

var ec2AuthOptions tokens.AuthOptionsBuilder
ec2AuthOptions = &ec2tokens.AuthOptions{
ec2AuthOptions := &ec2tokens.AuthOptions{
Access: "181920",
Secret: "secretKey",
}
Expand Down
10 changes: 0 additions & 10 deletions internal/acceptance/openstack/clustering/v1/clustering.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ func DeleteCluster(t *testing.T, client *gophercloud.ServiceClient, id string) {
}

t.Logf("Successfully deleted cluster: %s", id)

return
}

// DeleteNode will delete a given node. A fatal error will occur if the
Expand All @@ -368,8 +366,6 @@ func DeleteNode(t *testing.T, client *gophercloud.ServiceClient, id string) {
}

t.Logf("Successfully deleted node: %s", id)

return
}

// DeletePolicy will delete a given policy. A fatal error will occur if the
Expand All @@ -383,8 +379,6 @@ func DeletePolicy(t *testing.T, client *gophercloud.ServiceClient, id string) {
}

t.Logf("Successfully deleted policy: %s", id)

return
}

// DeleteProfile will delete a given profile. A fatal error will occur if the
Expand All @@ -398,8 +392,6 @@ func DeleteProfile(t *testing.T, client *gophercloud.ServiceClient, id string) {
}

t.Logf("Successfully deleted profile: %s", id)

return
}

// DeleteReceiver will delete a given receiver. A fatal error will occur if the
Expand All @@ -413,8 +405,6 @@ func DeleteReceiver(t *testing.T, client *gophercloud.ServiceClient, id string)
}

t.Logf("Successfully deleted receiver: %s", id)

return
}

// GetActionID parses an HTTP header and returns the action ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestInstanceActionsMicroversions(t *testing.T) {
}

err = servers.Reboot(context.TODO(), client, server.ID, rebootOpts).ExtractErr()
th.AssertNoErr(t, err)
if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 0 additions & 2 deletions internal/acceptance/openstack/compute/v2/keypairs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"golang.org/x/crypto/ssh"
)

const keyName = "gophercloud_test_key_pair"

func TestKeyPairsParse(t *testing.T) {
client, err := clients.NewComputeV2Client()
th.AssertNoErr(t, err)
Expand Down
7 changes: 5 additions & 2 deletions internal/acceptance/openstack/compute/v2/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func TestServersUpdate(t *testing.T) {

return latest.Name == alternateName, nil
})
th.AssertNoErr(t, err)
}

func TestServersMetadata(t *testing.T) {
Expand Down Expand Up @@ -331,7 +332,8 @@ func TestServersActionResizeConfirm(t *testing.T) {
defer DeleteServer(t, client, server)

t.Logf("Attempting to resize server %s", server.ID)
ResizeServer(t, client, server)
err = ResizeServer(t, client, server)
th.AssertNoErr(t, err)

t.Logf("Attempting to confirm resize for server %s", server.ID)
if res := servers.ConfirmResize(context.TODO(), client, server.ID); res.Err != nil {
Expand Down Expand Up @@ -362,7 +364,8 @@ func TestServersActionResizeRevert(t *testing.T) {
defer DeleteServer(t, client, server)

t.Logf("Attempting to resize server %s", server.ID)
ResizeServer(t, client, server)
err = ResizeServer(t, client, server)
th.AssertNoErr(t, err)

t.Logf("Attempting to revert resize for server %s", server.ID)
if res := servers.RevertResize(context.TODO(), client, server.ID); res.Err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ func DeleteClusterTemplate(t *testing.T, client *gophercloud.ServiceClient, id s
}

t.Logf("Successfully deleted cluster-template: %s", id)

return
}

// CreateClusterTimeout will create a random cluster and wait for it to reach CREATE_COMPLETE status
Expand Down Expand Up @@ -180,8 +178,6 @@ func DeleteCluster(t *testing.T, client *gophercloud.ServiceClient, id string) {
}

t.Logf("Successfully deleted cluster: %s", id)

return
}

func WaitForCluster(client *gophercloud.ServiceClient, clusterID string, status string, timeout time.Duration) error {
Expand Down
2 changes: 2 additions & 0 deletions internal/acceptance/openstack/dns/v2/transfers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ func TestTransferRequestAccept(t *testing.T) {

// Create transfers request to new tenant
transferRequest, err := CreateTransferRequest(t, client, zone, project.ID)
th.AssertNoErr(t, err)

// Accept Zone Transfer Request
transferAccept, err := CreateTransferAccept(t, client, transferRequest.ID, transferRequest.Key)
th.AssertNoErr(t, err)

allTransferAcceptsPages, err := transferAccepts.List(client, nil).AllPages(context.TODO())
th.AssertNoErr(t, err)
Expand Down
1 change: 1 addition & 0 deletions internal/acceptance/openstack/identity/v3/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestLimitsCRUD(t *testing.T) {
th.AssertNoErr(t, err)

svList, err := services.ExtractServices(allPages)
th.AssertNoErr(t, err)
serviceID := ""
for _, service := range svList {
serviceID = service.ID
Expand Down
4 changes: 2 additions & 2 deletions internal/acceptance/openstack/identity/v3/oauth1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ func TestOAuth1CRUD(t *testing.T) {

// test HMACSHA1 and PLAINTEXT signature methods
for _, method := range []oauth1.SignatureMethod{oauth1.HMACSHA1, oauth1.PLAINTEXT} {
oauth1MethodTest(t, client, consumer, method, user, project, roles, ao.IdentityEndpoint)
oauth1MethodTest(t, client, consumer, method, user, project, roles)
}
}

func oauth1MethodTest(t *testing.T, client *gophercloud.ServiceClient, consumer *oauth1.Consumer, method oauth1.SignatureMethod, user *tokens.User, project *tokens.Project, roles []tokens.Role, identityEndpoint string) {
func oauth1MethodTest(t *testing.T, client *gophercloud.ServiceClient, consumer *oauth1.Consumer, method oauth1.SignatureMethod, user *tokens.User, project *tokens.Project, roles []tokens.Role) {
// Request a token
requestTokenOpts := oauth1.RequestTokenOpts{
OAuthConsumerKey: consumer.ID,
Expand Down
1 change: 1 addition & 0 deletions internal/acceptance/openstack/identity/v3/reauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestReauthAuthResultDeadlock(t *testing.T) {
provider.SetToken("this is not a valid token")

client, err := openstack.NewIdentityV3(provider, gophercloud.EndpointOpts{})
th.AssertNoErr(t, err)
pages, err := projects.List(client, nil).AllPages(context.TODO())
th.AssertNoErr(t, err)
_, err = projects.ExtractProjects(pages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestRegisteredLimitsCRUD(t *testing.T) {
th.AssertNoErr(t, err)

svList, err := services.ExtractServices(allServicePages)
th.AssertNoErr(t, err)
serviceID := ""
for _, service := range svList {
serviceID = service.ID
Expand Down
1 change: 1 addition & 0 deletions internal/acceptance/openstack/image/v2/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestImagesListEachPage(t *testing.T) {

return true, nil
})
th.AssertNoErr(t, err)
}

func TestImagesListAllPages(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions internal/acceptance/openstack/image/v2/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestTasksListEachPage(t *testing.T) {

return true, nil
})
th.AssertNoErr(t, err)
}

func TestTasksListAllPages(t *testing.T) {
Expand Down

0 comments on commit 1505427

Please sign in to comment.