def test_patch_job(self):
        project_id = os.environ["PROJECT_ID"]
        client = OsConfigServiceClient()

        # ExecutePatchJob
        request = patch_jobs.ExecutePatchJobRequest(
            parent=f"projects/{project_id}",
            description="Python Client Library System Test",
            instance_filter=patch_jobs.PatchInstanceFilter(all=True),
        )
        patch_job = client.execute_patch_job(request)
        assert patch_job is not None

        # GetPatchJob
        request = patch_jobs.GetPatchJobRequest(name=patch_job.name)
        patch_job = client.get_patch_job(request)
        assert patch_job.description == "Python Client Library System Test"

        # ListPatchJobInstanceDetails
        request = patch_jobs.ListPatchJobInstanceDetailsRequest(parent=patch_job.name)
        response = client.list_patch_job_instance_details(request)
        assert len(response.patch_job_instance_details) >= 0

        # CancelPatchJob
        request = patch_jobs.CancelPatchJobRequest(name=patch_job.name)
        patch_job = client.cancel_patch_job(request)
        assert patch_job.state == patch_jobs.PatchJob.State.CANCELED

        # ListPatchJobs
        request = patch_jobs.ListPatchJobsRequest(parent=f"projects/{project_id}")
        response = client.list_patch_jobs(request)
        assert response.patch_jobs
Exemple #2
0
    def get_patch_job(
            self,
            request: patch_jobs.GetPatchJobRequest = None,
            *,
            name: str = None,
            retry: retries.Retry = gapic_v1.method.DEFAULT,
            timeout: float = None,
            metadata: Sequence[Tuple[str, str]] = (),
    ) -> patch_jobs.PatchJob:
        r"""Get the patch job. This can be used to track the
        progress of an ongoing patch job or review the details
        of completed jobs.

        Args:
            request (:class:`~.patch_jobs.GetPatchJobRequest`):
                The request object. Request to get an active or
                completed patch job.
            name (:class:`str`):
                Required. Name of the patch in the form
                ``projects/*/patchJobs/*``
                This corresponds to the ``name`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.

            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.
            timeout (float): The timeout for this request.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.

        Returns:
            ~.patch_jobs.PatchJob:
                A high level representation of a patch job that is
                either in progress or has completed.

                Instances details are not included in the job. To
                paginate through instance details, use
                ListPatchJobInstanceDetails.

                For more information about patch jobs, see `Creating
                patch
                jobs <https://cloud.google.com/compute/docs/os-patch-management/create-patch-job>`__.

        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        if request is not None and any([name]):
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        request = patch_jobs.GetPatchJobRequest(request)

        # If we have keyword arguments corresponding to fields on the
        # request, apply these.

        if name is not None:
            request.name = name

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method.wrap_method(
            self._transport.get_patch_job,
            default_timeout=None,
            client_info=_client_info,
        )

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata(
            (("name", request.name), )), )

        # Send the request.
        response = rpc(request,
                       retry=retry,
                       timeout=timeout,
                       metadata=metadata)

        # Done; return the response.
        return response