Skip to content

Commit

Permalink
Add GetCPCproperties function (#96)
Browse files Browse the repository at this point in the history
* add GetCPCProperties function

* delete //

* Add getting cpc props via cpcName

* Move conditional check to GetCPCURI
  • Loading branch information
CaryChencn authored and GitHub Enterprise committed Sep 19, 2023
1 parent 01e9e74 commit 2ee1229
Show file tree
Hide file tree
Showing 6 changed files with 535 additions and 3 deletions.
44 changes: 44 additions & 0 deletions pkg/zhmcclient/cpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
//go:generate counterfeiter -o fakes/cpc.go --fake-name CpcAPI . CpcAPI
type CpcAPI interface {
ListCPCs(query map[string]string) ([]CPC, int, *HmcError)
GetCPCProperties(cpcURI string) (*CPCProperties, int, *HmcError)
}

type CpcManager struct {
Expand Down Expand Up @@ -83,3 +84,46 @@ func (m *CpcManager) ListCPCs(query map[string]string) ([]CPC, int, *HmcError) {

return nil, status, errorResponseBody
}

/**
* GET /api/cpcs/{cpc-id}
* @return cpc properties
* Return: 200 and Cpcs properties
* or: 400, 404, 409
*/
func (m *CpcManager) GetCPCProperties(cpcURI string) (*CPCProperties, int, *HmcError) {
requestUrl := m.client.CloneEndpointURL()
requestUrl.Path = path.Join(requestUrl.Path, cpcURI)

logger.Info(fmt.Sprintf("Request URL: %v, Method: %v", requestUrl, http.MethodGet))
status, responseBody, err := m.client.ExecuteRequest(http.MethodGet, requestUrl, nil, "")
if err != nil {
logger.Error("error on getting cpc properties",
genlog.String("request url", fmt.Sprint(requestUrl)),
genlog.String("method", http.MethodGet),
genlog.String("status", fmt.Sprint(status)),
genlog.Error(fmt.Errorf("%v", err)))
return nil, status, err
}

if status == http.StatusOK {
cpcProps := &CPCProperties{}
err := json.Unmarshal(responseBody, cpcProps)
if err != nil {
logger.Error("error on unmarshalling cpcs",
genlog.String("request url", fmt.Sprint(requestUrl)),
genlog.String("method", http.MethodGet),
genlog.Error(fmt.Errorf("%v", getHmcErrorFromErr(ERR_CODE_HMC_UNMARSHAL_FAIL, err))))
return nil, status, getHmcErrorFromErr(ERR_CODE_HMC_UNMARSHAL_FAIL, err)
}
logger.Info(fmt.Sprintf("Response: request url: %v, method: %v, status: %v, cpcs: %v", requestUrl, http.MethodGet, status, cpcProps))
return cpcProps, status, nil
}
errorResponseBody := GenerateErrorFromResponse(responseBody)
logger.Error("error getting cpc properties",
genlog.String("request url", fmt.Sprint(requestUrl)),
genlog.String("method", http.MethodGet),
genlog.String("status: ", fmt.Sprint(status)),
genlog.Error(fmt.Errorf("%v", errorResponseBody)))
return nil, status, errorResponseBody
}
82 changes: 82 additions & 0 deletions pkg/zhmcclient/fakes/cpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ type CpcAPI struct {
result2 int
result3 *zhmcclient.HmcError
}
GetCPCPropertiesStub func(string) (*zhmcclient.CPCProperties, int, *zhmcclient.HmcError)
getCPCPropertiesMutex sync.RWMutex
getCPCPropertiesArgsForCall []struct {
arg1 string
}
getCPCPropertiesReturns struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
}
getCPCPropertiesReturnsOnCall map[int]struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
Expand Down Expand Up @@ -107,6 +122,73 @@ func (fake *CpcAPI) ListCPCsReturnsOnCall(i int, result1 []zhmcclient.CPC, resul
}{result1, result2, result3}
}

func (fake *CpcAPI) GetCPCProperties(arg1 string) (*zhmcclient.CPCProperties, int, *zhmcclient.HmcError) {
fake.getCPCPropertiesMutex.Lock()
ret, specificReturn := fake.getCPCPropertiesReturnsOnCall[len(fake.getCPCPropertiesArgsForCall)]
fake.getCPCPropertiesArgsForCall = append(fake.getCPCPropertiesArgsForCall, struct {
arg1 string
}{arg1})
stub := fake.GetCPCPropertiesStub
fakeReturns := fake.getCPCPropertiesReturns
fake.recordInvocation("GetCPCProperties", []interface{}{arg1})
fake.getCPCPropertiesMutex.Unlock()
if stub != nil {
return stub(arg1)
}
if specificReturn {
return ret.result1, ret.result2, ret.result3
}
return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3
}

func (fake *CpcAPI) GetCPCPropertiesCallCount() int {
fake.getCPCPropertiesMutex.RLock()
defer fake.getCPCPropertiesMutex.RUnlock()
return len(fake.getCPCPropertiesArgsForCall)
}

func (fake *CpcAPI) GetCPCPropertiesCalls(stub func(string) (*zhmcclient.CPCProperties, int, *zhmcclient.HmcError)) {
fake.getCPCPropertiesMutex.Lock()
defer fake.getCPCPropertiesMutex.Unlock()
fake.GetCPCPropertiesStub = stub
}

func (fake *CpcAPI) GetCPCPropertiesArgsForCall(i int) string {
fake.getCPCPropertiesMutex.RLock()
defer fake.getCPCPropertiesMutex.RUnlock()
argsForCall := fake.getCPCPropertiesArgsForCall[i]
return argsForCall.arg1
}

