diff --git a/.version b/.version index 84cc529..815d5ca 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.18.0 +1.19.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0c87c..6786e5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.19.0] - 2022-07-06 + +### Changed + +- Change HSM v1 API references to v2 + ## [1.18.0] - 2022-03-07 ### Removed diff --git a/Dockerfile b/Dockerfile index 5c02dfd..f0f81d7 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # MIT License # -# (C) Copyright [2019-2021] Hewlett Packard Enterprise Development LP +# (C) Copyright [2019-2022] Hewlett Packard Enterprise Development LP # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -55,7 +55,7 @@ LABEL maintainer="Hewlett Packard Enterprise" STOPSIGNAL SIGTERM # Setup environment variables. -ENV HSM_URL=https://api-gateway.default.svc.cluster.local/apis/smd/hsm/v1 +ENV HSM_URL=https://api-gateway.default.svc.cluster.local/apis/smd/hsm/v2 ENV MEDS_OPTS="" ENV VAULT_ADDR="http://cray-vault.vault:8200" diff --git a/cmd/meds/meds.go b/cmd/meds/meds.go index 32e2638..273b45d 100644 --- a/cmd/meds/meds.go +++ b/cmd/meds/meds.go @@ -1,7 +1,7 @@ /* * MIT License * - * (C) Copyright [2019-2021] Hewlett Packard Enterprise Development LP + * (C) Copyright [2019-2022] Hewlett Packard Enterprise Development LP * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -952,7 +952,7 @@ func init_cabinet(cab GenericHardware) error { log.Println("Failed to get ethernet interfaces from HSM, not processing further: ", err) return err } - hsmEthernetInterfacesMap := map[string]sm.CompEthInterface{} + hsmEthernetInterfacesMap := map[string]sm.CompEthInterfaceV2{} for _, ei := range hsmEthernetInterfaces { hsmEthernetInterfacesMap[ei.ID] = ei } @@ -969,7 +969,7 @@ func init_cabinet(cab GenericHardware) error { } // Preload HSM EthernetInterfaces with the endpoints. - ethernetInterface := sm.CompEthInterface{ + ethernetInterface := sm.CompEthInterfaceV2{ MACAddr: normalizedMAC, CompID: v.name, } @@ -1148,8 +1148,8 @@ func main() { "Default SSH key to use when communicating with targets") flag.StringVar(&sls, "sls", "http://cray-sls/v1", "Location of the System Layout Service API, up through the /v1 portion. (Do not include trailing slash)") - flag.StringVar(&hsm, "hsm", "http://cray-smd/hsm/v1", - "Location of the Hardware State Manager API, up through the /v1 portion. (Do not include trailing slash)") + flag.StringVar(&hsm, "hsm", "http://cray-smd/hsm/v2", + "Location of the Hardware State Manager API, up through the /v2 portion. (Do not include trailing slash)") flag.StringVar(&syslogTarg, "syslog", "", "Server:Port of the syslog aggregator") flag.StringVar(&ntpTarg, "ntp", "", diff --git a/cmd/meds/meds_test.go b/cmd/meds/meds_test.go index bd25c3d..786fce5 100644 --- a/cmd/meds/meds_test.go +++ b/cmd/meds/meds_test.go @@ -1,7 +1,7 @@ /* * MIT License * - * (C) Copyright [2019-2021] Hewlett Packard Enterprise Development LP + * (C) Copyright [2019-2022] Hewlett Packard Enterprise Development LP * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -528,7 +528,7 @@ func Test_notifyHSMXnamePresent(t *testing.T) { map[string]HTTPResponse{ "/Inventory/RedfishEndpoints": HTTPResponse{ 201, - `[{"URI": "/hsm/v1/Inventory/RedfishEndpoints/x0c0s0b0"}]`, + `[{"URI": "/hsm/v2/Inventory/RedfishEndpoints/x0c0s0b0"}]`, json.RawMessage(`{"ID":"x7c5s3b1","FQDN":"x7c5s3b1","MACAddr":"02:00:07:05:33:10","RediscoverOnUpdate":true}`), }, }, diff --git a/docker-compose.developer.full.yaml b/docker-compose.developer.full.yaml index 1f8b2c6..3fe14ce 100644 --- a/docker-compose.developer.full.yaml +++ b/docker-compose.developer.full.yaml @@ -165,7 +165,7 @@ services: context: . command: ["vault_loader"] environment: - - HSM_URL=http://cray-smd:27779/hsm/v1 + - HSM_URL=http://cray-smd:27779/hsm/v2 - MEDS_OPTS="" - CRAY_VAULT_AUTH_PATH=auth/token/create - CRAY_VAULT_ROLE_FILE=configs/namespace @@ -184,7 +184,7 @@ services: build: context: . environment: - - HSM_URL=http://cray-smd:27779/hsm/v1 + - HSM_URL=http://cray-smd:27779/hsm/v2 - "MEDS_OPTS=-sls http://cray-sls:8376/v1" - CRAY_VAULT_AUTH_PATH=auth/token/create - CRAY_VAULT_ROLE_FILE=configs/namespace diff --git a/go.mod b/go.mod index e6fdb6f..74f9293 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/Cray-HPE/hms-bmc-networkprotocol v1.5.2 github.com/Cray-HPE/hms-certs v1.3.2 github.com/Cray-HPE/hms-compcredentials v1.11.2 - github.com/Cray-HPE/hms-dns-dhcp v1.5.2 + github.com/Cray-HPE/hms-dns-dhcp v1.6.0 github.com/Cray-HPE/hms-securestorage v1.12.2 github.com/Cray-HPE/hms-sls v1.10.4 github.com/Cray-HPE/hms-smd v1.30.9 diff --git a/go.sum b/go.sum index f785d95..a396d7b 100644 --- a/go.sum +++ b/go.sum @@ -49,6 +49,8 @@ github.com/Cray-HPE/hms-compcredentials v1.11.2 h1:Ug7e7vMSx1STHKkniWY27ddD1X49p github.com/Cray-HPE/hms-compcredentials v1.11.2/go.mod h1:tmurR+zsOtB61n6j3GlEfsl7wmNIAGJqErFymOUb0Hw= github.com/Cray-HPE/hms-dns-dhcp v1.5.2 h1:O/NMxUWy3zHGu1tYTyjNBa3MU5iSlKwJA01mR5AfO2w= github.com/Cray-HPE/hms-dns-dhcp v1.5.2/go.mod h1:F5EyKyAD88Q+Mlc8N3YNUiY/hCfJDDtNyVF4MgN1h80= +github.com/Cray-HPE/hms-dns-dhcp v1.6.0 h1:m7yarg1Pju8ya9gkaATW7v1lcsMJFcDHCwNKwqkmYh4= +github.com/Cray-HPE/hms-dns-dhcp v1.6.0/go.mod h1:F5EyKyAD88Q+Mlc8N3YNUiY/hCfJDDtNyVF4MgN1h80= github.com/Cray-HPE/hms-go-http-lib v1.5.3/go.mod h1:BKlB4HKAGW5GgS3x01y7zxxYFLaJM2byACUunmes2z8= github.com/Cray-HPE/hms-msgbus v1.10.2/go.mod h1:DM5Iw58ejMxbCOX2KgmcBwDS5YWIlba3BOW9JsDQl4w= github.com/Cray-HPE/hms-s3 v1.9.2/go.mod h1:p5pVsMDeOdXKssd9qyFtXo4ztrn2lhD04nrO8+NOi7g= diff --git a/runUnitTest.sh b/runUnitTest.sh index 61b69ad..8727c79 100755 --- a/runUnitTest.sh +++ b/runUnitTest.sh @@ -25,17 +25,24 @@ # set -x +# Add .exe if running in a WSL environment +if $(uname -r | grep -q "Microsoft"); then + shopt -s expand_aliases + alias docker-compose=docker-compose.exe +fi # Configure docker compose export COMPOSE_PROJECT_NAME=$RANDOM export COMPOSE_FILE=docker-compose.test.unit.yaml +args="-f $COMPOSE_FILE -p $COMPOSE_PROJECT_NAME" + echo "COMPOSE_PROJECT_NAME: ${COMPOSE_PROJECT_NAME}" echo "COMPOSE_FILE: $COMPOSE_FILE" function cleanup() { - docker-compose down + docker-compose $args down if ! [[ $? -eq 0 ]]; then echo "Failed to decompose environment!" exit 1 @@ -45,8 +52,8 @@ function cleanup() { echo "Starting containers..." -docker-compose build -docker-compose up --exit-code-from unit-tests unit-tests +docker-compose $args build +docker-compose $args up --exit-code-from unit-tests unit-tests test_result=$? diff --git a/vendor/github.com/Cray-HPE/hms-dns-dhcp/pkg/dns_dhcp.go b/vendor/github.com/Cray-HPE/hms-dns-dhcp/pkg/dns_dhcp.go index ba74206..43a0931 100644 --- a/vendor/github.com/Cray-HPE/hms-dns-dhcp/pkg/dns_dhcp.go +++ b/vendor/github.com/Cray-HPE/hms-dns-dhcp/pkg/dns_dhcp.go @@ -1,6 +1,6 @@ // MIT License // -// (C) Copyright [2019, 2021] Hewlett Packard Enterprise Development LP +// (C) Copyright [2019, 2022] Hewlett Packard Enterprise Development LP // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -37,14 +37,18 @@ import ( ) type DNSDHCPHelper struct { - HSMURL string + HSMURL string HTTPClient *retryablehttp.Client } var serviceName string func NewDHCPDNSHelper(HSMURL string, HTTPClient *retryablehttp.Client) (helper DNSDHCPHelper) { - helper.HSMURL = HSMURL + // We're locking to a version of the HSM API (Curently V2) + // to ensure we can handle that version's payload. Cut off + // any additional URL after 'hsm' (e.g. /hsm/v2/) + url := strings.Split(HSMURL, "/hsm") + helper.HSMURL = url[0] if HTTPClient != nil { helper.HTTPClient = HTTPClient @@ -54,7 +58,7 @@ func NewDHCPDNSHelper(HSMURL string, HTTPClient *retryablehttp.Client) (helper D if (serviceName == "") { var err error - serviceName,err = os.Hostname() + serviceName, err = os.Hostname() if (err != nil) { serviceName = "DNS_DHCP" } @@ -69,26 +73,26 @@ func NewDHCPDNSHelperInstance(HSMURL string, HTTPClient *retryablehttp.Client, s } func rtGet(helper *DNSDHCPHelper, url string) (*http.Response, error) { - req,err := http.NewRequest("GET",url,nil) + req, err := http.NewRequest("GET", url, nil) if (err != nil) { - return nil,err + return nil, err } - base.SetHTTPUserAgent(req,serviceName) - rtReq,rtErr := retryablehttp.FromRequest(req) + base.SetHTTPUserAgent(req, serviceName) + rtReq, rtErr := retryablehttp.FromRequest(req) if (rtErr != nil) { - return nil,rtErr + return nil, rtErr } rsp, rspErr := helper.HTTPClient.Do(rtReq) if (rspErr != nil) { - return nil,rspErr + return nil, rspErr } - return rsp,nil + return rsp, nil } -func (helper *DNSDHCPHelper) GetUnknownComponents() (unknownComponents []sm.CompEthInterface, err error) { - url := fmt.Sprintf("%s/Inventory/EthernetInterfaces?ComponentID", helper.HSMURL) +func (helper *DNSDHCPHelper) GetUnknownComponents() (unknownComponents []sm.CompEthInterfaceV2, err error) { + url := fmt.Sprintf("%s/hsm/v2/Inventory/EthernetInterfaces?ComponentID", helper.HSMURL) - response, err := rtGet(helper,url) + response, err := rtGet(helper, url) if err != nil { return } @@ -110,8 +114,8 @@ func (helper *DNSDHCPHelper) GetUnknownComponents() (unknownComponents []sm.Comp return } -func (helper *DNSDHCPHelper) GetAllEthernetInterfaces() (unknownComponents []sm.CompEthInterface, err error) { - url := fmt.Sprintf("%s/Inventory/EthernetInterfaces", helper.HSMURL) +func (helper *DNSDHCPHelper) GetAllEthernetInterfaces() (unknownComponents []sm.CompEthInterfaceV2, err error) { + url := fmt.Sprintf("%s/hsm/v2/Inventory/EthernetInterfaces", helper.HSMURL) response, err := helper.HTTPClient.Get(url) if err != nil { @@ -135,7 +139,7 @@ func (helper *DNSDHCPHelper) GetAllEthernetInterfaces() (unknownComponents []sm. return } -func (helper *DNSDHCPHelper) AddNewEthernetInterface(newInterface sm.CompEthInterface, patchIfConflict bool) ( +func (helper *DNSDHCPHelper) AddNewEthernetInterface(newInterface sm.CompEthInterfaceV2, patchIfConflict bool) ( err error) { payloadBytes, marshalErr := json.Marshal(newInterface) if marshalErr != nil { @@ -143,7 +147,7 @@ func (helper *DNSDHCPHelper) AddNewEthernetInterface(newInterface sm.CompEthInte return } - url := fmt.Sprintf("%s/Inventory/EthernetInterfaces", helper.HSMURL) + url := fmt.Sprintf("%s/hsm/v2/Inventory/EthernetInterfaces", helper.HSMURL) request, requestErr := retryablehttp.NewRequest("POST", url, bytes.NewBuffer(payloadBytes)) if requestErr != nil { @@ -159,7 +163,7 @@ func (helper *DNSDHCPHelper) AddNewEthernetInterface(newInterface sm.CompEthInte } if (response.Body != nil) { - _,_ = ioutil.ReadAll(response.Body) + _, _ = ioutil.ReadAll(response.Body) defer response.Body.Close() } @@ -176,7 +180,7 @@ func (helper *DNSDHCPHelper) AddNewEthernetInterface(newInterface sm.CompEthInte return } -func (helper *DNSDHCPHelper) PatchEthernetInterface(theInterface sm.CompEthInterface) (err error) { +func (helper *DNSDHCPHelper) PatchEthernetInterface(theInterface sm.CompEthInterfaceV2) (err error) { payloadBytes, marshalErr := json.Marshal(theInterface) if marshalErr != nil { err = fmt.Errorf("failed to marshal interface: %w", marshalErr) @@ -184,7 +188,7 @@ func (helper *DNSDHCPHelper) PatchEthernetInterface(theInterface sm.CompEthInter } macID := strings.ReplaceAll(theInterface.MACAddr, ":", "") - url := fmt.Sprintf("%s/Inventory/EthernetInterfaces/%s", helper.HSMURL, macID) + url := fmt.Sprintf("%s/hsm/v2/Inventory/EthernetInterfaces/%s", helper.HSMURL, macID) request, requestErr := retryablehttp.NewRequest("PATCH", url, bytes.NewBuffer(payloadBytes)) if requestErr != nil { @@ -199,7 +203,7 @@ func (helper *DNSDHCPHelper) PatchEthernetInterface(theInterface sm.CompEthInter return } if (response.Body != nil) { - _,_ = ioutil.ReadAll(response.Body) + _, _ = ioutil.ReadAll(response.Body) defer response.Body.Close() } diff --git a/vendor/modules.txt b/vendor/modules.txt index bea2bbd..4218f4f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -10,7 +10,7 @@ github.com/Cray-HPE/hms-certs/pkg/hms_certs # github.com/Cray-HPE/hms-compcredentials v1.11.2 ## explicit github.com/Cray-HPE/hms-compcredentials -# github.com/Cray-HPE/hms-dns-dhcp v1.5.2 +# github.com/Cray-HPE/hms-dns-dhcp v1.6.0 ## explicit github.com/Cray-HPE/hms-dns-dhcp/pkg # github.com/Cray-HPE/hms-securestorage v1.12.2