Fix file modes to be Python 2/3 compatible.
This commit is contained in:
parent
65f89fb1b5
commit
239519a75d
@ -1,3 +1,4 @@
|
|||||||
.tox
|
.tox
|
||||||
dist
|
dist
|
||||||
cloud_init.egg-info
|
cloud_init.egg-info
|
||||||
|
__pycache__
|
||||||
|
@ -272,7 +272,7 @@ class Distro(object):
|
|||||||
if header:
|
if header:
|
||||||
contents.write("%s\n" % (header))
|
contents.write("%s\n" % (header))
|
||||||
contents.write("%s\n" % (eh))
|
contents.write("%s\n" % (eh))
|
||||||
util.write_file(self.hosts_fn, contents.getvalue(), mode=0644)
|
util.write_file(self.hosts_fn, contents.getvalue(), mode=0o644)
|
||||||
|
|
||||||
def _bring_up_interface(self, device_name):
|
def _bring_up_interface(self, device_name):
|
||||||
cmd = ['ifup', device_name]
|
cmd = ['ifup', device_name]
|
||||||
|
@ -1250,7 +1250,7 @@ def rename(src, dest):
|
|||||||
os.rename(src, dest)
|
os.rename(src, dest)
|
||||||
|
|
||||||
|
|
||||||
def ensure_dirs(dirlist, mode=0755):
|
def ensure_dirs(dirlist, mode=0o755):
|
||||||
for d in dirlist:
|
for d in dirlist:
|
||||||
ensure_dir(d, mode)
|
ensure_dir(d, mode)
|
||||||
|
|
||||||
@ -1264,7 +1264,7 @@ def read_write_cmdline_url(target_fn):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
if key and content:
|
if key and content:
|
||||||
write_file(target_fn, content, mode=0600)
|
write_file(target_fn, content, mode=0o600)
|
||||||
LOG.debug(("Wrote to %s with contents of command line"
|
LOG.debug(("Wrote to %s with contents of command line"
|
||||||
" url %s (len=%s)"), target_fn, url, len(content))
|
" url %s (len=%s)"), target_fn, url, len(content))
|
||||||
elif key and not content:
|
elif key and not content:
|
||||||
@ -1489,7 +1489,7 @@ def append_file(path, content):
|
|||||||
write_file(path, content, omode="ab", mode=None)
|
write_file(path, content, omode="ab", mode=None)
|
||||||
|
|
||||||
|
|
||||||
def ensure_file(path, mode=0644):
|
def ensure_file(path, mode=0o644):
|
||||||
write_file(path, content='', omode="ab", mode=mode)
|
write_file(path, content='', omode="ab", mode=mode)
|
||||||
|
|
||||||
|
|
||||||
@ -1507,7 +1507,7 @@ def chmod(path, mode):
|
|||||||
os.chmod(path, real_mode)
|
os.chmod(path, real_mode)
|
||||||
|
|
||||||
|
|
||||||
def write_file(filename, content, mode=0644, omode="wb"):
|
def write_file(filename, content, mode=0o644, omode="wb"):
|
||||||
"""
|
"""
|
||||||
Writes a file with the given content and sets the file mode as specified.
|
Writes a file with the given content and sets the file mode as specified.
|
||||||
Resotres the SELinux context if possible.
|
Resotres the SELinux context if possible.
|
||||||
|
@ -48,7 +48,7 @@ class TestWalkerHandleHandler(MockerTestCase):
|
|||||||
# Mock the write_file function
|
# Mock the write_file function
|
||||||
write_file_mock = self.mocker.replace(util.write_file,
|
write_file_mock = self.mocker.replace(util.write_file,
|
||||||
passthrough=False)
|
passthrough=False)
|
||||||
write_file_mock(expected_file_fullname, self.payload, 0600)
|
write_file_mock(expected_file_fullname, self.payload, 0o600)
|
||||||
|
|
||||||
def test_no_errors(self):
|
def test_no_errors(self):
|
||||||
"""Payload gets written to file and added to C{pdata}."""
|
"""Payload gets written to file and added to C{pdata}."""
|
||||||
|
@ -337,7 +337,7 @@ p: 1
|
|||||||
|
|
||||||
mock_write = self.mocker.replace("cloudinit.util.write_file",
|
mock_write = self.mocker.replace("cloudinit.util.write_file",
|
||||||
passthrough=False)
|
passthrough=False)
|
||||||
mock_write(ci.paths.get_ipath("cloud_config"), "", 0600)
|
mock_write(ci.paths.get_ipath("cloud_config"), "", 0o600)
|
||||||
self.mocker.replay()
|
self.mocker.replay()
|
||||||
|
|
||||||
log_file = self.capture_log(logging.WARNING)
|
log_file = self.capture_log(logging.WARNING)
|
||||||
|
@ -45,7 +45,7 @@ def _write_cloud_info_file(value):
|
|||||||
cifile = open(cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE, 'w')
|
cifile = open(cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE, 'w')
|
||||||
cifile.write(value)
|
cifile.write(value)
|
||||||
cifile.close()
|
cifile.close()
|
||||||
os.chmod(cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE, 0664)
|
os.chmod(cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE, 0o664)
|
||||||
|
|
||||||
|
|
||||||
def _remove_cloud_info_file():
|
def _remove_cloud_info_file():
|
||||||
|
@ -153,7 +153,7 @@ class TestAzureDataSource(MockerTestCase):
|
|||||||
ret = dsrc.get_data()
|
ret = dsrc.get_data()
|
||||||
self.assertTrue(ret)
|
self.assertTrue(ret)
|
||||||
self.assertTrue(os.path.isdir(self.waagent_d))
|
self.assertTrue(os.path.isdir(self.waagent_d))
|
||||||
self.assertEqual(stat.S_IMODE(os.stat(self.waagent_d).st_mode), 0700)
|
self.assertEqual(stat.S_IMODE(os.stat(self.waagent_d).st_mode), 0o700)
|
||||||
|
|
||||||
def test_user_cfg_set_agent_command_plain(self):
|
def test_user_cfg_set_agent_command_plain(self):
|
||||||
# set dscfg in via plaintext
|
# set dscfg in via plaintext
|
||||||
|
@ -96,7 +96,7 @@ class TestNetCfgDistro(MockerTestCase):
|
|||||||
|
|
||||||
write_bufs = {}
|
write_bufs = {}
|
||||||
|
|
||||||
def replace_write(filename, content, mode=0644, omode="wb"):
|
def replace_write(filename, content, mode=0o644, omode="wb"):
|
||||||
buf = WriteBuffer()
|
buf = WriteBuffer()
|
||||||
buf.mode = mode
|
buf.mode = mode
|
||||||
buf.omode = omode
|
buf.omode = omode
|
||||||
|
@ -150,7 +150,7 @@ class TestAddCaCerts(MockerTestCase):
|
|||||||
mock_load = self.mocker.replace(util.load_file, passthrough=False)
|
mock_load = self.mocker.replace(util.load_file, passthrough=False)
|
||||||
|
|
||||||
mock_write("/usr/share/ca-certificates/cloud-init-ca-certs.crt",
|
mock_write("/usr/share/ca-certificates/cloud-init-ca-certs.crt",
|
||||||
cert, mode=0644)
|
cert, mode=0o644)
|
||||||
|
|
||||||
mock_load("/etc/ca-certificates.conf")
|
mock_load("/etc/ca-certificates.conf")
|
||||||
self.mocker.result(ca_certs_content)
|
self.mocker.result(ca_certs_content)
|
||||||
|
@ -145,7 +145,7 @@ class TestResize(MockerTestCase):
|
|||||||
# this patches out devent2dev, os.stat, and device_part_info
|
# this patches out devent2dev, os.stat, and device_part_info
|
||||||
# so in the end, doesn't test a lot
|
# so in the end, doesn't test a lot
|
||||||
devs = ["/dev/XXda1", "/dev/YYda2"]
|
devs = ["/dev/XXda1", "/dev/YYda2"]
|
||||||
devstat_ret = Bunch(st_mode=25008, st_ino=6078, st_dev=5L,
|
devstat_ret = Bunch(st_mode=25008, st_ino=6078, st_dev=5,
|
||||||
st_nlink=1, st_uid=0, st_gid=6, st_size=0,
|
st_nlink=1, st_uid=0, st_gid=6, st_size=0,
|
||||||
st_atime=0, st_mtime=0, st_ctime=0)
|
st_atime=0, st_mtime=0, st_ctime=0)
|
||||||
enoent = ["/dev/NOENT"]
|
enoent = ["/dev/NOENT"]
|
||||||
|
@ -41,7 +41,7 @@ class TestSimpleRun(helpers.FilesystemMockingTestCase):
|
|||||||
{
|
{
|
||||||
'path': '/etc/blah.ini',
|
'path': '/etc/blah.ini',
|
||||||
'content': 'blah',
|
'content': 'blah',
|
||||||
'permissions': 0755,
|
'permissions': 0o755,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
'cloud_init_modules': ['write-files'],
|
'cloud_init_modules': ['write-files'],
|
||||||
|
@ -79,7 +79,7 @@ class TestWriteFile(MockerTestCase):
|
|||||||
create_contents = f.read()
|
create_contents = f.read()
|
||||||
self.assertEqual(contents, create_contents)
|
self.assertEqual(contents, create_contents)
|
||||||
file_stat = os.stat(path)
|
file_stat = os.stat(path)
|
||||||
self.assertEqual(0644, stat.S_IMODE(file_stat.st_mode))
|
self.assertEqual(0o644, stat.S_IMODE(file_stat.st_mode))
|
||||||
|
|
||||||
def test_dir_is_created_if_required(self):
|
def test_dir_is_created_if_required(self):
|
||||||
"""Verifiy that directories are created is required."""
|
"""Verifiy that directories are created is required."""
|
||||||
@ -97,12 +97,12 @@ class TestWriteFile(MockerTestCase):
|
|||||||
path = os.path.join(self.tmp, "NewFile.txt")
|
path = os.path.join(self.tmp, "NewFile.txt")
|
||||||
contents = "Hey there"
|
contents = "Hey there"
|
||||||
|
|
||||||
util.write_file(path, contents, mode=0666)
|
util.write_file(path, contents, mode=0o666)
|
||||||
|
|
||||||
self.assertTrue(os.path.exists(path))
|
self.assertTrue(os.path.exists(path))
|
||||||
self.assertTrue(os.path.isfile(path))
|
self.assertTrue(os.path.isfile(path))
|
||||||
file_stat = os.stat(path)
|
file_stat = os.stat(path)
|
||||||
self.assertEqual(0666, stat.S_IMODE(file_stat.st_mode))
|
self.assertEqual(0o666, stat.S_IMODE(file_stat.st_mode))
|
||||||
|
|
||||||
def test_custom_omode(self):
|
def test_custom_omode(self):
|
||||||
"""Verify custom omode works properly."""
|
"""Verify custom omode works properly."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user