Skip to content

Commit

Permalink
Simplestreams: Look for simplestreams type through context
Browse files Browse the repository at this point in the history
The following changes allows the lookup of a simplestreams type via a
context check. The changes here are required to start exposing that
context for tests to pass through the right simplestreams.
  • Loading branch information
SimonRichardson committed Jun 3, 2021
1 parent 048d4e2 commit 47b7df6
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 130 deletions.
2 changes: 1 addition & 1 deletion caas/kubernetes/provider/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *bootstrapSuite) SetUpTest(c *gc.C) {
s.pcfg = pcfg
s.controllerStackerGetter = func() provider.ControllerStackerForTest {
controllerStacker, err := provider.NewcontrollerStackForTest(
envtesting.BootstrapContext(c), "juju-controller-test", "some-storage", s.broker, s.pcfg,
envtesting.BootstrapContext(context.TODO(), c), "juju-controller-test", "some-storage", s.broker, s.pcfg,
)
c.Assert(err, jc.ErrorIsNil)
return controllerStacker
Expand Down
11 changes: 6 additions & 5 deletions caas/kubernetes/provider/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package provider_test

import (
stdcontext "context"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -1276,7 +1277,7 @@ func (s *K8sBrokerSuite) TestBootstrapNoOperatorStorage(c *gc.C) {
ctrl := s.setupController(c)
defer ctrl.Finish()

ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapContext(stdcontext.TODO(), c)
callCtx := &context.CloudCallContext{}
bootstrapParams := environs.BootstrapParams{
ControllerConfig: testing.FakeControllerConfig(),
Expand All @@ -1297,7 +1298,7 @@ func (s *K8sBrokerSuite) TestBootstrap(c *gc.C) {
// Ensure the broker is configured with operator storage.
s.setupOperatorStorageConfig(c)

ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapContext(stdcontext.TODO(), c)
callCtx := &context.CloudCallContext{}
bootstrapParams := environs.BootstrapParams{
ControllerConfig: testing.FakeControllerConfig(),
Expand Down Expand Up @@ -1359,7 +1360,7 @@ func (s *K8sBrokerSuite) TestPrepareForBootstrap(c *gc.C) {
s.mockStorageClass.EXPECT().Get(gomock.Any(), "some-storage", v1.GetOptions{}).
Return(sc, nil),
)
ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapContext(stdcontext.TODO(), c)
c.Assert(
s.broker.PrepareForBootstrap(ctx, "ctrl-1"), jc.ErrorIsNil,
)
Expand All @@ -1376,7 +1377,7 @@ func (s *K8sBrokerSuite) TestPrepareForBootstrapAlreadyExistNamespaceError(c *gc
s.mockNamespaces.EXPECT().Get(gomock.Any(), "controller-ctrl-1", v1.GetOptions{}).
Return(ns, nil),
)
ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapContext(stdcontext.TODO(), c)
c.Assert(
s.broker.PrepareForBootstrap(ctx, "ctrl-1"), jc.Satisfies, errors.IsAlreadyExists,
)
Expand All @@ -1394,7 +1395,7 @@ func (s *K8sBrokerSuite) TestPrepareForBootstrapAlreadyExistControllerAnnotation
s.mockNamespaces.EXPECT().List(gomock.Any(), v1.ListOptions{}).
Return(&core.NamespaceList{Items: []core.Namespace{*ns}}, nil),
)
ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapContext(stdcontext.TODO(), c)
c.Assert(
s.broker.PrepareForBootstrap(ctx, "ctrl-1"), jc.Satisfies, errors.IsAlreadyExists,
)
Expand Down
4 changes: 3 additions & 1 deletion cmd/juju/commands/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,9 @@ to create a new model to deploy %sworkloads.

// Validate the storage provider config.
registry := stateenvirons.NewStorageProviderRegistry(environ)
m := poolmanager.MemSettings{make(map[string]map[string]interface{})}
m := poolmanager.MemSettings{
Settings: make(map[string]map[string]interface{}),
}
pm := poolmanager.New(m, registry)
for poolName, cfg := range bootstrapCfg.storagePools {
poolType, _ := cfg[poolmanager.Type].(string)
Expand Down
3 changes: 2 additions & 1 deletion cmd/juju/commands/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package commands

import (
"bytes"
stdcontext "context"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -1346,7 +1347,7 @@ func (s *BootstrapSuite) TestAutoSyncLocalSource(c *gc.C) {
Config: cfg,
})
c.Assert(err, jc.ErrorIsNil)
err = env.PrepareForBootstrap(envtesting.BootstrapContext(c), "controller-1")
err = env.PrepareForBootstrap(envtesting.BootstrapContext(stdcontext.TODO(), c), "controller-1")
c.Assert(err, jc.ErrorIsNil)

// Now check the available tools which are the 1.2.0 envtools.
Expand Down
76 changes: 38 additions & 38 deletions environs/bootstrap/bootstrap_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion environs/bootstrap/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *PrepareSuite) assertPrepare(c *gc.C, skipVerify bool) {
cfg, err := config.New(config.NoDefaults, baselineAttrs)
c.Assert(err, jc.ErrorIsNil)
controllerStore := jujuclient.NewMemStore()
ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapTODOContext(c)
controllerCfg := controller.Config{
controller.ControllerUUIDKey: testing.ControllerTag.Id(),
controller.CACertKey: testing.CACert,
Expand Down
4 changes: 3 additions & 1 deletion environs/imagemetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package environs_test

import (
stdcontext "context"

"github.com/juju/errors"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils/v2"
Expand Down Expand Up @@ -46,7 +48,7 @@ func (s *ImageMetadataSuite) env(c *gc.C, imageMetadataURL, stream string) envir
}
env, err := bootstrap.PrepareController(
false,
envtesting.BootstrapContext(c),
envtesting.BootstrapContext(stdcontext.TODO(), c),
jujuclient.NewMemStore(),
bootstrap.PrepareParams{
ControllerConfig: testing.FakeControllerConfig(),
Expand Down
11 changes: 6 additions & 5 deletions environs/jujutest/livetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ func (t *LiveTests) PrepareOnce(c *gc.C) {
if t.prepared {
return
}

args := t.prepareForBootstrapParams(c)
e, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(c), t.ControllerStore, args)
e, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(stdcontext.TODO(), c), t.ControllerStore, args)
c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", t.TestConfig))
c.Assert(e, gc.NotNil)
t.Env = e.(environs.Environ)
Expand Down Expand Up @@ -228,7 +229,7 @@ func (t *LiveTests) BootstrapOnce(c *gc.C) {
args := t.bootstrapParams()
args.BootstrapConstraints = cons
args.ModelConstraints = cons
err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), t.Env, t.ProviderCallContext, args)
err := bootstrap.Bootstrap(envtesting.BootstrapContext(stdcontext.TODO(), c), t.Env, t.ProviderCallContext, args)
c.Assert(err, jc.ErrorIsNil)
t.bootstrapped = true
}
Expand Down Expand Up @@ -955,7 +956,7 @@ func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) {
})
args := t.prepareForBootstrapParams(c)
args.ModelConfig = dummyCfg
e, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(c),
e, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(stdcontext.TODO(), c),
jujuclient.NewMemStore(),
args,
)
Expand All @@ -969,13 +970,13 @@ func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) {
"default-series": "quantal",
})
args.ModelConfig = attrs
env, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(c),
env, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(stdcontext.TODO(), c),
t.ControllerStore,
args)
c.Assert(err, jc.ErrorIsNil)
defer func() { _ = environs.Destroy("livetests", env, t.ProviderCallContext, t.ControllerStore) }()

err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, t.ProviderCallContext, t.bootstrapParams())
err = bootstrap.Bootstrap(envtesting.BootstrapContext(stdcontext.TODO(), c), env, t.ProviderCallContext, t.bootstrapParams())
c.Assert(err, jc.ErrorIsNil)

