Commit b4573791 authored by Deyuan Deng's avatar Deyuan Deng

Merge pull request #5033 from mikedanese/lookup-mock

mock LookupIP to speedup nodecontroller_test on some runtimes
parents ea0524fd a663d3b1
...@@ -40,6 +40,11 @@ var ( ...@@ -40,6 +40,11 @@ var (
ErrCloudInstance = errors.New("cloud provider doesn't support instances.") ErrCloudInstance = errors.New("cloud provider doesn't support instances.")
) )
var (
// aliased to allow mocking in tests
lookupIP = net.LookupIP
)
type NodeController struct { type NodeController struct {
cloud cloudprovider.Interface cloud cloudprovider.Interface
matchRE string matchRE string
...@@ -285,7 +290,7 @@ func (s *NodeController) PopulateIPs(nodes *api.NodeList) (*api.NodeList, error) ...@@ -285,7 +290,7 @@ func (s *NodeController) PopulateIPs(nodes *api.NodeList) (*api.NodeList, error)
if addr != nil { if addr != nil {
node.Status.HostIP = node.Name node.Status.HostIP = node.Name
} else { } else {
addrs, err := net.LookupIP(node.Name) addrs, err := lookupIP(node.Name)
if err != nil { if err != nil {
glog.Errorf("Can't get ip address of node %s: %v", node.Name, err) glog.Errorf("Can't get ip address of node %s: %v", node.Name, err)
} else if len(addrs) == 0 { } else if len(addrs) == 0 {
......
...@@ -18,6 +18,7 @@ package controller ...@@ -18,6 +18,7 @@ package controller
import ( import (
"errors" "errors"
"fmt"
"net" "net"
"reflect" "reflect"
"sort" "sort"
...@@ -51,6 +52,12 @@ type FakeNodeHandler struct { ...@@ -51,6 +52,12 @@ type FakeNodeHandler struct {
RequestCount int RequestCount int
} }
func init() {
lookupIP = func(host string) ([]net.IP, error) {
return nil, fmt.Errorf("lookup %v: no such host", host)
}
}
func (c *FakeNodeHandler) Nodes() client.NodeInterface { func (c *FakeNodeHandler) Nodes() client.NodeInterface {
return c return c
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment