// Register tests to run against a test Openstack instance (service doubles). func registerLocalTests() { cred := &identity.Credentials{ User: "******", Secrets: "secret", Region: "some-region", TenantName: "some tenant", } config := makeTestConfig(cred) config["agent-version"] = version.CurrentNumber().String() config["authorized-keys"] = "fakekey" Suite(&localLiveSuite{ LiveTests: LiveTests{ cred: cred, LiveTests: jujutest.LiveTests{ TestConfig: jujutest.TestConfig{config}, }, }, }) Suite(&localServerSuite{ cred: cred, Tests: jujutest.Tests{ TestConfig: jujutest.TestConfig{config}, }, }) Suite(&publicBucketSuite{ cred: cred, }) }
// Open implements environs.EnvironProvider.Open. func (environProvider) Open(cfg *config.Config) (env environs.Environ, err error) { logger.Infof("opening environment %q", cfg.Name()) if _, ok := cfg.AgentVersion(); !ok { cfg, err = cfg.Apply(map[string]interface{}{ "agent-version": version.CurrentNumber().String(), }) if err != nil { return nil, err } } environ := &localEnviron{name: cfg.Name()} err = environ.SetConfig(cfg) if err != nil { logger.Errorf("failure setting config: %v", err) return nil, err } return environ, nil }
func (s *StorageSuite) TestUploadFakeSeries(c *gc.C) { t, err := tools.Upload(s.env.Storage(), nil, "sham", "fake") c.Assert(err, gc.IsNil) c.Assert(t.Version, gc.Equals, version.Current) expectRaw := downloadToolsRaw(c, t) list, err := tools.ReadList(s.env.Storage(), version.Current.Major) c.Assert(err, gc.IsNil) c.Assert(list, gc.HasLen, 3) expectSeries := []string{"fake", "sham", version.CurrentSeries()} sort.Strings(expectSeries) c.Assert(list.Series(), gc.DeepEquals, expectSeries) for _, t := range list { c.Logf("checking %s", t.URL) c.Assert(t.Version.Number, gc.Equals, version.CurrentNumber()) actualRaw := downloadToolsRaw(c, t) c.Assert(string(actualRaw), gc.Equals, string(expectRaw)) } }
// newConfig creates a MAAS environment config from attributes. func newConfig(values map[string]interface{}) (*maasEnvironConfig, error) { defaults := map[string]interface{}{ "name": "testenv", "type": "maas", "admin-secret": "ssshhhhhh", "authorized-keys": "I-am-not-a-real-key", "agent-version": version.CurrentNumber().String(), // These are not needed by MAAS, but juju-core breaks without them. Needs // fixing there. "ca-cert": testing.CACert, "ca-private-key": testing.CAKey, } cfg := make(map[string]interface{}) copyAttrs(defaults, cfg) copyAttrs(values, cfg) env, err := environs.NewFromAttrs(cfg) if err != nil { return nil, err } return env.(*maasEnviron).ecfg(), nil }
// makeEnviron creates a functional maasEnviron for a test. Its configuration // is a bit arbitrary and none of the test code's business. func (suite *EnvironSuite) makeEnviron() *maasEnviron { config, err := config.New(map[string]interface{}{ "name": suite.environ.Name(), "type": "maas", "admin-secret": "local-secret", "authorized-keys": "foo", "agent-version": version.CurrentNumber().String(), "maas-oauth": "a:b:c", "maas-server": suite.testMAASObject.TestServer.URL, // These are not needed by MAAS, but juju-core breaks without them. Needs // fixing there. "ca-cert": testing.CACert, "ca-private-key": testing.CAKey, }) if err != nil { panic(err) } env, err := NewEnviron(config) if err != nil { panic(err) } return env }
func (t *LiveTests) TestBootstrapAndDeploy(c *C) { if !t.CanOpenState || !t.HasProvisioner { c.Skip(fmt.Sprintf("skipping provisioner test, CanOpenState: %v, HasProvisioner: %v", t.CanOpenState, t.HasProvisioner)) } t.BootstrapOnce(c) // TODO(niemeyer): Stop growing this kitchen sink test and split it into proper parts. c.Logf("opening connection") conn, err := juju.NewConn(t.Env) c.Assert(err, IsNil) defer conn.Close() c.Logf("opening API connection") apiConn, err := juju.NewAPIConn(t.Env, api.DefaultDialOpts()) c.Assert(err, IsNil) defer conn.Close() // Check that the agent version has made it through the // bootstrap process (it's optional in the config.Config) cfg, err := conn.State.EnvironConfig() c.Assert(err, IsNil) agentVersion, ok := cfg.AgentVersion() c.Check(ok, Equals, true) c.Check(agentVersion, Equals, version.CurrentNumber()) // Check that the constraints have been set in the environment. cons, err := conn.State.EnvironConstraints() c.Assert(err, IsNil) c.Assert(cons.String(), Equals, "mem=2048M") // Wait for machine agent to come up on the bootstrap // machine and find the deployed series from that. m0, err := conn.State.Machine("0") c.Assert(err, IsNil) instId0, err := m0.InstanceId() c.Assert(err, IsNil) // Check that the API connection is working. status, err := apiConn.State.Client().Status() c.Assert(err, IsNil) c.Assert(status.Machines["0"].InstanceId, Equals, string(instId0)) mw0 := newMachineToolWaiter(m0) defer mw0.Stop() // If the series has not been specified, we expect the most recent Ubuntu LTS release to be used. expectedVersion := version.Current expectedVersion.Series = config.DefaultSeries mtools0 := waitAgentTools(c, mw0, expectedVersion) // Create a new service and deploy a unit of it. c.Logf("deploying service") repoDir := c.MkDir() url := coretesting.Charms.ClonedURL(repoDir, mtools0.Series, "dummy") sch, err := conn.PutCharm(url, &charm.LocalRepository{repoDir}, false) c.Assert(err, IsNil) svc, err := conn.State.AddService("dummy", sch) c.Assert(err, IsNil) units, err := conn.AddUnits(svc, 1, "") c.Assert(err, IsNil) unit := units[0] // Wait for the unit's machine and associated agent to come up // and announce itself. mid1, err := unit.AssignedMachineId() c.Assert(err, IsNil) m1, err := conn.State.Machine(mid1) c.Assert(err, IsNil) mw1 := newMachineToolWaiter(m1) defer mw1.Stop() waitAgentTools(c, mw1, mtools0.Binary) err = m1.Refresh() c.Assert(err, IsNil) instId1, err := m1.InstanceId() c.Assert(err, IsNil) uw := newUnitToolWaiter(unit) defer uw.Stop() utools := waitAgentTools(c, uw, expectedVersion) // Check that we can upgrade the environment. newVersion := utools.Binary newVersion.Patch++ t.checkUpgrade(c, conn, newVersion, mw0, mw1, uw) // BUG(niemeyer): Logic below is very much wrong. Must be: // // 1. EnsureDying on the unit and EnsureDying on the machine // 2. Unit dies by itself // 3. Machine removes dead unit // 4. Machine dies by itself // 5. Provisioner removes dead machine // // Now remove the unit and its assigned machine and // check that the PA removes it. c.Logf("removing unit") err = unit.Destroy() c.Assert(err, IsNil) // Wait until unit is dead uwatch := unit.Watch() defer uwatch.Stop() for unit.Life() != state.Dead { c.Logf("waiting for unit change") <-uwatch.Changes() err := unit.Refresh() c.Logf("refreshed; err %v", err) if errors.IsNotFoundError(err) { c.Logf("unit has been removed") break } c.Assert(err, IsNil) } for { c.Logf("destroying machine") err := m1.Destroy() if err == nil { break } c.Assert(err, FitsTypeOf, &state.HasAssignedUnitsError{}) time.Sleep(5 * time.Second) err = m1.Refresh() if errors.IsNotFoundError(err) { break } c.Assert(err, IsNil) } c.Logf("waiting for instance to be removed") t.assertStopInstance(c, conn.Environ, instId1) }