func (s *baseProviderSuite) SetUpTest(c *gc.C) {
	s.LoggingSuite.SetUpTest(c)
	s.TestSuite.SetUpTest(c)
	s.home = testing.MakeFakeHomeNoEnvironments(c, "test")
	loggo.GetLogger("juju.environs.local").SetLogLevel(loggo.TRACE)
	s.restore = local.MockAddressForInterface()
}
Exemple #2
0
// Start starts logging using the given Context.
func (l *Log) Start(ctx *Context) (err error) {
	var target io.Writer
	if l.Path != "" {
		path := ctx.AbsPath(l.Path)
		target, err = os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
		if err != nil {
			return err
		}
	} else if l.Verbose || l.Debug {
		target = ctx.Stderr
	}

	if target != nil {
		writer := loggo.NewSimpleWriter(target, &loggo.DefaultFormatter{})
		_, err = loggo.ReplaceDefaultWriter(writer)
		if err != nil {
			return err
		}
	} else {
		loggo.RemoveWriter("default")
	}
	if l.Verbose || l.Debug {
		level := loggo.INFO
		if l.Debug {
			level = loggo.DEBUG
		}
		// Set the level on the root logger.
		loggo.GetLogger("").SetLogLevel(level)
	}
	loggo.ConfigureLoggers(l.Config)
	return nil
}
func (s *LogSuite) TestVerboseSetsLogLevel(c *C) {
	l := &cmd.Log{Verbose: true}
	ctx := testing.Context(c)
	err := l.Start(ctx)
	c.Assert(err, IsNil)

	c.Assert(loggo.GetLogger("").LogLevel(), Equals, loggo.INFO)
}
func (s *LogSuite) TestDebugSetsLogLevel(c *C) {
	l := &cmd.Log{Debug: true}
	ctx := testing.Context(c)
	err := l.Start(ctx)
	c.Assert(err, IsNil)

	c.Assert(loggo.GetLogger("").LogLevel(), Equals, loggo.DEBUG)
}
Exemple #5
0
func (s *suite) SetUpTest(c *C) {
	var err error
	s.writer = &testWriter{}
	s.oldWriter, s.oldLevel, err = loggo.RemoveWriter("default")
	c.Assert(err, IsNil)
	err = loggo.RegisterWriter("test", s.writer, loggo.TRACE)
	c.Assert(err, IsNil)
	logger := loggo.GetLogger("juju")
	logger.SetLogLevel(loggo.TRACE)
}
Exemple #6
0
func (srv *Server) serveConn(wsConn *websocket.Conn) error {
	codec := jsoncodec.NewWebsocket(wsConn)
	if loggo.GetLogger("").EffectiveLogLevel() >= loggo.DEBUG {
		codec.SetLogging(true)
	}
	conn := rpc.NewConn(codec)
	if err := conn.Serve(newStateServer(srv, conn), serverError); err != nil {
		return err
	}
	conn.Start()
	select {
	case <-conn.Dead():
	case <-srv.tomb.Dying():
	}
	return conn.Close()
}
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package minunitsworker

import (
	"launchpad.net/loggo"

	"launchpad.net/juju-core/state"
	"launchpad.net/juju-core/state/api"
	"launchpad.net/juju-core/worker"
)

var logger = loggo.GetLogger("juju.worker.minunitsworker")

// MinUnitsWorker ensures the minimum number of units for services is respected.
type MinUnitsWorker struct {
	st *state.State
}

// NewMinUnitsWorker returns a Worker that runs service.EnsureMinUnits()
// if the number of alive units belonging to a service decreases, or if the
// minimum required number of units for a service is increased.
func NewMinUnitsWorker(st *state.State) worker.Worker {
	mu := &MinUnitsWorker{st: st}
	return worker.NewStringsWorker(mu)
}

func (mu *MinUnitsWorker) SetUp() (api.StringsWatcher, error) {
	return mu.st.WatchMinUnits(), nil
}
Exemple #8
0
package environs

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"

	"launchpad.net/goyaml"
	"launchpad.net/loggo"

	"launchpad.net/juju-core/environs/config"
)

var logger = loggo.GetLogger("juju.environs")

// environ holds information about one environment.
type environ struct {
	config *config.Config
	err    error // an error if the config data could not be parsed.
}

// Environs holds information about each named environment
// in an environments.yaml file.
type Environs struct {
	Default  string // The name of the default environment.
	environs map[string]environ
}

// Names returns the list of environment names.
Exemple #9
0
	return "must restart: an agent upgrade is available"
}

