Example #1
0
  def test_write_service(self):
    self.assertEquals(0, root_setup.root_setup())
    root_setup.write_service('foo', 'bar', 'baz', [1, 2])

    path = os.path.join(root_setup.SERVICES_DIRECTORY, 'foo.json')
    contents = open(path).read()
    self.assertEquals({
        'name': 'foo',
        'root_directory': 'bar',
        'tool': 'baz',
        'args': [1, 2],
    }, json.loads(contents))
Example #2
0
  def test_write_service(self):
    self.assertEquals(0, root_setup.root_setup())
    root_setup.write_service('foo', 'bar', 'baz', [1, 2])

    path = os.path.join(root_setup.SERVICES_DIRECTORY, 'foo.json')
    contents = open(path).read()
    self.assertEquals({
        'name': 'foo',
        'root_directory': 'bar',
        'tool': 'baz',
        'args': [1, 2],
    }, json.loads(contents))
Example #3
0
  def main(self, opts):
    if opts.root_setup:
      return root_setup.root_setup()

    cloudtail_active = experiments.is_active_for_host(
        'cloudtail', opts.cloudtail_experiment_percent)

    watcher = config_watcher.ConfigWatcher(
        opts.config_directory,
        opts.config_poll_interval,
        opts.service_poll_interval,
        opts.state_directory,
        opts.root_directory,
        opts.cloudtail_path if cloudtail_active else None)

    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)
Example #4
0
    def main(self, opts):
        if opts.root_setup:
            return root_setup.root_setup()

        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.root_directory, 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)
Example #5
0
def main(argv):
  opts = parse_args(argv)

  if opts.root_setup:
    return root_setup.root_setup()

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

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

  try:
    previous_sigint_handler = signal.signal(signal.SIGINT, sigint_handler)
    watcher.run()
    signal.signal(signal.SIGINT, previous_sigint_handler)
  finally:
    ts_mon.close()

  return 0
Example #6
0
def main(argv):
  opts = parse_args(argv)

  if opts.root_setup:
    return root_setup.root_setup()

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

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

  try:
    previous_sigint_handler = signal.signal(signal.SIGINT, sigint_handler)
    watcher.run()
    signal.signal(signal.SIGINT, previous_sigint_handler)
  finally:
    ts_mon.close()

  return 0
Example #7
0
 def test_non_root(self):
   self.mock_getuid.return_value = 42
   self.assertEquals(1, root_setup.root_setup())
Example #8
0
 def test_does_not_restart_service(self):
   self.mock_check_output.return_value = 'service_manager start/running'
   self.assertEquals(0, root_setup.root_setup())
   self.assertEquals(1, self.mock_check_call.call_count)
Example #9
0
 def test_starts_service(self):
   self.assertEquals(0, root_setup.root_setup())
   self.assertEquals(2, self.mock_check_call.call_count)
   self.mock_check_call.assert_called_with(
       ['initctl', 'start', 'service_manager'])
Example #10
0
 def test_writes_upstart_config(self):
   self.assertFalse(os.path.exists(root_setup.UPSTART_CONFIG_FILENAME))
   self.assertEquals(0, root_setup.root_setup())
   contents = open(root_setup.UPSTART_CONFIG_FILENAME).read()
   self.assertIn('run.py infra.services.service_manager', contents)
Example #11
0
 def test_services_directory_already_exists(self):
   os.mkdir(root_setup.SERVICES_DIRECTORY)
   self.assertEquals(0, root_setup.root_setup())
   self.assertTrue(os.path.exists(root_setup.SERVICES_DIRECTORY))
Example #12
0
 def test_creates_services_directory(self):
   self.assertFalse(os.path.exists(root_setup.SERVICES_DIRECTORY))
   self.assertEquals(0, root_setup.root_setup())
   self.assertTrue(os.path.exists(root_setup.SERVICES_DIRECTORY))
Example #13
0
 def test_non_root(self):
   self.mock_getuid.return_value = 42
   self.assertEquals(1, root_setup.root_setup())
Example #14
0
 def test_creates_services_directory(self):
   self.assertFalse(os.path.exists(root_setup.SERVICES_DIRECTORY))
   self.assertEquals(0, root_setup.root_setup())
   self.assertTrue(os.path.exists(root_setup.SERVICES_DIRECTORY))
Example #15
0
 def test_does_not_restart_service(self):
   self.mock_check_output.return_value = 'service_manager start/running'
   self.assertEquals(0, root_setup.root_setup())
   self.assertEquals(1, self.mock_check_call.call_count)
Example #16
0
 def test_starts_service(self):
   self.assertEquals(0, root_setup.root_setup())
   self.assertEquals(2, self.mock_check_call.call_count)
   self.mock_check_call.assert_called_with(
       ['initctl', 'start', 'service_manager'])
Example #17
0
 def test_writes_upstart_config(self):
   self.assertFalse(os.path.exists(root_setup.UPSTART_CONFIG_FILENAME))
   self.assertEquals(0, root_setup.root_setup())
   contents = open(root_setup.UPSTART_CONFIG_FILENAME).read()
   self.assertIn('run.py infra.services.service_manager', contents)
Example #18
0
 def test_services_directory_already_exists(self):
   os.mkdir(root_setup.SERVICES_DIRECTORY)
   self.assertEquals(0, root_setup.root_setup())
   self.assertTrue(os.path.exists(root_setup.SERVICES_DIRECTORY))