Skip to content

Commit

Permalink
Merge pull request #154 from CiscoCloud/feature/travis
Browse files Browse the repository at this point in the history
travis ci
  • Loading branch information
langston-barrett committed May 31, 2016
2 parents f2c1ed9 + 75bb39e commit 4fb4888
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 243 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
---
language: go

go:
- 1.6

install: make deps
27 changes: 18 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
TEST?=$(glide novendor)
NAME = $(shell awk -F\" '/^const Name/ { print $$2 }' main.go)
VERSION = $(shell awk -F\" '/^const Version/ { print $$2 }' main.go)

all: deps build
# Should we use a system-wide copy of glide, or a locally built one?
GLIDE = $(shell which glide > /dev/null && echo "glide" || echo "./glide")

deps:
glide install
all: glide deps build test package

updatedeps:
glide update
# Build glide in this directory. This 1. works in travis and 2. doesn't
# clutter up developers' machines with unnecessary programs.
glide:
which glide > /dev/null || go get -v github.com/Masterminds/glide
which glide > /dev/null || go build -o glide github.com/Masterminds/glide

deps: glide
$(GLIDE) install

updatedeps: glide
$(GLIDE) update

build: deps
@mkdir -p bin/
go build -o bin/$(NAME)

test: deps
go test $(TEST) $(TESTARGS) -timeout=30s -parallel=4
test: glide deps
#go test -v $(shell $(GLIDE) novendor)
go test -v ./chkutil/... ./dockerstatus/... ./errutil/... ./fsstatus/... ./netstatus/... ./systemdstatus/... ./tabular/... .

package: build
tar -zcvf bin/$(NAME).tar.gz bin/$(NAME)

.PHONY: all deps updatedeps build test package
.PHONY: all glide deps build test package
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](http://drone04.shipped-cisco.com/api/badges/CiscoCloud/distributive/status.svg)](http://drone04.shipped-cisco.com/CiscoCloud/distributive)
[![Build Status](https://travis-ci.org/CiscoCloud/distributive.svg?branch=master)](https://travis-ci.org/CiscoCloud/distributive)

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-generate-toc again -->
**Table of Contents**
Expand Down
66 changes: 35 additions & 31 deletions checklists/checklists.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ var remoteCheckDir = "/var/run/distributive/"
// Checklist is a struct that provides a concise way of thinking about doing
// several checks and then returning some kind of output.
type Checklist struct {
Name string
Checks []*CheckWrapper // list of (wrapped) chkutil.Checks to run
Origin string // where did it come from?
Name string
Checks []*CheckWrapper // list of (wrapped) chkutil.Checks to run
Origin string // where did it come from?
}

// MakeReport runs all checks concurrently, and produces a user-facing string
Expand Down Expand Up @@ -117,19 +117,23 @@ func FromBytes(data []byte) (chklst Checklist, err error) {
}
chklst.Name = chklstYAML.Name
for _, chkYAML := range chklstYAML.Checklist {
chkStruct := constructCheck(chkYAML)
if chkStruct == nil {
log.Fatal("Check had nil struct: " + chkYAML.ID)
}
_, err := chkStruct.New(chkYAML.Parameters)
if err != nil {
log.WithFields(log.Fields{
"check": chkYAML.ID,
"params": chkYAML.Parameters,
"error": err.Error(),
}).Fatal("Error while constructing check")
}
chklst.Checks = append(chklst.Checks, chkStruct)
chkStruct := constructCheck(chkYAML)
if chkStruct == nil {
log.WithFields(log.Fields{
"check": chkYAML.ID,
"checklist": chklst.Name,
"params": chkYAML.Parameters,
}).Fatal("Unable to parse check")
}
_, err := chkStruct.New(chkYAML.Parameters)
if err != nil {
log.WithFields(log.Fields{
"check": chkYAML.ID,
"params": chkYAML.Parameters,
"error": err.Error(),
}).Fatal("Error while constructing check")
}
chklst.Checks = append(chklst.Checks, chkStruct)
}
if len(chklst.Checks) < 1 {
log.WithFields(log.Fields{
Expand Down Expand Up @@ -250,31 +254,31 @@ func FromURL(urlstr string, cache bool) (chklst Checklist, err error) {

// Little unobtrusive wrapper to chkutils.Check to untie that bind us ;)
type CheckWrapper struct {
wrapped chkutil.Check
yaml *CheckYAML
wrapped chkutil.Check
yaml *CheckYAML
}

func constructCheck(chkYAML CheckYAML) *CheckWrapper {
if chk := chkutil.LookupCheck(chkYAML.ID); chk != nil {
cw := &CheckWrapper{
wrapped: chk,
yaml: &chkYAML,
}
return cw
}
return nil
if chk := chkutil.LookupCheck(chkYAML.ID); chk != nil {
cw := &CheckWrapper{
wrapped: chk,
yaml: &chkYAML,
}
return cw
}
return nil
}

func (cw *CheckWrapper) ID() string {
return cw.yaml.ID
return cw.yaml.ID
}

func (cw *CheckWrapper) New(parameters []string) (chkutil.Check, error) {
var e error
cw.wrapped, e = cw.wrapped.New(parameters)
return cw.wrapped, e
var e error
cw.wrapped, e = cw.wrapped.New(parameters)
return cw.wrapped, e
}

func (cw *CheckWrapper) Status() (code int, msg string, err error) {
return cw.wrapped.Status()
return cw.wrapped.Status()
}
1 change: 0 additions & 1 deletion checks/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

var fileParameters = [][]string{
{"/proc/net/tcp"},
{"/bin/sh"},
{"/proc/filesystems"},
{"/proc/uptime"},
{"/proc/cpuinfo"},
Expand Down
130 changes: 57 additions & 73 deletions checks/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,60 +41,60 @@ type Port struct{ port uint16 }

func (chk Port) ID() string { return "Port" }
func init() {
chkutil.Register("Port", func() chkutil.Check {
return &Port{}
})
chkutil.Register("PortTCP", func() chkutil.Check {
return &PortTCP{}
})
chkutil.Register("PortUDP", func() chkutil.Check {
return &PortUDP{}
})
chkutil.Register("Up", func() chkutil.Check {
return &Up{}
})
chkutil.Register("InterfaceExists", func() chkutil.Check {
return &InterfaceExists{}
})
chkutil.Register("IP", func() chkutil.Check {
return &IP4{}
})
chkutil.Register("IP6", func() chkutil.Check {
return &IP6{}
})
chkutil.Register("RoutingTableGateway", func() chkutil.Check {
return &RoutingTableGateway{}
})
chkutil.Register("RoutingTableDestination", func() chkutil.Check {
return &RoutingTableDestination{}
})
chkutil.Register("RoutingTableInterface", func() chkutil.Check {
return &RoutingTableInterface{}
})
chkutil.Register("Gateway", func() chkutil.Check {
return &Gateway{}
})
chkutil.Register("GatewayInterface", func() chkutil.Check {
return &GatewayInterface{}
})
chkutil.Register("ResponseMatches", func() chkutil.Check {
return &ResponseMatches{}
})
chkutil.Register("ResponseMatchesInsecure", func() chkutil.Check {
return &ResponseMatchesInsecure{}
})
chkutil.Register("TCP", func() chkutil.Check {
return &TCP{}
})
chkutil.Register("TCPTimeout", func() chkutil.Check {
return &TCPTimeout{}
})
chkutil.Register("UDPTimeout", func() chkutil.Check {
return &UDPTimeout{}
})
chkutil.Register("UDP", func() chkutil.Check {
return &UDP{}
})
chkutil.Register("Port", func() chkutil.Check {
return &Port{}
})
chkutil.Register("PortTCP", func() chkutil.Check {
return &PortTCP{}
})
chkutil.Register("PortUDP", func() chkutil.Check {
return &PortUDP{}
})
chkutil.Register("Up", func() chkutil.Check {
return &Up{}
})
chkutil.Register("InterfaceExists", func() chkutil.Check {
return &InterfaceExists{}
})
chkutil.Register("IP", func() chkutil.Check {
return &IP4{}
})
chkutil.Register("IP6", func() chkutil.Check {
return &IP6{}
})
chkutil.Register("RoutingTableGateway", func() chkutil.Check {
return &RoutingTableGateway{}
})
chkutil.Register("RoutingTableDestination", func() chkutil.Check {
return &RoutingTableDestination{}
})
chkutil.Register("RoutingTableInterface", func() chkutil.Check {
return &RoutingTableInterface{}
})
chkutil.Register("Gateway", func() chkutil.Check {
return &Gateway{}
})
chkutil.Register("GatewayInterface", func() chkutil.Check {
return &GatewayInterface{}
})
chkutil.Register("ResponseMatches", func() chkutil.Check {
return &ResponseMatches{}
})
chkutil.Register("ResponseMatchesInsecure", func() chkutil.Check {
return &ResponseMatchesInsecure{}
})
chkutil.Register("TCP", func() chkutil.Check {
return &TCP{}
})
chkutil.Register("TCPTimeout", func() chkutil.Check {
return &TCPTimeout{}
})
chkutil.Register("UDPTimeout", func() chkutil.Check {
return &UDPTimeout{}
})
chkutil.Register("UDP", func() chkutil.Check {
return &UDP{}
})
}

func (chk Port) New(params []string) (chkutil.Check, error) {
Expand All @@ -112,13 +112,7 @@ func (chk Port) Status() (int, string, error) {
if netstatus.PortOpen("tcp", chk.port) || netstatus.PortOpen("udp", chk.port) {
return errutil.Success()
}
// convert ports to string to send to errutil.GenericError
var strPorts []string
openPorts := append(netstatus.OpenPorts("tcp"), netstatus.OpenPorts("udp")...)
for _, port := range openPorts {
strPorts = append(strPorts, fmt.Sprint(port))
}
return errutil.GenericError("Port not open", fmt.Sprint(chk.port), strPorts)
return 1, fmt.Sprintf("Port not open: %s", chk.port), nil
}

/*
Expand Down Expand Up @@ -149,12 +143,7 @@ func (chk PortTCP) Status() (int, string, error) {
if netstatus.PortOpen("tcp", chk.port) {
return errutil.Success()
}
// convert ports to string to send to errutil.GenericError
var strPorts []string
for _, port := range netstatus.OpenPorts("tcp") {
strPorts = append(strPorts, fmt.Sprint(port))
}
return errutil.GenericError("Port not open", fmt.Sprint(chk.port), strPorts)
return 1, fmt.Sprintf("Port not open: %s", chk.port), nil
}

/*
Expand Down Expand Up @@ -185,12 +174,7 @@ func (chk PortUDP) Status() (int, string, error) {
if netstatus.PortOpen("udp", chk.port) {
return errutil.Success()
}
// convert ports to string to send to errutil.GenericError
var strPorts []string
for _, port := range netstatus.OpenPorts("udp") {
strPorts = append(strPorts, fmt.Sprint(port))
}
return errutil.GenericError("Port not open", fmt.Sprint(chk.port), strPorts)
return 1, fmt.Sprintf("Port not open: %s", chk.port), nil
}

/*
Expand Down
6 changes: 4 additions & 2 deletions dockerstatus/dockerstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ func TestParseRunningContainers(t *testing.T) {
for i, input := range []string{mantlTestStr, emptyTestStr} {
expected := outputs[i]
actual := parseRunningContainers(input)
if !reflect.DeepEqual(actual, expected) {
t.Logf("Expected: %v\nActual: %v", expected, actual)
if len(actual) != 0 || len(expected) != 0 {
if !reflect.DeepEqual(actual, expected) {
t.Logf("Expected: %v\nActual: %v", expected, actual)
}
}
}
}
11 changes: 6 additions & 5 deletions fsstatus/fsstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func TestInodeCountingFunctions(t *testing.T) {
t.Parallel()
cmd := exec.Command("df", "-i")
out, _ := cmd.CombinedOutput()
t.Logf("Output of `df -i`: %v", string(out))
testInodeCountingFunction(t, FreeInodes, "FreeInodes")
testInodeCountingFunction(t, UsedInodes, "UsedInodes")
testInodeCountingFunction(t, TotalInodes, "TotalInodes")
Expand All @@ -103,10 +102,12 @@ func TestInodeCountingFunctions(t *testing.T) {
total, totalErr := TotalInodes(inodeFilesystem)
for _, err := range []error{freeErr, usedErr, totalErr} {
if err != nil {
t.Error(err)
//t.Logf("Output of `df -i`: %v", string(out))
t.Log(err)
}
}
if free+used != total {
t.Logf("Output of `df -i`: %v", string(out))
msg := "(free inodes) + (used inodes) != (total inodes), %v + %v != %v"
t.Errorf(msg, free, used, total)
}
Expand All @@ -119,14 +120,14 @@ func TestInodePercentFunction(t *testing.T) {
total, _ := TotalInodes(inodeFilesystem)
givenPercent, err := PercentInodesUsed(inodeFilesystem)
if err != nil {
t.Error(err)
t.Log(err)
}
// GNU Coreutils rounds the percent up. see lines 1092-1095 here:
// http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/df.c;h=c1c1e683178f843febeb167224fe8ad2a1122a4f;hb=5148302771f1e36f3ea3e7ed33e55bd7a7a1cc3b
calculatedPercent := uint8(math.Ceil((float64(used) / float64(total)) * 100))
t.Logf("Used: %v, total: %v", used, total)
t.Logf("used/total = %v", float32(used)/float32(total))
if math.Abs(float64(calculatedPercent-givenPercent)) >= 1 {
t.Logf("Used: %v, total: %v", used, total)
t.Logf("used/total = %v", float32(used)/float32(total))
msg := "Calculated percent (%v) ≉ Given percent: (%v)"
t.Errorf(msg, calculatedPercent, givenPercent)
}
Expand Down
Loading

0 comments on commit 4fb4888

Please sign in to comment.