Repository: sonic-net/sonic-utilities

Issue:
show vlan brief - traceback when no configured vlan ip address / dhcp helper address
**Description**
If you have configured vlan's, but have not configured the IP address or dhcp helper address for the vlan interface, then a traceback is thrown.

```
root@sonic:/home/user# show vlan brief
Traceback (most recent call last):
  File "/usr/bin/show", line 9, in <module>
    load_entry_point('sonic-utilities==1.2', 'console_scripts', 'show')()
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/show/main.py", line 1233, in brief
    ip_address = ','.replace(',', '\n').join(vlan_ip_dict[key])
KeyError: '1000'
root@sonic:/home/user#
```
<!--
Briefly describe the problem you are having in a few paragraphs.
-->

**Steps to reproduce the issue**
1. `config vlan add 1000`
2. `config vlan member add 1000 Ethernet0`
3. `show vlan brief`

**Describe the results you received**
```
root@sonic:/home/user# show vlan brief
Traceback (most recent call last):
  File "/usr/bin/show", line 9, in <module>
    load_entry_point('sonic-utilities==1.2', 'console_scripts', 'show')()
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/show/main.py", line 1233, in brief
    ip_address = ','.replace(',', '\n').join(vlan_ip_dict[key])
KeyError: '1000'
root@sonic:/home/user#
```

**Describe the results you expected**
```
root@sonic:/home/user# show vlan brief
+-----------+--------------+------------+-----------------------+
|   VLAN ID | IP Address   | Ports      | DHCP Helper Address   |
+===========+==============+============+=======================+
|      1000 |              | Ethernet0  |                       |
+-----------+--------------+------------+-----------------------+
|      1001 |              | Ethernet4  |                       |
+-----------+--------------+------------+-----------------------+
|      1002 |              | Ethernet8  |                       |
+-----------+--------------+------------+-----------------------+
|      1003 |              | Ethernet12 |                       |
+-----------+--------------+------------+-----------------------+
|      2000 |              | Ethernet0  |                       |
+-----------+--------------+------------+-----------------------+
|      2001 |              | Ethernet4  |                       |
+-----------+--------------+------------+-----------------------+
|      2002 |              | Ethernet8  |                       |
+-----------+--------------+------------+-----------------------+
|      2003 |              | Ethernet12 |                       |
+-----------+--------------+------------+-----------------------+
root@sonic:/home/user# 
```


**Output of `show version`**

```
root@sonic:/home/user# show version
SONiC Software Version: SONiC.master.0-dirty-20181018.210426
Distribution: Debian 9.5
Kernel: 4.9.0-7-amd64
Build commit: 891e256
Build date: Fri Oct 19 08:26:58 UTC 2018
Built by: stegen@hobbes

Docker images:
REPOSITORY                 TAG                              IMAGE ID            SIZE
docker-syncd-brcm          latest                           c7b6fe2ab8ed        336.6 MB
docker-syncd-brcm          master.0-dirty-20181018.210426   c7b6fe2ab8ed        336.6 MB
docker-orchagent-brcm      latest                           d7b79d338dbf        259.8 MB
docker-orchagent-brcm      master.0-dirty-20181018.210426   d7b79d338dbf        259.8 MB
docker-dhcp-relay          latest                           46311aedb64c        253.8 MB
docker-dhcp-relay          master.0-dirty-20181018.210426   46311aedb64c        253.8 MB
docker-database            latest                           7ef183223900        252.5 MB
docker-database            master.0-dirty-20181018.210426   7ef183223900        252.5 MB
docker-teamd               latest                           54593d4350da        257.8 MB
docker-teamd               master.0-dirty-20181018.210426   54593d4350da        257.8 MB
docker-snmp-sv2            latest                           4f369da7559e        291.3 MB
docker-snmp-sv2            master.0-dirty-20181018.210426   4f369da7559e        291.3 MB
docker-router-advertiser   latest                           7a777bafa37a        250.1 MB
docker-router-advertiser   master.0-dirty-20181018.210426   7a777bafa37a        250.1 MB
docker-platform-monitor    latest                           2d6cf7bad3c3        283.6 MB
docker-platform-monitor    master.0-dirty-20181018.210426   2d6cf7bad3c3        283.6 MB
docker-lldp-sv2            latest                           1ba582fc6e5e        271.2 MB
docker-lldp-sv2            master.0-dirty-20181018.210426   1ba582fc6e5e        271.2 MB
docker-fpm-frr             latest                           a98f1f09de10        264.4 MB
docker-fpm-frr             master.0-dirty-20181018.210426   a98f1f09de10        264.4 MB

root@sonic:/home/user# 
```



Discussion:

Resolving patch:
diff --git a/show/main.py b/show/main.py
--- a/show/main.py
+++ b/show/main.py
@@ -1232,8 +1232,14 @@ def brief(verbose):
     # vlan_dhcp_helper_dict={}, vlan_ip_dict = {}, vlan_ports_dict = {}
     for key in natsorted(vlan_dhcp_helper_dict.keys()):
         dhcp_helpers = ','.replace(',', '\n').join(vlan_dhcp_helper_dict[key])
-        ip_address = ','.replace(',', '\n').join(vlan_ip_dict[key])
-        vlan_ports = ','.replace(',', '\n').join((vlan_ports_dict[key]))
+        if key not in vlan_ip_dict:
+            ip_address = ""
+        else:
+            ip_address = ','.replace(',', '\n').join(vlan_ip_dict[key])
+        if key not in vlan_ports_dict:
+            vlan_ports = ""
+        else:
+            vlan_ports = ','.replace(',', '\n').join((vlan_ports_dict[key]))
         body.append([key, ip_address, vlan_ports, dhcp_helpers])
     click.echo(tabulate(body, header, tablefmt="grid"))
 


Test patch: