Skip to content

Commit

Permalink
Merge pull request #31 from l50/master
Browse files Browse the repository at this point in the history
Add integration tests for chef; various fixes/improvements
  • Loading branch information
l50 committed Dec 3, 2019
2 parents 140038f + b0c6965 commit 9b97ab0
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 44 deletions.
6 changes: 3 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ steps:
cd docker/basic
bash create_ssh_key.sh
docker-compose up -d --build
echo "Sleeping for 10 minutes (600 seconds) while waiting for the chef environment to finish building."
sleep 600
echo "Sleeping for 12 minutes (720 seconds) while waiting for the chef environment to finish building."
sleep 720
docker ps
displayName: 'Build and configure chef test environment'
workingDirectory: "$(modulePath)"
Expand Down Expand Up @@ -122,4 +122,4 @@ steps:
export GO111MODULE=on
go test -count=1 -v -race ./...
displayName: 'Run unit tests'
workingDirectory: "$(modulePath)"
workingDirectory: "$(modulePath)"
4 changes: 2 additions & 2 deletions chefEnv.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/gobuffalo/packr/v2"
"github.com/l50/mose/pkg/chefutils"
"github.com/master-of-servers/mose/pkg/moseutils"
"github.com/mholt/archiver"
"io"
"io/ioutil"
Expand Down Expand Up @@ -236,7 +236,7 @@ func runMoseInContainer(cli *client.Client, id string, osTarget string) {
os.Exit(0)
}
// Run the MOSE binary on the new workstation that we just created
agents, err := chefutils.TargetAgents(nodes, osTarget)
agents, err := moseutils.TargetAgents(nodes, osTarget)
if err != nil {
log.Println("Quitting...")
signalChan <- os.Interrupt
Expand Down
14 changes: 7 additions & 7 deletions cmd/mose/chef/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import (
"crypto/tls"
"encoding/json"
"flag"
"github.com/fatih/color"
"github.com/gobuffalo/packr/v2"
"github.com/l50/goutils"
"github.com/l50/mose/pkg/chefutils"
"github.com/l50/mose/pkg/moseutils"
"io"
"log"
"mime/multipart"
Expand All @@ -26,6 +21,11 @@ import (
"strings"
"text/template"
"time"

"github.com/fatih/color"
"github.com/gobuffalo/packr/v2"
utils "github.com/l50/goutils"
"github.com/master-of-servers/mose/pkg/moseutils"
)

type Command struct {
Expand Down Expand Up @@ -397,7 +397,7 @@ func chefWorkstation(knifeFile string, chefDirs []string) {
if suppliedNodes != "" {
agents = strings.Fields(suppliedNodes)
} else {
agents, err = chefutils.TargetAgents(nodes, osTarget)
agents, err = moseutils.TargetAgents(nodes, osTarget)
if err != nil {
log.Fatal("Quitting")
}
Expand All @@ -418,7 +418,7 @@ func chefWorkstation(knifeFile string, chefDirs []string) {
}
var cookbooksLoc string
for _, dir := range chefDirs {
if strings.Contains(dir, "cookbooks") {
if strings.Contains(dir, ".chef/cookbooks") {
cookbooksLoc = dir
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/mose/puppet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/fatih/color"
"github.com/gobuffalo/packr/v2"
"github.com/l50/goutils"
"github.com/l50/mose/pkg/moseutils"
"github.com/master-of-servers/mose/pkg/moseutils"
"io/ioutil"
"log"
"os"
Expand Down
2 changes: 1 addition & 1 deletion filehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package main
import (
"context"
"encoding/json"
"github.com/l50/mose/pkg/moseutils"
"github.com/master-of-servers/mose/pkg/moseutils"
"io"
"log"
"net/http"
Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/l50/mose
module github.com/master-of-servers/mose

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
Expand All @@ -25,16 +25,15 @@ require (
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/rogpeppe/go-internal v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
golang.org/x/sys v0.0.0-20191126131656-8a8471f7e56d // indirect
golang.org/x/crypto v0.0.0-20191128160524-b544559bb6d1 // indirect
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
golang.org/x/tools v0.0.0-20191126181543-fc82735a89db // indirect
google.golang.org/grpc v1.21.1 // indirect
gopkg.in/src-d/go-git.v4 v4.12.0 // indirect
gotest.tools v2.2.0+incompatible // indirect
)

replace github.com/docker/docker => github.com/docker/engine v0.0.0-20190423201726-d2cfbce3f3b0

go 1.13
go 1.13
19 changes: 5 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ github.com/gobuffalo/logger v1.0.3 h1:YaXOTHNPCvkqqA7w05A4v0k2tCdpr+sgFlgINbQ6gq
github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7TCjEhjKxM=
github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4=
github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q=
github.com/gobuffalo/packr v1.30.1 h1:hu1fuVR3fXEZR7rXNW3h8rqSML8EVAf6KNm0NKO/wKg=
github.com/gobuffalo/packr/v2 v2.7.1 h1:n3CIW5T17T8v4GGK5sWXLVWJhCz7b5aNLSxW6gYim4o=
github.com/gobuffalo/packr/v2 v2.7.1/go.mod h1:qYEvAazPaVxy7Y7KR0W8qYEE+RymX74kETFqjFoFlOc=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
Expand Down Expand Up @@ -141,8 +140,6 @@ github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tL
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
Expand All @@ -169,10 +166,10 @@ golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd h1:sMHc2rZHuzQmrbVoSpt9Hg
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIoF2s4qxv0xSSS0BVZUE/ss=
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c h1:/nJuwDLoL/zrqY6gf57vxC+Pi+pZ8bfhpPkicO5H7W4=
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20191128160524-b544559bb6d1 h1:anGSYQpPhQwXlwsu5wmfq0nWkCNaMEMUwAv13Y92hd8=
golang.org/x/crypto v0.0.0-20191128160524-b544559bb6d1/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -199,10 +196,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 h1:khxRGsvPk4n2y8I/mLLjp7e5dMTJmH75wvqS6nMwUtY=
golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c h1:S/FtSvpNLtFBgjTqcKsRpsa6aVsI6iztaz1bQd9BJwE=
golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191126131656-8a8471f7e56d h1:kCXqdOO2GMlu0vCsEMBXwj/b0E9wyFpNPBpuv/go/F8=
golang.org/x/sys v0.0.0-20191126131656-8a8471f7e56d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
Expand All @@ -211,10 +206,6 @@ golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3 h1:2AmBLzhAfXj+2HCW09VCkJtHIYgHTIPcTeYqgP7Bwt0=
golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191101200257-8dbcdeb83d3f h1:+QO45yvqhfD79HVNFPAgvstYLFye8zA+rd0mHFsGV9s=
golang.org/x/tools v0.0.0-20191101200257-8dbcdeb83d3f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191126181543-fc82735a89db h1:V4rRGyV8ZqAxwMEXqLeXFp0XyBG1r03/vXVGBt6k1dc=
golang.org/x/tools v0.0.0-20191126181543-fc82735a89db/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
Expand All @@ -237,4 +228,4 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
14 changes: 9 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ import (
"context"
"encoding/json"
"flag"
"github.com/fatih/color"
"github.com/gobuffalo/packr/v2"
"github.com/l50/goutils"
"github.com/l50/mose/pkg/moseutils"
"log"
"os"
"path"
"path/filepath"
"strings"
"text/template"
"time"

"github.com/fatih/color"
"github.com/gobuffalo/packr/v2"
utils "github.com/l50/goutils"
"github.com/master-of-servers/mose/pkg/moseutils"
)

var (
Expand All @@ -37,7 +38,7 @@ var (
filePath string
cmdFileUpload string
cmdUploadPath string
imageName = "l50/chef-workstation-test"
imageName = "mose/chef-workstation"
chefNodeName string
chefClientKey string
chefValidationKey string
Expand Down Expand Up @@ -252,6 +253,9 @@ func generatePayload() {
}

res, err := utils.RunCommand("env", "GOOS="+strings.ToLower(osTarget), "GOARCH=amd64", "go", "build", "-o", fPayload)
if verbose {
log.Printf("env GOOS=" + strings.ToLower(osTarget) + " GOARCH=amd64" + " go" + " build" + " -o " + fPayload)
}
if err != nil {
log.Fatalf("Error running the command to generate the target payload: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/chefutils/chefutils.go → pkg/moseutils/agentutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.

package chefutils
package moseutils

import (
"bufio"
"errors"
"fmt"
"github.com/l50/mose/pkg/moseutils"
"os"
"strings"
)

// TargetAgents allows a user to select specific chef agents, or return them all as a []string
func TargetAgents(nodes []string, osTarget string) ([]string, error) {
var targets []string
if ans, err := moseutils.AskUserQuestion("Do you want to target specific chef agents?", osTarget); ans && err == nil {
if ans, err := AskUserQuestion("Do you want to target specific chef agents?", osTarget); ans && err == nil {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("%s", nodes[0])
for _, node := range nodes[1:] {
Expand Down
3 changes: 2 additions & 1 deletion pkg/moseutils/fileutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ package moseutils
import (
"bufio"
"errors"
"github.com/mholt/archiver"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/mholt/archiver"
)

func CreateFolders(folders []string) bool {
Expand Down
2 changes: 1 addition & 1 deletion templates/chef/params.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/l50/mose/pkg/agent"
"github.com/master-of-servers/mose/pkg/agent"
)

func CreateAgent() agent.Agent {
Expand Down
2 changes: 1 addition & 1 deletion templates/puppet/params.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/l50/mose/pkg/agent"
"github.com/master-of-servers/mose/pkg/agent"
)

func CreateAgent() agent.Agent {
Expand Down

0 comments on commit 9b97ab0

Please sign in to comment.