Example #1
0
    def test_explicit_cipd_version_file_empty_string(self):
        self.config['cipd_version_file'] = ''
        self.assertEqual({}, version_finder.find_version(self.config))

        with open(os.path.join(self.path, 'CIPD_VERSION.json'), 'w') as fh:
            fh.write('{"package_name": "foo", "instance_id": "bar"}')

        self.assertEqual(
            {
                'cipd_version_file': {
                    'package_name': 'foo',
                    'instance_id': 'bar',
                }
            }, version_finder.find_version(self.config))
Example #2
0
  def has_version_changed(self, state):
    """Returns True if the version has changed since the process started."""

    if state.version is None:
      return False

    return state.version != version_finder.find_version(self.config)
Example #3
0
  def has_version_changed(self, state):
    """Returns True if the version has changed since the process started."""

    if state.version is None:
      return False

    return state.version != version_finder.find_version(self.config)
Example #4
0
  def test_cipd_version_file(self):
    with open(os.path.join(self.path, 'CIPD_VERSION.json'), 'w') as fh:
      fh.write('{"package_name": "foo", "instance_id": "bar"}')

    self.assertEqual({'cipd_version_file': {
        'package_name': 'foo',
        'instance_id': 'bar',
    }}, version_finder.find_version(self.config))
Example #5
0
  def _write_state_file(self, pid):
    try:
      state = ProcessState.from_pid(pid)
    except ProcessStateError as ex:
      raise ServiceException(
          'Failed to start %s: daemon process exited (%r)' % (self.name, ex))

    state.version = version_finder.find_version(self.config)
    state.cmd = self._cmd
    state.write_to_file(self._state_file)
Example #6
0
  def _write_state_file(self, pid):
    try:
      state = ProcessState.from_pid(pid)
    except ProcessStateError as ex:
      raise ServiceException(
          'Failed to start %s: daemon process exited (%r)' % (self.name, ex))

    state.version = version_finder.find_version(self.config)
    state.args = self.args
    state.write_to_file(self._state_file)
Example #7
0
    def test_cipd_version_file(self):
        with open(self.cipd_version_file, 'w') as fh:
            fh.write('{"package_name": "foo", "instance_id": "bar"}')

        self.assertEqual(
            {
                'cipd_version_file': {
                    'package_name': 'foo',
                    'instance_id': 'bar',
                }
            }, version_finder.find_version(self.config))
Example #8
0
    def test_explicit_cipd_version_file(self):
        self.config['cipd_version_file'] = os.path.join(self.path, 'foo')
        with open(self.config['cipd_version_file'], 'w') as fh:
            fh.write('{"package_name": "foo", "instance_id": "bar"}')

        self.assertEqual(
            {
                'cipd_version_file': {
                    'package_name': 'foo',
                    'instance_id': 'bar',
                }
            }, version_finder.find_version(self.config))
Example #9
0
    def has_version_changed(self, state):
        """Returns True if the version has changed since the process started.

    Args:
      state(ProcessState): a process state.

    Returns:
      changed(bool): True if the running version does not match the one
        deployed on disk.
    """

        if state.version is None:
            return False

        deployed_version = version_finder.find_version(self.config)
        if state.version != deployed_version:
            LOGGER.info('Version changed: %s -> %s. (cmd: %s)' %
                        (state.version, deployed_version, str(state.cmd)))
            return True
        return False
Example #10
0
  def has_version_changed(self, state):
    """Returns True if the version has changed since the process started.

    Args:
      state(ProcessState): a process state.

    Returns:
      changed(bool): True if the running version does not match the one
        deployed on disk.
    """

    if state.version is None:
      return False

    deployed_version = version_finder.find_version(self.config)
    if state.version != deployed_version:
      LOGGER.info('Version changed: %s -> %s. (cmd: %s)'
                  % (state.version, deployed_version, str(state.cmd)))
      return True
    return False
Example #11
0
 def test_explicit_cipd_version_file_does_not_exist(self):
     self.config['cipd_version_file'] = os.path.join(self.path, 'foo')
     self.assertEqual({}, version_finder.find_version(self.config))
Example #12
0
 def test_missing_directory(self):
     self.assertEqual({},
                      version_finder.find_version({
                          'root_directory':
                          '/does/not/exist',
                      }))
Example #13
0
 def test_empty_directory(self):
     self.assertEqual({}, version_finder.find_version(self.config))
Example #14
0
 def test_explicit_cipd_version_file_empty_string(self):
     self.config['cipd_version_file'] = ''
     self.assertEqual({}, version_finder.find_version(self.config))
Example #15
0
 def test_missing_directory(self):
   self.assertEqual({}, version_finder.find_version({
       'root_directory': '/does/not/exist',
   }))
Example #16
0
 def test_empty_directory(self):
   self.assertEqual({}, version_finder.find_version(self.config))