Beispiel #1
0
    def get_resources(self, type, extra_args=None, no_resource_ok=False):
        """Observe resources of a particular type.

    This ultimately calls a "kubectl ... get |type| |extra_args|"

    Args:
      no_resource_ok: Whether or not the resource is required.
          If the resource is not required, "not found" is treated as a valid
          check. Because resource deletion is asynchronous, there is no
          explicit API here to confirm that a resource does not exist.
    """
        self.observer = self.__factory.new_get_resources(type,
                                                         extra_args=extra_args)

        if no_resource_ok:
            # Unfortunately gcloud does not surface the actual 404 but prints an
            # error message saying that it was not found.
            error_verifier = cli_agent.CliAgentObservationFailureVerifier(
                title='Not Found Permitted', error_regex='.* not found')
            disjunction_builder = jc.ObservationVerifierBuilder(
                'Get {0} {1} or Not Found'.format(type, extra_args))
            disjunction_builder.append_verifier(error_verifier)

            get_builder = jc.ValueObservationVerifierBuilder(
                'Get {0} {1}'.format(type, extra_args), strict=self.__strict)
            disjunction_builder.append_verifier_builder(get_builder,
                                                        new_term=True)
            self.verifier_builder.append_verifier_builder(disjunction_builder,
                                                          new_term=True)
        else:
            get_builder = jc.ValueObservationVerifierBuilder(
                'Get {0} {1}'.format(type, extra_args), strict=self.__strict)
            self.verifier_builder.append_verifier_builder(get_builder)

        return get_builder
Beispiel #2
0
    def inspect_resource(self,
                         type,
                         name,
                         extra_args=None,
                         no_resource_ok=False):
        """Observe the details of a specific instance.

    This ultimately calls a "gcloud ... |type| |name| describe |extra_args|"

    Args:
      type: The gcloud resource type  (e.g. instances)
      name: The GCE resource name
      extra_args: Additional parameters to pass to gcloud.
      no_resource_ok: Whether or not the resource is required.
          If the resource is not required, a 404 is treated as a valid check.
          Because resource deletion is asynchronous, there is no explicit
          API here to confirm that a resource does not exist.

    Returns:
      A js.ValueObservationVerifier that will collect the requested resource
          when its verify() method is run.
    """

        self.observer = self.__factory.new_inspect_resource(
            type, name, extra_args)

        if no_resource_ok:
            # Unfortunately gcloud does not surface the actual 404 but prints an
            # error message saying that it was not found.
            error_verifier = cli_agent.CliAgentObservationFailureVerifier(
                title='404 Permitted', error_regex='.* was not found.*')
            disjunction_builder = jc.ObservationVerifierBuilder(
                'Inspect {0} {1} or 404'.format(type, name))
            disjunction_builder.append_verifier(error_verifier)

            inspect_builder = jc.ValueObservationVerifierBuilder(
                'Inspect {0} {1}'.format(type, name), strict=self.__strict)
            disjunction_builder.append_verifier_builder(inspect_builder,
                                                        new_term=True)
            self.verifier_builder.append_verifier_builder(disjunction_builder,
                                                          new_term=True)
        else:
            inspect_builder = jc.ValueObservationVerifierBuilder(
                'Inspect {0} {1}'.format(type, name), strict=self.__strict)
            self.verifier_builder.append_verifier_builder(inspect_builder)

        return inspect_builder
