~ubuntu-branches/ubuntu/wily/openvswitch/wily

« back to all changes in this revision

Viewing changes to utilities/ovs-dev.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-08-10 11:35:15 UTC
  • mfrom: (1.1.30)
  • Revision ID: package-import@ubuntu.com-20150810113515-575vj06oq29emxsn
Tags: 2.4.0~git20150810.97bab95-0ubuntu1
* New upstream snapshot from 2.4 branch:
  - d/*: Align any relevant packaging changes with upstream.
* d/*: wrap-and-sort.
* d/openvswitch-{common,vswitch}.install: Correct install location for
  bash completion files.
* d/tests/openflow.py: Explicitly use ovs-testcontroller as provided
  by 2.4.0 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
 
# Copyright (c) 2013, 2014 Nicira, Inc.
 
2
# Copyright (c) 2013, 2014, 2015 Nicira, Inc.
3
3
#
4
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
5
# you may not use this file except in compliance with the License.
26
26
ROOT = HOME + "/root"
27
27
BUILD_GCC = OVS_SRC + "/_build-gcc"
28
28
BUILD_CLANG = OVS_SRC + "/_build-clang"
29
 
PATH = "%(ovs)s/utilities:%(ovs)s/ovsdb:%(ovs)s/vswitchd" % {"ovs": BUILD_GCC}
30
 
 
31
 
ENV["PATH"] = PATH + ":" + ENV["PATH"]
32
29
 
33
30
options = None
34
31
parser = None
35
32
commands = []
36
33
 
 
34
def set_path(build):
 
35
    PATH = "%(ovs)s/utilities:%(ovs)s/ovsdb:%(ovs)s/vswitchd" % {"ovs": build}
 
36
 
 
37
    ENV["PATH"] = PATH + ":" + ENV["PATH"]
37
38
 
38
39
def _sh(*args, **kwargs):
39
40
    print "------> " + " ".join(args)
81
82
    if options.optimize is None:
82
83
        options.optimize = 0
83
84
 
84
 
    cflags += " -O%d" % options.optimize
 
85
    cflags += " -O%s" % str(options.optimize)
85
86
 
86
87
    ENV["CFLAGS"] = cflags
87
88
 
131
132
    if clang:
132
133
        mf.write(make_str % BUILD_CLANG)
133
134
    mf.write("\t$(MAKE) -C %s %s $@\n" % (BUILD_GCC, c1))
 
135
    mf.write("\ncheck-valgrind:\n")
134
136
    mf.write("\ncheck:\n")
135
137
    mf.write(make_str % BUILD_GCC)
136
138
    mf.close()
144
146
 
145
147
 
146
148
def check():
 
149
    flags = ""
 
150
    if options.jobs:
 
151
        flags += "-j%d " % options.jobs
 
152
    else:
 
153
        flags += "-j8 "
 
154
    if options.tests:
 
155
        for arg in str.split(options.tests):
 
156
            if arg[0].isdigit():
 
157
                flags += "%s " % arg
 
158
            else:
 
159
                flags += "-k %s " % arg
 
160
    ENV["TESTSUITEFLAGS"] = flags
147
161
    make("check")
148
162
commands.append(check)
149
163
 
203
217
        _sh("ovsdb-tool", "create", ROOT + "/conf.db",
204
218
            OVS_SRC + "/vswitchd/vswitch.ovsschema")
205
219
 
206
 
    opts = ["--pidfile", "--log-file", "--enable-dummy"]
 
220
    opts = ["--pidfile", "--log-file"]
207
221
 
208
222
    _sh(*(["ovsdb-server",
209
223
           "--remote=punix:%s/run/db.sock" % ROOT,
223
237
    _sh("ovs-vsctl --no-wait set Open_vSwitch %s ovs_version=%s"
224
238
        % (root_uuid, version))
225
239
 
226
 
    cmd = [BUILD_GCC + "/vswitchd/ovs-vswitchd"]
 
240
    build = BUILD_CLANG if options.clang else BUILD_GCC
 
241
    cmd = [build + "/vswitchd/ovs-vswitchd"]
 
242
 
 
243
    if options.dpdk:
 
244
        cmd.append("--dpdk")
 
245
        cmd.extend(options.dpdk)
 
246
        cmd.append("--")
 
247
 
227
248
    if options.gdb:
228
249
        cmd = ["gdb", "--args"] + cmd
229
250
    elif options.valgrind:
232
253
               "--suppressions=%s/tests/openssl.supp" % OVS_SRC] + cmd
233
254
    else:
234
255
        cmd = ["sudo"] + cmd
235
 
        opts = opts + ["-vconsole:off", "--detach"]
 
256
        opts = opts + ["-vconsole:off", "--detach", "--enable-dummy"]
236
257
    _sh(*(cmd + opts))
237
258
commands.append(run)
238
259
 
248
269
        pass  # Module isn't loaded
249
270
 
250
271
    try:
251
 
        _sh("rm /lib/modules/%s/extra/openvswitch.ko" % uname())
 
272
        _sh("rm -f /lib/modules/%s/extra/openvswitch.ko" % uname())
 
273
        _sh("rm -f /lib/modules/%s/extra/vport-*.ko" % uname())
252
274
    except subprocess.CalledProcessError, e:
253
275
        pass  # Module isn't installed
254
276
 
258
280
 
259
281
    _sh("modprobe", "openvswitch")
260
282
    _sh("dmesg | grep openvswitch | tail -1")
 
283
    _sh("find /lib/modules/%s/ -iname vport-*.ko -exec insmod '{}' \;" % uname())
261
284
commands.append(modinst)
262
285
 
263
286
 
294
317
    # Install the kernel module
295
318
    sudo insmod %(ovs)s/datapath/linux/openvswitch.ko
296
319
 
 
320
    # If needed, manually load all required vport modules:
 
321
    sudo insmod %(ovs)s/datapath/linux/vport-vxlan.ko
 
322
    sudo insmod %(ovs)s/datapath/linux/vport-geneve.ko
 
323
    [...]
 
324
 
297
325
    # Run the switch.
298
326
    %(v)s run
299
327
 
312
340
    sys.exit(0)
313
341
commands.append(doc)
314
342
 
 
343
def parse_subargs(option, opt_str, value, parser):
 
344
    subopts = []
 
345
 
 
346
    while parser.rargs:
 
347
        dpdkarg = parser.rargs.pop(0)
 
348
        if dpdkarg == "--":
 
349
            break
 
350
        subopts.append(dpdkarg)
 
351
 
 
352
    setattr(parser.values, option.dest, subopts)
315
353
 
316
354
def main():
317
355
    global options
333
371
                     help="configure the man documentation install directory")
334
372
    group.add_option("--with-dpdk", dest="with_dpdk", metavar="DPDK_BUILD",
335
373
                     help="built with dpdk libraries located at DPDK_BUILD");
336
 
 
337
 
    for i in range(4):
338
 
        group.add_option("--O%d" % i, dest="optimize", action="store_const",
339
 
                         const=i, help="compile with -O%d" % i)
 
374
    parser.add_option_group(group)
 
375
 
 
376
    group = optparse.OptionGroup(parser, "Optimization Flags")
 
377
    for i in ["s", "g"] + range(4) + ["fast"]:
 
378
        group.add_option("--O%s" % str(i), dest="optimize",
 
379
                         action="store_const", const=i,
 
380
                         help="compile with -O%s" % str(i))
 
381
    parser.add_option_group(group)
 
382
 
 
383
    group = optparse.OptionGroup(parser, "check")
 
384
    group.add_option("-j", "--jobs", dest="jobs", metavar="N", type="int",
 
385
                     help="Run N tests in parallel")
 
386
    group.add_option("--tests", dest="tests", metavar="FILTER",
 
387
                     help="""run specific tests and/or a test category
 
388
                          eg, --tests=\"1-10 megaflow\"""")
340
389
    parser.add_option_group(group)
341
390
 
342
391
    group = optparse.OptionGroup(parser, "run")
344
393
                     help="run ovs-vswitchd under gdb")
345
394
    group.add_option("--valgrind", dest="valgrind", action="store_true",
346
395
                     help="run ovs-vswitchd under valgrind")
 
396
    group.add_option("--dpdk", dest="dpdk", action="callback",
 
397
                     callback=parse_subargs,
 
398
                     help="run ovs-vswitchd with dpdk subopts (ended by --)")
 
399
    group.add_option("--clang", dest="clang", action="store_true",
 
400
                     help="Use binaries built by clang")
 
401
 
347
402
    parser.add_option_group(group)
348
403
 
349
404
    options, args = parser.parse_args()
353
408
            print "Unknown argument " + arg
354
409
            doc()
355
410
 
 
411
    if options.clang:
 
412
        set_path(BUILD_CLANG)
 
413
    else:
 
414
        set_path(BUILD_GCC)
 
415
 
356
416
    try:
357
417
        os.chdir(OVS_SRC)
358
418
    except OSError: