Skip to content

Commit

Permalink
Merge pull request #36 from DanSheps/develop
Browse files Browse the repository at this point in the history
Add tests, upgrade to pyproject.toml
  • Loading branch information
DanSheps authored Sep 16, 2024
2 parents b85c6ac + 3d18f44 commit 2036202
Show file tree
Hide file tree
Showing 20 changed files with 488 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ body:
attributes:
label: Plugin version
description: What version of the plugin are you currently running?
placeholder: v1.0.0
placeholder: v2.1.1
validations:
required: true
- type: input
attributes:
label: NetBox version
description: What version of NetBox are you currently running?
placeholder: v3.2.0
placeholder: v4.1.1
validations:
required: true
- type: dropdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ body:
label: Plugin version
description: >
What version of the plugin are you running?
placeholder: v1.0.0
placeholder: v2.1.1
validations:
required: true
- type: input
Expand All @@ -25,17 +25,17 @@ body:
What version of NetBox are you currently running? (If you don't have access to the most
recent NetBox release, consider testing on our [demo instance](https://demo.netbox.dev/)
before opening a bug report to see if your issue has already been addressed.)
placeholder: v3.2.0
placeholder: v4.1.1
validations:
required: true
- type: dropdown
attributes:
label: Python version
description: What version of Python are you currently running?
options:
- 3.8
- 3.9
- 3.10
- 3.11
- 3.12
validations:
required: true
- type: textarea
Expand Down
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/03-housekeeping.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: 🏡 Housekeeping
description: A change pertaining to the codebase itself (developers only)
labels: ["type: housekeeping"]
body:
- type: markdown
attributes:
value: >
**NOTE:** This template is for use by maintainers only. Please do not submit
an issue using this template unless you have been specifically asked to do so.
- type: textarea
attributes:
label: Proposed Changes
description: >
Describe in detail the new feature or behavior you'd like to propose.
Include any specific changes to work flows, data models, or the user interface.
validations:
required: true
- type: textarea
attributes:
label: Justification
description: Please provide justification for the proposed change(s).
validations:
required: true
2 changes: 1 addition & 1 deletion .github/configuration.testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}

PLUGINS = [
'netbox_plugin_extensions',
'netbox_routing',
]

REDIS = {
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build Test
on: [push, pull_request]
jobs:
build:
name: Build Distribution
runs-on: ubuntu-latest
environment:
name: build
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel
python -m pip install build --user
- name: Build a binary wheel and a source tarball
run: python -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI
on: [push, pull_request]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
env:
NETBOX_CONFIGURATION: netbox.configuration_testing
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
services:
redis:
image: redis
ports:
- 6379:6379
postgres:
image: postgres
env:
POSTGRES_USER: netbox
POSTGRES_PASSWORD: netbox
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Check out NetBox
uses: actions/checkout@v4
with:
repository: netbox-community/netbox
ref: master
path: netbox

- name: Check out repo
uses: actions/checkout@v4
with:
path: netbox-routing

- name: Install dependencies & set up configuration
run: |
python -m pip install --upgrade pip
pip install -r netbox/requirements.txt
pip install pycodestyle coverage tblib
pip install -e netbox-routing
cp -f netbox-routing/.github/configuration.testing.py netbox/netbox/netbox/configuration_testing.py
- name: Run tests
run: coverage run --source="netbox-routing/netbox_routing" netbox/netbox/manage.py test netbox-routing/netbox_routing --parallel

- name: Show coverage report
run: coverage report --skip-covered --omit '*/migrations/*,*/tests/*'
64 changes: 44 additions & 20 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,64 @@ on:
types: released

jobs:
jobs:

build:
name: Build Distribution
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
environment: release
steps:

- name: Checkout repo
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade --force-reinstall setuptools wheel
- name: Build
run: python setup.py sdist bdist_wheel

pip install --upgrade setuptools wheel
python -m pip install build --user
- name: Build a binary wheel and a source tarball
run: python -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to PyPI
needs:
- build
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/netbox-routing
permissions:
id-token: write
steps:
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true

publish-to-pypi:
name: Publish Python 🐍 distribution 📦 to PyPI
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/netbox-routing
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
4 changes: 2 additions & 2 deletions netbox_routing/api/_serializers/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

class StaticRouteSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_routing-api:staticroute-detail')
devices = DeviceSerializer(many=True, nested=True, required=False)
vrf = VRFSerializer(nested=True, required=False)
devices = DeviceSerializer(many=True, nested=True, required=False, allow_null=True)
vrf = VRFSerializer(nested=True, required=False, allow_null=True)
next_hop = IPAddressField()

class Meta:
Expand Down
6 changes: 3 additions & 3 deletions netbox_routing/forms/bulk_import/ospf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class OSPFInstanceImportForm(NetBoxModelImportForm):

class Meta:
model = OSPFInstance
fields = ('name', 'router_id', 'process_id', 'device', 'tags')
fields = ('name', 'router_id', 'process_id', 'device', 'description', 'comments', 'tags',)


class OSPFAreaImportForm(NetBoxModelImportForm):

class Meta:
model = OSPFArea
fields = ('area_id', 'tags')
fields = ('area_id', 'description', 'comments', 'tags',)


class OSPFInterfaceImportForm(NetBoxModelImportForm):
Expand All @@ -56,4 +56,4 @@ class OSPFInterfaceImportForm(NetBoxModelImportForm):

class Meta:
model = OSPFInterface
fields = ('instance', 'area', 'interface', 'tags')
fields = ('instance', 'area', 'interface', 'description', 'comments', 'tags',)
5 changes: 4 additions & 1 deletion netbox_routing/tables/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ class StaticRouteTable(NetBoxTable):

class Meta(NetBoxTable.Meta):
model = StaticRoute
fields = ('pk', 'id', 'devices', 'vrf', 'prefix', 'next_hop', 'name')
fields = (
'pk', 'id', 'devices', 'vrf', 'prefix', 'next_hop', 'name', 'metric', 'permanent', 'description',
'comments',
)
default_columns = ('pk', 'id', 'devices', 'vrf', 'prefix', 'next_hop', 'name')
19 changes: 19 additions & 0 deletions netbox_routing/templates/netbox_routing/staticroute.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@
{% block content %}
<div class="row">
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">Details</h5>
<div class="card-body">
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>
{{object.name}}
</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>
{{object.description}}
</td>
</tr>
</table>
</div>
</div>
<div class="card">
<h5 class="card-header">Static Route</h5>
<div class="card-body">
Expand Down
Empty file.
11 changes: 11 additions & 0 deletions netbox_routing/tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from netaddr.ip import IPAddress


class IPAddressFieldMixin:
def model_to_dict(self, instance, fields, api=False):
model_dict = super().model_to_dict(instance, fields, api)
for key, value in list(model_dict.items()):
if api:
if type(value) is IPAddress:
model_dict[key] = str(value)
return model_dict
Loading

0 comments on commit 2036202

Please sign in to comment.