Skip to content

Commit

Permalink
Remove lxc and convert to lxd where needed
Browse files Browse the repository at this point in the history
We no longer need to support lxc containers directly, instead we should
be using lxd containers.  Thus, a lot of code needed a simple
s/lxc/lxd.  Much of the code removed in this patch was options for
twiddling with lxc that are not needed or supported for lxd.
  • Loading branch information
natefinch committed Jun 14, 2016
1 parent 40673e3 commit c96e51d
Show file tree
Hide file tree
Showing 91 changed files with 544 additions and 6,171 deletions.
2 changes: 1 addition & 1 deletion api/firewaller/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *stateSuite) TestWatchModelMachines(c *gc.C) {
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
_, err = s.State.AddMachineInsideMachine(template, s.machines[0].Id(), instance.LXC)
_, err = s.State.AddMachineInsideMachine(template, s.machines[0].Id(), instance.LXD)
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
}
Expand Down
96 changes: 10 additions & 86 deletions api/provisioner/provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/juju/juju/feature"
"github.com/juju/juju/instance"
"github.com/juju/juju/juju/testing"
"github.com/juju/juju/mongo/mongotest"
"github.com/juju/juju/network"
"github.com/juju/juju/state"
"github.com/juju/juju/status"
Expand Down Expand Up @@ -465,15 +464,15 @@ func (s *provisionerSuite) TestWatchContainers(c *gc.C) {
apiMachine, err := s.provisioner.Machine(s.machine.Tag().(names.MachineTag))
c.Assert(err, jc.ErrorIsNil)

// Add one LXC container.
// Add one LXD container.
template := state.MachineTemplate{
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
container, err := s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
container, err := s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXD)
c.Assert(err, jc.ErrorIsNil)

w, err := apiMachine.WatchContainers(instance.LXC)
w, err := apiMachine.WatchContainers(instance.LXD)
c.Assert(err, jc.ErrorIsNil)
wc := watchertest.NewStringsWatcherC(c, w, s.BackingState.StartSync)
defer wc.AssertStops()
Expand All @@ -492,8 +491,8 @@ func (s *provisionerSuite) TestWatchContainers(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()

// Add another LXC container and make sure it's detected.
container, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
// Add another LXD container and make sure it's detected.
container, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXD)
c.Assert(err, jc.ErrorIsNil)
wc.AssertChange(container.Id())
}
Expand Down Expand Up @@ -546,7 +545,7 @@ func (s *provisionerSuite) TestWatchModelMachines(c *gc.C) {
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
_, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
_, err = s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXD)
c.Assert(err, jc.ErrorIsNil)
wc.AssertNoChange()
}
Expand Down Expand Up @@ -592,57 +591,6 @@ func (s *provisionerSuite) TestContainerManagerConfigKVM(c *gc.C) {
})
}

func (s *provisionerSuite) TestContainerManagerConfigLXC(c *gc.C) {
args := params.ContainerManagerConfigParams{Type: instance.LXC}
st, err := state.Open(s.State.ModelTag(), s.MongoInfo(c), mongotest.DialOpts(), state.Policy(nil))
c.Assert(err, jc.ErrorIsNil)
defer st.Close()

tests := []struct {
lxcUseClone bool
lxcUseCloneAufs bool
expectedUseClone string
expectedUseCloneAufs string
}{{
lxcUseClone: true,
expectedUseClone: "true",
expectedUseCloneAufs: "false",
}, {
lxcUseClone: false,
expectedUseClone: "false",
expectedUseCloneAufs: "false",
}, {
lxcUseCloneAufs: false,
expectedUseClone: "false",
expectedUseCloneAufs: "false",
}, {
lxcUseClone: true,
lxcUseCloneAufs: true,
expectedUseClone: "true",
expectedUseCloneAufs: "true",
}}

result, err := s.provisioner.ContainerManagerConfig(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.ManagerConfig[container.ConfigModelUUID], gc.Equals, coretesting.ModelTag.Id())
c.Assert(result.ManagerConfig["use-clone"], gc.Equals, "")

// Change lxc-clone, and ensure it gets picked up.
for i, t := range tests {
c.Logf("test %d: %+v", i, t)
err = st.UpdateModelConfig(map[string]interface{}{
"lxc-clone": t.lxcUseClone,
"lxc-clone-aufs": t.lxcUseCloneAufs,
}, nil, nil)
c.Assert(err, jc.ErrorIsNil)
result, err := s.provisioner.ContainerManagerConfig(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.ManagerConfig[container.ConfigModelUUID], gc.Equals, coretesting.ModelTag.Id())
c.Assert(result.ManagerConfig["use-clone"], gc.Equals, t.expectedUseClone)
c.Assert(result.ManagerConfig["use-aufs"], gc.Equals, t.expectedUseCloneAufs)
}
}

