Skip to content

Commit

Permalink
Merge pull request #134 from networktocode/mzb-develop-fix-93
Browse files Browse the repository at this point in the history
Fix Issue #93
  • Loading branch information
mzbroch authored Mar 16, 2021
2 parents 35912e8 + b4eada1 commit 63b746c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions netbox_onboarding/migrations/0004_create_onboardingdevice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.db import migrations


def create_missing_onboardingdevice(apps, schema_editor):
Device = apps.get_model("dcim", "Device")
OnboardingDevice = apps.get_model("netbox_onboarding", "OnboardingDevice")

for device in Device.objects.filter(onboardingdevice__isnull=True):
OnboardingDevice.objects.create(device=device)


class Migration(migrations.Migration):

dependencies = [
("netbox_onboarding", "0003_onboardingtask_change_logging_model"),
]

operations = [
migrations.RunPython(create_missing_onboardingdevice),
]
6 changes: 5 additions & 1 deletion netbox_onboarding/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

@REQUEST_TIME.time()
@job("default")
def onboard_device(task_id, credentials): # pylint: disable=too-many-statements
def onboard_device(task_id, credentials): # pylint: disable=too-many-statements, too-many-branches
"""Process a single OnboardingTask instance."""
username = credentials.username
password = credentials.password
Expand Down Expand Up @@ -108,6 +108,10 @@ def onboard_device(task_id, credentials): # pylint: disable=too-many-statements
ot.save()
onboarding_status = False

finally:
if onboarded_device and not OnboardingDevice.objects.filter(device=onboarded_device):
OnboardingDevice.objects.create(device=onboarded_device)

onboardingtask_results_counter.labels(status=ot.status).inc()

return dict(ok=onboarding_status)

0 comments on commit 63b746c

Please sign in to comment.