From 453a8ecb2eb841c750eb0ddc269f31950ec40054 Mon Sep 17 00:00:00 2001 From: Joel Rebello Date: Fri, 9 Aug 2024 15:17:11 +0200 Subject: [PATCH] purge unused code --- cmd/run.go | 6 +--- internal/store/yaml.go | 42 ------------------------ internal/worker/outofband.go | 23 ------------- internal/worker/worker_test.go | 59 ---------------------------------- 4 files changed, 1 insertion(+), 129 deletions(-) delete mode 100644 internal/store/yaml.go delete mode 100644 internal/worker/worker_test.go diff --git a/cmd/run.go b/cmd/run.go index 8c812094..0314a4e4 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -109,11 +109,7 @@ func runWorker(ctx context.Context) { } func initStore(ctx context.Context, config *app.Configuration, logger *logrus.Logger) (store.Repository, error) { - switch { - // from CLI flags - case strings.HasSuffix(storeKind, ".yml"), strings.HasSuffix(storeKind, ".yaml"): - return store.NewYamlInventory(storeKind) - case storeKind == string(model.InventoryStoreServerservice): + if storeKind == string(model.InventoryStoreServerservice) { return store.NewServerserviceStore(ctx, config.FleetDBAPIOptions, logger) } diff --git a/internal/store/yaml.go b/internal/store/yaml.go deleted file mode 100644 index 863bcfce..00000000 --- a/internal/store/yaml.go +++ /dev/null @@ -1,42 +0,0 @@ -package store - -import ( - "context" - "errors" - - "github.com/google/uuid" - "github.com/metal-toolbox/flasher/internal/model" -) - -const ( - InventorySourceYAML = "inventoryStoreYAML" -) - -var ( - ErrYamlSource = errors.New("error in Yaml inventory") -) - -// Yaml type implements the inventory interface -type Yaml struct { - YamlFile string -} - -// NewYamlInventory returns a Yaml type that implements the inventory interface. -func NewYamlInventory(yamlFile string) (Repository, error) { - return &Yaml{YamlFile: yamlFile}, nil -} - -// AssetByID returns device attributes by its identifier -func (c *Yaml) AssetByID(_ context.Context, _ string) (*model.Asset, error) { - return nil, nil -} - -// FirmwareByDeviceVendorModel returns the firmware for the device vendor, model. -func (c *Yaml) FirmwareByDeviceVendorModel(_ context.Context, _, _ string) ([]*model.Firmware, error) { - return nil, nil -} - -// FirmwareSetByID returns a list of firmwares part of a firmware set identified by the given id. -func (c *Yaml) FirmwareSetByID(_ context.Context, _ uuid.UUID) ([]*model.Firmware, error) { - return nil, nil -} diff --git a/internal/worker/outofband.go b/internal/worker/outofband.go index c75c1a12..1852c43b 100644 --- a/internal/worker/outofband.go +++ b/internal/worker/outofband.go @@ -139,26 +139,3 @@ func (h *OobConditionTaskHandler) HandleTask( hLogger.Info("task for device completed") return nil } - -// newTaskFromMsg returns a new task object with the given parameters -func newTaskFromCondition(condition *rctypes.Condition, dryRun, faultInjection bool) (*model.Task, error) { - parameters := &rctypes.FirmwareInstallTaskParameters{} - if err := json.Unmarshal(condition.Parameters, parameters); err != nil { - return nil, errors.Wrap(errInitTask, "Firmware install task parameters error: "+err.Error()) - } - - t, err := model.NewTask(condition.ID, parameters) - if err != nil { - return nil, err - } - - if faultInjection && condition.Fault != nil { - t.Fault = condition.Fault - } - - if dryRun { - t.Parameters.DryRun = true - } - - return &t, nil -} diff --git a/internal/worker/worker_test.go b/internal/worker/worker_test.go deleted file mode 100644 index 32c89dd6..00000000 --- a/internal/worker/worker_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// nolint -package worker - -import ( - "testing" - - "github.com/google/uuid" - "github.com/metal-toolbox/flasher/internal/model" - "github.com/stretchr/testify/assert" - - rctypes "github.com/metal-toolbox/rivets/condition" -) - -func TestNewTaskFromCondition(t *testing.T) { - tests := []struct { - name string - condition *rctypes.Condition - want *model.Task - wantErr bool - }{ - { - "condition parameters parsed into task parameters", - &rctypes.Condition{ - ID: uuid.MustParse("abc81024-f62a-4288-8730-3fab8ccea777"), - Kind: rctypes.FirmwareInstall, - Version: "1", - Parameters: []byte(`{"asset_id":"ede81024-f62a-4288-8730-3fab8cceab78","firmware_set_id":"9d70c28c-5f65-4088-b014-205c54ad4ac7", "force_install": true, "reset_bmc_before_install": true}`), - }, - func() *model.Task { - t, _ := model.NewTask( - uuid.MustParse("abc81024-f62a-4288-8730-3fab8ccea777"), - &rctypes.FirmwareInstallTaskParameters{ - AssetID: uuid.MustParse("ede81024-f62a-4288-8730-3fab8cceab78"), - FirmwareSetID: uuid.MustParse("9d70c28c-5f65-4088-b014-205c54ad4ac7"), - ForceInstall: true, - ResetBMCBeforeInstall: true, - }, - ) - return &t - }(), - false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := newTaskFromCondition(tt.condition, false, false) - if (err != nil) != tt.wantErr { - t.Errorf("newTaskFromCondition() error = %v, wantErr %v", err, tt.wantErr) - return - } - - assert.Equal(t, tt.want.ID, got.ID) - assert.Equal(t, tt.want.State, got.State) - assert.Equal(t, tt.want.Parameters, got.Parameters) - assert.Contains(t, string(got.Status.MustMarshal()), "initialized task") - }) - } -}