func (fake *CpcAPI) GetCPCPropertiesReturns(result1 *zhmcclient.CPCProperties, result2 int, result3 *zhmcclient.HmcError) {
fake.getCPCPropertiesMutex.Lock()
defer fake.getCPCPropertiesMutex.Unlock()
fake.GetCPCPropertiesStub = nil
fake.getCPCPropertiesReturns = struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
}{result1, result2, result3}
}

func (fake *CpcAPI) GetCPCPropertiesReturnsOnCall(i int, result1 *zhmcclient.CPCProperties, result2 int, result3 *zhmcclient.HmcError) {
fake.getCPCPropertiesMutex.Lock()
defer fake.getCPCPropertiesMutex.Unlock()
fake.GetCPCPropertiesStub = nil
if fake.getCPCPropertiesReturnsOnCall == nil {
fake.getCPCPropertiesReturnsOnCall = make(map[int]struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
})
}
fake.getCPCPropertiesReturnsOnCall[i] = struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
}{result1, result2, result3}
}

func (fake *CpcAPI) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
Expand Down
82 changes: 82 additions & 0 deletions pkg/zhmcclient/fakes/zhmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,21 @@ type ZhmcAPI struct {
result1 int
result2 *zhmcclient.HmcError
}
GetCPCPropertiesStub func(string) (*zhmcclient.CPCProperties, int, *zhmcclient.HmcError)
getCPCPropertiesMutex sync.RWMutex
getCPCPropertiesArgsForCall []struct {
arg1 string
}
getCPCPropertiesReturns struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
}
getCPCPropertiesReturnsOnCall map[int]struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
}
GetAdapterPropertiesStub func(string) (*zhmcclient.AdapterProperties, int, *zhmcclient.HmcError)
getAdapterPropertiesMutex sync.RWMutex
getAdapterPropertiesArgsForCall []struct {
Expand Down Expand Up @@ -1772,6 +1787,73 @@ func (fake *ZhmcAPI) GetNicPropertiesReturnsOnCall(i int, result1 *zhmcclient.NI
}{result1, result2, result3}
}

func (fake *ZhmcAPI) GetCPCProperties(arg1 string) (*zhmcclient.CPCProperties, int, *zhmcclient.HmcError) {
fake.getCPCPropertiesMutex.Lock()
ret, specificReturn := fake.getCPCPropertiesReturnsOnCall[len(fake.getCPCPropertiesArgsForCall)]
fake.getCPCPropertiesArgsForCall = append(fake.getCPCPropertiesArgsForCall, struct {
arg1 string
}{arg1})
stub := fake.GetCPCPropertiesStub
fakeReturns := fake.getCPCPropertiesReturns
fake.recordInvocation("GetCPCProperties", []interface{}{arg1})
fake.getCPCPropertiesMutex.Unlock()
if stub != nil {
return stub(arg1)
}
if specificReturn {
return ret.result1, ret.result2, ret.result3
}
return fakeReturns.result1, fakeReturns.result2, fakeReturns.result3
}

func (fake *ZhmcAPI) GetCPCPropertiesCallCount() int {
fake.getCPCPropertiesMutex.RLock()
defer fake.getCPCPropertiesMutex.RUnlock()
return len(fake.getCPCPropertiesArgsForCall)
}

func (fake *ZhmcAPI) GetCPCPropertiesCalls(stub func(string) (*zhmcclient.CPCProperties, int, *zhmcclient.HmcError)) {
fake.getCPCPropertiesMutex.Lock()
defer fake.getCPCPropertiesMutex.Unlock()
fake.GetCPCPropertiesStub = stub
}

func (fake *ZhmcAPI) GetCPCPropertiesArgsForCall(i int) string {
fake.getCPCPropertiesMutex.RLock()
defer fake.getCPCPropertiesMutex.RUnlock()
argsForCall := fake.getCPCPropertiesArgsForCall[i]
return argsForCall.arg1
}

func (fake *ZhmcAPI) GetCPCPropertiesReturns(result1 *zhmcclient.CPCProperties, result2 int, result3 *zhmcclient.HmcError) {
fake.getCPCPropertiesMutex.Lock()
defer fake.getCPCPropertiesMutex.Unlock()
fake.GetCPCPropertiesStub = nil
fake.getCPCPropertiesReturns = struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
}{result1, result2, result3}
}

func (fake *ZhmcAPI) GetCPCPropertiesReturnsOnCall(i int, result1 *zhmcclient.CPCProperties, result2 int, result3 *zhmcclient.HmcError) {
fake.getCPCPropertiesMutex.Lock()
defer fake.getCPCPropertiesMutex.Unlock()
fake.GetCPCPropertiesStub = nil
if fake.getCPCPropertiesReturnsOnCall == nil {
fake.getCPCPropertiesReturnsOnCall = make(map[int]struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
})
}
fake.getCPCPropertiesReturnsOnCall[i] = struct {
result1 *zhmcclient.CPCProperties
result2 int
result3 *zhmcclient.HmcError
}{result1, result2, result3}
}

func (fake *ZhmcAPI) GetStorageAdapterPortProperties(arg1 string) (*zhmcclient.StorageAdapterPort, int, *zhmcclient.HmcError) {
fake.getStorageAdapterPortPropertiesMutex.Lock()
ret, specificReturn := fake.getStorageAdapterPortPropertiesReturnsOnCall[len(fake.getStorageAdapterPortPropertiesArgsForCall)]
Expand Down
Loading

0 comments on commit 2ee1229

Please sign in to comment.