Bulk copy files to /etc/cinder

This commit is contained in:
Corey Bryant 2015-04-13 17:42:38 +00:00
parent d33070988d
commit 01538b5b43
2 changed files with 14 additions and 48 deletions

View File

@ -1,6 +1,4 @@
import grp
import os import os
import pwd
import shutil import shutil
import subprocess import subprocess
@ -518,17 +516,7 @@ def git_install(projects_yaml):
def git_pre_install(): def git_pre_install():
"""Perform cinder pre-install setup.""" """Perform cinder pre-install setup."""
dirs = [{'path': '/etc/cinder', dirs = [{'path': '/etc/tgt',
'owner': 'cinder',
'group': 'cinder',
'perms': 0750,
},
{'path': '/etc/cinder/rootwrap.d',
'owner': 'root',
'group': 'root',
'perms': 0755,
},
{'path': '/etc/tgt',
'owner': 'cinder', 'owner': 'cinder',
'group': 'cinder', 'group': 'cinder',
'perms': 0750, 'perms': 0750,
@ -577,31 +565,13 @@ def git_post_install(projects_yaml):
"""Perform cinder post-install setup.""" """Perform cinder post-install setup."""
src_etc = os.path.join(git_src_dir(projects_yaml, 'cinder'), 'etc/cinder') src_etc = os.path.join(git_src_dir(projects_yaml, 'cinder'), 'etc/cinder')
configs = { configs = {
'api-paste': { 'src': src_etc,
'src': os.path.join(src_etc, 'api-paste.ini'), 'dest': '/etc/cinder',
'dest': '/etc/cinder/api-paste.ini',
},
'policy': {
'src': os.path.join(src_etc, 'policy.json'),
'dest': '/etc/cinder/policy.json',
},
'rootwrap': {
'src': os.path.join(src_etc, 'rootwrap.conf'),
'dest': '/etc/cinder/rootwrap.conf',
},
'filters': {
'src': os.path.join(src_etc, 'rootwrap.d/volume.filters'),
'dest': '/etc/cinder/rootwrap.d/volume.filters',
},
} }
for conf, files in configs.iteritems(): if os.path.exists(configs['dest']):
shutil.copyfile(files['src'], files['dest']) shutil.rmtree(configs['dest'])
shutil.copytree(configs['src'], configs['dest'])
uid = pwd.getpwnam('cinder').pw_uid
gid = grp.getgrnam('cinder').gr_gid
os.chown('/etc/cinder/api-paste.ini', uid, gid)
os.chown('/etc/cinder/policy.json', uid, gid)
render('cinder.conf', '/etc/cinder/cinder.conf', {}, owner='cinder', render('cinder.conf', '/etc/cinder/cinder.conf', {}, owner='cinder',
group='cinder', perms=0o644) group='cinder', perms=0o644)
@ -613,7 +583,6 @@ def git_post_install(projects_yaml):
owner='root', group='root', perms=0o440) owner='root', group='root', perms=0o440)
os.chmod('/etc/sudoers.d', 0o750) os.chmod('/etc/sudoers.d', 0o750)
os.chmod('/etc/cinder', 0o750)
cinder_api_context = { cinder_api_context = {
'service_description': 'Cinder API server', 'service_description': 'Cinder API server',

View File

@ -545,10 +545,6 @@ class TestCinderUtils(CharmTestCase):
add_group.assert_called_with('cinder', system_group=True) add_group.assert_called_with('cinder', system_group=True)
add_user_to_group.assert_called_with('cinder', 'cinder') add_user_to_group.assert_called_with('cinder', 'cinder')
expected = [ expected = [
call('/etc/cinder', owner='cinder', perms=488, force=False,
group='cinder'),
call('/etc/cinder/rootwrap.d', owner='root', perms=493,
force=False, group='root'),
call('/etc/tgt', owner='cinder', perms=488, force=False, call('/etc/tgt', owner='cinder', perms=488, force=False,
group='cinder'), group='cinder'),
call('/var/lib/cinder', owner='cinder', perms=493, force=False, call('/var/lib/cinder', owner='cinder', perms=493, force=False,
@ -577,22 +573,23 @@ class TestCinderUtils(CharmTestCase):
@patch.object(cinder_utils, 'service_restart') @patch.object(cinder_utils, 'service_restart')
@patch.object(cinder_utils, 'render') @patch.object(cinder_utils, 'render')
@patch('os.path.join') @patch('os.path.join')
@patch('shutil.copyfile') @patch('os.path.exists')
@patch('shutil.copytree')
@patch('shutil.rmtree')
@patch('pwd.getpwnam') @patch('pwd.getpwnam')
@patch('grp.getgrnam') @patch('grp.getgrnam')
@patch('os.chown') @patch('os.chown')
@patch('os.chmod') @patch('os.chmod')
def test_git_post_install(self, chmod, chown, grp, pwd, copyfile, join, def test_git_post_install(self, chmod, chown, grp, pwd, rmtree, copytree,
render, service_restart, git_src_dir): exists, join, render, service_restart,
git_src_dir):
projects_yaml = openstack_origin_git projects_yaml = openstack_origin_git
join.return_value = 'joined-string' join.return_value = 'joined-string'
cinder_utils.git_post_install(projects_yaml) cinder_utils.git_post_install(projects_yaml)
expected = [ expected = [
call('joined-string', '/etc/cinder/policy.json'), call('joined-string', '/etc/cinder'),
call('joined-string', '/etc/cinder/rootwrap.conf'),
call('joined-string', '/etc/cinder/rootwrap.d/volume.filters'),
] ]
copyfile.assert_has_calls(expected, any_order=True) copytree.assert_has_calls(expected)
cinder_api_context = { cinder_api_context = {
'service_description': 'Cinder API server', 'service_description': 'Cinder API server',