confidential-containers / cloud-api-adaptor

Ability to create Kata pods using cloud provider APIs aka the peer-pods approach
Apache License 2.0
47 stars 81 forks source link

ibmcloud: unit tests don't compile #48

Closed wainersm closed 2 years ago

wainersm commented 2 years ago

While working on https://github.com/confidential-containers/cloud-api-adaptor/issues/47 I realized the tests pkg/adaptor/hypervisor/ibmcloud/server_test.go and pkg/adaptor/hypervisor/ibmcloud/shim_test.go don't compile.

The build errors:

[wmoschet@wainer-laptop ibmcloud]$ go test
# github.com/confidential-containers/cloud-api-adaptor/pkg/adaptor/hypervisor/ibmcloud [github.com/confidential-containers/cloud-api-adaptor/pkg/adaptor/hypervisor/ibmcloud.test]
./server_test.go:89:58: undefined: Server
./server_test.go:138:64: cannot use newAgentService() (type *agentService) as type grpc.AgentServiceService in argument to grpc.RegisterAgentServiceService:
    *agentService does not implement grpc.AgentServiceService (missing CreateSandbox method)
./server_test.go:159:58: undefined: Server
./server_test.go:163:19: too many arguments in call to NewServer
./server_test.go:163:47: undefined: ServiceConfig
./server_test.go:193:41: undefined: Server
./shim_test.go:444:63: undefined: grpc.StartTracingRequest
./shim_test.go:448:62: undefined: grpc.StopTracingRequest
./shim_test.go:456:59: undefined: grpc.CreateVMRequest
./shim_test.go:460:60: undefined: grpc.DestroyVMRequest
./server_test.go:163:19: too many errors
FAIL    github.com/confidential-containers/cloud-api-adaptor/pkg/adaptor/hypervisor/ibmcloud [build failed]

I did a couple of fixes as shown in the diff below:

diff --git a/pkg/adaptor/hypervisor/ibmcloud/server_test.go b/pkg/adaptor/hypervisor/ibmcloud/server_test.go
index c1ada6e..f98fd80 100644
--- a/pkg/adaptor/hypervisor/ibmcloud/server_test.go
+++ b/pkg/adaptor/hypervisor/ibmcloud/server_test.go
@@ -1,5 +1,6 @@
 // (C) Copyright IBM Corp. 2022.
 // SPDX-License-Identifier: Apache-2.0
+// +build ibmcloud

 package ibmcloud

@@ -21,6 +22,7 @@ import (
        "github.com/IBM/vpc-go-sdk/vpcv1"

        "github.com/confidential-containers/cloud-api-adaptor/pkg/adaptor/forwarder"
+       "github.com/confidential-containers/cloud-api-adaptor/pkg/adaptor/hypervisor"
        daemon "github.com/confidential-containers/cloud-api-adaptor/pkg/forwarder"
        "github.com/confidential-containers/cloud-api-adaptor/pkg/podnetwork/tunneler"
        "github.com/confidential-containers/cloud-api-adaptor/pkg/util/http/upgrader"
@@ -86,7 +88,7 @@ func TestCreateStartAndStop(t *testing.T) {
        }
 }

