Revision 10b86782 test/ganeti.utils.wrapper_unittest.py
b/test/ganeti.utils.wrapper_unittest.py | ||
---|---|---|
27 | 27 |
import socket |
28 | 28 |
import tempfile |
29 | 29 |
import unittest |
30 |
import shutil |
|
30 | 31 |
|
31 | 32 |
from ganeti import constants |
32 | 33 |
from ganeti import utils |
... | ... | |
122 | 123 |
self.assertEquals(utils.IgnoreSignals(self._Return, 33), 33) |
123 | 124 |
|
124 | 125 |
|
126 |
class TestIsExecutable(unittest.TestCase): |
|
127 |
def setUp(self): |
|
128 |
self.tmpdir = tempfile.mkdtemp() |
|
129 |
|
|
130 |
def tearDown(self): |
|
131 |
shutil.rmtree(self.tmpdir) |
|
132 |
|
|
133 |
def testNonExisting(self): |
|
134 |
fname = utils.PathJoin(self.tmpdir, "file") |
|
135 |
assert not os.path.exists(fname) |
|
136 |
self.assertFalse(utils.IsExecutable(fname)) |
|
137 |
|
|
138 |
def testNoFile(self): |
|
139 |
path = utils.PathJoin(self.tmpdir, "something") |
|
140 |
os.mkdir(path) |
|
141 |
assert os.path.isdir(path) |
|
142 |
self.assertFalse(utils.IsExecutable(path)) |
|
143 |
|
|
144 |
def testExecutable(self): |
|
145 |
fname = utils.PathJoin(self.tmpdir, "file") |
|
146 |
utils.WriteFile(fname, data="#!/bin/bash", mode=0700) |
|
147 |
assert os.path.exists(fname) |
|
148 |
self.assertTrue(utils.IsExecutable(fname)) |
|
149 |
|
|
150 |
self.assertTrue(self._TestSymlink(fname)) |
|
151 |
|
|
152 |
def testFileNotExecutable(self): |
|
153 |
fname = utils.PathJoin(self.tmpdir, "file") |
|
154 |
utils.WriteFile(fname, data="#!/bin/bash", mode=0600) |
|
155 |
assert os.path.exists(fname) |
|
156 |
self.assertFalse(utils.IsExecutable(fname)) |
|
157 |
|
|
158 |
self.assertFalse(self._TestSymlink(fname)) |
|
159 |
|
|
160 |
def _TestSymlink(self, fname): |
|
161 |
assert os.path.exists(fname) |
|
162 |
|
|
163 |
linkname = utils.PathJoin(self.tmpdir, "cmd") |
|
164 |
os.symlink(fname, linkname) |
|
165 |
|
|
166 |
assert os.path.islink(linkname) |
|
167 |
|
|
168 |
return utils.IsExecutable(linkname) |
|
169 |
|
|
170 |
|
|
125 | 171 |
if __name__ == "__main__": |
126 | 172 |
testutils.GanetiTestProgram() |
Also available in: Unified diff