ciscocloud / distributive Goto Github PK
View Code? Open in Web Editor NEWUnit testing for the cloud
License: Apache License 2.0
Unit testing for the cloud
License: Apache License 2.0
TableToString is almost RST format, and there's no reason why it shouldn't be. It is a pretty format for printing, and useful in other scenarios. WIll make tabular useful in more cases.
This is a bug that has been floating around for a while. The source is definitely probabalisticSplit.
Proposed solutions:
It seems if the file isn't there the error it throughs isn't a very had one. @noahjl discovered this in the haproxy.json health checks.
This was using version 0.1.1 on the mi vagrant box.
# The way to cause it -
bash-4.2# distributive -v=2 -f haproxy.json
Running with verbosity level 2
Creating checklist(s)...
Running checklist: haproxy health check
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x30 pc=0x418a70]
goroutine 1 [running]:
main.func·001(0xc20801c5a0, 0x14, 0x4a41b5, 0x0, 0x0)
/home/vagrant/rpmbuild/BUILD/distributive-0.1.1/filesystem.go:38 +0x70
main.isType(0x73d0b0, 0x4, 0x7cead0, 0xc20801c5a0, 0x14, 0x10, 0x0, 0x0)
/home/vagrant/rpmbuild/BUILD/distributive-0.1.1/filesystem.go:20 +0x58
main.file(0xc20800a240, 0x1, 0x4, 0x1, 0x0, 0x0)
/home/vagrant/rpmbuild/BUILD/distributive-0.1.1/filesystem.go:43 +0x6e
main.runChecks(0xc20801c4e0, 0x14, 0xc20803ad80, 0x28, 0xc20803c320, 0x2, 0x2, 0x0, 0x0, 0x0, ...)
/home/vagrant/rpmbuild/BUILD/distributive-0.1.1/main.go:288 +0x3b2
main.main()
/home/vagrant/rpmbuild/BUILD/distributive-0.1.1/main.go:326 +0x31f
# The particular file used to get here
-bash-4.2# cat haproxy.json
{
"Name": "haproxy health check",
"Notes": "For use with Microservice Infrastructure",
"Checklist" : [
{
"Name": "haproxy environment file",
"Check": "file",
"Parameters": ["/etc/default/haproxy"]
},
{
"Name": "haproxy configuration file",
"Check": "file",
"Parameters": ["/usr/lib/systemd/system/haproxy.service"]
}
]
}
I am implementing the ability to input multiple health checks in a single JSON file. Every JSON file will have the following structure:
{
"Name": "Name",
"Notes": "Notes",
"Checklist": [
{
"Port": 80
},
{
"Exists": "/foo/bar"
}
]
}
We should have an option to disable certificate validation when connection to a remote server to get a response. The solution is outlined here.
Repo checks are currently known to be buggy and don't work for any package manager.
I'm currently implementing these network interface checks:
A command line flag, maybe -u
for url, which then downloads the file to /var/run/distributive/checks
.
We have to consider security.
Add a function to print only if a certain verbosity requirement is met.
The main logic should be this:
So testers can verify which version of distributive is installed
Given an ocatal permissions mode (0[0-7][0-7][0-7]), ensure that the given file has those permissions.
Add a check for:
I'd like to add considerably more documentation. It will take the form of a Github wiki.
Things to be documented:
The README will then consist of the following sections:
In these spots
Given a regex, does this file match said regex?
Static checks should go in /etc/distributive.d
, dynamic in /var/run/distributive/checks/
Even if the command fails.
Noah had difficulties installing Distributive with the current README instructions. Add more details, especially about $GOPATH and go get.
Currently fails if the table can't be split. instead, it should log a warning and then return the rows, unsplit.
systemctl list-units
)systemctl list-sockets
)systemctl list-timers
)systemctl list-timers --all
)systemctl list-unit-files
)So that the response from something like Consul can be parsed.
A few things:
thunk-utils.go
should do the trickfatal
with a descriptive log.Fatal
.For example:
docker ps image NAME:
ciscocloud/mesos-consul
distributive query required to match that image:
docker.io/ciscocloud/mesos-consul
Add a new command line flag, --stdin
The dict/switch scenario in main.go
is unsustainable. We need something like
registerCheck(name string, thunk Thunk, numParams int)
Every single check will now just take a list of strings, Parameters. They will simply return an exit code and exit message. This is a complete overhaul of the internal architecture, but I've already got a working version (decomposition FTW).
This should ultimately lead to more sustainability and simpler code.
Likely, none of the methods need to be public, as they are all called within the same namespace. Just lower the caps.
All workers should be lower case.
It seems that the systemctl checks are not quite parsing the unit status correctly. Example:
{
"Name": "zookeeper service active",
"Check": "systemctlActive",
"Parameters": ["zookeeper.service"]
},
{
"Name": "zookeeper service loaded",
"Check": "systemctlLoaded",
"Parameters": ["zookeeper.service"]
},
Which returns -
Service did not have state:
Specified: active
Actual: []
Service did not have state:
Specified: loaded
Actual: []
From looking at systemctl.go (which I may completely be mis-interpreting) I'm wondering if it would be simpler running something like -
Active -
systemctl show -p ActiveState $SERVICE
Loaded -
systemctl show -p LoadState $SERVICE
This returns something like -
-bash-4.2# systemctl show -p ActiveState zookeeper.service
ActiveState=active
-bash-4.2# systemctl show -p LoadState zookeeper.service
LoadState=loaded
Some headers have changed, there are new ones as well
This function will have a signature of:
func SplitByAlignment(str string) Table
It will take a string and split it into rows, then find the index of name in the first row, and separate the column that is aligned by index with that name.
Distributive deals with a lot of tabular data. With methods like strIn, strContainedIn, reIn, commandColumnNoHeader, it's clear that this could be abstracted even further. My proposal is as follows:
We need one, unified method for splitting a tabular string into a 2D slice. It should detect which regexp to use, judging by the consistency of the row widths (it would assume even rows). It might do this using standard deviation or something. It would abstract further and eliminate the need for separateString
, stringToSlice
, and stringToSliceMultispace
. Possible regexp's: for rows: "\n+"
, for columns: "\\s{2,}"
, "\\s+"
, "\t+"
.
In conjunction, we need a method that fetches the a column (sans header) by the header title. This should be super simple and will totally prettify the code.
For organization, this will all go into another go package: tabular.go
From @LeeLammert:
It would be very nice to have a check that would match a string via http/https - e.g. "Running" for the Marathon UI, to simple status checks via the a webUI.
The basic process is curl -> response -> regex match
Questions: how do we deal with HTTP/HTTPS?
Generalize yum repo to other package managers
Then, the following functions will cover the functionality of PPA, yumrepo, etc.:
Concurrency stands to be implemented in a few more spots.
I've learned a lot more about concurrecy recently (2015-08-05) and am starting work on this.
Two phases:
And later,
Enable sending logs to disk:
It must be
Taken from the official documentation. Need to figure out which ones we want to do, as well as which ones we've already done.
-a
should run everything in a given directory. It should be non-blank by default, in particular -a=/etc/distributive.d/
.
Serverspec currently defines these kinds of checks for Linux systems:
I'd like to implement more of them.
Several package managers can output a list of active repos. Try parsing this. For example, yum repolist
.
Repo name matches regex
Update docs
Golang's flag package just isn't great. Look into libraries for this.
All *.go files in the root dir should be autonomous. They should register their own checks when imported, so that they can be left out at compile time.
Improvement for genericError
: Don't just fmt.Sprint
whole tables depending on length. Join them with ", " and then truncate that string.
Validating some of the checks and noticing a consistent fail for repoExists checks -
{
"Name": "chronos health check",
"Notes": "For use with Microservice Infrastructure",
"Checklist" : [
{
"Name": "mesosphere repo present in yum",
"Check": "repoExistsURI",
"Parameters": ["yum","http://repos.mesosphere.io/el/7/noarch/"]
},
....
based on packages.go it seems that the baseurl or name in /etc/yum.repos.d/mesosphere.repo should fit the parameters. But they return errors:
Repo with given Url not found:
Specified: http://repos.mesosphere.io/el/7/$basearch/
Actual: []
Using repoExists and the "name=" in mesosphere.repo
Repo with given Name not found:
Specified: Mesosphere Packages for EL 7 - noarch
Actual: []
Using the microservices-infrastructure vagrant box for testing.
I've also installed the RPM of distributive 0.1.
Make the Check struct have two fields: check type (string) and options ([]string).
I am implementing more granular filesystem checks, specifically File, Directory, and Symlink. These will all properly handle not found and permissions errors.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.