本文整理汇总了Python中ovs.extensions.generic.sshclient.SSHClient.file_chmod方法的典型用法代码示例。如果您正苦于以下问题:Python SSHClient.file_chmod方法的具体用法?Python SSHClient.file_chmod怎么用?Python SSHClient.file_chmod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.extensions.generic.sshclient.SSHClient
的用法示例。
在下文中一共展示了SSHClient.file_chmod方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_logrotate
# 需要导入模块: from ovs.extensions.generic.sshclient import SSHClient [as 别名]
# 或者: from ovs.extensions.generic.sshclient.SSHClient import file_chmod [as 别名]
def test_basic_logrotate():
"""
Verify current openvstorage logrotate configuration
Apply the openvstorage logrotate on custom logfile and see if it rotates as predicted
Update ownership of custom file and verify logrotate raises issue
"""
storagerouters = GeneralStorageRouter.get_storage_routers()
logrotate_content = """{0} {{
rotate 5
size 20M
compress
copytruncate
notifempty
}}
{1} {{
su ovs ovs
rotate 10
size 19M
compress
delaycompress
notifempty
create 666 ovs ovs
postrotate
/usr/bin/pkill -SIGUSR1 arakoon
endscript
}}"""
if len(storagerouters) == 0:
raise ValueError('No Storage Routers found in the model')
logrotate_include_dir = '/etc/logrotate.d'
logrotate_cfg_file = '/etc/logrotate.conf'
logrotate_cron_file = '/etc/cron.daily/logrotate'
logrotate_ovs_file = '{0}/openvstorage-logs'.format(logrotate_include_dir)
expected_logrotate_content = logrotate_content.format('/var/log/ovs/*.log', '/var/log/arakoon/*/*.log')
# Verify basic logrotate configurations
for storagerouter in storagerouters:
root_client = SSHClient(endpoint=storagerouter, username='root')
assert_true(expr=root_client.file_exists(filename=logrotate_cfg_file),
msg='Logrotate config {0} does not exist on Storage Router {1}'.format(logrotate_cfg_file, storagerouter.name))
assert_true(expr=root_client.file_exists(filename=logrotate_ovs_file),
msg='Logrotate file {0} does not exist on Storage Router {1}'.format(logrotate_ovs_file, storagerouter.name))
assert_true(expr=root_client.file_exists(filename=logrotate_cron_file),
msg='Logrotate file {0} does not exist on Storage Router {1}'.format(logrotate_cron_file, storagerouter.name))
assert_true(expr='include {0}'.format(logrotate_include_dir) in root_client.file_read(filename=logrotate_cfg_file).splitlines(),
msg='Logrotate on Storage Router {0} does not include {1}'.format(storagerouter.name, logrotate_include_dir))
assert_true(expr='/usr/sbin/logrotate /etc/logrotate.conf' in root_client.file_read(filename=logrotate_cron_file).splitlines(),
msg='Logrotate will not be executed on Storage Router {0}'.format(storagerouter.name))
actual_file_contents = root_client.file_read(filename=logrotate_ovs_file).rstrip('\n')
assert_equal(first=expected_logrotate_content,
second=actual_file_contents,
msg='Logrotate contents does not match expected contents on Storage Router {0}'.format(storagerouter.name))
# Create custom logrotate file for testing purposes
custom_logrotate_cfg_file = '/opt/OpenvStorage/ci/logrotate-conf'
custom_logrotate_dir = '/opt/OpenvStorage/ci/logrotate'
custom_logrotate_file1 = '{0}/logrotate_test_file1.log'.format(custom_logrotate_dir)
custom_logrotate_file2 = '{0}/logrotate_test_file2.log'.format(custom_logrotate_dir)
custom_logrotate_content = logrotate_content.format(custom_logrotate_file1, custom_logrotate_file2)
local_sr = GeneralStorageRouter.get_local_storagerouter()
root_client = SSHClient(endpoint=local_sr, username='root')
root_client.file_write(filename=custom_logrotate_cfg_file, contents=custom_logrotate_content)
# No logfile present --> logrotate should fail
assert_raises(excClass=CalledProcessError,
callableObj=root_client.run,
command='logrotate {0}'.format(custom_logrotate_cfg_file))
##########################################
# Test 1st logrotate configuration entry #
##########################################
root_client.dir_create(directories=custom_logrotate_dir)
root_client.dir_chown(directories=custom_logrotate_dir,
user='ovs',
group='ovs',
recursive=True)
root_client.run(command='touch {0}'.format(custom_logrotate_file1))
root_client.run(command='touch {0}'.format(custom_logrotate_file2))
root_client.file_chmod(filename=custom_logrotate_file1, mode=666)
root_client.file_chmod(filename=custom_logrotate_file2, mode=666)
# Write data to the file less than size for rotation and verify rotation
GeneralVDisk.write_to_volume(location=custom_logrotate_file1,
count=15,
bs='1M',
input_type='zero',
root_client=root_client)
root_client.run('logrotate {0}'.format(custom_logrotate_cfg_file))
assert_equal(first=len(root_client.file_list(directory=custom_logrotate_dir)),
second=2,
msg='More files than expected present in {0}'.format(custom_logrotate_dir))
# Write data to file larger than size in configuration and verify amount of rotations
files_to_delete = []
for counter in range(7):
expected_file = '{0}.{1}.gz'.format(custom_logrotate_file1, counter + 1 if counter < 5 else 5)
GeneralVDisk.write_to_volume(location=custom_logrotate_file1,
count=30,
bs='1M',
#.........这里部分代码省略.........