From 0ea43ef148d70e6e3adb7073d4da6f76e39067f8 Mon Sep 17 00:00:00 2001 From: Anthony Floeder Date: Fri, 6 Sep 2024 16:02:06 -0500 Subject: [PATCH] Exit after initialization complete by default, use http command line parameter to enable redfish interface Signed-off-by: Anthony Floeder --- Dockerfile | 6 +++--- pkg/controller.go | 10 +++++----- pkg/ec/ec.go | 2 +- pkg/manager-nnf/manager.go | 14 ++++++++++---- pkg/tests/benchmarks/benchmark_test.go | 2 +- pkg/tests/filesystem/file_system_test.go | 2 +- pkg/tests/nnf_test.go | 2 +- pkg/tests/recovery/recovery_test.go | 2 +- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 785377b..093c91f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM golang:1.19 as builder +FROM golang:1.19 AS builder WORKDIR /workspace @@ -38,12 +38,12 @@ ENTRYPOINT ["sh", "runContainerTest.sh"] # Setup Static Analysis # TODO: These should move to pre-commit check -FROM builder as codestyle +FROM builder AS codestyle COPY static-analysis/docker_codestyle_entry.sh static-analysis/docker_codestyle_entry.sh ENTRYPOINT ["sh", "static-analysis/docker_codestyle_entry.sh"] # the static-analysis-lint-container -FROM builder as lint +FROM builder AS lint COPY static-analysis/docker_lint_entry.sh static-analysis/docker_lint_entry.sh ENTRYPOINT ["sh", "static-analysis/docker_lint_entry.sh"] diff --git a/pkg/controller.go b/pkg/controller.go index b9e5937..b57dff2 100644 --- a/pkg/controller.go +++ b/pkg/controller.go @@ -58,7 +58,7 @@ type Options struct { json string // Initialize the element controller with the provided json file direct string // Enable direct management of NVMe devices matching this regexp pattern InitializeAndExit bool // Initialize all controllers then exit without starting the http server (mfg use) - DeleteUnknownVolumes bool // Delete volumes not represented by a storage pool at the end of initialization + deleteUnknownVolumes bool // Delete volumes not represented by a storage pool at the end of initialization } func newDefaultOptions() *Options { @@ -78,7 +78,7 @@ func BindFlags(fs *flag.FlagSet) *Options { fs.StringVar(&opts.json, "json", "", "Initialize database with provided json file") fs.StringVar(&opts.direct, "direct", opts.direct, "Enable direct management of NVMe block devices matching this regexp pattern. Implies Mock.") fs.BoolVar(&opts.InitializeAndExit, "initializeAndExit", opts.InitializeAndExit, "Initialize all hardware controllers, then exit without starting the http server. Useful in hardware bringup") - fs.BoolVar(&opts.DeleteUnknownVolumes, "deleteUnknownVolumes", opts.DeleteUnknownVolumes, "Delete volumes not represented by storage pools") + fs.BoolVar(&opts.deleteUnknownVolumes, "deleteUnknownVolumes", opts.deleteUnknownVolumes, "Delete volumes not represented by storage pools") nvme.BindFlags(fs) @@ -119,16 +119,16 @@ func NewController(opts *Options) *ec.Controller { persistent.StorageProvider = persistent.NewJsonFilePersistentStorageProvider(opts.json) } - return ec.NewController(Name, Port, Version, NewDefaultApiRouters(switchCtrl, nvmeCtrl, nnfCtrl)) + return ec.NewController(Name, Port, Version, NewDefaultApiRouters(switchCtrl, nvmeCtrl, nnfCtrl, opts.deleteUnknownVolumes)) } // NewDefaultApiRouters - -func NewDefaultApiRouters(switchCtrl fabric.SwitchtecControllerInterface, nvmeCtrl nvme.NvmeController, nnfCtrl nnf.NnfControllerInterface) ec.Routers { +func NewDefaultApiRouters(switchCtrl fabric.SwitchtecControllerInterface, nvmeCtrl nvme.NvmeController, nnfCtrl nnf.NnfControllerInterface, nnfUnknownVolumes bool) ec.Routers { routers := []ec.Router{ fabric.NewDefaultApiRouter(fabric.NewDefaultApiService(), switchCtrl), nvme.NewDefaultApiRouter(nvme.NewDefaultApiService(), nvmeCtrl), - nnf.NewDefaultApiRouter(nnf.NewDefaultApiService(nnf.NewDefaultStorageService()), nnfCtrl), + nnf.NewDefaultApiRouter(nnf.NewDefaultApiService(nnf.NewDefaultStorageService(nnfUnknownVolumes)), nnfCtrl), telemetry.NewDefaultApiRouter(telemetry.NewDefaultApiService()), event.NewDefaultApiRouter(event.NewDefaultApiService()), msgreg.NewDefaultApiRouter(msgreg.NewDefaultApiService()), diff --git a/pkg/ec/ec.go b/pkg/ec/ec.go index 6286c0c..b415dc9 100644 --- a/pkg/ec/ec.go +++ b/pkg/ec/ec.go @@ -109,7 +109,7 @@ type Options struct { } func NewDefaultOptions() *Options { - return &Options{Http: true, Port: 8080, Log: false, Verbose: false} + return &Options{Http: false, Port: 8080, Log: false, Verbose: false} } func NewDefaultTestOptions() *Options { diff --git a/pkg/manager-nnf/manager.go b/pkg/manager-nnf/manager.go index f08641e..cd2d78b 100644 --- a/pkg/manager-nnf/manager.go +++ b/pkg/manager-nnf/manager.go @@ -55,7 +55,8 @@ var storageService = StorageService{ health: sf.CRITICAL_RH, } -func NewDefaultStorageService() StorageServiceApi { +func NewDefaultStorageService(unknownVolumes bool) StorageServiceApi { + storageService.deleteUnknownVolumes = unknownVolumes return NewAerService(&storageService) // Wrap the default storage service with Advanced Error Reporting capabilities } @@ -76,9 +77,12 @@ type StorageService struct { // Index of the Id field of any Storage Service resource (Pools, Groups, Endpoints, FileSystems) // That is, given a Storage Service resource OdataId field, ResourceIndex will correspond to the - // index within the OdataId splity by "/" i.e. strings.split(OdataId, "/")[ResourceIndex] + // index within the OdataId split by "/" i.e. strings.split(OdataId, "/")[ResourceIndex] resourceIndex int + // This flag controls whether we delete volumes that don't appear in storage pools we know about. + deleteUnknownVolumes bool + log ec.Logger } @@ -539,8 +543,10 @@ func (s *StorageService) EventHandler(e event.Event) error { } // Remove any namespaces that are not part of a Storage Pool - log.V(2).Info("Cleanup unknown volumes") - s.cleanupVolumes() + if s.deleteUnknownVolumes { + log.V(2).Info("Cleanup unknown volumes") + s.cleanupVolumes() + } s.state = sf.ENABLED_RST s.health = sf.OK_RH diff --git a/pkg/tests/benchmarks/benchmark_test.go b/pkg/tests/benchmarks/benchmark_test.go index d37ec32..fac7ab5 100644 --- a/pkg/tests/benchmarks/benchmark_test.go +++ b/pkg/tests/benchmarks/benchmark_test.go @@ -39,7 +39,7 @@ func BenchmarkStorage(b *testing.B) { b.Fatalf("Failed to start nnf controller") } - ss := nnf.NewDefaultStorageService() + ss := nnf.NewDefaultStorageService(true /* deleteUnknownVolumes */) b.ResetTimer() pools := make([]*sf.StoragePoolV150StoragePool, 0) diff --git a/pkg/tests/filesystem/file_system_test.go b/pkg/tests/filesystem/file_system_test.go index ac9b464..42a03ec 100644 --- a/pkg/tests/filesystem/file_system_test.go +++ b/pkg/tests/filesystem/file_system_test.go @@ -43,7 +43,7 @@ func TestFileSystem(t *testing.T) { server.FileSystemRegistry.RegisterFileSystem(testFs) // TODO: defer server.FileSystemRegistry.UnregisterFileSystem(testFs) - ss := nnf.NewDefaultStorageService() + ss := nnf.NewDefaultStorageService(true /* deleteUnknownVolumes */) sp := &sf.StoragePoolV150StoragePool{ CapacityBytes: 1024 * 1024, diff --git a/pkg/tests/nnf_test.go b/pkg/tests/nnf_test.go index 07bf552..60a8d3e 100644 --- a/pkg/tests/nnf_test.go +++ b/pkg/tests/nnf_test.go @@ -39,7 +39,7 @@ func TestStoragePools(t *testing.T) { t.Fatalf("Failed to start nnf controller") } - ss := nnf.NewDefaultStorageService() + ss := nnf.NewDefaultStorageService(true /* deleteUnknownVolumes */) cs := &sf.CapacityCapacitySource{} if err := ss.StorageServiceIdCapacitySourceGet(ss.Id(), cs); err != nil { diff --git a/pkg/tests/recovery/recovery_test.go b/pkg/tests/recovery/recovery_test.go index 91688da..5b77f2f 100644 --- a/pkg/tests/recovery/recovery_test.go +++ b/pkg/tests/recovery/recovery_test.go @@ -83,7 +83,7 @@ var _ = Describe("Reboot Recovery Testing", func() { c = nnfec.NewController(nnfec.NewMockOptions(true)) Expect(c.Init(ec.NewDefaultOptions())).NotTo(HaveOccurred()) - ss = nnf.NewDefaultStorageService() + ss = nnf.NewDefaultStorageService(true /* deleteUnknownVolumes */) }) // After each test we close the NNF Element Controller, thereby safely closing