예제 #1
0
    def testUpdateFromFile(self):
        wp_in = self.msg.WorkerPool()
        wp_in.workerConfig = self.msg.WorkerConfig()
        wp_in.name = 'fake_name'
        update_mask = cloudbuild_util.MessageToFieldPaths(wp_in)

        wp_out = copy.deepcopy(wp_in)
        wp_out.createTime = self.frozen_time_str
        wp_out.state = self.msg.WorkerPool.StateValueValuesEnum.RUNNING

        self.mocked_cloudbuild_v1alpha2.projects_workerPools.Patch.Expect(
            self.msg.CloudbuildProjectsWorkerPoolsPatchRequest(
                name=u'projects/{}/workerPools/{}'.format(
                    self.project_id, wp_in.name),
                workerPool=wp_in,
                updateMask=','.join(update_mask)),
            response=wp_out)

        wp_path = self.Touch('.',
                             'workerpool.yaml',
                             contents=protojson.encode_message(wp_in))

        self._Run([
            'alpha', 'builds', 'worker-pools', 'update', '--config-from-file',
            wp_path
        ])
        self.AssertOutputContains("""\
NAME CREATE_TIME STATE
fake_name {} RUNNING
""".format(self.frozen_time_str),
                                  normalize_space=True)
예제 #2
0
    def testUpdateWithDisk(self):
        wp_in = self.msg.WorkerPool()
        wp_in.workerConfig = self.msg.WorkerConfig()
        wp_in.name = 'fake_name'
        wp_in.workerConfig.diskSizeGb = 123
        update_mask = cloudbuild_util.MessageToFieldPaths(wp_in)

        wp_out = copy.deepcopy(wp_in)
        wp_out.createTime = self.frozen_time_str
        wp_out.state = self.msg.WorkerPool.StateValueValuesEnum.RUNNING

        self.mocked_cloudbuild_v1alpha2.projects_workerPools.Patch.Expect(
            self.msg.CloudbuildProjectsWorkerPoolsPatchRequest(
                name=u'projects/{}/workerPools/{}'.format(
                    self.project_id, wp_in.name),
                workerPool=wp_in,
                updateMask=','.join(update_mask)),
            response=wp_out)

        self._Run([
            'alpha', 'builds', 'worker-pools', 'update', wp_in.name,
            '--worker-disk-size',
            str(wp_in.workerConfig.diskSizeGb)
        ])
        self.AssertOutputContains("""\
NAME CREATE_TIME STATE
fake_name {} RUNNING
""".format(self.frozen_time_str),
                                  normalize_space=True)
예제 #3
0
    def testUpdateWithDisk(self):
        wp_in = self.msg.WorkerPool()
        wp_in.workerConfig = self.msg.WorkerConfig()
        wp_in.name = 'fake_name'
        wp_in.workerConfig.diskSizeGb = 123
        update_mask = cloudbuild_util.MessageToFieldPaths(wp_in)

        wp_out = copy.deepcopy(wp_in)
        wp_out.createTime = self.frozen_time_str
        wp_out.state = self.msg.WorkerPool.StateValueValuesEnum.RUNNING

        self.mocked_cloudbuild_client.projects_locations_workerPools.Patch.Expect(
            self.msg.CloudbuildProjectsLocationsWorkerPoolsPatchRequest(
                name='projects/{}/locations/{}/workerPools/{}'.format(
                    self.project_id, self.workerpool_location, wp_in.name),
                workerPool=wp_in,
                updateMask=','.join(update_mask)),
            response=self.msg.Operation(response=encoding.JsonToMessage(
                self.msg.Operation.ResponseValue, encoding.MessageToJson(
                    wp_out))))

        self._Run([
            'builds', 'worker-pools', 'update', wp_in.name, '--region',
            self.workerpool_location, '--worker-disk-size',
            six.text_type(wp_in.workerConfig.diskSizeGb)
        ])
        self.AssertOutputContains("""\
NAME CREATE_TIME STATE
fake_name {} RUNNING
""".format(self.frozen_time_str),
                                  normalize_space=True)
    def testMessageToFieldPaths_Build(self):
        messages = cloudbuild_util.GetMessagesModule()

        b = messages.Build()
        b.projectId = 'projectId'
        b.options = messages.BuildOptions()
        b.options.diskSizeGb = 123

        self.assertEqual(set(cloudbuild_util.MessageToFieldPaths(b)),
                         set(['project_id', 'options.disk_size_gb']))
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()
        config_id = args.CONFIG
        bbs = cloudbuild_util.BitbucketServerConfigFromArgs(args, True)

        parent = properties.VALUES.core.project.Get(required=True)

        # Get the bitbucket server config ref
        bbs_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.locations.bitbucketServerConfigs',
            api_version='v1',
            params={
                'projectsId': parent,
                # Use default region global until Proctor is fully regionalized.
                'locationsId': cloudbuild_util.DEFAULT_REGION,
                'bitbucketServerConfigsId': config_id,
            })

        update_mask = cloudbuild_util.MessageToFieldPaths(bbs)
        req = messages.CloudbuildProjectsLocationsBitbucketServerConfigsPatchRequest(
            name=bbs_resource.RelativeName(),
            bitbucketServerConfig=bbs,
            updateMask=','.join(update_mask))
        # Send the Update request
        updated_op = client.projects_locations_bitbucketServerConfigs.Patch(
            req)
        op_resource = resources.REGISTRY.ParseRelativeName(
            updated_op.name,
            collection='cloudbuild.projects.locations.operations')

        updated_bbs = waiter.WaitFor(
            waiter.CloudOperationPoller(
                client.projects_locations_bitbucketServerConfigs,
                client.projects_locations_operations), op_resource,
            'Updating Bitbucket Server config')

        log.UpdatedResource(bbs_resource)

        return updated_bbs
