Skip to content

Commit

Permalink
Merge pull request juju#9220 from hmlanigan/use-profile
Browse files Browse the repository at this point in the history
juju#9220

$pr_descr
  • Loading branch information
jujubot authored Sep 26, 2018
2 parents 2107f5c + 186e745 commit 2a1d0f5
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apiserver/facades/agent/provisioner/provisioninginfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ func (p *ProvisionerAPI) getProvisioningInfo(m *state.Machine, env environs.Envi
// TODO: lxd-profile 2018-09-18
// Add withoutControllerSuite.TestProvisioningInfoWithLXDProfile when
// lxd profiles added to ProvisioningInfo.
var pNames []string
if featureflag.Enabled(feature.LXDProfile) {
_, err = p.machineLXDProfiles(m, env)
pNames, err = p.machineLXDProfiles(m, env)
if err != nil {
return nil, errors.Annotate(err, "cannot write lxd profiles")
}
Expand Down Expand Up @@ -121,6 +122,7 @@ func (p *ProvisionerAPI) getProvisioningInfo(m *state.Machine, env environs.Envi
ImageMetadata: imageMetadata,
ControllerConfig: controllerCfg,
CloudInitUserData: env.Config().CloudInitUserData(),
CharmLXDProfiles: pNames,
}, nil
}

Expand Down
57 changes: 57 additions & 0 deletions apiserver/facades/agent/provisioner/provisioninginfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package provisioner_test

import (
"fmt"
"os"

jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"gopkg.in/juju/names.v2"
Expand All @@ -13,6 +16,8 @@ import (
apiservertesting "github.com/juju/juju/apiserver/testing"
"github.com/juju/juju/constraints"
"github.com/juju/juju/environs/tags"
"github.com/juju/juju/feature"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/juju/testing"
"github.com/juju/juju/provider/dummy"
"github.com/juju/juju/state"
Expand Down Expand Up @@ -279,6 +284,58 @@ func (s *withoutControllerSuite) TestProvisioningInfoWithUnsuitableSpacesConstra
c.Assert(result, jc.DeepEquals, expected)
}

func (s *withoutControllerSuite) TestProvisioningInfoWithLXDProfile(c *gc.C) {
// TODO (hml) lxd-profile
// enable this test once charmrepo test accepts charms with an lxdprofile
c.Skip("will fail until charm.v6 lxdprofile functionality added to charmrepo testing")
err := os.Setenv(osenv.JujuFeatureFlagEnvKey, feature.LXDProfile)
c.Assert(err, jc.ErrorIsNil)
defer os.Unsetenv(osenv.JujuFeatureFlagEnvKey)

profileMachine, err := s.State.AddOneMachine(state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
})
c.Assert(err, jc.ErrorIsNil)

profileCharm := s.AddTestingCharm(c, "lxd-profile")
profileService := s.AddTestingApplication(c, "lxd-profile", profileCharm)
profileUnit, err := profileService.AddUnit(state.AddUnitParams{})
c.Assert(err, jc.ErrorIsNil)
err = profileUnit.AssignToMachine(profileMachine)
c.Assert(err, jc.ErrorIsNil)

args := params.Entities{Entities: []params.Entity{
{Tag: profileMachine.Tag().String()},
}}
result, err := s.provisioner.ProvisioningInfo(args)
c.Assert(err, jc.ErrorIsNil)

controllerCfg := coretesting.FakeControllerConfig()
// Dummy provider uses a random port, which is added to cfg used to create environment.
apiPort := dummy.APIPort(s.Environ.Provider())
controllerCfg["api-port"] = apiPort

pName := fmt.Sprintf("juju-%s-lxd-profile-0", coretesting.ModelConfig(c).Name())
expected := params.ProvisioningInfoResults{
Results: []params.ProvisioningInfoResult{{
Result: &params.ProvisioningInfo{
ControllerConfig: controllerCfg,
Series: "quantal",
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
Tags: map[string]string{
tags.JujuController: coretesting.ControllerTag.Id(),
tags.JujuModel: coretesting.ModelTag.Id(),
tags.JujuMachine: "controller-machine-5",
tags.JujuUnitsDeployed: profileUnit.Name(),
},
EndpointBindings: map[string]string{},
CharmLXDProfiles: []string{pName},
},
}}}
c.Assert(result, jc.DeepEquals, expected)
}

func (s *withoutControllerSuite) TestStorageProviderFallbackToType(c *gc.C) {
template := state.MachineTemplate{
Series: "quantal",
Expand Down
1 change: 1 addition & 0 deletions apiserver/params/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ type ProvisioningInfo struct {
EndpointBindings map[string]string `json:"endpoint-bindings,omitempty"`
ControllerConfig map[string]interface{} `json:"controller-config,omitempty"`
CloudInitUserData map[string]interface{} `json:"cloudinit-userdata,omitempty"`
CharmLXDProfiles []string `json:"charm-lxd-profiles,omitempty"`
}

// ProvisioningInfoResult holds machine provisioning info or an error.
Expand Down
5 changes: 5 additions & 0 deletions environs/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ type StartInstanceParams struct {
// Abort is a channel that will be closed to indicate that the command
// should be aborted.
Abort <-chan struct{}

// CharmLXDProfiles is a slice of names of lxd profiles to be used creating
// the LXD container, if specified and an LXD container. The profiles
// come from charms deployed on the machine.
CharmLXDProfiles []string
}

// StartInstanceResult holds the result of an
Expand Down
6 changes: 6 additions & 0 deletions provider/dummy/environs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/juju/utils/arch"
"github.com/juju/version"
gc "gopkg.in/check.v1"
"gopkg.in/juju/charm.v6"
"gopkg.in/juju/environschema.v1"
"gopkg.in/juju/names.v2"
"gopkg.in/juju/worker.v1"
Expand Down Expand Up @@ -1844,6 +1845,11 @@ func (*environ) AreSpacesRoutable(ctx context.ProviderCallContext, space1, space
return false, nil
}

// MaybeWriteLXDProfile implements environs.LXDProfiler.
func (env *environ) MaybeWriteLXDProfile(pName string, put *charm.LXDProfile) error {
return nil
}

// SSHAddresses implements environs.SSHAddresses.
// For testing we cut "100.100.100.100" out of this list.
func (*environ) SSHAddresses(ctx context.ProviderCallContext, addresses []network.Address) ([]network.Address, error) {
Expand Down
2 changes: 1 addition & 1 deletion provider/lxd/environ_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (env *environ) getContainerSpec(
}
cSpec := lxd.ContainerSpec{
Name: hostname,
Profiles: []string{"default", env.profileName()},
Profiles: append([]string{"default", env.profileName()}, args.CharmLXDProfiles...),
Image: image,
Config: make(map[string]string),
}
Expand Down
37 changes: 37 additions & 0 deletions provider/lxd/environ_broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,43 @@ func (s *environBrokerSuite) TestStartInstanceWithConstraints(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
}

func (s *environBrokerSuite) TestStartInstanceWithCharmLXDProfile(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()
svr := lxd.NewMockServer(ctrl)

// Check that the lxd profile name was passed through to spec.Config.
check := func(spec containerlxd.ContainerSpec) bool {
profiles := spec.Profiles
if len(profiles) != 3 {
return false
}
if profiles[0] != "default" {
return false
}
if profiles[1] != "juju-" {
return false
}
return profiles[2] == "juju-model-test-0"
}

exp := svr.EXPECT()
gomock.InOrder(
exp.HostArch().Return(arch.AMD64),
exp.FindImage("bionic", arch.AMD64, gomock.Any(), true, gomock.Any()).Return(containerlxd.SourcedImage{}, nil),
exp.GetNICsFromProfile("default").Return(s.defaultProfile.Devices, nil),
exp.CreateContainerFromSpec(matchesContainerSpec(check)).Return(&containerlxd.Container{}, nil),
exp.HostArch().Return(arch.AMD64),
)

args := s.GetStartInstanceArgs(c, "bionic")
args.CharmLXDProfiles = []string{"juju-model-test-0"}

env := s.NewEnviron(c, svr, nil)
_, err := env.StartInstance(s.callCtx, args)
c.Assert(err, jc.ErrorIsNil)
}

func (s *environBrokerSuite) TestStartInstanceNoTools(c *gc.C) {
ctrl := gomock.NewController(c)
defer ctrl.Finish()
Expand Down
1 change: 1 addition & 0 deletions worker/provisioner/provisioner_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ func (task *provisionerTask) constructStartInstanceParams(
ImageMetadata: possibleImageMetadata,
StatusCallback: machine.SetInstanceStatus,
Abort: task.catacomb.Dying(),
CharmLXDProfiles: provisioningInfo.CharmLXDProfiles,
}

return startInstanceParams, nil
Expand Down

0 comments on commit 2a1d0f5

Please sign in to comment.