Skip to content

Commit

Permalink
Add headless (#14)
Browse files Browse the repository at this point in the history
* Updating.

* updating to use homebrew as part of release.

* Added basic assemble headless fn.

* removed unused heroku config.

* Added mirrors for headless.  Copied the way VDC was used.

* have us-east tunnel endpoint working.

* Added headless to the 'all' dc tests.
  • Loading branch information
mdsauce committed Jul 17, 2019
1 parent f2e1479 commit 7f1d87d
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 28 deletions.
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

32 changes: 23 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ during a Sauce Labs session (RDC or VDC) .`,
whichCloud = strings.ToLower(whichCloud)
whichDC = strings.ToLower(whichDC)
vdcTest := endpoints.NewVDCTest(whichDC)
headlessTest := endpoints.NewHeadlessTest(whichDC)
rdcTest := endpoints.NewRDCTest(whichDC)
defPublic := endpoints.NewPublicTest()
vdcAPITest, err := endpoints.AssembleVDCEndpoints(whichDC)
if err != nil {
log.Info(err)
}
headlessAPITest, err := endpoints.AssembleHeadlessEndpoints(whichDC)
if err != nil {
log.Info(err)
}

if whichDC != "all" {
validateDC(whichDC)
}
Expand All @@ -110,6 +116,13 @@ during a Sauce Labs session (RDC or VDC) .`,
if whichCloud == "rdc" {
diagnostics.RDCServices(rdcTest.Endpoints)
}
// Headless
if whichCloud == "headless" {
diagnostics.HeadlessServices(headlessTest.Endpoints)
if headlessAPITest != nil {
diagnostics.HeadlessAPI(headlessAPITest.Endpoints)
}
}
}

