networkmanager-dbus 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +5 -1
- data/README.md +20 -2
- data/Rakefile +13 -1
- data/TODO.md +3 -3
- data/examples/change_ip.rb +17 -0
- data/examples/connectivity.rb +1 -1
- data/lib/dbus_interface.rb +14 -5
- data/lib/dbus_interface/class.rb +28 -4
- data/lib/dbus_interface/connection.rb +58 -0
- data/lib/dbus_interface/object.rb +15 -7
- data/lib/network_manager.rb +3 -2
- data/lib/network_manager/dbus.rb +2 -0
- data/lib/network_manager/dbus/device.rb +9 -7
- data/lib/network_manager/dbus/root.rb +8 -4
- data/lib/network_manager/dbus/settings.rb +18 -5
- data/lib/network_manager/dbus/settings_connection.rb +86 -0
- data/lib/network_manager/ip4_config.rb +33 -0
- data/lib/network_manager/version.rb +1 -1
- data/lib/networkmanager-dbus.rb +1 -1
- data/networkmanager-dbus.gemspec +4 -0
- data/script/console +7 -0
- data/script/spec_server +1 -0
- data/spec/fixtures/active_connections.yml +10 -0
- data/spec/fixtures/devices.yml +18 -37
- data/spec/fixtures/dhcp4_configs.yml +17 -0
- data/spec/fixtures/ip4_configs.yml +7 -0
- data/spec/fixtures/settings.yml +4 -14
- data/spec/fixtures/settings_connections.yml +10 -0
- data/spec/lib/dbus_interface/class_spec.rb +31 -0
- data/spec/lib/dbus_interface/object_spec.rb +32 -0
- data/spec/{network_manager → lib/network_manager}/dbus/active_connection_spec.rb +6 -6
- data/spec/lib/network_manager/dbus/device_spec.rb +58 -0
- data/spec/lib/network_manager/dbus/dhcp4_config_spec.rb +19 -0
- data/spec/lib/network_manager/dbus/ethernet_device_spec.rb +14 -0
- data/spec/lib/network_manager/dbus/ip4_config_spec.rb +19 -0
- data/spec/lib/network_manager/dbus/root_spec.rb +38 -0
- data/spec/lib/network_manager/dbus/settings_connection_spec.rb +69 -0
- data/spec/lib/network_manager/dbus/settings_spec.rb +53 -0
- data/spec/lib/network_manager/ip4_config_spec.rb +27 -0
- data/spec/{network_manager_spec.rb → lib/network_manager_spec.rb} +2 -0
- data/spec/mocks/dbus/ethernet_device_mock.rb +5 -0
- data/spec/mocks/dbus/root_mock.rb +14 -0
- data/spec/mocks/dbus/settings_connection_mock.rb +21 -0
- data/spec/mocks/dbus/settings_mock.rb +9 -0
- data/spec/mocks/dbus_mock.rb +33 -0
- data/spec/mocks/init.rb +18 -0
- data/spec/mocks/system_bus_mock.rb +5 -0
- data/spec/mocks/system_bus_service_mock.rb +9 -0
- data/spec/spec_helper.rb +22 -3
- data/spec/support/fixture_helper.rb +21 -4
- metadata +96 -28
- data/lib/network_manager/ip4_helper.rb +0 -14
- data/spec/network_manager/dbus/device_spec.rb +0 -36
- data/spec/network_manager/dbus/dhcp4_config_spec.rb +0 -14
- data/spec/network_manager/dbus/ethernet_device_spec.rb +0 -21
- data/spec/network_manager/dbus/ip4_config_spec.rb +0 -14
- data/spec/network_manager/dbus/root_spec.rb +0 -22
- data/spec/network_manager/dbus/settings_connection_spec.rb +0 -13
- data/spec/network_manager/dbus/settings_spec.rb +0 -30
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::Dhcp4Config" do
|
4
|
+
before :each do
|
5
|
+
@data = fixture('dhcp4_configs.yml')
|
6
|
+
@object_paths = object_paths_from_fixture('dhcp4_configs.yml')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should map interface "org.freedesktop.NetworkManager.DHCP4Config"' do
|
10
|
+
NetworkManager::DBus::Dhcp4Config.default_iface.should ==
|
11
|
+
'org.freedesktop.NetworkManager.DHCP4Config'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'shoud list properties' do
|
15
|
+
network_manager_dbus_mock
|
16
|
+
con = NetworkManager::DBus::Dhcp4Config.new @object_paths.first
|
17
|
+
con.properties.should == @data.first.last['properties']
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::EthernetDevice" do
|
4
|
+
before :each do
|
5
|
+
@data = fixture('devices.yml')
|
6
|
+
@object_paths = object_paths_from_fixture('devices.yml')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should list poperties" do
|
10
|
+
network_manager_dbus_mock
|
11
|
+
dev = NetworkManager::DBus::EthernetDevice.new @object_paths.first
|
12
|
+
dev.properties.should == @data.first.last['ethernet']['properties']
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::Ip4Config" do
|
4
|
+
before :each do
|
5
|
+
@data = fixture('ip4_configs.yml')
|
6
|
+
@object_paths = object_paths_from_fixture('ip4_configs.yml')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should map interface "org.freedesktop.NetworkManager.IP4Config"' do
|
10
|
+
NetworkManager::DBus::Ip4Config.default_iface.should ==
|
11
|
+
'org.freedesktop.NetworkManager.IP4Config'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'shoud list properties' do
|
15
|
+
network_manager_dbus_mock
|
16
|
+
con = NetworkManager::DBus::Ip4Config.new @object_paths.first
|
17
|
+
con.properties.should == @data.first.last['properties']
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::Root" do
|
4
|
+
before :each do
|
5
|
+
@devices = fixture('devices.yml')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should list devices" do
|
9
|
+
network_manager_dbus_mock
|
10
|
+
list = NetworkManager::DBus::Root.devices
|
11
|
+
list.size.should > 0
|
12
|
+
list.first.class.should == NetworkManager::DBus::Device
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return device_by_interface" do
|
16
|
+
network_manager_dbus_mock
|
17
|
+
dev = NetworkManager::DBus::Root.device_by_interface 'eth0'
|
18
|
+
dev.properties.should == @devices.first.last['properties']
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "internet_connection?" do
|
22
|
+
it 'should recognize internet_connection? if NM_STATE_CONNECTED_GLOBAL' do
|
23
|
+
network_manager_dbus_mock
|
24
|
+
stub(NetworkManager::DBus::Root.instance).call('state') {
|
25
|
+
[NetworkManager::DBus::Root::NM_STATE_CONNECTED_GLOBAL]
|
26
|
+
}
|
27
|
+
NetworkManager::DBus::Root.internet_connection?.should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should not recognize internet_connection? if not NM_STATE_CONNECTED_GLOBAL' do
|
31
|
+
network_manager_dbus_mock
|
32
|
+
stub(NetworkManager::DBus::Root.instance).call('state') {
|
33
|
+
[Time.now.to_i]
|
34
|
+
}
|
35
|
+
NetworkManager::DBus::Root.internet_connection?.should be_false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::SettingsConnection" do
|
4
|
+
before :each do
|
5
|
+
@data = fixture('settings_connections.yml')
|
6
|
+
@object_paths = object_paths_from_fixture('settings_connections.yml')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have no properties" do
|
10
|
+
network_manager_dbus_mock
|
11
|
+
con = NetworkManager::DBus::SettingsConnection.new @object_paths.first
|
12
|
+
con.properties.should == nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should get settings" do
|
16
|
+
network_manager_dbus_mock
|
17
|
+
con = NetworkManager::DBus::SettingsConnection.new @object_paths.first
|
18
|
+
con.settings.should == @data.first.last['settings']
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should get secrets' do
|
22
|
+
network_manager_dbus_mock
|
23
|
+
con = NetworkManager::DBus::SettingsConnection.new @object_paths.first
|
24
|
+
lambda do
|
25
|
+
con.secrets
|
26
|
+
end.should raise_error(NetworkManager::DBus::SettingsConnection::SecretsCacheInvalidError)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'update' do
|
30
|
+
it 'should do update' do
|
31
|
+
network_manager_dbus_mock
|
32
|
+
con = NetworkManager::DBus::SettingsConnection.new @object_paths.first
|
33
|
+
hash = con.settings.dup
|
34
|
+
hash['connection']['id'] = 'bar'
|
35
|
+
con.update hash
|
36
|
+
con.settings['connection']['id'].should == 'bar'
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should get #name' do
|
40
|
+
network_manager_dbus_mock
|
41
|
+
con = NetworkManager::DBus::SettingsConnection.new @object_paths.first
|
42
|
+
con.name.should == 'Wired connection 1'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set #name=' do
|
46
|
+
network_manager_dbus_mock
|
47
|
+
con = NetworkManager::DBus::SettingsConnection.new @object_paths.first
|
48
|
+
con.name = 'foo'
|
49
|
+
con.name.should == 'foo'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should set ip4 auto' do
|
53
|
+
network_manager_dbus_mock
|
54
|
+
con = NetworkManager::DBus::SettingsConnection.new @object_paths.first
|
55
|
+
con.ip4_auto!
|
56
|
+
con.ip4.should == 'auto'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should set ip4 manual' do
|
60
|
+
network_manager_dbus_mock
|
61
|
+
con = NetworkManager::DBus::SettingsConnection.new @object_paths.first
|
62
|
+
con.ip4_manual = NetworkManager::Ip4Config.from_dot_notation '192.168.10.66', '255.255.0.0', '192.168.10.1'
|
63
|
+
con.ip4.address.to_s.should == '192.168.10.66'
|
64
|
+
con.ip4.address.netmask.should == '255.255.0.0'
|
65
|
+
con.ip4.gateway.to_s.should == '192.168.10.1'
|
66
|
+
con.ip4.gateway.netmask.should == '255.255.0.0'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::Settings" do
|
4
|
+
before :each do
|
5
|
+
@data = fixture('settings.yml')
|
6
|
+
@object_paths = object_paths_from_fixture('settings.yml')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should list properties" do
|
10
|
+
network_manager_dbus_mock
|
11
|
+
NetworkManager::DBus::Settings.instance.properties.should ==
|
12
|
+
@data.first.last['properties']
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should list connections" do
|
16
|
+
network_manager_dbus_mock
|
17
|
+
NetworkManager::DBus::Settings.connections.size.should == 1
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'can_modify' do
|
21
|
+
it 'should provide can_modify?' do
|
22
|
+
network_manager_dbus_mock
|
23
|
+
NetworkManager::DBus::Settings.instance.can_modify?.should ==
|
24
|
+
@data.first.last['properties']['CanModify']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'hostname' do
|
29
|
+
it 'should get hostname from properties' do
|
30
|
+
network_manager_dbus_mock
|
31
|
+
NetworkManager::DBus::Settings.instance.hostname.should ==
|
32
|
+
@data.first.last['properties']['Hostname']
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should set hostname via object.SaveHostname' do
|
36
|
+
network_manager_dbus_mock
|
37
|
+
|
38
|
+
# manual spy
|
39
|
+
new_hostname = nil
|
40
|
+
subject = NetworkManager::DBus::Settings.instance
|
41
|
+
stub(subject).call('SaveHostname', is_a(String)) do |method,hostn|
|
42
|
+
new_hostname = hostn
|
43
|
+
[ ]
|
44
|
+
end
|
45
|
+
|
46
|
+
# action
|
47
|
+
NetworkManager::DBus::Settings.instance.hostname = 'a-host-name'
|
48
|
+
|
49
|
+
# assert
|
50
|
+
new_hostname.should == 'a-host-name'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::Ip4Config" do
|
4
|
+
it 'should #from_dot_notation' do
|
5
|
+
network_manager_dbus_mock
|
6
|
+
c = NetworkManager::Ip4Config.from_dot_notation '192.168.10.7', '255.255.255.0', '192.168.10.1'
|
7
|
+
c.address.to_s == '192.168.10.7'
|
8
|
+
c.address.netmask == '255.255.255.0'
|
9
|
+
c.gateway.to_s == '192.168.10.1'
|
10
|
+
c.gateway.netmask == '255.255.255.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should #to_nm_au' do
|
14
|
+
network_manager_dbus_mock
|
15
|
+
c = NetworkManager::Ip4Config.from_dot_notation '192.168.10.7', '255.255.255.0', '192.168.10.1'
|
16
|
+
c.to_nm_au.should == [118139072, 24, 17475776]
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should #from_nm_au' do
|
20
|
+
network_manager_dbus_mock
|
21
|
+
c = NetworkManager::Ip4Config.from_nm_au *[118139072, 24, 17475776]
|
22
|
+
c.address.to_s == '192.168.10.7'
|
23
|
+
c.address.netmask == '255.255.255.0'
|
24
|
+
c.gateway.to_s == '192.168.10.1'
|
25
|
+
c.gateway.netmask == '255.255.255.0'
|
26
|
+
end
|
27
|
+
end
|
@@ -2,11 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "NetworkManager" do
|
4
4
|
it 'should expose all devices' do
|
5
|
+
network_manager_dbus_mock
|
5
6
|
NetworkManager.devices.size.should == NetworkManager::DBus::Root.devices.size
|
6
7
|
NetworkManager.devices.first.class.should == NetworkManager::DBus::Device
|
7
8
|
end
|
8
9
|
|
9
10
|
it 'should expose settings' do
|
11
|
+
network_manager_dbus_mock
|
10
12
|
NetworkManager.settings.should == NetworkManager::DBus::Settings.instance
|
11
13
|
end
|
12
14
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RootMock
|
2
|
+
def GetDevices
|
3
|
+
object_paths = object_paths_from_fixture('devices.yml')
|
4
|
+
[ object_paths ]
|
5
|
+
end
|
6
|
+
|
7
|
+
def GetDeviceByIpIface(iface)
|
8
|
+
devices_data = fixture('devices.yml')
|
9
|
+
object_path, hash = devices_data.find do |object_path,hash|
|
10
|
+
hash['properties']['Interface'] == iface
|
11
|
+
end
|
12
|
+
[ object_path ]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SettingsConnectionMock
|
2
|
+
def GetSettings
|
3
|
+
[ data['settings'] ]
|
4
|
+
end
|
5
|
+
|
6
|
+
def GetSecrets(name)
|
7
|
+
# until we know what it correctly can return, here return sth broken
|
8
|
+
raise DBus::Error.new 'm-settings-connection.c.830 - Internal error; secrets cache invalid.'
|
9
|
+
end
|
10
|
+
|
11
|
+
def Update(hash)
|
12
|
+
if ipv4 = hash['ipv4']
|
13
|
+
if addresses = ipv4['addresses']
|
14
|
+
if addresses.first == 'aau'
|
15
|
+
ipv4['addresses'] = addresses.last
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
data.merge(hash)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class DBusMock
|
2
|
+
attr_reader :data
|
3
|
+
attr_accessor :default_iface, :introspect, :all_properties
|
4
|
+
def initialize(path)
|
5
|
+
@data = merged_dbus_fixtures[path]
|
6
|
+
end
|
7
|
+
def default_iface=(iface)
|
8
|
+
@default_iface = iface
|
9
|
+
case iface
|
10
|
+
when /NetworkManager$/
|
11
|
+
extend RootMock
|
12
|
+
when /NetworkManager.ActiveConnection$/
|
13
|
+
extend ActiveConnection
|
14
|
+
when /NetworkManager.Settings$/
|
15
|
+
extend SettingsMock
|
16
|
+
when /NetworkManager.Device.Wired$/
|
17
|
+
extend EthernetDeviceMock
|
18
|
+
when /NetworkManager.Settings.Connection$/
|
19
|
+
extend SettingsConnectionMock
|
20
|
+
end
|
21
|
+
iface
|
22
|
+
end
|
23
|
+
def call(method, *args)
|
24
|
+
if self.respond_to?(method)
|
25
|
+
self.send(method, *args)
|
26
|
+
else
|
27
|
+
[ ]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
def all_properties
|
31
|
+
data['properties']
|
32
|
+
end
|
33
|
+
end
|
data/spec/mocks/init.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'dbus_mock')
|
2
|
+
require File.join(File.dirname(__FILE__), 'dbus/root_mock')
|
3
|
+
require File.join(File.dirname(__FILE__), 'dbus/settings_mock')
|
4
|
+
require File.join(File.dirname(__FILE__), 'dbus/settings_connection_mock')
|
5
|
+
require File.join(File.dirname(__FILE__), 'dbus/ethernet_device_mock')
|
6
|
+
|
7
|
+
require File.join(File.dirname(__FILE__), 'system_bus_mock')
|
8
|
+
require File.join(File.dirname(__FILE__), 'system_bus_service_mock')
|
9
|
+
|
10
|
+
def dbus_interface_mock
|
11
|
+
system_bus_mock = ::SystemBusMock.new
|
12
|
+
stub(DBusInterface).system_bus { system_bus_mock }
|
13
|
+
end
|
14
|
+
|
15
|
+
def network_manager_dbus_mock
|
16
|
+
DBusInterface::Connection.clear!
|
17
|
+
dbus_interface_mock
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# load spec helper
|
2
|
-
|
2
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'support/**/*')).each do |path|
|
3
|
+
require path
|
4
|
+
end
|
3
5
|
|
4
6
|
# load lib
|
5
7
|
require File.join(File.dirname(__FILE__), '../lib/network_manager')
|
6
8
|
|
7
|
-
require '
|
9
|
+
require 'bundler'
|
10
|
+
Bundler.require :development
|
8
11
|
require 'rspec/core/formatters/base_formatter'
|
9
12
|
class JsonFormatter < RSpec::Core::Formatters::BaseFormatter
|
10
13
|
|
@@ -37,5 +40,21 @@ class JsonFormatter < RSpec::Core::Formatters::BaseFormatter
|
|
37
40
|
end
|
38
41
|
|
39
42
|
RSpec.configure do |config|
|
40
|
-
config.formatter =
|
43
|
+
config.formatter = begin
|
44
|
+
case ENV['RSPEC_FORMAT']
|
45
|
+
when 'growl'
|
46
|
+
'Growl::RSpec::Formatter'
|
47
|
+
when 'remote'
|
48
|
+
'JsonFormatter'
|
49
|
+
else
|
50
|
+
'progress'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
config.mock_with :rr
|
55
|
+
# or if that doesn't work due to a version incompatibility
|
56
|
+
# config.mock_with RR::Adapters::Rspec
|
41
57
|
end
|
58
|
+
|
59
|
+
# load mocks
|
60
|
+
require File.join(File.dirname(__FILE__), 'mocks/init')
|
@@ -1,11 +1,28 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
|
-
def
|
4
|
-
|
3
|
+
def fixture_path(subpath)
|
4
|
+
File.join(File.dirname(__FILE__), '../fixtures', subpath)
|
5
|
+
end
|
6
|
+
|
7
|
+
def fixture(subpath)
|
8
|
+
path = fixture_path(subpath)
|
5
9
|
case File.extname(path)
|
6
10
|
when '.yml'
|
7
|
-
YAML.load_file(
|
11
|
+
YAML.load_file(path)
|
8
12
|
else
|
9
|
-
File.read(
|
13
|
+
File.read(path)
|
10
14
|
end
|
11
15
|
end
|
16
|
+
|
17
|
+
def merged_dbus_fixtures
|
18
|
+
data = {}
|
19
|
+
Dir.glob(fixture_path('*')).each do |path|
|
20
|
+
data.merge!(YAML.load_file(path))
|
21
|
+
end
|
22
|
+
data
|
23
|
+
end
|
24
|
+
|
25
|
+
def object_paths_from_fixture(subpath)
|
26
|
+
data = fixture(subpath)
|
27
|
+
data.map{|object_path, hash| object_path}
|
28
|
+
end
|