Browse code

Specify UI bind address in integration tests

Jordan Liggitt authored on 2015/02/27 10:48:58
Showing 5 changed files
... ...
@@ -43,6 +43,9 @@ type Config struct {
43 43
 	// addresses for external clients
44 44
 	MasterPublicAddr     flagtypes.Addr
45 45
 	KubernetesPublicAddr flagtypes.Addr
46
+	// addresses for asset server
47
+	AssetBindAddr   flagtypes.Addr
48
+	AssetPublicAddr flagtypes.Addr
46 49
 
47 50
 	ImageFormat         string
48 51
 	LatestReleaseImages bool
... ...
@@ -90,6 +93,8 @@ func NewDefaultConfig() *Config {
90 90
 		PortalNet:            flagtypes.DefaultIPNet("172.30.17.0/24"),
91 91
 		MasterPublicAddr:     flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
92 92
 		KubernetesPublicAddr: flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
93
+		AssetPublicAddr:      flagtypes.Addr{Value: "localhost:8444", DefaultScheme: "https", DefaultPort: 8444, AllowPrefix: true}.Default(),
94
+		AssetBindAddr:        flagtypes.Addr{Value: "0.0.0.0:8444", DefaultScheme: "https", DefaultPort: 8444, AllowPrefix: true}.Default(),
93 95
 
94 96
 		ImageTemplate: variable.NewDefaultImageTemplate(),
95 97
 
... ...
@@ -211,7 +216,11 @@ func (cfg Config) GetKubernetesPublicAddress() (*url.URL, error) {
211 211
 }
212 212
 
213 213
 func (cfg Config) GetAssetPublicAddress() (*url.URL, error) {
214
+	if cfg.AssetPublicAddr.Provided {
215
+		return cfg.AssetPublicAddr.URL, nil
216
+	}
214 217
 	// Derive the asset public address by incrementing the master public address port by 1
218
+	// TODO: derive the scheme/port from the asset bind scheme/port once that is settable via the command line
215 219
 	t, err := cfg.GetMasterPublicAddress()
216 220
 	if err != nil {
217 221
 		return nil, err
... ...
@@ -223,6 +232,9 @@ func (cfg Config) GetAssetPublicAddress() (*url.URL, error) {
223 223
 }
224 224
 
225 225
 func (cfg Config) GetAssetBindAddress() string {
226
+	if cfg.AssetBindAddr.Provided {
227
+		return cfg.AssetBindAddr.URL.Host
228
+	}
226 229
 	// Derive the asset bind address by incrementing the master bind address port by 1
227 230
 	return net.JoinHostPort(cfg.BindAddr.Host, strconv.Itoa(cfg.BindAddr.Port+1))
228 231
 }
... ...
@@ -39,6 +39,66 @@ func TestMasterPublicAddressExplicit(t *testing.T) {
39 39
 	}
40 40
 }
41 41
 
42
+func TestAssetPublicAddressDefaulting(t *testing.T) {
43
+	master := "http://example.com:9011"
44
+	expected := "http://example.com:9012"
45
+
46
+	cfg := NewDefaultConfig()
47
+	cfg.MasterAddr.Set(master)
48
+
49
+	actual, err := cfg.GetAssetPublicAddress()
50
+	if err != nil {
51
+		t.Errorf("unexpected error: %v", err)
52
+	}
53
+	if expected != actual.String() {
54
+		t.Errorf("expected %v, got %v", expected, actual)
55
+	}
56
+}
57
+
58
+func TestAssetPublicAddressExplicit(t *testing.T) {
59
+	master := "http://example.com:9011"
60
+	expected := "https://example.com:9014"
61
+
62
+	cfg := NewDefaultConfig()
63
+	cfg.MasterAddr.Set(master)
64
+	cfg.AssetPublicAddr.Set(expected)
65
+
66
+	actual, err := cfg.GetAssetPublicAddress()
67
+	if err != nil {
68
+		t.Errorf("unexpected error: %v", err)
69
+	}
70
+	if expected != actual.String() {
71
+		t.Errorf("expected %v, got %v", expected, actual)
72
+	}
73
+}
74
+
75
+func TestAssetBindAddressDefaulting(t *testing.T) {
76
+	bind := "1.2.3.4:9011"
77
+	expected := "1.2.3.4:9012"
78
+
79
+	cfg := NewDefaultConfig()
80
+	cfg.BindAddr.Set(bind)
81
+
82
+	actual := cfg.GetAssetBindAddress()
83
+	if expected != actual {
84
+		t.Errorf("expected %v, got %v", expected, actual)
85
+	}
86
+}
87
+
88
+func TestAssetBindAddressExplicit(t *testing.T) {
89
+	bind := "1.2.3.4:9011"
90
+	expected := "2.3.4.5:1234"
91
+
92
+	cfg := NewDefaultConfig()
93
+	cfg.BindAddr.Set(bind)
94
+	cfg.AssetBindAddr.Set(expected)
95
+
96
+	actual := cfg.GetAssetBindAddress()
97
+	if expected != actual {
98
+		t.Errorf("expected %v, got %v", expected, actual)
99
+	}
100
+}
101
+
42 102
 func TestKubernetesPublicAddressDefaultToKubernetesAddress(t *testing.T) {
43 103
 	expected := "http://example.com:9012"
44 104
 
... ...
@@ -722,7 +722,7 @@ func namespacingFilter(handler http.Handler, contextMapper kapi.RequestContextMa
722 722
 
723 723
 				ctx = kapi.WithNamespace(ctx, namespace)
724 724
 				contextMapper.Update(req, ctx)
725
-				glog.V(2).Infof("set namespace on context to %v", requestInfo.Namespace)
725
+				glog.V(4).Infof("set namespace on context to %v", requestInfo.Namespace)
726 726
 			}
727 727
 		}
728 728
 
... ...
@@ -22,7 +22,7 @@ func WaitForSuccessfulDial(https bool, network, address string, timeout, interva
22 22
 			conn, err = dialer.Dial(network, address)
23 23
 		}
24 24
 		if err != nil {
25
-			glog.V(4).Infof("Got error %#v, trying again: %#v\n", err, address)
25
+			glog.V(5).Infof("Got error %#v, trying again: %#v\n", err, address)
26 26
 			time.Sleep(interval)
27 27
 			continue
28 28
 		}
... ...
@@ -37,11 +37,15 @@ func StartTestServer(args ...string) (start.Config, error) {
37 37
 
38 38
 	masterAddr := httptest.NewUnstartedServer(nil).Listener.Addr().String()
39 39
 	fmt.Printf("masterAddr: %#v\n", masterAddr)
40
-
41 40
 	startConfig.MasterAddr.Set(masterAddr)
42 41
 	startConfig.BindAddr.Set(masterAddr)
43 42
 	startConfig.EtcdAddr.Set(getEtcdURL())
44 43
 
44
+	assetAddr := httptest.NewUnstartedServer(nil).Listener.Addr().String()
45
+	fmt.Printf("assetAddr: %#v\n", assetAddr)
46
+	startConfig.AssetBindAddr.Set(assetAddr)
47
+	startConfig.AssetPublicAddr.Set(assetAddr)
48
+
45 49
 	startConfig.Complete(args)
46 50
 
47 51
 	var startError error
... ...
@@ -54,7 +58,7 @@ func StartTestServer(args ...string) (start.Config, error) {
54 54
 	}()
55 55
 
56 56
 	// wait for the server to come up: 35 seconds
57
-	if err := cmdutil.WaitForSuccessfulDial(true, "tcp", masterAddr, 100*time.Millisecond, 100*time.Millisecond, 175); err != nil {
57
+	if err := cmdutil.WaitForSuccessfulDial(true, "tcp", masterAddr, 100*time.Millisecond, 1*time.Second, 35); err != nil {
58 58
 		return *startConfig, err
59 59
 	}
60 60