-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete old redfish subscriptions (#49)
When hardware is moved the bmc may retain its old subscriptions. These old subscriptions refer to the old location/xname. This causes problems when the hardware sends events. The listeners mistakenly think the events are for the old location/xname. This commit changes hmcollector to automatically delete these old subscriptions. Here are the cases where it can find a bad subscription - At start up it will check all subscriptions. - Periodically it will check for its own subscriptions, and it will delete any bad ones that it finds, however, in this case it does not necessarily read all the subscriptions. It only reads until it finds the subscription it is looking for. CASMHMS-5685
- Loading branch information
Showing
14 changed files
with
1,202 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: Run Unit Tests | ||
on: [push, pull_request, workflow_dispatch] | ||
jobs: | ||
run_unit_test: | ||
uses: Cray-HPE/hms-build-image-workflows/.github/workflows/run_unit_test.yaml@v2 | ||
with: | ||
runs-on: ubuntu-latest | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.25.0 | ||
2.26.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# MIT License | ||
# | ||
# (C) Copyright [2023] 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"), | ||
# to deal in the Software without restriction, including without limitation | ||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
# and/or sell copies of the Software, and to permit persons to whom the | ||
# Software is furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
# OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
# Dockerfile for running HMS Redfish Collector unit tests. | ||
|
||
# v1.1.0 of Confluent Go Kafka requires at least v1.1.0 of librdkafka. | ||
ARG LIBRDKAFKA_VER_MIN=1.1.0 | ||
|
||
# Build base just has the packages installed we need. | ||
FROM artifactory.algol60.net/docker.io/library/golang:1.16-alpine AS build-base | ||
|
||
ARG LIBRDKAFKA_VER_MIN | ||
|
||
RUN set -ex \ | ||
&& apk -U upgrade \ | ||
&& apk add --no-cache \ | ||
build-base \ | ||
"librdkafka-dev>${LIBRDKAFKA_VER_MIN}" \ | ||
pkgconf | ||
|
||
# Base copies in the files we need to test/build. | ||
FROM build-base AS base | ||
|
||
RUN go env -w GO111MODULE=auto | ||
|
||
# Copy all the necessary files to the image. | ||
COPY cmd $GOPATH/src/github.com/Cray-HPE/hms-hmcollector/cmd | ||
COPY internal $GOPATH/src/github.com/Cray-HPE/hms-hmcollector/internal | ||
COPY vendor $GOPATH/src/github.com/Cray-HPE/hms-hmcollector/vendor | ||
|
||
### Build Stage ### | ||
FROM base AS builder | ||
|
||
RUN set -ex \ | ||
&& go test -cover github.com/Cray-HPE/hms-hmcollector/cmd/hmcollector | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// MIT License | ||
// | ||
// (C) Copyright [2023] 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"), | ||
// to deal in the Software without restriction, including without limitation | ||
// the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
// and/or sell copies of the Software, and to permit persons to whom the | ||
// Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
// OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/Cray-HPE/hms-hmcollector/internal/hmcollector" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
setupLoggingForTest() | ||
m.Run() | ||
} | ||
|
||
func setupLoggingForTest() { | ||
logLevel := os.Getenv("LOG_LEVEL") | ||
if logLevel == "" { | ||
os.Setenv("LOG_LEVEL", "debug") | ||
} | ||
SetupLogging() | ||
} | ||
|
||
func TestTrueCaseForIsSubscriptionForWrongXname(t *testing.T) { | ||
xname := "x3000c0s19b1" | ||
wrongXnameSubscriptions := []*hmcollector.EventSubscription{ | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71/x3000c0s19b7"}, | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71", Context: "x3000c0s19b7"}, | ||
} | ||
for i, sub := range wrongXnameSubscriptions { | ||
if !isSubscriptionForWrongXname(xname, sub) { | ||
t.Errorf("Expected isSubscriptionForWrongXname to return true. "+ | ||
"i: %d, xname: %s, destination: %s, context: %s", | ||
i, xname, sub.Destination, sub.Context) | ||
} | ||
} | ||
} | ||
|
||
func TestFalseCaseForIsSubscriptionForWrongXname(t *testing.T) { | ||
xname := "x3000c0s19b1" | ||
unnormalizedXname := "x3000c0s19b000001" | ||
subscriptions := []*hmcollector.EventSubscription{ | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71/" + xname, Context: ""}, | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71/", Context: xname}, | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71", Context: xname}, | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71/" + unnormalizedXname, Context: ""}, | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71", Context: unnormalizedXname}, | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71/" + unnormalizedXname, Context: unnormalizedXname}, | ||
// subscriptions that are not owned by hmcollector | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71", Context: "fabric-manager-hardware-telemetry-sub"}, | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71:80", Context: "fabric-manager-hardware-telemetry-sub"}, | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71", Context: ""}, | ||
&hmcollector.EventSubscription{Destination: "http://10.94.100.71/junk", Context: ""}, | ||
&hmcollector.EventSubscription{Destination: "", Context: ""}, | ||
} | ||
for i, sub := range subscriptions { | ||
if isSubscriptionForWrongXname(xname, sub) { | ||
t.Errorf("Expected isSubscriptionForWrongXname to return false. "+ | ||
"i: %d, xname: %s, destination: %s, context: %s", | ||
i, xname, sub.Destination, sub.Context) | ||
} | ||
} | ||
} | ||
func TestBadXnameCaseForIsSubscriptionForWrongXname(t *testing.T) { | ||
xname := "10.94.101.71" | ||
unnormalizedXname := "x3000c0s19b000001" | ||
subscriptions := []*hmcollector.EventSubscription{ | ||
&hmcollector.EventSubscription{Destination: "http://" + xname, Context: ""}, | ||
&hmcollector.EventSubscription{Destination: "http://" + xname, Context: xname}, | ||
&hmcollector.EventSubscription{Destination: "http://" + xname, Context: unnormalizedXname}, | ||
} | ||
for i, sub := range subscriptions { | ||
if isSubscriptionForWrongXname(xname, sub) { | ||
t.Errorf("Expected isSubscriptionForWrongXname to return false. "+ | ||
"i: %d, xname: %s, destination: %s, context: %s", | ||
i, xname, sub.Destination, sub.Context) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.