1df6c8
From 04b824ebfcf80c648d5855f10bc30fde45fd62eb Mon Sep 17 00:00:00 2001
1df6c8
From: Sunny Kumar <sunkumar@redhat.com>
1df6c8
Date: Thu, 26 Mar 2020 10:46:16 +0000
1df6c8
Subject: [PATCH 361/362] snap_scheduler: python3 compatibility and new test
1df6c8
 case
1df6c8
MIME-Version: 1.0
1df6c8
Content-Type: text/plain; charset=UTF-8
1df6c8
Content-Transfer-Encoding: 8bit
1df6c8
1df6c8
Problem:
1df6c8
"snap_scheduler.py init" command failing with the below traceback:
1df6c8
1df6c8
[root@dhcp43-104 ~]# snap_scheduler.py init
1df6c8
Traceback (most recent call last):
1df6c8
  File "/usr/sbin/snap_scheduler.py", line 941, in <module>
1df6c8
    sys.exit(main(sys.argv[1:]))
1df6c8
  File "/usr/sbin/snap_scheduler.py", line 851, in main
1df6c8
    initLogger()
1df6c8
  File "/usr/sbin/snap_scheduler.py", line 153, in initLogger
1df6c8
    logfile = os.path.join(process.stdout.read()[:-1], SCRIPT_NAME + ".log")
1df6c8
  File "/usr/lib64/python3.6/posixpath.py", line 94, in join
1df6c8
    genericpath._check_arg_types('join', a, *p)
1df6c8
  File "/usr/lib64/python3.6/genericpath.py", line 151, in _check_arg_types
1df6c8
    raise TypeError("Can't mix strings and bytes in path components") from None
1df6c8
TypeError: Can't mix strings and bytes in path components
1df6c8
1df6c8
Solution:
1df6c8
1df6c8
Added the 'universal_newlines' flag to Popen to support backward compatibility.
1df6c8
1df6c8
Added a basic test for snapshot scheduler.
1df6c8
1df6c8
Backport Of:
1df6c8
   
1df6c8
        >Upstream Patch: https://review.gluster.org/#/c/glusterfs/+/24257/
1df6c8
        >Change-Id: I78e8fabd866fd96638747ecd21d292f5ca074a4e
1df6c8
        >Fixes: #1134
1df6c8
        >Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
1df6c8
   
1df6c8
BUG: 1817369
1df6c8
Change-Id: I78e8fabd866fd96638747ecd21d292f5ca074a4e
1df6c8
Signed-off-by: Sunny Kumar <sunkumar@redhat.com>
1df6c8
Reviewed-on: https://code.engineering.redhat.com/gerrit/196482
1df6c8
Tested-by: RHGS Build Bot <nigelb@redhat.com>
1df6c8
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
1df6c8
---
1df6c8
 extras/snap_scheduler/snap_scheduler.py |  2 +-
1df6c8
 tests/basic/volume-snap-scheduler.t     | 49 +++++++++++++++++++++++++++++++++
1df6c8
 2 files changed, 50 insertions(+), 1 deletion(-)
1df6c8
 create mode 100644 tests/basic/volume-snap-scheduler.t
1df6c8
1df6c8
diff --git a/extras/snap_scheduler/snap_scheduler.py b/extras/snap_scheduler/snap_scheduler.py
1df6c8
index a66c5e3..5a29d41 100755
1df6c8
--- a/extras/snap_scheduler/snap_scheduler.py
1df6c8
+++ b/extras/snap_scheduler/snap_scheduler.py
1df6c8
@@ -149,7 +149,7 @@ def initLogger():
1df6c8
     sh.setFormatter(formatter)
1df6c8
 
1df6c8
     process = subprocess.Popen(["gluster", "--print-logdir"],
1df6c8
-                               stdout=subprocess.PIPE)
1df6c8
+                               stdout=subprocess.PIPE, universal_newlines=True)
1df6c8
     logfile = os.path.join(process.stdout.read()[:-1], SCRIPT_NAME + ".log")
1df6c8
 
1df6c8
     fh = logging.FileHandler(logfile)
1df6c8
diff --git a/tests/basic/volume-snap-scheduler.t b/tests/basic/volume-snap-scheduler.t
1df6c8
new file mode 100644
1df6c8
index 0000000..a638c5c
1df6c8
--- /dev/null
1df6c8
+++ b/tests/basic/volume-snap-scheduler.t
1df6c8
@@ -0,0 +1,49 @@
1df6c8
+#!/bin/bash
1df6c8
+
1df6c8
+. $(dirname $0)/../include.rc
1df6c8
+. $(dirname $0)/../volume.rc
1df6c8
+
1df6c8
+cleanup;
1df6c8
+
1df6c8
+TEST glusterd;
1df6c8
+TEST pidof glusterd;
1df6c8
+
1df6c8
+TEST $CLI volume create $V0 replica 2 $H0:$B0/${GMV0}{1,2,3,4};
1df6c8
+TEST $CLI volume start $V0
1df6c8
+
1df6c8
+## Create, start and mount meta_volume as
1df6c8
+## snap_scheduler expects shared storage to be enabled.
1df6c8
+## This test is very basic in nature not creating any snapshot
1df6c8
+## and purpose is to validate snap scheduling commands.
1df6c8
+
1df6c8
+TEST $CLI volume create $META_VOL replica 3 $H0:$B0/${META_VOL}{1,2,3};
1df6c8
+TEST $CLI volume start $META_VOL
1df6c8
+TEST mkdir -p $META_MNT
1df6c8
+TEST glusterfs -s $H0 --volfile-id $META_VOL $META_MNT
1df6c8
+
1df6c8
+##function to check status
1df6c8
+function check_status_scheduler()
1df6c8
+{
1df6c8
+     local key=$1
1df6c8
+     snap_scheduler.py status | grep -F "$key" | wc -l
1df6c8
+}
1df6c8
+
1df6c8
+##Basic snap_scheduler command test init/enable/disable/list
1df6c8
+
1df6c8
+TEST snap_scheduler.py init
1df6c8
+
1df6c8
+TEST snap_scheduler.py enable
1df6c8
+
1df6c8
+EXPECT 1 check_status_scheduler "Enabled"
1df6c8
+
1df6c8
+TEST snap_scheduler.py disable
1df6c8
+
1df6c8
+EXPECT 1 check_status_scheduler "Disabled"
1df6c8
+
1df6c8
+TEST snap_scheduler.py list
1df6c8
+
1df6c8
+TEST $CLI volume stop $V0;
1df6c8
+
1df6c8
+TEST $CLI volume delete $V0;
1df6c8
+
1df6c8
+cleanup;
1df6c8
-- 
1df6c8
1.8.3.1
1df6c8