예제 #6
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The updated github enterprise resource.
    """

        client = cloudbuild_util.GetClientInstance()
        messages = cloudbuild_util.GetMessagesModule()

        config_id = args.CONFIG
        ghe = cloudbuild_util.GitHubEnterpriseConfigFromArgs(args, True)

        parent = properties.VALUES.core.project.Get(required=True)

        # Get the github enterprise config ref
        ghe_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.githubEnterpriseConfigs',
            api_version='v1',
            params={
                'projectsId': parent,
                'githubEnterpriseConfigsId': config_id,
            })

        ghe.name = ghe_resource.RelativeName()
        update_mask = cloudbuild_util.MessageToFieldPaths(ghe)
        req = messages.CloudbuildProjectsGithubEnterpriseConfigsPatchRequest(
            name=ghe.name,
            gitHubEnterpriseConfig=ghe,
            updateMask=','.join(update_mask))
        # Send the Update request
        updated_op = client.projects_githubEnterpriseConfigs.Patch(req)

        op_resource = resources.REGISTRY.ParseRelativeName(
            updated_op.name,
            collection='cloudbuild.projects.locations.operations')

        updated_ghe = waiter.WaitFor(
            waiter.CloudOperationPoller(
                client.projects_githubEnterpriseConfigs,
                client.projects_locations_operations), op_resource,
            'Updating GitHub Enterprise Config')

        log.UpdatedResource(ghe_resource)

        return updated_ghe
예제 #7
0
  def testMessageToFieldPaths_WorkerPool(self):
    messages = cloudbuild_util.GetMessagesModuleAlpha()

    wp = messages.WorkerPool()
    wp.name = 'name'
    wp.networkConfig = messages.NetworkConfig()
    wp.networkConfig.peeredNetwork = 'network'
    wp.region = 'region'
    worker_config = messages.WorkerConfig()
    worker_config.machineType = 'machine_type'
    worker_config.diskSizeGb = 100
    wp.workerConfig = worker_config

    self.assertEqual(
        set(cloudbuild_util.MessageToFieldPaths(wp)),
        set([
            'name', 'network_config.peered_network', 'region',
            'worker_config.machine_type', 'worker_config.disk_size_gb'
        ]))
예제 #8
0
    def Run(self, args):
        """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

        wp_region = args.region

        release_track = self.ReleaseTrack()
        client = cloudbuild_util.GetClientInstance(release_track)
        messages = cloudbuild_util.GetMessagesModule(release_track)

        parent = properties.VALUES.core.project.Get(required=True)

        # Get the workerpool proto from either the flags or the specified file.
        wp = messages.WorkerPool()
        if args.config_from_file is not None:
            wp = workerpool_config.LoadWorkerpoolConfigFromPath(
                args.config_from_file, messages)
        else:
            wp.name = args.WORKER_POOL
            if args.peered_network is not None:
                network_config = messages.NetworkConfig()
                network_config.peeredNetwork = args.peered_network
                wp.networkConfig = network_config
            worker_config = messages.WorkerConfig()
            if args.worker_machine_type is not None:
                worker_config.machineType = args.worker_machine_type
            if args.worker_disk_size is not None:
                worker_config.diskSizeGb = compute_utils.BytesToGb(
                    args.worker_disk_size)
            if args.no_external_ip:
                worker_config.noExternalIp = True
            wp.workerConfig = worker_config

        # Get the workerpool ref
        wp_resource = resources.REGISTRY.Parse(
            None,
            collection='cloudbuild.projects.locations.workerPools',
            api_version=cloudbuild_util.
            RELEASE_TRACK_TO_API_VERSION[release_track],
            params={
                'projectsId': parent,
                'locationsId': wp_region,
                'workerPoolsId': wp.name,
            })

        update_mask = cloudbuild_util.MessageToFieldPaths(wp)
        req = messages.CloudbuildProjectsLocationsWorkerPoolsPatchRequest(
            name=wp_resource.RelativeName(),
            workerPool=wp,
            updateMask=','.join(update_mask))
        # Send the Update request
        updated_op = client.projects_locations_workerPools.Patch(req)

        raw_dict = encoding.MessageToDict(updated_op.response)
        updated_wp = encoding.DictToMessage(raw_dict, messages.WorkerPool)

        log.UpdatedResource(wp_resource)

        # Format the workerpool name for display
        try:
            updated_wp.name = cloudbuild_util.RegionalWorkerPoolShortName(
                updated_wp.name)
        except ValueError:
            pass  # Must be an old version.

        return updated_wp
