示例#1
0
    def get_or_create_project_info(self, project_name):
        """Get OSS-Fuzz CPU info by project name (or create a new one if it doesn't
    exist)."""
        key = ndb.Key(data_types.OssFuzzProjectInfo, project_name)
        project_info = key.get()
        if not project_info:
            project_info = data_types.OssFuzzProjectInfo(name=project_name,
                                                         id=project_name)
            project_info.put()

        return project_info
示例#2
0
  def setUp(self):
    test_helpers.patch_environ(self)
    test_helpers.patch(self, [
        'base.utils.is_oss_fuzz',
        'handlers.cron.helpers.bot_manager.BotManager',
        'system.environment.is_running_on_app_engine',
        'google.appengine.api.app_identity.get_application_id',
        'google_cloud_utils.compute_engine_projects.load_project',
    ])

    self.mock.is_oss_fuzz.return_value = True
    self.mock.is_running_on_app_engine.return_value = True
    self.mock.get_application_id.return_value = 'clusterfuzz-external'
    self.mock.load_project.return_value = compute_engine_projects.Project(
        project_id='clusterfuzz-external',
        clusters=[
            compute_engine_projects.Cluster(
                name='oss-fuzz-linux-zone2-pre',
                gce_zone='us-east2-a',
                instance_count=997,
                instance_template='external-pre-zone2',
                distribute=True,
                worker=False,
                high_end=False),
            compute_engine_projects.Cluster(
                name='oss-fuzz-linux-zone3-host',
                gce_zone='us-central1-d',
                instance_count=2,
                instance_template='host-zone3',
                distribute=False,
                worker=False,
                high_end=False),
            compute_engine_projects.Cluster(
                name='oss-fuzz-linux-zone3-worker',
                gce_zone='us-central1-d',
                instance_count=16,
                instance_template='worker-zone3',
                distribute=True,
                worker=True,
                high_end=False),
            compute_engine_projects.Cluster(
                name='oss-fuzz-linux-zone3-host-high-end',
                gce_zone='us-central1-d',
                instance_count=1,
                instance_template='host-high-end-zone3',
                distribute=False,
                worker=False,
                high_end=True),
            compute_engine_projects.Cluster(
                name='oss-fuzz-linux-zone3-worker-high-end',
                gce_zone='us-central1-d',
                instance_count=2,
                instance_template='worker-zone3',
                distribute=True,
                worker=True,
                high_end=True),
        ],
        instance_templates=[
            {
                'name': 'external-pre-zone2',
                'description': '{"version": 1}',
                'properties': {
                    'metadata': {
                        'items': [],
                    },
                    'disks': [{
                        'initializeParams': {
                            'diskSizeGb': 30,
                        },
                    }],
                    'serviceAccounts': [{
                        'email':
                            'email',
                        'scopes': [
                            'https://www.googleapis.com/auth/'
                            'devstorage.full_control',
                            'https://www.googleapis.com/auth/logging.write',
                            'https://www.googleapis.com/auth/userinfo.email',
                            'https://www.googleapis.com/auth/appengine.apis',
                            'https://www.googleapis.com/auth/prodxmon',
                            'https://www.googleapis.com/auth/bigquery',
                        ]
                    }],
                }
            },
            {
                'name': 'host-zone3',
                'description': '{"version": 1}',
                'properties': {
                    'metadata': {
                        'items': [],
                    },
                    'disks': [{
                        'initializeParams': {
                            'diskSizeGb': 30,
                        },
                    }],
                    'serviceAccounts': [{
                        'email':
                            'email',
                        'scopes': [
                            'https://www.googleapis.com/auth/'
                            'devstorage.full_control',
                            'https://www.googleapis.com/auth/logging.write',
                            'https://www.googleapis.com/auth/userinfo.email',
                            'https://www.googleapis.com/auth/appengine.apis',
                            'https://www.googleapis.com/auth/prodxmon',
                            'https://www.googleapis.com/auth/bigquery',
                        ]
                    }],
                }
            },
            {
                'name': 'worker-zone3',
                'description': '{"version": 1}',
                'properties': {
                    'metadata': {
                        'items': [],
                    },
                    'disks': [{
                        'initializeParams': {
                            'diskSizeGb': 30,
                        },
                    }],
                    'serviceAccounts': [{
                        'email':
                            'email',
                        'scopes': [
                            'https://www.googleapis.com/auth/'
                            'devstorage.full_control',
                            'https://www.googleapis.com/auth/logging.write',
                            'https://www.googleapis.com/auth/userinfo.email',
                            'https://www.googleapis.com/auth/prodxmon',
                        ]
                    }],
                }
            },
            {
                'name': 'host-high-end-zone3',
                'description': '{"version": 1}',
                'properties': {
                    'metadata': {
                        'items': [],
                    },
                    'disks': [{
                        'initializeParams': {
                            'diskSizeGb': 100,
                        },
                    }],
                    'serviceAccounts': [{
                        'email':
                            'email',
                        'scopes': [
                            'https://www.googleapis.com/auth/'
                            'devstorage.full_control',
                            'https://www.googleapis.com/auth/logging.write',
                            'https://www.googleapis.com/auth/userinfo.email',
                            'https://www.googleapis.com/auth/prodxmon',
                        ]
                    }],
                }
            },
        ],
        host_worker_assignments=[
            compute_engine_projects.HostWorkerAssignment(
                host='oss-fuzz-linux-zone3-host',
                worker='oss-fuzz-linux-zone3-worker',
                workers_per_host=8),
            compute_engine_projects.HostWorkerAssignment(
                host='oss-fuzz-linux-zone3-host-high-end',
                worker='oss-fuzz-linux-zone3-worker-high-end',
                workers_per_host=2),
        ])

    data_types.OssFuzzProject(
        id='proj1',
        name='proj1',
        cpu_weight=1.0,
        service_account='*****@*****.**').put()

    data_types.OssFuzzProject(
        id='proj2',
        name='proj2',
        cpu_weight=2.0,
        service_account='*****@*****.**').put()

    data_types.OssFuzzProject(
        id='proj3',
        name='proj3',
        cpu_weight=5.0,
        service_account='*****@*****.**').put()

    data_types.OssFuzzProject(
        id='proj4',
        name='proj4',
        cpu_weight=1.0,
        service_account='*****@*****.**').put()

    data_types.OssFuzzProject(
        id='proj5',
        name='proj5',
        cpu_weight=1.0,
        service_account='*****@*****.**',
        disk_size_gb=10).put()

    data_types.OssFuzzProject(
        id='proj6',
        name='proj6',
        cpu_weight=1.0,
        service_account='*****@*****.**',
        high_end=True).put()

    for j in range(1, 7):
      project_name = 'proj%d' % j
      data_types.WorkerTlsCert(
          id=project_name,
          project_name=project_name,
          cert_contents=project_name + '_cert',
          key_contents=project_name + '_key').put()

    data_types.OssFuzzProjectInfo(id='old_proj', name='old_proj').put()

    data_types.OssFuzzProjectInfo(
        id='proj2',
        name='proj2',
        clusters=[
            data_types.OssFuzzProjectInfo.ClusterInfo(
                cluster='oss-fuzz-linux-zone2-pre',
                gce_zone='us-east2-a',
                cpu_count=1,
            ),
            data_types.OssFuzzProjectInfo.ClusterInfo(
                cluster='old-cluster',
                gce_zone='us-east2-a',
                cpu_count=1,
            ),
        ]).put()

    data_types.OssFuzzProjectInfo(
        id='proj3',
        name='proj3',
        clusters=[
            data_types.OssFuzzProjectInfo.ClusterInfo(
                cluster='oss-fuzz-linux-zone2-pre',
                gce_zone='us-east2-a',
                cpu_count=499,
            )
        ]).put()

    data_types.OssFuzzProjectInfo(
        id='proj4',
        name='proj4',
        clusters=[
            data_types.OssFuzzProjectInfo.ClusterInfo(
                cluster='oss-fuzz-linux-zone2-pre',
                gce_zone='us-east2-a',
                cpu_count=99,
            )
        ]).put()

    data_types.OssFuzzProjectInfo(
        id='proj5',
        name='proj5',
        clusters=[
            data_types.OssFuzzProjectInfo.ClusterInfo(
                cluster='oss-fuzz-linux-zone2-pre',
                gce_zone='us-east2-a',
                cpu_count=99,
            )
        ]).put()

    data_types.OssFuzzProjectInfo(
        id='old_proj',
        name='old_proj',
        clusters=[
            data_types.OssFuzzProjectInfo.ClusterInfo(
                cluster='oss-fuzz-linux-zone2-pre',
                gce_zone='us-east2-a',
                cpu_count=5,
            )
        ]).put()

    data_types.HostWorkerAssignment(
        id='old-host-0',
        host_name='old-host',
        worker_name='worker',
        instance_num=0).put()

    instance_groups = {}
    instance_templates = {}
    self.mock.BotManager.side_effect = functools.partial(
        MockBotManager,
        instance_groups=instance_groups,
        instance_templates=instance_templates)