# Buggy code
def _generate_switchport_commands(self, if_name, req_conf):
    commands = []
    curr_conf = self._current_config.get(if_name, {})
    curr_mode = curr_conf.get("mode")
    req_mode = req_conf.get("mode")
    if req_mode != curr_mode:
        commands.append("switchport mode %s" % req_mode)
    curr_access_vlan = curr_conf.get("access_vlan")
    req_access_vlan = req_conf.get("access_vlan")
    if curr_access_vlan != req_access_vlan and req_access_vlan:
        commands.append("switchport access vlan %s" % req_access_vlan)
    curr_trunk_vlans = curr_conf.get("trunk_allowed_vlans") or set()
    if curr_trunk_vlans:
        curr_trunk_vlans = set(curr_trunk_vlans)
    req_trunk_vlans = req_conf.get("trunk_allowed_vlans") or set()
    if req_trunk_vlans:
        req_trunk_vlans = set(req_trunk_vlans)
    if req_mode != "access" and curr_trunk_vlans != req_trunk_vlans:
        removed_vlans = curr_trunk_vlans - req_trunk_vlans
        for vlan_id in removed_vlans:
            commands.append(
                "switchport %s allowed-vlan remove %s" % (req_mode, vlan_id)
            )
        added_vlans = req_trunk_vlans - curr_trunk_vlans
        for vlan_id in added_vlans:
            commands.append("switchport %s allowed-vlan add %s" % (req_mode, vlan_id))

    if commands:
        self._add_interface_commands(if_name, commands)


# Traceback (ValueError)
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: invalid literal for int() with base 10: 'N/A'
fatal: [l-csi-2700-03]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-local-162000Bkv_Bv/ansible-tmp-1538555779.75-97896039323320/AnsiballZ_onyx_l2_interface.py\", line 113, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-local-162000Bkv_Bv/ansible-tmp-1538555779.75-97896039323320/AnsiballZ_onyx_l2_interface.py\", line 105, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-local-162000Bkv_Bv/ansible-tmp-1538555779.75-97896039323320/AnsiballZ_onyx_l2_interface.py\", line 48, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_onyx_l2_interface_payload_Y_eddw/__main__.py\", line 288, in <module>\n  File \"/tmp/ansible_onyx_l2_interface_payload_Y_eddw/__main__.py\", line 284, in main\n  File \"/tmp/ansible_onyx_l2_interface_payload_Y_eddw/ansible_onyx_l2_interface_payload.zip/ansible/module_utils/network/onyx/onyx.py\", line 249, in main\n  File \"/tmp/ansible_onyx_l2_interface_payload_Y_eddw/ansible_onyx_l2_interface_payload.zip/ansible/module_utils/network/onyx/onyx.py\", line 227, in run\n  File \"/tmp/ansible_onyx_l2_interface_payload_Y_eddw/__main__.py\", line 187, in load_current_config\n  File \"/tmp/ansible_onyx_l2_interface_payload_Y_eddw/__main__.py\", line 171, in _create_switchport_data\n  File \"/tmp/ansible_onyx_l2_interface_payload_Y_eddw/__main__.py\", line 162, in get_access_vlan\nValueError: invalid literal for int() with base 10: 'N/A'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
to retry, use: --limit @/swgwork/eddies/ansible/lab/case_488640/l2_interface.retry

# Fixed code
def _generate_switchport_commands(self, if_name, req_conf):
    commands = []
    curr_conf = self._current_config.get(if_name, {})
    curr_mode = curr_conf.get("mode")
    req_mode = req_conf.get("mode")
    if req_mode != curr_mode:
        commands.append("switchport mode %s" % req_mode)
    curr_access_vlan = curr_conf.get("access_vlan")
    req_access_vlan = req_conf.get("access_vlan")
    if curr_access_vlan != req_access_vlan and req_access_vlan:
        commands.append("switchport access vlan %s" % req_access_vlan)
    curr_trunk_vlans = curr_conf.get("trunk_allowed_vlans") or set()
    if curr_trunk_vlans:
        curr_trunk_vlans = set(curr_trunk_vlans)
    req_trunk_vlans = req_conf.get("trunk_allowed_vlans") or set()
    if req_trunk_vlans:
        req_trunk_vlans = set(req_trunk_vlans)
    if req_mode != "access" and curr_trunk_vlans != req_trunk_vlans:
        added_vlans = req_trunk_vlans - curr_trunk_vlans
        for vlan_id in added_vlans:
            commands.append("switchport %s allowed-vlan add %s" % (req_mode, vlan_id))
        removed_vlans = curr_trunk_vlans - req_trunk_vlans
        for vlan_id in removed_vlans:
            commands.append(
                "switchport %s allowed-vlan remove %s" % (req_mode, vlan_id)
            )

    if commands:
        self._add_interface_commands(if_name, commands)