Beispiel #3
0
    def collect_resources(self,
                          aws_module,
                          command,
                          args=None,
                          filter=None,
                          no_resources_ok=False):
        """Collect the AWS resources of a particular type.

    Args:
      aws_module: The aws program module name we're looking in (e.g. 'ec2')
      command: The aws command name to run (e.g. 'describe-instances')
      args: An array of strings containing the remaining aws command parameters.
      filter: If provided, a filter to use for refining the collection.
      no_resources_ok: Whether or not the resource is required.
          If the resource is not required, 'resource not found' error is
          considered successful.
    """
        args = args or []
        cmd = self.__aws.build_aws_command_args(command,
                                                args,
                                                aws_module=aws_module,
                                                profile=self.__aws.profile)

        self.observer = AwsObjectObserver(self.__aws, cmd)

        if no_resources_ok:
            error_verifier = cli_agent.CliAgentObservationFailureVerifier(
                title='"Not Found" permitted.',
                error_regex=
                '(?:.* operation: Cannot find .*)|(?:.*\(.*NotFound\).*)')
            disjunction_builder = jc.ObservationVerifierBuilder(
                'Collect {0} or Not Found'.format(command))
            disjunction_builder.append_verifier(error_verifier)

            collect_builder = jc.ValueObservationVerifierBuilder(
                'Collect {0}'.format(command), strict=self.__strict)
            disjunction_builder.append_verifier_builder(collect_builder,
                                                        new_term=True)
            self.verifier_builder.append_verifier_builder(disjunction_builder,
                                                          new_term=True)
        else:
            collect_builder = jc.ValueObservationVerifierBuilder(
                'Collect {0}'.format(command), strict=self.__strict)
            self.verifier_builder.append_verifier_builder(collect_builder)

        return collect_builder
Beispiel #4
0
    def collect_resources(self,
                          command,
                          args=None,
                          filter=None,
                          no_resources_ok=False):
        """Collect the OpenStack resources of a particular type.

    Args:
      command: The openstack command name to run (e.g. 'image', 'server')
      args: An array of strings containing the remaining openstack command
      parameters.
      filter: If provided, a filter to use for refining the collection.
      no_resources_ok: Whether or not the resource is required.
          If the resource is not required, 'resource not found' error is
          considered successful.
    """
        args = args or []
        cmd = self.__os.build_os_command_args(command,
                                              args,
                                              os_cloud=self.__os.os_cloud)

        self.observer = OsObjectObserver(self.__os, cmd)

        if no_resources_ok:
            error_verifier = cli_agent.CliAgentObservationFailureVerifier(
                title='"Not Found" permitted.',
                error_regex=
                '(?:.* operation: Cannot find .*)|(?:.*\(.*NotFound\)|(Error .*).*)'
            )
            disjunction_builder = jc.ObservationVerifierBuilder(
                'Collect {0} or Not Found'.format(command))
            disjunction_builder.append_verifier(error_verifier)

            collect_builder = jc.ValueObservationVerifierBuilder(
                'Collect {0}'.format(command), strict=self.__strict)
            disjunction_builder.append_verifier_builder(collect_builder,
                                                        new_term=True)
            self.verifier_builder.append_verifier_builder(disjunction_builder,
                                                          new_term=True)
        else:
            collect_builder = jc.ValueObservationVerifierBuilder(
                'Collect {0}'.format(command), strict=self.__strict)
            self.verifier_builder.append_verifier_builder(collect_builder)

        return collect_builder
Beispiel #5
0
    def show_resource(self, command, resource_name, no_resources_ok=False):
        """Show the OpenStack resource of a particular type.

    Args:
      command: The openstack command name to run
      (e.g. 'security group', 'server').
      resource_name: Name of the OpenStack resource
      (e.g. Name of a security group or an image).
      no_resources_ok: Whether or not the resource is required.
      If the resource is not required, 'resource not found' error is
      considered successful.
    """
        args = ['show', resource_name, '--format', 'json']

        cmd = self.__os.build_os_command_args(command,
                                              args,
                                              os_cloud=self.__os.os_cloud)
        self.observer = OsObjectObserver(self.__os, cmd)
        if no_resources_ok:
            error_verifier = cli_agent.CliAgentObservationFailureVerifier(
                title='"Not Found" permitted.',
                error_regex=
                '(?:.* operation: Cannot find .*)|(?:.*\(.*NotFound\)|(Error .*).*)'
            )
            disjunction_builder = jc.ObservationVerifierBuilder(
                'Collect {0} or Not Found'.format(command))
            disjunction_builder.append_verifier(error_verifier)

            collect_builder = jc.ValueObservationVerifierBuilder(
                'Collect {0}'.format(command), strict=self.__strict)
            disjunction_builder.append_verifier_builder(collect_builder,
                                                        new_term=True)
            self.verifier_builder.append_verifier_builder(disjunction_builder,
                                                          new_term=True)
        else:
            collect_builder = jc.ValueObservationVerifierBuilder(
                'Collect {0}'.format(command), strict=self.__strict)
            self.verifier_builder.append_verifier_builder(collect_builder)

        return collect_builder