Skip to content

Commit 53d1bf2

Browse files
committed
Merge changes from 2.4 branch.
2 parents 62ab711 + bc96a4d commit 53d1bf2

File tree

29 files changed

+484
-86
lines changed

29 files changed

+484
-86
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,21 @@ Installing prerequisites
9696

9797
### *Making use of Makefile*
9898

99-
The `juju` repository contains a `Makefile`, which is the preferred way to install dependencies and other features.
100-
It is advisable, when installing `juju` from source, to look at the [Makefile](./Makefile), located in `$GOPATH/src/github.com/juju/juju/Makefile`.
99+
The `juju` repository contains a `Makefile`, which is the preferred way to
100+
install dependencies and other features. It is advisable, when installing
101+
`juju` from source, to look at the [Makefile](./Makefile), located in
102+
`$GOPATH/src/github.com/juju/juju/Makefile`.
101103

102104
### *Dependencies*
103105

104106
Juju needs some dependencies in order to be installed and the preferred way to
105107
collect the necessary packages is to use the provided `Makefile`.
108+
<<<<<<< HEAD
106109
The target `dep` will download the go packages listed in `Gopkg.lock`. The following bash code will install the dependencies.
110+
=======
111+
The target `godeps` will download the go packages listed in `dependencies.tsv`.
112+
The following bash code will install the dependencies.
113+
>>>>>>> upstream/2.4
107114
108115
cd $GOPATH/src/github.com/juju/juju
109116
export JUJU_MAKE_GODEPS=true

apiserver/common/crossmodel/state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func (p *statePoolShim) Get(modelUUID string) (Backend, func(), error) {
3131
}
3232
model, err := st.Model()
3333
if err != nil {
34-
return stateShim{}, closer, err
34+
closer()
35+
return nil, nil, err
3536
}
3637
return stateShim{st.State, model}, closer, err
3738
}

apiserver/common/modelmanagerinterface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func (st modelManagerStateShim) GetBackend(modelUUID string) (ModelManagerBacken
151151
}
152152
otherModel, err := otherState.Model()
153153
if err != nil {
154+
otherState.Release()
154155
return nil, nil, err
155156
}
156157
return modelManagerStateShim{otherState.State, otherModel, st.pool}, otherState.Release, nil

apiserver/common/storagecommon/blockdevices.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
package storagecommon
55

66
import (
7+
"github.com/juju/loggo"
8+
79
"github.com/juju/juju/state"
810
"github.com/juju/juju/storage"
911
)
1012

