コード例 #1
0
class TestPailgunService(unittest.TestCase):
  def setUp(self):
    self.mock_exiter_class = mock.Mock(side_effect=Exception('should not be called'))
    self.mock_runner_class = mock.Mock(side_effect=Exception('should not be called'))
    self.mock_scheduler_service = mock.Mock(side_effect=Exception('should not be called'))
    self.mock_target_roots_calculator = mock.Mock(side_effect=Exception('should not be called'))
    self.service = PailgunService(bind_addr=(None, None),
                                  runner_class=self.mock_runner_class,
                                  scheduler_service=self.mock_scheduler_service,
                                  shutdown_after_run=False)

  @mock.patch.object(PailgunService, '_setup_pailgun', **PATCH_OPTS)
  def test_pailgun_property_values(self, mock_setup):
    fake_pailgun = FakePailgun()
    mock_setup.return_value = fake_pailgun
    self.assertIs(self.service.pailgun, fake_pailgun)
    self.assertEqual(self.service.pailgun_port, 33333)

  @mock.patch.object(PailgunService, 'terminate', **PATCH_OPTS)
  def test_pailgun_service_closes_when_callback_is_called(self, mock_setup):
    fake_pailgun = FakePailgun()
    mock_setup.return_value = fake_pailgun
    self.service._shutdown_after_run = True
    self.service._request_complete_callback()
    self.assertIs(self.service.terminate.called, True)
コード例 #2
0
ファイル: pants_daemon.py プロジェクト: wiwa/pants
    def _setup_services(
        build_root,
        bootstrap_options,
        legacy_graph_scheduler,
        native,
        watchman,
        union_membership: UnionMembership,
    ):
        """Initialize pantsd services.

        :returns: A PantsServices instance.
        """
        native.override_thread_logging_destination_to_just_pantsd()
        fs_event_service = (FSEventService(
            watchman,
            scheduler=legacy_graph_scheduler.scheduler,
            build_root=build_root)
                            if bootstrap_options.watchman_enable else None)

        invalidation_globs = OptionsInitializer.compute_pantsd_invalidation_globs(
            build_root, bootstrap_options)

        scheduler_service = SchedulerService(
            fs_event_service=fs_event_service,
            legacy_graph_scheduler=legacy_graph_scheduler,
            build_root=build_root,
            invalidation_globs=invalidation_globs,
            union_membership=union_membership,
        )

        pailgun_service = PailgunService(
            bootstrap_options.pantsd_pailgun_port,
            DaemonPantsRunner(scheduler_service),
            scheduler_service,
        )

        store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

        return PantsServices(
            services=tuple(service for service in (
                fs_event_service,
                scheduler_service,
                pailgun_service,
                store_gc_service,
            ) if service is not None),
            port_map=dict(pailgun=pailgun_service.pailgun_port()),
        )
コード例 #3
0
        def _setup_services(
            build_root,
            bootstrap_options,
            legacy_graph_scheduler,
            watchman,
            union_membership: UnionMembership,
        ):
            """Initialize pantsd services.

            :returns: A PantsServices instance.
            """
            should_shutdown_after_run = bootstrap_options.shutdown_pantsd_after_run
            fs_event_service = (FSEventService(
                watchman,
                build_root,
            ) if bootstrap_options.watchman_enable else None)

            pidfile_absolute = PantsDaemon.metadata_file_path(
                "pantsd", "pid", bootstrap_options.pants_subprocessdir)
            if pidfile_absolute.startswith(build_root):
                pidfile = os.path.relpath(pidfile_absolute, build_root)
            else:
                pidfile = None
                logging.getLogger(__name__).warning(
                    "Not watching pantsd pidfile because subprocessdir is outside of buildroot. Having "
                    "subprocessdir be a child of buildroot (as it is by default) may help avoid stray "
                    "pantsd processes.")

            # TODO make SchedulerService handle fs_event_service_being None
            scheduler_service = SchedulerService(
                fs_event_service=fs_event_service,
                legacy_graph_scheduler=legacy_graph_scheduler,
                build_root=build_root,
                invalidation_globs=OptionsInitializer.
                compute_pantsd_invalidation_globs(build_root,
                                                  bootstrap_options),
                pantsd_pidfile=pidfile,
                union_membership=union_membership,
            )

            pailgun_service = PailgunService(
                (bootstrap_options.pantsd_pailgun_host,
                 bootstrap_options.pantsd_pailgun_port),
                DaemonPantsRunner,
                scheduler_service,
                should_shutdown_after_run,
            )

            store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

            return PantsServices(
                services=tuple(service for service in (
                    fs_event_service,
                    scheduler_service,
                    pailgun_service,
                    store_gc_service,
                ) if service is not None),
                port_map=dict(pailgun=pailgun_service.pailgun_port),
            )
