Coverage for manila/privsep/os.py: 42%
49 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2021 Red Hat, Inc
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
15"""
16Helpers for os basic commands
17"""
19from oslo_concurrency import processutils
21from manila import exception
23import manila.privsep
26@manila.privsep.sys_admin_pctxt.entrypoint
27def rmdir(dir_path):
28 processutils.execute('rmdir', dir_path)
31@manila.privsep.sys_admin_pctxt.entrypoint
32def mkdir(dir_path):
33 processutils.execute('mkdir', dir_path)
36@manila.privsep.sys_admin_pctxt.entrypoint
37def recursive_forced_rm(dir_path):
38 processutils.execute('rm', '-rf', dir_path)
41@manila.privsep.sys_admin_pctxt.entrypoint
42def is_data_definition_direct_io_supported(src_str, dest_str):
43 try:
44 processutils.execute(
45 'dd', 'count=0', f'if={src_str}', f'of={dest_str}',
46 'iflag=direct', 'oflag=direct')
47 is_direct_io_supported = True
48 except exception.ProcessExecutionError:
49 is_direct_io_supported = False
51 return is_direct_io_supported
54@manila.privsep.sys_admin_pctxt.entrypoint
55def data_definition(src_str, dest_str, size_in_g, use_direct_io=False):
56 extra_flags = []
57 if use_direct_io:
58 extra_flags += ['iflag=direct', 'oflag=direct']
59 processutils.execute(
60 'dd', 'if=%s' % src_str, 'of=%s' % dest_str, 'count=%d' % size_in_g,
61 'bs=1M', *extra_flags)
64@manila.privsep.sys_admin_pctxt.entrypoint
65def umount(mount_path):
66 processutils.execute('umount', '-f', mount_path)
69@manila.privsep.sys_admin_pctxt.entrypoint
70def mount(device_name, mount_path, mount_type=None):
71 extra_args = ['-t', mount_type] if mount_type else []
72 processutils.execute('mount', device_name, mount_path, *extra_args)
75@manila.privsep.sys_admin_pctxt.entrypoint
76def list_mounts():
77 out, err = processutils.execute('mount', '-l')
78 return out, err
81@manila.privsep.sys_admin_pctxt.entrypoint
82def chmod(permission_level_str, mount_path):
83 processutils.execute('chmod', permission_level_str, mount_path)
86@manila.privsep.sys_admin_pctxt.entrypoint
87def find(directory_to_find, min_depth='1', dirs_to_ignore=[], delete=False):
88 ignored_dirs = []
89 extra_args = []
90 for dir in dirs_to_ignore:
91 ignored_dirs += '!', '-path', dir
93 if delete:
94 extra_args.append('-delete')
96 processutils.execute(
97 'find', directory_to_find, '-mindepth', min_depth, *ignored_dirs,
98 *extra_args)