Beispiel #1
func (s *AssignSuite) assertAssignUnitToNewMachineContainerConstraint(c *C) {
	unit, err := s.wordpress.AddUnit()
	c.Assert(err, IsNil)
	err = unit.AssignToNewMachine()
	c.Assert(err, IsNil)
	machineId := s.assertAssignedUnit(c, unit)
	c.Assert(state.ParentId(machineId), Not(Equals), "")
	c.Assert(state.ContainerTypeFromId(machineId), Equals, instance.LXC)
Beispiel #2
// EnsureWeHaveLXC checks if we have lxc installed, and installs it if we
// don't. Juju 1.11 added the ability to deploy into LXC containers, and uses
// functionality from the lxc package in order to do so. Juju 1.10 did not
// install lxc, so we ensure it is installed.
// See
// dataDir is the root location where data files are put. It is used to grab
// the uniter-hook-execution lock so that we don't try run to apt-get at the
// same time that a hook might want to run it.
func EnsureWeHaveLXC(dataDir, machineTag string) error {
	// We need to short circuit this in two places:
	//   1. if we are running a local provider, then the machines are lxc
	//     containers, and if we install lxc on them, it adds an lxc bridge
	//     network device with the same ip address as the hosts bridge.  This
	//     screws up all the networking routes.
	//   2. if the machine is an lxc container, we need to avoid installing lxc
	//     package for exactly the same reasons.
	// Later, post-precise LTS, when we have updated lxc, we can bring this
	// back in to have nested lxc, but until then, we have to avoid it.
	containerType := state.ContainerTypeFromId(state.MachineIdFromTag(machineTag))
	providerType := os.Getenv("JUJU_PROVIDER_TYPE")
	if providerType == provider.Local || containerType == instance.LXC {
		return nil
	manager := lxc.NewContainerManager(lxc.ManagerConfig{Name: "lxc-test"})
	if _, err := manager.ListContainers(); err == nil {
		validationLogger.Debugf("found lxc, not installing")
		// We already have it, nothing more to do
		return nil
	validationLogger.Debugf("got error looking for lxc, attempting to install")
	if dataDir != "" {
		lock, err := getUniterLock(dataDir, "apt-get install lxc for juju 1.11 upgrade")
		if err == nil {
			defer lock.Unlock()
		} else {
			validationLogger.Warningf("Failed to acquire lock: %v, will try to install lxc anyway", lock)
		// If we got an error trying to acquire the lock, we try to install
		// lxc anyway. Worst case the install will fail, which is where we
		// are already
	// TODO: This is not platform independent. If jujud is running on
	//       something other than a debian-based Linux, and we are missing
	//       lxc, this call will always fail. However, in juju 1.11+ we
	//       install lxc via cloud-init or whatever bootstrap code we use.
	//       So this is really only upgrade compatibility and juju 1.10
	//       only supports debian-based anyway
	return utils.AptGetInstall("lxc")