1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# Copyright (C) 2015-2016 Red Hat, Inc. <http://www.redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from glusto.core import Glusto as g
from glustolibs.gluster.brick_libs import get_all_bricks
from glustolibs.gluster.exceptions import ExecutionError
from glustolibs.gluster.gluster_base_class import GlusterBaseClass, runs_on
from glustolibs.misc.misc_libs import upload_scripts
from glustolibs.gluster.glusterfile import get_file_stat
@runs_on([['replicated'],
['glusterfs']])
class AfrReadlinkTest(GlusterBaseClass):
"""
Description:
Test Case which tests the working of FOPS in AFR.
"""
@classmethod
def setUpClass(cls):
# Calling GlusterBaseClass setUpClass
cls.get_super_method(cls, 'setUpClass')()
# Override replica count to be 3
if cls.volume_type == "replicated":
cls.volume['voltype'] = {
'type': 'replicated',
'replica_count': 3,
'transport': 'tcp'}
# Upload io scripts for running IO on mounts
g.log.info("Upload io scripts to clients %s for running IO on "
"mounts", cls.clients)
script_abs_path = "/usr/share/glustolibs/io/scripts/file_dir_ops.py"
cls.script_upload_path = ("/usr/share/glustolibs/io/scripts/"
"file_dir_ops.py")
ret = upload_scripts(cls.clients, script_abs_path)
if not ret:
raise ExecutionError("Failed to upload IO scripts to clients")
def setUp(self):
# Calling GlusterBaseClass setUp
self.get_super_method(self, 'setUp')()
# Setup Volume and Mount Volume
g.log.info("Starting to Setup Volume and Mount Volume")
ret = self.setup_volume_and_mount_volume(mounts=self.mounts,
volume_create_force=False)
if not ret:
raise ExecutionError("Failed to Setup_Volume and Mount_Volume")
g.log.info("Successful in Setup Volume and Mount Volume")
self.bricks_list = get_all_bricks(self.mnode, self.volname)
self.assertIsNotNone(self.bricks_list, "unable to get list of bricks")
def tearDown(self):
# Cleanup and umount volume
g.log.info("Starting to Unmount Volume and Cleanup Volume")
ret = self.unmount_volume_and_cleanup_volume(mounts=self.mounts)
if not ret:
raise ExecutionError("Failed to umount the vol & cleanup Volume")
g.log.info("Successful in umounting the volume and Cleanup")
# Calling GlusterBaseClass teardown
self.get_super_method(self, 'tearDown')()
def test_readlink(self):
# create file
g.log.info("Creating %s/file.txt", self.mounts[0].mountpoint)
cmd = ("echo 'hello_world' > %s/file.txt" % self.mounts[0].mountpoint)
ret, _, _ = g.run(self.clients[0], cmd)
self.assertEqual(ret, 0, "File creation failed")
g.log.info("Created %s/file.txt", self.mounts[0].mountpoint)
# create symlink
g.log.info("Creating %s/symlink.txt to %s/file.txt",
self.mounts[0].mountpoint, self.mounts[0].mountpoint)
cmd = ("ln -s file.txt %s/symlink.txt" % self.mounts[0].mountpoint)
ret, _, _ = g.run(self.clients[0], cmd)
self.assertEqual(ret, 0, "symlink creation failed")
g.log.info("Created %s/symlink.txt to %s/file.txt",
self.mounts[0].mountpoint, self.mounts[0].mountpoint)
# stat symlink on mount and verify file type and permission.
g.log.info("Checking file permissions")
path = ("%s/symlink.txt" % self.mounts[0].mountpoint)
stat_dict = get_file_stat(self.clients[0], path)
self.assertEqual(stat_dict['filetype'], 'symbolic link', "Expected "
"symlink but found %s" % stat_dict['filetype'])
self.assertEqual(stat_dict['access'], '777', "Expected 777 "
"but found %s" % stat_dict['access'])
g.log.info("File permissions for symlink.txt is 777 as expected")
# readlink to verify contents
g.log.info("Performing readlink on %s/symlink.txt",
self.mounts[0].mountpoint)
cmd = ("readlink %s/symlink.txt" % self.mounts[0].mountpoint)
_, val, _ = g.run(self.clients[0], cmd)
content = val.strip()
self.assertEqual(content, "file.txt", "Readlink error:got %s"
% content)
g.log.info("readlink returned 'file.txt' as expected")
# stat symlink on bricks and verify file type and permission.
g.log.info("Checking file type and permissions on bricks")
for brick in self.bricks_list:
node, path = brick.split(':')
filepath = path + "/symlink.txt"
stat_dict = get_file_stat(node, filepath)
self.assertEqual(stat_dict['filetype'], 'symbolic link', "Expected"
" symlink but found %s" % stat_dict['filetype'])
g.log.info("file permission 777 for symlink.txt on %s", brick)
|