From 62fc58d8873b46b1377190251fde004fd713b1a0 Mon Sep 17 00:00:00 2001 From: Ritwick DSouza Date: Wed, 19 Jul 2017 17:48:13 +0530 Subject: [PATCH] [raspbian] Added support for manual mode in interfaces --- .../raspbian/templates/interfaces.jinja2 | 13 +++++----- tests/raspbian/test_hostapd.py | 16 +++++++++++++ tests/raspbian/test_interfaces.py | 4 ++-- tests/raspbian/test_radios.py | 24 +++++++++++++++++++ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/netjsonconfig/backends/raspbian/templates/interfaces.jinja2 b/netjsonconfig/backends/raspbian/templates/interfaces.jinja2 index 2a68ec789..85265c39a 100644 --- a/netjsonconfig/backends/raspbian/templates/interfaces.jinja2 +++ b/netjsonconfig/backends/raspbian/templates/interfaces.jinja2 @@ -2,8 +2,8 @@ {% if i|string() == 'interfaces' %} {% for interface in j %} {% if interface.get('iftype') in ['ethernet', 'bridge', 'loopback', 'wireless'] %} - {% if interface.get('address') != None %} # config: /etc/network/interfaces + {% if interface.get('address') != None %} auto {{ interface.get('ifname') }} {% for address in interface.get('address') %} @@ -67,17 +67,16 @@ {% endif%} {% endfor %} {% else %} - {% if interface.get('iftype') == 'bridge' %} - # config: /etc/network/interfaces auto {{ interface.get('ifname') }} + {% if interface.get('iftype') == 'wireless' and interface.get('mode') != 'adhoc' %} + iface {{ interface.get('ifname') }} inet manual + {% endif %} + {% if interface.get('iftype') == 'bridge' %} bridge_ports {{ interface.get('bridge_members')[0] }} {{ interface.get('bridge_members')[1] }} {% endif %} {% if interface.get('mode') == 'adhoc' %} - # config: /etc/network/interfaces - - auto {{ interface.get('iftype') }} - iface {{ interface.get('iftype') }} inet static + iface {{ interface.get('ifname') }} inet static address 172.128.1.1 netmask 255.255.255.0 wireless-channel 1 diff --git a/tests/raspbian/test_hostapd.py b/tests/raspbian/test_hostapd.py index 1a76c0389..b092911df 100644 --- a/tests/raspbian/test_hostapd.py +++ b/tests/raspbian/test_hostapd.py @@ -50,6 +50,10 @@ def test_wpa2_personal(self): wpa_key_mgmt=WPA-PSK wpa_passphrase=passphrase012345 wpa_pairwise=TKIP CCMP +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected) @@ -97,6 +101,10 @@ def test_wpa_personal(self): wpa=1 wpa_key_mgmt=WPA-PSK wpa_passphrase=passphrase012345 +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected) @@ -209,6 +217,10 @@ def test_encryption_disabled(self): channel=3 ieee80211n=1 ssid=MyNetwork +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected) @@ -248,6 +260,10 @@ def test_no_encryption(self): channel=3 ieee80211n=1 ssid=open +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected) diff --git a/tests/raspbian/test_interfaces.py b/tests/raspbian/test_interfaces.py index 7d13cc385..ee9598031 100644 --- a/tests/raspbian/test_interfaces.py +++ b/tests/raspbian/test_interfaces.py @@ -401,8 +401,8 @@ def test_adhoc_wireless(self): expected = '''# config: /etc/network/interfaces -auto wireless -iface wireless inet static +auto wlan0 +iface wlan0 inet static address 172.128.1.1 netmask 255.255.255.0 wireless-channel 1 diff --git a/tests/raspbian/test_radios.py b/tests/raspbian/test_radios.py index 994b88b7e..7587ad8a4 100644 --- a/tests/raspbian/test_radios.py +++ b/tests/raspbian/test_radios.py @@ -51,6 +51,10 @@ def test_radio_multi(self): channel=11 ieee80211n=1 ssid=myWiFi +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected) @@ -89,6 +93,10 @@ def test_radio_n_24ghz(self): channel=3 ieee80211n=1 ssid=myWiFi +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected) @@ -127,6 +135,10 @@ def test_radio_n_5ghz(self): channel=36 ieee80211n=1 ssid=myWiFi +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected) @@ -164,6 +176,10 @@ def test_radio_ac(self): channel=132 ieee80211ac=1 ssid=myWiFi +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected) @@ -200,6 +216,10 @@ def test_radio_a(self): hw_mode=a channel=0 ssid=myWiFi +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected) @@ -236,6 +256,10 @@ def test_radio_g(self): hw_mode=g channel=0 ssid=myWiFi +# config: /etc/network/interfaces + +auto wlan0 +iface wlan0 inet manual ''' self.assertEqual(o.render(), expected)