Skip to content

Commit 88b9aa3

Browse files
author
jojimt
authored
Revert "Fixes #541"
1 parent 052879b commit 88b9aa3

File tree

7 files changed

+49
-249
lines changed

7 files changed

+49
-249
lines changed

netctl/netctl.go

100644100755
+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func inspectPolicy(ctx *cli.Context) {
6565
tenant := ctx.String("tenant")
6666
policy := ctx.Args()[0]
6767

68-
fmt.Printf("Inspecting policy: %s tenant: %s\n", policy, tenant)
68+
fmt.Printf("Inspeting policy: %s tenant: %s\n", policy, tenant)
6969

7070
pol, err := getClient(ctx).PolicyInspect(tenant, policy)
7171
errCheck(ctx, err)
@@ -471,7 +471,7 @@ func inspectNetwork(ctx *cli.Context) {
471471
tenant := ctx.String("tenant")
472472
network := ctx.Args()[0]
473473

474-
fmt.Printf("Inspecting network: %s tenant: %s\n", network, tenant)
474+
fmt.Printf("Inspeting network: %s tenant: %s\n", network, tenant)
475475

476476
net, err := getClient(ctx).NetworkInspect(tenant, network)
477477
errCheck(ctx, err)
@@ -661,7 +661,7 @@ func inspectEndpointGroup(ctx *cli.Context) {
661661
tenant := ctx.String("tenant")
662662
endpointGroup := ctx.Args()[0]
663663

664-
fmt.Printf("Inspecting endpointGroup: %s tenant: %s\n", endpointGroup, tenant)
664+
fmt.Printf("Inspeting endpointGroup: %s tenant: %s\n", endpointGroup, tenant)
665665

666666
epg, err := getClient(ctx).EndpointGroupInspect(tenant, endpointGroup)
667667
errCheck(ctx, err)

netmaster/master/api.go

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func UpdateEndpointHandler(w http.ResponseWriter, r *http.Request, vars map[stri
346346
return nil, err
347347
}
348348

349-
if epUpdReq.Event == "start" || epUpdReq.Event == "connect" {
349+
if epUpdReq.Event == "start" {
350350
//Received container start event from netplugin. Check if the Provider
351351
//matches any service and perform service provider update if there is a matching
352352
//service.

netplugin/agent/docker_event.go

+42-81
Original file line numberDiff line numberDiff line change
@@ -28,80 +28,64 @@ import (
2828
"golang.org/x/net/context"
2929
)
3030

31-
// Handles docker events monitored by dockerclient. Currently we only handle // container start and die event*/
31+
// Handles docker events monitored by dockerclient. Currently we only handle
32+
// container start and die event*/
3233
func handleDockerEvents(event *dockerclient.Event, ec chan error, args ...interface{}) {
3334

3435
log.Debugf("Received Docker event: {%#v}\n", *event)
3536
endpointUpdReq := &master.UpdateEndpointRequest{}
36-
37-
var containerID string
38-
var networkID string
39-
40-
if (event.Type == "container" && event.Action == "start") ||
41-
(event.Type == "network" && event.Action == "connect") {
42-
43-
if event.Type == "container" {
44-
containerID = event.ID
45-
networkID = ""
46-
} else {
47-
containerID = event.Actor.Attributes["container"]
48-
networkID = event.Actor.ID
49-
}
50-
51-
if containerID == "" {
52-
log.Errorf("Container ID missing in docker event {%#v}\n", *event)
53-
return
54-
}
55-
37+
switch event.Status {
38+
case "start":
5639
defaultHeaders := map[string]string{"User-Agent": "engine-api-cli-1.0"}
5740
cli, err := client.NewClient("unix:///var/run/docker.sock", "v1.21", nil, defaultHeaders)
5841
if err != nil {
59-
log.Errorf("Client lookup failed :%s", err)
60-
return
42+
panic(err)
6143
}
6244

63-
containerInfo, err := cli.ContainerInspect(context.Background(), containerID)
45+
containerInfo, err := cli.ContainerInspect(context.Background(), event.ID)
6446

6547
if err != nil {
6648
log.Errorf("Container Inspect failed :%s", err)
6749
return
6850
}
6951

70-
labelMap := getLabelsFromContainerInspect(&containerInfo)
71-
containerTenant := getTenantFromContainerInspect(&containerInfo)
72-
networkName, ipAddress, err := getEpNetworkInfoFromContainerInspect(&containerInfo, networkID)
73-
if err != nil {
74-
log.Errorf("Error getting container network info for %v.Err:%s", containerID, err)
75-
}
76-
endpoint := getEndpointFromContainerInspect(&containerInfo,
77-
networkName, containerTenant)
78-
79-
if ipAddress != "" {
80-
//Create provider info
81-
endpointUpdReq.IPAddress = ipAddress
82-
endpointUpdReq.ContainerID = containerID
83-
endpointUpdReq.Tenant = containerTenant
84-
endpointUpdReq.Network = networkName
85-
endpointUpdReq.Event = event.Action
86-
endpointUpdReq.EndpointID = endpoint
87-
endpointUpdReq.ContainerName = containerInfo.Name
88-
endpointUpdReq.Labels = make(map[string]string)
89-
90-
for k, v := range labelMap {
91-
endpointUpdReq.Labels[k] = v
52+
if event.ID != "" {
53+
labelMap := getLabelsFromContainerInspect(&containerInfo)
54+
containerTenant := getTenantFromContainerInspect(&containerInfo)
55+
networkName, ipAddress, err := getEpNetworkInfoFromContainerInspect(&containerInfo)
56+
if err != nil {
57+
log.Errorf("Error getting container network info for %v.Err:%s", event.ID, err)
58+
}
59+
endpoint := getEndpointFromContainerInspect(&containerInfo)
60+
61+
if ipAddress != "" {
62+
//Create provider info
63+
endpointUpdReq.IPAddress = ipAddress
64+
endpointUpdReq.ContainerID = event.ID
65+
endpointUpdReq.Tenant = containerTenant
66+
endpointUpdReq.Network = networkName
67+
endpointUpdReq.Event = "start"
68+
endpointUpdReq.EndpointID = endpoint
69+
endpointUpdReq.ContainerName = containerInfo.Name
70+
endpointUpdReq.Labels = make(map[string]string)
71+
72+
for k, v := range labelMap {
73+
endpointUpdReq.Labels[k] = v
74+
}
9275
}
93-
}
9476

95-
var epUpdResp master.UpdateEndpointResponse
77+
var epUpdResp master.UpdateEndpointResponse
9678

97-
log.Infof("Sending Endpoint update request to master: {%+v}", endpointUpdReq)
79+
log.Infof("Sending Endpoint update request to master: {%+v}", endpointUpdReq)
9880

99-
err = cluster.MasterPostReq("/plugin/updateEndpoint", endpointUpdReq, &epUpdResp)
100-
if err != nil {
101-
log.Errorf("Event: 'start' , Http error posting endpoint update, Error:%s", err)
81+
err = cluster.MasterPostReq("/plugin/updateEndpoint", endpointUpdReq, &epUpdResp)
82+
if err != nil {
83+
log.Errorf("Event: 'start' , Http error posting endpoint update, Error:%s", err)
84+
}
85+
} else {
86+
log.Errorf("Unable to fetch container labels for container %s ", event.ID)
10287
}
103-
104-
} else if event.Type == "container" && event.Action == "die" {
88+
case "die":
10589
endpointUpdReq.ContainerID = event.ID
10690
endpointUpdReq.Event = "die"
10791
var epUpdResp master.UpdateEndpointResponse
@@ -136,21 +120,14 @@ func getTenantFromContainerInspect(containerInfo *types.ContainerJSON) string {
136120
}
137121

138122
/*getEpNetworkInfoFromContainerInspect inspects the network info from containerinfo returned by dockerclient*/
139-
func getEpNetworkInfoFromContainerInspect(containerInfo *types.ContainerJSON,
140-
networkID string) (string, string, error) {
141-
123+
func getEpNetworkInfoFromContainerInspect(containerInfo *types.ContainerJSON) (string, string, error) {
142124
var networkName string
143125
var IPAddress string
144126
var networkUUID string
145-
146-
networkName = ""
147-
IPAddress = ""
148-
149127
if containerInfo != nil && containerInfo.NetworkSettings != nil {
150128
for _, endpoint := range containerInfo.NetworkSettings.Networks {
151129
IPAddress = endpoint.IPAddress
152130
networkUUID = endpoint.NetworkID
153-
154131
_, network, serviceName, err := dockplugin.GetDockerNetworkName(networkUUID)
155132
if err != nil {
156133
log.Errorf("Error getting docker networkname for network uuid : %s", networkUUID)
@@ -161,13 +138,8 @@ func getEpNetworkInfoFromContainerInspect(containerInfo *types.ContainerJSON,
161138
} else {
162139
networkName = network
163140
}
164-
165-
if networkID != "" && strings.EqualFold(networkID, networkUUID) {
166-
break
167-
}
168141
}
169142
}
170-
171143
return networkName, IPAddress, nil
172144
}
173145

@@ -183,25 +155,14 @@ func getContainerFromContainerInspect(containerInfo *types.ContainerJSON) string
183155

184156
}
185157

186-
func getEndpointFromContainerInspect(containerInfo *types.ContainerJSON,
187-
networkName string,
188-
tenantName string,
189-
) string {
158+
func getEndpointFromContainerInspect(containerInfo *types.ContainerJSON) string {
190159

191160
endpointID := ""
192-
qualifiedName := ""
193-
194-
if 0 == strings.Compare(tenantName, "default") {
195-
qualifiedName = networkName
196-
} else {
197-
qualifiedName = networkName + "/" + tenantName
198-
}
199-
200161
if containerInfo != nil && containerInfo.NetworkSettings != nil {
201-
endpoint, ok := containerInfo.NetworkSettings.Networks[qualifiedName]
202-
if ok {
162+
for _, endpoint := range containerInfo.NetworkSettings.Networks {
203163
endpointID = endpoint.EndpointID
204164
}
205165
}
206166
return endpointID
167+
207168
}

test/systemtests/aci_util.go

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// EPSpec for aci-gw
1515
type EPSpec struct {
1616
Tenant string `json:"tenant,omitempty"`
17-
App string `json:"app-prof,omitempty"`
17+
App string `json:"app,omitempty"`
1818
Epg string `json:"epg,omitempty"`
1919
EpMac string `json:"epmac,omitempty"`
2020
}

test/systemtests/docker_test.go

100644100755
File mode changed.

test/systemtests/network_test.go

100644100755
-130
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,6 @@ func (s *systemtestSuite) TestNetworkAddDeleteVLAN(c *C) {
8989
s.testNetworkAddDelete(c, "vlan")
9090
}
9191

92-
func (s *systemtestSuite) TestNetworkAddDeleteVLANWithDns(c *C) {
93-
s.testNetworkAddDeleteWithDns(c, "vlan")
94-
}
95-
96-
func (s *systemtestSuite) TestNetworkAddDeleteVXLANWithDns(c *C) {
97-
s.testNetworkAddDeleteWithDns(c, "vxlan")
98-
}
99-
10092
func (s *systemtestSuite) testNetworkAddDelete(c *C, encap string) {
10193

10294
if s.fwdMode == "routing" && encap == "vlan" {
@@ -198,58 +190,6 @@ func (s *systemtestSuite) testNetworkAddDelete(c *C, encap string) {
198190
}
199191
}
200192

201-
func (s *systemtestSuite) testNetworkAddDeleteWithDns(c *C, encap string) {
202-
203-
var err error
204-
205-
for i := 0; i < s.basicInfo.Iterations; i++ {
206-
var (
207-
netNames = []string{}
208-
)
209-
210-
for networkNum := 0; networkNum < 3; networkNum++ {
211-
var v6subnet, v6gateway string
212-
if networkNum%2 == 0 {
213-
v6subnet = ""
214-
v6gateway = ""
215-
} else {
216-
v6subnet = fmt.Sprintf("1001:%d::/120", networkNum)
217-
v6gateway = fmt.Sprintf("1001:%d::254", networkNum)
218-
}
219-
network := &client.Network{
220-
TenantName: "default",
221-
NetworkName: fmt.Sprintf("net%d-%d", networkNum, i),
222-
Subnet: fmt.Sprintf("10.1.%d.0/24", networkNum),
223-
Gateway: fmt.Sprintf("10.1.%d.254", networkNum),
224-
Ipv6Subnet: v6subnet,
225-
Ipv6Gateway: v6gateway,
226-
PktTag: 1001 + networkNum,
227-
Encap: encap,
228-
}
229-
230-
c.Assert(s.cli.NetworkPost(network), IsNil)
231-
netNames = append(netNames, network.NetworkName)
232-
}
233-
234-
// Wait 5 seconds for the call backs to come through
235-
236-
time.Sleep(5 * time.Second)
237-
238-
for _, netName := range netNames {
239-
240-
/*
241-
Now that the networks are created, check that there is a dns endpoint on each network
242-
*/
243-
_, err = s.checkNetworkInspectDNS("default", netName)
244-
c.Assert(err, IsNil)
245-
}
246-
247-
for _, netName := range netNames {
248-
c.Assert(s.cli.NetworkDelete("default", netName), IsNil)
249-
}
250-
}
251-
}
252-
253193
func (s *systemtestSuite) TestNetworkAddDeleteNoGatewayVXLAN(c *C) {
254194
s.testNetworkAddDeleteNoGateway(c, "vxlan")
255195
}
@@ -339,10 +279,6 @@ func (s *systemtestSuite) TestNetworkAddDeleteTenantVLAN(c *C) {
339279
s.testNetworkAddDeleteTenant(c, "vlan", s.fwdMode)
340280
}
341281

342-
func (s *systemtestSuite) TestNetworkAddDeleteTenantWithDns(c *C) {
343-
s.testNetworkAddDeleteTenantWithDns(c, "vlan", s.fwdMode)
344-
}
345-
346282
func (s *systemtestSuite) testNetworkAddDeleteTenant(c *C, encap, fwdmode string) {
347283
mutex := sync.Mutex{}
348284

@@ -435,72 +371,6 @@ func (s *systemtestSuite) testNetworkAddDeleteTenant(c *C, encap, fwdmode string
435371

436372
}
437373

438-
func (s *systemtestSuite) testNetworkAddDeleteTenantWithDns(c *C, encap, fwdmode string) {
439-
440-
var err error
441-
442-
for i := 0; i < s.basicInfo.Iterations; i++ {
443-
var (
444-
tenantNames = map[string][]string{}
445-
netNames = []string{}
446-
pktTag = 0
447-
)
448-
449-
for tenantNum := 0; tenantNum < 3; tenantNum++ {
450-
tenantName := fmt.Sprintf("tenant%d", tenantNum)
451-
c.Assert(s.cli.TenantPost(&client.Tenant{TenantName: tenantName}), IsNil)
452-
tenantNames[tenantName] = []string{}
453-
454-
for networkNum := 0; networkNum < 3; networkNum++ {
455-
var v6subnet, v6gateway string
456-
if networkNum%2 == 0 {
457-
v6subnet = ""
458-
v6gateway = ""
459-
} else {
460-
v6subnet = fmt.Sprintf("1001:%d:%d::/120", tenantNum, networkNum)
461-
v6gateway = fmt.Sprintf("1001:%d:%d::254", tenantNum, networkNum)
462-
}
463-
network := &client.Network{
464-
TenantName: tenantName,
465-
NetworkName: fmt.Sprintf("net%d-%d", networkNum, i),
466-
Subnet: fmt.Sprintf("10.%d.%d.0/24", tenantNum, networkNum),
467-
Gateway: fmt.Sprintf("10.%d.%d.254", tenantNum, networkNum),
468-
Ipv6Subnet: v6subnet,
469-
Ipv6Gateway: v6gateway,
470-
PktTag: pktTag + 1000,
471-
Encap: encap,
472-
}
473-
474-
logrus.Infof("Creating network %s on tenant %s", network.NetworkName, network.TenantName)
475-
476-
c.Assert(s.cli.NetworkPost(network), IsNil)
477-
netNames = append(netNames, network.NetworkName)
478-
tenantNames[tenantName] = append(tenantNames[tenantName], network.NetworkName)
479-
pktTag++
480-
}
481-
}
482-
483-
// Wait 10 seconds for the call backs to come through
484-
485-
time.Sleep(10 * time.Second)
486-
487-
for tenant, networks := range tenantNames {
488-
for _, network := range networks {
489-
_, err = s.testNetworkInspectDNS(tenant, network)
490-
c.Assert(err, IsNil)
491-
}
492-
}
493-
494-
for tenant, networks := range tenantNames {
495-
for _, network := range networks {
496-
c.Assert(s.cli.NetworkDelete(tenant, network), IsNil)
497-
}
498-
c.Assert(s.cli.TenantDelete(tenant), IsNil)
499-
}
500-
}
501-
502-
}
503-
504374
func (s *systemtestSuite) TestNetworkAddDeleteTenantFwdModeChangeVXLAN(c *C) {
505375
fwdMode := s.fwdMode
506376
for i := 0; i < s.basicInfo.Iterations; i++ {

0 commit comments

Comments
 (0)