// TestBootstrapImageMetadataFromAllSources tests that we are looking for // image metadata in all data sources available to environment. // Abandoning look up too soon led to misleading bootstrap failures: // Juju reported no images available for a particular configuration, // despite image metadata in other data sources compatible with the same configuration as well. // Related to bug#1560625. func (s *bootstrapSuite) TestBootstrapImageMetadataFromAllSources(c *gc.C) { s.PatchValue(&series.HostSeries, func() string { return "raring" }) s.PatchValue(&arch.HostArch, func() string { return arch.AMD64 }) // Ensure that we can find at least one image metadata // early on in the image metadata lookup. // We should continue looking despite it. metadataDir, _ := createImageMetadata(c) stor, err := filestorage.NewFileStorageWriter(metadataDir) c.Assert(err, jc.ErrorIsNil) envtesting.UploadFakeTools(c, stor, "released", "released") env := bootstrapEnvironWithRegion{ newEnviron("foo", useDefaultKeys, nil), simplestreams.CloudSpec{ Region: "region", Endpoint: "endpoint", }, } s.setDummyStorage(c, env.bootstrapEnviron) bootstrapCons := constraints.MustParse("arch=amd64") err = bootstrap.Bootstrap(envtesting.BootstrapContext(c), env, bootstrap.BootstrapParams{ BootstrapConstraints: bootstrapCons, MetadataDir: metadataDir, }) c.Assert(err, jc.ErrorIsNil) datasources, err := environs.ImageMetadataSources(env) c.Assert(err, jc.ErrorIsNil) for _, source := range datasources { // make sure we looked in each and all... c.Assert(c.GetTestLog(), jc.Contains, fmt.Sprintf("image metadata in %s", source.Description())) } }
func (s *clientSuite) TestUnshareEnvironmentMissingUser(c *gc.C) { client := s.APIState.Client() user := names.NewUserTag("bob@local") cleanup := api.PatchClientFacadeCall(client, func(request string, paramsIn interface{}, response interface{}) error { if users, ok := paramsIn.(params.ModifyEnvironUsers); ok { c.Assert(users.Changes, gc.HasLen, 1) c.Logf(string(users.Changes[0].Action), gc.Equals, string(params.RemoveEnvUser)) c.Logf(users.Changes[0].UserTag, gc.Equals, user.String()) } else { c.Fatalf("wrong input structure") } if result, ok := response.(*params.ErrorResults); ok { err := ¶ms.Error{ Message: "error message", Code: params.CodeNotFound, } *result = params.ErrorResults{Results: []params.ErrorResult{{Error: err}}} } else { c.Fatalf("wrong input structure") } return nil }, ) defer cleanup() err := client.UnshareEnvironment(user) c.Assert(err, jc.ErrorIsNil) logMsg := fmt.Sprintf("WARNING juju.api environment was not previously shared with user %s", user.Username()) c.Assert(c.GetTestLog(), jc.Contains, logMsg) }
func (s *DeploySuite) TestDeployCharmsEndpointNotImplemented(c *gc.C) { setter := &testMetricCredentialsSetter{ assert: func(serviceName string, data []byte) {}, err: ¶ms.Error{ Message: "IsMetered", Code: params.CodeNotImplemented, }, } cleanup := jujutesting.PatchValue(&getMetricCredentialsAPI, func(_ api.Connection) (metricCredentialsAPI, error) { return setter, nil }) defer cleanup() stub := &jujutesting.Stub{} handler := &testMetricsRegistrationHandler{Stub: stub} server := httptest.NewServer(handler) defer server.Close() testcharms.Repo.ClonedDirPath(s.SeriesPath, "metered") deploy := &DeployCommand{Steps: []DeployStep{&RegisterMeteredCharm{RegisterURL: server.URL, QueryURL: server.URL}}} _, err := coretesting.RunCommand(c, envcmd.Wrap(deploy), "local:quantal/metered-1", "--plan", "someplan") c.Assert(err, jc.ErrorIsNil) c.Check(c.GetTestLog(), jc.Contains, "current state server version does not support charm metering") }
func (s *SetSuite) assertSetWarning(c *gc.C, dir string, args []string, w string) { ctx := coretesting.ContextForDir(c, dir) code := cmd.Main(service.NewSetCommandWithAPI(s.fakeClientAPI, s.fakeServiceAPI), ctx, append([]string{"dummy-service"}, args...)) c.Check(code, gc.Equals, 0) c.Assert(strings.Replace(c.GetTestLog(), "\n", " ", -1), gc.Matches, ".*WARNING.*"+w+".*") }
func (s *DefaultsCommandSuite) TestResetBlockedError(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockedError") _, err := s.run(c, "--reset", "attr") c.Assert(err, gc.Equals, cmd.ErrSilent) // msg is logged c.Check(c.GetTestLog(), jc.Contains, "TestBlockedError") }
func (*logSuite) TestLog(c *gc.C) { logger := loggo.GetLogger("test") jujuLogger := loggo.GetLogger("juju") logConfig = "<root>=DEBUG;juju=TRACE" c.Assert(logger.EffectiveLogLevel(), gc.Equals, loggo.WARNING) var suite LoggingSuite suite.SetUpSuite(c) c.Assert(logger.EffectiveLogLevel(), gc.Equals, loggo.DEBUG) c.Assert(jujuLogger.EffectiveLogLevel(), gc.Equals, loggo.TRACE) logger.Debugf("message 1") logger.Tracef("message 2") jujuLogger.Tracef("message 3") c.Assert(c.GetTestLog(), gc.Matches, ".*DEBUG test message 1\n"+ ".*TRACE juju message 3\n", ) suite.TearDownSuite(c) logger.Debugf("message 1") logger.Tracef("message 2") jujuLogger.Tracef("message 3") c.Assert(c.GetTestLog(), gc.Matches, ".*DEBUG test message 1\n"+ ".*TRACE juju message 3\n", ) c.Assert(logger.EffectiveLogLevel(), gc.Equals, loggo.WARNING) c.Assert(jujuLogger.EffectiveLogLevel(), gc.Equals, loggo.WARNING) }
func (s *CacheAPIEndpointsSuite) TestResolveSkippedWhenHostnamesUnchanged(c *gc.C) { // Test that if new endpoints hostnames are the same as the // cached, no DNS resolution happens (i.e. we don't resolve on // every connection, but as needed). hps := network.NewHostPorts(1234, "8.8.8.8", "example.com", "10.0.0.1", ) controllerDetails := jujuclient.ControllerDetails{ ControllerUUID: fakeUUID, CACert: "certificate", UnresolvedAPIEndpoints: network.HostPortsToStrings(hps), } err := s.ControllerStore.AddController("controller-name", controllerDetails) c.Assert(err, jc.ErrorIsNil) addrs, hosts, changed := juju.PrepareEndpointsForCaching( controllerDetails, [][]network.HostPort{hps}, ) c.Assert(addrs, gc.IsNil) c.Assert(hosts, gc.IsNil) c.Assert(changed, jc.IsFalse) c.Assert(s.resolveNumCalls, gc.Equals, 0) c.Assert( c.GetTestLog(), jc.Contains, "DEBUG juju.juju API hostnames unchanged - not resolving", ) }
func (s *SetSuite) TestSettingKnownValue(c *gc.C) { _, err := s.run(c, "special=extra", "unknown=foo") c.Assert(err, jc.ErrorIsNil) // Command succeeds, but warning logged. expected := `key "unknown" is not defined in the current environment configuration: possible misspelling` c.Check(c.GetTestLog(), jc.Contains, expected) }
func (s *DestroySuite) TestBlockedDestroy(c *gc.C) { s.api.SetErrors(¶ms.Error{Code: params.CodeOperationBlocked}) s.runDestroyCommand(c, "test1", "-y") testLog := c.GetTestLog() c.Check(testLog, jc.Contains, "To enable controller destruction, please run:") c.Check(testLog, jc.Contains, "juju enable-destroy-controller") }
func (s *SetSuite) TestBlockedError(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockedError") _, err := s.run(c, "special=extra") c.Assert(err, gc.Equals, cmd.ErrSilent) // msg is logged c.Check(c.GetTestLog(), jc.Contains, "TestBlockedError") }
func (s *DestroySuite) TestBlockedDestroy(c *gc.C) { s.api.err = ¶ms.Error{Code: params.CodeOperationBlocked} s.runDestroyCommand(c, "test1", "-y") testLog := c.GetTestLog() c.Check(testLog, jc.Contains, "To remove all blocks in the controller, please run:") c.Check(testLog, jc.Contains, "juju controller remove-blocks") }
func (s *DestroySuite) TestDestroyCannotConnectToAPI(c *gc.C) { s.apierror = errors.New("connection refused") _, err := s.runDestroyCommand(c, "test1", "-y") c.Assert(err, gc.ErrorMatches, "cannot connect to API: connection refused") c.Check(c.GetTestLog(), jc.Contains, "If the controller is unusable") checkControllerExistsInStore(c, "test1", s.store) }
func (*NetworkSuite) TestNetworkConfigTemplate(c *gc.C) { // Intentionally using an invalid type "foo" here to test it gets // changed to the default "veth" and a warning is logged. config := lxc.NetworkConfigTemplate(container.NetworkConfig{"foo", "bar", 4321, nil}) // In the past, the entire lxc.conf file was just networking. With // the addition of the auto start, we now have to have better // isolate this test. As such, we parse the conf template results // and just get the results that start with 'lxc.network' as that // is what the test cares about. obtained := []string{} for _, value := range strings.Split(config, "\n") { if strings.HasPrefix(value, "lxc.network") { obtained = append(obtained, value) } } expected := []string{ "lxc.network.type = veth", "lxc.network.link = bar", "lxc.network.flags = up", "lxc.network.mtu = 4321", } c.Assert(obtained, jc.DeepEquals, expected) log := c.GetTestLog() c.Assert(log, jc.Contains, `WARNING juju.container.lxc unknown network type "foo", using the default "bridge" config`, ) }
func (s *DestroySuite) TestDestroyControllerNotFoundNotRemovedFromStore(c *gc.C) { s.apierror = errors.NotFoundf("test1") _, err := s.runDestroyCommand(c, "test1", "-y") c.Assert(err, gc.ErrorMatches, "cannot connect to API: test1 not found") c.Check(c.GetTestLog(), jc.Contains, "If the controller is unusable") checkControllerExistsInStore(c, "test1", s.store) }
func (s *CacheAPIEndpointsSuite) TestResolveSkippedWhenHostnamesUnchanged(c *gc.C) { // Test that if new endpoints hostnames are the same as the // cached, no DNS resolution happens (i.e. we don't resolve on // every connection, but as needed). info := s.store.CreateInfo("env-name") hps := network.NewHostPorts(1234, "8.8.8.8", "example.com", "10.0.0.1", ) info.SetAPIEndpoint(configstore.APIEndpoint{ Hostnames: network.HostPortsToStrings(hps), }) err := info.Write() c.Assert(err, jc.ErrorIsNil) addrs, hosts, changed := juju.PrepareEndpointsForCaching( info, [][]network.HostPort{hps}, network.HostPort{}, ) c.Assert(addrs, gc.IsNil) c.Assert(hosts, gc.IsNil) c.Assert(changed, jc.IsFalse) c.Assert(s.resolveNumCalls, gc.Equals, 0) c.Assert( c.GetTestLog(), jc.Contains, "DEBUG juju.api API hostnames unchanged - not resolving", ) }
func (s *DestroySuite) TestDestroyCannotConnectToAPI(c *gc.C) { s.api.err = errors.New("connection refused") _, err := s.runDestroyCommand(c, "test2", "-y") c.Assert(err, gc.ErrorMatches, "cannot destroy environment: connection refused") c.Check(c.GetTestLog(), jc.Contains, "failed to destroy environment \"test2\"") checkEnvironmentExistsInStore(c, "test2", s.store) }
func (s *configCommandSuite) assertSetWarning(c *gc.C, dir string, args []string, w string) { ctx := coretesting.ContextForDir(c, dir) code := cmd.Main(application.NewConfigCommandForTest(s.fake), ctx, append([]string{"dummy-application"}, args...)) c.Check(code, gc.Equals, 0) c.Assert(strings.Replace(c.GetTestLog(), "\n", " ", -1), gc.Matches, ".*WARNING.*"+w+".*") }
func (s *clientSuite) TestShareEnvironmentExistingUser(c *gc.C) { client := s.APIState.Client() user := s.Factory.MakeEnvUser(c, nil) cleanup := api.PatchClientFacadeCall(client, func(request string, paramsIn interface{}, response interface{}) error { if users, ok := paramsIn.(params.ModifyEnvironUsers); ok { c.Assert(users.Changes, gc.HasLen, 1) c.Logf(string(users.Changes[0].Action), gc.Equals, string(params.AddEnvUser)) c.Logf(users.Changes[0].UserTag, gc.Equals, user.UserTag().String()) } else { c.Fatalf("wrong input structure") } if result, ok := response.(*params.ErrorResults); ok { err := ¶ms.Error{ Message: "error message", Code: params.CodeAlreadyExists, } *result = params.ErrorResults{Results: []params.ErrorResult{{Error: err}}} } else { c.Fatalf("wrong input structure") } return nil }, ) defer cleanup() err := client.ShareEnvironment(user.UserTag()) c.Assert(err, jc.ErrorIsNil) logMsg := fmt.Sprintf("WARNING juju.api environment is already shared with %s", user.UserName()) c.Assert(c.GetTestLog(), jc.Contains, logMsg) }
func (s *logSuite) TestFlagSet(c *gc.C) { s.SetFeatureFlags(feature.LogErrorStack) err := errors.New("test error") err2 := utils.LoggedErrorStack(err) c.Assert(err, gc.Equals, err2) expected := "ERROR juju.utils error stack:\ntest error" c.Assert(c.GetTestLog(), jc.Contains, expected) }
func (s *UnsetSuite) TestUnsettingKnownValue(c *gc.C) { _, err := s.run(c, "unknown") c.Assert(err, jc.ErrorIsNil) c.Assert(s.fake.keys, jc.DeepEquals, []string{"unknown"}) // Command succeeds, but warning logged. expected := `key "unknown" is not defined in the current environment configuration: possible misspelling` c.Check(c.GetTestLog(), jc.Contains, expected) }
func (*LxcSuite) TestManagerWarnsAboutUnknownOption(c *gc.C) { _, err := lxc.NewContainerManager(container.ManagerConfig{ container.ConfigName: "BillyBatson", "shazam": "Captain Marvel", }, &containertesting.MockURLGetter{}) c.Assert(err, jc.ErrorIsNil) c.Assert(c.GetTestLog(), jc.Contains, `WARNING juju.container unused config option: "shazam" -> "Captain Marvel"`) }
func (s *AddMachineSuite) TestBlockedError(c *gc.C) { s.fakeAddMachine.addError = common.OperationBlockedError("TestBlockedError") _, err := s.run(c) c.Assert(err, gc.Equals, cmd.ErrSilent) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockedError.*") }
func (*KVMSuite) TestManagerWarnsAboutUnknownOption(c *gc.C) { _, err := kvm.NewContainerManager(container.ManagerConfig{ container.ConfigModelUUID: coretesting.ModelTag.Id(), "shazam": "Captain Marvel", }) c.Assert(err, jc.ErrorIsNil) c.Assert(c.GetTestLog(), jc.Contains, `INFO juju.container unused config option: "shazam" -> "Captain Marvel"`) }
func (*kernelVersionSuite) TestMacOSXSeriesFromKernelVersionError(c *gc.C) { // We suppress the actual error in favor of returning "unknown", but we // do log the error series, err := version.MacOSXSeriesFromKernelVersion(sysctlError) c.Assert(err, gc.ErrorMatches, "no such syscall") c.Assert(series, gc.Equals, "unknown") c.Check(c.GetTestLog(), gc.Matches, ".* juju.version unable to determine OS version: no such syscall\n") }
func (s *UserAddCommandSuite) TestBlockAddUser(c *gc.C) { // Block operation s.mockAPI.blocked = true _, err := s.run(c, "foobar", "Foo Bar") c.Assert(err, gc.ErrorMatches, cmd.ErrSilent.Error()) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*To unblock changes.*") }
func (s *EnableHASuite) TestBlockEnableHA(c *gc.C) { s.fake.err = common.OperationBlockedError("TestBlockEnableHA") _, err := s.runEnableHA(c, "-n", "1") c.Assert(err, gc.ErrorMatches, cmd.ErrSilent.Error()) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockEnableHA.*") }
func (s *RemoveMachineSuite) TestBlockedError(c *gc.C) { s.fake.removeError = common.ErrOperationBlocked("TestBlockedError") _, err := s.run(c, "1") c.Assert(err, gc.Equals, cmd.ErrSilent) c.Assert(s.fake.forced, jc.IsFalse) // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Assert(stripped, gc.Matches, ".*TestBlockedError.*") }
func (s *vpcSuite) TestValidateModelVPCSuccess(c *gc.C) { s.stubAPI.PrepareValidateVPCResponses() err := validateModelVPC(s.stubAPI, "model", anyVPCID) c.Assert(err, jc.ErrorIsNil) s.stubAPI.CheckCallNames(c, "VPCs", "Subnets", "InternetGateways", "RouteTables") c.Check(c.GetTestLog(), jc.Contains, `INFO juju.provider.ec2 Using VPC "vpc-anything" for model "model"`) }
func (s *AddUnitSuite) TestBlockAddUnit(c *gc.C) { // Block operation s.fake.err = common.OperationBlockedError("TestBlockAddUnit") s.runAddUnit(c, "some-application-name") // msg is logged stripped := strings.Replace(c.GetTestLog(), "\n", "", -1) c.Check(stripped, gc.Matches, ".*TestBlockAddUnit.*") }
func (s *DestroySuite) TestDestroyListBlocksError(c *gc.C) { s.api.err = ¶ms.Error{Code: params.CodeOperationBlocked} s.api.blocksErr = errors.New("unexpected api error") s.runDestroyCommand(c, "test1", "-y") testLog := c.GetTestLog() c.Check(testLog, jc.Contains, "To remove all blocks in the controller, please run:") c.Check(testLog, jc.Contains, "juju controller remove-blocks") c.Check(testLog, jc.Contains, "Unable to list blocked models: unexpected api error") }