Skip to content

Commit 509af00

Browse files
committed
import ofnet and improve integ test
1 parent ab6fb19 commit 509af00

File tree

8 files changed

+245
-161
lines changed

8 files changed

+245
-161
lines changed

Godeps/Godeps.json

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/integ_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ type integTestSuite struct {
3636
clusterStore string // cluster store URL
3737

3838
// internal state
39-
cluster *clusterState // netplugin + netmaster cluster
40-
client *client.ContivClient // contiv client
39+
npcluster *NPCluster // netplugin + netmaster cluster
40+
client *client.ContivClient // contiv client
41+
uniqEPID uint64 // rolling int to generate unique EP IDs
4142
}
4243

4344
var integ = &integTestSuite{}
@@ -67,15 +68,15 @@ func (its *integTestSuite) SetUpSuite(c *C) {
6768
// clear all etcd state before running the tests
6869
exec.Command("etcdctl", "rm", "--recursive", "/contiv.io").Output()
6970

70-
cluster, err := newCluster(its.fwdMode, its.clusterStore)
71+
npcluster, err := NewNPCluster(its.fwdMode, its.clusterStore)
7172
assertNoErr(err, c, "creating cluster")
7273

7374
// create a new contiv client
7475
contivClient, err := client.NewContivClient("http://localhost:9999")
7576
assertNoErr(err, c, "creating contivmodel client")
7677

7778
// setup test suite
78-
its.cluster = cluster
79+
its.npcluster = npcluster
7980
its.client = contivClient
8081
}
8182

