From 3bf60b3db2c9f472729f082b957e3ac4ef07e1bb Mon Sep 17 00:00:00 2001 From: Myron Sosyak <49795530+msosyak@users.noreply.github.com> Date: Mon, 31 May 2021 15:36:24 +0300 Subject: [PATCH] [docker-database] Fix Python3 issue (#7700) #### Why I did it To avoid the following error ``` Traceback (most recent call last): File "/usr/local/bin/flush_unused_database", line 10, in 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 --- dockers/docker-database/flush_unused_database | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockers/docker-database/flush_unused_database b/dockers/docker-database/flush_unused_database index e253bc2a4c5d..b1d4af063860 100755 --- a/dockers/docker-database/flush_unused_database +++ b/dockers/docker-database/flush_unused_database @@ -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)