Skip to content

Add support for default status #45

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

Merged
merged 3 commits into from
May 27, 2020
Merged

Add support for default status #45

merged 3 commits into from
May 27, 2020

Conversation

dgarros
Copy link
Contributor

@dgarros dgarros commented May 23, 2020

fixes #23

@dgarros dgarros requested a review from glennmatthews May 23, 2020 14:41
device = Device.objects.get(
name=self.netdev.hostname,
device_type=self.device_type,
device_role=self.netdev.ot.role,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to move device_type and device_role out of the get() call (so we match the device based only on name and site), and possibly update them even if we have an existing device? I'm thinking something like:

try:
    device = Device.objects.get(name=self.netdev.hostname, site=self.netdev.ot.site)
except Device.DoesNotExist:
    device = Device.objects.create(name=self.netdev.hostname, site=self.netdev.ot.site, status=default_status)

device.device_type = self.device_type
device.device_role = self.netdev.ot.role
device.platform = self.netdev.ot.platform
device.serial = self.netdev.serial_number
device.save()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@glennmatthews thanks, I think it's a great idea
I remove device_role and device_type from the get() but I couldn't remove them from create() because both are mandatory.
Now if a device already exist but doesn't have a platform, it will be updated as part of the onboarding as well as the serial number.

self.assertIsInstance(nbk.device, Device)
self.assertEqual(nbk.device.status, "planned")
self.assertEqual(nbk.device, nbk.netdev.ot.created_device)
self.assertEqual(nbk.device.serial, "123456")
Copy link
Contributor

Choose a reason for hiding this comment

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

If you accept my previous comment, then it'd make sense to check nbk.device.device_role, nbk.device.device_type, nbk.device.platform here as well.

@dgarros dgarros mentioned this pull request May 27, 2020
@dgarros dgarros merged commit e616611 into master May 27, 2020
@dgarros dgarros deleted the dga-issue-23 branch July 29, 2020 22:07
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.

Add a setting for default Status
2 participants