Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ksubrmnn committed Oct 13, 2020
1 parent 5899bd8 commit 7e24fb1
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 242 deletions.
300 changes: 101 additions & 199 deletions client/api/system/v1alpha1/api.pb.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions client/api/system/v1alpha1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ package v1alpha1;
option go_package = "github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1";

service System {
// GetSerialNumber returns the device's serial number
rpc GetSerialNumber(GetSerialNumberRequest) returns (GetSerialNumberResponse) {}
// GetBIOSSerialNumber returns the device's serial number
rpc GetBIOSSerialNumber(GetBIOSSerialNumberRequest) returns (GetBIOSSerialNumberResponse) {}
}

message GetSerialNumberRequest {
message GetBIOSSerialNumberRequest {
// Intentionally empty
}

message GetSerialNumberResponse {
message GetBIOSSerialNumberResponse {
// Serial number
string serial_number = 1;
}
4 changes: 2 additions & 2 deletions client/groups/system/v1alpha1/client_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions integrationtests/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ package integrationtests

import (
"context"
"os/exec"
"strings"
"testing"

"github.com/kubernetes-csi/csi-proxy/client/api/system/v1alpha1"
v1alpha1client "github.com/kubernetes-csi/csi-proxy/client/groups/system/v1alpha1"
"github.com/stretchr/testify/require"
)

func TestGetSerialNumber(t *testing.T) {
t.Run("GetSerialNumber", func(t *testing.T) {
func TestGetBIOSSerialNumber(t *testing.T) {
t.Run("GetBIOSSerialNumber", func(t *testing.T) {
client, err := v1alpha1client.NewClient()
require.Nil(t, err)
defer client.Close()

request := &v1alpha1.GetSerialNumberRequest{}
response, err := client.GetSerialNumber(context.TODO(), request)
request := &v1alpha1.GetBIOSSerialNumberRequest{}
response, err := client.GetBIOSSerialNumber(context.TODO(), request)
require.Nil(t, err)
require.NotNil(t, response)
require.NotEmpty(t, response.SerialNumber)

result, err := exec.Command("wmic", "bios", "get", "serialnumber").Output()
require.Nil(t, err)

t.Logf("The serial number is %s", response.SerialNumber)

resultString := string(result)
require.True(t, strings.Contains(resultString, response.SerialNumber))
})
}
2 changes: 1 addition & 1 deletion internal/os/system/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func New() APIImplementor {
return APIImplementor{}
}

func (APIImplementor) GetSerialNumber() (string, error) {
func (APIImplementor) GetBIOSSerialNumber() (string, error) {
// Taken from Kubernetes vSphere cloud provider
// https://github.com/kubernetes/kubernetes/blob/103e926604de6f79161b78af3e792d0ed282bc06/staging/src/k8s.io/legacy-cloud-providers/vsphere/vsphere_util_windows.go#L28
result, err := exec.Command("wmic", "bios", "get", "serialnumber").Output()
Expand Down
4 changes: 2 additions & 2 deletions internal/server/system/internal/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package internal

type GetSerialNumberRequest struct {
type GetBIOSSerialNumberRequest struct {
}

type GetSerialNumberResponse struct {
type GetBIOSSerialNumberResponse struct {
SerialNumber string
}
2 changes: 1 addition & 1 deletion internal/server/system/internal/types_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions internal/server/system/internal/v1alpha1/conversion_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions internal/server/system/internal/v1alpha1/server_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions internal/server/system/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Server struct {
}

type API interface {
GetSerialNumber() (string, error)
GetBIOSSerialNumber() (string, error)
}

func NewServer(hostAPI API) (*Server, error) {
Expand All @@ -22,12 +22,12 @@ func NewServer(hostAPI API) (*Server, error) {
}, nil
}

func (s *Server) GetSerialNumber(context context.Context, request *internal.GetSerialNumberRequest, version apiversion.Version) (*internal.GetSerialNumberResponse, error) {
klog.V(4).Infof("calling GetSerialNumber")
response := &internal.GetSerialNumberResponse{}
serialNumber, err := s.hostAPI.GetSerialNumber()
func (s *Server) GetBIOSSerialNumber(context context.Context, request *internal.GetBIOSSerialNumberRequest, version apiversion.Version) (*internal.GetBIOSSerialNumberResponse, error) {
klog.V(4).Infof("calling GetBIOSSerialNumber")
response := &internal.GetBIOSSerialNumberResponse{}
serialNumber, err := s.hostAPI.GetBIOSSerialNumber()
if err != nil {
klog.Errorf("failed GetSerialNumber: %v", err)
klog.Errorf("failed GetBIOSSerialNumber: %v", err)
return response, err
}

Expand Down

0 comments on commit 7e24fb1

Please sign in to comment.