예제 #9
0
  def testMessageToFieldPaths_EmptyMessage(self):
    messages = cloudbuild_util.GetMessagesModuleAlpha()

    self.assertEqual(
        len(cloudbuild_util.MessageToFieldPaths(messages.WorkerPool())),
        0)
    def testMessageToFieldPaths_EmptyMessage(self):
        messages = cloudbuild_util.GetMessagesModule()

        self.assertEqual(
            len(cloudbuild_util.MessageToFieldPaths(messages.Build())), 0)
  def Run(self, args):
    """This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.
    """

    wp_name = args.WORKER_POOL
    wp_region = args.region

    release_track = self.ReleaseTrack()
    client = cloudbuild_util.GetClientInstance(release_track)
    messages = cloudbuild_util.GetMessagesModule(release_track)

    parent = properties.VALUES.core.project.Get(required=True)

    # Get the workerpool proto from either the flags or the specified file.
    wp = messages.WorkerPool()
    if args.config_from_file is not None:
      try:
        wp = workerpool_config.LoadWorkerpoolConfigFromPath(
            args.config_from_file, messages)
        # Don't allow a worker pool config for hybrid pools in any other
        # track but alpha.
        if release_track != base.ReleaseTrack.ALPHA:
          if wp.hybridPoolConfig is not None:
            raise cloudbuild_exceptions.HybridNonAlphaConfigError
      except cloudbuild_exceptions.ParseProtoException as err:
        log.err.Print('\nFailed to parse configuration from file.\n')
        raise err
    else:
      wp.privatePoolV1Config = messages.PrivatePoolV1Config()
      worker_config = messages.WorkerConfig()
      if args.worker_machine_type is not None:
        worker_config.machineType = args.worker_machine_type
      if args.worker_disk_size is not None:
        worker_config.diskSizeGb = compute_utils.BytesToGb(
            args.worker_disk_size)
      wp.privatePoolV1Config.workerConfig = worker_config

      private_worker_network_config = messages.NetworkConfig()
      # All of the egress flags are mutually exclusive with each other.
      if args.no_public_egress or (release_track == base.ReleaseTrack.GA and
                                   args.no_external_ip):
        private_worker_network_config.egressOption = messages.NetworkConfig.EgressOptionValueValuesEnum.NO_PUBLIC_EGRESS
      if args.public_egress:
        private_worker_network_config.egressOption = messages.NetworkConfig.EgressOptionValueValuesEnum.PUBLIC_EGRESS
      wp.privatePoolV1Config.networkConfig = private_worker_network_config

    # Get the workerpool ref
    wp_resource = resources.REGISTRY.Parse(
        None,
        collection='cloudbuild.projects.locations.workerPools',
        api_version=cloudbuild_util.RELEASE_TRACK_TO_API_VERSION[release_track],
        params={
            'projectsId': parent,
            'locationsId': wp_region,
            'workerPoolsId': wp_name,
        })

    update_mask = cloudbuild_util.MessageToFieldPaths(wp)
    req = messages.CloudbuildProjectsLocationsWorkerPoolsPatchRequest(
        name=wp_resource.RelativeName(),
        workerPool=wp,
        updateMask=','.join(update_mask))
    # Send the Update request
    updated_op = client.projects_locations_workerPools.Patch(req)

    op_resource = resources.REGISTRY.ParseRelativeName(
        updated_op.name, collection='cloudbuild.projects.locations.operations')
    updated_wp = waiter.WaitFor(
        waiter.CloudOperationPoller(client.projects_locations_workerPools,
                                    client.projects_locations_operations),
        op_resource, 'Updating worker pool')

    log.UpdatedResource(wp_resource)

    return updated_wp