prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Investigate RDMA nightly run failures on 202012
  <!--
  If you are reporting a new issue, make sure that we do not have any duplicates
  already open. You can ensure this by searching the issue list for this
  repository. If there is a duplicate, please close your issue and add a comment
  to the existing issue instead.
  
  If you suspect your issue is a bug, please edit your issue description to
  include the BUG REPORT INFORMATION shown below. If you fail to provide this
  information within 7 days, we cannot debug your issue and will close it. We
  will, however, reopen it if you later provide the information.
  
  For more information about reporting issues, see
  https://github.com/Azure/SONiC/wiki#report-issues
  
  ---------------------------------------------------
  GENERAL SUPPORT INFORMATION
  ---------------------------------------------------
  
  The GitHub issue tracker is for bug reports and feature requests.
  General support can be found at the following locations:
  
  - SONiC Support Forums - https://groups.google.com/forum/#!forum/sonicproject
  
  ---------------------------------------------------
  BUG REPORT INFORMATION
  ---------------------------------------------------
  Use the commands below to provide key information from your environment:
  You do NOT have to include this information if this is a FEATURE REQUEST
  -->
  
  **Description**
  RDMA test runs on TD2 with 202012 are quite flaky. Different set of test failures are seen daily and sometimes test fails at pretest
  09/09 run skipped all tgen tests with the following reason
  SKIPPED [1] /azp/agent/_work/27/s/tests/common/helpers/assertions.py:13: Port is not mapped to the expected DUT
  
  
  
  </issue>
  <code>
  [start of ansible/library/testbed_vm_info.py]
  1 #!/usr/bin/env python
  2 
  3 import re
  4 import yaml
  5 import os
  6 import traceback
  7 import subprocess
  8 import ipaddr as ipaddress
  9 from operator import itemgetter
  10 from itertools import groupby
  11 from collections import defaultdict
  12 import re
  13 
  14 from ansible.parsing.dataloader import DataLoader
  15 from ansible.inventory.manager import InventoryManager
  16 
  17 DOCUMENTATION = '''
  18 module: testbed_vm_info.py
  19 Ansible_version_added:  2.0.0.2
  20 short_description:   Gather all related VMs info
  21 Description:
  22        When deploy testbed topology with VM connected to SONiC, gather neighbor VMs info for generating SONiC minigraph file
  23  options:
  24     base_vm:  base vm name defined in testbed.csv for the deployed topology; required: True
  25     topo:     topology name defined in testbed.csv for the deployed topology; required: True
  26     vm_file:  the virtual machine file path ; default: 'veos'
  27 
  28 Ansible_facts:
  29     'neighbor_eosvm_mgmt':  all VM hosts management IPs
  30     'topoall':              topology information
  31 
  32 '''
  33 
  34 EXAMPLES = '''
  35     - name: gather vm information
  36       testbed_vm_info: base_vm='VM0100' topo='t1' vm_file='veos'
  37 '''
  38 
  39 ### Here are the assumption/expectation of files to gather VM informations, if the file location or name changes, please modify it here
  40 TOPO_PATH = 'vars/'
  41 VM_INV_FILE = 'veos'
  42 
  43 
  44 class TestbedVMFacts():
  45     """
  46     Retrieve testbed VMs management information that for a specified toplogy defined in testbed.csv
  47 
  48     """
  49 
  50     def __init__(self, toponame, vmbase, vmfile):
  51         CLET_SUFFIX = "-clet"
  52         toponame = re.sub(CLET_SUFFIX + "$", "", toponame)
  53         self.topofile = TOPO_PATH+'topo_'+toponame +'.yml'
  54         self.start_index = int(re.findall('VM(\d+)', vmbase)[0])
  55         self.vmhosts = {}
  56         self.vmfile = vmfile
  57         self.inv_mgr = InventoryManager(loader=DataLoader(), sources=self.vmfile)
  58         return
  59 
  60 
  61     def get_neighbor_eos(self):
  62         eos = {}
  63         with open(self.topofile) as f:
  64             vm_topology = yaml.load(f)
  65         self.topoall = vm_topology
  66         for  vm in vm_topology['topology']['VMs']:
  67             vm_index = int(vm_topology['topology']['VMs'][vm]['vm_offset'])+self.start_index
  68             eos[vm] = vm_index
  69         return eos
  70 
  71 
  72 def main():
  73     module = AnsibleModule(
  74         argument_spec=dict(
  75             base_vm=dict(required=True, type='str'),
  76             topo=dict(required=True, type='str'),
  77             vm_file=dict(default=VM_INV_FILE, type='str')
  78         ),
  79         supports_check_mode=True
  80     )
  81     m_args = module.params
  82     topo_type = m_args['topo']
  83     if 'ptf' in topo_type:
  84         module.exit_json(ansible_facts={'neighbor_eosvm_mgmt': {}})
  85     try:
  86         vmsall = TestbedVMFacts(m_args['topo'], m_args['base_vm'], m_args['vm_file'])
  87         neighbor_eos = vmsall.get_neighbor_eos()
  88         for eos in neighbor_eos:
  89             vmname = 'VM'+format(neighbor_eos[eos], '04d')
  90             if vmname in vmsall.inv_mgr.hosts:
  91                 vmsall.vmhosts[eos] = vmsall.inv_mgr.get_host(vmname).get_vars()['ansible_host']
  92             else:
  93                 err_msg = "cannot find the vm " + vmname + " in VM inventory file, please make sure you have enough VMs for the topology you are using"
  94                 module.fail_json(msg=err_msg)
  95         module.exit_json(ansible_facts={'neighbor_eosvm_mgmt':vmsall.vmhosts, 'topoall': vmsall.topoall})
  96     except (IOError, OSError):
  97         module.fail_json(msg="Can not find file "+vmsall.topofile+" or "+m_args['vm_file']+" or "+VM_INV_FILE)
  98     except Exception as e:
  99         module.fail_json(msg=traceback.format_exc())
  100 
  101 from ansible.module_utils.basic import *
  102 if __name__ == "__main__":
  103     main()
  104 
  105
  [end of ansible/library/testbed_vm_info.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/ansible/library/testbed_vm_info.py b/ansible/library/testbed_vm_info.py
  --- a/ansible/library/testbed_vm_info.py
  +++ b/ansible/library/testbed_vm_info.py
  @@ -39,6 +39,7 @@
   ### Here are the assumption/expectation of files to gather VM informations, if the file location or name changes, please modify it here
   TOPO_PATH = 'vars/'
   VM_INV_FILE = 'veos'
  +TGEN_MGMT_NETWORK = '10.65.32.0/24'
   
   
   class TestbedVMFacts():
  @@ -51,7 +52,10 @@
           CLET_SUFFIX = "-clet"
           toponame = re.sub(CLET_SUFFIX + "$", "", toponame)
           self.topofile = TOPO_PATH+'topo_'+toponame +'.yml'
  -        self.start_index = int(re.findall('VM(\d+)', vmbase)[0])
  +        if vmbase != '':
  +            self.start_index = int(re.findall('VM(\d+)', vmbase)[0])
  +        else:
  +            self.start_index = 0
           self.vmhosts = {}
           self.vmfile = vmfile
           self.inv_mgr = InventoryManager(loader=DataLoader(), sources=self.vmfile)
  @@ -85,9 +89,12 @@
       try:
           vmsall = TestbedVMFacts(m_args['topo'], m_args['base_vm'], m_args['vm_file'])
           neighbor_eos = vmsall.get_neighbor_eos()
  -        for eos in neighbor_eos:
  +        tgen_mgmt_ips = list(ipaddress.IPNetwork(unicode(TGEN_MGMT_NETWORK)))
  +        for index, eos in enumerate(neighbor_eos):
               vmname = 'VM'+format(neighbor_eos[eos], '04d')
  -            if vmname in vmsall.inv_mgr.hosts:
  +            if 'tgen' in topo_type:
  +                vmsall.vmhosts[eos] = str(tgen_mgmt_ips[index])
  +            elif vmname in vmsall.inv_mgr.hosts:
                   vmsall.vmhosts[eos] = vmsall.inv_mgr.get_host(vmname).get_vars()['ansible_host']
               else:
                   err_msg = "cannot find the vm " + vmname + " in VM inventory file, please make sure you have enough VMs for the topology you are using"
  
verification_info: {"golden_diff": "diff --git a/ansible/library/testbed_vm_info.py b/ansible/library/testbed_vm_info.py\n--- a/ansible/library/testbed_vm_info.py\n+++ b/ansible/library/testbed_vm_info.py\n@@ -39,6 +39,7 @@\n ### Here are the assumption/expectation of files to gather VM informations, if the file location or name changes, please modify it here\n TOPO_PATH = 'vars/'\n VM_INV_FILE = 'veos'\n+TGEN_MGMT_NETWORK = '10.65.32.0/24'\n \n \n class TestbedVMFacts():\n@@ -51,7 +52,10 @@\n         CLET_SUFFIX = \"-clet\"\n         toponame = re.sub(CLET_SUFFIX + \"$\", \"\", toponame)\n         self.topofile = TOPO_PATH+'topo_'+toponame +'.yml'\n-        self.start_index = int(re.findall('VM(\\d+)', vmbase)[0])\n+        if vmbase != '':\n+            self.start_index = int(re.findall('VM(\\d+)', vmbase)[0])\n+        else:\n+            self.start_index = 0\n         self.vmhosts = {}\n         self.vmfile = vmfile\n         self.inv_mgr = InventoryManager(loader=DataLoader(), sources=self.vmfile)\n@@ -85,9 +89,12 @@\n     try:\n         vmsall = TestbedVMFacts(m_args['topo'], m_args['base_vm'], m_args['vm_file'])\n         neighbor_eos = vmsall.get_neighbor_eos()\n-        for eos in neighbor_eos:\n+        tgen_mgmt_ips = list(ipaddress.IPNetwork(unicode(TGEN_MGMT_NETWORK)))\n+        for index, eos in enumerate(neighbor_eos):\n             vmname = 'VM'+format(neighbor_eos[eos], '04d')\n-            if vmname in vmsall.inv_mgr.hosts:\n+            if 'tgen' in topo_type:\n+                vmsall.vmhosts[eos] = str(tgen_mgmt_ips[index])\n+            elif vmname in vmsall.inv_mgr.hosts:\n                 vmsall.vmhosts[eos] = vmsall.inv_mgr.get_host(vmname).get_vars()['ansible_host']\n             else:\n                 err_msg = \"cannot find the vm \" + vmname + \" in VM inventory file, please make sure you have enough VMs for the topology you are using\"\n", "issue": "Investigate RDMA nightly run failures on 202012\n<!--\r\nIf you are reporting a new issue, make sure that we do not have any duplicates\r\nalready open. You can ensure this by searching the issue list for this\r\nrepository. If there is a duplicate, please close your issue and add a comment\r\nto the existing issue instead.\r\n\r\nIf you suspect your issue is a bug, please edit your issue description to\r\ninclude the BUG REPORT INFORMATION shown below. If you fail to provide this\r\ninformation within 7 days, we cannot debug your issue and will close it. We\r\nwill, however, reopen it if you later provide the information.\r\n\r\nFor more information about reporting issues, see\r\nhttps://github.com/Azure/SONiC/wiki#report-issues\r\n\r\n---------------------------------------------------\r\nGENERAL SUPPORT INFORMATION\r\n---------------------------------------------------\r\n\r\nThe GitHub issue tracker is for bug reports and feature requests.\r\nGeneral support can be found at the following locations:\r\n\r\n- SONiC Support Forums - https://groups.google.com/forum/#!forum/sonicproject\r\n\r\n---------------------------------------------------\r\nBUG REPORT INFORMATION\r\n---------------------------------------------------\r\nUse the commands below to provide key information from your environment:\r\nYou do NOT have to include this information if this is a FEATURE REQUEST\r\n-->\r\n\r\n**Description**\r\nRDMA test runs on TD2 with 202012 are quite flaky. Different set of test failures are seen daily and sometimes test fails at pretest\r\n09/09 run skipped all tgen tests with the following reason\r\nSKIPPED [1] /azp/agent/_work/27/s/tests/common/helpers/assertions.py:13: Port is not mapped to the expected DUT\r\n\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\nimport re\nimport yaml\nimport os\nimport traceback\nimport subprocess\nimport ipaddr as ipaddress\nfrom operator import itemgetter\nfrom itertools import groupby\nfrom collections import defaultdict\nimport re\n\nfrom ansible.parsing.dataloader import DataLoader\nfrom ansible.inventory.manager import InventoryManager\n\nDOCUMENTATION = '''\nmodule: testbed_vm_info.py\nAnsible_version_added:  2.0.0.2\nshort_description:   Gather all related VMs info\nDescription:\n       When deploy testbed topology with VM connected to SONiC, gather neighbor VMs info for generating SONiC minigraph file\n options:\n    base_vm:  base vm name defined in testbed.csv for the deployed topology; required: True\n    topo:     topology name defined in testbed.csv for the deployed topology; required: True\n    vm_file:  the virtual machine file path ; default: 'veos'\n\nAnsible_facts:\n    'neighbor_eosvm_mgmt':  all VM hosts management IPs\n    'topoall':              topology information\n\n'''\n\nEXAMPLES = '''\n    - name: gather vm information\n      testbed_vm_info: base_vm='VM0100' topo='t1' vm_file='veos'\n'''\n\n### Here are the assumption/expectation of files to gather VM informations, if the file location or name changes, please modify it here\nTOPO_PATH = 'vars/'\nVM_INV_FILE = 'veos'\n\n\nclass TestbedVMFacts():\n    \"\"\"\n    Retrieve testbed VMs management information that for a specified toplogy defined in testbed.csv\n\n    \"\"\"\n\n    def __init__(self, toponame, vmbase, vmfile):\n        CLET_SUFFIX = \"-clet\"\n        toponame = re.sub(CLET_SUFFIX + \"$\", \"\", toponame)\n        self.topofile = TOPO_PATH+'topo_'+toponame +'.yml'\n        self.start_index = int(re.findall('VM(\\d+)', vmbase)[0])\n        self.vmhosts = {}\n        self.vmfile = vmfile\n        self.inv_mgr = InventoryManager(loader=DataLoader(), sources=self.vmfile)\n        return\n\n\n    def get_neighbor_eos(self):\n        eos = {}\n        with open(self.topofile) as f:\n            vm_topology = yaml.load(f)\n        self.topoall = vm_topology\n        for  vm in vm_topology['topology']['VMs']:\n            vm_index = int(vm_topology['topology']['VMs'][vm]['vm_offset'])+self.start_index\n            eos[vm] = vm_index\n        return eos\n\n\ndef main():\n    module = AnsibleModule(\n        argument_spec=dict(\n            base_vm=dict(required=True, type='str'),\n            topo=dict(required=True, type='str'),\n            vm_file=dict(default=VM_INV_FILE, type='str')\n        ),\n        supports_check_mode=True\n    )\n    m_args = module.params\n    topo_type = m_args['topo']\n    if 'ptf' in topo_type:\n        module.exit_json(ansible_facts={'neighbor_eosvm_mgmt': {}})\n    try:\n        vmsall = TestbedVMFacts(m_args['topo'], m_args['base_vm'], m_args['vm_file'])\n        neighbor_eos = vmsall.get_neighbor_eos()\n        for eos in neighbor_eos:\n            vmname = 'VM'+format(neighbor_eos[eos], '04d')\n            if vmname in vmsall.inv_mgr.hosts:\n                vmsall.vmhosts[eos] = vmsall.inv_mgr.get_host(vmname).get_vars()['ansible_host']\n            else:\n                err_msg = \"cannot find the vm \" + vmname + \" in VM inventory file, please make sure you have enough VMs for the topology you are using\"\n                module.fail_json(msg=err_msg)\n        module.exit_json(ansible_facts={'neighbor_eosvm_mgmt':vmsall.vmhosts, 'topoall': vmsall.topoall})\n    except (IOError, OSError):\n        module.fail_json(msg=\"Can not find file \"+vmsall.topofile+\" or \"+m_args['vm_file']+\" or \"+VM_INV_FILE)\n    except Exception as e:\n        module.fail_json(msg=traceback.format_exc())\n\nfrom ansible.module_utils.basic import *\nif __name__ == \"__main__\":\n    main()\n\n", "path": "ansible/library/testbed_vm_info.py"}]}