Exemplo n.º 1
0
func (s *AddresserSuite) TestRemoveSuccess(c *gc.C) {
	tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
	tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")
	tag3 := names.NewIPAddressTag("33333333-0000-0000-0000-000000000000")

	var called int
	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag1.String()},
			{Tag: tag2.String()},
			{Tag: tag3.String()},
		},
	}
	results := params.ErrorResults{
		Results: []params.ErrorResult{{nil}, {nil}, {nil}},
	}
	apiCaller := successAPICaller(c, "Remove", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddress1 := addresser.NewIPAddress(api, tag1, params.Alive)
	ipAddress2 := addresser.NewIPAddress(api, tag2, params.Dying)
	ipAddress3 := addresser.NewIPAddress(api, tag3, params.Dead)

	err := api.Remove(ipAddress1, ipAddress2, ipAddress3)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, gc.Equals, 1)
}
Exemplo n.º 2
0
func (s *AddresserSuite) TestIPAddressesSuccess(c *gc.C) {
	tests := []struct {
		tag  names.IPAddressTag
		life params.Life
	}{
		{names.NewIPAddressTag("11111111-0000-0000-0000-000000000000"), params.Alive},
		{names.NewIPAddressTag("22222222-0000-0000-0000-000000000000"), params.Dying},
		{names.NewIPAddressTag("33333333-0000-0000-0000-000000000000"), params.Dead},
	}
	for _, test := range tests {
		var called int
		args := params.Entities{
			Entities: []params.Entity{{Tag: test.tag.String()}},
		}
		results := params.LifeResults{
			Results: []params.LifeResult{{test.life, nil}},
		}
		apiCaller := successAPICaller(c, "Life", args, results, &called)
		api := addresser.NewAPI(apiCaller)

		ipAddress, err := api.IPAddress(test.tag)
		c.Assert(err, jc.ErrorIsNil)
		c.Assert(called, gc.Equals, 1)
		c.Check(ipAddress.Tag(), gc.Equals, test.tag)
		c.Check(ipAddress.Life(), gc.Equals, test.life)
	}
}
Exemplo n.º 3
0
func (s *AddresserSuite) TestIPAddressesSuccess(c *gc.C) {
	tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
	tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")
	tag3 := names.NewIPAddressTag("33333333-0000-0000-0000-000000000000")

	var called int
	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag1.String()},
			{Tag: tag2.String()},
			{Tag: tag3.String()},
		},
	}
	results := params.LifeResults{
		Results: []params.LifeResult{
			{Life: params.Alive},
			{Life: params.Dying},
			{Life: params.Dead},
		},
	}
	apiCaller := successAPICaller(c, "Life", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddresses, err := api.IPAddresses(tag1, tag2, tag3)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(called, gc.Equals, 1)
	c.Assert(len(ipAddresses), gc.Equals, 3)
	for i, ipAddress := range ipAddresses {
		c.Check(ipAddress.Tag().String(), gc.Equals, args.Entities[i].Tag)
		c.Check(ipAddress.Life(), gc.Equals, results.Results[i].Life)
	}
}
Exemplo n.º 4
0
func (s *AddresserSuite) TestIPAddressesServerError(c *gc.C) {
	tag1 := names.NewIPAddressTag("11111111-0000-0000-0000-000000000000")
	tag2 := names.NewIPAddressTag("22222222-0000-0000-0000-000000000000")

	var called int
	args := params.Entities{
		Entities: []params.Entity{
			{Tag: tag1.String()},
			{Tag: tag2.String()},
		},
	}
	results := params.LifeResults{
		Results: []params.LifeResult{
			{params.Alive, nil},
			{"", apiservertesting.ServerError("server failure")},
		},
	}
	apiCaller := successAPICaller(c, "Life", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddresses, err := api.IPAddresses(tag1, tag2)
	c.Assert(len(ipAddresses), gc.Equals, 2)
	c.Assert(ipAddresses[0].Tag().String(), gc.Equals, tag1.String())
	c.Assert(ipAddresses[1], gc.IsNil)
	c.Assert(err, gc.Equals, common.ErrPartialResults)
	c.Assert(called, gc.Equals, 1)
}
Exemplo n.º 5
0
func (s *ipAddressSuite) TestNewIPAddressTag(c *gc.C) {
	uuid := utils.MustNewUUID()
	tag := names.NewIPAddressTag(uuid.String())
	parsed, err := names.ParseIPAddressTag(tag.String())
	c.Assert(err, gc.IsNil)
	c.Assert(parsed.Kind(), gc.Equals, names.IPAddressTagKind)
	c.Assert(parsed.Id(), gc.Equals, uuid.String())
	c.Assert(parsed.String(), gc.Equals, names.IPAddressTagKind+"-"+uuid.String())

	f := func() {
		tag = names.NewIPAddressTag("42")
	}
	c.Assert(f, gc.PanicMatches, `invalid UUID: "42"`)
}
Exemplo n.º 6
0
func (mst *mockState) setUpState() {
	mst.mu.Lock()
	defer mst.mu.Unlock()

	ips := []struct {
		value      string
		uuid       string
		life       state.Life
		subnetId   string
		instanceId string
		macaddr    string
	}{
		{"0.1.2.3", "00000000-1111-2222-3333-0123456789ab", state.Alive, "a", "a3", "fff3"},
		{"0.1.2.4", "00000000-1111-2222-4444-0123456789ab", state.Alive, "b", "b4", "fff4"},
		{"0.1.2.5", "00000000-1111-2222-5555-0123456789ab", state.Alive, "b", "b5", "fff5"},
		{"0.1.2.6", "00000000-1111-2222-6666-0123456789ab", state.Dead, "c", "c6", "fff6"},
		{"0.1.2.7", "00000000-1111-2222-7777-0123456789ab", state.Dead, "c", "c7", "fff7"},
	}
	for _, ip := range ips {
		mst.ipAddresses[ip.value] = &mockIPAddress{
			stub:       mst.stub,
			st:         mst,
			value:      ip.value,
			tag:        names.NewIPAddressTag(ip.uuid),
			life:       ip.life,
			subnetId:   ip.subnetId,
			instanceId: instance.Id(ip.instanceId),
			addr:       network.NewAddress(ip.value),
			macaddr:    ip.macaddr,
		}
	}
}
Exemplo n.º 7
0
func (s *AddresserSuite) TestIPAddressesClientError(c *gc.C) {
	var called int
	apiCaller := clientErrorAPICaller(c, "Life", nil, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddress, err := api.IPAddress(names.NewIPAddressTag("00000000-0000-0000-0000-000000000000"))
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(ipAddress, gc.IsNil)
	c.Assert(called, gc.Equals, 1)
}
Exemplo n.º 8
0
func (s *AddresserSuite) TestRemoveClientError(c *gc.C) {
	var called int
	tag := names.NewIPAddressTag("00000000-0000-0000-0000-000000000000")
	apiCaller := clientErrorAPICaller(c, "Remove", nil, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddress := addresser.NewIPAddress(api, tag, params.Alive)
	err := ipAddress.Remove()
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(called, gc.Equals, 1)
}
Exemplo n.º 9
0
func (s *IPAddressSuite) TestIPAddressByTag(c *gc.C) {
	addr := network.NewScopedAddress("0.1.2.3", network.ScopePublic)
	added, err := s.State.AddIPAddress(addr, "foobar")
	c.Assert(err, jc.ErrorIsNil)

	uuid, err := added.UUID()
	c.Assert(err, jc.ErrorIsNil)
	tag := names.NewIPAddressTag(uuid.String())
	found, err := s.State.IPAddressByTag(tag)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(found.Id(), gc.Equals, added.Id())
}
Exemplo n.º 10
0
func (s *AddresserSuite) TestNewAPISuccess(c *gc.C) {
	var called int
	// IPAddress below uses common.Life for implementation.
	apiCaller := clientErrorAPICaller(c, "Life", nil, &called)
	api := addresser.NewAPI(apiCaller)
	c.Check(api, gc.NotNil)
	c.Check(called, gc.Equals, 0)

	// Make a call so that an error will be returned.
	addresses, err := api.IPAddress(names.NewIPAddressTag("00000000-0000-0000-0000-000000000000"))
	c.Assert(err, gc.ErrorMatches, "client error!")
	c.Assert(addresses, gc.IsNil)
	c.Assert(called, gc.Equals, 1)
}
Exemplo n.º 11
0
func (s *AddresserSuite) TestRemoveServerError(c *gc.C) {
	var called int
	tag := names.NewIPAddressTag("00000000-0000-0000-0000-000000000000")
	args := params.Entities{
		Entities: []params.Entity{{Tag: tag.String()}},
	}
	results := params.ErrorResults{
		Results: []params.ErrorResult{{apiservertesting.ServerError("server boom!")}},
	}
	apiCaller := successAPICaller(c, "Remove", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddress := addresser.NewIPAddress(api, tag, params.Alive)
	err := ipAddress.Remove()
	c.Assert(err, gc.ErrorMatches, "server boom!")
	c.Assert(called, gc.Equals, 1)
}
Exemplo n.º 12
0
func (s *AddresserSuite) TestIPAddressesServerError(c *gc.C) {
	var called int
	tag := names.NewIPAddressTag("00000000-0000-0000-0000-000000000000")
	args := params.Entities{
		Entities: []params.Entity{{Tag: tag.String()}},
	}
	results := params.LifeResults{
		Results: []params.LifeResult{{"", apiservertesting.ServerError("server boom!")}},
	}
	apiCaller := successAPICaller(c, "Life", args, results, &called)
	api := addresser.NewAPI(apiCaller)

	ipAddress, err := api.IPAddress(tag)
	c.Assert(ipAddress, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "server boom!")
	c.Assert(called, gc.Equals, 1)
}
Exemplo n.º 13
0
func (mst *mockState) setUpIPAddresses() {
	ips := []struct {
		value string
		uuid  string
		life  state.Life
	}{
		{"0.1.2.3", "00000000-1111-2222-3333-0123456789ab", state.Alive},
		{"0.1.2.4", "00000000-1111-2222-4444-0123456789ab", state.Alive},
		{"0.1.2.5", "00000000-1111-2222-5555-0123456789ab", state.Alive},
		{"0.1.2.6", "00000000-1111-2222-6666-0123456789ab", state.Dead},
		{"0.1.2.7", "00000000-1111-2222-7777-0123456789ab", state.Dead},
	}
	for _, ip := range ips {
		mst.ipAddresses[ip.value] = &mockIPAddress{
			stub:  mst.stub,
			st:    mst,
			value: ip.value,
			tag:   names.NewIPAddressTag(ip.uuid),
			life:  ip.life,
		}
	}
}
Exemplo n.º 14
0
	c.Assert(parsed.Id(), gc.Equals, uuid.String())
	c.Assert(parsed.String(), gc.Equals, names.IPAddressTagKind+"-"+uuid.String())

	f := func() {
		tag = names.NewIPAddressTag("42")
	}
	c.Assert(f, gc.PanicMatches, `invalid UUID: "42"`)
}

var parseIPAddressTagTests = []struct {
	tag      string
	expected names.Tag
	err      error
}{
	{tag: "", err: names.InvalidTagError("", "")},
	{tag: "ipaddress-42424242-1111-2222-3333-0123456789ab", expected: names.NewIPAddressTag("42424242-1111-2222-3333-0123456789ab")},
	{tag: "ipaddress-012345678", err: names.InvalidTagError("ipaddress-012345678", names.IPAddressTagKind)},
	{tag: "ipaddress-42", err: names.InvalidTagError("ipaddress-42", names.IPAddressTagKind)},
	{tag: "foobar", err: names.InvalidTagError("foobar", "")},
	{tag: "space-yadda", err: names.InvalidTagError("space-yadda", names.IPAddressTagKind)}}

func (s *ipAddressSuite) TestParseIPAddressTag(c *gc.C) {
	for i, t := range parseIPAddressTagTests {
		c.Logf("test %d: %s", i, t.tag)
		got, err := names.ParseIPAddressTag(t.tag)
		if err != nil || t.err != nil {
			c.Check(err, gc.DeepEquals, t.err)
			continue
		}
		c.Check(got, gc.FitsTypeOf, t.expected)
		c.Check(got, gc.Equals, t.expected)
Exemplo n.º 15
0
func (s *IPAddressSuite) TestIPAddressByTagNotFound(c *gc.C) {
	tag := names.NewIPAddressTag("42424242-1111-2222-3333-0123456789ab")
	_, err := s.State.IPAddressByTag(tag)
	c.Assert(err, gc.ErrorMatches, `IP address "ipaddress-42424242-1111-2222-3333-0123456789ab" not found`)
}
Exemplo n.º 16
0
// Tag returns the tag of the IP address.
func (i *IPAddress) Tag() names.Tag {
	return names.NewIPAddressTag(i.doc.UUID)
}
Exemplo n.º 17
0
	resultId:   "myspace1",
}}

var makeTag = map[string]func(string) names.Tag{
	names.MachineTagKind:    func(tag string) names.Tag { return names.NewMachineTag(tag) },
	names.UnitTagKind:       func(tag string) names.Tag { return names.NewUnitTag(tag) },
	names.ServiceTagKind:    func(tag string) names.Tag { return names.NewServiceTag(tag) },
	names.RelationTagKind:   func(tag string) names.Tag { return names.NewRelationTag(tag) },
	names.EnvironTagKind:    func(tag string) names.Tag { return names.NewEnvironTag(tag) },
	names.UserTagKind:       func(tag string) names.Tag { return names.NewUserTag(tag) },
	names.NetworkTagKind:    func(tag string) names.Tag { return names.NewNetworkTag(tag) },
	names.ActionTagKind:     func(tag string) names.Tag { return names.NewActionTag(tag) },
	names.VolumeTagKind:     func(tag string) names.Tag { return names.NewVolumeTag(tag) },
	names.FilesystemTagKind: func(tag string) names.Tag { return names.NewFilesystemTag(tag) },
	names.StorageTagKind:    func(tag string) names.Tag { return names.NewStorageTag(tag) },
	names.IPAddressTagKind:  func(tag string) names.Tag { return names.NewIPAddressTag(tag) },
	names.SubnetTagKind:     func(tag string) names.Tag { return names.NewSubnetTag(tag) },
	names.SpaceTagKind:      func(tag string) names.Tag { return names.NewSpaceTag(tag) },
}

func (*tagSuite) TestParseTag(c *gc.C) {
	for i, test := range parseTagTests {
		c.Logf("test %d: %q expectKind %q", i, test.tag, test.expectKind)
		tag, err := names.ParseTag(test.tag)
		if test.resultErr != "" {
			c.Assert(err, gc.ErrorMatches, test.resultErr)
			c.Assert(tag, gc.IsNil)

			// If the tag has a valid kind which matches the
			// expected kind, test that using an empty
			// expectKind does not change the error message.