New top-level package: wrench

This tiny package provides simple way for any part of Juju to check if a "wrench should be dropped in the works" at some part of Juju's execution. It checks $datadir/wrench for files which signal that something should break, performing some error checking and logging.

The idea is that judicious calls to wrench.IsEnabled can be permanently left in the code to aid manual and CI testing.


Thanks, maybe the DOS line ending scenario is unpossible, but I think there
are cases where the wrenchfile can be malformed, and we would be slapping
outselves on the back for our great software when actaully the wrench never
did anything.


On Mon, Aug 18, 2014 at 10:23 AM, Menno Smits <notifications@github.com>
wrote:

> In wrench/wrench.go:
>
> > +
> > +	wrenchFile, err := os.Open(fileName)
> > +	if err != nil {
> > +		logger.Errorf("unable to read wrench data for %s/%s (ignored): %v",
> > +			category, feature, err)
> > +		return false
> > +	}
> > +	defer wrenchFile.Close()
> > +	lines := bufio.NewScanner(wrenchFile)
> > +	for lines.Scan() {
> > +		line := strings.TrimSpace(lines.Text())
> > +		if line == feature {
> > +			logger.Warningf("wrench for %s/%s is active", category, feature)
> > +			return true
> > +		}
> > +	}
>
> Ok, so the scanner takes care of DOS and Unix line endings just fine. I
> just wrote up a little example to make sure. I'm not sure what your
> concerns about DOS line endings are about. Please let me know if I've
> missed something.
>
> http://play.golang.org/p/Iciha8LdXH
>
> My comments about TrimSpace only made sense for the previous
> implementation that didn't use bufio.Scanner. TrimSpace is still useful
> however in case someone accidentally adds some spaces around lines.
>
> You're right that I need to be calling Err() on the scanner and logging if
> something went wrong during file reading. I'll fix that.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/juju/juju/pull/508/files#r16333574>.
>