|
|
@ -20,6 +20,7 @@ import ( |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/http/httptest" |
|
|
|
"net/http/httptest" |
|
|
|
|
|
|
|
"net/url" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gorilla/rpc/v2/json" |
|
|
|
"github.com/gorilla/rpc/v2/json" |
|
|
@ -29,6 +30,7 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
type ControllerRPCSuite struct { |
|
|
|
type ControllerRPCSuite struct { |
|
|
|
root string |
|
|
|
root string |
|
|
|
|
|
|
|
url *url.URL |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var _ = Suite(&ControllerRPCSuite{}) |
|
|
|
var _ = Suite(&ControllerRPCSuite{}) |
|
|
@ -48,6 +50,10 @@ func (s *ControllerRPCSuite) SetUpSuite(c *C) { |
|
|
|
testServerRPC = httptest.NewUnstartedServer(getServerRPCHandler()) |
|
|
|
testServerRPC = httptest.NewUnstartedServer(getServerRPCHandler()) |
|
|
|
testServerRPC.Config.Addr = ":9002" |
|
|
|
testServerRPC.Config.Addr = ":9002" |
|
|
|
testServerRPC.Start() |
|
|
|
testServerRPC.Start() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
url, gerr := url.Parse(testServerRPC.URL) |
|
|
|
|
|
|
|
c.Assert(gerr, IsNil) |
|
|
|
|
|
|
|
s.url = url |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *ControllerRPCSuite) TearDownSuite(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TearDownSuite(c *C) { |
|
|
@ -59,7 +65,7 @@ func (s *ControllerRPCSuite) TearDownSuite(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TestMemStats(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TestMemStats(c *C) { |
|
|
|
op := rpcOperation{ |
|
|
|
op := rpcOperation{ |
|
|
|
Method: "Controller.GetServerMemStats", |
|
|
|
Method: "Controller.GetServerMemStats", |
|
|
|
Request: ServerArg{URL: testServerRPC.URL + "/rpc"}, |
|
|
|
Request: ControllerArgs{Hosts: []string{s.url.Host}}, |
|
|
|
} |
|
|
|
} |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
@ -77,7 +83,7 @@ func (s *ControllerRPCSuite) TestMemStats(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TestDiskStats(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TestDiskStats(c *C) { |
|
|
|
op := rpcOperation{ |
|
|
|
op := rpcOperation{ |
|
|
|
Method: "Controller.GetServerDiskStats", |
|
|
|
Method: "Controller.GetServerDiskStats", |
|
|
|
Request: ServerArg{URL: testServerRPC.URL + "/rpc"}, |
|
|
|
Request: ControllerArgs{Hosts: []string{s.url.Host}}, |
|
|
|
} |
|
|
|
} |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
@ -95,7 +101,7 @@ func (s *ControllerRPCSuite) TestDiskStats(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TestSysInfo(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TestSysInfo(c *C) { |
|
|
|
op := rpcOperation{ |
|
|
|
op := rpcOperation{ |
|
|
|
Method: "Controller.GetServerSysInfo", |
|
|
|
Method: "Controller.GetServerSysInfo", |
|
|
|
Request: ServerArg{URL: testServerRPC.URL + "/rpc"}, |
|
|
|
Request: ControllerArgs{Hosts: []string{s.url.Host}}, |
|
|
|
} |
|
|
|
} |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
@ -113,7 +119,7 @@ func (s *ControllerRPCSuite) TestSysInfo(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TestServerList(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TestServerList(c *C) { |
|
|
|
op := rpcOperation{ |
|
|
|
op := rpcOperation{ |
|
|
|
Method: "Controller.ListServers", |
|
|
|
Method: "Controller.ListServers", |
|
|
|
Request: ServerArg{URL: testServerRPC.URL + "/rpc"}, |
|
|
|
Request: ControllerArgs{Hosts: []string{s.url.Host}}, |
|
|
|
} |
|
|
|
} |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
@ -125,13 +131,13 @@ func (s *ControllerRPCSuite) TestServerList(c *C) { |
|
|
|
var reply ServerListRep |
|
|
|
var reply ServerListRep |
|
|
|
c.Assert(json.DecodeClientResponse(resp.Body, &reply), IsNil) |
|
|
|
c.Assert(json.DecodeClientResponse(resp.Body, &reply), IsNil) |
|
|
|
resp.Body.Close() |
|
|
|
resp.Body.Close() |
|
|
|
c.Assert(reply, Not(DeepEquals), ServerListRep{}) |
|
|
|
c.Assert(reply, Not(DeepEquals), ServerListRep{List: []ServerRep{}}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *ControllerRPCSuite) TestServerAdd(c *C) { |
|
|
|
func (s *ControllerRPCSuite) TestServerAdd(c *C) { |
|
|
|
op := rpcOperation{ |
|
|
|
op := rpcOperation{ |
|
|
|
Method: "Controller.AddServer", |
|
|
|
Method: "Controller.AddServer", |
|
|
|
Request: ServerArg{URL: testServerRPC.URL + "/rpc"}, |
|
|
|
Request: ControllerArgs{Hosts: []string{s.url.Host}}, |
|
|
|
} |
|
|
|
} |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
req, err := newRPCRequest(testControllerRPC.URL+"/rpc", op, http.DefaultTransport) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
|