Skip to content

Commit

Permalink
Make test labels better. Fix ZET scp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Oct 17, 2023
1 parent ba09965 commit 400f4ce
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 231 deletions.
24 changes: 2 additions & 22 deletions zititest/models/simple/actions/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ import (
"github.com/openziti/ziti/zititest/zitilab/models"
)

func NewStartAction(metricbeat MetricbeatConfig, consul ConsulConfig) model.ActionBinder {
action := &startAction{
Metricbeat: metricbeat,
Consul: consul,
}
func NewStartAction() model.ActionBinder {
action := &startAction{}
return action.bind
}

Expand All @@ -44,8 +41,6 @@ func (a *startAction) bind(m *model.Model) model.Action {
workflow.AddAction(component.StartInParallel(".iperf", 5))

workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(zitilib_actions.StartMetricbeat("*", a.Metricbeat.ConfigPath, a.Metricbeat.DataPath, a.Metricbeat.LogPath))
workflow.AddAction(zitilib_actions.StartConsul("*", a.Consul.ServerAddr, a.Consul.ConfigDir, a.Consul.DataPath, a.Consul.LogPath))
workflow.AddAction(semaphore.Sleep(2 * time.Second))
workflow.AddAction(component.StartInParallel(".sdk-app", 5))

Expand All @@ -57,19 +52,4 @@ func (a *startAction) bind(m *model.Model) model.Action {
}

type startAction struct {
Metricbeat MetricbeatConfig
Consul ConsulConfig
}

type MetricbeatConfig struct {
ConfigPath string
DataPath string
LogPath string
}

type ConsulConfig struct {
ConfigDir string
ServerAddr string
DataPath string
LogPath string
}
24 changes: 0 additions & 24 deletions zititest/models/simple/configs/consul.hcl

This file was deleted.

8 changes: 0 additions & 8 deletions zititest/models/simple/configs/elasticsearch.repo

This file was deleted.

53 changes: 0 additions & 53 deletions zititest/models/simple/configs/metricbeat.yml

This file was deleted.

9 changes: 0 additions & 9 deletions zititest/models/simple/configs/ziti.hcl

This file was deleted.

84 changes: 7 additions & 77 deletions zititest/models/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
"time"
)

const ZitiEdgeTunnelVersion = "v0.21.4"

//go:embed configs
var configResource embed.FS

Expand Down Expand Up @@ -156,7 +158,7 @@ var Model = &model.Model{
"ziti-edge-tunnel-client": {
Scope: model.Scope{Tags: model.Tags{"sdk-app", "client"}},
Type: &zitilab.ZitiEdgeTunnelType{
Version: "v0.21.4",
Version: ZitiEdgeTunnelVersion,
},
},
},
Expand Down Expand Up @@ -206,7 +208,7 @@ var Model = &model.Model{
"ziti-edge-tunnel-host": {
Scope: model.Scope{Tags: model.Tags{"sdk-app", "host", "zet-host"}},
Type: &zitilab.ZitiEdgeTunnelType{
Version: "v0.21.4",
Version: ZitiEdgeTunnelVersion,
},
},
"iperf-server-zet": {
Expand Down Expand Up @@ -235,19 +237,9 @@ var Model = &model.Model{

Actions: model.ActionBinders{
"bootstrap": actions.NewBootstrapAction(),
"start": actions.NewStartAction(actions.MetricbeatConfig{
ConfigPath: "metricbeat",
DataPath: "metricbeat/data",
LogPath: "metricbeat/logs",
},
actions.ConsulConfig{
ServerAddr: os.Getenv("CONSUL_ENDPOINT"),
ConfigDir: "consul",
DataPath: "consul/data",
LogPath: "consul/log.out",
}),
"stop": model.Bind(component.StopInParallel("*", 15)),
"login": model.Bind(edge.Login("#ctrl1")),
"start": actions.NewStartAction(),
"stop": model.Bind(component.StopInParallel("*", 15)),
"login": model.Bind(edge.Login("#ctrl1")),
},

Infrastructure: model.Stages{
Expand All @@ -262,68 +254,6 @@ var Model = &model.Model{

Distribution: model.Stages{
distribution.DistributeSshKey("*"),
distribution.Locations("*", "logs"),
distribution.DistributeDataWithReplaceCallbacks(
"*",
string(getConfigData("metricbeat.yml")),
"metricbeat/metricbeat.yml",
os.FileMode(0644),
map[string]func(*model.Host) string{
"${host}": func(h *model.Host) string {
return os.Getenv("ELASTIC_ENDPOINT")
},
"${user}": func(h *model.Host) string {
return os.Getenv("ELASTIC_USERNAME")
},
"${password}": func(h *model.Host) string {
return os.Getenv("ELASTIC_PASSWORD")
},
"${build_number}": func(h *model.Host) string {
return os.Getenv("BUILD_NUMBER")
},
"${ziti_version}": func(h *model.Host) string {
return h.MustStringVariable("ziti_version")
},
},
),

distribution.DistributeDataWithReplaceCallbacks(
"*",
string(getConfigData("consul.hcl")),
"consul/consul.hcl",
os.FileMode(0644),
map[string]func(*model.Host) string{
"${public_ip}": func(h *model.Host) string {
return h.PublicIp
},
"${encryption_key}": func(h *model.Host) string {
return os.Getenv("CONSUL_ENCRYPTION_KEY")
},
"${build_number}": func(h *model.Host) string {
return os.Getenv("BUILD_NUMBER")
},
"${ziti_version}": func(h *model.Host) string {
return h.MustStringVariable("ziti_version")
},
},
),
distribution.DistributeDataWithReplaceCallbacks(
"#ctrl",
string(getConfigData("ziti.hcl")),
"consul/ziti.hcl",
os.FileMode(0644),
map[string]func(*model.Host) string{
"${build_number}": func(h *model.Host) string {
return os.Getenv("BUILD_NUMBER")
},
"${ziti_version}": func(h *model.Host) string {
return h.MustStringVariable("ziti_version")
},
}),
distribution.DistributeData(
"*",
[]byte(os.Getenv("CONSUL_AGENT_CERT")),
"consul/consul-agent-ca.pem"),
rsync.RsyncStaged(),
},

Expand Down
2 changes: 1 addition & 1 deletion zititest/tests/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func testFileDownload(t *testing.T, hostSelector string, client httpClient, host

success := false

t.Run(fmt.Sprintf("%v-(%s->%s)-%s-%v", client, hostSelector, hostType, fileSize, encDesk), func(t *testing.T) {
t.Run(fmt.Sprintf("%v-(%s<-%s)-%s-%v", client, hostSelector, hostType, fileSize, encDesk), func(t *testing.T) {
host, err := model.GetModel().SelectHost("." + hostSelector + "-client")
req := require.New(t)
req.NoError(err)
Expand Down
77 changes: 40 additions & 37 deletions zititest/tests/scp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ func TestScp(t *testing.T) {
req := require.New(t)
req.False(allZetHostedFailed, "all zet hosted file transfer should not failed, indicates bigger issue")

// TODO: fix once ZET client tests are working
req.True(allZetClientsFailed, "all zet client file transfers should not failed, indicates bigger issue")
req.False(allZetClientsFailed, "all zet client file transfers should not failed, indicates bigger issue")
}

func testScp(t *testing.T, hostSelector string, hostType string, encrypted bool) bool {
Expand All @@ -88,40 +87,44 @@ func testScp(t *testing.T, hostSelector string, hostType string, encrypted bool)

success := false

t.Run(fmt.Sprintf("(%s->%s)-%v", hostSelector, hostType, encDesk), func(t *testing.T) {
if hostSelector == "zet" {
t.Skipf("zet is currently failing as client")
}
host, err := model.GetModel().SelectHost("." + hostSelector + "-client")
req := require.New(t)
req.NoError(err)

nameExtra := ""
if !encrypted {
nameExtra = "-unencrypted"
}

sshConfigFactory := lib.NewSshConfigFactory(host)

cmds := []string{
fmt.Sprintf("scp -o StrictHostKeyChecking=no ssh-%s%s.ziti:./fablab/bin/ziti /tmp/ziti-%s", hostType, nameExtra, uuid.NewString()),
fmt.Sprintf("scp -o StrictHostKeyChecking=no ./fablab/bin/ziti ssh-%s%s.ziti:/tmp/ziti-%s", hostType, nameExtra, uuid.NewString()),
}

o, err := lib.RemoteExecAllWithTimeout(sshConfigFactory, 30*time.Second, cmds...)
if hostType == "zet" && err != nil {
t.Skipf("zet hosted ssh failed [%v]", err.Error())
return
}

if hostSelector == "zet" && err != nil {
t.Skipf("zet client ssh failed [%v]", err.Error())
return
}

t.Log(o)
req.NoError(err)
success = true
})
nameExtra := ""
if !encrypted {
nameExtra = "-unencrypted"
}

tests := []struct {
direction string
cmd string
}{
{
direction: "<-",
cmd: fmt.Sprintf("scp -o StrictHostKeyChecking=no scp://ssh-%s%s.ziti:2022/fablab/bin/ziti /tmp/ziti-%s", hostType, nameExtra, uuid.NewString()),
}, {
direction: "->",
cmd: fmt.Sprintf("scp -o StrictHostKeyChecking=no ./fablab/bin/ziti scp://ssh-%s%s.ziti:2022//tmp/ziti-%s", hostType, nameExtra, uuid.NewString()),
},
}

for _, test := range tests {
t.Run(fmt.Sprintf("(%s%s%s)-%v", hostSelector, test.direction, hostType, encDesk), func(t *testing.T) {
host, err := model.GetModel().SelectHost("." + hostSelector + "-client")
req := require.New(t)
req.NoError(err)

sshConfigFactory := lib.NewSshConfigFactory(host)

o, err := lib.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 {
t.Skipf("zet client ssh failed [%v]", err.Error())
} else {
t.Log(o)
req.NoError(err)
success = true
}
})
}

return success
}

0 comments on commit 400f4ce

Please sign in to comment.