コード例 #4
0
 def setUp(self):
   self.mock_exiter_class = mock.Mock(side_effect=Exception('should not be called'))
   self.mock_runner_class = mock.Mock(side_effect=Exception('should not be called'))
   self.mock_scheduler_service = mock.Mock(side_effect=Exception('should not be called'))
   self.mock_target_roots_calculator = mock.Mock(side_effect=Exception('should not be called'))
   self.service = PailgunService(bind_addr=(None, None),
                                 runner_class=self.mock_runner_class,
                                 scheduler_service=self.mock_scheduler_service,
                                 shutdown_after_run=False)
コード例 #5
0
 def setUp(self):
   self.mock_exiter_class = mock.Mock(side_effect=Exception('should not be called'))
   self.mock_runner_class = mock.Mock(side_effect=Exception('should not be called'))
   self.mock_scheduler_service = mock.Mock(side_effect=Exception('should not be called'))
   self.mock_spec_parser = mock.Mock(side_effect=Exception('should not be called'))
   self.service = PailgunService(bind_addr=(None, None),
                                 exiter_class=self.mock_exiter_class,
                                 runner_class=self.mock_runner_class,
                                 scheduler_service=self.mock_scheduler_service,
                                 spec_parser=self.mock_spec_parser)
コード例 #6
0
 def setUp(self):
     self.mock_exiter_class = mock.Mock(
         side_effect=Exception('should not be called'))
     self.mock_runner_class = mock.Mock(
         side_effect=Exception('should not be called'))
     self.mock_scheduler_service = mock.Mock(
         side_effect=Exception('should not be called'))
     self.mock_target_roots_calculator = mock.Mock(
         side_effect=Exception('should not be called'))
     self.service = PailgunService(
         bind_addr=(None, None),
         runner_class=self.mock_runner_class,
         scheduler_service=self.mock_scheduler_service)
コード例 #7
0
ファイル: pants_daemon.py プロジェクト: sazlin/pants
        def _setup_services(build_root, bootstrap_options,
                            legacy_graph_scheduler, watchman):
            """Initialize pantsd services.

      :returns: A PantsServices instance.
      """
            should_shutdown_after_run = bootstrap_options.shutdown_pantsd_after_run
            fs_event_service = FSEventService(
                watchman,
                build_root,
            )

            pidfile_absolute = PantsDaemon.metadata_file_path(
                'pantsd', 'pid', bootstrap_options.pants_subprocessdir)
            if pidfile_absolute.startswith(build_root):
                pidfile = os.path.relpath(pidfile_absolute, build_root)
            else:
                pidfile = None
                logging.getLogger(__name__).warning(
                    'Not watching pantsd pidfile because subprocessdir is outside of buildroot. Having '
                    'subprocessdir be a child of buildroot (as it is by default) may help avoid stray '
                    'pantsd processes.')

            scheduler_service = SchedulerService(
                fs_event_service,
                legacy_graph_scheduler,
                build_root,
                OptionsInitializer.compute_pantsd_invalidation_globs(
                    build_root, bootstrap_options),
                pidfile,
            )

            pailgun_service = PailgunService(
                (bootstrap_options.pantsd_pailgun_host,
                 bootstrap_options.pantsd_pailgun_port),
                DaemonPantsRunner,
                scheduler_service,
                should_shutdown_after_run,
            )

            store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

            return PantsServices(
                services=(fs_event_service, scheduler_service, pailgun_service,
                          store_gc_service),
                port_map=dict(pailgun=pailgun_service.pailgun_port),
            )
コード例 #8
0
ファイル: pants_daemon.py プロジェクト: rkstap/pants
    def _setup_services(build_root, bootstrap_options, legacy_graph_scheduler, watchman):
      """Initialize pantsd services.

      :returns: A tuple of (`tuple` service_instances, `dict` port_map).
      """
      fs_event_service = FSEventService(
        watchman,
        build_root,
        bootstrap_options.pantsd_fs_event_workers
      )

      pidfile_absolute = PantsDaemon.metadata_file_path('pantsd', 'pid', bootstrap_options.pants_subprocessdir)
      if pidfile_absolute.startswith(build_root):
        pidfile = os.path.relpath(pidfile_absolute, build_root)
      else:
        pidfile = None
        logging.getLogger(__name__).warning(
          'Not watching pantsd pidfile because subprocessdir is outside of buildroot. Having '
          'subprocessdir be a child of buildroot (as it is by default) may help avoid stray '
          'pantsd processes.'
        )

      scheduler_service = SchedulerService(
        fs_event_service,
        legacy_graph_scheduler,
        build_root,
        bootstrap_options.pantsd_invalidation_globs,
        pidfile,
      )

      pailgun_service = PailgunService(
        bind_addr=(bootstrap_options.pantsd_pailgun_host, bootstrap_options.pantsd_pailgun_port),
        exiter_class=DaemonExiter,
        runner_class=DaemonPantsRunner,
        target_roots_calculator=TargetRootsCalculator,
        scheduler_service=scheduler_service
      )

      store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

      return (
        # Services.
        (fs_event_service, scheduler_service, pailgun_service, store_gc_service),
        # Port map.
        dict(pailgun=pailgun_service.pailgun_port)
      )