if runTCP {
Expand All @@ -118,12 +131,16 @@ during a Sauce Labs session (RDC or VDC) .`,
} else if whichCloud == "all" {
diagnostics.VDCServices(vdcTest.Endpoints)
diagnostics.RDCServices(rdcTest.Endpoints)
diagnostics.HeadlessServices(headlessTest.Endpoints)
if whichDC == "all" {
diagnostics.PublicSites(defPublic.Sitelist)
}
if vdcAPITest != nil {
diagnostics.VdcAPI(vdcAPITest.Endpoints)
}
if headlessAPITest != nil {
diagnostics.HeadlessAPI(headlessAPITest.Endpoints)
}
}
},
}
Expand All @@ -149,14 +166,11 @@ func init() {
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "print all logging levels")
rootCmd.PersistentFlags().StringVarP(&userProxy, "proxy", "p", "", "upstream proxy for nethelp to use. Enter like -p protocol://username:password@host:port")

// Cobra also supports local flags, which will only run
// when this action is called directly.
//rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.Flags().BoolP("lucky", "l", false, "disable the proxy check at startup and instead test the proxy during execution.")
rootCmd.Flags().Bool("tcp", false, "run TCP tests. Will always run against all endpoints.")
rootCmd.Flags().Bool("log", false, "enables logging and creates a nethelp.log file. Will automatically append data to the file in a non-destructive manner.")
rootCmd.Flags().String("cloud", "all", "options are: VDC or RDC. Select which services you'd like to test, Virtual Device Cloud or Real Device Cloud respectively.")
rootCmd.Flags().String("dc", "all", "options are: EU or NA. Choose which data centers you want run diagnostics against, Europe or North America respectively.")
rootCmd.Flags().String("cloud", "all", "options are: VDC, RDC, or HEADLESS. Select which services you'd like to test, Virtual Device Cloud, Real Device Cloud, or the Headless Cloud.")
rootCmd.Flags().String("dc", "all", "options are: EU, NA, or EAST. Choose which data centers you want run diagnostics against, Europe, North America(West), or North America(East).")

// http client settings
http.DefaultTransport = &http.Transport{
Expand Down Expand Up @@ -250,13 +264,13 @@ func checkForEnvProxies() {
}

func validateCloud(whichCloud string) {
if whichCloud != "vdc" && whichCloud != "rdc" {
log.Fatal("The parameter is not valid. Only 'all', 'vdc', or 'rdc' are allowed")
if whichCloud != "vdc" && whichCloud != "rdc" && whichCloud != "headless" {
log.Fatal("The parameter is not valid. Only 'all', 'vdc', 'rdc', or 'headless' are allowed")
}
}

func validateDC(whichDC string) {
if whichDC != "na" && whichDC != "eu" {
log.Fatal("The parameter is not valid. Only 'all', 'na', or 'eu' are allowed")
if whichDC != "na" && whichDC != "eu" && whichDC != "east" {
log.Fatal("The parameter is not valid. Only 'all', 'na', 'eu', or 'east' are allowed")
}
}
78 changes: 78 additions & 0 deletions diagnostics/headless_conns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package diagnostics

import (
"bytes"
"fmt"
"net/http"
"net/url"
"os"

log "github.com/sirupsen/logrus"
)

// HeadlessServices sends HTTP requests to Headless Sauce endpoints to prove
// tests could theoretically be created and the data centers are reachable
func HeadlessServices(sauceEndpoints []string) {
for _, endpoint := range sauceEndpoints {
u, err := url.ParseRequestURI(endpoint)
if err != nil {
log.WithFields(log.Fields{
"err": err,
"endpoint": endpoint,
}).Debug("Could not parse endpoint.")
fmt.Printf("[ ] %s is not reachable. Err: %v\n", endpoint, err)
continue
}
log.WithFields(log.Fields{
"url": u,
"IsAbs?": u.IsAbs(),
"scheme": u.Scheme,
"port": u.Port,
"path": u.Path,
}).Debug("URL after Parsing")

log.Debug("Sending GET req to ", u)
resp, err := http.Get(u.String())
if err != nil {
fmt.Printf("[ ] %s not reachable\n", u)
log.WithFields(log.Fields{
"error": err,
"endpoint": u,
}).Infof("[ ] %s not reachable\n", u)
}

if err == nil {
respOutput(resp, endpoint)
}
}
}

// HeadlessAPI connects to Headless (us-east-1) REST endpoints to make sure
// 1) credentials work
// 2) api is reachable
// 3) api retrieves the expected data if 1 & 2 are true
func HeadlessAPI(vdcRESTEndpoints []string) {
log.Debug("Sending out HTTP reqs to these endpoints: ", vdcRESTEndpoints)
username := os.Getenv("SAUCE_USERNAME")
apiKey := os.Getenv("SAUCE_ACCESS_KEY")
for _, endpoint := range vdcRESTEndpoints {
log.Debug("Sending GET req to ", endpoint)
var jsonBody = []byte(`{}`)
req, err := http.NewRequest("GET", endpoint, bytes.NewBuffer(jsonBody))
req.SetBasicAuth(username, apiKey)
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("[ ] %s not reachable\n", endpoint)
log.WithFields(log.Fields{
"error": err,
}).Infof("[ ] %s not reachable\n", endpoint)
}

if err == nil {
respOutput(resp, endpoint)
}
}
}
34 changes: 33 additions & 1 deletion endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,17 @@ func NewVDCTest(dc string) SauceService {
return vdcTest
}

// NewHeadlessTest constructs a SauceService object that contains the specificed Datacenter and endpoints
func NewHeadlessTest(dc string) SauceService {
headlessTest := SauceService{Datacenter: dc, Cloud: "headless"}
if dc == "east" || dc == "all" {
headlessTest.Endpoints = []string{"http://ondemand.us-east-1.saucelabs.com:80", "https://ondemand.us-east-1.saucelabs.com:443"}
}
return headlessTest
}

// AssembleVDCEndpoints interpolates user variables like
// SAUCE_USERNAMe and SAUCE_ACCESS_KEY to create a valid URI.
// SAUCE_USERNAME and SAUCE_ACCESS_KEY to create a valid URI.
func AssembleVDCEndpoints(dc string) (*SauceService, error) {
if os.Getenv("SAUCE_USERNAME") == "" {
log.Info("SAUCE_USERNAME environment variables not found. Not running VDC REST endpoint tests.")
Expand All @@ -101,3 +110,26 @@ func AssembleVDCEndpoints(dc string) (*SauceService, error) {
return nil, errors.New("Only 'all', 'vdc', or 'rdc' are allowed")
}
}

// AssembleHeadlessEndpoints interpolates user variables like
// SAUCE_USERNAME and SAUCE_ACCESS_KEY to create a valid URI.
func AssembleHeadlessEndpoints(dc string) (*SauceService, error) {
if os.Getenv("SAUCE_USERNAME") == "" {
log.Info("SAUCE_USERNAME environment variables not found. Not running VDC REST endpoint tests.")
return nil, errors.New("SAUCE_USERNAME environment variables not found, not running VDC REST endpoint tests")
}
eastHeadless := fmt.Sprintf("https://us-east-1.saucelabs.com/rest/v1/%s/tunnels", os.Getenv("SAUCE_USERNAME"))

switch dc {
case "all":
e := make([]string, 1)
e[0] = eastHeadless
return &SauceService{Datacenter: dc, Cloud: "headless", Endpoints: e}, nil
case "east":
e := make([]string, 1)
e[0] = eastHeadless
return &SauceService{Datacenter: dc, Cloud: "headless", Endpoints: e}, nil
default:
return nil, errors.New("Only 'east' or 'all' is allowed")
}
}
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand All @@ -19,6 +20,7 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand All @@ -35,6 +37,7 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38=
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down
17 changes: 0 additions & 17 deletions nethelp.rb

This file was deleted.

0 comments on commit 7f1d87d

Please sign in to comment.