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

Implements all of the Alloy components #4

Merged
merged 31 commits into from
Aug 2, 2022
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
13332d2
docs: Add README, development notes
joelrebel Jul 15, 2022
64b16d1
examples: add sample config, image assets
joelrebel Jul 15, 2022
a6ab5db
Update Makefile, CI linter, pull request template
joelrebel Jul 15, 2022
121a3c5
internal/model: define Asset, AssetDevice, Config structs
joelrebel Jul 15, 2022
ae68e72
app: App holds attributes to initialize Alloy
joelrebel Jul 15, 2022
ac2ef68
internal/asset: Asset getter interface and csv implemention
joelrebel Jul 15, 2022
bf58f74
internal/fixtures: add emapi getter mock implementation
joelrebel Jul 15, 2022
dcf769b
internal/asset/emapi: emapi asset getter implementation
joelrebel Jul 15, 2022
3338b8c
internal/collect: define interface, errors
joelrebel Jul 15, 2022
fc9a012
internal/fixtures: add device mock data, returned by a collector
joelrebel Jul 15, 2022
c0df8f4
internal/fixtures: add out of band fixture data for tests
joelrebel Jul 15, 2022
04e4e2e
internal/fixtures: add inband fixture data for tests
joelrebel Jul 15, 2022
fcef249
internal/collect/inband: implement inband inventory collector
joelrebel Jul 15, 2022
c0c8837
internal/collect/inband: implement out of band inventory collector
joelrebel Jul 15, 2022
556df08
internal/fixtures: add asset getter mock implementation
joelrebel Jul 15, 2022
f50c86a
internal/publish: define interface and implement stdout publisher
joelrebel Jul 15, 2022
9f250c1
internal/publisher: implement hollow publisher
joelrebel Jul 15, 2022
89c73f7
internal/fixtures: add hollow service mock data
joelrebel Jul 15, 2022
79474ef
cmd: cli commands and inband cli command
joelrebel Jul 15, 2022
492af47
cmd/outofband: implement outofband cli command
joelrebel Jul 15, 2022
9c2f1ff
purge bin file
joelrebel Jul 15, 2022
d20a58f
docs: a directory for docs and related files
joelrebel Jul 25, 2022
aa65471
.gitignore: ignore alloy binary
joelrebel Jul 25, 2022
b548170
cmd/outofband: follow camelcase convention for struct name
joelrebel Jul 25, 2022
f265661
replace all references and variable names from hollow to serverService
joelrebel Jul 25, 2022
0d9ff9c
clear unused global vars and add proper method comments
joelrebel Jul 25, 2022
8897e98
go: update to upstream bmclib v2 release; switch to Go 1.18
joelrebel Jul 26, 2022
7e7d5b2
CI: update dockerfile for alloy inband build
joelrebel Jul 26, 2022
e2bde96
ci: disable CODEQL scanning until repository is public
joelrebel Jul 26, 2022
322c79c
ci: build alloy docker image as alloy-inband
joelrebel Jul 26, 2022
010af01
README: stick with short flag options in the examples
joelrebel Jul 26, 2022
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
Prev Previous commit
Next Next commit
internal/collect/inband: implement inband inventory collector
joelrebel committed Jul 15, 2022

Verified

This commit was signed with the committer’s verified signature.
ProgHaj Magnus Tullberg
commit fcef2490fcf9f770d3e3a1438aa96ee2d4fe1cde
67 changes: 67 additions & 0 deletions internal/collect/inband.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package collect

import (
"context"
"os"

"github.com/metal-toolbox/alloy/internal/app"
"github.com/metal-toolbox/alloy/internal/model"
"github.com/metal-toolbox/ironlib"
ironlibm "github.com/metal-toolbox/ironlib/model"
"github.com/sirupsen/logrus"
)

// Inband collector collects hardware, firmware inventory inband
type InbandCollector struct {
deviceManager ironlibm.DeviceManager
logger *logrus.Entry
collectorCh chan<- *model.AssetDevice
termCh <-chan os.Signal
mock bool
}

// New returns an inband inventory collector
func NewInbandCollector(alloy *app.App) Collector {
logger := app.NewLogrusEntryFromLogger(logrus.Fields{"component": "collector.inband"}, alloy.Logger)

return &InbandCollector{
logger: logger,
collectorCh: alloy.CollectorCh,
termCh: alloy.TermCh,
}
}

func (i *InbandCollector) SetMockGetter(getter interface{}) {
i.deviceManager = getter.(ironlibm.DeviceManager)
i.mock = true
}

// Inventory implements the Collector interface to collect inventory inband
func (i *InbandCollector) Inventory(ctx context.Context) error {
if !i.mock {
var err error

i.deviceManager, err = ironlib.New(i.logger.Logger)
if err != nil {
return err
}
}

defer close(i.collectorCh)

for {
select {
case <-ctx.Done():
return nil
default:
device, err := i.deviceManager.GetInventory(ctx)
if err != nil {
return err
}

i.collectorCh <- &model.AssetDevice{ID: "", Device: device}

return nil
}
}
}
61 changes: 61 additions & 0 deletions internal/collect/inband_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package collect

import (
"context"
"testing"
"time"

"github.com/metal-toolbox/alloy/internal/app"
"github.com/metal-toolbox/alloy/internal/fixtures"
"gotest.tools/assert"

"github.com/metal-toolbox/alloy/internal/model"
)

func Test_InbandInventory(t *testing.T) {
// init mock ironlib with test fixture
mockIronlib := fixtures.NewMockIronlib()
mockIronlib.SetMockDevice(fixtures.CopyDevice(fixtures.E3C246D4INL))

// init alloy app
alloy, err := app.New(context.TODO(), app.KindInband, "", model.LogLevelTrace)
if err != nil {
t.Fatal(err)
}

// init mock inband inventory collector
collector := NewInbandCollector(alloy)
collector.SetMockGetter(mockIronlib)

var got *model.AssetDevice

// background routine to collect device inventory objects sent from the collector
go func(t *testing.T) {
t.Helper()

timeout := time.NewTicker(time.Second * 2).C

var ok bool

Loop:
for {
select {
case got, ok = <-alloy.CollectorCh:
if !ok {
continue
}
break Loop
case <-timeout:
break Loop
}
}
}(t)

// collect inventory
err = collector.Inventory(context.TODO())
if err != nil {
t.Fatal(err)
}

assert.DeepEqual(t, &model.AssetDevice{Device: fixtures.E3C246D4INL}, got)
}