Example #1
0
    def test_get_metadata_by_instance_id_null_context(self, mock_uuid, mock_context):
        inst = objects.Instance()
        mock_uuid.return_value = inst
        mock_context.return_value = "CONTEXT"

        with mock.patch.object(base, "InstanceMetadata") as imd:
            base.get_metadata_by_instance_id("foo", "bar")

        mock_context.assert_called_once_with()
        mock_uuid.assert_called_once_with(
            "CONTEXT", "foo", expected_attrs=["ec2_ids", "flavor", "info_cache", "metadata", "system_metadata"]
        )
        imd.assert_called_once_with(inst, "bar")
Example #2
0
    def test_get_metadata_by_instance_id(self, mock_uuid, mock_context):
        inst = objects.Instance()
        mock_uuid.return_value = inst

        with mock.patch.object(base, "InstanceMetadata") as imd:
            base.get_metadata_by_instance_id("foo", "bar", ctxt="CONTEXT")

        self.assertFalse(
            mock_context.called, "get_admin_context() should not" "have been called, the context was given"
        )
        mock_uuid.assert_called_once_with(
            "CONTEXT", "foo", expected_attrs=["ec2_ids", "flavor", "info_cache", "metadata", "system_metadata"]
        )
        imd.assert_called_once_with(inst, "bar")
Example #3
0
    def get_metadata_by_instance_id(self, instance_id, address):
        cache_key = 'metadata-%s' % instance_id
        data = self._cache.get(cache_key)
        if data:
            return data

        try:
            data = base.get_metadata_by_instance_id(instance_id, address)
        except exception.NotFound:
            return None

        self._cache.set(cache_key, data, CACHE_EXPIRATION)

        return data
Example #4
0
    def get_metadata_by_instance_id(self, instance_id, address):
        cache_key = 'metadata-%s' % instance_id
        data = self._cache.get(cache_key)
        if data:
            LOG.debug("Using cached metadata for instance %s", instance_id)
            return data

        try:
            data = base.get_metadata_by_instance_id(instance_id, address)
        except exception.NotFound:
            return None

        if CONF.metadata_cache_expiration > 0:
            self._cache.set(cache_key, data, CONF.metadata_cache_expiration)

        return data
Example #5
0
    def get_metadata_by_instance_id(self, instance_id, address):
        cache_key = 'metadata-%s' % instance_id
        data = self._cache.get(cache_key)
        if data:
            LOG.debug("Using cached metadata for instance %s", instance_id)
            return data

        try:
            data = base.get_metadata_by_instance_id(instance_id, address)
        except exception.NotFound:
            return None

        if CONF.metadata_cache_expiration > 0:
            self._cache.set(cache_key, data)

        return data