def setUp(self):
    self.config_directory = tempfile.mkdtemp()

    self.mock_sleep = mock.create_autospec(time.sleep, spec_set=True)

    self.mock_ownservice_ctor = mock.patch(
        'infra.services.service_manager.service.OwnService',
        autospec=True).start()
    self.mock_thread_ctor = mock.patch(
        'infra.services.service_manager.service_thread.ServiceThread',
        autospec=True).start()
    self.mock_thread = self.mock_thread_ctor.return_value
    self.mock_ownservice = self.mock_ownservice_ctor.return_value
    self.mock_ownservice.start.return_value = True
    self.mock_ownservice.has_version_changed.return_value = False
    self.mock_cloudtail = cloudtail_factory.DummyCloudtailFactory()

    self.cw = config_watcher.ConfigWatcher(
        self.config_directory,
        42,
        43,
        '/state',
        '/rootdir',
        self.mock_cloudtail,
        _sleep_fn=self.mock_sleep)
Esempio n. 2
0
  def setUp(self):
    super(ServiceTestBase, self).setUp()

    self.mock_sleep = mock.Mock(time.sleep)
    self.mock_time = mock.Mock(time.time)
    self.mock_time.return_value = 1234

    self.s = service.Service(
        self.state_directory,
        config_watcher.parse_config(self._CONFIG_JSON),
        cloudtail_factory.DummyCloudtailFactory(),
        _time_fn=self.mock_time,
        _sleep_fn=self.mock_sleep)

    if sys.platform == 'win32':  # pragma: no cover
      self.mock_fork = mock.Mock()
      self.mock_setrlimit = mock.Mock()
    else:
      self.mock_fork = mock.patch('os.fork', autospec=True).start()
      self.mock_setrlimit = (
          mock.patch('resource.setrlimit', autospec=True).start())

    self.mock_pipe = mock.patch('os.pipe', autospec=True).start()
    self.mock_close = mock.patch('os.close', autospec=True).start()
    self.mock_exit = mock.patch('os._exit', autospec=True).start()
    self.mock_fdopen = mock.patch('os.fdopen', autospec=True).start()
    self.mock_waitpid = mock.patch('os.waitpid', autospec=True).start()
    self.mock_execve = mock.patch('os.execve', autospec=True).start()
    self.mock_kill = mock.patch('os.kill', autospec=True).start()
    self.mock_become_daemon = mock.patch(
        'infra.libs.service_utils.daemon.become_daemon', autospec=True).start()
    self.mock_close_all_fds = mock.patch(
        'infra.libs.service_utils.daemon.close_all_fds', autospec=True).start()
    self.mock_chdir = mock.patch('os.chdir', autospec=True).start()
Esempio n. 3
0
  def main(self, opts):
    if opts.cloudtail_path:
      cloudtail = cloudtail_factory.CloudtailFactory(
          opts.cloudtail_path,
          opts.cloudtail_ts_mon_credentials)
    else:
      cloudtail = cloudtail_factory.DummyCloudtailFactory()

    watcher = config_watcher.ConfigWatcher(
        opts.config_directory,
        opts.config_poll_interval,
        opts.service_poll_interval,
        opts.state_directory,
        opts.cipd_version_file,
        cloudtail)

    def sigint_handler(_signal, _frame):
      watcher.stop()

    previous_sigint_handler = signal.signal(signal.SIGINT, sigint_handler)
    watcher.run()
    signal.signal(signal.SIGINT, previous_sigint_handler)
Esempio n. 4
0
    def test_start(self):
        f = cloudtail_factory.DummyCloudtailFactory()

        with self.assertRaises(OSError):
            f.start('foo', mock.Mock())