st := t.Env.(jujutesting.GetStater).GetStateInAPIServer()
Expand Down
8 changes: 4 additions & 4 deletions environs/jujutest/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (t *Tests) Prepare(c *gc.C) environs.Environ {

// PrepareWithParams prepares an instance of the testing environment.
func (t *Tests) PrepareWithParams(c *gc.C, params bootstrap.PrepareParams) environs.Environ {
e, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(c), t.ControllerStore, params)
e, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(stdcontext.TODO(), c), t.ControllerStore, params)
c.Assert(err, gc.IsNil, gc.Commentf("preparing environ %#v", params.ModelConfig))
c.Assert(e, gc.NotNil)
t.Env = e.(environs.Environ)
Expand All @@ -112,7 +112,7 @@ func (t *Tests) AssertPrepareFailsWithConfig(c *gc.C, badConfig coretesting.Attr
args := t.PrepareParams(c)
args.ModelConfig = coretesting.Attrs(args.ModelConfig).Merge(badConfig)

e, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(c), t.ControllerStore, args)
e, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(stdcontext.TODO(), c), t.ControllerStore, args)
c.Assert(err, gc.ErrorMatches, errorMatches)
c.Assert(e, gc.IsNil)
return err
Expand Down Expand Up @@ -218,7 +218,7 @@ func (t *Tests) TestBootstrap(c *gc.C) {
}

