diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2012-11-12 14:07:23 +0200 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-11-23 12:58:50 +0200 |
commit | db54a482b1190562e17627d42b5edd28c169a3d6 (patch) | |
tree | 39acd75514b3ce23016803cc792378146ff7da9a /test | |
parent | 6ed9559f6914a32fd90c17c097251f2bd5e01ef0 (diff) | |
download | connman-db54a482b1190562e17627d42b5edd28c169a3d6.tar.gz connman-db54a482b1190562e17627d42b5edd28c169a3d6.tar.bz2 connman-db54a482b1190562e17627d42b5edd28c169a3d6.zip |
test: New VPN test script that connect to connman-vpnd
Diffstat (limited to 'test')
-rwxr-xr-x | test/monitor-vpn | 81 | ||||
-rwxr-xr-x | test/vpn-connect | 24 | ||||
-rwxr-xr-x | test/vpn-disconnect | 24 | ||||
-rwxr-xr-x | test/vpn-get | 48 |
4 files changed, 177 insertions, 0 deletions
diff --git a/test/monitor-vpn b/test/monitor-vpn new file mode 100755 index 00000000..2b636871 --- /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 00000000..0f8636da --- /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 <VPN connection id>" % (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 00000000..d7a49ba9 --- /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 <VPN connection id>" % (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 00000000..f1f760cc --- /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 |