func (s *provisionerSuite) TestContainerManagerConfigPermissive(c *gc.C) {
// ContainerManagerConfig is permissive of container types, and
// will just return the basic type-independent configuration.
Expand All @@ -656,30 +604,6 @@ func (s *provisionerSuite) TestContainerManagerConfigPermissive(c *gc.C) {
})
}

func (s *provisionerSuite) TestContainerManagerConfigLXCDefaultMTU(c *gc.C) {
var resultConfig = map[string]string{
"lxc-default-mtu": "9000",
}
var called bool
provisioner.PatchFacadeCall(s, s.provisioner, func(request string, args, response interface{}) error {
called = true
c.Assert(request, gc.Equals, "ContainerManagerConfig")
expected := params.ContainerManagerConfigParams{
Type: instance.LXC,
}
c.Assert(args, gc.Equals, expected)
result := response.(*params.ContainerManagerConfig)
result.ManagerConfig = resultConfig
return nil
})

args := params.ContainerManagerConfigParams{Type: instance.LXC}
result, err := s.provisioner.ContainerManagerConfig(args)
c.Assert(called, jc.IsTrue)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.ManagerConfig, jc.DeepEquals, resultConfig)
}

func (s *provisionerSuite) TestContainerConfig(c *gc.C) {
result, err := s.provisioner.ContainerConfig()
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -691,14 +615,14 @@ func (s *provisionerSuite) TestContainerConfig(c *gc.C) {
func (s *provisionerSuite) TestSetSupportedContainers(c *gc.C) {
apiMachine, err := s.provisioner.Machine(s.machine.Tag().(names.MachineTag))
c.Assert(err, jc.ErrorIsNil)
err = apiMachine.SetSupportedContainers(instance.LXC, instance.KVM)
err = apiMachine.SetSupportedContainers(instance.LXD, instance.KVM)
c.Assert(err, jc.ErrorIsNil)

err = s.machine.Refresh()
c.Assert(err, jc.ErrorIsNil)
containers, ok := s.machine.SupportedContainers()
c.Assert(ok, jc.IsTrue)
c.Assert(containers, gc.DeepEquals, []instance.ContainerType{instance.LXC, instance.KVM})
c.Assert(containers, gc.DeepEquals, []instance.ContainerType{instance.LXD, instance.KVM})
}

func (s *provisionerSuite) TestSupportsNoContainers(c *gc.C) {
Expand Down Expand Up @@ -785,7 +709,7 @@ func (s *provisionerSuite) TestPrepareContainerInterfaceInfo(c *gc.C) {
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
container, err := s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
container, err := s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXD)
c.Assert(err, jc.ErrorIsNil)

ifaceInfo, err := s.provisioner.PrepareContainerInterfaceInfo(container.MachineTag())
Expand Down Expand Up @@ -824,7 +748,7 @@ func (s *provisionerSuite) TestReleaseContainerAddresses(c *gc.C) {
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
container, err := s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXC)
container, err := s.State.AddMachineInsideMachine(template, s.machine.Id(), instance.LXD)

// allocate some addresses to release
subInfo := state.SubnetInfo{
Expand Down
8 changes: 4 additions & 4 deletions apiserver/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *agentSuite) SetUpTest(c *gc.C) {
Series: "quantal",
Jobs: []state.MachineJob{state.JobHostUnits},
}
s.container, err = s.State.AddMachineInsideMachine(template, s.machine1.Id(), instance.LXC)
s.container, err = s.State.AddMachineInsideMachine(template, s.machine1.Id(), instance.LXD)
c.Assert(err, jc.ErrorIsNil)

s.resources = common.NewResources()
Expand Down Expand Up @@ -85,7 +85,7 @@ func (s *agentSuite) TestGetEntities(c *gc.C) {
Entities: []params.Entity{
{Tag: "machine-1"},
{Tag: "machine-0"},
{Tag: "machine-1-lxc-0"},
{Tag: "machine-1-lxd-0"},
{Tag: "machine-42"},
},
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *agentSuite) TestGetEntitiesContainer(c *gc.C) {
Entities: []params.Entity{
{Tag: "machine-1"},
{Tag: "machine-0"},
{Tag: "machine-1-lxc-0"},
{Tag: "machine-1-lxd-0"},
{Tag: "machine-42"},
},
}
Expand All @@ -129,7 +129,7 @@ func (s *agentSuite) TestGetEntitiesContainer(c *gc.C) {
{
Life: "dying",
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
ContainerType: instance.LXC,
ContainerType: instance.LXD,
},
{Error: apiservertesting.ErrUnauthorized},
},
Expand Down
8 changes: 0 additions & 8 deletions apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,14 +418,6 @@ func (srv *Server) endpoints() []apihttp.Endpoint {
)
add("/model/:modeluuid/api", mainAPIHandler)

add("/model/:modeluuid/images/:kind/:series/:arch/:filename",
&imagesDownloadHandler{
ctxt: httpCtxt,
dataDir: srv.dataDir,
state: srv.state,
},
)

endpoints = append(endpoints, guiEndpoints("/gui/:modeluuid/", srv.dataDir, httpCtxt)...)
add("/gui-archive", &guiArchiveHandler{
ctxt: httpCtxt,
Expand Down
8 changes: 4 additions & 4 deletions apiserver/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1713,15 +1713,15 @@ func (s *serviceSuite) TestAddServiceUnitsToNewContainer(c *gc.C) {
_, err = s.applicationApi.AddUnits(params.AddApplicationUnits{
ApplicationName: "dummy",
NumUnits: 1,
Placement: []*instance.Placement{instance.MustParsePlacement("lxc:" + machine.Id())},
Placement: []*instance.Placement{instance.MustParsePlacement("lxd:" + machine.Id())},
})
c.Assert(err, jc.ErrorIsNil)

units, err := svc.AllUnits()
c.Assert(err, jc.ErrorIsNil)
mid, err := units[0].AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
c.Assert(mid, gc.Equals, machine.Id()+"/lxc/0")
c.Assert(mid, gc.Equals, machine.Id()+"/lxd/0")
}

var addServiceUnitTests = []struct {
Expand All @@ -1740,8 +1740,8 @@ var addServiceUnitTests = []struct {
}, {
about: "direct machine assignment placement directive",
expected: []string{"dummy/1", "dummy/2"},
placement: []*instance.Placement{{"#", "1"}, {"lxc", "1"}},
machineIds: []string{"1", "1/lxc/0"},
placement: []*instance.Placement{{"#", "1"}, {"lxd", "1"}},
machineIds: []string{"1", "1/lxd/0"},
}, {
about: "invalid placement directive",
err: ".* invalid placement is invalid",
Expand Down
16 changes: 8 additions & 8 deletions apiserver/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,13 +1042,13 @@ func (s *clientSuite) TestClientAddMachineInsideMachine(c *gc.C) {

machines, err := s.APIState.Client().AddMachines([]params.AddMachineParams{{
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
ContainerType: instance.LXC,
ContainerType: instance.LXD,
ParentId: "0",
Series: "quantal",
}})
c.Assert(err, jc.ErrorIsNil)
c.Assert(machines, gc.HasLen, 1)
c.Assert(machines[0].Machine, gc.Equals, "0/lxc/0")
c.Assert(machines[0].Machine, gc.Equals, "0/lxd/0")
}

// updateConfig sets config variable with given key to a given value
Expand Down Expand Up @@ -1083,15 +1083,15 @@ func (s *clientSuite) TestClientAddMachinesWithPlacement(c *gc.C) {
Jobs: []multiwatcher.MachineJob{multiwatcher.JobHostUnits},
}
}
apiParams[0].Placement = instance.MustParsePlacement("lxc")
apiParams[1].Placement = instance.MustParsePlacement("lxc:0")
apiParams[1].ContainerType = instance.LXC
apiParams[0].Placement = instance.MustParsePlacement("lxd")
apiParams[1].Placement = instance.MustParsePlacement("lxd:0")
apiParams[1].ContainerType = instance.LXD
apiParams[2].Placement = instance.MustParsePlacement("controller:invalid")
apiParams[3].Placement = instance.MustParsePlacement("controller:valid")
machines, err := s.APIState.Client().AddMachines(apiParams)
c.Assert(err, jc.ErrorIsNil)
c.Assert(len(machines), gc.Equals, 4)
c.Assert(machines[0].Machine, gc.Equals, "0/lxc/0")
c.Assert(machines[0].Machine, gc.Equals, "0/lxd/0")
c.Assert(machines[1].Error, gc.ErrorMatches, "container type and placement are mutually exclusive")
c.Assert(machines[2].Error, gc.ErrorMatches, "cannot add a new machine: invalid placement is invalid")
c.Assert(machines[3].Machine, gc.Equals, "1")
Expand All @@ -1112,8 +1112,8 @@ func (s *clientSuite) TestClientAddMachinesSomeErrors(c *gc.C) {
// Create a machine to host the requested containers.
host, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, jc.ErrorIsNil)
// The host only supports lxc containers.
err = host.SetSupportedContainers([]instance.ContainerType{instance.LXC})
// The host only supports ldc containers.
err = host.SetSupportedContainers([]instance.ContainerType{instance.LXD})
c.Assert(err, jc.ErrorIsNil)

// Set up params for adding 3 containers.
Expand Down
8 changes: 4 additions & 4 deletions apiserver/client/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func (s *statusUnitTestSuite) TestProcessMachinesWithOneMachineAndOneContainer(c

func (s *statusUnitTestSuite) TestProcessMachinesWithEmbeddedContainers(c *gc.C) {
host := s.MakeMachine(c, &factory.MachineParams{InstanceId: instance.Id("1")})
lxcHost := s.MakeMachineNested(c, host.Id(), nil)
lxdHost := s.MakeMachineNested(c, host.Id(), nil)
machines := map[string][]*state.Machine{
host.Id(): {
host,
lxcHost,
s.MakeMachineNested(c, lxcHost.Id(), nil),
lxdHost,
s.MakeMachineNested(c, lxdHost.Id(), nil),
s.MakeMachineNested(c, host.Id(), nil),
},
}
Expand All @@ -94,7 +94,7 @@ func (s *statusUnitTestSuite) TestProcessMachinesWithEmbeddedContainers(c *gc.C)

hostContainer := statuses[host.Id()].Containers
c.Check(hostContainer, gc.HasLen, 2)
c.Check(hostContainer[lxcHost.Id()].Containers, gc.HasLen, 1)
c.Check(hostContainer[lxdHost.Id()].Containers, gc.HasLen, 1)
}

var testUnits = []struct {
Expand Down
2 changes: 1 addition & 1 deletion apiserver/common/modeldestroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *destroyModelSuite) setUpInstances(c *gc.C) (m0, m1, m2 *state.Machine)
m2, err = s.State.AddMachineInsideMachine(state.MachineTemplate{
Series: "precise",
Jobs: []state.MachineJob{state.JobHostUnits},
}, m1.Id(), instance.LXC)
}, m1.Id(), instance.LXD)
c.Assert(err, jc.ErrorIsNil)
err = m2.SetProvisioned("container0", "fake_nonce", nil)
c.Assert(err, jc.ErrorIsNil)
Expand Down
Loading

0 comments on commit c96e51d

Please sign in to comment.