def test_exec_file_no_executor(self, _):
        with testutils.LogSnatcher('cloudbaseinit.plugins.common.'
                                   'fileexecutils') as snatcher:
            retval = fileexecutils.exec_file("fake.fake")

        expected_logging = ['Unsupported script file type: fake']
        self.assertEqual(0, retval)
        self.assertEqual(expected_logging, snatcher.output)
Beispiel #2
0
 def test_exec_file_(self, mock_execute, _):
     mock_execute.return_value = (
         mock.sentinel.out,
         mock.sentinel.error,
         0,
     )
     retval = fileexecutils.exec_file("fake.py")
     mock_execute.assert_called_once_with()
     self.assertEqual(0, retval)
    def test_exec_file_(self, mock_execute, _):
        mock_execute.return_value = (
            mock.sentinel.out,
            mock.sentinel.error,
            0,
        )

        retval = fileexecutils.exec_file("fake.py")
        mock_execute.assert_called_once_with()
        self.assertEqual(0, retval)
    def test_exec_file_fails(self, mock_execute, _):
        mock_execute.side_effect = ValueError
        with testutils.LogSnatcher('cloudbaseinit.plugins.common.'
                                   'fileexecutils') as snatcher:
            retval = fileexecutils.exec_file("fake.py")

        expected_logging = [
            "An error occurred during file execution: ''",
            'Script "fake.py" ended with exit code: 0'
        ]
        mock_execute.assert_called_once_with()
        self.assertEqual(0, retval)
        self.assertEqual(expected_logging, snatcher.output)
Beispiel #5
0
    def process(self, part):
        file_name = part.get_filename()
        target_path = os.path.join(tempfile.gettempdir(), file_name)

        try:
            encoding.write_file(target_path, part.get_payload())

            return fileexecutils.exec_file(target_path)
        except Exception as ex:
            LOG.warning(
                'An error occurred during user_data execution: \'%s\'' % ex)
        finally:
            if os.path.exists(target_path):
                os.remove(target_path)
    def process(self, part):
        file_name = part.get_filename()
        target_path = os.path.join(tempfile.gettempdir(), file_name)

        try:
            encoding.write_file(target_path, part.get_payload())

            return fileexecutils.exec_file(target_path)
        except Exception as ex:
            LOG.warning('An error occurred during user_data execution: \'%s\''
                        % ex)
        finally:
            if os.path.exists(target_path):
                os.remove(target_path)
    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 execute(self, service, shared_data):
        plugin_status = base.PLUGIN_EXECUTION_DONE
        reboot = False

        if CONF.local_scripts_path:
            for file_path in self._get_files_in_dir(CONF.local_scripts_path):
                ret_val = fileexecutils.exec_file(file_path)
                new_plugin_status, new_reboot = \
                    execcmd.get_plugin_return_value(ret_val)
                plugin_status = max(plugin_status, new_plugin_status)
                reboot = reboot or new_reboot
                if reboot:
                    break

        return plugin_status, reboot
    def execute(self, service, shared_data):
        plugin_status = base.PLUGIN_EXECUTION_DONE
        reboot = False

        if CONF.local_scripts_path:
            for file_path in self._get_files_in_dir(CONF.local_scripts_path):
                ret_val = fileexecutils.exec_file(file_path)
                new_plugin_status, new_reboot = \
                    execcmd.get_plugin_return_value(ret_val)
                plugin_status = max(plugin_status, new_plugin_status)
                reboot = reboot or new_reboot
                if reboot:
                    break

        return plugin_status, reboot
Beispiel #10
0
    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 execute(self, service, shared_data):
        if CONF.local_scripts_path:
            for file_path in self._get_files_in_dir(CONF.local_scripts_path):
                fileexecutils.exec_file(file_path)

        return (base.PLUGIN_EXECUTION_DONE, False)
Beispiel #12
0
    def execute(self, service, shared_data):
        if CONF.local_scripts_path:
            for file_path in self._get_files_in_dir(CONF.local_scripts_path):
                fileexecutils.exec_file(file_path)

        return (base.PLUGIN_EXECUTION_DONE, False)
 def test_exec_file_fails(self, mock_execute, _):
     mock_execute.side_effect = ValueError
     retval = fileexecutils.exec_file("fake.py")
     mock_execute.assert_called_once_with()
     self.assertEqual(0, retval)
 def test_exec_file_no_executor(self, _):
     retval = fileexecutils.exec_file("fake.fake")
     self.assertEqual(0, retval)
Beispiel #15
0
 def test_exec_file_fails(self, mock_execute, _):
     mock_execute.side_effect = ValueError
     retval = fileexecutils.exec_file("fake.py")
     mock_execute.assert_called_once_with()
     self.assertEqual(0, retval)
Beispiel #16
0
 def test_exec_file_no_executor(self, _):
     retval = fileexecutils.exec_file("fake.fake")
     self.assertEqual(0, retval)