Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

DO NOT MERGE Docs revamp #85

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ docs/_build/
preso_secret/
client/repeattest.sh
*.out
*.DS_Store*
*.DS_Store*
agent/testing/downloaded_testlets/
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ build:
docker build -t mierdin/todd -f Dockerfile .

compile:
# TODO(mierdin): Need to support some kind of mode that allows for development (i.e. not downloading the testlets live, but rather from a directory?)

# Installing testlets
./scripts/gettestlets.sh

# Installing ToDD
go install ./cmd/...

install: configureenv
Expand All @@ -27,7 +33,7 @@ update_deps:

update_assets:
go get -u github.com/jteeuwen/go-bindata/...
go-bindata -o assets/assets_unpack.go -pkg="assets" -prefix="agent" agent/testing/testlets/... agent/facts/collectors/...
go-bindata -o assets/assets_unpack.go -pkg="assets" -prefix="agent" agent/testing/bashtestlets/... agent/facts/collectors/...

start: compile
start-containers.sh 3 /etc/todd/server-int.cfg /etc/todd/agent-int.cfg
Expand All @@ -37,3 +43,6 @@ configureenv:
if ! [ "etc" -ef "/etc/todd" ]; then mkdir -p /etc/todd && cp -f ./etc/{agent,server}.cfg /etc/todd/; fi
mkdir -p /opt/todd/{agent,server}/assets/{factcollectors,testlets}
chmod -R 777 /opt/todd

# If on Linux, enable ping testlet functionality
sudo sysctl -w net.ipv4.ping_group_range="0 12345"
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = "trusty64"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
config.vm.synced_folder '.', '/home/vagrant/go/src/github.com/Mierdin/todd', nfs: true
config.vm.synced_folder '../../', '/home/vagrant/go/src/github.com', nfs: true


config.vm.provider "virtualbox" do |v|
Expand Down
54 changes: 39 additions & 15 deletions agent/tasks/executetestrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ import (
log "github.com/Sirupsen/logrus"

"github.com/Mierdin/todd/agent/cache"
"github.com/Mierdin/todd/agent/testing/testlets"
"github.com/Mierdin/todd/config"
)

var (
// gatheredData represents test data from this agent for all targets.
// Key is target name, value is JSON output from testlet for that target
// This is reset to a blank map every time ExecuteTestRunTask is called
gatheredData = make(map[string]string)

// Use a wait group to ensure that all of the testlets have a chance to finish
wg sync.WaitGroup
)

