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