func (s *StorageSuite) TestReadList(c *gc.C) { store := s.env.Storage() v001 := version.MustParseBinary("0.0.1-precise-amd64") t001 := envtesting.UploadFakeToolsVersion(c, store, v001) v100 := version.MustParseBinary("1.0.0-precise-amd64") t100 := envtesting.UploadFakeToolsVersion(c, store, v100) v101 := version.MustParseBinary("1.0.1-precise-amd64") t101 := envtesting.UploadFakeToolsVersion(c, store, v101) for i, t := range []struct { majorVersion int list tools.List }{{ 0, tools.List{t001}, }, { 1, tools.List{t100, t101}, }, { 2, nil, }} { c.Logf("test %d", i) list, err := tools.ReadList(store, t.majorVersion) if t.list != nil { c.Assert(err, gc.IsNil) c.Assert(list, gc.DeepEquals, t.list) } else { c.Assert(err, gc.Equals, tools.ErrNoMatches) } } }
func (s *ToolsSuite) uploadVersions(c *C, storage environs.Storage, verses ...version.Binary) map[version.Binary]string { uploaded := map[version.Binary]string{} for _, vers := range verses { uploaded[vers] = envtesting.UploadFakeToolsVersion(c, storage, vers).URL } return uploaded }
func (s *syncToolsSuite) TestCopyToDummyPublicBlockedByPrivate(c *C) { envtesting.UploadFakeToolsVersion(c, s.targetEnv.Storage(), v200p64) _, err := runSyncToolsCommand(c, "-e", "test-target", "--public") c.Assert(err, ErrorMatches, "private tools present: public tools would be ignored") assertEmpty(c, s.targetEnv.PublicStorage()) }
func (s *syncSuite) TestCopyToDummyPublicBlockedByPrivate(c *gc.C) { s.setUpTest(c) defer s.tearDownTest(c) envtesting.UploadFakeToolsVersion(c, s.targetEnv.Storage(), v200p64) ctx := &sync.SyncContext{ EnvName: "test-target", PublicBucket: true, } err := sync.SyncTools(ctx) c.Assert(err, gc.ErrorMatches, "private tools present: public tools would be ignored") assertEmpty(c, s.targetEnv.PublicStorage()) }
func (s *MachineSuite) TestManageEnviron(c *C) { usefulVersion := version.Current usefulVersion.Series = "series" // to match the charm created below envtesting.UploadFakeToolsVersion(c, s.Conn.Environ.Storage(), usefulVersion) m, _, _ := s.primeAgent(c, state.JobManageEnviron) op := make(chan dummy.Operation, 200) dummy.Listen(op) a := s.newAgent(c, m) // Make sure the agent is stopped even if the test fails. defer a.Stop() done := make(chan error) go func() { done <- a.Run(nil) }() // Check that the provisioner and firewaller are alive by doing // a rudimentary check that it responds to state changes. // Add one unit to a service; it should get allocated a machine // and then its ports should be opened. charm := s.AddTestingCharm(c, "dummy") svc, err := s.State.AddService("test-service", charm) c.Assert(err, IsNil) err = svc.SetExposed() c.Assert(err, IsNil) units, err := s.Conn.AddUnits(svc, 1, "") c.Assert(err, IsNil) c.Check(opRecvTimeout(c, s.State, op, dummy.OpStartInstance{}), NotNil) // Wait for the instance id to show up in the state. id1, err := units[0].AssignedMachineId() c.Assert(err, IsNil) m1, err := s.State.Machine(id1) c.Assert(err, IsNil) w := m1.Watch() defer w.Stop() for _ = range w.Changes() { err = m1.Refresh() c.Assert(err, IsNil) if _, err := m1.InstanceId(); err == nil { break } else { c.Check(err, FitsTypeOf, (*state.NotProvisionedError)(nil)) } } err = units[0].OpenPort("tcp", 999) c.Assert(err, IsNil) c.Check(opRecvTimeout(c, s.State, op, dummy.OpOpenPorts{}), NotNil) err = a.Stop() c.Assert(err, IsNil) select { case err := <-done: c.Assert(err, IsNil) case <-time.After(5 * time.Second): c.Fatalf("timed out waiting for agent to terminate") } }
func (test bootstrapTest) run(c *C) { defer testing.MakeFakeHome(c, envConfig).Restore() dummy.Reset() env, err := environs.NewFromName("peckham") c.Assert(err, IsNil) envtesting.RemoveAllTools(c, env) if test.version != "" { origVersion := version.Current version.Current = version.MustParseBinary(test.version) defer func() { version.Current = origVersion }() } uploadCount := len(test.uploads) if uploadCount == 0 { usefulVersion := version.Current usefulVersion.Series = env.Config().DefaultSeries() envtesting.UploadFakeToolsVersion(c, env.Storage(), usefulVersion) } // Run command and check for uploads. opc, errc := runCommand(new(BootstrapCommand), test.args...) if uploadCount > 0 { for i := 0; i < uploadCount; i++ { c.Check((<-opc).(dummy.OpPutFile).Env, Equals, "peckham") } list, err := environs.FindAvailableTools(env, version.Current.Major) c.Check(err, IsNil) c.Logf("found: " + list.String()) urls := list.URLs() c.Check(urls, HasLen, len(test.uploads)) for _, v := range test.uploads { c.Logf("seeking: " + v) vers := version.MustParseBinary(v) _, found := urls[vers] c.Check(found, Equals, true) } } // Check for remaining operations/errors. if test.err != "" { c.Check(<-errc, ErrorMatches, test.err) return } if !c.Check(<-errc, IsNil) { return } opPutBootstrapVerifyFile := (<-opc).(dummy.OpPutFile) c.Check(opPutBootstrapVerifyFile.Env, Equals, "peckham") c.Check(opPutBootstrapVerifyFile.FileName, Equals, "bootstrap-verify") opBootstrap := (<-opc).(dummy.OpBootstrap) c.Check(opBootstrap.Env, Equals, "peckham") c.Check(opBootstrap.Constraints, DeepEquals, test.constraints) // Check a CA cert/key was generated by reloading the environment. env, err = environs.NewFromName("peckham") c.Assert(err, IsNil) _, hasCert := env.Config().CACert() c.Check(hasCert, Equals, true) _, hasKey := env.Config().CAPrivateKey() c.Check(hasKey, Equals, true) }