Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail instead of panic when HNS network cannot be created in test. #96728

Merged
merged 1 commit into from Dec 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 27 additions & 44 deletions pkg/proxy/winkernel/hns_test.go
Expand Up @@ -110,10 +110,7 @@ func TestDeleteLoadBalancer(t *testing.T) {
testDeleteLoadBalancer(t, hnsV2)
}
func testGetNetworkByName(t *testing.T, hns HostNetworkService) {
Network, err := createTestNetwork()
if err != nil {
t.Error(err)
}
Network := mustTestNetwork(t)

network, err := hns.getNetworkByName(Network.Name)
if err != nil {
Expand All @@ -129,10 +126,7 @@ func testGetNetworkByName(t *testing.T, hns HostNetworkService) {
}
}
func testGetEndpointByID(t *testing.T, hns HostNetworkService) {
Network, err := createTestNetwork()
if err != nil {
t.Error(err)
}
Network := mustTestNetwork(t)

ipConfig := &hcn.IpConfig{
IpAddress: epIpAddress,
Expand All @@ -146,7 +140,7 @@ func testGetEndpointByID(t *testing.T, hns HostNetworkService) {
},
}

Endpoint, err = Network.CreateEndpoint(Endpoint)
Endpoint, err := Network.CreateEndpoint(Endpoint)
if err != nil {
t.Error(err)
}
Expand All @@ -169,10 +163,7 @@ func testGetEndpointByID(t *testing.T, hns HostNetworkService) {
}
}
func testGetEndpointByIpAddress(t *testing.T, hns HostNetworkService) {
Network, err := createTestNetwork()
if err != nil {
t.Error(err)
}
Network := mustTestNetwork(t)

ipConfig := &hcn.IpConfig{
IpAddress: epIpAddress,
Expand All @@ -185,7 +176,7 @@ func testGetEndpointByIpAddress(t *testing.T, hns HostNetworkService) {
Minor: 0,
},
}
Endpoint, err = Network.CreateEndpoint(Endpoint)
Endpoint, err := Network.CreateEndpoint(Endpoint)
if err != nil {
t.Error(err)
}
Expand All @@ -211,18 +202,15 @@ func testGetEndpointByIpAddress(t *testing.T, hns HostNetworkService) {
}
}
func testCreateEndpointLocal(t *testing.T, hns HostNetworkService) {
Network, err := createTestNetwork()
if err != nil {
t.Error(err)
}
Network := mustTestNetwork(t)

endpoint := &endpointsInfo{
ip: epIpAddress,
macAddress: epMacAddress,
isLocal: true,
}

endpoint, err = hns.createEndpoint(endpoint, Network.Name)
endpoint, err := hns.createEndpoint(endpoint, Network.Name)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -250,10 +238,7 @@ func testCreateEndpointLocal(t *testing.T, hns HostNetworkService) {
}
}
func testCreateEndpointRemote(t *testing.T, hns HostNetworkService, providerAddress string) {
Network, err := createTestNetwork()
if err != nil {
t.Error(err)
}
Network := mustTestNetwork(t)

endpoint := &endpointsInfo{
ip: epIpAddressRemote,
Expand All @@ -262,7 +247,7 @@ func testCreateEndpointRemote(t *testing.T, hns HostNetworkService, providerAddr
providerAddress: providerAddress,
}

endpoint, err = hns.createEndpoint(endpoint, Network.Name)
endpoint, err := hns.createEndpoint(endpoint, Network.Name)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -293,10 +278,7 @@ func testCreateEndpointRemote(t *testing.T, hns HostNetworkService, providerAddr
}
}
func testDeleteEndpoint(t *testing.T, hns HostNetworkService) {
Network, err := createTestNetwork()
if err != nil {
t.Error(err)
}
Network := mustTestNetwork(t)

ipConfig := &hcn.IpConfig{
IpAddress: epIpAddress,
Expand All @@ -309,7 +291,7 @@ func testDeleteEndpoint(t *testing.T, hns HostNetworkService) {
Minor: 0,
},
}
Endpoint, err = Network.CreateEndpoint(Endpoint)
Endpoint, err := Network.CreateEndpoint(Endpoint)
if err != nil {
t.Error(err)
}
Expand All @@ -330,10 +312,7 @@ func testDeleteEndpoint(t *testing.T, hns HostNetworkService) {
}

func testGetLoadBalancerExisting(t *testing.T, hns HostNetworkService) {
Network, err := createTestNetwork()
if err != nil {
t.Error(err)
}
Network := mustTestNetwork(t)

ipConfig := &hcn.IpConfig{
IpAddress: epIpAddress,
Expand All @@ -346,7 +325,7 @@ func testGetLoadBalancerExisting(t *testing.T, hns HostNetworkService) {
Minor: 0,
},
}
Endpoint, err = Network.CreateEndpoint(Endpoint)
Endpoint, err := Network.CreateEndpoint(Endpoint)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -394,10 +373,7 @@ func testGetLoadBalancerExisting(t *testing.T, hns HostNetworkService) {
}
}
func testGetLoadBalancerNew(t *testing.T, hns HostNetworkService) {
Network, err := createTestNetwork()
if err != nil {
t.Error(err)
}
Network := mustTestNetwork(t)

ipConfig := &hcn.IpConfig{
IpAddress: epIpAddress,
Expand All @@ -410,7 +386,7 @@ func testGetLoadBalancerNew(t *testing.T, hns HostNetworkService) {
Minor: 0,
},
}
Endpoint, err = Network.CreateEndpoint(Endpoint)
Endpoint, err := Network.CreateEndpoint(Endpoint)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -445,10 +421,7 @@ func testGetLoadBalancerNew(t *testing.T, hns HostNetworkService) {
}
}
func testDeleteLoadBalancer(t *testing.T, hns HostNetworkService) {
Network, err := createTestNetwork()
if err != nil {
t.Error(err)
}
Network := mustTestNetwork(t)

ipConfig := &hcn.IpConfig{
IpAddress: epIpAddress,
Expand All @@ -461,7 +434,7 @@ func testDeleteLoadBalancer(t *testing.T, hns HostNetworkService) {
Minor: 0,
},
}
Endpoint, err = Network.CreateEndpoint(Endpoint)
Endpoint, err := Network.CreateEndpoint(Endpoint)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -499,6 +472,16 @@ func testDeleteLoadBalancer(t *testing.T, hns HostNetworkService) {
t.Error(err)
}
}
func mustTestNetwork(t *testing.T) *hcn.HostComputeNetwork {
network, err := createTestNetwork()
if err != nil {
t.Fatalf("cannot create test network: %v", err)
}
if network == nil {
t.Fatal("test network was nil without error")
}
return network
}
func createTestNetwork() (*hcn.HostComputeNetwork, error) {
network := &hcn.HostComputeNetwork{
Type: "Overlay",
Expand Down