Repository: nautobot/nautobot

Issue:
config context in git repo using device_types is not mapped in nautobot
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    This form is only for reporting reproducible bugs. If you need assistance
    with Nautobot installation, or if you have a general question, please start a
    discussion instead: https://github.com/nautobot/nautobot/discussions

    Please describe the environment in which you are running Nautobot. Be sure
    that you are running an unmodified instance of the latest stable release
    before submitting a bug report, and that any plugins have been disabled.
-->
### Environment
* Python version: 3.8.2
* Nautobot version: 1.0.2

<!--
    Describe in detail the exact steps that someone else can take to reproduce
    this bug using the current stable release of Nautobot. Begin with the
    creation of any necessary database objects and call out every operation
    being performed explicitly. If reporting a bug in the REST API, be sure to
    reconstruct the raw HTTP request(s) being made: Don't rely on a client
    library such as pynautobot.
-->
### Steps to Reproduce
1.  Configure nautobot to point to git repo supporting `config_context` data type.
2. Create `test.yaml`, include `device_type`:
```
_metadata:
  name: "Apply Me To The Mars"
  weight: 1000
  is_active: true
  device_types:
    - model: DCS-7280CR3-32D4
  roles:
    - slug: pe
    - slug: bdr
mars:
  - 998
 ```
3. Commit `test.yaml` to repo
4. Sync repo with nautobot

<!-- What did you expect to happen? -->
### Expected Behavior
Review `[nautobot] Apply Me To The Mars` config context in Nautobot should display all mappings configured in `test.yaml`

<!-- What happened instead? -->

### Observed Behavior
All mappings except `device_types` are mapped.

Reviewing the change log after the repo sync shows `device_types` as an empty list.


Discussion:
Thank you for the report!

Resolving patch:
diff --git a/nautobot/extras/datasources/git.py b/nautobot/extras/datasources/git.py
--- a/nautobot/extras/datasources/git.py
+++ b/nautobot/extras/datasources/git.py
@@ -13,7 +13,7 @@
 from django_rq import job
 import yaml
 
-from nautobot.dcim.models import Device, DeviceRole, Platform, Region, Site
+from nautobot.dcim.models import Device, DeviceRole, DeviceType, Platform, Region, Site
 from nautobot.extras.choices import LogLevelChoices, JobResultStatusChoices
 from nautobot.extras.models import (
     ConfigContext,
@@ -226,6 +226,7 @@ def update_git_config_contexts(repository_record, job_result):
     for filter_type in (
         "regions",
         "sites",
+        "device_types",
         "roles",
         "platforms",
         "cluster_groups",
@@ -343,6 +344,7 @@ def import_config_context(context_data, repository_record, job_result, logger):
     for key, model_class in [
         ("regions", Region),
         ("sites", Site),
+        ("device_types", DeviceType),
         ("roles", DeviceRole),
         ("platforms", Platform),
         ("cluster_groups", ClusterGroup),


Test patch:
diff --git a/nautobot/extras/tests/test_datasources.py b/nautobot/extras/tests/test_datasources.py
--- a/nautobot/extras/tests/test_datasources.py
+++ b/nautobot/extras/tests/test_datasources.py
@@ -157,10 +157,11 @@ def populate_repo(path, url):
                         yaml.dump(
                             {
                                 "_metadata": {
-                                    "name": "Region NYC servers",
+                                    "name": "Frobozz 1000 NTP servers",
                                     "weight": 1500,
-                                    "description": "NTP servers for region NYC",
+                                    "description": "NTP servers for Frobozz 1000 devices **only**",
                                     "is_active": True,
+                                    "device_types": [{"slug": self.device_type.slug}],
                                 },
                                 "ntp-servers": ["172.16.10.22", "172.16.10.33"],
                             },
@@ -191,14 +192,15 @@ def populate_repo(path, url):
 
                 # Make sure ConfigContext was successfully loaded from file
                 config_context = ConfigContext.objects.get(
-                    name="Region NYC servers",
+                    name="Frobozz 1000 NTP servers",
                     owner_object_id=self.repo.pk,
                     owner_content_type=ContentType.objects.get_for_model(GitRepository),
                 )
                 self.assertIsNotNone(config_context)
                 self.assertEqual(1500, config_context.weight)
-                self.assertEqual("NTP servers for region NYC", config_context.description)
+                self.assertEqual("NTP servers for Frobozz 1000 devices **only**", config_context.description)
                 self.assertTrue(config_context.is_active)
+                self.assertEqual(list(config_context.device_types.all()), [self.device_type])
                 self.assertEqual(
                     {"ntp-servers": ["172.16.10.22", "172.16.10.33"]},
                     config_context.data,