Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspbian Backend #92

Open
wants to merge 183 commits into
base: master
Choose a base branch
from
Open

Raspbian Backend #92

wants to merge 183 commits into from

Conversation

ritwickdsouza
Copy link
Contributor

@ritwickdsouza ritwickdsouza commented Jul 15, 2017

References #78 and #79

@coveralls
Copy link

coveralls commented Jul 15, 2017

Coverage Status

Coverage decreased (-0.06%) to 99.875% when pulling bdf028d on raspbian into a37cdea on master.

@coveralls
Copy link

coveralls commented Jul 19, 2017

Coverage Status

Coverage decreased (-0.5%) to 99.386% when pulling 62fc58d on raspbian into a37cdea on master.

@@ -0,0 +1,74 @@
from ipaddress import IPv4Interface, ip_network
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about ipv6?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it now.

{% if i|string() == 'general' %}
{% for general in j %}
{% if general.get('timezone') %}
run commands:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find a method to set timezone by modifying a config file.
So created a template which tells what command needs to be run to do the required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about a script? We can then create an install script that must be launched to deploy the configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about doing the same. I will do that.

@@ -0,0 +1,12 @@
{% for i, j in data.items() %}
Copy link
Member

@nemesifier nemesifier Jul 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you just loop over data.general instead of doing this cumbersome thing? (same concept applies to other templates)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also use more readable variable names than i and j please? This applies to other lines of code too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The templates are now much cleaner.

@coveralls
Copy link

coveralls commented Jul 20, 2017

Coverage Status

Coverage decreased (-0.05%) to 99.878% when pulling 3fbcffd on raspbian into a37cdea on master.

from ...schema import schema as default_schema
from ...utils import merge_config

schema = merge_config(default_schema, {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with no schema additions we can't validate mandatory data or enforce checks, are you sure this step is not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll work on a schema

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ritwickdsouza at least the minimum required stuff. This part will become clearer when we'll be able to start viewing the configuration form in web UI

{% for wireless in data.wireless %}
# config: /etc/hostapd/hostapd.conf

interface={{ wireless.get('ifname') }}
Copy link
Member

@nemesifier nemesifier Jul 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not {{ wireless.ifname }} instead? Jinja2 should allow you this syntax which is more concise and easy to read, sampe applies for the rest of attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll make the changes in all the templates.

ieee80211ac=1
{% endif %}
ssid={{ wireless.get('ssid') }}
{% if wireless.get('encryption') != {} %}
Copy link
Member

@nemesifier nemesifier Jul 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try just:

{% if wireless.get('encryption') %}

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress! 👍

See more inline comments on details that need improvement.

wpa={{ wireless.get('encryption').get('wpa') }}
wpa_key_mgmt={{ wireless.get('encryption').get('wpa_key_mgmt') }}
wpa_passphrase={{ wireless.get('encryption').get('wpa_passphrase') }}
{% if wireless.get('encryption', None).get('wpa_pairwise') != 'AUTO' %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code:

wireless.get('encryption', None).get('wpa_pairwise')

is broken because if encryption is not present, wireless['encryption'] will be None and then you will be trying to call the get method on a None object, which will raise an exception.

But if you apply my previous suggestion, this code block will be executed only if wireless.encryption is not empty or None, hence the default value in the get method is not necessary and you may write just:

{% if  wireless.encryption.wpa_pairwise != 'AUTO' %}

{{ general.get('hostname') }}

{% endif %}
{% endfor %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't this template be simplified a lot? Eg:

{% if data.general and general.hostname %}
    # config: /etc/hostname
    {{ general.hostname }}
{% endif %}

{% for interface in data.interfaces %}
{% if interface.get('iftype') in ['ethernet', 'bridge', 'loopback', 'wireless'] %}
# config: /etc/network/interfaces
{% if interface.get('address') != None %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try:

{% if interface.address %}

@@ -127,7 +127,7 @@ def render(self, files=True):
if self.intermediate_data is None:
self.to_intermediate()
# support multiple renderers
renderers = getattr(self, 'renderers', [self.renderer])
renderers = getattr(self, 'renderers', None) or [self.renderer]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you rebased on master yet? This change shouldn't show up because is already on master

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh. I thought I created the branch after this update.

--------------

.. automethod:: netjsonconfig.Raspbian.__init__

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unnecessary blank line


config: /etc/network/interfaces
auto eth0
iface eth0 inet static
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use 4 spaces indentation for consistency with other examples on the same page which are using 4


Will be rendered as follows::

config: /etc/hostapd/hostapd.conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update example

Wireless AdHoc Mode
~~~~~~~~~~~~~~~~~~~

In wireless adhoc mode, the ``bssid`` property is required.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great 👍


Will be rendered as follows::

config: /etc/hostapd/hostapd.conf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update example

"0.openwrt.pool.ntp.org",
"1.openwrt.pool.ntp.org",
"2.openwrt.pool.ntp.org",
"3.openwrt.pool.ntp.org"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a different pool of servers otherwise it looks badly copied from the openwrt backend page :-P

config: /etc/network/interfaces
auto eth0.1
iface eth0.1 inet static
address 192.168.1.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about making indentation consistent with other examples which use 4 spaces?

>>> o = Raspbian({
... "interfaces": [
... {
... "name": "eth0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 spaces

After modifying the config files run the following command to change the
hostname::

$ /etc/init.d/hostname.sh start
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the install configuration idea we can move this command there too


This will enable on the next reboot. Incase you want to activate it immediately::

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this go to the install script too?

Now we just need to start our services::

sudo service hostapd start
sudo service dnsmasq start
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this?

wireless-channel 1
wireless-essid freifunk
wireless-mode ad-hoc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove blank line

from netjsonconfig.utils import _TabsMixin


class TestHostapdRenderer(unittest.TestCase, _TabsMixin):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to TestHostapd

expected = '''# config: /etc/network/interfaces

auto eth0
iface eth0 inet static
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why in the examples contained in the docs we have indentation for these? Ensure the documentation returns the same output the library generates please, otherwise users will get confused

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had made changes to the template and not updated the docs. I'll make the changes.

@coveralls
Copy link

coveralls commented Jul 20, 2017

Coverage Status

Coverage decreased (-0.05%) to 99.878% when pulling d5c4de8 on raspbian into a37cdea on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.05%) to 99.878% when pulling 2de2246 on raspbian into 4373b24 on master.

1 similar comment
@coveralls
Copy link

coveralls commented Jul 24, 2017

Coverage Status

Coverage decreased (-0.05%) to 99.878% when pulling 2de2246 on raspbian into 4373b24 on master.

@coveralls
Copy link

coveralls commented Jul 25, 2017

Coverage Status

Coverage decreased (-0.05%) to 99.878% when pulling 4ee19f1 on raspbian into 4373b24 on master.

@coveralls
Copy link

coveralls commented Jul 26, 2017

Coverage Status

Coverage decreased (-0.1%) to 99.818% when pulling 81c390e on raspbian into 4373b24 on master.

@coveralls
Copy link

coveralls commented Jul 26, 2017

Coverage Status

Coverage decreased (-0.1%) to 99.818% when pulling 81c390e on raspbian into 4373b24 on master.

@coveralls
Copy link

coveralls commented Jul 28, 2017

Coverage Status

Coverage decreased (-0.1%) to 99.819% when pulling 367fb29 on raspbian into 4373b24 on master.

@ritwickdsouza ritwickdsouza changed the title Raspbian Backend Phase 1 Raspbian Backend Aug 1, 2017
@coveralls
Copy link

coveralls commented Aug 1, 2017

Coverage Status

Coverage decreased (-0.1%) to 99.82% when pulling 68a896d on raspbian into 4373b24 on master.

@coveralls
Copy link

coveralls commented Aug 2, 2017

Coverage Status

Coverage increased (+0.009%) to 99.939% when pulling 3354cfc on raspbian into 4373b24 on master.

@nemesifier
Copy link
Member

@ritwickdsouza remember the install procedure and instructions

@@ -169,7 +169,7 @@ method_arguments = parse_method_arguments(args.args)
backends = {
'openwrt': netjsonconfig.OpenWrt,
'openwisp': netjsonconfig.OpenWisp,
'openvpn': netjsonconfig.OpenVpn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the openvpn key removed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants