Skip to content

Commit

Permalink
update for fablab changes
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Oct 18, 2023
1 parent 7981f0a commit 1a7cf83
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 142 deletions.
5 changes: 3 additions & 2 deletions ziti/util/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ func (edgeTransport *edgeTransport) RoundTrip(r *http.Request) (*http.Response,
}

type ApiErrorPayload interface {
Error() string
GetPayload() *rest_model.APIErrorEnvelope
}

Expand Down Expand Up @@ -573,12 +574,12 @@ func (a RestApiError) Error() string {
if payload := a.ApiErrorPayload.GetPayload(); payload != nil {

if payload.Error == nil {
return fmt.Sprintf("could not read API error, payload.error was nil: %v", a.Error())
return fmt.Sprintf("could not read API error, payload.error was nil: %v", a.ApiErrorPayload.Error())
}
return formatApiError(payload.Error)
}

return fmt.Sprintf("could not read API error, payload was nil: %v", a.Error())
return fmt.Sprintf("could not read API error, payload was nil: %v", a.ApiErrorPayload.Error())
}

func WrapIfApiError(err error) error {
Expand Down
4 changes: 2 additions & 2 deletions zititest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/michaelquigley/pfxlog v0.6.10
github.com/openziti/agent v1.0.15
github.com/openziti/channel/v2 v2.0.101
github.com/openziti/fablab v0.5.16
github.com/openziti/fablab v0.5.20
github.com/openziti/foundation/v2 v2.0.33
github.com/openziti/identity v1.0.64
github.com/openziti/sdk-golang v0.20.122
Expand Down Expand Up @@ -111,7 +111,7 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-tty v0.0.3 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions zititest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOA
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
Expand Down Expand Up @@ -657,8 +657,8 @@ github.com/openziti/dilithium v0.3.3 h1:PLgQ6PMNLSTzCFbX/h98cmudgz/cU6TmjdSv5NAP
github.com/openziti/dilithium v0.3.3/go.mod h1:vsCjI2AU/hon9e+dLhUFbCNGesJDj2ASgkySOcpmvjo=
github.com/openziti/edge-api v0.25.38 h1:aijFEC4pMCi2gR6zL6FYQRkm59SQAwrF0tZS4LZsxi4=
github.com/openziti/edge-api v0.25.38/go.mod h1:5mmcMgqK1MsBb0K8V1CBfGbtRUji5KYdmhJJJkJBMqY=
github.com/openziti/fablab v0.5.16 h1:+tqqDR5Sl4qLT3fSC+Dv1AGZuOeeX87h9LNKa1KJS5Y=
github.com/openziti/fablab v0.5.16/go.mod h1:KiU/NxThNtH9U803Ep0WcSrbov3moZso2oRgIpQq0S0=
github.com/openziti/fablab v0.5.20 h1:7Xo85q2S0QpEQXkizjV/5Sh3FJ3w/W4dy+1puN4K8Gs=
github.com/openziti/fablab v0.5.20/go.mod h1:wKw2t0WrOPwVd7mfshGpxqtslC6ffaBeXI1DryPnko4=
github.com/openziti/foundation/v2 v2.0.33 h1:8CP+fi4KsmzA4jDi54jibwFWWxKpd0rSiplzN9Z0Isw=
github.com/openziti/foundation/v2 v2.0.33/go.mod h1:dWR0g3NOka3uKz9MgUHq6dmuRLmSvunkyeuOXEW/5qU=
github.com/openziti/identity v1.0.64 h1:HwALRY1J/rNNcIAlr1OwCwTHU/rlMRaUi5TXAfZotjw=
Expand Down
4 changes: 1 addition & 3 deletions zititest/models/simple/actions/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (a *startAction) bind(m *model.Model) model.Action {
workflow.AddAction(component.StartInParallel(models.EdgeRouterTag, 25))
workflow.AddAction(component.StartInParallel(".iperf", 5))

workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(component.StartInParallel(".sdk-app", 5))

Expand All @@ -51,5 +50,4 @@ func (a *startAction) bind(m *model.Model) model.Action {
return workflow
}

type startAction struct {
}
type startAction struct{}
6 changes: 2 additions & 4 deletions zititest/tests/echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package tests
import (
"fmt"
"github.com/google/uuid"
"github.com/openziti/fablab/kernel/lib"
"github.com/stretchr/testify/require"
"strings"
"testing"
Expand All @@ -37,13 +36,12 @@ func TestSdkEcho(t *testing.T) {
}

for _, c := range components {
ssh := lib.NewSshConfigFactory(c.GetHost())
remoteConfigFile := "/home/ubuntu/fablab/cfg/" + c.Id + ".json"

echoClientCmd := fmt.Sprintf(`echo "%s" | /home/%s/fablab/bin/ziti demo zcat --identity %s ziti:echo 2>&1`,
string(data), ssh.User(), remoteConfigFile)
string(data), c.GetHost().GetSshUser(), remoteConfigFile)

output, err := lib.RemoteExec(ssh, echoClientCmd)
output, err := c.GetHost().ExecLogged(echoClientCmd)
t.Logf("test output:\n%s", output)
req.NoError(err)
//trim the newline ssh added
Expand Down
3 changes: 2 additions & 1 deletion zititest/tests/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tests
import (
"fmt"
"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/libssh"
"github.com/openziti/fablab/kernel/model"
"github.com/stretchr/testify/require"
"testing"
Expand Down Expand Up @@ -138,7 +139,7 @@ func testFileDownload(t *testing.T, hostSelector string, client httpClient, host
}

timeout := timeouts[fileSize]
o, err := lib.RemoteExecAllWithTimeout(sshConfigFactory, timeout, cmd)
o, err := libssh.RemoteExecAllWithTimeout(sshConfigFactory, timeout, cmd)
if hostType == "zet" && err != nil {
t.Skipf("zet hosted file transfer failed [%v]", err.Error())
return
Expand Down
3 changes: 2 additions & 1 deletion zititest/tests/iperf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tests
import (
"fmt"
"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/libssh"
"github.com/openziti/fablab/kernel/model"
"github.com/stretchr/testify/require"
"testing"
Expand Down Expand Up @@ -98,7 +99,7 @@ func testIPerf(t *testing.T, hostSelector string, hostType string, encrypted boo
cmd := fmt.Sprintf(`set -o pipefail; iperf3 -c %s -P 1 -t 10 %s`, addr, extraOptions)

sshConfigFactory := lib.NewSshConfigFactory(host)
o, err := lib.RemoteExecAllWithTimeout(sshConfigFactory, 20*time.Second, cmd)
o, err := libssh.RemoteExecAllWithTimeout(sshConfigFactory, 20*time.Second, cmd)
if hostType == "zet" && err != nil {
t.Skipf("zet hosted iperf test failed [%v]", err.Error())
return
Expand Down
3 changes: 2 additions & 1 deletion zititest/tests/scp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"github.com/google/uuid"
"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/libssh"
"github.com/openziti/fablab/kernel/model"
"github.com/stretchr/testify/require"
"testing"
Expand Down Expand Up @@ -112,7 +113,7 @@ func testScp(t *testing.T, hostSelector string, hostType string, encrypted bool)

sshConfigFactory := lib.NewSshConfigFactory(host)

o, err := lib.RemoteExecAllWithTimeout(sshConfigFactory, 50*time.Second, test.cmd)
o, err := libssh.RemoteExecAllWithTimeout(sshConfigFactory, 50*time.Second, test.cmd)
if hostType == "zet" && err != nil {
t.Skipf("zet hosted ssh failed [%v]", err.Error())
} else if hostSelector == "zet" && err != nil {
Expand Down
8 changes: 4 additions & 4 deletions zititest/zitilab/actions/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package zitilib_actions

import (
"fmt"
"github.com/openziti/fablab/kernel/libssh"

"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/model"
"github.com/sirupsen/logrus"
)
Expand All @@ -27,12 +27,12 @@ func StartConsul(hostSpec, consulServer, configDir, dataPath, logFile string) mo
}

func (cs *consulStart) Execute(run model.Run) error {
return run.GetModel().ForEachHost(cs.hostSpec, 24, func(c *model.Host) error {
ssh := lib.NewSshConfigFactory(c)
return run.GetModel().ForEachHost(cs.hostSpec, 24, func(host *model.Host) error {
ssh := host.NewSshConfigFactory()

cmd := fmt.Sprintf("screen -d -m nohup consul agent -join %s -config-dir %s -data-dir %s -log-file %s 2>&1 &", cs.consulServer, cs.configDir, cs.dataPath, cs.logFile)

if output, err := lib.RemoteExec(ssh, cmd); err != nil {
if output, err := libssh.RemoteExec(ssh, cmd); err != nil {
logrus.Errorf("error starting consul service [%s] (%v)", output, err)
return err
}
Expand Down
3 changes: 1 addition & 2 deletions zititest/zitilab/actions/edge/ctrl_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package edge

import (
"fmt"
"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/lib/actions/component"
"github.com/openziti/fablab/kernel/lib/actions/host"
"github.com/openziti/fablab/kernel/model"
Expand Down Expand Up @@ -44,7 +43,7 @@ func (init *raftInit) Execute(run model.Run) error {
}

for _, c := range m.SelectComponents(init.componentSpec) {
sshConfigFactory := lib.NewSshConfigFactory(c.GetHost())
sshConfigFactory := c.GetHost().NewSshConfigFactory()

tmpl := "set -o pipefail; /home/%s/fablab/bin/ziti agent controller init %s %s default.admin 2>&1 | tee logs/controller.edge.init.log"
if err := host.Exec(c.GetHost(), fmt.Sprintf(tmpl, sshConfigFactory.User(), username, password)).Execute(run); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions zititest/zitilab/actions/edge/init_identities.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edge

import (
"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/libssh"
"github.com/openziti/fablab/kernel/model"
zitilib_actions "github.com/openziti/ziti/zititest/zitilab/actions"
"github.com/openziti/ziti/zititest/zitilab/cli"
Expand All @@ -27,7 +27,7 @@ func (action *initIdentitiesAction) Execute(run model.Run) error {
}

func (action *initIdentitiesAction) createAndEnrollIdentity(run model.Run, c *model.Component) error {
ssh := lib.NewSshConfigFactory(c.GetHost())
ssh := c.GetHost().NewSshConfigFactory()

jwtFileName := filepath.Join(run.GetTmpDir(), c.Id+".jwt")

Expand All @@ -48,7 +48,7 @@ func (action *initIdentitiesAction) createAndEnrollIdentity(run model.Run, c *mo
}

remoteConfigFile := "/home/ubuntu/fablab/cfg/" + c.Id + ".json"
return lib.SendFile(ssh, configFileName, remoteConfigFile)
return libssh.SendFile(ssh, configFileName, remoteConfigFile)
}

type initIdentitiesAction struct {
Expand Down
3 changes: 1 addition & 2 deletions zititest/zitilab/actions/edge/raft_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package edge

import (
"fmt"
"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/lib/actions/host"
"github.com/openziti/fablab/kernel/model"
"github.com/pkg/errors"
Expand All @@ -24,7 +23,7 @@ func (self *raftJoin) Execute(run model.Run) error {
return errors.Errorf("no controllers found with spec '%v'", self.componentSpec)
}
primary := ctrls[0]
sshConfigFactory := lib.NewSshConfigFactory(primary.GetHost())
sshConfigFactory := primary.GetHost().NewSshConfigFactory()
for _, c := range ctrls[1:] {
tmpl := "/home/%s/fablab/bin/ziti agent cluster add %v --id %v"
if err := host.Exec(primary.GetHost(), fmt.Sprintf(tmpl, sshConfigFactory.User(), "tls:"+c.Host.PublicIp+":6262", c.Id)).Execute(run); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions zititest/zitilab/actions/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package zitilib_actions

import (
"fmt"
"github.com/openziti/fablab/kernel/libssh"
"os"
"path/filepath"

"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/model"
"github.com/openziti/foundation/v2/info"
"github.com/sirupsen/logrus"
Expand All @@ -39,7 +39,7 @@ func (self *logs) Execute(run model.Run) error {
snapshot := fmt.Sprintf("%d", info.NowInMilliseconds())
for rn, r := range run.GetModel().Regions {
for hn, h := range r.Hosts {
ssh := lib.NewSshConfigFactory(h)
ssh := h.NewSshConfigFactory()
if err := self.forHost(snapshot, rn, hn, ssh); err != nil {
return fmt.Errorf("error retrieving logs for [%s/%s] (%w)", rn, hn, err)
}
Expand All @@ -48,14 +48,14 @@ func (self *logs) Execute(run model.Run) error {
return nil
}

func (self *logs) forHost(snapshot, rn, hn string, ssh lib.SshConfigFactory) error {
func (self *logs) forHost(snapshot, rn, hn string, ssh libssh.SshConfigFactory) error {
path := filepath.Join(model.AllocateForensicScenario(snapshot, "logs"), rn, hn)
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return fmt.Errorf("error creating logs path [%s] for host [%s/%s] (%w)", path, rn, hn, err)
}
logrus.Infof("=> [%s]", path)

fis, err := lib.RemoteFileList(ssh, ".")
fis, err := libssh.RemoteFileList(ssh, ".")
if err != nil {
return fmt.Errorf("error retrieving home directory for host [%s/%s] (%w)", rn, hn, err)
}
Expand All @@ -76,8 +76,8 @@ func (self *logs) forHost(snapshot, rn, hn string, ssh lib.SshConfigFactory) err
return nil
}

func (self *logs) forHostDir(localPath, remotePath string, ssh lib.SshConfigFactory) error {
fis, err := lib.RemoteFileList(ssh, remotePath)
func (self *logs) forHostDir(localPath, remotePath string, ssh libssh.SshConfigFactory) error {
fis, err := libssh.RemoteFileList(ssh, remotePath)
if err != nil {
return err
}
Expand All @@ -97,7 +97,7 @@ func (self *logs) forHostDir(localPath, remotePath string, ssh lib.SshConfigFact
paths = append(paths, filepath.Join(remotePath, fi.Name()))
}
}
if err := lib.RetrieveRemoteFiles(ssh, localPath, paths...); err != nil {
if err := libssh.RetrieveRemoteFiles(ssh, localPath, paths...); err != nil {
return fmt.Errorf("error retrieving from [%s] (%w)", localPath, err)
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions zititest/zitilab/actions/metricbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package zitilib_actions

import (
"fmt"
"github.com/openziti/fablab/kernel/libssh"

"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/model"
"github.com/sirupsen/logrus"
)
Expand All @@ -25,12 +25,12 @@ func StartMetricbeat(hostSpec, configPath, dataPath, logPath string) model.Actio
}

func (mbs *metricbeatStart) Execute(run model.Run) error {
return run.GetModel().ForEachHost(mbs.hostSpec, 24, func(c *model.Host) error {
ssh := lib.NewSshConfigFactory(c)
return run.GetModel().ForEachHost(mbs.hostSpec, 24, func(host *model.Host) error {
ssh := host.NewSshConfigFactory()

cmd := fmt.Sprintf("screen -d -m nohup metricbeat --path.config %s --path.data %s --path.logs %s 2>&1 &", mbs.configPath, mbs.dataPath, mbs.logPath)

if output, err := lib.RemoteExec(ssh, cmd); err != nil {
if output, err := libssh.RemoteExec(ssh, cmd); err != nil {
logrus.Errorf("error starting metricbeat service [%s] (%v)", output, err)
return err
}
Expand Down
26 changes: 13 additions & 13 deletions zititest/zitilab/component_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package zitilab

import (
"fmt"
"github.com/openziti/fablab/kernel/lib"
"github.com/openziti/fablab/kernel/lib/actions/host"
"github.com/openziti/fablab/kernel/model"
zitilib_actions "github.com/openziti/ziti/zititest/zitilab/actions"
"github.com/sirupsen/logrus"
Expand All @@ -42,11 +40,11 @@ func startZitiComponent(c *model.Component, zitiType string, version string, con
binaryName += "-" + version
}

factory := lib.NewSshConfigFactory(c.GetHost())
user := c.GetHost().GetSshUser()

binaryPath := fmt.Sprintf("/home/%s/fablab/bin/%s", factory.User(), binaryName)
configPath := fmt.Sprintf("/home/%s/fablab/cfg/%s", factory.User(), configName)
logsPath := fmt.Sprintf("/home/%s/logs/%s.log", factory.User(), c.Id)
binaryPath := fmt.Sprintf("/home/%s/fablab/bin/%s", user, binaryName)
configPath := fmt.Sprintf("/home/%s/fablab/cfg/%s", user, configName)
logsPath := fmt.Sprintf("/home/%s/logs/%s.log", user, c.Id)

useSudo := ""
if zitiType == "tunnel" || c.HasTag("tunneler") {
Expand All @@ -56,7 +54,7 @@ func startZitiComponent(c *model.Component, zitiType string, version string, con
serviceCmd := fmt.Sprintf("nohup %s %s %s run --log-formatter pfxlog %s --cli-agent-alias %s > %s 2>&1 &",
useSudo, binaryPath, zitiType, configPath, c.Id, logsPath)

value, err := lib.RemoteExec(factory, serviceCmd)
value, err := c.GetHost().ExecLogged(serviceCmd)
if err != nil {
return err
}
Expand All @@ -80,23 +78,25 @@ func reEnrollIdentity(run model.Run, c *model.Component, binaryName string, conf
return err
}

ssh := lib.NewSshConfigFactory(c.GetHost())
if err := zitilib_actions.EdgeExec(run.GetModel(), "delete", "enrollment", "where", fmt.Sprintf("identity=\"%v\"", c.Id)); err != nil {
return err
}

jwtFileName := filepath.Join(model.ConfigBuild(), c.Id+".jwt")

args := []string{"create", "enrollment", "ott", c.Id, "-j", "--jwt-output-file", jwtFileName}
args := []string{"create", "enrollment", "ott", "--jwt-output-file", jwtFileName, "--", c.Id}

if err := zitilib_actions.EdgeExec(c.GetModel(), args...); err != nil {
return err
}

remoteJwt := "/home/ubuntu/fablab/cfg/" + c.Id + ".jwt"
if err := lib.SendFile(ssh, jwtFileName, remoteJwt); err != nil {
if err := c.GetHost().SendFile(jwtFileName, remoteJwt); err != nil {
return err
}

tmpl := "set -o pipefail; /home/ubuntu/fablab/bin/%s edge enroll /home/ubuntu/fablab/cfg/%s -j %s 2>&1 | tee /home/ubuntu/logs/%s.router.enroll.log "
cmd := fmt.Sprintf(tmpl, binaryName, configName, remoteJwt, c.Id)
tmpl := "set -o pipefail; /home/ubuntu/fablab/bin/%s edge enroll %s 2>&1 | tee /home/ubuntu/logs/%s.identity.enroll.log "
cmd := fmt.Sprintf(tmpl, binaryName, remoteJwt, c.Id)

return host.Exec(c.GetHost(), cmd).Execute(run)
return c.GetHost().ExecLogOnlyOnError(cmd)
}
Loading

0 comments on commit 1a7cf83

Please sign in to comment.