From: Jukka Rissanen Date: Mon, 12 Nov 2012 12:07:23 +0000 (+0200) Subject: test: New VPN test script that connect to connman-vpnd X-Git-Tag: 1.10~184 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db54a482b1190562e17627d42b5edd28c169a3d6;p=platform%2Fupstream%2Fconnman.git test: New VPN test script that connect to connman-vpnd --- diff --git a/Makefile.am b/Makefile.am index ce4517f..ff32933 100644 --- a/Makefile.am +++ b/Makefile.am @@ -309,6 +309,11 @@ test_scripts = test/get-state test/list-services \ test/set-global-timeservers test/get-global-timeservers \ test/set-nameservers test/set-domains test/set-timeservers +if VPN +test_scripts += test/vpn-connect test/vpn-disconnect test/vpn-get \ + test/monitor-vpn +endif + if TEST testdir = $(pkglibdir)/test test_SCRIPTS = $(test_scripts) diff --git a/test/monitor-vpn b/test/monitor-vpn new file mode 100755 index 0000000..2b63687 --- /dev/null +++ b/test/monitor-vpn @@ -0,0 +1,81 @@ +#!/usr/bin/python + +import gobject + +import dbus +import dbus.mainloop.glib + +from dbus.lowlevel import MethodCallMessage, HANDLER_RESULT_NOT_YET_HANDLED + +def extract_list(list): + val = "[" + for i in list: + if type(i).__name__ == 'Dictionary': + val += extract_values(i) + elif type(i).__name__ == 'Struct': + val += extract_list(i) + else: + val += " " + str(i) + val += "]" + return val + +def extract_values(values): + val = "{" + for key in values.keys(): + val += " " + key + "=" + if key in ["ProtocolFamily"]: + val += "%s" % (int(values[key])) + elif key in ["IPv4", "IPv6"]: + val += extract_values(values[key]) + else: + val += str(values[key]) + val += " }" + return val + +def extract(name, value): + val = None + + if name in ["Index"]: + val = int(value) + elif name in ["IPv4", "IPv6" ]: + val = extract_values(value) + elif name in ["UserRoutes", "ServerRoutes", "Nameservers"]: + val = extract_list(value) + else: + val = str(value) + + return val + +def property_changed(name, value, path, interface): + iface = interface[interface.rfind(".") + 1:] + val = extract(name, value) + + print "{%s} [%s] %s = %s" % (iface, path, name, val) + +def message_filter(connection, message): + if not isinstance(message, MethodCallMessage): + return HANDLER_RESULT_NOT_YET_HANDLED + + interface = message.get_interface() + path = message.get_path() + name = message.get_member() + args = message.get_args_list() + + property_changed(name, args, path, interface) + +if __name__ == '__main__': + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + bus = dbus.SystemBus() + + bus.add_signal_receiver(property_changed, + bus_name="net.connman.vpn", + signal_name = "PropertyChanged", + path_keyword="path", + interface_keyword="interface") + + bus.add_message_filter(message_filter) + + mainloop = gobject.MainLoop() + + mainloop.run() diff --git a/test/vpn-connect b/test/vpn-connect new file mode 100755 index 0000000..0f8636d --- /dev/null +++ b/test/vpn-connect @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import sys +import dbus + +if (len(sys.argv) < 2): + print "Usage: %s " % (sys.argv[0]) + sys.exit(1) + +bus = dbus.SystemBus() + +manager = dbus.Interface(bus.get_object("net.connman.vpn", "/"), + "net.connman.vpn.Manager") + +connections = manager.GetConnections() + +path = "/net/connman/vpn/connection/" + sys.argv[1] + +print "Attempting to connect VPN %s" % (path) + +connection = dbus.Interface(bus.get_object("net.connman.vpn", path), + "net.connman.vpn.Connection") + +connection.Connect() diff --git a/test/vpn-disconnect b/test/vpn-disconnect new file mode 100755 index 0000000..d7a49ba --- /dev/null +++ b/test/vpn-disconnect @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import sys +import dbus + +if (len(sys.argv) < 1): + print "Usage: %s " % (sys.argv[0]) + sys.exit(1) + +bus = dbus.SystemBus() + +manager = dbus.Interface(bus.get_object("net.connman.vpn", "/"), + "net.connman.vpn.Manager") + +connections = manager.GetConnections() + +path = "/net/connman/vpn/connection/" + sys.argv[1] + +print "Attempting to disconnect VPN %s" % (path) + +connection = dbus.Interface(bus.get_object("net.connman.vpn", path), + "net.connman.vpn.Connection") + +connection.Disconnect() diff --git a/test/vpn-get b/test/vpn-get new file mode 100755 index 0000000..f1f760c --- /dev/null +++ b/test/vpn-get @@ -0,0 +1,48 @@ +#!/usr/bin/python + +import dbus + +def extract_values(values): + val = "{" + for key in values.keys(): + val += " " + key + "=" + if key in ["Servers", "Excludes"]: + val += extract_list(values[key]) + else: + val += str(values[key]) + val += " }" + return val + +def extract_list(list): + val = "[" + for i in list: + if type(i).__name__ == 'Dictionary': + val += extract_values(i) + elif type(i).__name__ == 'Struct': + val += extract_list(i) + else: + val += " " + str(i) + val += "]" + return val + +bus = dbus.SystemBus() + +manager = dbus.Interface(bus.get_object('net.connman.vpn', '/'), + 'net.connman.vpn.Manager') + +for entry in manager.GetConnections(): + path = entry[0] + properties = entry[1] + + print "[ %s ]" % (path) + + for key in properties.keys(): + if key in ["IPv4", "IPv6" ]: + val = extract_values(properties[key]) + elif key in ["Nameservers","ServerRoutes","UserRoutes"]: + val = extract_list(properties[key]) + else: + val = str(properties[key]) + print " %s = %s" % (key, val) + + print