Skip to content

Commit

Permalink
[docker-database] Fix Python3 issue (#7700)
Browse files Browse the repository at this point in the history
#### Why I did it
To avoid the following error
```
Traceback (most recent call last):
  File "/usr/local/bin/flush_unused_database", line 10, in <module>
    if 'PONG' in output:
TypeError: a bytes-like object is required, not 'str'
```
`communicate` method returns the strings if streams were opened in text mode; otherwise, bytes.
In our case text arg  in Popen is not true and that means that `communicate` return the bytes
#### How I did it
Set `text=True` to get strings instead of bytes
#### How to verify it
run `/usr/local/bin/flush_unused_database` inside database container
  • Loading branch information
msosyak committed May 31, 2021
1 parent 3bb1239 commit 3bf60b3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dockers/docker-database/flush_unused_database
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import subprocess
import time

while(True):
output = subprocess.Popen(['sonic-db-cli', 'PING'], stdout=subprocess.PIPE).communicate()[0]
output = subprocess.Popen(['sonic-db-cli', 'PING'], stdout=subprocess.PIPE, text=True).communicate()[0]
if 'PONG' in output:
break
time.sleep(1)
Expand Down

0 comments on commit 3bf60b3

Please sign in to comment.