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

[qa] Automatic reformatting of code and docs #896

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .coveragerc

This file was deleted.

7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
- master

jobs:

build:
name: Python==${{ matrix.python-version }} | ${{ matrix.django-version }}
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -56,7 +55,7 @@ jobs:
id: deps
run: |
sudo apt update
sudo apt-get -qq -y install sqlite3 gdal-bin libproj-dev \
sudo apt -qq -y install sqlite3 gdal-bin libproj-dev \
libgeos-dev libspatialite-dev spatialite-bin \
libsqlite3-mod-spatialite
sudo npm install -g jshint stylelint
Expand All @@ -75,10 +74,10 @@ jobs:
# the following command runs tests with Postgres/PostGIS but
# only for specific test cases which are tagged with "db_tests"
POSTGRESQL=1 coverage run runtests.py --parallel --keepdb
# tests the extension capability
SAMPLE_APP=1 coverage run ./runtests.py --parallel --keepdb
coverage combine
coverage xml
# tests the extension capability
SAMPLE_APP=1 ./runtests.py --keepdb
env:
SELENIUM_HEADLESS: 1

Expand Down
455 changes: 260 additions & 195 deletions CHANGES.rst

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Please refer to the `OpenWISP Contribution Guidelines <http://openwisp.io/docs/developer/contributing.html>`_.
Please refer to the `OpenWISP Contribution Guidelines
<http://openwisp.io/docs/developer/contributing.html>`_.
3,258 changes: 1,740 additions & 1,518 deletions README.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions openwisp_controller/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Base admin classes and mixins
"""

from django.core.exceptions import PermissionDenied

from openwisp_users.multitenancy import (
Expand Down
1 change: 0 additions & 1 deletion openwisp_controller/config/base/multitenancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class AbstractOrganizationConfigSettings(UUIDModel):

organization = models.OneToOneField(
swapper.get_model_name('openwisp_users', 'Organization'),
verbose_name=_('organization'),
Expand Down
108 changes: 58 additions & 50 deletions openwisp_controller/config/base/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _validate_host(self):

def save(self, *args, **kwargs):
"""
Calls _auto_create_cert() if cert is not set
Calls _auto_create_cert() if cert is not set.
"""
config = {}
created = self._state.adding
Expand Down Expand Up @@ -328,9 +328,9 @@ def dhparam(cls, length):

@classmethod
def post_delete(cls, instance, **kwargs):
"""
class method for ``post_delete`` signal
for managing automatic deletion of vpn servers
"""Receiver for ``post_delete`` signal.
Manages automatic deletion of vpn servers.
"""
if not instance._is_backend_type('zerotier'):
return
Expand Down Expand Up @@ -510,9 +510,11 @@ def get_system_context(self):
return self.get_context()

def _is_backend_type(self, backend_type):
"""
returns true if the backend path used converted to lowercase
"""Returns True if backend contains specified backend_type.
Returns true if the backend path used converted to lowercase
contains ``backend_type``.
Checking for the exact path may not be the best choices
given backends can be extended and customized.
By using this method, customizations will just have
Expand All @@ -521,22 +523,30 @@ def _is_backend_type(self, backend_type):
return backend_type.lower() in self.backend.lower()

def _get_auto_context_keys(self):
"""
returns a dictionary which indicates the names of
"""Returns context keys automatically.
Returns a dictionary which indicates the names of
the configuration variables needed to access:
* path to CA file
* CA certificate in PEM format
* path to cert file
* cert in PEM format
* path to key file
* key in PEM format
* path to CA file
* CA certificate in PEM format
* path to cert file
* cert in PEM format
* path to key file
* key in PEM format
WireGuard:
* public key
* ip address
* public key
* ip address
VXLAN:
* vni (VXLAN Network Identifier)
ZeroTier
* network_id (ZeroTier Network Identifier)
* vni (VXLAN Network Identifier)
ZeroTier:
* network_id (ZeroTier Network Identifier)
"""
pk = self.pk.hex
context_keys = {
Expand Down Expand Up @@ -585,8 +595,9 @@ def _get_auto_context_keys(self):
return context_keys

def auto_client(self, auto_cert=True, template_backend_class=None):
"""
calls backend ``auto_client`` method and returns a configuration
"""Calls backend ``auto_client`` method.
Returns a configuration
dictionary that is suitable to be used as a template
if ``auto_cert`` is ``False`` the resulting configuration
won't include autogenerated key and certificate details
Expand Down Expand Up @@ -653,9 +664,9 @@ def _auto_create_cert_extra(self, cert):
return cert

def _generate_wireguard_keys(self):
"""
generates wireguard private and public keys
and set the respctive attributes
"""Generates wireguard private and public keys.
Also sets the respctive instance attributes.
"""
if not self.private_key or not self.public_key:
self.private_key, self.public_key = crypto.generate_wireguard_keys()
Expand All @@ -669,9 +680,10 @@ def get_config(self):
return config

def _invalidate_peer_cache(self, update=False):
"""
Invalidates peer cache, if update=True is passed,
the peer cache will be regenerated
"""Invalidates peer cache.
If update=True is passed,
the peer cache will be regenerated.
"""
for backend in ['wireguard', 'vxlan']:
if self._is_backend_type(backend):
Expand All @@ -682,9 +694,10 @@ def _invalidate_peer_cache(self, update=False):
vpn_peers_changed.send(sender=self.__class__, instance=self)

def _get_peer_queryset(self):
"""
returns an iterator to iterate over tunnel peers
used to generate the list of peers of a tunnel (WireGuard/VXLAN)
"""Returns peer queryset.
Returns an iterator to iterate over tunnel peers
used to generate the list of peers of a tunnel (WireGuard/VXLAN).
"""
return (
self.vpnclient_set.select_related('config', 'ip')
Expand All @@ -702,9 +715,9 @@ def _get_peer_queryset(self):
)

def _add_wireguard(self, config):
"""
Adds wireguard peers and private key to the generated
configuration without the need of manual intervention.
"""Adds wireguard peers and private key to the generated configuration
without the need of manual intervention.
Modifies the config data structure as a side effect.
"""
try:
Expand All @@ -722,9 +735,7 @@ def _add_wireguard(self, config):

@cache_memoize(_PEER_CACHE_TIMEOUT, args_rewrite=_peer_cache_key)
def _get_wireguard_peers(self):
"""
Returns list of wireguard peers, the result is cached.
"""
"""Returns list of wireguard peers, the result is cached."""
peers = []
for vpnclient in self._get_peer_queryset():
if vpnclient.ip:
Expand All @@ -738,8 +749,8 @@ def _get_wireguard_peers(self):
return peers

def _add_vxlan(self, config):
"""
Adds VXLAN peers to the generated configuration
"""Adds VXLAN peers to the generated configuration
without the need of manual intervention.
Modifies the config data structure as a side effect.
"""
Expand Down Expand Up @@ -831,8 +842,8 @@ def zerotier_member_id(self):

@classmethod
def register_auto_ip_stopper(cls, func):
"""
Adds "func" to "_auto_ip_stopper_funcs".
"""Adds "func" to "_auto_ip_stopper_funcs".
These functions are called in the "_auto_ip" method.
Output from these functions are used to determine
skipping automatic IP assignment.
Expand All @@ -856,10 +867,7 @@ def _get_unique_checks(self, exclude=None, include_meta_constraints=False):
return unique_checks, date_checks

def save(self, *args, **kwargs):
"""
automatically provisions tunnel keys
and configuration if ``auto_cert`` is True
"""
"""Performs automatic provisioning if ``auto_cert`` is True."""
if self.auto_cert:
self._auto_x509()
self._auto_ip()
Expand All @@ -870,7 +878,7 @@ def save(self, *args, **kwargs):

def _auto_x509(self):
"""
automatically creates an x509 certificate
Automatically creates an x509 certificate.
"""
if not self.vpn._is_backend_type('openvpn') or self.cert:
return
Expand All @@ -879,7 +887,7 @@ def _auto_x509(self):

def _get_common_name(self):
"""
returns the common name for a new certificate
Returns the common name for a new certificate.
"""
d = self.config.device
end = 63 - len(d.mac_address)
Expand Down Expand Up @@ -908,10 +916,10 @@ def _post_save():

@classmethod
def post_delete(cls, instance, **kwargs):
"""
class method for ``post_delete`` signal
automatically deletes related certificates
and ip addresses if necessary
"""Receiver of ``post_delete`` signal.
Automatically deletes related certificates
and ip addresses if necessary.
"""
# only invalidates, does not regenerate the cache
# to avoid generating high load during bulk deletes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class Migration(migrations.Migration):

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('config', '0001_squashed_0002_config_settings_uuid'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class Migration(migrations.Migration):

dependencies = [
('config', '0003_template_tags'),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [('config', '0005_populate_device')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [('config', '0006_config_device_not_null')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [('config', '0007_simplify_config')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [('config', '0008_update_indexes')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [('config', '0009_device_system')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [('config', '0010_auto_20180106_1814')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [('config', '0011_update_device_mac_address')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def migrate_status_backward(apps, schema_editor):


class Migration(migrations.Migration):

dependencies = [('config', '0012_auto_20180219_1501')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

dependencies = [('config', '0013_last_ip_management_ip_and_status_applied')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
('config', '0016_default_organization_config_settings'),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [('config', '0017_template_name_organization_unique_together')]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Migration(migrations.Migration):

dependencies = [
('config', '0018_config_context'),
]
Expand Down
Loading