// ChangeAgentTools does the actual agent upgrade.
// It should be called just before an agent exits, so that
// it will restart running the new tools.
func (e *UpgradeReadyError) ChangeAgentTools() error {
	tools, err := tools.ChangeAgentTools(e.DataDir, e.AgentName, e.NewTools.Version)
	if err != nil {
		return err
	}
	logger.Infof("upgraded from %v to %v (%q)", e.OldTools.Version, tools.Version, tools.URL)
	return nil
}

var logger = loggo.GetLogger("juju.worker.upgrader")

// Upgrader represents a worker that watches the state for upgrade
// requests.
type Upgrader struct {
	tomb    tomb.Tomb
	st      *upgrader.State
	dataDir string
	tag     string
}

// New returns a new upgrader worker. It watches changes to the
// current version of the current agent (with the given tag)
// and tries to download the tools for any new version
// into the given data directory.
// If an upgrade is needed, the worker will exit with an
Exemple #10
0
// Copyright 2011, 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package log

import (
	"launchpad.net/loggo"
)

var (
	logger = loggo.GetLogger("juju")
)

// Errorf logs a message using the ERROR priority.
func Errorf(format string, a ...interface{}) error {
	logger.Logf(loggo.ERROR, format, a...)
	return nil
}

// Warningf logs a message using the WARNING priority.
func Warningf(format string, a ...interface{}) error {
	logger.Logf(loggo.WARNING, format, a...)
	return nil
}

// Noticef logs a message using the NOTICE priority.
// Notice doesn't really convert to the loggo priorities...
func Noticef(format string, a ...interface{}) error {
	logger.Logf(loggo.INFO, format, a...)
	return nil
}
Exemple #11
0
import (
	"fmt"

	"launchpad.net/gnuflag"
	"launchpad.net/loggo"
	"launchpad.net/tomb"

	"launchpad.net/juju-core/cmd"
	"launchpad.net/juju-core/names"
	"launchpad.net/juju-core/state"
	"launchpad.net/juju-core/worker"
	"launchpad.net/juju-core/worker/uniter"
	"launchpad.net/juju-core/worker/upgrader"
)

var agentLogger = loggo.GetLogger("juju.jujud")

// UnitAgent is a cmd.Command responsible for running a unit agent.
type UnitAgent struct {
	cmd.CommandBase
	tomb     tomb.Tomb
	Conf     AgentConf
	UnitName string
	runner   *worker.Runner
}

// Info returns usage information for the command.
func (a *UnitAgent) Info() *cmd.Info {
	return &cmd.Info{
		Name:    "unit",
		Purpose: "run a juju unit agent",
Exemple #12
0
// Licensed under the AGPLv3, see LICENCE file for details.

package deployer

import (
	"fmt"
	"launchpad.net/juju-core/errors"
	"launchpad.net/juju-core/state"
	"launchpad.net/juju-core/state/watcher"
	"launchpad.net/juju-core/utils"
	"launchpad.net/juju-core/utils/set"
	"launchpad.net/loggo"
	"launchpad.net/tomb"
)

var logger = loggo.GetLogger("juju.deployer")

// Deployer is responsible for deploying and recalling unit agents, according
// to changes in a set of state units; and for the final removal of its agents'
// units from state when they are no longer needed.
type Deployer struct {
	tomb      tomb.Tomb
	st        *state.State
	ctx       Context
	machineId string
	deployed  set.Strings
}

// Context abstracts away the differences between different unit deployment
// strategies; where a Deployer is responsible for what to deploy, a Context
// is responsible for how to deploy.
Exemple #13
0
package beacon

import (
	"fmt"
	"launchpad.net/loggo"
	"os"
	"os/exec"
	"os/signal"
)

var log = loggo.GetLogger("hivy")

const (
	superVerboseLogLevel loggo.Level = loggo.TRACE
	verboseLogLevel      loggo.Level = loggo.INFO
	defaultLogLevel      loggo.Level = loggo.WARNING
	// Change here to absolute or relative path if etcd is not in your $PATH
	etcdBin string = "etcd"

	// Allowed is a macro representing an accessible method
	Allowed string = "true"
	// Forbidden is a macro representing an hiden method
	Forbidden string = "false"
)

// Version follows unstable git tag
type Version struct {
    major int
    minor int
    fix   int
}
Exemple #14
0
	"time"

	"launchpad.net/loggo"

	"launchpad.net/juju-core/charm"
	"launchpad.net/juju-core/environs"
	"launchpad.net/juju-core/juju"
	"launchpad.net/juju-core/state/api/params"
)

// Import the providers.
import (
	_ "launchpad.net/juju-core/environs/all"
)

var logger = loggo.GetLogger("juju.builddb")

func main() {
	if err := build(); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(1)
	}
}

func build() error {
	environ, err := environs.NewFromName("")
	if err != nil {
		return err
	}
	conn, err := juju.NewConn(environ)
	if err != nil {
Exemple #15
0
// Licensed under the AGPLv3, see LICENCE file for details.

package provisioner

import (
	"launchpad.net/loggo"

	"launchpad.net/juju-core/constraints"
	"launchpad.net/juju-core/container/lxc"
	"launchpad.net/juju-core/environs/config"
	"launchpad.net/juju-core/instance"
	"launchpad.net/juju-core/state"
	"launchpad.net/juju-core/state/api"
)

var lxcLogger = loggo.GetLogger("juju.provisioner.lxc")

var _ Broker = (*lxcBroker)(nil)

func NewLxcBroker(config *config.Config, tools *state.Tools) Broker {
	return &lxcBroker{
		manager: lxc.NewContainerManager(lxc.ManagerConfig{Name: "juju"}),
		config:  config,
		tools:   tools,
	}
}

type lxcBroker struct {
	manager lxc.ContainerManager
	config  *config.Config
	tools   *state.Tools
Exemple #16
0
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package tools

import (
	"io"

	"launchpad.net/loggo"

	"launchpad.net/juju-core/version"
)

var logger = loggo.GetLogger("juju.agent.tools")

type Tools struct {
	Version version.Binary
	URL     string
}

// ToolsManager keeps track of a pool of tools
type ToolsManager interface {

	// ReadTools looks in the current storage to see what tools are
	// available that match the given Binary version.
	ReadTools(version version.Binary) (*Tools, error)

	// UnpackTools reads the compressed tarball from the io.Reader and
	// extracts the tools to be used. tools is used to indicate what exact
	// version are in the contents of the tarball
	UnpackTools(tools *Tools, r io.Reader) error
Exemple #17
0
	"os"
	"path"
	"path/filepath"
	"sort"
	"time"

	"launchpad.net/loggo"

	"launchpad.net/juju-core/agent/tools"
	"launchpad.net/juju-core/environs"
	"launchpad.net/juju-core/environs/ec2"
	"launchpad.net/juju-core/utils"
	"launchpad.net/juju-core/version"
)

var logger = loggo.GetLogger("juju.environs.sync")

// DefaultToolsLocation leads to the default juju distribution on S3.
var DefaultToolsLocation = "https://juju-dist.s3.amazonaws.com/"

// SyncContext describes the context for tool synchronization.
type SyncContext struct {
	// EnvName names the target environment for synchronization.
	EnvName string

	// AllVersions controls the copy of all versions, not only the latest.
	AllVersions bool

	// DryRun controls that nothing is copied. Instead it's logged
	// what would be coppied.
	DryRun bool
Exemple #18
0
package main

import (
	"fmt"

	"github.com/benmanns/goworker"
	"launchpad.net/loggo"

	"github.com/hivetech/hivy/beacon"
)

var log = loggo.GetLogger("hivy.worker")

type hivyWorker struct {
	channel    string
	controller *beacon.Controller
}

func newHivyWorker() *hivyWorker {
	return &hivyWorker{
		channel: "Hivy",
		//TODO Hard coded
		controller: beacon.NewController("worker", false),
	}
}

func init() {
	//TODO Hard coded
	logfile := ""
	verbose := true
	modules := []string{"hivy.worker"}
Exemple #19
0
	"os"
	"os/exec"
	"path/filepath"
	"strconv"
	"strings"
	"sync"

	"github.com/ulrichSchreiner/carpo/workspace/builder"
	"github.com/ulrichSchreiner/carpo/workspace/filesystem"
	"github.com/ulrichSchreiner/gdbmi"
	"launchpad.net/loggo"
)

type buildType string

var workspaceLogger = loggo.GetLogger("workspace")

const (
	BUILD_GOLANG             = "golang"
	APPTYPE                  = "apptype"
	TYPE_GO        buildType = "go"
	TYPE_APPENGINE buildType = "appengine"

	SETTING_GOPATH    = "go_path"
	SETTING_GOAPPPATH = "goapp_path"
)

func (w *workspace) register(container *restful.Container) {
	var ws restful.WebService
	ws.
		Path("/workspace").
Exemple #20
0
package storage

import (
	"os"

	"launchpad.net/loggo"
	"launchpad.net/tomb"

	"launchpad.net/juju-core/environs/localstorage"
	"launchpad.net/juju-core/worker"
)

var logger = loggo.GetLogger("juju.local.storage")

type storageWorker struct {
	tomb tomb.Tomb
}

func NewWorker() worker.Worker {
	w := &storageWorker{}
	go func() {
		defer w.tomb.Done()
		w.tomb.Kill(w.waitForDeath())
	}()
	return w
}

// Kill implements worker.Worker.Kill.
func (s *storageWorker) Kill() {
	s.tomb.Kill(nil)
}
Exemple #21
0
// Licensed under the AGPLv3, see LICENCE file for details.
package machiner

import (
	"fmt"

	"launchpad.net/loggo"

	"launchpad.net/juju-core/errors"
	"launchpad.net/juju-core/state/api"
	"launchpad.net/juju-core/state/api/machiner"
	"launchpad.net/juju-core/state/api/params"
	"launchpad.net/juju-core/worker"
)

var logger = loggo.GetLogger("juju.worker.machiner")

// Machiner is responsible for a machine agent's lifecycle.
type Machiner struct {
	st      *machiner.State
	tag     string
	machine *machiner.Machine
}

// NewMachiner returns a Machiner that will wait for the identified machine
// to become Dying and make it Dead; or until the machine becomes Dead by
// other means.
func NewMachiner(st *machiner.State, tag string) worker.NotifyWorker {
	mr := &Machiner{st: st, tag: tag}
	return worker.NewNotifyWorker(mr)
}
Exemple #22
0
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package utils

import (
	"fmt"
	"os"
	"os/exec"
	"strings"

	"launchpad.net/juju-core/log"
	"launchpad.net/loggo"
)

var aptLogger = loggo.GetLogger("juju.utils.apt")

// Some helpful functions for running apt in a sane way

// commandOutput calls cmd.Output, this is used as an overloading point so we
// can test what *would* be run without actually executing another program
var commandOutput = (*exec.Cmd).CombinedOutput

// This is the default apt-get command used in cloud-init, the various settings
// mean that apt won't actually block waiting for a prompt from the user.
var aptGetCommand = []string{
	"apt-get", "--option=Dpkg::Options::=--force-confold",
	"--option=Dpkg::options::=--force-unsafe-io", "--assume-yes", "--quiet",
}

// aptEnvOptions are options we need to pass to apt-get to not have it prompt
Exemple #23
0
func (s *LxcSuite) SetUpTest(c *gc.C) {
	s.LoggingSuite.SetUpTest(c)
	s.TestSuite.SetUpTest(c)
	loggo.GetLogger("juju.container.lxc").SetLogLevel(loggo.TRACE)
}
Exemple #24
0
import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"launchpad.net/juju-core/environs"
	"launchpad.net/juju-core/environs/config"
	"launchpad.net/loggo"
)

// Register the Azure provider with Juju.
func init() {
	environs.RegisterProvider("azure", azureEnvironProvider{})
}

// Logger for the Azure provider.
var logger = loggo.GetLogger("juju.environs.azure")

type azureEnvironProvider struct{}

// azureEnvironProvider implements EnvironProvider.
var _ environs.EnvironProvider = (*azureEnvironProvider)(nil)

// Open is specified in the EnvironProvider interface.
func (prov azureEnvironProvider) Open(cfg *config.Config) (environs.Environ, error) {
	logger.Debugf("opening environment %q.", cfg.Name())
	// We can't return NewEnviron(cfg) directly here because otherwise,
	// when err is not nil, we end up with a non-nil returned environ and
	// this breaks the loop in cmd/jujud/upgrade.go:run() (see
	// http://golang.org/doc/faq#nil_error for the gory details).
	environ, err := NewEnviron(cfg)
	if err != nil {
Exemple #25
0
	"regexp"
	"strings"
	"time"

	"labix.org/v2/mgo"
	"launchpad.net/loggo"
	"launchpad.net/tomb"

	"launchpad.net/juju-core/environs/config"
	"launchpad.net/juju-core/errors"
	"launchpad.net/juju-core/instance"
	"launchpad.net/juju-core/state/watcher"
	"launchpad.net/juju-core/utils/set"
)

var watchLogger = loggo.GetLogger("juju.state.watch")

// NotifyWatcher generates signals when something changes, but it does not
// return any content for those changes
type NotifyWatcher interface {
	Stop() error
	Err() error
	Changes() <-chan struct{}
}

// StringsWatcher generates signals when something changes, returning
// the changes as a list of strings.
type StringsWatcher interface {
	Stop() error
	Err() error
	Changes() <-chan []string
Exemple #26
0
import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"time"

	"launchpad.net/loggo"

	"launchpad.net/juju-core/cert"
	"launchpad.net/juju-core/schema"
	"launchpad.net/juju-core/version"
)

var logger = loggo.GetLogger("juju.environs.config")

// FirewallMode defines the way in which the environment
// handles opening and closing of firewall ports.
type FirewallMode string

const (
	// FwDefault is the environment-specific default mode.
	FwDefault FirewallMode = ""

	// FwInstance requests the use of an individual firewall per instance.
	FwInstance FirewallMode = "instance"

	// FwGlobal requests the use of a single firewall group for all machines.
	// When ports are opened for one machine, all machines will have the same
	// port opened.
Exemple #27
0
	"time"

	"github.com/ulrichSchreiner/carpo/client"
	"github.com/ulrichSchreiner/carpo/workspace"
	"launchpad.net/loggo"
)

var port = flag.Int("port", 8787, "the port to use for carpo")
var clientpath = flag.String("clientpath", "", "the path to the client resource directory (should contain an index.html file)")
var wks = flag.String("workspace", "", "the path to the workspace")
var browser = flag.Bool("browser", false, "start a browser with the server URL")
var loglevel = flag.String("loglevel", "TRACE", "root loglevel")

var carpo_version string

var logger = loggo.GetLogger("main")

func main() {
	flag.Parse()

	loggo.ConfigureLoggers(fmt.Sprintf("<root>=%s", *loglevel))
	if carpo_version == "" {
		carpo_version = fmt.Sprintf("%d", time.Now().Unix())
	}
	logger.Infof("carpo '%s' started at port %d...\n", carpo_version, *port)

	ws := wks
	if ws == nil {
		wd, err := os.Getwd()
		if err != nil {
			log.Fatal(err)
Exemple #28
0
package hivy

import (
	"github.com/bitly/go-simplejson"
	"github.com/emicklei/go-restful"
	"launchpad.net/loggo"
)

var log = loggo.GetLogger("hivy.endpoint")

// JSON converts string to simple.Json object
func JSON(data string) *simplejson.Json {
	json, err := simplejson.NewJson([]byte(data))
	if err != nil {
		panic(err)
	}
	return json
}

// EmptyJSON is a commodity shortcut
func EmptyJSON() *simplejson.Json {
	return JSON("{}")
}

/*
 * Note:
 * Route{method:   restful.WebService.GET,
 *       path:     "GET /path/{with}/{parameters},
 *       endpoint: Dummy
 * }
 */
Exemple #29
0
	"launchpad.net/tomb"

	"launchpad.net/juju-core/agent/tools"
	"launchpad.net/juju-core/environs"
	"launchpad.net/juju-core/environs/config"
	"launchpad.net/juju-core/instance"
	"launchpad.net/juju-core/state"
	"launchpad.net/juju-core/state/watcher"
	"launchpad.net/juju-core/version"
	"launchpad.net/juju-core/worker"
)

type ProvisionerType string

var (
	logger = loggo.GetLogger("juju.provisioner")

	// ENVIRON provisioners create machines from the environment
	ENVIRON ProvisionerType = "environ"
	// LXC provisioners create lxc containers on their parent machine
	LXC ProvisionerType = "lxc"
)

// Provisioner represents a running provisioning worker.
type Provisioner struct {
	pt        ProvisionerType
	st        *state.State
	machineId string // Which machine runs the provisioner.
	dataDir   string
	machine   *state.Machine
	environ   environs.Environ
Exemple #30
0
	"launchpad.net/loggo"

	"launchpad.net/juju-core/agent"
	"launchpad.net/juju-core/container/lxc"
	"launchpad.net/juju-core/environs/provider"
	"launchpad.net/juju-core/instance"
	"launchpad.net/juju-core/state"
	"launchpad.net/juju-core/state/api"
	"launchpad.net/juju-core/utils"
	"launchpad.net/juju-core/utils/fslock"
)

// Functions in this package are here to help us with post-upgrade installing,
// etc. It is used to validate the system status after we have upgraded.

var validationLogger = loggo.GetLogger("juju.jujud.validation")

var lockTimeout = 1 * time.Minute

// getUniterLock grabs the "uniter-hook-execution" lock and holds it, or an error
func getUniterLock(dataDir, message string) (*fslock.Lock, error) {
	// Taken from worker/uniter/uniter.go setupLocks()
	lockDir := filepath.Join(dataDir, "locks")
	hookLock, err := fslock.NewLock(lockDir, "uniter-hook-execution")
	if err != nil {
		return nil, err
	}
	err = hookLock.LockWithTimeout(lockTimeout, message)
	if err != nil {
		return nil, err
	}