Fixes return code bug for powershell scripts

This commit is contained in:
Adrian Vladu 2014-02-24 22:10:17 +01:00
parent b4b9ba4fbb
commit 7b0c075ec1
4 changed files with 8 additions and 6 deletions

View File

@ -44,7 +44,7 @@ class ShellScriptPlugin(base.BaseUserDataPlugin):
shell = False shell = False
elif file_name.endswith(".ps1"): elif file_name.endswith(".ps1"):
args = ['powershell.exe', '-ExecutionPolicy', 'RemoteSigned', args = ['powershell.exe', '-ExecutionPolicy', 'RemoteSigned',
'-NonInteractive', target_path] '-NonInteractive', '-File', target_path]
shell = False shell = False
else: else:
# Unsupported # Unsupported

View File

@ -42,7 +42,7 @@ def execute_user_data_script(user_data):
elif re.search(r'^#ps1\s', user_data, re.I): elif re.search(r'^#ps1\s', user_data, re.I):
target_path += '.ps1' target_path += '.ps1'
args = ['powershell.exe', '-ExecutionPolicy', 'RemoteSigned', args = ['powershell.exe', '-ExecutionPolicy', 'RemoteSigned',
'-NonInteractive', target_path] '-NonInteractive', '-File', target_path]
shell = False shell = False
elif re.search(r'^#ps1_sysnative\s', user_data, re.I): elif re.search(r'^#ps1_sysnative\s', user_data, re.I):
if os.path.isdir(os.path.expandvars('%windir%\\sysnative')): if os.path.isdir(os.path.expandvars('%windir%\\sysnative')):
@ -51,7 +51,7 @@ def execute_user_data_script(user_data):
'WindowsPowerShell\\v1.0\\' 'WindowsPowerShell\\v1.0\\'
'powershell.exe'), 'powershell.exe'),
'-ExecutionPolicy', '-ExecutionPolicy',
'RemoteSigned', '-NonInteractive', target_path] 'RemoteSigned', '-NonInteractive', '-File', target_path]
shell = False shell = False
else: else:
# Unable to validate sysnative presence # Unable to validate sysnative presence

View File

@ -74,7 +74,7 @@ class UserDataUtilsTest(unittest.TestCase):
number_of_calls = 4 number_of_calls = 4
extension = '.ps1' extension = '.ps1'
args = ['powershell.exe', '-ExecutionPolicy', 'RemoteSigned', args = ['powershell.exe', '-ExecutionPolicy', 'RemoteSigned',
'-NonInteractive', path+extension] '-NonInteractive', '-File', path+extension]
shell = False shell = False
else: else:
side_effect = [None, None, None, None, match_instance] side_effect = [None, None, None, None, match_instance]
@ -86,7 +86,8 @@ class UserDataUtilsTest(unittest.TestCase):
'WindowsPowerShell\\v1.0\\' 'WindowsPowerShell\\v1.0\\'
'powershell.exe'), 'powershell.exe'),
'-ExecutionPolicy', '-ExecutionPolicy',
'RemoteSigned', '-NonInteractive', path+extension] 'RemoteSigned', '-NonInteractive', '-File',
path+extension]
mock_path_isdir.return_value = True mock_path_isdir.return_value = True
else: else:
mock_path_isdir.return_value = False mock_path_isdir.return_value = False

View File

@ -63,7 +63,8 @@ class ShellScriptPluginTests(unittest.TestCase):
elif filename.endswith(".ps1"): elif filename.endswith(".ps1"):
mock_osutils.execute_process.assert_called_with( mock_osutils.execute_process.assert_called_with(
['powershell.exe', '-ExecutionPolicy', 'RemoteSigned', ['powershell.exe', '-ExecutionPolicy', 'RemoteSigned',
'-NonInteractive', os.path.join(fake_dir_path, filename)], '-NonInteractive', '-File',
os.path.join(fake_dir_path, filename)],
False) False)
self.assertFalse(response) self.assertFalse(response)