Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/inmanta/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,18 +975,18 @@ def _ensure_code(self, environment, version, resourcetypes):
result = yield self._client.get_code(environment, version, rt)

if result.code == 200:
for key, source in result.result["sources"].items():
for hash_value, (path, name, content, requires) in result.result["sources"].items():
try:
LOGGER.debug("Installing handler %s for %s", rt, source[1])
yield self._install(key, source)
LOGGER.debug("Installed handler %s for %s", rt, source[1])
LOGGER.debug("Installing handler %s for %s", rt, name)
yield self._install(hash_value, name, content, requires)
LOGGER.debug("Installed handler %s for %s", rt, name)
except Exception:
LOGGER.exception("Failed to install handler %s for %s", rt, source[1])
LOGGER.exception("Failed to install handler %s for %s", rt, name)

@gen.coroutine
def _install(self, key, source):
yield self.thread_pool.submit(self._env.install_from_list, source[3], True)
yield self.thread_pool.submit(self._loader.deploy_version, key, source)
def _install(self, hash_value, module_name, module_source, module_requires):
yield self.thread_pool.submit(self._env.install_from_list, module_requires, True)
yield self.thread_pool.submit(self._loader.deploy_version, hash_value, module_name, module_source)

@protocol.handle(methods.trigger, env="tid", agent="id")
@gen.coroutine
Expand Down
33 changes: 6 additions & 27 deletions src/inmanta/agent/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Contact: code@inmanta.com
"""

import hashlib
import inspect
import logging
import base64
Expand All @@ -27,10 +26,10 @@


from tornado import concurrent
from typing import Tuple

from inmanta.agent.io import get_io
from inmanta import protocol, resources, const, data_pg as data
from inmanta.module import Project
from inmanta.agent.cache import AgentCache
import uuid
from typing import Dict
Expand Down Expand Up @@ -848,32 +847,12 @@ def add_provider(cls, resource: str, name: str, provider):
cls.__command_functions[resource][name] = provider

@classmethod
def sources(cls):
def get_providers(cls) -> typing.Iterator[Tuple[str, typing.Type["ResourceHandler"]]]:
""" Return an iterator over resource type, handler definition
"""
Get all source files that define resources
"""
resource_to_sources = {}
for resource, providers in cls.__command_functions.items():
sources = {}
resource_to_sources[resource] = sources
for provider in providers.values():
file_name = inspect.getsourcefile(provider)

source_code = ""
with open(file_name, "r") as fd:
source_code = fd.read()

sha1sum = hashlib.new("sha1")
sha1sum.update(source_code.encode("utf-8"))

hv = sha1sum.hexdigest()

if hv not in sources:
module_name = provider.__module__.split(".")[1]
req = Project.get().modules[module_name].get_python_requirements_as_list()
sources[hv] = (file_name, provider.__module__, source_code, req)

return resource_to_sources
for resource_type, handler_map in cls.__command_functions.items():
for handle_name, handler_class in handler_map.items():
yield (resource_type, handler_class)

@classmethod
def get_provider_class(cls, resource_type, name):
Expand Down
3 changes: 2 additions & 1 deletion src/inmanta/execute/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from copy import copy
from collections import Mapping
from typing import Union, Any

from inmanta.execute.util import Unknown, NoneValue
from inmanta.ast import RuntimeException
Expand Down Expand Up @@ -74,7 +75,7 @@ def unwrap(cls, item):
return item

@classmethod
def return_value(cls, value):
def return_value(cls, value: Any) -> Union[str, tuple, int, float, bool, "DynamicProxy"]:
if value is None:
return None

Expand Down
Loading