def testHandleConnectionError(self, method, expected):
        self._SetUpFile('True',
                        self.current_time - gce_cache._GCE_CACHE_MAX_AGE)
        gce_cache._SINGLETON_ON_GCE_CACHE = gce_cache._OnGCECache()

        self.assertTrue(gce_cache.GetOnGCE())
        md = gce._GCEMetadata()
        self.assertTrue(md.connected)

        # The server is set up to be an error though, so reset things when it fails.
        self.assertEqual(expected, method(md))
        # Class thinks it's no longer connected.
        self.assertFalse(md.connected)
        # Cache was actually reset also.
        self.assertFalse(gce_cache.GetOnGCE())
        self.AssertFileExistsWithContents('False', self.tempfilepath)
Beispiel #2
0
def GetMetricsEnvironment():
    """Get the metrics environment.

  Returns the property metrics/environment if set, if not, it tries to deduce if
  we're on some known platforms like devshell or GCE.

  Returns:
    None, if no environment is set or found
    str, a string denoting the environment if one is set or found
  """

    environment = VALUES.metrics.environment.Get()
    if environment:
        return environment

    # No explicit environment defined, try to deduce it.
    if c_devshell.IsDevshellEnvironment():
        return 'devshell'
    if gce_cache.GetOnGCE(check_age=False):
        return 'GCE'

    return None
Beispiel #3
0
 def __init__(self):
     self.connected = gce_cache.GetOnGCE()