|
2 | 2 | # Copyright 2024 NetBox Labs Inc
|
3 | 3 | """Diode NetBox Plugin - Tests."""
|
4 | 4 |
|
| 5 | +import copy |
5 | 6 | import datetime
|
6 | 7 | import decimal
|
7 | 8 | import logging
|
8 | 9 | from uuid import uuid4
|
9 | 10 |
|
10 |
| - |
| 11 | +import netaddr |
| 12 | +from circuits.models import Circuit |
11 | 13 | from core.models import ObjectType
|
12 | 14 | from dcim.models import Device, Interface, Site
|
13 |
| -from ipam.models import VLANGroup |
14 |
| -from circuits.models import Circuit |
15 | 15 | from django.contrib.auth import get_user_model
|
16 | 16 | from extras.models import CustomField
|
17 | 17 | from extras.models.customfields import CustomFieldTypeChoices
|
18 |
| -from ipam.models import IPAddress |
19 |
| -import netaddr |
| 18 | +from ipam.models import IPAddress, VLANGroup |
20 | 19 | from rest_framework import status
|
21 | 20 | from users.models import Token
|
22 | 21 | from utilities.testing import APITestCase
|
| 22 | +from virtualization.models import VMInterface |
23 | 23 |
|
24 | 24 | logger = logging.getLogger(__name__)
|
25 | 25 |
|
@@ -822,7 +822,78 @@ def test_generate_diff_update_ip_address(self):
|
822 | 822 | self.assertEqual(ip2.vrf, None)
|
823 | 823 | self.assertEqual(ip2.status, "deprecated")
|
824 | 824 |
|
| 825 | + def test_generate_diff_and_apply_complex_vminterface(self): |
| 826 | + """Test generate diff and apply and update a complex vm interface.""" |
| 827 | + payload = { |
| 828 | + "timestamp": 1, |
| 829 | + "object_type": "virtualization.vminterface", |
| 830 | + "entity": { |
| 831 | + "vm_interface": { |
| 832 | + "virtual_machine": { |
| 833 | + "name": "Virtual Machine 15e00bdf-4294-41df-a450-ffcfec6c7f2b", |
| 834 | + "status": "active", |
| 835 | + "site": { |
| 836 | + "name": "Site 10" |
| 837 | + }, |
| 838 | + "cluster": { |
| 839 | + "name": "Cluster 10", |
| 840 | + "type": { |
| 841 | + "name": "Cluster type 10" |
| 842 | + }, |
| 843 | + "group": { |
| 844 | + "name": "Cluster group 10" |
| 845 | + }, |
| 846 | + "status": "active", |
| 847 | + "scope_site": { |
| 848 | + "name": "Site 10" |
| 849 | + } |
| 850 | + }, |
| 851 | + "role": { |
| 852 | + "name": "Role 10" |
| 853 | + }, |
| 854 | + "platform": { |
| 855 | + "name": "Platform 10", |
| 856 | + "manufacturer": { |
| 857 | + "name": "Manufacturer 10" |
| 858 | + } |
| 859 | + }, |
| 860 | + "vcpus": 1.0, |
| 861 | + "memory": "4096", |
| 862 | + "disk": "100", |
| 863 | + "description": "Virtual Machine A description", |
| 864 | + "comments": "Lorem ipsum dolor sit amet", |
| 865 | + "tags": [ |
| 866 | + { |
| 867 | + "name": "tag 1" |
| 868 | + } |
| 869 | + ] |
| 870 | + }, |
| 871 | + "name": "Interface 47e8a593-8b74-4e94-9a8e-c02113f0bf88", |
| 872 | + "enabled": False, |
| 873 | + "mtu": "1500", |
| 874 | + "primary_mac_address": { |
| 875 | + "mac_address": "00:00:00:00:00:00" |
| 876 | + }, |
| 877 | + "description": "Interface A description", |
| 878 | + "tags": [ |
| 879 | + { |
| 880 | + "name": "tag 1" |
| 881 | + } |
| 882 | + ] |
| 883 | + } |
| 884 | + } |
| 885 | + } |
| 886 | + _ = self.diff_and_apply(payload) |
825 | 887 |
|
| 888 | + payload2 = copy.deepcopy(payload) |
| 889 | + payload2['entity']['vm_interface']["mtu"] = "2000" |
| 890 | + payload2['entity']['vm_interface']["primary_mac_address"] = { |
| 891 | + "mac_address": "00:00:00:00:00:01" |
| 892 | + } |
| 893 | + _ = self.diff_and_apply(payload2) |
| 894 | + vm_interface = VMInterface.objects.get(name="Interface 47e8a593-8b74-4e94-9a8e-c02113f0bf88") |
| 895 | + self.assertEqual(vm_interface.mtu, 2000) |
| 896 | + self.assertEqual(vm_interface.primary_mac_address.mac_address, "00:00:00:00:00:01") |
826 | 897 |
|
827 | 898 | def diff_and_apply(self, payload):
|
828 | 899 | """Diff and apply the payload."""
|
|
0 commit comments