Repository: sonic-net/sonic-utilities

Issue:
[consutil] show/connect command failed due to global name 'ConfigDBConnector' is not defined
<!--
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**

<!--
Briefly describe the problem you are having in a few paragraphs.
-->

An unexpected error thrown while executing `sudo consutil show` or `sudo consutil connect` command.
```bash
NameError: global name 'ConfigDBConnector' is not defined
```

**Steps to reproduce the issue**
1. Install newest image of SONiC
2. Execute `sudo consutil show` or `sudo consutil connect 1`

**Describe the results you received**
Output:
```bash
admin@sonic:~$ sudo consutil show
Traceback (most recent call last):
  File "/usr/bin/consutil", line 12, in <module>
    sys.exit(consutil())
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/consutil/main.py", line 43, in show
    actBaud, confBaud, _ = getConnectionInfo(lineNum)
  File "/usr/lib/python2.7/dist-packages/consutil/lib.py", line 98, in getConnectionInfo
    config_db = ConfigDBConnector()
NameError: global name 'ConfigDBConnector' is not defined
admin@sonic:~$ 
admin@sonic:~$ 
admin@sonic:~$ sudo consutil connect 1
Traceback (most recent call last):
  File "/usr/bin/consutil", line 12, in <module>
    sys.exit(consutil())
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/consutil/main.py", line 79, in connect
    actBaud, _, flowBool = getConnectionInfo(lineNumber)
  File "/usr/lib/python2.7/dist-packages/consutil/lib.py", line 98, in getConnectionInfo
    config_db = ConfigDBConnector()
NameError: global name 'ConfigDBConnector' is not defined
```

**Describe the results you expected**
For `sudo consutil show`, a table with line number/baud/... should be displayed without any error.
For `sudo consutil connect`, a console session should be attached or friendly error message will display if the line is busy.

**Additional information you deem important (e.g. issue happens only occasionally)**
Similar error found in another PR/Issue, maybe current issue and that issue are relating to some recent change? https://github.com/Azure/sonic-utilities/pull/1114

**Output of `show version`**

```
admin@sonic:~$ show version

SONiC Software Version: SONiC.dev_jika_cli01.0-0b4191fe
Distribution: Debian 10.5
Kernel: 4.19.0-9-2-amd64
Build commit: 0b4191fe
Build date: Fri Sep 11 07:36:01 UTC 2020
Built by: jika@jika-vm-01

Platform: x86_64-cel_e1031-r0
HwSKU: Celestica-E1031-T48S4
ASIC: broadcom
Serial Number: R0882B2F160615GD000006
Uptime: 11:41:37 up  1:29,  1 user,  load average: 0.09, 0.67, 1.15

Docker images:
REPOSITORY                    TAG                         IMAGE ID            SIZE
docker-teamd                  dev_jika_cli01.0-0b4191fe   06a9488f9400        390MB
docker-teamd                  latest                      06a9488f9400        390MB
docker-nat                    dev_jika_cli01.0-0b4191fe   9adedebc9007        393MB
docker-nat                    latest                      9adedebc9007        393MB
docker-router-advertiser      dev_jika_cli01.0-0b4191fe   9bca9fa2d027        359MB
docker-router-advertiser      latest                      9bca9fa2d027        359MB
docker-platform-monitor       dev_jika_cli01.0-0b4191fe   11092e178476        433MB
docker-platform-monitor       latest                      11092e178476        433MB
docker-lldp                   dev_jika_cli01.0-0b4191fe   bdc853ee9542        387MB
docker-lldp                   latest                      bdc853ee9542        387MB
docker-dhcp-relay             dev_jika_cli01.0-0b4191fe   787384652391        366MB
docker-dhcp-relay             latest                      787384652391        366MB
docker-database               dev_jika_cli01.0-0b4191fe   08143a381945        359MB
docker-database               latest                      08143a381945        359MB
docker-orchagent              dev_jika_cli01.0-0b4191fe   78b74caafb9b        404MB
docker-orchagent              latest                      78b74caafb9b        404MB
docker-sonic-telemetry        dev_jika_cli01.0-0b4191fe   cd5e957ea52a        429MB
docker-sonic-telemetry        latest                      cd5e957ea52a        429MB
docker-sonic-mgmt-framework   dev_jika_cli01.0-0b4191fe   f91a73bd2111        486MB
docker-sonic-mgmt-framework   latest                      f91a73bd2111        486MB
docker-fpm-frr                dev_jika_cli01.0-0b4191fe   b7a0da93271f        406MB
docker-fpm-frr                latest                      b7a0da93271f        406MB
docker-sflow                  dev_jika_cli01.0-0b4191fe   60511099fae8        394MB
docker-sflow                  latest                      60511099fae8        394MB
docker-snmp                   dev_jika_cli01.0-0b4191fe   c3b585b7970f        399MB
docker-snmp                   latest                      c3b585b7970f        399MB
docker-syncd-brcm             dev_jika_cli01.0-0b4191fe   64ac8a8a6401        447MB
docker-syncd-brcm             latest                      64ac8a8a6401        447MB
```

<!--
Also attach debug file produced by `sudo generate_dump`
-->




Discussion:

Resolving patch:
diff --git a/consutil/lib.py b/consutil/lib.py
--- a/consutil/lib.py
+++ b/consutil/lib.py
@@ -10,6 +10,7 @@
     import re
     import subprocess
     import sys
+    from swsssdk import ConfigDBConnector
 except ImportError as e:
     raise ImportError("%s - required module not found" % str(e))
 


Test patch: