Skip to content

Commit d770881

Browse files
committed
setup swarm
1 parent 7f49de7 commit d770881

File tree

9 files changed

+117
-90
lines changed

9 files changed

+117
-90
lines changed

Vagrantfile

+19
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ source /etc/profile.d/envvar.sh
3131
mv /etc/resolv.conf /etc/resolv.conf.bak
3232
cp #{gopath_folder}/src/github.com/contiv/netplugin/resolv.conf /etc/resolv.conf
3333
34+
# setup docker remote api
35+
cp #{gopath_folder}/src/github.com/contiv/netplugin/scripts/docker-tcp.socket /etc/systemd/system/docker-tcp.socket
36+
systemctl enable docker-tcp.socket
37+
3438
mkdir /etc/systemd/system/docker.service.d
3539
echo "[Service]" | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
3640
echo "Environment=\\\"no_proxy=192.168.0.0/16,localhost,127.0.0.0/8\\\" \\\"http_proxy=$http_proxy\\\" \\\"https_proxy=$https_proxy\\\"" | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
3741
sudo systemctl daemon-reload
3842
sudo systemctl stop docker
43+
systemctl start docker-tcp.socket
3944
sudo systemctl start docker
4045
4146
if [ $# -gt 5 ]; then
@@ -46,6 +51,13 @@ fi
4651
# Install experimental docker
4752
# curl -sSL https://experimental.docker.com/ | sh
4853
54+
# Get swarm binary
55+
(wget https://cisco.box.com/shared/static/isn9te95op8qgmz9o0al45eps2zmfz7c -q -O /usr/bin/swarm &&
56+
chmod +x /usr/bin/swarm) || exit 1
57+
58+
# remove duplicate docker key
59+
rm /etc/docker/key.json
60+
4961
(service docker restart) || exit 1
5062
5163
(ovs-vsctl set-manager tcp:127.0.0.1:6640 && \
@@ -122,10 +134,17 @@ set -x
122134
## start consul
123135
(nohup consul agent -server #{consul_join_flag} #{consul_bootstrap_flag} \
124136
-bind=#{node_addr} -data-dir /opt/consul 0<&- &>/tmp/consul.log &) || exit 1
137+
138+
# start swarm
139+
(nohup #{gopath_folder}/src/github.com/contiv/netplugin/scripts/start-swarm.sh #{node_addr} > /tmp/start-swarm.log &) || exit 1
140+
125141
SCRIPT
126142
node.vm.provision "shell", run: "always" do |s|
127143
s.inline = provision_node
128144
end
145+
146+
# forward netmaster port
147+
# node.vm.network "forwarded_port", guest: 9999, host: 8080 + n
129148
end
130149
end
131150
end

netmaster/main.go

+21-5
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,29 @@ func (d *daemon) execOpts() {
177177
}
178178

179179
func (d *daemon) ListenAndServe() {
180-
r := mux.NewRouter()
180+
router := mux.NewRouter()
181181

182182
// Create a new api controller
183-
d.apiController = objApi.NewAPIController(r)
183+
d.apiController = objApi.NewAPIController(router)
184+
185+
// Setup the router to serve the web UI
186+
goPath := os.Getenv("GOPATH")
187+
if goPath != "" {
188+
webPath := goPath + "/src/github.com/contiv/objmodel/contivModel/www/"
189+
190+
log.Infof("Using webPath: %s", webPath)
191+
192+
// serve static files
193+
router.PathPrefix("/web/").Handler(http.StripPrefix("/web/", http.FileServer(http.Dir(webPath))))
194+
195+
// Special case to serve main index.html
196+
router.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
197+
http.ServeFile(rw, req, webPath+"index.html")
198+
})
199+
}
184200

185201
// Add REST routes
186-
s := r.Headers("Content-Type", "application/json").Methods("Post").Subrouter()
202+
s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()
187203
s.HandleFunc(fmt.Sprintf("/%s", master.DesiredConfigRESTEndpoint),
188204
post(d.desiredConfig))
189205
s.HandleFunc(fmt.Sprintf("/%s", master.AddConfigRESTEndpoint),
@@ -193,7 +209,7 @@ func (d *daemon) ListenAndServe() {
193209
s.HandleFunc(fmt.Sprintf("/%s", master.HostBindingConfigRESTEndpoint),
194210
post(d.hostBindingsConfig))
195211

196-
s = r.Methods("Get").Subrouter()
212+
s = router.Methods("Get").Subrouter()
197213
s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetEndpointRESTEndpoint, "{id}"),
198214
get(false, d.endpoints))
199215
s.HandleFunc(fmt.Sprintf("/%s", master.GetEndpointsRESTEndpoint),
@@ -205,7 +221,7 @@ func (d *daemon) ListenAndServe() {
205221

206222
log.Infof("Netmaster listening on %s", d.opts.listenURL)
207223

208-
if err := http.ListenAndServe(d.opts.listenURL, r); err != nil {
224+
if err := http.ListenAndServe(d.opts.listenURL, router); err != nil {
209225
log.Fatalf("Error listening for http requests. Error: %s", err)
210226
}
211227
}

scripts/docker-tcp.socket

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=Docker Socket for the API
3+
4+
[Socket]
5+
ListenStream=2385
6+
BindIPv6Only=both
7+
Service=docker.service
8+
9+
[Install]
10+
WantedBy=sockets.target

scripts/python/dummy.py

-16
This file was deleted.

scripts/python/objmodelTest.py

-57
This file was deleted.

scripts/python/sanity.py

100644100755
+7-6
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,18 @@ def testPolicyAddDeleteRule(testbed, numContainer, numIter):
196196
# Setup testbed
197197
testbed = testbedApi.testbed(addrList)
198198

199-
time.sleep(5)
199+
time.sleep(15)
200200

201201
numCntr = testbed.numNodes() * 2
202+
numIteration = 2
202203

203204
# Run the test
204-
testBasicPolicy(testbed, numCntr, 4)
205-
testPolicyAddDeleteRule(testbed, numCntr, 4)
206-
startRemoveContainer(testbed, numCntr, 4)
205+
testBasicPolicy(testbed, numCntr, numIteration)
206+
testPolicyAddDeleteRule(testbed, numCntr, numIteration)
207+
startRemoveContainer(testbed, numCntr, numIteration)
207208

208-
# FIXME: This test is not passing yet
209-
#startStopContainer(testbed, numCntr, 4)
209+
# FIXME: This test is not passing yet as native-integ mode cleanup is not working
210+
# startStopContainer(testbed, numCntr, 4)
210211

211212
# Cleanup testbed
212213
testbed.cleanup()

scripts/python/startPlugin.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/python
2+
3+
# Start netplugin and netmaster
4+
import testbedApi
5+
import time
6+
import sys
7+
import os
8+
9+
# Parse command line args
10+
if len(sys.argv) <= 1:
11+
print "Usage: " + sys.argv[0] + " <ip-addr> <ip-addr>..."
12+
print "This starts netplugin and netmaster"
13+
sys.exit(1)
14+
15+
# Form address list
16+
addrList = []
17+
for addr in sys.argv[1:]:
18+
addrList.append(addr)
19+
20+
# Cleanup all state and start netplugin/netmaster
21+
testbed = testbedApi.testbed(addrList)
22+
time.sleep(2)
23+
24+
os._exit(0)

scripts/python/testbedApi.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def runCmd(self, cmd, timeout=None):
5757
# Start netplugin process on vagrant node
5858
def startNetplugin(self):
5959
ssh_object = self.sshConnect()
60-
command = "sudo /opt/gopath/bin/netplugin > /tmp/netplugin.log 2>&1"
60+
command = "sudo /opt/gopath/bin/netplugin -native-integration=true > /tmp/netplugin.log 2>&1"
6161
self.npThread = threading.Thread(target=ssh_exec_thread, args=(ssh_object, command))
6262
# npThread.setDaemon(True)
6363
self.npThread.start()
@@ -129,6 +129,9 @@ def __init__(self, addrList):
129129
# Cleanup all state before we can start
130130
node.stopNetmaster()
131131
node.stopNetplugin()
132+
133+
# cleanup master and slave state
134+
for node in self.nodes:
132135
node.cleanupMaster()
133136
node.cleanupSlave()
134137

@@ -143,17 +146,17 @@ def __init__(self, addrList):
143146

144147
# Cleanup a testbed once test is done
145148
def cleanup(self):
146-
# cleanup master
147-
print "Cleaning up master"
148-
self.nodes[0].stopNetmaster()
149-
self.nodes[0].cleanupMaster()
150-
151149
# Cleanup each node
152150
for node in self.nodes:
153151
print "Cleaning up node " + node.addr
154152
node.stopNetplugin()
155153
node.cleanupSlave()
156154

155+
# cleanup master
156+
print "Cleaning up master"
157+
self.nodes[0].stopNetmaster()
158+
self.nodes[0].cleanupMaster()
159+
157160
# Number of nodes in the testbed
158161
def numNodes(self):
159162
return len(self.nodes)

scripts/start-swarm.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
USAGE="Usage: $0 <node-addr>"
4+
5+
if [ $# -ne 1 ]; then
6+
echo $USAGE
7+
exit 1
8+
fi
9+
10+
node_addr=$1
11+
12+
echo "start-swarm waiting for etcd"
13+
14+
etcdctl cluster-health
15+
while [[ `etcdctl cluster-health | head -n 1` != "cluster is healthy" ]]; do
16+
echo "Cluster is unhealthy";
17+
sleep 1;
18+
etcdctl cluster-health;
19+
done
20+
21+
echo "starting swarm on " $node_addr
22+
23+
# Start swarm discovery
24+
nohup /usr/bin/swarm join --advertise=$node_addr:2385 etcd://localhost:2379 > /tmp/swarm-join.log 2>&1 &
25+
26+
# Start swarm manager
27+
nohup /usr/bin/swarm manage -H tcp://$node_addr:2375 etcd://localhost:2379 > /tmp/swarm-manage.log 2>&1 &

0 commit comments

Comments
 (0)