Пример #1
0
func (s *CacheChangedAPISuite) TestAPIEndpointNotMachineLocalOrLinkLocal(c *gc.C) {
	store := configstore.NewMem()
	info, err := store.CreateInfo("env-name")
	c.Assert(err, gc.IsNil)

	hostPorts := [][]network.HostPort{
		network.AddressesWithPort([]network.Address{
			network.NewAddress("1.0.0.1", network.ScopeUnknown),
			network.NewAddress("192.0.0.1", network.ScopeUnknown),
			network.NewAddress("127.0.0.1", network.ScopeUnknown),
			network.NewAddress("localhost", network.ScopeMachineLocal),
			network.NewAddress("::1", network.ScopeUnknown),
			network.NewAddress("fe80::1", network.ScopeUnknown),
			network.NewAddress("fc00::1", network.ScopeUnknown),
			network.NewAddress("2001:db8::1", network.ScopeUnknown),
		}, 1234),
		network.AddressesWithPort([]network.Address{
			network.NewAddress("1.0.0.2", network.ScopeUnknown),
			network.NewAddress("2002:0:0:0:0:0:100:2", network.ScopeUnknown),
			network.NewAddress("::1", network.ScopeUnknown),
			network.NewAddress("127.0.0.1", network.ScopeUnknown),
			network.NewAddress("localhost", network.ScopeMachineLocal),
		}, 1235),
	}

	envTag := names.NewEnvironTag("fake-uuid")
	err = juju.CacheChangedAPIInfo(info, hostPorts, envTag.String())
	c.Assert(err, gc.IsNil)

	endpoint := info.APIEndpoint()
	c.Check(endpoint.Addresses, gc.DeepEquals, []string{
		"1.0.0.1:1234",
		"192.0.0.1:1234",
		"[fc00::1]:1234",
		"[2001:db8::1]:1234",
		"1.0.0.2:1235",
		"[2002:0:0:0:0:0:100:2]:1235",
	})
}
Пример #2
0
func (s *CacheAPIEndpointsSuite) TestPrepareEndpointsForCachingPreferIPv6False(c *gc.C) {
	info := s.store.CreateInfo("env-name1")
	s.PatchValue(juju.MaybePreferIPv6, func(_ configstore.EnvironInfo) bool {
		return false
	})
	// First test cacheChangedAPIInfo behaves as expected.
	err := juju.CacheChangedAPIInfo(info, s.hostPorts, s.apiHostPort, s.envTag.Id(), "")
	c.Assert(err, jc.ErrorIsNil)
	s.assertEndpointsPreferIPv6False(c, info)

	// Now test cacheAPIInfo behaves the same way.
	s.resolveSeq = 1
	s.resolveNumCalls = 0
	s.numResolved = 0
	info = s.store.CreateInfo("env-name2")
	mockAPIInfo := s.APIInfo(c)
	mockAPIInfo.EnvironTag = s.envTag
	hps := network.CollapseHostPorts(s.hostPorts)
	mockAPIInfo.Addrs = network.HostPortsToStrings(hps)
	err = juju.CacheAPIInfo(s.APIState, info, mockAPIInfo)
	c.Assert(err, jc.ErrorIsNil)
	s.assertEndpointsPreferIPv6False(c, info)
}