Skip to content

Commit

Permalink
Remove local provider
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Feb 5, 2016
1 parent 0f40661 commit 986932b
Show file tree
Hide file tree
Showing 60 changed files with 112 additions and 3,519 deletions.
16 changes: 2 additions & 14 deletions agent/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/juju/juju/instance"
"github.com/juju/juju/mongo"
"github.com/juju/juju/network"
"github.com/juju/juju/provider"
"github.com/juju/juju/state"
"github.com/juju/juju/state/multiwatcher"
)
Expand Down Expand Up @@ -101,13 +100,8 @@ func InitializeState(adminUser names.UserTag, c ConfigSetter, envCfg *config.Con
servingInfo.SharedSecret = machineCfg.SharedSecret
c.SetStateServingInfo(servingInfo)

// Filter out any LXC bridge addresses from the machine addresses,
// except for local environments. See LP bug #1416928.
if !isLocalEnv(envCfg) {
machineCfg.Addresses = network.FilterLXCAddresses(machineCfg.Addresses)
} else {
logger.Debugf("local model - not filtering addresses from %v", machineCfg.Addresses)
}
// Filter out any LXC bridge addresses from the machine addresses.
machineCfg.Addresses = network.FilterLXCAddresses(machineCfg.Addresses)

if err = initAPIHostPorts(c, st, machineCfg.Addresses, servingInfo.APIPort); err != nil {
return nil, nil, err
Expand All @@ -123,12 +117,6 @@ func InitializeState(adminUser names.UserTag, c ConfigSetter, envCfg *config.Con
return st, m, nil
}

// isLocalEnv returns true if the given config is for a local
// environment. Defined like this for testing.
var isLocalEnv = func(cfg *config.Config) bool {
return cfg.Type() == provider.Local
}

func paramsStateServingInfoToStateStateServingInfo(i params.StateServingInfo) state.StateServingInfo {
return state.StateServingInfo{
APIPort: i.APIPort,
Expand Down
20 changes: 2 additions & 18 deletions agent/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,7 @@ func (s *bootstrapSuite) TearDownTest(c *gc.C) {
s.BaseSuite.TearDownTest(c)
}

func (s *bootstrapSuite) TestInitializeStateNonLocal(c *gc.C) {
s.testInitializeState(c, false)
}

func (s *bootstrapSuite) TestInitializeStateLocal(c *gc.C) {
s.testInitializeState(c, true)
}

func (s *bootstrapSuite) testInitializeState(c *gc.C, fakeLocalEnv bool) {
func (s *bootstrapSuite) TestInitializeState(c *gc.C) {
dataDir := c.MkDir()

lxcFakeNetConfig := filepath.Join(c.MkDir(), "lxc-net")
Expand All @@ -80,10 +72,6 @@ LXC_BRIDGE="ignored"`[1:])
}, nil
})
s.PatchValue(&network.LXCNetDefaultConfig, lxcFakeNetConfig)
s.PatchValue(agent.IsLocalEnv, func(*config.Config) bool {
c.Logf("fakeLocalEnv=%v", fakeLocalEnv)
return fakeLocalEnv
})

pwHash := utils.UserPasswordHash(testing.DefaultMongoPassword, utils.CompatSalt)
configParams := agent.AgentConfigParams{
Expand Down Expand Up @@ -115,7 +103,7 @@ LXC_BRIDGE="ignored"`[1:])
initialAddrs := network.NewAddresses(
"zeroonetwothree",
"0.1.2.3",
"10.0.3.1", // lxc bridge address filtered (when fakeLocalEnv=false).
"10.0.3.1", // lxc bridge address filtered.
"10.0.3.4", // lxc bridge address filtered (-"-).
"10.0.3.3", // not a lxc bridge address
)
Expand All @@ -133,10 +121,6 @@ LXC_BRIDGE="ignored"`[1:])
"0.1.2.3",
"10.0.3.3",
)
if fakeLocalEnv {
// For local environments - no filtering.
filteredAddrs = append([]network.Address{}, initialAddrs...)
}
envAttrs := dummy.SampleConfig().Delete("admin-secret").Merge(testing.Attrs{
"agent-version": version.Current.String(),
"state-id": "1", // needed so policy can Open config
Expand Down
1 change: 0 additions & 1 deletion agent/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func ConfigFileExists(config Config) bool {

var (
MachineJobFromParams = machineJobFromParams
IsLocalEnv = &isLocalEnv
)

func EmptyConfig() Config {
Expand Down
6 changes: 0 additions & 6 deletions apiserver/modelmanager/modelmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
_ "github.com/juju/juju/provider/azure"
_ "github.com/juju/juju/provider/ec2"
_ "github.com/juju/juju/provider/joyent"
_ "github.com/juju/juju/provider/local"
_ "github.com/juju/juju/provider/maas"
_ "github.com/juju/juju/provider/openstack"
"github.com/juju/juju/state"
Expand Down Expand Up @@ -152,11 +151,6 @@ func (s *modelManagerSuite) TestRestrictedProviderFields(c *gc.C) {
provider: "joyent",
expected: []string{
"type", "ca-cert", "state-port", "api-port"},
}, {
provider: "local",
expected: []string{
"type", "ca-cert", "state-port", "api-port",
"container", "network-bridge", "root-dir", "proxy-ssh"},
}, {
provider: "maas",
expected: []string{
Expand Down
2 changes: 1 addition & 1 deletion cloudconfig/cloudinit/cloudinit_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (cfg *windowsCloudConfig) RenderYAML() ([]byte, error) {
// RenderScript is defined on the RenderConfig interface.
func (cfg *windowsCloudConfig) RenderScript() (string, error) {
// NOTE: This shouldn't really be called on windows as it's used only for
// initialization via ssh or on local providers.
// initialization via ssh.
script, err := cfg.renderWindows()
if err != nil {
return "", err
Expand Down
3 changes: 1 addition & 2 deletions cloudconfig/cloudinit/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ type RenderConfig interface {
RenderYAML() ([]byte, error)

// Renders a script that will execute the cloud config
// It is eiher used over ssh for bootstrapping and manual or locally by
// the local provider
// It is used over ssh for bootstrapping with the manual provider.
RenderScript() (string, error)

// ShellRenderer renturns the shell renderer of this particular instance.
Expand Down
2 changes: 1 addition & 1 deletion cloudconfig/containerinit/container_userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TemplateUserData(
// /etc/network/interfaces file which is left on the template LXC
// container on shutdown. This is needed to allow cloned containers to
// start in case no network config is provided during cloud-init, e.g.
// when AUFS is used or with the local provider (see bug #1431888).
// when AUFS is used.
const defaultEtcNetworkInterfaces = `
# loopback interface
auto lo
Expand Down
2 changes: 1 addition & 1 deletion cloudconfig/userdatacfg_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (w *unixConfigure) ConfigureJuju() error {
w.conf.AddScripts(
// We look to see if the proxy line is there already as
// the manual provider may have had it already. The ubuntu
// user may not exist (local provider only).
// user may not exist.
`([ ! -e /home/ubuntu/.profile ] || grep -q '.juju-proxy' /home/ubuntu/.profile) || ` +
`printf '\n# Added by juju\n[ -f "$HOME/.juju-proxy" ] && . "$HOME/.juju-proxy"\n' >> /home/ubuntu/.profile`)
if (w.icfg.ProxySettings != proxy.Settings{}) {
Expand Down
8 changes: 0 additions & 8 deletions cmd/juju/commands/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/juju/juju/juju"
"github.com/juju/juju/juju/osenv"
"github.com/juju/juju/network"
"github.com/juju/juju/provider"
"github.com/juju/juju/version"
)

Expand Down Expand Up @@ -279,13 +278,6 @@ func (c *bootstrapCommand) Run(ctx *cmd.Context) (resultErr error) {
metadataDir = ctx.AbsPath(c.MetadataSource)
}

// TODO (wallyworld): 2013-09-20 bug 1227931
// We can set a custom tools data source instead of doing an
// unnecessary upload.
if environ.Config().Type() == provider.Local {
c.UploadTools = true
}

// Merge environ and bootstrap-specific constraints.
constraintsValidator, err := environ.ConstraintsValidator()
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions cmd/juju/commands/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ func NewJujuCommand(ctx *cmd.Context) cmd.Command {
UserAliasesFilename: osenv.JujuHomePath("aliases"),
})
jcmd.AddHelpTopic("basics", "Basic commands", helptopics.Basics)
jcmd.AddHelpTopic("local-provider", "How to configure a local (LXC) provider",
helptopics.LocalProvider)
jcmd.AddHelpTopic("openstack-provider", "How to configure an OpenStack provider",
helptopics.OpenstackProvider, "openstack")
jcmd.AddHelpTopic("ec2-provider", "How to configure an Amazon EC2 provider",
Expand Down
1 change: 0 additions & 1 deletion cmd/juju/commands/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ var topicNames = []string{
"glossary",
"hpcloud-provider",
"juju",
"local-provider",
"logging",
"maas-provider",
"openstack-provider",
Expand Down
29 changes: 0 additions & 29 deletions cmd/juju/controller/createmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package controller

import (
"os"
"os/user"
"strings"

"github.com/juju/cmd"
Expand All @@ -20,7 +18,6 @@ import (
"github.com/juju/juju/cmd/modelcmd"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/environs/configstore"
localProvider "github.com/juju/juju/provider/local"
)

// NewCreateModelCommand returns a command to create an model.
Expand Down Expand Up @@ -242,9 +239,6 @@ func (c *createModelCommand) getConfigValues(ctx *cmd.Context, serverSkeleton pa
}
configValues["name"] = c.Name

if err := setConfigSpecialCaseDefaults(c.Name, configValues); err != nil {
return nil, errors.Trace(err)
}
// TODO: allow version to be specified on the command line and add here.
cfg, err := config.New(config.UseDefaults, configValues)
if err != nil {
Expand All @@ -253,26 +247,3 @@ func (c *createModelCommand) getConfigValues(ctx *cmd.Context, serverSkeleton pa

return cfg.AllAttrs(), nil
}

var userCurrent = user.Current

func setConfigSpecialCaseDefaults(envName string, cfg map[string]interface{}) error {
// As a special case, the local provider's namespace value
// comes from the user's name and the environment name.
switch cfg["type"] {
case "local":
if _, ok := cfg[localProvider.NamespaceKey]; ok {
return nil
}
username := os.Getenv("USER")
if username == "" {
u, err := userCurrent()
if err != nil {
return errors.Annotatef(err, "failed to determine username for namespace")
}
username = u.Username
}
cfg[localProvider.NamespaceKey] = username + "-" + envName
}
return nil
}
99 changes: 0 additions & 99 deletions cmd/juju/controller/createmodel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package controller_test

import (
"io/ioutil"
"os"
"os/user"

"github.com/juju/cmd"
"github.com/juju/errors"
Expand Down Expand Up @@ -259,103 +257,6 @@ func (s *createSuite) TestConfigValuePrecedence(c *gc.C) {
c.Assert(s.fake.config["cloud"], gc.Equals, "special")
}

var setConfigSpecialCaseDefaultsTests = []struct {
about string
userEnvVar string
userCurrent func() (*user.User, error)
config map[string]interface{}
expectConfig map[string]interface{}
expectError string
}{{
about: "use env var if available",
userEnvVar: "bob",
config: map[string]interface{}{
"name": "envname",
"type": "local",
},
expectConfig: map[string]interface{}{
"name": "envname",
"type": "local",
"namespace": "bob-envname",
},
}, {
about: "fall back to user.Current",
userCurrent: func() (*user.User, error) {
return &user.User{Username: "bob"}, nil
},
config: map[string]interface{}{
"name": "envname",
"type": "local",
},
expectConfig: map[string]interface{}{
"name": "envname",
"type": "local",
"namespace": "bob-envname",
},
}, {
about: "other provider types unaffected",
userEnvVar: "bob",
config: map[string]interface{}{
"name": "envname",
"type": "dummy",
},
expectConfig: map[string]interface{}{
"name": "envname",
"type": "dummy",
},
}, {
about: "explicit namespace takes precedence",
userCurrent: func() (*user.User, error) {
return &user.User{Username: "bob"}, nil
},
config: map[string]interface{}{
"name": "envname",
"namespace": "something",
"type": "local",
},
expectConfig: map[string]interface{}{
"name": "envname",
"namespace": "something",
"type": "local",
},
}, {
about: "user.Current returns error",
userCurrent: func() (*user.User, error) {
return nil, errors.New("an error")
},
config: map[string]interface{}{
"name": "envname",
"type": "local",
},
expectError: "failed to determine username for namespace: an error",
}}

func (s *createSuite) TestSetConfigSpecialCaseDefaults(c *gc.C) {
noUserCurrent := func() (*user.User, error) {
panic("should not be called")
}
s.PatchValue(controller.UserCurrent, noUserCurrent)
// We test setConfigSpecialCaseDefaults independently
// because we can't use the local provider in the tests.
for i, test := range setConfigSpecialCaseDefaultsTests {
c.Logf("test %d: %s", i, test.about)
os.Setenv("USER", test.userEnvVar)
if test.userCurrent != nil {
*controller.UserCurrent = test.userCurrent
} else {
*controller.UserCurrent = noUserCurrent
}
err := controller.SetConfigSpecialCaseDefaults(test.config["name"].(string), test.config)
if test.expectError != "" {
c.Assert(err, gc.ErrorMatches, test.expectError)
} else {
c.Assert(err, gc.IsNil)
c.Assert(test.config, jc.DeepEquals, test.expectConfig)
}
}

}

func (s *createSuite) TestCreateErrorRemoveConfigstoreInfo(c *gc.C) {
s.fake.err = errors.New("bah humbug")

Expand Down
5 changes: 0 additions & 5 deletions cmd/juju/controller/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import (
"github.com/juju/juju/environs/configstore"
)

var (
SetConfigSpecialCaseDefaults = setConfigSpecialCaseDefaults
UserCurrent = &userCurrent
)

// NewListCommandForTest returns a ListCommand with the configstore provided
// as specified.
func NewListCommandForTest(cfgStore configstore.Storage) *listCommand {
Expand Down
Loading

0 comments on commit 986932b

Please sign in to comment.