コード例 #9
0
  def _setup_services(self):
    """Initialize pantsd services.

    :returns: A tuple of (`tuple` service_instances, `dict` port_map).
    """
    # N.B. This inline import is currently necessary to avoid a circular reference in the import
    # of LocalPantsRunner for use by DaemonPantsRunner. This is because LocalPantsRunner must
    # ultimately import the pantsd services in order to itself launch pantsd.
    from pants.bin.daemon_pants_runner import DaemonExiter, DaemonPantsRunner

    pailgun_service = PailgunService((self._pailgun_host, self._pailgun_port),
                                     DaemonExiter,
                                     DaemonPantsRunner)

    # Construct a mapping of named ports used by the daemon's services. In the default case these
    # will be randomly assigned by the underlying implementation so we can't reference via options.
    port_map = dict(pailgun=pailgun_service.pailgun_port)
    services = (pailgun_service,)

    return services, port_map
コード例 #10
0
    def _setup_services(self, watchman):
        """Initialize pantsd services.

    :returns: A tuple of (`tuple` service_instances, `dict` port_map).
    """
        # N.B. This inline import is currently necessary to avoid a circular reference in the import
        # of LocalPantsRunner for use by DaemonPantsRunner. This is because LocalPantsRunner must
        # ultimately import the pantsd services in order to itself launch pantsd.
        from pants.bin.daemon_pants_runner import DaemonExiter, DaemonPantsRunner

        services = []
        scheduler_service = None
        if self._fs_event_enabled:
            fs_event_service = FSEventService(watchman, self._build_root,
                                              self._fs_event_workers)

            legacy_graph_helper = self._engine_initializer.setup_legacy_graph(
                self._pants_ignore_patterns,
                self._pants_workdir,
                build_ignore_patterns=self._build_ignore_patterns,
                exclude_target_regexps=self._exclude_target_regexp,
                subproject_roots=self._subproject_roots,
            )
            scheduler_service = SchedulerService(fs_event_service,
                                                 legacy_graph_helper)
            services.extend((fs_event_service, scheduler_service))

        pailgun_service = PailgunService(bind_addr=(self._pailgun_host,
                                                    self._pailgun_port),
                                         exiter_class=DaemonExiter,
                                         runner_class=DaemonPantsRunner,
                                         target_roots_class=TargetRoots,
                                         scheduler_service=scheduler_service)
        services.append(pailgun_service)

        # Construct a mapping of named ports used by the daemon's services. In the default case these
        # will be randomly assigned by the underlying implementation so we can't reference via options.
        port_map = dict(pailgun=pailgun_service.pailgun_port)

        return tuple(services), port_map
コード例 #11
0
    def _setup_services(build_root, bootstrap_options, legacy_graph_helper, watchman):
      """Initialize pantsd services.

      :returns: A tuple of (`tuple` service_instances, `dict` port_map).
      """
      fs_event_service = FSEventService(watchman, build_root, bootstrap_options.pantsd_fs_event_workers)
      scheduler_service = SchedulerService(fs_event_service, legacy_graph_helper)
      pailgun_service = PailgunService(
        bind_addr=(bootstrap_options.pantsd_pailgun_host, bootstrap_options.pantsd_pailgun_port),
        exiter_class=DaemonExiter,
        runner_class=DaemonPantsRunner,
        target_roots_class=TargetRoots,
        scheduler_service=scheduler_service
      )
      store_gc_service = StoreGCService(legacy_graph_helper.scheduler)

      return (
        # Services.
        (fs_event_service, scheduler_service, pailgun_service, store_gc_service),
        # Port map.
        dict(pailgun=pailgun_service.pailgun_port)
      )
コード例 #12
0
  def _setup_services(self, watchman):
    """Initialize pantsd services.

    :returns: A tuple of (`tuple` service_instances, `dict` port_map).
    """
    # N.B. This inline import is currently necessary to avoid a circular reference in the import
    # of LocalPantsRunner for use by DaemonPantsRunner. This is because LocalPantsRunner must
    # ultimately import the pantsd services in order to itself launch pantsd.
    from pants.bin.daemon_pants_runner import DaemonExiter, DaemonPantsRunner

    legacy_graph_helper = self._engine_initializer.setup_legacy_graph(
      self._pants_ignore_patterns,
      self._pants_workdir,
      native=self._native,
      build_ignore_patterns=self._build_ignore_patterns,
      exclude_target_regexps=self._exclude_target_regexp,
      subproject_roots=self._subproject_roots,
    )

    fs_event_service = FSEventService(watchman, self._build_root, self._fs_event_workers)
    scheduler_service = SchedulerService(fs_event_service, legacy_graph_helper)
    pailgun_service = PailgunService(
      bind_addr=(self._pailgun_host, self._pailgun_port),
      exiter_class=DaemonExiter,
      runner_class=DaemonPantsRunner,
      target_roots_class=TargetRoots,
      scheduler_service=scheduler_service
    )

    return (
      # Use the schedulers reentrant lock as the daemon's global lock.
      legacy_graph_helper.scheduler.lock,
      # Services.
      (fs_event_service, scheduler_service, pailgun_service),
      # Port map.
      dict(pailgun=pailgun_service.pailgun_port)
    )