-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
juju: use new DNS caching functionality
We rely on the new API client functionality to do our DNS resolving for us, and store any resulting cached names in the controllers.yaml entry. The UnresolvedAPIEndpoints field is now redundant and is replaced by the strictly advisory DNSCache field. The APIEndpoints field now always contains all the host names returned from the Login call with the exception of addresses deemed unusable (e.g. link-local addresses). We also change rpcreflect.Value.FindMethod to accept any version so that it's more useful for testing - this makes it possible to server limited portions of the juju API from a mocked API type without implementing a custom FindMethod. And, in passing, fix rpc.NewConn so that it works with a nil obververFactory as documented. QA check that API connections still work OK, particularly on MAAS setups where some of the returned host names will not resolve on a client. Also, check that: juju register jaas juju list-models does not produce the "cannot validate certificate for because it doesn't contain any IP SANs" error. Fixes https://bugs.launchpad.net/juju/+bug/1692905
- Loading branch information
Showing
20 changed files
with
510 additions
and
670 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package testing | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/juju/juju/rpc" | ||
"github.com/juju/juju/rpc/jsoncodec" | ||
) | ||
|
||
// FakeAPIServer returns a net.Conn implementation | ||
// that serves the RPC server defined by the given | ||
// root object (see rpc.Conn.Serve). | ||
func FakeAPIServer(root interface{}) net.Conn { | ||
c0, c1 := net.Pipe() | ||
serverCodec := jsoncodec.NewNet(c1) | ||
serverRPC := rpc.NewConn(serverCodec, nil) | ||
serverRPC.Serve(root, nil) | ||
serverRPC.Start() | ||
go func() { | ||
<-serverRPC.Dead() | ||
serverRPC.Close() | ||
}() | ||
return c0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2017 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package testing | ||
|
||
import ( | ||
"context" | ||
"net" | ||
|
||
"github.com/juju/errors" | ||
|
||
"github.com/juju/juju/api" | ||
) | ||
|
||
var _ api.IPAddrResolver = IPAddrResolverMap(nil) | ||
|
||
// IPAddrResolverMap implements IPAddrResolver by looking up the | ||
// addresses in the map, which maps host names to IP addresses. The | ||
// strings in the value slices should be valid IP addresses. | ||
type IPAddrResolverMap map[string][]string | ||
|
||
func (r IPAddrResolverMap) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error) { | ||
if ip := net.ParseIP(host); ip != nil { | ||
return []net.IPAddr{{IP: ip}}, nil | ||
} | ||
ipStrs := r[host] | ||
if len(ipStrs) == 0 { | ||
return nil, errors.Errorf("mock resolver cannot resolve %q", host) | ||
} | ||
ipAddrs := make([]net.IPAddr, len(ipStrs)) | ||
for i, ipStr := range ipStrs { | ||
ip := net.ParseIP(ipStr) | ||
if ip == nil { | ||
panic("invalid IP address: " + ipStr) | ||
} | ||
ipAddrs[i] = net.IPAddr{ | ||
IP: ip, | ||
} | ||
} | ||
return ipAddrs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.