def test_get_metadata_by_address(self, mock_net_api, mock_get_context): mock_get_context.return_value = "CONTEXT" api = mock.Mock() fixed_ip = objects.FixedIP(instance_uuid="2bfd8d71-6b69-410c-a2f5-dbca18d02966") api.get_fixed_ip_by_address.return_value = fixed_ip mock_net_api.return_value = api with mock.patch.object(base, "get_metadata_by_instance_id") as gmd: base.get_metadata_by_address("foo") api.get_fixed_ip_by_address.assert_called_once_with("CONTEXT", "foo") gmd.assert_called_once_with(fixed_ip.instance_uuid, "foo", "CONTEXT")
def get_metadata_by_remote_address(self, address): if not address: raise exception.FixedIpNotFoundForAddress(address=address) cache_key = 'metadata-%s' % address data = self._cache.get(cache_key) if data: return data try: data = base.get_metadata_by_address(self.conductor_api, address) except exception.NotFound: return None self._cache.set(cache_key, data, CACHE_EXPIRATION) return data
def get_metadata(self, address): if not address: raise exception.FixedIpNotFoundForAddress(address=address) cache_key = 'metadata-%s' % address data = self._cache.get(cache_key) if data: return data try: data = base.get_metadata_by_address(address) except exception.NotFound: return None self._cache.set(cache_key, data, 15) return data
def get_metadata_by_remote_address(self, address): if not address: raise exception.FixedIpNotFoundForAddress(address=address) cache_key = 'metadata-%s' % address data = self._cache.get(cache_key) if data: LOG.debug("Using cached metadata for %s", address) return data try: data = base.get_metadata_by_address(address) except exception.NotFound: return None if CONF.metadata_cache_expiration > 0: self._cache.set(cache_key, data, CONF.metadata_cache_expiration) return data
def get_metadata_by_remote_address(self, address): if not address: raise exception.FixedIpNotFoundForAddress(address=address) cache_key = 'metadata-%s' % address data = self._cache.get(cache_key) if data: LOG.debug("Using cached metadata for %s", address) return data try: data = base.get_metadata_by_address(address) except exception.NotFound: return None if CONF.metadata_cache_expiration > 0: self._cache.set(cache_key, data) return data