test/integration/npcluster_test.go

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/***
2+
Copyright 2014 Cisco Systems Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package integration
17+
18+
import (
19+
"os"
20+
"strings"
21+
"time"
22+
23+
log "github.com/Sirupsen/logrus"
24+
25+
"github.com/contiv/contivmodel"
26+
"github.com/contiv/netplugin/core"
27+
"github.com/contiv/netplugin/netmaster/daemon"
28+
"github.com/contiv/netplugin/netplugin/agent"
29+
"github.com/contiv/netplugin/netplugin/cluster"
30+
"github.com/contiv/netplugin/netplugin/plugin"
31+
)
32+
33+
// NPCluster holds a new neplugin/netmaster cluster stats
34+
type NPCluster struct {
35+
MasterDaemon *daemon.MasterDaemon // master instance
36+
PluginAgent *agent.Agent // netplugin agent
37+
HostLabel string // local host name
38+
LocalIP string // local ip addr
39+
}
40+
41+
// NewNPCluster creates a new cluster of netplugin/netmaster
42+
func NewNPCluster(fwdMode, clusterStore string) (*NPCluster, error) {
43+
// get local host name
44+
hostLabel, err := os.Hostname()
45+
if err != nil {
46+
log.Fatalf("Failed to fetch hostname. Error: %s", err)
47+
}
48+
49+
// get local IP addr
50+
localIP, err := cluster.GetLocalAddr()
51+
if err != nil {
52+
log.Fatalf("Error getting local address. Err: %v", err)
53+
}
54+
55+
// create master daemon
56+
md := &daemon.MasterDaemon{
57+
ListenURL: ":9999",
58+
ClusterStore: clusterStore,
59+
ClusterMode: "test",
60+
DNSEnabled: false,
61+
}
62+
63+
// initialize the plugin config
64+
pluginConfig := plugin.Config{
65+
Drivers: plugin.Drivers{
66+
Network: "ovs",
67+
State: strings.Split(clusterStore, "://")[0],
68+
},
69+
Instance: core.InstanceInfo{
70+
HostLabel: hostLabel,
71+
CtrlIP: localIP,
72+
VtepIP: localIP,
73+
VlanIntf: "eth2",
74+
DbURL: clusterStore,
75+
PluginMode: "test",
76+
},
77+
}
78+
79+
// initialize master daemon
80+
md.Init()
81+
82+
// Run daemon FSM
83+
go md.RunMasterFsm()
84+
85+
// Wait for a second for master to initialize
86+
time.Sleep(time.Second)
87+
88+
// set forwarding mode if required
89+
if fwdMode != "bridge" {
90+
err := contivModel.CreateGlobal(&contivModel.Global{
91+
Key: "global",
92+
Name: "global",
93+
NetworkInfraType: "default",
94+
Vlans: "1-4094",
95+
Vxlans: "1-10000",
96+
FwdMode: fwdMode,
97+
})
98+
if err != nil {
99+
log.Fatalf("Error creating global state. Err: %v", err)
100+
}
101+
}
102+
103+
// Create a new agent
104+
ag := agent.NewAgent(&pluginConfig)
105+
106+
// Process all current state
107+
ag.ProcessCurrentState()
108+
109+
// post initialization processing
110+
ag.PostInit()
111+
112+
// handle events
113+
go func() {
114+
if err := ag.HandleEvents(); err != nil {
115+
log.Infof("Netplugin exiting due to error: %v", err)
116+
os.Exit(1)
117+
}
118+
}()
119+
120+
// Wait for a second for things to settle down
121+
time.Sleep(time.Second)
122+
123+
cl := &NPCluster{
124+
MasterDaemon: md,
125+
PluginAgent: ag,
126+
HostLabel: hostLabel,
127+
LocalIP: localIP,
128+
}
129+
130+
return cl, nil
131+
}

test/integration/utils_test.go

+6-113
Original file line numberDiff line numberDiff line change
@@ -17,127 +17,20 @@ package integration
1717

1818
import (
1919
"fmt"
20-
"os"
2120
"os/exec"
2221
"runtime/debug"
2322
"strings"
24-
"time"
2523

26-
"github.com/contiv/contivmodel"
27-
"github.com/contiv/netplugin/core"
28-
"github.com/contiv/netplugin/netmaster/daemon"
2924
"github.com/contiv/netplugin/netmaster/intent"
3025
"github.com/contiv/netplugin/netmaster/master"
3126
"github.com/contiv/netplugin/netmaster/mastercfg"
32-
"github.com/contiv/netplugin/netplugin/agent"
3327
"github.com/contiv/netplugin/netplugin/cluster"
34-
"github.com/contiv/netplugin/netplugin/plugin"
3528
"github.com/contiv/ofnet"
3629

3730
log "github.com/Sirupsen/logrus"
3831
. "gopkg.in/check.v1"
3932
)
4033

41-
type clusterState struct {
42-
masterDaemon *daemon.MasterDaemon // master instance
43-
pluginAgent *agent.Agent // netplugin agent
44-
hostLabel string // local host name
45-
localIP string // local ip addr
46-
uniqEPID uint64 // rolling int to generate unique EP IDs
47-
}
48-
49-
// newCluster creates a new cluster of netplugin/netmaster
50-
func newCluster(fwdMode, clusterStore string) (*clusterState, error) {
51-
// get local host name
52-
hostLabel, err := os.Hostname()
53-
if err != nil {
54-
log.Fatalf("Failed to fetch hostname. Error: %s", err)
55-
}
56-
57-
// get local IP addr
58-
localIP, err := cluster.GetLocalAddr()
59-
if err != nil {
60-
log.Fatalf("Error getting local address. Err: %v", err)
61-
}
62-
63-
// create master daemon
64-
md := &daemon.MasterDaemon{
65-
ListenURL: ":9999",
66-
ClusterStore: clusterStore,
67-
ClusterMode: "test",
68-
DNSEnabled: false,
69-
}
70-
71-
// initialize the plugin config
72-
pluginConfig := plugin.Config{
73-
Drivers: plugin.Drivers{
74-
Network: "ovs",
75-
State: strings.Split(clusterStore, "://")[0],
76-
},
77-
Instance: core.InstanceInfo{
78-
HostLabel: hostLabel,
79-
CtrlIP: localIP,
80-
VtepIP: localIP,
81-
VlanIntf: "eth2",
82-
DbURL: clusterStore,
83-
PluginMode: "test",
84-
},
85-
}
86-
87-
// initialize master daemon
88-
md.Init()
89-
90-
// Run daemon FSM
91-
go md.RunMasterFsm()
92-
93-
// Wait for a second for master to initialize
94-
time.Sleep(time.Second)
95-
96-
// set forwarding mode if required
97-
if fwdMode != "bridge" {
98-
err := contivModel.CreateGlobal(&contivModel.Global{
99-
Key: "global",
100-
Name: "global",
101-
NetworkInfraType: "default",
102-
Vlans: "1-4094",
103-
Vxlans: "1-10000",
104-
FwdMode: fwdMode,
105-
})
106-
if err != nil {
107-
log.Fatalf("Error creating global state. Err: %v", err)
108-
}
109-
}
110-
111-
// Create a new agent
112-
ag := agent.NewAgent(&pluginConfig)
113-
114-
// Process all current state
115-
ag.ProcessCurrentState()
116-
117-
// post initialization processing
118-
ag.PostInit()
119-
120-
// handle events
121-
go func() {
122-
if err := ag.HandleEvents(); err != nil {
123-
log.Infof("Netplugin exiting due to error: %v", err)
124-
os.Exit(1)
125-
}
126-
}()
127-
128-
// Wait for a second for things to settle down
129-
time.Sleep(time.Second)
130-
131-
cl := &clusterState{
132-
masterDaemon: md,
133-
pluginAgent: ag,
134-
hostLabel: hostLabel,
135-
localIP: localIP,
136-
}
137-
138-
return cl, nil
139-
}
140-
14134
// assertNoErr utility function to assert no error
14235
func assertNoErr(err error, c *C, msg string) {
14336
if err != nil {
@@ -169,8 +62,8 @@ func (its *integTestSuite) allocAddress(addrPool, networkID, prefAddress string)
16962

17063
// createEndpoint creates an endpoint using netplugin api
17164
func (its *integTestSuite) createEndpoint(tenantName, netName, epgName, v4Addr, v6Addr string) (*mastercfg.CfgEndpointState, error) {
172-
its.cluster.uniqEPID++
173-
epID := fmt.Sprintf("%s-%s-%s-%d", tenantName, netName, epgName, its.cluster.uniqEPID)
65+
its.uniqEPID++
66+
epID := fmt.Sprintf("%s-%s-%s-%d", tenantName, netName, epgName, its.uniqEPID)
17467
// Build endpoint request
17568
mreq := master.CreateEndpointRequest{
17669
TenantName: tenantName,
@@ -179,7 +72,7 @@ func (its *integTestSuite) createEndpoint(tenantName, netName, epgName, v4Addr,
17972
EndpointID: epID,
18073
ConfigEP: intent.ConfigEP{
18174
Container: epID,
182-
Host: its.cluster.hostLabel,
75+
Host: its.npcluster.HostLabel,
18376
IPAddress: v4Addr,
18477
IPv6Address: v6Addr,
18578
ServiceName: epgName,
@@ -197,7 +90,7 @@ func (its *integTestSuite) createEndpoint(tenantName, netName, epgName, v4Addr,
19790
netID := netName + "." + tenantName
19891

19992
// Ask netplugin to create the endpoint
200-
err = its.cluster.pluginAgent.Plugin().CreateEndpoint(netID + "-" + epID)
93+
err = its.npcluster.PluginAgent.Plugin().CreateEndpoint(netID + "-" + epID)
20194
if err != nil {
20295
log.Errorf("Endpoint creation failed. Error: %s", err)
20396
return nil, err
@@ -265,7 +158,7 @@ func (its *integTestSuite) deleteEndpoint(tenantName, netName, epgName string, e
265158
}
266159

267160
// delete the endpoint
268-
err = its.cluster.pluginAgent.Plugin().DeleteEndpoint(epCfg.ID)
161+
err = its.npcluster.PluginAgent.Plugin().DeleteEndpoint(epCfg.ID)
269162
if err != nil {
270163
log.Errorf("Error deleting endpoint %s. Err: %v", epCfg.ID, err)
271164
return err
@@ -312,7 +205,7 @@ func (its *integTestSuite) verifyEndpointInspect(tenantName, netName string, epC
312205
c.Assert(ep.IpAddress[0], Equals, epCfg.IPAddress)
313206
c.Assert(ep.Network, Equals, fmt.Sprintf("%s.%s", netName, tenantName))
314207
c.Assert(ep.MacAddress, Equals, epCfg.MacAddress)
315-
c.Assert(ep.HomingHost, Equals, its.cluster.hostLabel)
208+
c.Assert(ep.HomingHost, Equals, its.npcluster.HostLabel)
316209
foundCount++
317210
}
318211
}

vendor/github.com/contiv/ofnet/ofnetSvcProxy.go

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)