Merge "Set permissions on generated ring files"

This commit is contained in:
Jenkins 2014-04-09 20:55:04 +00:00 committed by Gerrit Code Review
commit 4721deeb40
2 changed files with 11 additions and 0 deletions

View File

@ -120,6 +120,7 @@ class RingData(object):
tempf.flush() tempf.flush()
os.fsync(tempf.fileno()) os.fsync(tempf.fileno())
tempf.close() tempf.close()
os.chmod(tempf.name, 0o644)
os.rename(tempf.name, filename) os.rename(tempf.name, filename)
def to_dict(self): def to_dict(self):

View File

@ -18,6 +18,7 @@ import cPickle as pickle
import os import os
import sys import sys
import unittest import unittest
import stat
from contextlib import closing from contextlib import closing
from gzip import GzipFile from gzip import GzipFile
from tempfile import mkdtemp from tempfile import mkdtemp
@ -98,6 +99,15 @@ class TestRingData(unittest.TestCase):
with open(ring_fname2) as ring2: with open(ring_fname2) as ring2:
self.assertEqual(ring1.read(), ring2.read()) self.assertEqual(ring1.read(), ring2.read())
def test_permissions(self):
ring_fname = os.path.join(self.testdir, 'stat.ring.gz')
rd = ring.RingData(
[array.array('H', [0, 1, 0, 1]), array.array('H', [0, 1, 0, 1])],
[{'id': 0, 'zone': 0}, {'id': 1, 'zone': 1}], 30)
rd.save(ring_fname)
self.assertEqual(oct(stat.S_IMODE(os.stat(ring_fname).st_mode)),
'0644')
class TestRing(unittest.TestCase): class TestRing(unittest.TestCase):