Skip to content

Commit

Permalink
Update openstack.MockCloud to use cloudmock clients
Browse files Browse the repository at this point in the history
  • Loading branch information
rifelpet committed Aug 10, 2020
1 parent 230d870 commit a852a9d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
5 changes: 5 additions & 0 deletions upup/pkg/fi/cloudup/openstack/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ go_library(
importpath = "k8s.io/kops/upup/pkg/fi/cloudup/openstack",
visibility = ["//visibility:public"],
deps = [
"//cloudmock/openstack/mockblockstorage:go_default_library",
"//cloudmock/openstack/mockcompute:go_default_library",
"//cloudmock/openstack/mockdns:go_default_library",
"//cloudmock/openstack/mockloadbalancer:go_default_library",
"//cloudmock/openstack/mocknetworking:go_default_library",
"//dnsprovider/pkg/dnsprovider:go_default_library",
"//dnsprovider/pkg/dnsprovider/providers/openstack/designate:go_default_library",
"//pkg/apis/kops:go_default_library",
Expand Down
45 changes: 32 additions & 13 deletions upup/pkg/fi/cloudup/openstack/mock_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ import (
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
v1 "k8s.io/api/core/v1"
"k8s.io/kops/cloudmock/openstack/mockblockstorage"
"k8s.io/kops/cloudmock/openstack/mockcompute"
"k8s.io/kops/cloudmock/openstack/mockdns"
"k8s.io/kops/cloudmock/openstack/mockloadbalancer"
"k8s.io/kops/cloudmock/openstack/mocknetworking"
"k8s.io/kops/dnsprovider/pkg/dnsprovider"
dnsproviderdesignate "k8s.io/kops/dnsprovider/pkg/dnsprovider/providers/openstack/designate"
"k8s.io/kops/pkg/apis/kops"
Expand All @@ -50,12 +55,12 @@ import (
)

type MockCloud struct {
MockCinderClient *gophercloud.ServiceClient
MockNeutronClient *gophercloud.ServiceClient
MockNovaClient *gophercloud.ServiceClient
MockDNSClient *gophercloud.ServiceClient
MockLBClient *gophercloud.ServiceClient
MockGlanceClient *gophercloud.ServiceClient
MockCinderClient *mockblockstorage.MockClient
MockNeutronClient *mocknetworking.MockClient
MockNovaClient *mockcompute.MockClient
MockDNSClient *mockdns.MockClient
MockLBClient *mockloadbalancer.MockClient
MockGlanceClient *mockcompute.MockClient
region string
tags map[string]string
useOctavia bool
Expand All @@ -80,27 +85,41 @@ func BuildMockOpenstackCloud(region string) *MockCloud {
var _ fi.Cloud = (*MockCloud)(nil)

func (c *MockCloud) ComputeClient() *gophercloud.ServiceClient {
return c.MockNovaClient
client := c.MockNovaClient.ServiceClient()
client.UserAgent.Prepend("compute")
return client
}

func (c *MockCloud) BlockStorageClient() *gophercloud.ServiceClient {
return c.MockCinderClient
client := c.MockCinderClient.ServiceClient()
client.UserAgent.Prepend("blockstorage")
return client
}

func (c *MockCloud) NetworkingClient() *gophercloud.ServiceClient {
return c.MockNeutronClient
client := c.MockNeutronClient.ServiceClient()
client.UserAgent.Prepend("networking")
return client
}

func (c *MockCloud) LoadBalancerClient() *gophercloud.ServiceClient {
return c.MockLBClient
client := c.MockLBClient.ServiceClient()
client.UserAgent.Prepend("loadbalancer")
return client
}

func (c *MockCloud) DNSClient() *gophercloud.ServiceClient {
return c.MockDNSClient
client := c.MockDNSClient.ServiceClient()
client.UserAgent.Prepend("dns")
return client
}

func (c *MockCloud) ImageClient() *gophercloud.ServiceClient {
return c.MockGlanceClient
// Some compute endpoints implicitly call image endpoints
// so it is easiest to share the same mock client
client := c.MockNovaClient.ServiceClient()
client.UserAgent.Prepend("image")
return client
}

func (c *MockCloud) DeleteGroup(g *cloudinstances.CloudInstanceGroup) error {
Expand All @@ -127,7 +146,7 @@ func (c *MockCloud) DNS() (dnsprovider.Interface, error) {
if c.MockDNSClient == nil {
return nil, fmt.Errorf("MockDNS not set")
}
return dnsproviderdesignate.New(c.MockDNSClient), nil
return dnsproviderdesignate.New(c.DNSClient()), nil
}

func (c *MockCloud) FindVPCInfo(id string) (*fi.VPCInfo, error) {
Expand Down

0 comments on commit a852a9d

Please sign in to comment.