From 52148f6a934d51edba9287ce171bca855a22e78c Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Wed, 25 Apr 2018 16:31:22 +0200 Subject: [PATCH 1/2] cmd/swarm/swarm-smoke: extract cluster type and from/to ports and scheme --- cmd/swarm/swarm-smoke/main.go | 38 ++++++++++++++++-------- cmd/swarm/swarm-smoke/upload_and_sync.go | 10 ++++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/cmd/swarm/swarm-smoke/main.go b/cmd/swarm/swarm-smoke/main.go index 9f5e25de0e28..bab230afbc37 100644 --- a/cmd/swarm/swarm-smoke/main.go +++ b/cmd/swarm/swarm-smoke/main.go @@ -17,7 +17,6 @@ package main import ( - "fmt" "os" "sort" @@ -29,16 +28,13 @@ import ( var ( endpoints []string - endpoint string + cluster string + scheme string filesize int + from int + to int ) -func init() { - for port := 8501; port <= 8512; port++ { - endpoints = append(endpoints, fmt.Sprintf("http://%v.testing.swarm-gateways.net", port)) - } -} - func main() { log.PrintOrigins(true) log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(colorable.NewColorableStderr(), log.TerminalFormat(true)))) @@ -49,10 +45,28 @@ func main() { app.Flags = []cli.Flag{ cli.StringFlag{ - Name: "bzz-api", - Value: endpoints[0], - Usage: "upload node endpoint", - Destination: &endpoint, + Name: "cluster-endpoint", + Value: "testing", + Usage: "cluster to point to (open, or testing)", + Destination: &cluster, + }, + cli.IntFlag{ + Name: "cluster-from", + Value: 8501, + Usage: "swarm node (from)", + Destination: &from, + }, + cli.IntFlag{ + Name: "cluster-to", + Value: 8512, + Usage: "swarm node (to)", + Destination: &to, + }, + cli.StringFlag{ + Name: "cluster-scheme", + Value: "http", + Usage: "http or https", + Destination: &scheme, }, cli.IntFlag{ Name: "filesize", diff --git a/cmd/swarm/swarm-smoke/upload_and_sync.go b/cmd/swarm/swarm-smoke/upload_and_sync.go index b490098809f1..d5ddb69c16c0 100644 --- a/cmd/swarm/swarm-smoke/upload_and_sync.go +++ b/cmd/swarm/swarm-smoke/upload_and_sync.go @@ -20,10 +20,18 @@ import ( cli "gopkg.in/urfave/cli.v1" ) +func generateEndpoints(scheme string, cluster string, from int, to int) { + for port := from; port <= to; port++ { + endpoints = append(endpoints, fmt.Sprintf("%s://%v.%s.swarm-gateways.net", scheme, port, cluster)) + } +} + func cliUploadAndSync(c *cli.Context) error { defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "size", filesize) }(time.Now()) - log.Info("uploading and syncing") + generateEndpoints(scheme, cluster, from, to) + + log.Info("uploading to " + endpoints[0] + " and syncing") f, cleanup := generateRandomFile(filesize * 1000000) defer cleanup() From 4e882674e015df18b50800ee7354def2672c5d3f Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 26 Apr 2018 16:41:08 +0200 Subject: [PATCH 2/2] cmd/swarm: include localhost flag --- cmd/swarm/swarm-smoke/main.go | 18 ++++++++++++------ cmd/swarm/swarm-smoke/upload_and_sync.go | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/swarm/swarm-smoke/main.go b/cmd/swarm/swarm-smoke/main.go index bab230afbc37..87bc39816d6e 100644 --- a/cmd/swarm/swarm-smoke/main.go +++ b/cmd/swarm/swarm-smoke/main.go @@ -27,12 +27,13 @@ import ( ) var ( - endpoints []string - cluster string - scheme string - filesize int - from int - to int + endpoints []string + includeLocalhost bool + cluster string + scheme string + filesize int + from int + to int ) func main() { @@ -68,6 +69,11 @@ func main() { Usage: "http or https", Destination: &scheme, }, + cli.BoolFlag{ + Name: "include-localhost", + Usage: "whether to include localhost:8500 as an endpoint", + Destination: &includeLocalhost, + }, cli.IntFlag{ Name: "filesize", Value: 1, diff --git a/cmd/swarm/swarm-smoke/upload_and_sync.go b/cmd/swarm/swarm-smoke/upload_and_sync.go index d5ddb69c16c0..70c33d14653a 100644 --- a/cmd/swarm/swarm-smoke/upload_and_sync.go +++ b/cmd/swarm/swarm-smoke/upload_and_sync.go @@ -24,6 +24,10 @@ func generateEndpoints(scheme string, cluster string, from int, to int) { for port := from; port <= to; port++ { endpoints = append(endpoints, fmt.Sprintf("%s://%v.%s.swarm-gateways.net", scheme, port, cluster)) } + + if includeLocalhost { + endpoints = append(endpoints, "http://localhost:8500") + } } func cliUploadAndSync(c *cli.Context) error {