13+
var logger = loggo.GetLogger("juju.apiserver.storagecommon")
14+
1115
// BlockDeviceFromState translates a state.BlockDeviceInfo to a
1216
// storage.BlockDevice.
1317
func BlockDeviceFromState(in state.BlockDeviceInfo) storage.BlockDevice {
@@ -34,6 +38,7 @@ func MatchingBlockDevice(
3438
attachmentInfo state.VolumeAttachmentInfo,
3539
planBlockInfo state.BlockDeviceInfo,
3640
) (*state.BlockDeviceInfo, bool) {
41+
logger.Tracef("looking for block device for volume %#v", volumeInfo)
3742
for _, dev := range blockDevices {
3843
if planBlockInfo.HardwareId != "" {
3944
if planBlockInfo.HardwareId == dev.HardwareId {
@@ -56,18 +61,21 @@ func MatchingBlockDevice(
5661
if volumeInfo.WWN == dev.WWN {
5762
return &dev, true
5863
}
64+
logger.Tracef("no match for block device WWN: %v", dev.WWN)
5965
continue
6066
}
6167
if volumeInfo.HardwareId != "" {
6268
if volumeInfo.HardwareId == dev.HardwareId {
6369
return &dev, true
6470
}
71+
logger.Tracef("no match for block device hardware id: %v", dev.HardwareId)
6572
continue
6673
}
6774
if attachmentInfo.BusAddress != "" {
6875
if attachmentInfo.BusAddress == dev.BusAddress {
6976
return &dev, true
7077
}
78+
logger.Tracef("no match for block device bus address: %v", dev.BusAddress)
7179
continue
7280
}
7381
if attachmentInfo.DeviceLink != "" {
@@ -76,11 +84,13 @@ func MatchingBlockDevice(
7684
return &dev, true
7785
}
7886
}
87+
logger.Tracef("no match for block device dev links: %v", dev.DeviceLinks)
7988
continue
8089
}
8190
if attachmentInfo.DeviceName == dev.DeviceName {
8291
return &dev, true
8392
}
93+
logger.Tracef("no match for block device name: %v", dev.DeviceName)
8494
}
8595
return nil, false
8696
}

cloudconfig/cloudinit/network_ubuntu.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,5 @@ if __name__ == "__main__":
432432
main()
433433
`
434434

435-
const CloudInitNetworkConfigDisabled = `network:
436-
config: "disabled"
435+
const CloudInitNetworkConfigDisabled = `config: "disabled"
437436
`

cmd/juju/cloud/list_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func (s *listSuite) TestListPublic(c *gc.C) {
2929
c.Assert(err, jc.ErrorIsNil)
3030
out := cmdtesting.Stdout(ctx)
3131
out = strings.Replace(out, "\n", "", -1)
32+
3233
// Check that we are producing the expected fields
3334
c.Assert(out, gc.Matches, `Cloud Regions Default Type Description.*`)
3435
// // Just check couple of snippets of the output to make sure it looks ok.

cmd/jujud/agent/machine.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,9 @@ func (a *MachineAgent) Run(*cmd.Context) (err error) {
459459
}
460460

461461
agentConfig := a.CurrentConfig()
462+
agentName := a.Tag().String()
462463
machineLock, err := machinelock.New(machinelock.Config{
463-
AgentName: a.Tag().String(),
464+
AgentName: agentName,
464465
Clock: clock.WallClock,
465466
Logger: loggo.GetLogger("juju.machinelock"),
466467
LogFilename: agent.MachineLockLogFilename(agentConfig),
@@ -473,7 +474,7 @@ func (a *MachineAgent) Run(*cmd.Context) (err error) {
473474
a.machineLock = machineLock
474475
a.upgradeComplete = upgradesteps.NewLock(agentConfig)
475476

476-
createEngine := a.makeEngineCreator(agentConfig.UpgradedToVersion())
477+
createEngine := a.makeEngineCreator(agentName, agentConfig.UpgradedToVersion())
477478
charmrepo.CacheDir = filepath.Join(agentConfig.DataDir(), "charmcache")
478479
if err := a.createJujudSymlinks(agentConfig.DataDir()); err != nil {
479480
return err
@@ -496,7 +497,7 @@ func (a *MachineAgent) Run(*cmd.Context) (err error) {
496497
return cmdutil.AgentDone(logger, err)
497498
}
498499

499-
func (a *MachineAgent) makeEngineCreator(previousAgentVersion version.Number) func() (worker.Worker, error) {
500+
func (a *MachineAgent) makeEngineCreator(agentName string, previousAgentVersion version.Number) func() (worker.Worker, error) {
500501
return func() (worker.Worker, error) {
501502
engine, err := dependency.NewEngine(dependencyEngineConfig())
502503
if err != nil {
@@ -549,6 +550,7 @@ func (a *MachineAgent) makeEngineCreator(previousAgentVersion version.Number) fu
549550

550551
manifolds := machineManifolds(machine.ManifoldsConfig{
551552
PreviousAgentVersion: previousAgentVersion,
553+
AgentName: agentName,
552554
Agent: agent.APIHostPortsSetter{Agent: a},
553555
RootDir: a.rootDir,
554556
AgentConfigChanged: a.configChangedVal,

cmd/jujud/agent/machine/manifolds.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ const (
108108
// ManifoldsConfig allows specialisation of the result of Manifolds.
109109
type ManifoldsConfig struct {
110110

111+
// AgentName is the name of the machine agent, like "machine-12".
112+
// This will never change during the execution of an agent, and
113+
// is used to provide this as config into a worker rather than
114+
// making the worker get it from the agent worker itself.
115+
AgentName string
116+
111117
// Agent contains the agent that will be wrapped and made available to
112118
// its dependencies via a dependency.Engine.
113119
Agent coreagent.Agent
@@ -735,6 +741,7 @@ func Manifolds(config ManifoldsConfig) dependency.Manifolds {
735741
APIServerName: apiServerName,
736742
RaftTransportName: raftTransportName,
737743
PrometheusRegisterer: config.PrometheusRegisterer,
744+
AgentName: config.AgentName,
738745
Clock: config.Clock,
739746
GetControllerConfig: httpserver.GetControllerConfig,
740747
NewTLSConfig: httpserver.NewTLSConfig,

container/lxd/export_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func PatchGenerateVirtualMACAddress(patcher patcher) {
4040
})
4141
}
4242

43+
func PatchLXDViaSnap(patcher patcher, isSnap bool) {
44+
patcher.PatchValue(&lxdViaSnap, func() bool { return isSnap })
45+
}
46+
4347
func GetImageSources(mgr container.Manager) ([]ServerSpec, error) {
4448
return mgr.(*containerManager).getImageSources()
4549
}

container/lxd/initialisation_linux.go

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/juju/packaging/manager"
2222
"github.com/juju/proxy"
2323
"github.com/juju/utils/series"
24+
"github.com/lxc/lxd/shared"
2425

2526
"github.com/juju/juju/container"
2627
"github.com/juju/juju/service"
@@ -255,7 +256,12 @@ func editLXDBridgeFile(input string, subnet string) string {
255256
// apt.GetInstall.
256257
func ensureDependencies(series string) error {
257258
if series == "precise" {
258-
return fmt.Errorf("LXD is not supported in precise.")
259+
return errors.NotSupportedf(`LXD containers on series "precise"`)
260+
}
261+
262+
if lxdViaSnap() {
263+
logger.Infof("LXD snap is installed; skipping package installation")
264+
return nil
259265
}
260266

261267
pacman, err := getPackageManager(series)
@@ -286,6 +292,12 @@ func ensureDependencies(series string) error {
286292
return errors.Trace(err)
287293
}
288294

295+
// lxdViaSnap interrogates the location of the Snap LXD socket in order
296+
// to determine if LXD is being provided via that method.
297+
var lxdViaSnap = func() bool {
298+
return shared.IsUnixSocket("/var/snap/lxd/common/lxd/unix.socket")
299+
}
300+
289301
// randomizedOctetRange is a variable for testing purposes.
290302
var randomizedOctetRange = func() []int {
291303
rand.Seed(time.Now().UnixNano())
@@ -376,26 +388,22 @@ func parseLXDBridgeConfigValues(input string) map[string]string {
376388

377389
for _, line := range strings.Split(input, "\n") {
378390
line = strings.TrimSpace(line)
379-
380391
if line == "" || strings.HasPrefix(line, "#") || !strings.Contains(line, "=") {
381392
continue
382393
}
383394

384395
tokens := strings.Split(line, "=")
385-
386396
if tokens[0] == "" {
387397
continue // no key
388398
}
389399

390400
value := ""
391-
392401
if len(tokens) > 1 {
393402
value = tokens[1]
394403
if strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`) {
395404
value = strings.Trim(value, `"`)
396405
}
397406
}
398-
399407
values[tokens[0]] = value
400408
}
401409
return values
@@ -424,41 +432,44 @@ func bridgeConfiguration(input string) (string, error) {
424432
var IsRunningLocally = isRunningLocally
425433

426434
func isRunningLocally() (bool, error) {
427-
installed, err := IsInstalledLocally()
428-
if err != nil {
429-
return installed, errors.Trace(err)
430-
}
431-
if !installed {
432-
return false, nil
435+
svcName, err := InstalledServiceName()
436+
if svcName == "" || err != nil {
437+
return false, errors.Trace(err)
433438
}
434439

435440
hostSeries, err := series.HostSeries()
436441
if err != nil {
437442
return false, errors.Trace(err)
438443
}
439-
svc, err := service.NewService("lxd", common.Conf{}, hostSeries)
444+
445+
svc, err := service.NewService(svcName, common.Conf{}, hostSeries)
440446
if err != nil {
441447
return false, errors.Trace(err)
442448
}
443-
444449
running, err := svc.Running()
445450
if err != nil {
446451
return running, errors.Trace(err)
447452
}
448-
449453
return running, nil
450454
}
451455

452-
// IsInstalledLocally returns true if LXD is installed locally.
453-
func IsInstalledLocally() (bool, error) {
456+
// InstalledServiceName returns the name of the running service for the LXD
457+
// daemon. If LXD is not installed, the return is an empty string.
458+
func InstalledServiceName() (string, error) {
454459
names, err := service.ListServices()
455460
if err != nil {
456-
return false, errors.Trace(err)
461+
return "", errors.Trace(err)
457462
}
463+
464+
// Prefer the Snap service.
465+
svcName := ""
458466
for _, name := range names {
467+
if name == "snap.lxd.daemon" {
468+
return name, nil
469+
}
459470
if name == "lxd" {
460-
return true, nil
471+
svcName = name
461472
}
462473
}
463-
return false, nil
474+
return svcName, nil
464475
}

container/lxd/initialisation_test.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,40 @@ func getMockRunCommandWithRetry(calledCmds *[]string) func(string, func(string)
110110
}
111111

112112
func (s *InitialiserSuite) TestLTSSeriesPackages(c *gc.C) {
113-
// Momentarily, the only series with a dedicated cloud archive is precise,
114-
// which we will use for the following test:
115113
paccmder, err := commands.NewPackageCommander("trusty")
116114
c.Assert(err, jc.ErrorIsNil)
117115

116+
PatchLXDViaSnap(s, false)
118117
s.PatchValue(&series.MustHostSeries, func() string { return "trusty" })
119-
container := NewContainerInitialiser("trusty")
120118

121-
err = container.Initialise()
119+
err = NewContainerInitialiser("trusty").Initialise()
122120
c.Assert(err, jc.ErrorIsNil)
123121

124122
c.Assert(s.calledCmds, gc.DeepEquals, []string{
125123
paccmder.InstallCmd("--target-release", "trusty-backports", "lxd"),
126124
})
127125
}
128126

127+
func (s *InitialiserSuite) TestSnapInstalledNoAptInstall(c *gc.C) {
128+
PatchLXDViaSnap(s, true)
129+
s.PatchValue(&series.MustHostSeries, func() string { return "cosmic" })
130+
131+
err := NewContainerInitialiser("cosmic").Initialise()
132+
c.Assert(err, jc.ErrorIsNil)
133+
134+
c.Assert(s.calledCmds, gc.DeepEquals, []string{})
135+
}
136+
129137
func (s *InitialiserSuite) TestNoSeriesPackages(c *gc.C) {
138+
PatchLXDViaSnap(s, false)
139+
130140
// Here we want to test for any other series whilst avoiding the
131141
// possibility of hitting a cloud archive-requiring release.
132142
// As such, we simply pass an empty series.
133143
paccmder, err := commands.NewPackageCommander("xenial")
134144
c.Assert(err, jc.ErrorIsNil)
135145

136-
container := NewContainerInitialiser("")
137-
138-
err = container.Initialise()
146+
err = NewContainerInitialiser("").Initialise()
139147
c.Assert(err, jc.ErrorIsNil)
140148

141149
c.Assert(s.calledCmds, gc.DeepEquals, []string{

network/containerizer/bridgepolicy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ var skippedDeviceNames = set.NewStrings(
180180
// 2. Add b- to device name, if it doesn't fit in 15 characters then:
181181
// 3a. For devices starting in 'en' remove 'en' and add 'b-'
182182
// 3b. For all other devices 'b-' + 6-char hash of name + '-' + last 6 chars of name
183+
// 4. If using the device name directly always replace '.' with '-', to make sure that bridges from VLANs won't break
183184
func BridgeNameForDevice(device string) string {
185+
device = strings.Replace(device, ".", "-", -1)
184186
switch {
185187
case len(device) < 13:
186188
return fmt.Sprintf("br-%s", device)

0 commit comments

Comments
 (0)