Skip to content

Commit 7686c5a

Browse files
shalemanshaleman
shaleman
authored andcommitted
Bug fixes
1 parent 94926a7 commit 7686c5a

File tree

10 files changed

+95
-38
lines changed

10 files changed

+95
-38
lines changed

Godeps/Godeps.json

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

Godeps/_workspace/src/github.com/contiv/ofnet/ofnetMaster.go

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

Godeps/_workspace/src/github.com/contiv/ofnet/rpcHub/rpcHub.go

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

Vagrantfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8484
config.vm.box = "shaleman/ubuntu-v4"
8585
# Commenting out the url since we host the image on Atlas.
8686
# config.vm.box_url = "https://cisco.box.com/shared/static/27u8utb1em5730rzprhr5szeuv2p0wir.box"
87-
num_nodes = 1
87+
num_nodes = 2
8888
if ENV['CONTIV_NODES'] && ENV['CONTIV_NODES'] != "" then
8989
num_nodes = ENV['CONTIV_NODES'].to_i
9090
end

drivers/ovsdriver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (d *OvsDriver) Init(config *core.Config, info *core.InstanceInfo) error {
109109
// Publish peer host info to registry
110110
err = publishHostInfo(info)
111111
if err != nil {
112-
log.Fatalf("Error publiching my host info. Err: %v", err)
112+
log.Fatalf("Error publishing my host info. Err: %v", err)
113113
}
114114

115115
log.Infof("Initializing ovsdriver")

drivers/peerHostState.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
// This file deals with peer host discovery
2828

29-
const peerHostPath = "/contiv/oper/peer/"
29+
const peerHostPath = "/contiv/oper/peer"
3030

3131
// PeerHostState : Information about the peer host
3232
type PeerHostState struct {
@@ -67,6 +67,11 @@ func (s *PeerHostState) Clear() error {
6767

6868
// Run peer discovery
6969
func publishHostInfo(info *core.InstanceInfo) error {
70+
// Some error checking
71+
if info.VtepIP == "" {
72+
log.Errorf("Error: Vtep IP is empty")
73+
}
74+
7075
// first publish ourselves
7176
myHostInfo := new(PeerHostState)
7277
myHostInfo.ID = info.HostLabel

netplugin/netd.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -714,20 +714,28 @@ func main() {
714714
}
715715
}
716716

717-
// extract host-label from the configuration
718-
tmpInstInfo := &struct {
719-
Instance core.InstanceInfo `json:"plugin-instance"`
720-
}{}
721-
err = json.Unmarshal(config, tmpInstInfo)
717+
// Parse the config
718+
pluginConfig := plugin.Config{}
719+
err = json.Unmarshal([]byte(config), &pluginConfig)
722720
if err != nil {
723-
log.Fatalf("Failed to parse configuration. Error: %s", err)
721+
log.Fatalf("Error parsing config. Err: %v", err)
724722
}
725-
if tmpInstInfo.Instance.HostLabel == "" {
723+
724+
// extract host-label from the configuration
725+
if pluginConfig.Instance.HostLabel == "" {
726726
log.Fatalf("Empty host-label passed in configuration")
727727
}
728-
opts.hostLabel = tmpInstInfo.Instance.HostLabel
728+
opts.hostLabel = pluginConfig.Instance.HostLabel
729+
730+
// Use default values when config options are not specified
731+
if pluginConfig.Instance.VtepIP == "" {
732+
pluginConfig.Instance.VtepIP = opts.vtepIP
733+
}
734+
if pluginConfig.Instance.VlanIntf == "" {
735+
pluginConfig.Instance.VlanIntf = opts.vlanIntf
736+
}
729737

730-
err = netPlugin.Init(string(config))
738+
err = netPlugin.Init(pluginConfig, string(config))
731739
if err != nil {
732740
log.Fatalf("Failed to initialize the plugin. Error: %s", err)
733741
}

plugin/netplugin.go

+4-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ limitations under the License.
1616
package plugin
1717

1818
import (
19-
"encoding/json"
2019
"sync"
2120

2221
"github.com/contiv/netplugin/core"
@@ -25,7 +24,8 @@ import (
2524

2625
// implements the generic Plugin interface
2726

28-
type config struct {
27+
// Config has the configuration for the plugin
28+
type Config struct {
2929
Drivers struct {
3030
Network string `json:"network"`
3131
Endpoint string `json:"endpoint"`
@@ -45,17 +45,8 @@ type NetPlugin struct {
4545
}
4646

4747
// Init initializes the NetPlugin instance via the configuration string passed.
48-
func (p *NetPlugin) Init(configStr string) error {
49-
if configStr == "" {
50-
return core.Errorf("empty config passed")
51-
}
52-
53-
pluginConfig := &config{}
54-
err := json.Unmarshal([]byte(configStr), pluginConfig)
55-
if err != nil {
56-
return err
57-
}
58-
48+
func (p *NetPlugin) Init(pluginConfig Config, configStr string) error {
49+
var err error
5950
if pluginConfig.Instance.HostLabel == "" {
6051
return core.Errorf("empty host-label passed")
6152
}

plugin/netplugin_test.go

+64-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
package plugin
1717

1818
import (
19+
"encoding/json"
1920
"testing"
2021

2122
"github.com/contiv/netplugin/state"
@@ -44,8 +45,16 @@ func TestNetPluginInit(t *testing.T) {
4445
"socket" : "unix:///var/run/docker.sock"
4546
}
4647
}`
48+
49+
// Parse the config
50+
pluginConfig := Config{}
51+
err := json.Unmarshal([]byte(configStr), &pluginConfig)
52+
if err != nil {
53+
t.Fatalf("Error parsing config. Err: %v", err)
54+
}
55+
4756
plugin := NetPlugin{}
48-
err := plugin.Init(configStr)
57+
err = plugin.Init(pluginConfig, configStr)
4958
if err != nil {
5059
t.Fatalf("plugin init failed: Error: %s", err)
5160
}
@@ -54,8 +63,10 @@ func TestNetPluginInit(t *testing.T) {
5463

5564
func TestNetPluginInitInvalidConfigEmptyString(t *testing.T) {
5665
configStr := ""
66+
pluginConfig := Config{}
67+
5768
plugin := NetPlugin{}
58-
err := plugin.Init(configStr)
69+
err := plugin.Init(pluginConfig, configStr)
5970
if err == nil {
6071
t.Fatalf("plugin init succeeded, should have failed!")
6172
}
@@ -79,8 +90,13 @@ func TestNetPluginInitInvalidConfigMissingInstance(t *testing.T) {
7990
"socket" : "unix:///var/run/docker.sock"
8091
}
8192
}`
93+
94+
// Parse the config
95+
pluginConfig := Config{}
96+
err := json.Unmarshal([]byte(configStr), &pluginConfig)
97+
8298
plugin := NetPlugin{}
83-
err := plugin.Init(configStr)
99+
err = plugin.Init(pluginConfig, configStr)
84100
if err == nil {
85101
t.Fatalf("plugin init succeeded, should have failed!")
86102
}
@@ -107,8 +123,16 @@ func TestNetPluginInitInvalidConfigEmptyHostLabel(t *testing.T) {
107123
"socket" : "unix:///var/run/docker.sock"
108124
}
109125
}`
126+
127+
// Parse the config
128+
pluginConfig := Config{}
129+
err := json.Unmarshal([]byte(configStr), &pluginConfig)
130+
if err != nil {
131+
t.Fatalf("Error parsing config. Err: %v", err)
132+
}
133+
110134
plugin := NetPlugin{}
111-
err := plugin.Init(configStr)
135+
err = plugin.Init(pluginConfig, configStr)
112136
if err == nil {
113137
t.Fatalf("plugin init succeeded, should have failed!")
114138
}
@@ -136,8 +160,16 @@ func TestNetPluginInitInvalidConfigMissingStateDriverName(t *testing.T) {
136160
}
137161
138162
}`
163+
164+
// Parse the config
165+
pluginConfig := Config{}
166+
err := json.Unmarshal([]byte(configStr), &pluginConfig)
167+
if err != nil {
168+
t.Fatalf("Error parsing config. Err: %v", err)
169+
}
170+
139171
plugin := NetPlugin{}
140-
err := plugin.Init(configStr)
172+
err = plugin.Init(pluginConfig, configStr)
141173
if err == nil {
142174
t.Fatalf("plugin init succeeded, should have failed!")
143175
}
@@ -162,8 +194,16 @@ func TestNetPluginInitInvalidConfigMissingStateDriver(t *testing.T) {
162194
"socket" : "unix:///var/run/docker.sock"
163195
}
164196
}`
197+
198+
// Parse the config
199+
pluginConfig := Config{}
200+
err := json.Unmarshal([]byte(configStr), &pluginConfig)
201+
if err != nil {
202+
t.Fatalf("Error parsing config. Err: %v", err)
203+
}
204+
165205
plugin := NetPlugin{}
166-
err := plugin.Init(configStr)
206+
err = plugin.Init(pluginConfig, configStr)
167207
if err != nil {
168208
t.Fatalf("plugin init failed: Error: %s", err)
169209
}
@@ -190,8 +230,16 @@ func TestNetPluginInitInvalidConfigMissingNetworkDriverName(t *testing.T) {
190230
"socket" : "unix:///var/run/docker.sock"
191231
}
192232
}`
233+
234+
// Parse the config
235+
pluginConfig := Config{}
236+
err := json.Unmarshal([]byte(configStr), &pluginConfig)
237+
if err != nil {
238+
t.Fatalf("Error parsing config. Err: %v", err)
239+
}
240+
193241
plugin := NetPlugin{}
194-
err := plugin.Init(configStr)
242+
err = plugin.Init(pluginConfig, configStr)
195243
if err == nil {
196244
t.Fatalf("plugin init succeeded, should have failed!")
197245
}
@@ -214,8 +262,16 @@ func TestNetPluginInitInvalidConfigMissingNetworkDriver(t *testing.T) {
214262
"socket" : "unix:///var/run/docker.sock"
215263
}
216264
}`
265+
266+
// Parse the config
267+
pluginConfig := Config{}
268+
err := json.Unmarshal([]byte(configStr), &pluginConfig)
269+
if err != nil {
270+
t.Fatalf("Error parsing config. Err: %v", err)
271+
}
272+
217273
plugin := NetPlugin{}
218-
err := plugin.Init(configStr)
274+
err = plugin.Init(pluginConfig, configStr)
219275
if err != nil {
220276
t.Fatalf("plugin init failed: Error: %s", err)
221277
}

systemtests/utils/utils.go

-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ func GetNetpluginConfigWithConsul() string {
386386
return `{
387387
"drivers" : {
388388
"network": "ovs",
389-
"endpoint": "ovs",
390389
"state": "consul"
391390
},
392391
"plugin-instance": {

0 commit comments

Comments
 (0)