network: Allow setting the auto-connect property on a connection

Also don't require updating all the common properties of a connection when
updating only some properties such as 'autoconnect'.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2020-01-15 14:52:08 -08:00 committed by James Valleroy
parent 68e5684d10
commit 42569d75ec
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 22 additions and 5 deletions

View File

@ -307,11 +307,22 @@ def _update_common_settings(connection, connection_uuid, common):
connection.add_setting(settings)
settings.set_property(nm.SETTING_CONNECTION_UUID, connection_uuid)
settings.set_property(nm.SETTING_CONNECTION_ID, common['name'])
settings.set_property(nm.SETTING_CONNECTION_TYPE, common['type'])
settings.set_property(nm.SETTING_CONNECTION_INTERFACE_NAME,
common['interface'])
settings.set_property(nm.SETTING_CONNECTION_ZONE, common['zone'])
if 'name' in common:
settings.set_property(nm.SETTING_CONNECTION_ID, common['name'])
if 'type' in common:
settings.set_property(nm.SETTING_CONNECTION_TYPE, common['type'])
if 'interface' in common:
settings.set_property(nm.SETTING_CONNECTION_INTERFACE_NAME,
common['interface'])
if 'zone' in common:
settings.set_property(nm.SETTING_CONNECTION_ZONE, common['zone'])
if 'autoconnect' in common:
settings.set_property(nm.SETTING_CONNECTION_AUTOCONNECT,
common['autoconnect'])
return connection

View File

@ -174,6 +174,7 @@ def test_edit_ethernet_connection(network, ethernet_uuid):
ethernet_settings2['common']['name'] = 'plinth_test_eth_new'
ethernet_settings2['common']['interface'] = 'eth1'
ethernet_settings2['common']['zone'] = 'external'
ethernet_settings2['common']['autoconnect'] = False
ethernet_settings2['ipv4']['method'] = 'auto'
network.edit_connection(connection, ethernet_settings2)
@ -183,6 +184,7 @@ def test_edit_ethernet_connection(network, ethernet_uuid):
settings_connection = connection.get_setting_connection()
assert settings_connection.get_interface_name() == 'eth1'
assert settings_connection.get_zone() == 'external'
assert not settings_connection.get_autoconnect()
settings_ipv4 = connection.get_setting_ip4_config()
assert settings_ipv4.get_method() == 'auto'
@ -195,6 +197,7 @@ def test_edit_pppoe_connection(network, pppoe_uuid):
pppoe_settings2['common']['name'] = 'plinth_test_pppoe_new'
pppoe_settings2['common']['interface'] = 'eth2'
pppoe_settings2['common']['zone'] = 'external'
pppoe_settings2['common']['autoconnect'] = False
pppoe_settings2['pppoe']['username'] = 'x-user-new'
pppoe_settings2['pppoe']['password'] = 'x-password-new'
network.edit_connection(connection, pppoe_settings2)
@ -205,6 +208,7 @@ def test_edit_pppoe_connection(network, pppoe_uuid):
settings_connection = connection.get_setting_connection()
assert settings_connection.get_interface_name() == 'eth2'
assert settings_connection.get_zone() == 'external'
assert not settings_connection.get_autoconnect()
settings_pppoe = connection.get_setting_pppoe()
assert settings_pppoe.get_username() == 'x-user-new'
@ -223,6 +227,7 @@ def test_edit_wifi_connection(network, wifi_uuid):
wifi_settings2['common']['name'] = 'plinth_test_wifi_new'
wifi_settings2['common']['interface'] = 'wlan1'
wifi_settings2['common']['zone'] = 'external'
wifi_settings2['common']['autoconnect'] = False
wifi_settings2['ipv4']['method'] = 'auto'
wifi_settings2['wireless']['ssid'] = 'plinthtestwifi2'
wifi_settings2['wireless']['mode'] = 'infrastructure'
@ -237,6 +242,7 @@ def test_edit_wifi_connection(network, wifi_uuid):
settings_connection = connection.get_setting_connection()
assert settings_connection.get_interface_name() == 'wlan1'
assert settings_connection.get_zone() == 'external'
assert not settings_connection.get_autoconnect()
settings_wireless = connection.get_setting_wireless()
assert settings_wireless.get_ssid().get_data() == b'plinthtestwifi2'