mirror of
https://github.com/compute-blade-community/compute-blade-agent.git
synced 2026-04-21 17:45:43 +02:00
feat(bladectl)!: add more bladectl commands (#91)
This PR introduces a comprehensive set of new subcommands to bladectl, expanding its capabilities for querying and managing compute blade state. It also includes an internal refactor to simplify interface management across the gRPC API.
* `get`
* `fan`: Returns current fan speed.
* `identify`: Indicates whether the identify mode is active.
* `stealth`: Shows if stealth mode is currently enabled.
* `status`: Prints a full blade status report.
* `temperature`: Retrieves current SoC temperature.
* `critical`: Shows whether critical mode is active.
* `power`: Reports the current power source (e.g., PoE+ or USB).
* `set`
* `stealth`: Enables stealth mode.
* `remove`
* `stealth`: Disables stealth mode.
* `describe`
* `fan`: Outputs the current fan curve configuration.
* `monitor`: plot some charts about the state of the compute-blade-agent
* **gRPC API refactor**: The gRPC service definitions previously located in `internal/api` have been folded into `internal/agent`. This eliminates redundant interface declarations and ensures that all ComputeBladeAgent implementations are directly compatible with the gRPC API.
This reduces duplication and improves long-term maintainability and clarity of the interface contract.
```bash
bladectl set fan --percent 90 --blade 1 --blade 2
bladectl unset identify --blade 1 --blade 2 --blade 3 --blade 4
bladectl set stealth --blade 1 --blade 2 --blade 3 --blade 4
bladectl get status --blade 1 --blade 2 --blade 3 --blade 4
┌───────┬─────────────┬────────────────────┬───────────────┬──────────────┬──────────┬───────────────┬──────────────┐
│ BLADE │ TEMPERATURE │ FAN SPEED OVERRIDE │ FAN SPEED │ STEALTH MODE │ IDENTIFY │ CRITICAL MODE │ POWER STATUS │
├───────┼─────────────┼────────────────────┼───────────────┼──────────────┼──────────┼───────────────┼──────────────┤
│ 1 │ 50°C │ 90% │ 5825 RPM(90%) │ Active │ Off │ Off │ poe+ │
│ 2 │ 48°C │ 90% │ 5825 RPM(90%) │ Active │ Off │ Off │ poe+ │
│ 3 │ 49°C │ Not set │ 4643 RPM(56%) │ Active │ Off │ Off │ poe+ │
│ 4 │ 49°C │ Not set │ 4774 RPM(58%) │ Active │ Off │ Off │ poe+ │
└───────┴─────────────┴────────────────────┴───────────────┴──────────────┴──────────┴───────────────┴──────────────┘
bladectl rm stealth --blade 1 --blade 2 --blade 3 --blade 4
bladectl rm fan --blade 1 --blade 2 --blade 3 --blade 4
bladectl get status --blade 1 --blade 2 --blade 3 --blade 4
┌───────┬─────────────┬────────────────────┬───────────────┬──────────────┬──────────┬───────────────┬──────────────┐
│ BLADE │ TEMPERATURE │ FAN SPEED OVERRIDE │ FAN SPEED │ STEALTH MODE │ IDENTIFY │ CRITICAL MODE │ POWER STATUS │
├───────┼─────────────┼────────────────────┼───────────────┼──────────────┼──────────┼───────────────┼──────────────┤
│ 1 │ 51°C │ Not set │ 5177 RPM(66%) │ Off │ Off │ Off │ poe+ │
│ 2 │ 49°C │ Not set │ 5177 RPM(58%) │ Off │ Off │ Off │ poe+ │
│ 3 │ 50°C │ Not set │ 4659 RPM(60%) │ Off │ Off │ Off │ poe+ │
│ 4 │ 48°C │ Not set │ 4659 RPM(54%) │ Off │ Off │ Off │ poe+ │
└───────┴─────────────┴────────────────────┴───────────────┴──────────────┴──────────┴───────────────┴──────────────┘
```
when having multiple compute-blades in your bladeconfig:
```yaml
blades:
- name: 1
blade:
server: blade-pi1:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
- name: 2
blade:
server: blade-pi2:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
- name: 3
blade:
server: blade-pi3:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
- name: 4
blade:
server: blade-pi4:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
- name: 4
blade:
server: blade-pi4:8081
cert:
certificate-authority-data: <redacted>
client-certificate-data: <redacted>
client-key-data: <redacted>
current-blade: 1
```
Fixes #4, #9 (partially), should help with #5
* test: improve unit-testing
* fix: pin github.com/warthog618/gpiod
---------
Co-authored-by: Cedric Kienzler <cedric@specht-labs.de>
This commit is contained in:
committed by
Cedric Kienzler
parent
7ec49ce05c
commit
781ded8e43
@@ -20,7 +20,7 @@ type LedEngine interface {
|
||||
|
||||
// ledEngineImpl is the implementation of the LedEngine interface
|
||||
type ledEngineImpl struct {
|
||||
ledIdx uint
|
||||
ledIdx hal.LedIndex
|
||||
restart chan struct{}
|
||||
pattern BlinkPattern
|
||||
hal hal.ComputeBladeHal
|
||||
@@ -101,6 +101,13 @@ func NewSlowBlinkPattern(baseColor led.Color, activeColor led.Color) BlinkPatter
|
||||
}
|
||||
}
|
||||
|
||||
func New(hal hal.ComputeBladeHal, ledIdx hal.LedIndex) LedEngine {
|
||||
return NewLedEngine(Options{
|
||||
Hal: hal,
|
||||
LedIdx: ledIdx,
|
||||
})
|
||||
}
|
||||
|
||||
func NewLedEngine(opts Options) LedEngine {
|
||||
clock := opts.Clock
|
||||
if clock == nil {
|
||||
|
||||
@@ -123,6 +123,17 @@ func TestNewLedEngine(t *testing.T) {
|
||||
assert.NotNil(t, engine)
|
||||
}
|
||||
|
||||
func TestLedEngine_NewLedEngineWithoutClock(t *testing.T) {
|
||||
opts := ledengine.Options{
|
||||
Clock: nil,
|
||||
LedIdx: 0,
|
||||
Hal: &hal.ComputeBladeHalMock{},
|
||||
}
|
||||
|
||||
engine := ledengine.NewLedEngine(opts)
|
||||
assert.NotNil(t, engine)
|
||||
}
|
||||
|
||||
func Test_LedEngine_SetPattern_WhileRunning(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -131,8 +142,8 @@ func Test_LedEngine_SetPattern_WhileRunning(t *testing.T) {
|
||||
clk.On("After", time.Hour).Times(2).Return(clkAfterChan)
|
||||
|
||||
cbMock := hal.ComputeBladeHalMock{}
|
||||
cbMock.On("SetLed", uint(0), led.Color{Green: 0, Blue: 0, Red: 0}).Once().Return(nil)
|
||||
cbMock.On("SetLed", uint(0), led.Color{Green: 0, Blue: 0, Red: 255}).Once().Return(nil)
|
||||
cbMock.On("SetLed", hal.LedTop, led.Color{Green: 0, Blue: 0, Red: 0}).Once().Return(nil)
|
||||
cbMock.On("SetLed", hal.LedTop, led.Color{Green: 0, Blue: 0, Red: 255}).Once().Return(nil)
|
||||
|
||||
opts := ledengine.Options{
|
||||
Hal: &cbMock,
|
||||
@@ -178,7 +189,7 @@ func Test_LedEngine_SetPattern_BeforeRun(t *testing.T) {
|
||||
clk.On("After", time.Hour).Once().Return(clkAfterChan)
|
||||
|
||||
cbMock := hal.ComputeBladeHalMock{}
|
||||
cbMock.On("SetLed", uint(0), led.Color{Green: 0, Blue: 0, Red: 255}).Once().Return(nil)
|
||||
cbMock.On("SetLed", hal.LedTop, led.Color{Green: 0, Blue: 0, Red: 255}).Once().Return(nil)
|
||||
|
||||
opts := ledengine.Options{
|
||||
Hal: &cbMock,
|
||||
@@ -220,8 +231,8 @@ func Test_LedEngine_SetPattern_SetLedFailureInPattern(t *testing.T) {
|
||||
clk.On("After", time.Hour).Once().Return(clkAfterChan)
|
||||
|
||||
cbMock := hal.ComputeBladeHalMock{}
|
||||
call0 := cbMock.On("SetLed", uint(0), led.Color{Green: 0, Blue: 0, Red: 0}).Once().Return(nil)
|
||||
cbMock.On("SetLed", uint(0), led.Color{Green: 0, Blue: 0, Red: 0}).Once().Return(errors.New("failure")).NotBefore(call0)
|
||||
call0 := cbMock.On("SetLed", hal.LedTop, led.Color{Green: 0, Blue: 0, Red: 0}).Once().Return(nil)
|
||||
cbMock.On("SetLed", hal.LedTop, led.Color{Green: 0, Blue: 0, Red: 0}).Once().Return(errors.New("failure")).NotBefore(call0)
|
||||
|
||||
opts := ledengine.Options{
|
||||
Hal: &cbMock,
|
||||
@@ -254,3 +265,29 @@ func Test_LedEngine_SetPattern_SetLedFailureInPattern(t *testing.T) {
|
||||
clk.AssertExpectations(t)
|
||||
cbMock.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func Test_LedEngine_SetPattern_NoDelay(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
clk := util.MockClock{}
|
||||
clkAfterChan := make(chan time.Time)
|
||||
clk.On("After", time.Hour).Once().Return(clkAfterChan)
|
||||
|
||||
cbMock := hal.ComputeBladeHalMock{}
|
||||
cbMock.On("SetLed", hal.LedTop, led.Color{Green: 0, Blue: 0, Red: 255}).Once().Return(nil)
|
||||
|
||||
opts := ledengine.Options{
|
||||
Hal: &cbMock,
|
||||
Clock: &clk,
|
||||
LedIdx: 0,
|
||||
}
|
||||
|
||||
engine := ledengine.NewLedEngine(opts)
|
||||
invalidPattern := ledengine.NewStaticPattern(led.Color{Red: 255})
|
||||
invalidPattern.Delays = []time.Duration{}
|
||||
// We want to change the pattern BEFORE the engine is started
|
||||
t.Log("Setting pattern")
|
||||
err := engine.SetPattern(invalidPattern)
|
||||
assert.Error(t, err)
|
||||
assert.ErrorContains(t, err, "pattern must have at least one delay")
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
// Options are the options for the LedEngine
|
||||
type Options struct {
|
||||
// LedIdx is the index of the LED to control
|
||||
LedIdx uint
|
||||
LedIdx hal.LedIndex
|
||||
// Hal is the computeblade hardware abstraction layer
|
||||
Hal hal.ComputeBladeHal
|
||||
// Clock is the clock used for timing
|
||||
|
||||
Reference in New Issue
Block a user