def test_execute_cleanup(self, _): with testutils.create_tempfile() as tmp: cleanup = mock.Mock() command = execcmd.BaseCommand(tmp, cleanup=cleanup) command.execute() cleanup.assert_called_once_with()
def test_execute_powershell_command(self, mock_get_os_utils): mock_osutils = mock_get_os_utils() with testutils.create_tempfile() as tmp: command = execcmd.Powershell(tmp) command.execute() mock_osutils.execute_powershell_script.assert_called_once_with(command._target_path, command.sysnative)
def test_execute_powershell_command(self, mock_get_os_utils): mock_osutils = mock_get_os_utils() with testutils.create_tempfile() as tmp: command = execcmd.Powershell(tmp) command.execute() mock_osutils.execute_powershell_script.assert_called_once_with( command._target_path, command.sysnative)
def test_args(self, _): class FakeCommand(execcmd.BaseCommand): command = mock.sentinel.command with testutils.create_tempfile() as tmp: fake_command = FakeCommand(tmp) self.assertEqual([mock.sentinel.command, tmp], fake_command.args) fake_command = execcmd.BaseCommand(tmp) self.assertEqual([tmp], fake_command.args)
def test_execute_normal_command(self, mock_get_os_utils): mock_osutils = mock_get_os_utils() with testutils.create_tempfile() as tmp: command = execcmd.BaseCommand(tmp) command.execute() mock_osutils.execute_process.assert_called_once_with([command._target_path], shell=command.shell) # test __call__ API. mock_osutils.execute_process.reset_mock() command() mock_osutils.execute_process.assert_called_once_with([command._target_path], shell=command.shell)
def test_exec_file_no_executor(self, mock_execute_user_data_script, mock_get_command, _): mock_get_command.return_value = None with testutils.create_tempfile() as temp: with mock.patch('cloudbaseinit.plugins.common.userdatautils' '.open', create=True): with testutils.LogSnatcher('cloudbaseinit.plugins.common.' 'fileexecutils') as snatcher: retval = fileexecutils.exec_file(temp) expected_logging = ['No valid extension or header found' ' in the userdata: %s' % temp] self.assertEqual(0, retval) self.assertEqual(expected_logging, snatcher.output)
def test_execute_normal_command(self, mock_get_os_utils): mock_osutils = mock_get_os_utils() with testutils.create_tempfile() as tmp: command = execcmd.BaseCommand(tmp) command.execute() mock_osutils.execute_process.assert_called_once_with( [command._target_path], shell=command.shell) # test __call__ API. mock_osutils.execute_process.reset_mock() command() mock_osutils.execute_process.assert_called_once_with( [command._target_path], shell=command.shell)
def test_exec_file_no_executor(self, mock_execute_user_data_script, mock_get_command, _): mock_get_command.return_value = None with testutils.create_tempfile() as temp: with mock.patch( 'cloudbaseinit.plugins.common.userdatautils' '.open', create=True): with testutils.LogSnatcher('cloudbaseinit.plugins.common.' 'fileexecutils') as snatcher: retval = fileexecutils.exec_file(temp) expected_logging = [ 'No valid extension or header found' ' in the userdata: %s' % temp ] self.assertEqual(0, retval) self.assertEqual(expected_logging, snatcher.output)