1 # Copyright (c) 2012 Nicira Networks.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
21 vlog = ovs.vlog.Vlog("test-unixctl")
24 def unixctl_exit(conn, unused_argv, aux):
25 assert aux == "aux_exit"
32 def unixctl_echo(conn, argv, aux):
33 assert aux == "aux_echo"
37 def unixctl_echo_error(conn, argv, aux):
38 assert aux == "aux_echo_error"
39 conn.reply_error(str(argv))
43 parser = argparse.ArgumentParser(
44 description="Open vSwitch unixctl test program for Python")
45 parser.add_argument("--unixctl", help="UNIXCTL socket location or 'none'.")
47 ovs.daemon.add_args(parser)
48 ovs.vlog.add_args(parser)
49 args = parser.parse_args()
50 ovs.daemon.handle_args(args)
51 ovs.vlog.handle_args(args)
53 ovs.daemon.daemonize_start()
54 error, server = ovs.unixctl.UnixctlServer.create(args.unixctl)
56 ovs.util.ovs_fatal(error, "could not create unixctl server at %s"
59 ovs.unixctl.command_register("exit", "", 0, 0, unixctl_exit, "aux_exit")
60 ovs.unixctl.command_register("echo", "[arg ...]", 1, 2, unixctl_echo,
62 ovs.unixctl.command_register("echo_error", "[arg ...]", 1, 2,
63 unixctl_echo_error, "aux_echo_error")
64 ovs.daemon.daemonize_complete()
66 vlog.info("Entering run loop.")
67 poller = ovs.poller.Poller()
72 poller.immediate_wake()
77 if __name__ == '__main__':
81 # Let system.exit() calls complete normally
84 vlog.exception("traceback")
85 sys.exit(ovs.daemon.RESTART_EXIT_CODE)