From 456b265412be956761c623f248bc86040be0ddf5 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 26 Dec 2019 11:23:47 +0200 Subject: Fix: handle mode/owner/group as integers in files plugin Also, refactor how defaults are handled, for clarity and terseness. --- vmdb/plugins/files_plugin.py | 57 +++++++------------------------------------- 1 file changed, 9 insertions(+), 48 deletions(-) diff --git a/vmdb/plugins/files_plugin.py b/vmdb/plugins/files_plugin.py index 40dc86c..772443c 100644 --- a/vmdb/plugins/files_plugin.py +++ b/vmdb/plugins/files_plugin.py @@ -37,25 +37,12 @@ class CreateFileStepRunner(vmdb.StepRunnerInterface): root = state.tags.get_mount_point('/') newfile = step['create-file'] contents = step['contents'] - perm = step.get('perm') - uid = step.get('uid') - gid = step.get('gid') + perm = step.get('perm', 0o644) + uid = step.get('uid', 0) + gid = step.get('gid', 0) filename = '/'.join([root,newfile]) - if perm: - perm = int(perm, 8) - else: - perm = 0o0644 - if uid: - uid = int(uid) - else: - uid = 0 - if gid: - gid = int(gid) - else: - gid = 0 - logging.info('Creating file %s, uid %d, gid %d, perms %o' % (filename, uid, gid, perm)) fd = open(filename, 'w') fd.write(contents) @@ -74,25 +61,12 @@ class CopyFileStepRunner(vmdb.StepRunnerInterface): root = state.tags.get_mount_point('/') newfile = step['copy-file'] src = step['src'] - perm = step.get('perm') - uid = step.get('uid') - gid = step.get('gid') + perm = step.get('perm', 0o644) + uid = step.get('uid', 0) + gid = step.get('gid', 0) filename = '/'.join([root,newfile]) - if perm: - perm = int(perm, 8) - else: - perm = 0o0644 - if uid: - uid = int(uid) - else: - uid = 0 - if gid: - gid = int(gid) - else: - gid = 0 - logging.info( 'Copying file %s to %s, uid %d, gid %d, perms %o' % ( src, filename, uid, gid, perm)) @@ -117,22 +91,9 @@ class CreateDirStepRunner(vmdb.StepRunnerInterface): root = state.tags.get_mount_point('/') newdir = step['create-dir'] path = '/'.join([root, newdir]) - perm = step.get('perm') - uid = step.get('uid') - gid = step.get('gid') - - if perm: - perm = int(perm, 8) - else: - perm = 0o0755 - if uid: - uid = int(uid) - else: - uid = 0 - if gid: - gid = int(gid) - else: - gid = 0 + perm = step.get('perm', 0o755) + uid = step.get('uid', 0) + gid = step.get('gid', 0) logging.info('Creating directory %s, uid %d, gid %d, perms %o' % (path, uid, gid, perm)) -- cgit v1.2.1