Example #1
0
    def fail_on_invalid_host(host, properties):
        """
        Verify that host is in the host list for this project

        :param host: The host to look up
        :param host_list: Properties containing the host list
        """
        host_list = properties.get(
            '{}_hosts'.format(properties.get('technology')), [])
        if host not in host_list:
            raise PluginException(
                "Host {} not in list of valid hosts for this project".format(
                    host))
Example #2
0
    def execute(call):
        """
        Execute the command in ``call``. Returns the standard output if
        execution was successful, raises an exception with results from
        standard error otherwise.

        :param call: A dictionary, containing:

            * **args**: The command to execute as a string;
            * **stdout**: File-like object to write standard output to (optional);
            * **stderr**: File-like object to write standard error to (optional);
            * **stdin**: File-like object to read standard input from (optional);
            * **startupinfo**: Extra flags (optional).

        :return: The result from standard output.
        """
        args = call['args']
        shell = call['shell']
        stdout = call['stdout']
        stderr = call['stderr']
        stdin = call['stdin']
        startupinfo = call['startupinfo']

        # TODO: Popen isn't used any more. Remove?
        #p = subprocess.Popen(args, shell=shell, stdin=stdin, stderr=stderr, startupinfo=startupinfo)

        result = subprocess.call(args,
                                 shell=True,
                                 stdin=stdin,
                                 stdout=stdout,
                                 stderr=stderr,
                                 startupinfo=startupinfo)

        #output = p.communicate()
        #if p.returncode != 0:

        if result != 0:
            f = open(stderr.name)
            stream = f.read()
            f.close()
            raise PluginException(stream)

        f = open(stdout.name)
        stream = f.read()
        f.close()

        return stream
Example #3
0
 def fail_on_invalid_alias(alias, properties):
     """Verify that ``alias`` is valid for this project"""
     if alias and alias not in properties.get('aliasses'):
         raise PluginException(
             "alias '{}' is not valid for this project".format(alias))
Example #4
0
 def fail_on_invalid_environment(environment, properties):
     """Verify that ``environment`` is valid for this project"""
     if environment and environment not in properties.get('environments'):
         raise PluginException(
             "environment '{}' is not valid for this project".format(
                 environment))
Example #5
0
 def fail_on_invalid_schema(schema, properties):
     """Verify that ``schema`` is valid for this project"""
     if schema and schema not in properties.get('schemes'):
         raise PluginException(
             "schema '{}' is not valid for this project".format(schema))
Example #6
0
 def fail_on_invalid_database(database, properties):
     """Verify that ``database`` is valid for this project"""
     if database and database not in properties.get('databases'):
         raise PluginException(
             "database '{}' is not valid for this project".format(database))
Example #7
0
 def fail_on_no_user(user):
     """Verify that ``user`` is a string"""
     if not user:
         raise PluginException("no username provided")
     elif not issubclass(type(user), six.string_types):
         raise PluginException("provided username is not a string")
Example #8
0
 def fail_on_no_database(database):
     """Verify that ``database`` is a string"""
     if not database:
         raise PluginException("no database name provided")
     elif not issubclass(type(database), six.string_types):
         raise PluginException("provided database is not a string")
Example #9
0
 def fail_on_no_schema(schema):
     """Verify that ``schema`` is a string"""
     if not schema:
         raise PluginException("no schema name provided")
     elif not issubclass(type(schema), six.string_types):
         raise PluginException("provided schema is not a string")
Example #10
0
 def fail_on_no_users(users):
     """Verify that ``users`` is a list"""
     if not users:
         raise PluginException("no users found")
     elif type(users) is not list:
         raise PluginException("provided users is not a list")
Example #11
0
 def fail_on_no_version(version):
     """Verify that ``version`` is a string"""
     if not version:
         raise PluginException("no version was given")
     elif not issubclass(type(version), six.string_types):
         raise PluginException("version is not a string")
Example #12
0
 def fail_on_no_port(port):
     """Verify that ``port`` is an integer"""
     if not port:
         raise PluginException("no port was provided")
     elif type(port) is not int:
         raise PluginException("provided port is not an integer")
Example #13
0
 def fail_on_no_host(host):
     """Verify that ``host`` is a string"""
     if not host:
         raise PluginException("no host was given")
     elif not issubclass(type(host), six.string_types):
         raise PluginException("provided host is not a string")