-func testServerStart(t *testing.T, ctx context.Context) (Server, string, string, pb.HypervisorService, chan error) {
+func testServerStart(t *testing.T, ctx context.Context) (hypervisor.Server, string, string, pb.HypervisorService, chan error) {
        dir, err := ioutil.TempDir("", "helper")
        if err != nil {
                t.Fatal(err)
@@ -156,26 +158,41 @@ func startAgentServer(t *testing.T) string {
        return port
 }

-func newServer(t *testing.T, socketPath, podsDir string) Server {
+func newServer(t *testing.T, socketPath, podsDir string) hypervisor.Server {
+       hypervisorConfig := hypervisor.Config{
+               PodsDir:     podsDir,
+               SocketPath:  socketPath,
+               HypProvider: "ibmcloud",
+       }
        switch strings.ToLower(os.Getenv("USE_IBM_CLOUD")) {
        case "", "no", "false", "0":
                port := startAgentServer(t)
-               return NewServer(socketPath, &mockVpcV1{}, &ServiceConfig{}, &mockWorkerNode{}, podsDir, port)
+               return NewServer(hypervisorConfig, Config{}, &mockWorkerNode{}, port)
        }
        log.Print("Using IBM Cloud...")
        apiKey := os.Getenv("API_KEY")
        if apiKey == "" {
                t.Fatal("Specify the API key as API_KEY")
        }
-       vpcv1, err := NewVpcV1(apiKey)
-       if err != nil {
-               t.Fatal(err)
+
+       iamServiceURL := os.Getenv("IAM_SERVICE_URL")
+       if iamServiceURL == "" {
+               t.Fatal("Specify the IAM Service URL as IAM_SERVICE_URL")
        }
+
+       vpcServiceURL := os.Getenv("VPC_SERVICE_URL")
+       if vpcServiceURL == "" {
+               t.Fatal("Specify the VPC Service URL as VPC_SERVICE_URL")
+       }
+
        keyId := os.Getenv("KEY_ID")
        if keyId == "" {
                t.Fatal("Specify the SSH key ID as KEY_ID")
        }
-       serviceConfig := &ServiceConfig{
+
+       // TODO: need to remove the hard-coded config and finish the
+       // implementation in order to use vpcv1.
+       serviceConfig := Config{
                ProfileName:              "bx2-2x8",
                ZoneName:                 "us-south-2",
                ImageID:                  "r134-d2090805-5652-4845-b287-46232e1098c3",
@@ -185,12 +202,15 @@ func newServer(t *testing.T, socketPath, podsDir string) Server {
                SecondarySecurityGroupID: "r134-2d59206c-ac4d-4488-b9a4-a086bef59ee5",
                KeyID:                    keyId,
                VpcID:                    "r134-c199bf26-ec6d-4c5d-a0a2-1e74d312891f",
+               ApiKey:                   apiKey,
+               IamServiceURL:            iamServiceURL,
+               VpcServiceURL:            vpcServiceURL,
        }

-       return NewServer(socketPath, vpcv1, serviceConfig, &mockWorkerNode{}, podsDir, daemon.DefaultListenPort)
+       return NewServer(hypervisorConfig, serviceConfig, &mockWorkerNode{}, daemon.DefaultListenPort)
 }

-func testServerShutdown(t *testing.T, s Server, socketPath, dir string, serverErrCh chan error) {
+func testServerShutdown(t *testing.T, s hypervisor.Server, socketPath, dir string, serverErrCh chan error) {

        if err := s.Shutdown(); err != nil {
                t.Error(err)
diff --git a/pkg/adaptor/hypervisor/ibmcloud/shim_test.go b/pkg/adaptor/hypervisor/ibmcloud/shim_test.go
index d04c9fe..6bae051 100644
--- a/pkg/adaptor/hypervisor/ibmcloud/shim_test.go
+++ b/pkg/adaptor/hypervisor/ibmcloud/shim_test.go
@@ -1,5 +1,6 @@
 // (C) Copyright IBM Corp. 2022.
 // SPDX-License-Identifier: Apache-2.0
+// +build ibmcloud

 package ibmcloud

@@ -17,6 +18,7 @@ import (
        "testing"
        "time"

+       "github.com/confidential-containers/cloud-api-adaptor/pkg/adaptor/hypervisor"
        daemon "github.com/confidential-containers/cloud-api-adaptor/pkg/forwarder"
        "github.com/confidential-containers/cloud-api-adaptor/pkg/podnetwork"
        "github.com/containerd/containerd/pkg/cri/annotations"
@@ -85,7 +87,13 @@ func TestShim(t *testing.T) {
                workerNode = podnetwork.NewWorkerNode(t, "")
        }

-       server := NewServer(helperSocketPath, &mockVpcV1{primaryIP: primaryIP, secondaryIP: secondaryIP}, &ServiceConfig{}, workerNode, podsDir, port)
+       hypervisorConfig := hypervisor.Config{
+               PodsDir:        podsDir,
+               SocketPath:     helperSocketPath,
+               HypProvider:    "ibmcloud",
+       }
+
+       server := NewServer(hypervisorConfig, &mockVpcV1{primaryIP: primaryIP, secondaryIP: secondaryIP}, &ServiceConfig{}, workerNode, port)

        serverDone := make(chan struct{})
        go func() {

... however after those changes there are still errors:

# github.com/confidential-containers/cloud-api-adaptor/pkg/adaptor/hypervisor/ibmcloud [github.com/confidential-containers/cloud-api-adaptor/pkg/adaptor/hypervisor/ibmcloud.test]
./server_test.go:140:64: cannot use newAgentService() (type *agentService) as type grpc.AgentServiceService in argument to grpc.RegisterAgentServiceService:
    *agentService does not implement grpc.AgentServiceService (missing CreateSandbox method)
./shim_test.go:96:21: too many arguments in call to NewServer
./shim_test.go:96:101: undefined: ServiceConfig
./shim_test.go:195:64: cannot use newAgentService() (type *agentService) as type grpc.AgentServiceService in argument to grpc.RegisterAgentServiceService:
    *agentService does not implement grpc.AgentServiceService (missing CreateSandbox method)
./shim_test.go:452:63: undefined: grpc.StartTracingRequest
./shim_test.go:456:62: undefined: grpc.StopTracingRequest
./shim_test.go:464:59: undefined: grpc.CreateVMRequest
./shim_test.go:468:60: undefined: grpc.DestroyVMRequest
FAIL    github.com/confidential-containers/cloud-api-adaptor/pkg/adaptor/hypervisor/ibmcloud [build failed]

Unfortunately I cannot spend more time on this, so I am opening this issue.

wainersm commented 2 years ago

@bpradipt @stevenhorsman could you please re-open this issue as it was not fixed yet? I don't have permission to carry out such as operation in this repository...

stevenhorsman commented 2 years ago

I've re-opened this. @bpradipt - I think you are a co-co owner, so can you invite Wainer to https://github.com/orgs/confidential-containers/teams/peer-pod-maintainers please?

stevenhorsman commented 2 years ago

Sorry, I'm getting confused about whether this issue is fully resolved yet or not. I think it is though after #55 was merged!