Log useful information on 500's

* include error message in error (!!)
* add test verifying error message is correct for service ip allocation
This commit is contained in:
Daniel Smith
2016-08-30 16:56:56 -07:00
parent 1dfd6ab0c1
commit 1a23f5a79f
4 changed files with 66 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/http"
"strings"
"testing"
@@ -414,3 +415,54 @@ func TestMasterService(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
}
func TestServiceAlloc(t *testing.T) {
cfg := framework.NewIntegrationTestMasterConfig()
_, cidr, err := net.ParseCIDR("192.168.0.0/30")
if err != nil {
t.Fatalf("bad cidr: %v", err)
}
cfg.ServiceClusterIPRange = cidr
_, s := framework.RunAMaster(cfg)
defer s.Close()
client := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})
svc := func(i int) *api.Service {
return &api.Service{
ObjectMeta: api.ObjectMeta{
Name: fmt.Sprintf("svc-%v", i),
},
Spec: api.ServiceSpec{
Type: api.ServiceTypeClusterIP,
Ports: []api.ServicePort{
{Port: 80},
},
},
}
}
// Make a service.
if _, err := client.Services(api.NamespaceDefault).Create(svc(1)); err != nil {
t.Fatalf("got unexpected error: %v", err)
}
// Make a second service. It will fail because we're out of cluster IPs
if _, err := client.Services(api.NamespaceDefault).Create(svc(2)); err != nil {
if !strings.Contains(err.Error(), "range is full") {
t.Errorf("unexpected error text: %v", err)
}
} else {
t.Fatalf("unexpected sucess")
}
// Delete the first service.
if err := client.Services(api.NamespaceDefault).Delete(svc(1).ObjectMeta.Name); err != nil {
t.Fatalf("got unexpected error: %v", err)
}
// This time creating the second service should work.
if _, err := client.Services(api.NamespaceDefault).Create(svc(2)); err != nil {
t.Fatalf("got unexpected error: %v", err)
}
}