// ExecuteTestRunTask defines this particular task.
type ExecuteTestRunTask struct {
BaseTask
Expand All @@ -37,9 +48,13 @@ type ExecuteTestRunTask struct {
// a testrun will be executed once per target, all in parallel.
func (ett ExecuteTestRunTask) Run() error {

// Make sure we're working with a clean slate
gatheredData = map[string]string{}

// Waiting three seconds to ensure all the agents have their tasks before we potentially hammer the network
// TODO(mierdin): This is a bit of a copout. I would like to do something a little more robust than simply waiting
// for a few seconds in the future.
// TODO(mierdin): This is a temporary measure - in the future, testruns will be executed via time schedule,
// making not only this sleep, but also the entire task unnecessary. Testruns will simply be installed, and
// executed when the time is right.
time.Sleep(3000 * time.Millisecond)

// Retrieve test from cache by UUID
Expand All @@ -50,29 +65,38 @@ func (ett ExecuteTestRunTask) Run() error {
return errors.New("Problem retrieving testrun from agent cache")
}

// Generate path to testlet and make sure it exists.
testlet_path := fmt.Sprintf("%s/assets/testlets/%s", ett.Config.LocalResources.OptDir, tr.Testlet)
if _, err := os.Stat(testlet_path); os.IsNotExist(err) {
log.Errorf("Testlet %s does not exist on this agent", tr.Testlet)
return errors.New("Error executing testrun - testlet doesn't exist on this agent.")
}

log.Debugf("IMMA FIRIN MAH LAZER (for test %s) ", ett.TestUuid)

// Use a wait group to ensure that all of the testlets have a chance to finish
var wg sync.WaitGroup
// Specify size of wait group equal to number of targets
wg.Add(len(tr.Targets))

// gatheredData represents test data from this agent for all targets.
// Key is target name, value is JSON output from testlet for that target
gatheredData := make(map[string]string)
var testlet_path string
isNative, newTestletName := testlets.IsNativeTestlet(tr.Testlet)

// If we're running a native testlet, we want testlet_path to simply be the testlet name
// (since it is a requirement that the native-Go testlets are in the PATH)
// If the testlet is not native, we can get the full path.
if isNative {
testlet_path = newTestletName
} else {
// Generate path to testlet and make sure it exists.
testlet_path = fmt.Sprintf("%s/assets/testlets/%s", ett.Config.LocalResources.OptDir, tr.Testlet)
if _, err := os.Stat(testlet_path); os.IsNotExist(err) {
log.Errorf("Testlet %s does not exist on this agent", testlet_path)
return errors.New("Error executing testrun - testlet doesn't exist on this agent.")
}
}

// TODO(mierdin): What about testlets running as servers (i.e. 'iperf -s')? Are we spinning up len(tr.Targets)
// number of those?

// Execute testlets against all targets asynchronously
for i := range tr.Targets {

thisTarget := tr.Targets[i]

go func() {

defer wg.Done()

log.Debugf("Full testlet command and args: '%s %s %s'", testlet_path, thisTarget, tr.Args)
Expand All @@ -86,6 +110,7 @@ func (ett ExecuteTestRunTask) Run() error {
// Execute collector
cmd.Start()

// TODO(mierdin): Does this need to be a buffered channel?
done := make(chan error, 1)
go func() {
done <- cmd.Wait()
Expand All @@ -112,7 +137,6 @@ func (ett ExecuteTestRunTask) Run() error {

// Record test data
gatheredData[thisTarget] = string(cmdOutput.Bytes())

}()
}

Expand Down
24 changes: 19 additions & 5 deletions agent/tasks/installtestrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/Mierdin/todd/agent/cache"
"github.com/Mierdin/todd/agent/defs"
"github.com/Mierdin/todd/agent/testing/testlets"
"github.com/Mierdin/todd/config"
)

Expand All @@ -42,11 +43,24 @@ func (itt InstallTestRunTask) Run() error {
return errors.New("Testlet parameter for this testrun is null")
}

// Generate path to testlet and make sure it exists.
testlet_path := fmt.Sprintf("%s/assets/testlets/%s", itt.Config.LocalResources.OptDir, itt.Tr.Testlet)
if _, err := os.Stat(testlet_path); os.IsNotExist(err) {
log.Errorf("Testlet %s does not exist on this agent", itt.Tr.Testlet)
return errors.New("Error installing testrun - testlet doesn't exist on this agent.")
var testlet_path string

// Determine if this is a native testlet
isNative, newName := testlets.IsNativeTestlet(itt.Tr.Testlet)

// If we're running a native testlet, we want testlet_path to simply be the testlet name
// (since it is a requirement that the native-Go testlets are in the PATH)
// If the testlet is not native, we can get the full path.
if isNative {
log.Infof("%s is a native testlet - installing testrun.", itt.Tr.Testlet)
testlet_path = newName
} else {
// Generate path to testlet and make sure it exists.
testlet_path = fmt.Sprintf("%s/assets/testlets/%s", itt.Config.LocalResources.OptDir, itt.Tr.Testlet)
if _, err := os.Stat(testlet_path); os.IsNotExist(err) {
log.Errorf("Testlet %s does not exist on this agent", itt.Tr.Testlet)
return errors.New("Error installing testrun - testlet doesn't exist on this agent.")
}
}

// Run the testlet in check mode to verify that everything is okay to run this test
Expand Down
32 changes: 0 additions & 32 deletions agent/testing/testlets/ping

This file was deleted.

Loading