This file is indexed.

/usr/lib/python2.7/dist-packages/muranoagent/executors/chef_puppet_executor_base.py is in murano-agent 1:3.0.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
# Copyright (c) 2015 Telefonica I+D
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import os
import subprocess

from oslo_log import log as logging
import six

from muranoagent import bunch
import muranoagent.exceptions
from muranoagent import executors


LOG = logging.getLogger(__name__)


class ChefPuppetExecutorBase(object):
    def __init__(self, name):
        self._name = name

    def load(self, path, options):
        """Load the path and options from template into the executor.

           :param path: The path
           :param options: execution plan options.

        """
        self._path = path
        self._capture_stdout = options.get('captureStdout', True)
        self._capture_stderr = options.get('captureStderr', True)
        self._verify_exitcode = options.get('verifyExitcode', True)

    def _valid_module_name(self):
        if not self._valid_name(self._name):
            msg = ("Module recipe name format {0} is not valid".
                   format(self._name))
            LOG.debug(msg)
            raise muranoagent.exceptions.CustomException(
                0,
                message=msg,
                additional_data=None)

        self.module_name = self._name[0:self._name.rfind('::')]
        self.module_recipe = self._name[self._name.rfind('::') + 2:]

    def _valid_name(self, name):
        return '::' in name

    def _execute_command(self, command):
        stdout = subprocess.PIPE if self._capture_stdout else None
        stderr = subprocess.PIPE if self._capture_stderr else None
        process = subprocess.Popen(
            command,
            stdout=stdout,
            stderr=stderr,
            universal_newlines=True,
            cwd=os.getcwd(),
            shell=True)
        stdout, stderr = process.communicate(input)
        retcode = process.poll()

        if stdout is not None:
            if not isinstance(stdout, six.text_type):
                stdout = stdout.decode('utf-8')
            LOG.debug(u"'{0}' execution stdout: "
                      u"'{1}'".format(self.module_name, stdout))
        if stderr is not None:
            for line in stdout.splitlines():
                if 'ERROR' in line:
                    stderr += line + "\n"
            LOG.debug(u"'{0}' execution stderr: "
                      u"'{1}'".format(self.module_name, stderr))

        LOG.debug('Script {0} execution finished \
            with retcode: {1} {2}'.format(self.module_name, retcode, stderr))
        result = {
            'exitCode': retcode,
            'stdout': stdout.strip() if stdout else None,
            'stderr': stderr.strip() if stderr else None
        }
        if self._verify_exitcode and retcode != 0:
            raise muranoagent.exceptions.CustomException(
                0,
                message='Script {0} returned error code'.format(self._name),
                additional_data=result)

        return result