Compare commits

...

6 Commits

3 changed files with 32 additions and 13 deletions

View File

@ -20,10 +20,6 @@ if 'CONFIGURATION_DIR' in environ:
CONFIGURATION_DIR = environ['CONFIGURATION_DIR']
else:
CONFIGURATION_DIR = config.get('CONFIGURATION_DIR', '/srv/risotto/configurations')
if 'PROVIDER_FACTORY_CONFIG_DIR' in environ:
PROVIDER_FACTORY_CONFIG_DIR = environ['PROVIDER_FACTORY_CONFIG_DIR']
else:
PROVIDER_FACTORY_CONFIG_DIR = config.get('PROVIDER_FACTORY_CONFIG_DIR', '/srv/factory')
if 'DEFAULT_USER' in environ:
DEFAULT_USER = environ['DEFAULT_USER']
else:
@ -52,6 +48,18 @@ if 'TIRAMISU_DB_USER' in environ:
TIRAMISU_DB_USER = environ['TIRAMISU_DB_USER']
else:
TIRAMISU_DB_USER = config.get('TIRAMISU_DB_USER', 'tiramisu')
if 'CELERYRISOTTO_DB_NAME' in environ:
CELERYRISOTTO_DB_NAME = environ['CELERYRISOTTO_DB_NAME']
else:
CELERYRISOTTO_DB_NAME = config.get('CELERYRISOTTO_DB_NAME', None)
if 'CELERYRISOTTO_DB_PASSWORD' in environ:
CELERYRISOTTO_DB_PASSWORD = environ['CELERYRISOTTO_DB_PASSWORD']
else:
CELERYRISOTTO_DB_PASSWORD = config.get('CELERYRISOTTO_DB_PASSWORD', None)
if 'CELERYRISOTTO_DB_USER' in environ:
CELERYRISOTTO_DB_USER = environ['CELERYRISOTTO_DB_USER']
else:
CELERYRISOTTO_DB_USER = config.get('CELERYRISOTTO_DB_USER', None)
if 'DB_ADDRESS' in environ:
DB_ADDRESS = environ['DB_ADDRESS']
else:
@ -76,6 +84,10 @@ if 'TMP_DIR' in environ:
TMP_DIR = environ['TMP_DIR']
else:
TMP_DIR = config.get('TMP_DIR', '/tmp')
if 'IMAGE_PATH' in environ:
IMAGE_PATH = environ['IMAGE_PATH']
else:
IMAGE_PATH = config.get('IMAGE_PATH', '/tmp')
def dsn_factory(database, user, password, address=DB_ADDRESS):
@ -85,6 +97,7 @@ def dsn_factory(database, user, password, address=DB_ADDRESS):
_config = {'database': {'dsn': dsn_factory(RISOTTO_DB_NAME, RISOTTO_DB_USER, RISOTTO_DB_PASSWORD),
'tiramisu_dsn': dsn_factory(TIRAMISU_DB_NAME, TIRAMISU_DB_USER, TIRAMISU_DB_PASSWORD),
'celery_dsn': dsn_factory(CELERYRISOTTO_DB_NAME, CELERYRISOTTO_DB_USER, CELERYRISOTTO_DB_PASSWORD)
},
'http_server': {'port': RISOTTO_PORT,
'default_user': DEFAULT_USER},
@ -102,8 +115,9 @@ _config = {'database': {'dsn': dsn_factory(RISOTTO_DB_NAME, RISOTTO_DB_USER, RIS
'internal_source': 'internal'},
'submodule': {'allow_insecure_https': False,
'pki': '192.168.56.112'},
'provider': {'factory_configuration_dir': PROVIDER_FACTORY_CONFIG_DIR,
'factory_configuration_filename': 'infra.json'},
'provider': {'factory_configuration_filename': 'infra.json',
'packer_filename': 'recipe.json',
'risotto_images_dir': IMAGE_PATH},
}

View File

@ -220,7 +220,6 @@ class PublishDispatcher:
False,
)
for function_obj in self.messages[version][message]['functions']:
print('======', function_obj['function'].__name__)
async with self.pool.acquire() as connection:
try:
await self.check_message_type(risotto_context,
@ -395,10 +394,9 @@ class Dispatcher(register.RegisterDispatcher,
) -> Optional[Dict]:
# so send the message
function = function_obj['function']
submodule_name = function_obj['module']
risotto_context.module = function_obj['module'].split('.', 1)[0]
function_name = function.__name__
risotto_context.module = submodule_name.split('.', 1)[0]
info_msg = _(f'in module {submodule_name}.{function_name}')
info_msg = _(f"in function {function_obj['full_module_name']}.{function_name}")
# build argument for this function
if risotto_context.type == 'rpc':
kw = config_arguments

View File

@ -199,7 +199,8 @@ class RegisterDispatcher:
raise RegistrationError(_(f'the message {message} not exists'))
# xxx submodule can only be register with v1.yyy.xxx..... message
risotto_module_name, submodule_name = function.__module__.split('.')[-3:-1]
full_module_name = function.__module__
risotto_module_name, submodule_name = full_module_name.split('.')[-3:-1]
module_name = risotto_module_name.split('_')[-1]
message_module, message_submodule, message_name = message.split('.', 2)
if message_module not in self.risotto_modules:
@ -224,6 +225,7 @@ class RegisterDispatcher:
register(version,
message,
f'{module_name}.{submodule_name}',
full_module_name,
function,
function_args,
notification,
@ -233,11 +235,13 @@ class RegisterDispatcher:
version: str,
message: str,
module_name: str,
full_module_name: str,
function: Callable,
function_args: list,
notification: Optional[str],
):
self.messages[version][message]['module'] = module_name
self.messages[version][message]['full_module_name'] = full_module_name
self.messages[version][message]['function'] = function
self.messages[version][message]['arguments'] = function_args
if notification:
@ -247,6 +251,7 @@ class RegisterDispatcher:
version: str,
message: str,
module_name: str,
full_module_name: str,
function: Callable,
function_args: list,
notification: Optional[str],
@ -255,8 +260,10 @@ class RegisterDispatcher:
self.messages[version][message]['functions'] = []
dico = {'module': module_name,
'full_module_name': full_module_name,
'function': function,
'arguments': function_args}
'arguments': function_args,
}
if notification and notification:
dico['notification'] = notification
self.messages[version][message]['functions'].append(dico)
@ -309,7 +316,7 @@ class RegisterDispatcher:
risotto_context.type = None
risotto_context.connection = connection
risotto_context.module = submodule_name.split('.', 1)[0]
info_msg = _(f'in module risotto_{submodule_name}.on_join')
info_msg = _(f'in function risotto_{submodule_name}.on_join')
await log.info_msg(risotto_context,
None,
info_msg)