Merge "Drop usage of run_as_root"
This commit is contained in:
commit
359ac636f0
ironic_python_agent
@ -753,7 +753,7 @@ def _validate_partitioning(device):
|
||||
try:
|
||||
# Ensure we re-read the partition table before we try to list
|
||||
# partitions
|
||||
utils.execute('partprobe', device, run_as_root=True,
|
||||
utils.execute('partprobe', device,
|
||||
attempts=CONF.disk_utils.partprobe_attempts)
|
||||
except (processutils.UnknownArgumentError,
|
||||
processutils.ProcessExecutionError, OSError) as e:
|
||||
|
@ -156,7 +156,7 @@ def get_labelled_partition(device_path, label, node_uuid):
|
||||
try:
|
||||
output, err = utils.execute('lsblk', '-Po', 'name,label', device_path,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
use_standard_locale=True)
|
||||
|
||||
except (processutils.UnknownArgumentError,
|
||||
processutils.ProcessExecutionError, OSError) as e:
|
||||
@ -382,8 +382,7 @@ def create_config_drive_partition(node_uuid, device, configdrive):
|
||||
create_option = '0:-%dMB:0' % MAX_CONFIG_DRIVE_SIZE_MB
|
||||
uuid_option = '0:%s' % part_uuid
|
||||
utils.execute('sgdisk', '-n', create_option,
|
||||
'-u', uuid_option, device,
|
||||
run_as_root=True)
|
||||
'-u', uuid_option, device)
|
||||
else:
|
||||
cur_parts = set(part['number']
|
||||
for part in disk_utils.list_partitions(device))
|
||||
@ -425,7 +424,7 @@ def create_config_drive_partition(node_uuid, device, configdrive):
|
||||
|
||||
utils.execute('parted', '-a', 'optimal', '-s', '--', device,
|
||||
'mkpart', 'primary', 'fat32', startlimit,
|
||||
endlimit, run_as_root=True)
|
||||
endlimit)
|
||||
# Trigger device rescan
|
||||
disk_utils.trigger_device_rescan(device)
|
||||
|
||||
@ -588,8 +587,7 @@ def _is_disk_larger_than_max_size(device, node_uuid):
|
||||
try:
|
||||
disksize_bytes, err = utils.execute('blockdev', '--getsize64',
|
||||
device,
|
||||
use_standard_locale=True,
|
||||
run_as_root=True)
|
||||
use_standard_locale=True)
|
||||
except (processutils.UnknownArgumentError,
|
||||
processutils.ProcessExecutionError, OSError) as e:
|
||||
msg = ('Failed to get size of disk %(disk)s for node %(node)s. '
|
||||
|
@ -887,7 +887,6 @@ class TestStandbyExtension(base.IronicAgentTest):
|
||||
self.assertEqual(cmd_result, async_result.command_result['result'])
|
||||
list_part_mock.assert_called_with('manager')
|
||||
execute_mock.assert_called_with('partprobe', 'manager',
|
||||
run_as_root=True,
|
||||
attempts=mock.ANY)
|
||||
self.assertEqual({'root uuid': 'ROOT'},
|
||||
self.agent_extension.partition_uuids)
|
||||
@ -959,7 +958,6 @@ class TestStandbyExtension(base.IronicAgentTest):
|
||||
self.assertEqual(cmd_result, async_result.command_result['result'])
|
||||
list_part_mock.assert_called_with('manager')
|
||||
execute_mock.assert_called_with('partprobe', 'manager',
|
||||
run_as_root=True,
|
||||
attempts=mock.ANY)
|
||||
self.assertEqual({'root uuid': 'root_uuid'},
|
||||
self.agent_extension.partition_uuids)
|
||||
@ -1107,7 +1105,6 @@ class TestStandbyExtension(base.IronicAgentTest):
|
||||
self.assertEqual(cmd_result, async_result.command_result['result'])
|
||||
list_part_mock.assert_called_with('manager')
|
||||
execute_mock.assert_called_with('partprobe', 'manager',
|
||||
run_as_root=True,
|
||||
attempts=mock.ANY)
|
||||
self.assertEqual({}, self.agent_extension.partition_uuids)
|
||||
|
||||
|
@ -170,7 +170,7 @@ class GetLabelledPartitionTestCases(base.IronicAgentTest):
|
||||
mock.call('partprobe', self.dev, run_as_root=True, attempts=10),
|
||||
mock.call('lsblk', '-Po', 'name,label', self.dev,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
use_standard_locale=True)
|
||||
]
|
||||
mock_execute.assert_has_calls(execute_calls)
|
||||
|
||||
@ -186,7 +186,7 @@ class GetLabelledPartitionTestCases(base.IronicAgentTest):
|
||||
mock.call('partprobe', self.dev, run_as_root=True, attempts=10),
|
||||
mock.call('lsblk', '-Po', 'name,label', self.dev,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
use_standard_locale=True)
|
||||
]
|
||||
mock_execute.assert_has_calls(execute_calls)
|
||||
|
||||
@ -201,7 +201,7 @@ class GetLabelledPartitionTestCases(base.IronicAgentTest):
|
||||
mock.call('partprobe', self.dev, run_as_root=True, attempts=10),
|
||||
mock.call('lsblk', '-Po', 'name,label', self.dev,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
use_standard_locale=True)
|
||||
]
|
||||
mock_execute.assert_has_calls(execute_calls)
|
||||
|
||||
@ -220,7 +220,7 @@ class GetLabelledPartitionTestCases(base.IronicAgentTest):
|
||||
mock.call('partprobe', self.dev, run_as_root=True, attempts=10),
|
||||
mock.call('lsblk', '-Po', 'name,label', self.dev,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
use_standard_locale=True)
|
||||
]
|
||||
mock_execute.assert_has_calls(execute_calls)
|
||||
|
||||
@ -236,7 +236,7 @@ class GetLabelledPartitionTestCases(base.IronicAgentTest):
|
||||
mock.call('partprobe', self.dev, run_as_root=True, attempts=10),
|
||||
mock.call('lsblk', '-Po', 'name,label', self.dev,
|
||||
check_exit_code=[0, 1],
|
||||
use_standard_locale=True, run_as_root=True)
|
||||
use_standard_locale=True)
|
||||
]
|
||||
mock_execute.assert_has_calls(execute_calls)
|
||||
self.assertEqual(1, mock_log.call_count)
|
||||
@ -253,7 +253,7 @@ class IsDiskLargerThanMaxSizeTestCases(base.IronicAgentTest):
|
||||
result = partition_utils._is_disk_larger_than_max_size(self.dev,
|
||||
self.node_uuid)
|
||||
mock_execute.assert_called_once_with('blockdev', '--getsize64',
|
||||
'/dev/fake', run_as_root=True,
|
||||
'/dev/fake',
|
||||
use_standard_locale=True)
|
||||
return result
|
||||
|
||||
@ -277,7 +277,7 @@ class IsDiskLargerThanMaxSizeTestCases(base.IronicAgentTest):
|
||||
partition_utils._is_disk_larger_than_max_size,
|
||||
self.dev, self.node_uuid)
|
||||
mock_execute.assert_called_once_with('blockdev', '--getsize64',
|
||||
'/dev/fake', run_as_root=True,
|
||||
'/dev/fake',
|
||||
use_standard_locale=True)
|
||||
self.assertEqual(1, mock_log.call_count)
|
||||
|
||||
@ -697,7 +697,7 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
|
||||
config_url)
|
||||
mock_execute.assert_has_calls([
|
||||
mock.call('sgdisk', '-n', '0:-64MB:0', '-u', '0:fake-uuid',
|
||||
self.dev, run_as_root=True),
|
||||
self.dev),
|
||||
mock.call('sync'),
|
||||
mock.call('udevadm', 'settle'),
|
||||
mock.call('partprobe', self.dev, attempts=10, run_as_root=True),
|
||||
@ -758,7 +758,7 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
|
||||
config_url)
|
||||
mock_execute.assert_has_calls([
|
||||
mock.call('sgdisk', '-n', '0:-64MB:0', '-u', '0:fake-uuid',
|
||||
self.dev, run_as_root=True),
|
||||
self.dev),
|
||||
mock.call('sync'),
|
||||
mock.call('udevadm', 'settle'),
|
||||
mock.call('partprobe', self.dev, attempts=10, run_as_root=True),
|
||||
@ -823,7 +823,7 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
|
||||
config_url)
|
||||
mock_execute.assert_has_calls([
|
||||
mock.call('sgdisk', '-n', '0:-64MB:0', '-u', '0:fake-uuid',
|
||||
self.dev, run_as_root=True),
|
||||
self.dev),
|
||||
mock.call('sync'),
|
||||
mock.call('udevadm', 'settle'),
|
||||
mock.call('partprobe', self.dev, attempts=10, run_as_root=True),
|
||||
@ -918,13 +918,13 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
|
||||
parted_call = mock.call('parted', '-a', 'optimal', '-s',
|
||||
'--', self.dev, 'mkpart',
|
||||
'primary', 'fat32', 2097087,
|
||||
2097151, run_as_root=True)
|
||||
2097151)
|
||||
else:
|
||||
self.assertEqual(0, mock_log.call_count)
|
||||
parted_call = mock.call('parted', '-a', 'optimal', '-s',
|
||||
'--', self.dev, 'mkpart',
|
||||
'primary', 'fat32', '-64MiB',
|
||||
'-0', run_as_root=True)
|
||||
'-0')
|
||||
mock_execute.assert_has_calls([
|
||||
parted_call,
|
||||
mock.call('sync'),
|
||||
@ -1025,8 +1025,7 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
|
||||
mock_execute.assert_has_calls([
|
||||
mock.call('parted', '-a', 'optimal', '-s', '--',
|
||||
self.dev, 'mkpart', 'primary',
|
||||
'fat32', '-64MiB', '-0',
|
||||
run_as_root=True),
|
||||
'fat32', '-64MiB', '-0'),
|
||||
mock.call('sync'),
|
||||
mock.call('udevadm', 'settle'),
|
||||
mock.call('partprobe', self.dev, attempts=10, run_as_root=True),
|
||||
@ -1096,8 +1095,7 @@ class CreateConfigDriveTestCases(base.IronicAgentTest):
|
||||
mock_get_configdrive.assert_called_with(config_url, self.node_uuid)
|
||||
mock_execute.assert_called_with('parted', '-a', 'optimal', '-s', '--',
|
||||
self.dev, 'mkpart', 'primary',
|
||||
'fat32', '-64MiB', '-0',
|
||||
run_as_root=True)
|
||||
'fat32', '-64MiB', '-0')
|
||||
self.assertEqual(1, mock_list_partitions.call_count)
|
||||
mock_fix_gpt_partition.assert_called_with(self.dev, self.node_uuid)
|
||||
mock_table_type.assert_called_with(self.dev)
|
||||
@ -1263,7 +1261,7 @@ class RealFilePartitioningTestCase(base.IronicAgentTest):
|
||||
real_execute = utils.execute
|
||||
|
||||
def fake_execute(*cmd, **kwargs):
|
||||
kwargs['run_as_root'] = False
|
||||
kwargs.pop('run_as_root', None)
|
||||
return real_execute(*cmd, **kwargs)
|
||||
|
||||
with mock.patch.object(utils, 'execute', fake_execute):
|
||||
|
Loading…
x
Reference in New Issue
Block a user