コード例 #1
0
ファイル: environs_test.go プロジェクト: bac/juju
func (s *suite) TestSupportsSpaceDiscovery(c *gc.C) {
	e := s.bootstrapTestEnviron(c)
	defer func() {
		err := e.Destroy()
		c.Assert(err, jc.ErrorIsNil)
	}()

	// Without change space discovery is not supported.
	ok, err := e.SupportsSpaceDiscovery()
	c.Assert(ok, jc.IsFalse)
	c.Assert(err, jc.ErrorIsNil)

	// Now turn it on.
	isEnabled := dummy.SetSupportsSpaceDiscovery(true)
	c.Assert(isEnabled, jc.IsFalse)
	ok, err = e.SupportsSpaceDiscovery()
	c.Assert(ok, jc.IsTrue)
	c.Assert(err, jc.ErrorIsNil)

	// And finally turn it off again.
	isEnabled = dummy.SetSupportsSpaceDiscovery(false)
	c.Assert(isEnabled, jc.IsTrue)
	ok, err = e.SupportsSpaceDiscovery()
	c.Assert(ok, jc.IsFalse)
	c.Assert(err, jc.ErrorIsNil)
}
コード例 #2
0
ファイル: worker_test.go プロジェクト: AlexisBruemmer/juju
func (s *WorkerSuite) TestWorkerIgnoresExistingSpacesAndSubnets(c *gc.C) {
	dummy.SetSupportsSpaceDiscovery(true)
	spaceTag := names.NewSpaceTag("foo")
	args := params.CreateSpacesParams{
		Spaces: []params.CreateSpaceParams{{
			Public:     false,
			SpaceTag:   spaceTag.String(),
			ProviderId: "foo",
		}}}
	result, err := s.API.CreateSpaces(args)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result.Results, gc.HasLen, 1)
	c.Assert(result.Results[0].Error, gc.IsNil)

	subnetArgs := params.AddSubnetsParams{
		Subnets: []params.AddSubnetParams{{
			SubnetProviderId: "1",
			SpaceTag:         spaceTag.String(),
			Zones:            []string{"zone1"},
		}}}
	subnetResult, err := s.API.AddSubnets(subnetArgs)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(subnetResult.Results, gc.HasLen, 1)
	c.Assert(subnetResult.Results[0].Error, gc.IsNil)

	s.unlockCheck(c, func(c *gc.C) {
		spaces, err := s.State.AllSpaces()
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(spaces, gc.HasLen, 5)
	})
}
コード例 #3
0
ファイル: worker_test.go プロジェクト: makyo/juju
func (s *WorkerSuite) TestWorkerDiscoversSpaces(c *gc.C) {
	dummy.SetSupportsSpaceDiscovery(true)
	s.unlockCheck(c, func(*gc.C) {
		s.assertDiscoveredSpaces(c)
		s.assertNumCalls(c, 1, 1)
	})
}
コード例 #4
0
ファイル: worker_test.go プロジェクト: makyo/juju
func (s *WorkerSuite) TestWorkerIdempotent(c *gc.C) {
	dummy.SetSupportsSpaceDiscovery(true)
	s.unlockCheck(c, s.assertDiscoveredSpaces)
	s.unlockCheck(c, func(*gc.C) {
		s.assertDiscoveredSpaces(c)
		s.assertNumCalls(c, 2, 2)
	})
}
コード例 #5
0
ファイル: worker_test.go プロジェクト: OSBI/juju
func (s *workerSuite) TestSpacesBroken(c *gc.C) {
	dummy.SetSupportsSpaceDiscovery(true)
	s.AssertConfigParameterUpdated(c, "broken", "Spaces")

	newWorker, spacesDiscovered := discoverspaces.NewWorker(s.API)
	s.spacesDiscovered = spacesDiscovered
	err := worker.Stop(newWorker)
	c.Assert(err, gc.ErrorMatches, "dummy.Spaces is broken")
	s.assertSpaceDiscoveryCompleted(c)
}
コード例 #6
0
ファイル: worker_test.go プロジェクト: AlexisBruemmer/juju
func (s *WorkerSuite) TestSpacesBroken(c *gc.C) {
	dummy.SetSupportsSpaceDiscovery(true)
	s.AssertConfigParameterUpdated(c, "broken", "Spaces")

	worker, lock := s.startWorker(c)
	err := workertest.CheckKilled(c, worker)
	c.Assert(err, gc.ErrorMatches, "dummy.Spaces is broken")

	select {
	case <-time.After(coretesting.ShortWait):
	case <-lock.Unlocked():
		c.Fatalf("gate unlocked despite worker failure")
	}
}
コード例 #7
0
ファイル: worker_test.go プロジェクト: AlexisBruemmer/juju
func (s *WorkerSuite) TestWorkerSupportsNetworkingFalse(c *gc.C) {
	// We set SupportsSpaceDiscovery to true so that spaces *would* be
	// discovered if networking was supported. So we know that if they're
	// discovered it must be because networking is not supported.
	dummy.SetSupportsSpaceDiscovery(true)

	// TODO(fwereade): monkey-patching remote packages is even worse
	// than monkey-patching local packages, please don't do it.
	noNetworking := func(environs.Environ) (environs.NetworkingEnviron, bool) {
		return nil, false
	}
	s.PatchValue(&environs.SupportsNetworking, noNetworking)

	s.unlockCheck(c, s.assertDiscoveredNoSpaces)
}
コード例 #8
0
ファイル: worker_test.go プロジェクト: OSBI/juju
func (s *workerSuite) TestWorkerIgnoresExistingSpacesAndSubnets(c *gc.C) {
	dummy.SetSupportsSpaceDiscovery(true)
	spaceTag := names.NewSpaceTag("foo")
	args := params.CreateSpacesParams{
		Spaces: []params.CreateSpaceParams{{
			Public:     false,
			SpaceTag:   spaceTag.String(),
			ProviderId: "foo",
		}}}
	result, err := s.API.CreateSpaces(args)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result.Results, gc.HasLen, 1)
	c.Assert(result.Results[0].Error, gc.IsNil)

	subnetArgs := params.AddSubnetsParams{
		Subnets: []params.AddSubnetParams{{
			SubnetProviderId: "1",
			SpaceTag:         spaceTag.String(),
			Zones:            []string{"zone1"},
		}}}
	subnetResult, err := s.API.AddSubnets(subnetArgs)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(subnetResult.Results, gc.HasLen, 1)
	c.Assert(subnetResult.Results[0].Error, gc.IsNil)

	s.startWorker()
	for a := common.ShortAttempt.Start(); a.Next(); {
		spaces, err := s.State.AllSpaces()
		if err != nil {
			break
		}
		if len(spaces) == 4 {
			// All spaces have been created.
			break
		}
		if !a.HasNext() {
			c.Fatalf("spaces not imported")
		}
	}
	c.Assert(err, jc.ErrorIsNil)
}
コード例 #9
0
ファイル: worker_test.go プロジェクト: OSBI/juju
func (s *workerSuite) TestWorkerIdempotent(c *gc.C) {
	dummy.SetSupportsSpaceDiscovery(true)
	s.startWorker()
	var err error
	var spaces []*state.Space
	for a := common.ShortAttempt.Start(); a.Next(); {
		spaces, err = s.State.AllSpaces()
		if err != nil {
			break
		}
		if len(spaces) == 4 {
			// All spaces have been created.
			break
		}
		if !a.HasNext() {
			c.Fatalf("spaces not imported")
		}
	}
	c.Assert(err, jc.ErrorIsNil)
	newWorker, _ := discoverspaces.NewWorker(s.API)

	// This ensures that the worker can handle re-importing without error.
	defer func() {
		c.Assert(worker.Stop(newWorker), jc.ErrorIsNil)
	}()

	// Check that no extra spaces are imported.
	for a := common.ShortAttempt.Start(); a.Next(); {
		spaces, err = s.State.AllSpaces()
		if err != nil {
			break
		}
		if len(spaces) != 4 {
			c.Fatalf("unexpected number of spaces: %v", len(spaces))
		}
		if !a.HasNext() {
			break
		}
	}
}
コード例 #10
0
ファイル: worker_test.go プロジェクト: OSBI/juju
func (s *workerSuite) TestWorkerSupportsNetworkingFalse(c *gc.C) {
	// We set SupportsSpaceDiscovery to true so that spaces *would* be
	// discovered if networking was supported. So we know that if they're
	// discovered it must be because networking is not supported.
	dummy.SetSupportsSpaceDiscovery(true)
	noNetworking := func(environs.Environ) (environs.NetworkingEnviron, bool) {
		return nil, false
	}
	s.PatchValue(&environs.SupportsNetworking, noNetworking)
	s.startWorker()

	// No spaces will have been created, worker does nothing.
	for a := common.ShortAttempt.Start(); a.Next(); {
		spaces, err := s.State.AllSpaces()
		c.Assert(err, jc.ErrorIsNil)
		if len(spaces) != 0 {
			c.Fatalf("spaces should not be created, we have %v", len(spaces))
		}
		if !a.HasNext() {
			break
		}
	}
	s.assertSpaceDiscoveryCompleted(c)
}
コード例 #11
0
ファイル: worker_test.go プロジェクト: OSBI/juju
func (s *workerSuite) TestWorkerDiscoversSpaces(c *gc.C) {
	dummy.SetSupportsSpaceDiscovery(true)
	s.startWorker()
	var err error
	var spaces []*state.Space
	for a := common.ShortAttempt.Start(); a.Next(); {
		spaces, err = s.State.AllSpaces()
		if err != nil {
			break
		}
		if len(spaces) == 4 {
			// All spaces have been created.
			break
		}
		if !a.HasNext() {
			c.Fatalf("spaces not imported")
		}
	}
	c.Assert(err, jc.ErrorIsNil)
	expectedSpaces := []network.SpaceInfo{{
		Name:       "foo",
		ProviderId: network.Id("foo"),
		Subnets: []network.SubnetInfo{{
			ProviderId:        network.Id("1"),
			CIDR:              "192.168.1.0/24",
			AvailabilityZones: []string{"zone1"},
		}, {
			ProviderId:        network.Id("2"),
			CIDR:              "192.168.2.0/24",
			AvailabilityZones: []string{"zone1"},
		}}}, {
		Name:       "another-foo-99",
		ProviderId: network.Id("Another Foo 99!"),
		Subnets: []network.SubnetInfo{{
			ProviderId:        network.Id("3"),
			CIDR:              "192.168.3.0/24",
			AvailabilityZones: []string{"zone1"},
		}}}, {
		Name:       "foo-2",
		ProviderId: network.Id("foo-"),
		Subnets: []network.SubnetInfo{{
			ProviderId:        network.Id("4"),
			CIDR:              "192.168.4.0/24",
			AvailabilityZones: []string{"zone1"},
		}}}, {
		Name:       "empty",
		ProviderId: network.Id("---"),
		Subnets: []network.SubnetInfo{{
			ProviderId:        network.Id("5"),
			CIDR:              "192.168.5.0/24",
			AvailabilityZones: []string{"zone1"},
		}}}}
	expectedSpaceMap := make(map[string]network.SpaceInfo)
	for _, space := range expectedSpaces {
		expectedSpaceMap[space.Name] = space
	}
	for _, space := range spaces {
		expected, ok := expectedSpaceMap[space.Name()]
		if !c.Check(ok, jc.IsTrue) {
			continue
		}
		c.Check(space.ProviderId(), gc.Equals, expected.ProviderId)
		subnets, err := space.Subnets()
		if !c.Check(err, jc.ErrorIsNil) {
			continue
		}
		c.Check(len(subnets), gc.Equals, len(expected.Subnets))
		for i, subnet := range subnets {
			expectedSubnet := expected.Subnets[i]
			c.Check(subnet.ProviderId(), gc.Equals, expectedSubnet.ProviderId)
			c.Check([]string{subnet.AvailabilityZone()}, jc.DeepEquals, expectedSubnet.AvailabilityZones)
			c.Check(subnet.CIDR(), gc.Equals, expectedSubnet.CIDR)
		}
	}
	s.assertSpaceDiscoveryCompleted(c)
}
コード例 #12
0
ファイル: worker_test.go プロジェクト: AlexisBruemmer/juju
func (s *WorkerSuite) TestWorkerDiscoversSpaces(c *gc.C) {
	dummy.SetSupportsSpaceDiscovery(true)
	s.unlockCheck(c, s.assertDiscoveredSpaces)
}