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 cani schema check during import and warn of mismatches #87

Merged
merged 3 commits into from
Jul 10, 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
2 changes: 1 addition & 1 deletion .github/workflows/shellspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
name: Install shellspec (macOS)
run: |
brew tap shellspec/shellspec
brew update
# brew update
brew install shellspec ksh93 bash

- if: ${{ matrix.os == 'macos-latest' }}
Expand Down
26 changes: 26 additions & 0 deletions internal/provider/csm/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func loadJSON(path string, dest interface{}) error {
}

func (csm *CSM) Import(ctx context.Context, datastore inventory.Datastore) error {
// Check the schema version defined in the datastore
datastoreSchema, err := datastore.GetSchemaVersion()
if err != nil {
return err
}
currentSchema := string(datastoreSchema)

//
// Retrieve current state from the system
Expand Down Expand Up @@ -297,6 +303,11 @@ func (csm *CSM) Import(ctx context.Context, datastore inventory.Datastore) error
return fmt.Errorf("failed to decode SLS hardware extra properties (%s)", slsCabinet.Xname)
}

// if a schema is present but does not match the current schema, warn but accept so the user can adjust as needed
if slsCabinetEP.CaniSlsSchemaVersion != "" && slsCabinetEP.CaniSlsSchemaVersion != currentSchema {
log.Warn().Msgf("Schema mismatch: expected %s but found %s for SLS %s %s (%s)", currentSchema, slsCabinetEP.CaniSlsSchemaVersion, cCabinet.Type, slsCabinet.Xname, cCabinet.ID)
}

if slsCabinetEP.CaniId != cCabinet.ID.String() {
if len(slsCabinetEP.CaniId) != 0 {
log.Warn().Msgf("Detected CANI hardware ID change from %s to %s for SLS Hardware %s", slsCabinetEP.CaniId, cCabinet.ID, slsCabinet.Xname)
Expand Down Expand Up @@ -339,6 +350,11 @@ func (csm *CSM) Import(ctx context.Context, datastore inventory.Datastore) error
return fmt.Errorf("failed to decode SLS hardware extra properties (%s)", slsHardware.Xname)
}

// if a schema is present but does not match the current schema, warn but accept so the user can adjust as needed
if slsEP.CaniSlsSchemaVersion != "" && slsEP.CaniSlsSchemaVersion != currentSchema {
log.Warn().Msgf("Schema mismatch: expected %s but found %s for SLS %s %s (%s)", currentSchema, slsEP.CaniSlsSchemaVersion, cHardware.Type, slsHardware.Xname, cHardware.ID)
}

if slsEP.CaniId != cHardware.ID.String() {
if len(slsEP.CaniId) != 0 {
log.Warn().Msgf("Detected CANI hardware ID change from %s to %s for SLS Hardware %s", slsEP.CaniId, cHardware.ID, slsHardware.Xname)
Expand Down Expand Up @@ -381,6 +397,11 @@ func (csm *CSM) Import(ctx context.Context, datastore inventory.Datastore) error
return fmt.Errorf("failed to decode SLS hardware extra properties (%s)", slsHardware.Xname)
}

// if a schema is present but does not match the current schema, warn but accept so the user can adjust as needed
if slsEP.CaniSlsSchemaVersion != "" && slsEP.CaniSlsSchemaVersion != currentSchema {
log.Warn().Msgf("Schema mismatch: expected %s but found %s for SLS %s %s (%s)", currentSchema, slsEP.CaniSlsSchemaVersion, cHardware.Type, slsHardware.Xname, cHardware.ID)
}

if slsEP.CaniId != cHardware.ID.String() {
if len(slsEP.CaniId) != 0 {
log.Warn().Msgf("Detected CANI hardware ID change from %s to %s for SLS Hardware %s", slsEP.CaniId, cHardware.ID, slsHardware.Xname)
Expand Down Expand Up @@ -634,6 +655,11 @@ func (csm *CSM) Import(ctx context.Context, datastore inventory.Datastore) error
return fmt.Errorf("failed to update hardware (%s) in memory datastore", cNode.ID)
}

// if a schema is present but does not match the current schema, warn but accept so the user can adjust as needed
if slsNodeEP.CaniSlsSchemaVersion != "" && slsNodeEP.CaniSlsSchemaVersion != currentSchema {
log.Warn().Msgf("Schema mismatch: expected %s but found %s for SLS %s %s (%s)", currentSchema, slsNodeEP.CaniSlsSchemaVersion, cNode.Type, slsNode.Xname, cNode.ID)
}

//
// Update SLS Extra Properties
//
Expand Down
Loading