e := t.Prepare(c)
err := bootstrap.Bootstrap(envtesting.BootstrapContext(c), e, t.ProviderCallContext, args)
err := bootstrap.Bootstrap(envtesting.BootstrapContext(stdcontext.TODO(), c), e, t.ProviderCallContext, args)
c.Assert(err, jc.ErrorIsNil)

controllerInstances, err := e.ControllerInstances(t.ProviderCallContext, t.ControllerUUID)
Expand All @@ -237,7 +237,7 @@ func (t *Tests) TestBootstrap(c *gc.C) {
// Prepare again because Destroy invalidates old environments.
e3 := t.Prepare(c)

err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), e3, t.ProviderCallContext, args)
err = bootstrap.Bootstrap(envtesting.BootstrapContext(stdcontext.TODO(), c), e3, t.ProviderCallContext, args)
c.Assert(err, jc.ErrorIsNil)

err = environs.Destroy(e3.Config().Name(), e3, t.ProviderCallContext, t.ControllerStore)
Expand Down
8 changes: 5 additions & 3 deletions environs/open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package environs_test

import (
stdcontext "context"

"github.com/juju/errors"
gitjujutesting "github.com/juju/testing"
jc "github.com/juju/testing/checkers"
Expand Down Expand Up @@ -51,7 +53,7 @@ func (s *OpenSuite) TestNewDummyEnviron(c *gc.C) {
// matches *Settings.Map()
cfg, err := config.New(config.NoDefaults, dummySampleConfig())
c.Assert(err, jc.ErrorIsNil)
ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapContext(stdcontext.TODO(), c)
cache := jujuclient.NewMemStore()
controllerCfg := testing.FakeControllerConfig()
bootstrapEnviron, err := bootstrap.PrepareController(false, ctx, cache, bootstrap.PrepareParams{
Expand Down Expand Up @@ -85,7 +87,7 @@ func (s *OpenSuite) TestNewDummyEnviron(c *gc.C) {

func (s *OpenSuite) TestUpdateEnvInfo(c *gc.C) {
store := jujuclient.NewMemStore()
ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapContext(stdcontext.TODO(), c)
uuid := utils.MustNewUUID().String()
cfg, err := config.New(config.UseDefaults, map[string]interface{}{
"type": "dummy",
Expand Down Expand Up @@ -154,7 +156,7 @@ func (*OpenSuite) TestDestroy(c *gc.C) {
// Prepare the environment and sanity-check that
// the config storage info has been made.
controllerCfg := testing.FakeControllerConfig()
ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapContext(stdcontext.TODO(), c)
bootstrapEnviron, err := bootstrap.PrepareController(false, ctx, store, bootstrap.PrepareParams{
ControllerConfig: controllerCfg,
ControllerName: "controller-name",
Expand Down
8 changes: 6 additions & 2 deletions environs/testing/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func DisableFinishBootstrap() func() {
}

// BootstrapContext creates a simple bootstrap execution context.
func BootstrapContext(c *gc.C) environs.BootstrapContext {
return modelcmd.BootstrapContext(context.Background(), cmdtesting.Context(c))
func BootstrapContext(ctx context.Context, c *gc.C) environs.BootstrapContext {
return modelcmd.BootstrapContext(ctx, cmdtesting.Context(c))
}

func BootstrapTODOContext(c *gc.C) environs.BootstrapContext {
return BootstrapContext(context.TODO(), c)
}
3 changes: 2 additions & 1 deletion environs/tools/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package tools_test

import (
stdcontext "context"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -106,7 +107,7 @@ func (s *SimpleStreamsToolsSuite) resetEnv(c *gc.C, attrs map[string]interface{}
jujuversion.Current = s.origCurrentVersion
dummy.Reset(c)
attrs = dummy.SampleConfig().Merge(attrs)
env, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(c),
env, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(stdcontext.TODO(), c),
jujuclient.NewMemStore(),
bootstrap.PrepareParams{
ControllerConfig: coretesting.FakeControllerConfig(),
Expand Down
5 changes: 2 additions & 3 deletions environs/tools/urls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/juju/juju/juju/keys"
"github.com/juju/juju/jujuclient"
"github.com/juju/juju/provider/dummy"
"github.com/juju/juju/testing"
coretesting "github.com/juju/juju/testing"
)

Expand All @@ -40,11 +39,11 @@ func (s *URLsSuite) TearDownTest(c *gc.C) {
func (s *URLsSuite) env(c *gc.C, toolsMetadataURL string) environs.Environ {
attrs := dummy.SampleConfig()
if toolsMetadataURL != "" {
attrs = attrs.Merge(testing.Attrs{
attrs = attrs.Merge(coretesting.Attrs{
"agent-metadata-url": toolsMetadataURL,
})
}
env, err := bootstrap.PrepareController(false, envtesting.BootstrapContext(c),
env, err := bootstrap.PrepareController(false, envtesting.BootstrapTODOContext(c),
jujuclient.NewMemStore(),
bootstrap.PrepareParams{
ControllerConfig: coretesting.FakeControllerConfig(),
Expand Down
14 changes: 7 additions & 7 deletions provider/azure/environ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ const resourceGroupName = "juju-testmodel-deadbeef"
func (s *environSuite) TestBootstrap(c *gc.C) {
defer envtesting.DisableFinishBootstrap()()

ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapTODOContext(c)
env := prepareForBootstrap(c, ctx, s.provider, &s.sender)

s.sender = s.initResourceGroupSenders(resourceGroupName)
Expand Down Expand Up @@ -1644,7 +1644,7 @@ func (s *environSuite) TestBootstrap(c *gc.C) {
func (s *environSuite) TestBootstrapPrivateIP(c *gc.C) {
defer envtesting.DisableFinishBootstrap()()

ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapTODOContext(c)
env := prepareForBootstrap(c, ctx, s.provider, &s.sender)

s.sender = s.initResourceGroupSenders(resourceGroupName)
Expand Down Expand Up @@ -1677,7 +1677,7 @@ func (s *environSuite) TestBootstrapPrivateIP(c *gc.C) {
func (s *environSuite) TestBootstrapCustomNetwork(c *gc.C) {
defer envtesting.DisableFinishBootstrap()()

ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapTODOContext(c)
env := prepareForBootstrap(c, ctx, s.provider, &s.sender, testing.Attrs{"network": "mynetwork"})

s.sender = s.initResourceGroupSenders(resourceGroupName)
Expand Down Expand Up @@ -1714,7 +1714,7 @@ func (s *environSuite) TestBootstrapCustomNetwork(c *gc.C) {
func (s *environSuite) TestBootstrapWithInvalidCredential(c *gc.C) {
defer envtesting.DisableFinishBootstrap()()

ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapTODOContext(c)
env := prepareForBootstrap(c, ctx, s.provider, &s.sender)

s.createSenderWithUnauthorisedStatusCode(c)
Expand Down Expand Up @@ -1744,7 +1744,7 @@ func (s *environSuite) TestBootstrapInstanceConstraints(c *gc.C) {
}
defer envtesting.DisableFinishBootstrap()()

ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapTODOContext(c)
env := prepareForBootstrap(c, ctx, s.provider, &s.sender)

s.sender = append(s.sender, s.resourceSkusSender())
Expand Down Expand Up @@ -1796,7 +1796,7 @@ func (s *environSuite) TestBootstrapCustomResourceGroup(c *gc.C) {
}
defer envtesting.DisableFinishBootstrap()()

ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapTODOContext(c)
env := prepareForBootstrap(c, ctx, s.provider, &s.sender, testing.Attrs{"resource-group-name": "foo"})

s.sender = append(s.sender, s.resourceSkusSender())
Expand Down Expand Up @@ -1846,7 +1846,7 @@ func (s *environSuite) TestBootstrapCustomResourceGroup(c *gc.C) {
func (s *environSuite) TestBootstrapWithAutocert(c *gc.C) {
defer envtesting.DisableFinishBootstrap()()

ctx := envtesting.BootstrapContext(c)
ctx := envtesting.BootstrapTODOContext(c)
env := prepareForBootstrap(c, ctx, s.provider, &s.sender)

s.sender = s.initResourceGroupSenders(resourceGroupName)
Expand Down
Loading

0 comments on commit 47b7df6

Please sign in to comment.