prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Need to add the Yum updates datasource to the documentation
  The [PR](https://github.com/RedHatInsights/insights-core/pull/2993/files#diff-22151ef794ba196097984a47bf24b6759c261de6dc062ac541da099084e5c50a) adding this datasource did not add the datasource to the documentation [here](https://github.com/RedHatInsights/insights-core/blob/master/docs/custom_datasources_index.rst).
  
  </issue>
  <code>
  [start of insights/specs/datasources/yum_updates.py]
  1 """
  2 Custom datasource for collecting yum updates
  3 """
  4 import json
  5 import time
  6 
  7 from insights import datasource, HostContext, SkipComponent
  8 from insights.components.rhel_version import IsRhel7
  9 from insights.core.spec_factory import DatasourceProvider
  10 
  11 sorted_cmp = None
  12 try:
  13     # cmp_to_key is not available in python 2.6, but it has sorted function which accepts cmp function
  14     def sorted_cmp(it, cmp):
  15         from functools import cmp_to_key
  16         return sorted(it, key=cmp_to_key(cmp))
  17 except ImportError:
  18     sorted_cmp = sorted
  19 
  20 
  21 class UpdatesManager:
  22     """ Performs package resolution on yum based systems """
  23     def __init__(self):
  24         import yum
  25 
  26         self.base = yum.YumBase()
  27         self.base.doGenericSetup(cache=1)
  28         self.releasever = self.base.conf.yumvar['releasever']
  29         self.basearch = self.base.conf.yumvar['basearch']
  30         self.packages = []
  31         self.repos = []
  32         self.updict = {}
  33 
  34     def __enter__(self):
  35         return self
  36 
  37     def __exit__(self, *args):
  38         pass
  39 
  40     @staticmethod
  41     def pkg_cmp(a, b):
  42         vercmp = a.verCMP(b)
  43         if vercmp != 0:
  44             return vercmp
  45         if a.repoid != b.repoid:
  46             return -1 if a.repoid < b.repoid else 1
  47         return 0
  48 
  49     def sorted_pkgs(self, pkgs):
  50         return sorted_cmp(pkgs, self.pkg_cmp)
  51 
  52     def load(self):
  53         self.base.doRepoSetup()
  54         self.base.doSackSetup()
  55         self.packages = self.base.pkgSack.returnPackages()
  56         self.repos = self.base.repos.repos
  57         self._build_updict()
  58 
  59     def _build_updict(self):
  60         self.updict = {}
  61         for pkg in self.packages:
  62             self.updict.setdefault(pkg.na, []).append(pkg)
  63 
  64     def enabled_repos(self):
  65         return [repo.id for repo in self.base.repos.listEnabled()]
  66 
  67     def installed_packages(self):
  68         return self.base.rpmdb.returnPackages()
  69 
  70     def updates(self, pkg):
  71         nevra = pkg.nevra
  72         updates_list = []
  73         for upg in self.updict[pkg.na]:
  74             if upg.verGT(pkg):
  75                 updates_list.append(upg)
  76         return nevra, updates_list
  77 
  78     @staticmethod
  79     def pkg_nevra(pkg):
  80         return "{}-{}:{}-{}.{}".format(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch)
  81 
  82     @staticmethod
  83     def pkg_repo(pkg):
  84         return pkg.repoid
  85 
  86     def advisory(self, pkg):
  87         adv = self.base.upinfo.get_notice(pkg.nvr)
  88         if adv:
  89             return adv.get_metadata()['update_id']
  90         return None
  91 
  92     @staticmethod
  93     def last_update():
  94         return 0
  95 
  96 
  97 @datasource(HostContext, [IsRhel7])
  98 def yum_updates(_broker):
  99     """
  100     This datasource provides a list of available updates on the system.
  101     It uses the yum python library installed locally, and collects list of
  102     available package updates, along with advisory info where applicable.
  103     """
  104 
  105     if not _broker.get(IsRhel7):
  106         raise SkipComponent("Yum updates currently only works on RHEL 7")
  107 
  108     with UpdatesManager() as umgr:
  109         umgr.load()
  110 
  111         response = {
  112             "releasever": umgr.releasever,
  113             "basearch": umgr.basearch,
  114             "update_list": {},
  115         }
  116 
  117         data = {'package_list': umgr.installed_packages()}
  118         updates = {}
  119         for pkg in data["package_list"]:
  120             (nevra, updates_list) = umgr.updates(pkg)
  121             updates[nevra] = updates_list
  122             for (nevra, update_list) in updates.items():
  123                 if update_list:
  124                     out_list = []
  125                     for pkg in umgr.sorted_pkgs(update_list):
  126                         pkg_dict = {
  127                             "package": umgr.pkg_nevra(pkg),
  128                             "repository": umgr.pkg_repo(pkg),
  129                             "basearch": response["basearch"],
  130                             "releasever": response["releasever"],
  131                         }
  132                         erratum = umgr.advisory(pkg)
  133                         if erratum:
  134                             pkg_dict["erratum"] = erratum
  135                         out_list.append(pkg_dict)
  136                     response["update_list"][nevra] = {"available_updates": out_list}
  137 
  138         ts = umgr.last_update()
  139         if ts:
  140             response["metadata_time"] = time.strftime("%FT%TZ", time.gmtime(ts))
  141     return DatasourceProvider(content=json.dumps(response), relative_path='insights_commands/yum_updates_list')
  142
  [end of insights/specs/datasources/yum_updates.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/insights/specs/datasources/yum_updates.py b/insights/specs/datasources/yum_updates.py
  --- a/insights/specs/datasources/yum_updates.py
  +++ b/insights/specs/datasources/yum_updates.py
  @@ -70,7 +70,7 @@
       def updates(self, pkg):
           nevra = pkg.nevra
           updates_list = []
  -        for upg in self.updict[pkg.na]:
  +        for upg in self.updict.get(pkg.na, []):
               if upg.verGT(pkg):
                   updates_list.append(upg)
           return nevra, updates_list
  @@ -100,6 +100,32 @@
       This datasource provides a list of available updates on the system.
       It uses the yum python library installed locally, and collects list of
       available package updates, along with advisory info where applicable.
  +
  +    Sample data returned::
  +
  +        {
  +          "releasever": "8",
  +          "basearch": "x86_64",
  +          "update_list": {
  +            "NetworkManager-1:1.22.8-4.el8.x86_64": {
  +              "available_updates": [
  +                {
  +                  "package": "NetworkManager-1:1.22.8-5.el8_2.x86_64",
  +                  "repository": "rhel-8-for-x86_64-baseos-rpms",
  +                  "basearch": "x86_64",
  +                  "releasever": "8",
  +                  "erratum": "RHSA-2020:3011"
  +                }
  +              ]
  +            }
  +          },
  +          "metadata_time": "2021-01-01T09:39:45Z"
  +        }
  +
  +    Returns:
  +        list: List of available updates
  +    Raises:
  +        SkipComponent: Raised on systems different than RHEL 7
       """
   
       if not _broker.get(IsRhel7):
  
verification_info: {"golden_diff": "diff --git a/insights/specs/datasources/yum_updates.py b/insights/specs/datasources/yum_updates.py\n--- a/insights/specs/datasources/yum_updates.py\n+++ b/insights/specs/datasources/yum_updates.py\n@@ -70,7 +70,7 @@\n     def updates(self, pkg):\n         nevra = pkg.nevra\n         updates_list = []\n-        for upg in self.updict[pkg.na]:\n+        for upg in self.updict.get(pkg.na, []):\n             if upg.verGT(pkg):\n                 updates_list.append(upg)\n         return nevra, updates_list\n@@ -100,6 +100,32 @@\n     This datasource provides a list of available updates on the system.\n     It uses the yum python library installed locally, and collects list of\n     available package updates, along with advisory info where applicable.\n+\n+    Sample data returned::\n+\n+        {\n+          \"releasever\": \"8\",\n+          \"basearch\": \"x86_64\",\n+          \"update_list\": {\n+            \"NetworkManager-1:1.22.8-4.el8.x86_64\": {\n+              \"available_updates\": [\n+                {\n+                  \"package\": \"NetworkManager-1:1.22.8-5.el8_2.x86_64\",\n+                  \"repository\": \"rhel-8-for-x86_64-baseos-rpms\",\n+                  \"basearch\": \"x86_64\",\n+                  \"releasever\": \"8\",\n+                  \"erratum\": \"RHSA-2020:3011\"\n+                }\n+              ]\n+            }\n+          },\n+          \"metadata_time\": \"2021-01-01T09:39:45Z\"\n+        }\n+\n+    Returns:\n+        list: List of available updates\n+    Raises:\n+        SkipComponent: Raised on systems different than RHEL 7\n     \"\"\"\n \n     if not _broker.get(IsRhel7):\n", "issue": "Need to add the Yum updates datasource to the documentation\nThe [PR](https://github.com/RedHatInsights/insights-core/pull/2993/files#diff-22151ef794ba196097984a47bf24b6759c261de6dc062ac541da099084e5c50a) adding this datasource did not add the datasource to the documentation [here](https://github.com/RedHatInsights/insights-core/blob/master/docs/custom_datasources_index.rst).\n", "before_files": [{"content": "\"\"\"\nCustom datasource for collecting yum updates\n\"\"\"\nimport json\nimport time\n\nfrom insights import datasource, HostContext, SkipComponent\nfrom insights.components.rhel_version import IsRhel7\nfrom insights.core.spec_factory import DatasourceProvider\n\nsorted_cmp = None\ntry:\n    # cmp_to_key is not available in python 2.6, but it has sorted function which accepts cmp function\n    def sorted_cmp(it, cmp):\n        from functools import cmp_to_key\n        return sorted(it, key=cmp_to_key(cmp))\nexcept ImportError:\n    sorted_cmp = sorted\n\n\nclass UpdatesManager:\n    \"\"\" Performs package resolution on yum based systems \"\"\"\n    def __init__(self):\n        import yum\n\n        self.base = yum.YumBase()\n        self.base.doGenericSetup(cache=1)\n        self.releasever = self.base.conf.yumvar['releasever']\n        self.basearch = self.base.conf.yumvar['basearch']\n        self.packages = []\n        self.repos = []\n        self.updict = {}\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, *args):\n        pass\n\n    @staticmethod\n    def pkg_cmp(a, b):\n        vercmp = a.verCMP(b)\n        if vercmp != 0:\n            return vercmp\n        if a.repoid != b.repoid:\n            return -1 if a.repoid < b.repoid else 1\n        return 0\n\n    def sorted_pkgs(self, pkgs):\n        return sorted_cmp(pkgs, self.pkg_cmp)\n\n    def load(self):\n        self.base.doRepoSetup()\n        self.base.doSackSetup()\n        self.packages = self.base.pkgSack.returnPackages()\n        self.repos = self.base.repos.repos\n        self._build_updict()\n\n    def _build_updict(self):\n        self.updict = {}\n        for pkg in self.packages:\n            self.updict.setdefault(pkg.na, []).append(pkg)\n\n    def enabled_repos(self):\n        return [repo.id for repo in self.base.repos.listEnabled()]\n\n    def installed_packages(self):\n        return self.base.rpmdb.returnPackages()\n\n    def updates(self, pkg):\n        nevra = pkg.nevra\n        updates_list = []\n        for upg in self.updict[pkg.na]:\n            if upg.verGT(pkg):\n                updates_list.append(upg)\n        return nevra, updates_list\n\n    @staticmethod\n    def pkg_nevra(pkg):\n        return \"{}-{}:{}-{}.{}\".format(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch)\n\n    @staticmethod\n    def pkg_repo(pkg):\n        return pkg.repoid\n\n    def advisory(self, pkg):\n        adv = self.base.upinfo.get_notice(pkg.nvr)\n        if adv:\n            return adv.get_metadata()['update_id']\n        return None\n\n    @staticmethod\n    def last_update():\n        return 0\n\n\n@datasource(HostContext, [IsRhel7])\ndef yum_updates(_broker):\n    \"\"\"\n    This datasource provides a list of available updates on the system.\n    It uses the yum python library installed locally, and collects list of\n    available package updates, along with advisory info where applicable.\n    \"\"\"\n\n    if not _broker.get(IsRhel7):\n        raise SkipComponent(\"Yum updates currently only works on RHEL 7\")\n\n    with UpdatesManager() as umgr:\n        umgr.load()\n\n        response = {\n            \"releasever\": umgr.releasever,\n            \"basearch\": umgr.basearch,\n            \"update_list\": {},\n        }\n\n        data = {'package_list': umgr.installed_packages()}\n        updates = {}\n        for pkg in data[\"package_list\"]:\n            (nevra, updates_list) = umgr.updates(pkg)\n            updates[nevra] = updates_list\n            for (nevra, update_list) in updates.items():\n                if update_list:\n                    out_list = []\n                    for pkg in umgr.sorted_pkgs(update_list):\n                        pkg_dict = {\n                            \"package\": umgr.pkg_nevra(pkg),\n                            \"repository\": umgr.pkg_repo(pkg),\n                            \"basearch\": response[\"basearch\"],\n                            \"releasever\": response[\"releasever\"],\n                        }\n                        erratum = umgr.advisory(pkg)\n                        if erratum:\n                            pkg_dict[\"erratum\"] = erratum\n                        out_list.append(pkg_dict)\n                    response[\"update_list\"][nevra] = {\"available_updates\": out_list}\n\n        ts = umgr.last_update()\n        if ts:\n            response[\"metadata_time\"] = time.strftime(\"%FT%TZ\", time.gmtime(ts))\n    return DatasourceProvider(content=json.dumps(response), relative_path='insights_commands/yum_updates_list')\n", "path": "insights/specs/datasources/yum_updates.py"}]}