Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crypto adapters and domains attach support #10

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions pkg/zhmcclient/fakes/lpar.go

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

81 changes: 81 additions & 0 deletions pkg/zhmcclient/fakes/zhmc.go

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

39 changes: 36 additions & 3 deletions pkg/zhmcclient/lpar.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type LparAPI interface {
FetchAsciiConsoleURI(lparURI string, request *AsciiConsoleURIPayload) (*AsciiConsoleURIResponse, int, *HmcError)

GetEnergyDetailsforLPAR(lparURI string, props *EnergyRequestPayload) (uint64, int, *HmcError)

AttachCryptoToPartition(lparURI string, request *CryptoConfig) (int, *HmcError)
}

type LparManager struct {
Expand Down Expand Up @@ -625,13 +627,13 @@ func (m *LparManager) FetchAsciiConsoleURI(lparURI string, request *AsciiConsole
"timestamp": 1680408593302
}]
}
*/

*/
func (m *LparManager) GetEnergyDetailsforLPAR(lparURI string, props *EnergyRequestPayload) (uint64, int, *HmcError) {
requestUrl := m.client.CloneEndpointURL()

requestUrl.Path = path.Join(requestUrl.Path, lparURI, "/operations", "/get-historical-sustainability-data")
logger.Info("Request URL:" + string(requestUrl.Path) + " Method:" + http.MethodPost + " props" + fmt.Sprint(props))
logger.Info("Request URL:" + string(requestUrl.Path) + " Method:" + http.MethodPost + " props" + fmt.Sprint(props))
status, responseBody, err := m.client.ExecuteRequest(http.MethodPost, requestUrl, props, "")

if err != nil {
Expand All @@ -657,3 +659,34 @@ func (m *LparManager) GetEnergyDetailsforLPAR(lparURI string, props *EnergyReque
errorResponseBody := GenerateErrorFromResponse(responseBody)
return 0, status, errorResponseBody
}

func (m *LparManager) AttachCryptoToPartition(lparURI string, request *CryptoConfig) (int, *HmcError) {
requestUrl := m.client.CloneEndpointURL()
requestUrl.Path = path.Join(requestUrl.Path, lparURI, "/operations/increase-crypto-configuration")

logger.Info(fmt.Sprintf("Request URL: %v, Method: %v", requestUrl, http.MethodPost))
logger.Info(fmt.Sprintf("request: %v", request))
status, responseBody, err := m.client.ExecuteRequest(http.MethodPost, requestUrl, request, "")

if err != nil {
logger.Error("error on attach crypto adapters and domains to partition",
zap.String("request url", fmt.Sprint(lparURI)),
zap.String("method", http.MethodPost),
zap.String("status", fmt.Sprint(status)),
zap.Error(fmt.Errorf("%v", err)))
return status, err
}

if status == http.StatusNoContent {
logger.Info(fmt.Sprintf("Response: attach crypto adapters and domains to partition successfull, request url: %v, method: %v, status: %v", lparURI, http.MethodPost, status))
return status, nil
}

errorResponseBody := GenerateErrorFromResponse(responseBody)
logger.Error("error attaching crypto adapters and domains to partition",
zap.String("request url", fmt.Sprint(lparURI)),
zap.String("method", http.MethodPost),
zap.String("status: ", fmt.Sprint(status)),
zap.Error(fmt.Errorf("%v", errorResponseBody)))
return status, errorResponseBody
}
46 changes: 44 additions & 2 deletions pkg/zhmcclient/lpar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ var _ = Describe("LPAR", func() {

Describe("GetEnergyDetailsforLPAR", func() {
var (
bytes []byte
bytes []byte
)

BeforeEach(func() {
Expand All @@ -149,7 +149,7 @@ var _ = Describe("LPAR", func() {
fakeClient.CloneEndpointURLReturns(url)
fakeClient.ExecuteRequestReturns(http.StatusOK, bytes, nil)
props := &EnergyRequestPayload{
Range: "last-day",
Range: "last-day",
Resolution: "fifteen-minutes",
}
rets, _, err := manager.GetEnergyDetailsforLPAR(lparid, props)
Expand Down Expand Up @@ -680,4 +680,46 @@ var _ = Describe("LPAR", func() {
})
})

Describe("AttachCryptoToPartition", func() {
var cryptoConfig *CryptoConfig
BeforeEach(func() {
cryptoConfig = &CryptoConfig{
CryptoAdapterUris: []string{"uri"},
CryptoDomainConfigurations: []DomainInfo{
{
DomainIdx: 1,
AccessMode: "control",
},
},
}
})
Context("When AttachCryptoToPartition returns correctly", func() {
It("Check the results Succeed", func() {
fakeClient.CloneEndpointURLReturns(url)
fakeClient.ExecuteRequestReturns(http.StatusOK, nil, nil)
rets, _ := manager.AttachCryptoToPartition(lparid, cryptoConfig)
Expect(rets).ToNot(BeNil())
})

})
Context("When AttachCryptoToPartition returns error due to hmcErr", func() {
It("check the error happened", func() {
fakeClient.CloneEndpointURLReturns(url)
fakeClient.ExecuteRequestReturns(http.StatusOK, nil, hmcErr)
rets, err := manager.AttachCryptoToPartition(lparid, cryptoConfig)
Expect(rets).To(Equal(200))
Expect(err).To(Equal(hmcErr))
})
})
Context("When AttachCryptoToPartition returns correctly with status 204", func() {
It("check the response has no content", func() {
fakeClient.CloneEndpointURLReturns(url)
fakeClient.ExecuteRequestReturns(http.StatusNoContent, nil, nil)
rets, err := manager.AttachCryptoToPartition(lparid, cryptoConfig)
Expect(err).To(BeNil())
Expect(rets).To(Equal(204))
})
})
})

})
10 changes: 5 additions & 5 deletions pkg/zhmcclient/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ type LparProperties struct {
NicUris []string `json:"nic-uris,omitempty"`
HbaUris []string `json:"hba-uris,omitempty"`
StorageGroupURIs []string `json:"storage-group-uris,omitempty"`
CryptoConfiguration CryptoConfig `json:"-"`
CryptoConfiguration CryptoConfig `json:"crypto-configuration,omitempty"`
SscHostName string `json:"ssc-host-name,omitempty"`
SscBootSelection SscBootSelection `json:"ssc-boot-selection,omitempty"`
SscIpv4Gateway string `json:"ssc-ipv4-gateway,omitempty"`
Expand Down Expand Up @@ -1029,8 +1029,8 @@ type CryptoConfig struct {
}

type EnergyRequestPayload struct {
Timescale string `json:"timescale,omitempty"`
Type string `json:"type,omitempty"`
Range string `json:"range,omitempty"`
Resolution string `json:"resolution,omitempty"`
Timescale string `json:"timescale,omitempty"`
Type string `json:"type,omitempty"`
Range string `json:"range,omitempty"`
Resolution string `json:"resolution,omitempty"`
}
6 changes: 5 additions & 1 deletion pkg/zhmcclient/zhmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ func (m *ZhmcManager) GetEnergyDetailsforLPAR(lparURI string, props *EnergyReque
return m.lparManager.GetEnergyDetailsforLPAR(lparURI, props)
}

func (m *ZhmcManager) AttachCryptoToPartition(lparURI string, request *CryptoConfig) (int, *HmcError) {
return m.lparManager.AttachCryptoToPartition(lparURI, request)
}

func (m *ZhmcManager) GetLiveEnergyDetailsforLPAR(lparURI string) (uint64, int, *HmcError) {
return m.metricsManager.GetLiveEnergyDetailsforLPAR(lparURI)
return m.metricsManager.GetLiveEnergyDetailsforLPAR(lparURI)
}

// Adapter
Expand Down
Loading
Loading