Skip to content

Commit

Permalink
test: run test inside eos
Browse files Browse the repository at this point in the history
Signed-off-by: Rodney Osodo <[email protected]>
  • Loading branch information
rodneyosodo committed Aug 2, 2024
1 parent e4be311 commit 7da4182
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
5 changes: 1 addition & 4 deletions agent/algorithm/binary/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@ var _ algorithm.Algorithm = (*binary)(nil)

type binary struct {
algoFile string
datasets []string
logger *slog.Logger
stderr io.Writer
stdout io.Writer
}

func NewAlgorithm(logger *slog.Logger, eventsSvc events.Service, algoFile string) algorithm.Algorithm {
return &binary{
algoFile: algoFile,
logger: logger,
stderr: &algorithm.Stderr{Logger: logger, EventSvc: eventsSvc},
stdout: &algorithm.Stdout{Logger: logger},
}
}

func (b *binary) Run() error {
cmd := exec.Command(b.algoFile, b.datasets...)
cmd := exec.Command(b.algoFile, algorithm.DatasetsDir)
cmd.Stderr = b.stderr
cmd.Stdout = b.stdout

Expand Down
15 changes: 5 additions & 10 deletions agent/algorithm/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ var _ algorithm.Algorithm = (*python)(nil)

type python struct {
algoFile string
datasets []string
logger *slog.Logger
stderr io.Writer
stdout io.Writer
runtime string
Expand All @@ -44,7 +42,6 @@ type python struct {
func NewAlgorithm(logger *slog.Logger, eventsSvc events.Service, runtime, requirementsFile, algoFile string) algorithm.Algorithm {
p := &python{
algoFile: algoFile,
logger: logger,
stderr: &algorithm.Stderr{Logger: logger, EventSvc: eventsSvc},
stdout: &algorithm.Stdout{Logger: logger},
requirementsFile: requirementsFile,
Expand Down Expand Up @@ -77,13 +74,7 @@ func (p *python) Run() error {
}
}

defer func() {
if err := os.RemoveAll(venvPath); err != nil {
p.logger.Error("error removing virtual environment", slog.Any("error", err))
}
}()

args := append([]string{p.algoFile}, p.datasets...)
args := []string{p.algoFile, algorithm.DatasetsDir}
cmd := exec.Command(pythonPath, args...)
cmd.Stderr = p.stderr
cmd.Stdout = p.stdout
Expand All @@ -96,5 +87,9 @@ func (p *python) Run() error {
return fmt.Errorf("algorithm execution error: %v", err)
}

if err := os.RemoveAll(venvPath); err != nil {
return fmt.Errorf("error removing virtual environment: %v", err)
}

return nil
}
6 changes: 2 additions & 4 deletions agent/algorithm/wasm/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,22 @@ var _ algorithm.Algorithm = (*wasm)(nil)

type wasm struct {
algoFile string
datasets []string
logger *slog.Logger
stderr io.Writer
stdout io.Writer
}

func NewAlgorithm(logger *slog.Logger, eventsSvc events.Service, algoFile string) algorithm.Algorithm {
return &wasm{
algoFile: algoFile,
logger: logger,
stderr: &algorithm.Stderr{Logger: logger, EventSvc: eventsSvc},
stdout: &algorithm.Stdout{Logger: logger},
}
}

func (w *wasm) Run() error {
args := append(mapDirOption, w.algoFile)
args = append(args, w.datasets...)
args = append(args, algorithm.DatasetsDir)

cmd := exec.Command(wasmRuntime, args...)
cmd.Stderr = w.stderr
cmd.Stdout = w.stdout
Expand Down
27 changes: 16 additions & 11 deletions agent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,23 @@ func (as *agentService) Algo(ctx context.Context, algo Algorithm) error {
case string(algorithm.AlgoTypeBin):
as.algorithm = binary.NewAlgorithm(as.sm.logger, as.eventSvc, f.Name())
case string(algorithm.AlgoTypePython):
fr, err := os.CreateTemp("", "requirements.txt")
if err != nil {
return fmt.Errorf("error creating requirments file: %v", err)
}

if _, err := fr.Write(algo.Requirements); err != nil {
return fmt.Errorf("error writing requirements to file: %v", err)
}
if err := fr.Close(); err != nil {
return fmt.Errorf("error closing file: %v", err)
var requirementsFile string
if len(algo.Requirements) > 0 {
fr, err := os.CreateTemp("", "requirements.txt")
if err != nil {
return fmt.Errorf("error creating requirments file: %v", err)
}

if _, err := fr.Write(algo.Requirements); err != nil {
return fmt.Errorf("error writing requirements to file: %v", err)
}
if err := fr.Close(); err != nil {
return fmt.Errorf("error closing file: %v", err)
}
requirementsFile = fr.Name()
}
runtime := python.PythonRunTimeFromContext(ctx)
as.algorithm = python.NewAlgorithm(as.sm.logger, as.eventSvc, runtime, fr.Name(), f.Name())
as.algorithm = python.NewAlgorithm(as.sm.logger, as.eventSvc, runtime, requirementsFile, f.Name())
case string(algorithm.AlgoTypeWasm):
as.algorithm = wasm.NewAlgorithm(as.sm.logger, as.eventSvc, f.Name())
}
Expand Down Expand Up @@ -245,6 +249,7 @@ func (as *agentService) runComputation() {
as.publishEvent("failed", json.RawMessage{})()
return
}

defer func() {
if err := os.RemoveAll(algorithm.ResultsDir); err != nil {
as.sm.logger.Warn(fmt.Sprintf("error removing results directory and its contents: %s", err.Error()))
Expand Down
4 changes: 2 additions & 2 deletions hal/linux/package/agent/agent.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
################################################################################

AGENT_VERSION = main
AGENT_SITE = $(call github,ultravioletrs,cocos,$(AGENT_VERSION))
AGENT_VERSION = filesystem
AGENT_SITE = $(call github,rodneyosodo,cocos,$(AGENT_VERSION))

define AGENT_BUILD_CMDS
$(MAKE) -C $(@D) agent
Expand Down

0 comments on commit 7da4182

Please sign in to comment.