update tests

This commit is contained in:
Emmanuel Garette 2020-08-19 17:15:04 +02:00
parent a64131fb03
commit c309ebbd56
3 changed files with 192 additions and 139 deletions

View File

@ -238,11 +238,7 @@ class Dispatcher(register.RegisterDispatcher,
except AttributeError:
if get_config()['global']['debug']:
print_exc()
raise ValueError(_(f'"{uri}" is launch with an unknown: "{key}"'))
except ValueError as err:
if get_config()['global']['debug']:
print_exc()
raise ValueError(_(f'"{uri}" is launch with and invalid value for "{key}": {err}'))
raise ValueError(_(f'unknown parameter in "{uri}": "{key}"'))
# check mandatories options
if check_role and get_config().get('global').get('check_role'):
await self.check_role(subconfig,

View File

@ -115,7 +115,8 @@ async def api(request,
async with await Config(get_messages(current_module_names=risotto_modules,
load_shortarg=True,
current_version=risotto_context.version,
uris=uris)[1]) as config:
uris=uris)[1],
display_name=lambda self, dyn_name, suffix: self.impl_getname()) as config:
await config.property.read_write()
TIRAMISU = await config.option.dict(remotable='none')
return TIRAMISU

View File

@ -51,6 +51,7 @@ async def onjoin(source=True):
config_module = dispatcher.get_service('config')
assert config_module.servermodel == {}
assert config_module.server == {}
await delete_session()
#
#config_module.cache_root_path = 'tests/data'
await dispatcher.load()
@ -96,6 +97,9 @@ async def create_servermodel(name=SERVERMODEL_NAME,
)
###################################################################################################################################
# Servermodel
###################################################################################################################################
@pytest.mark.asyncio
async def test_servermodel_created():
await onjoin()
@ -129,78 +133,6 @@ async def test_servermodel_created():
assert not list(await config_module.servermodel['last_base'].config.parents())
assert len(list(await config_module.servermodel['last_sm1'].config.parents())) == 1
await delete_session()
@pytest.mark.asyncio
async def test_server_created_base():
await onjoin()
config_module = dispatcher.get_service('config')
fake_context = get_fake_context('config')
#
assert list(config_module.server) == []
await dispatcher.on_join(truncate=True)
server_name = 'dns.test.lan'
#FIXME pas de release ??
await dispatcher.publish('v1',
'infra.server.created',
fake_context,
server_name=server_name,
server_description='description_created',
servermodel_name='base',
release_distribution='last',
site_name='site_1',
zones_name=['zones'],
zones_ip=['1.1.1.1'],
)
assert list(config_module.server) == [server_name]
assert set(config_module.server[server_name]) == {'server', 'server_to_deploy', 'funcs_file'}
assert config_module.server[server_name]['funcs_file'] == '/var/cache/risotto/servermodel/last/base/funcs.py'
await delete_session()
#@pytest.mark.asyncio
#async def test_server_deleted():
# config_module = dispatcher.get_service('config')
# config_module.cache_root_path = 'tests/data'
# await config_module.on_join(fake_context)
# #
# assert list(config_module.server) == [3]
# await dispatcher.publish('v1',
# 'server.created',
# fake_context,
# server_id=4,
# server_name='name4',
# server_description='description4',
# server_servermodel_id=2)
# assert list(config_module.server) == [3, 4]
# await dispatcher.publish('v1',
# 'server.deleted',
# fake_context,
# server_id=4)
# assert list(config_module.server) == [3]
# await delete_session()
#
#
#@pytest.mark.asyncio
#async def test_servermodel_created():
# config_module = dispatcher.get_service('config')
# fake_context = get_fake_context('config')
# config_module.cache_root_path = 'tests/data'
# await config_module.on_join(fake_context)
# #
# assert list(config_module.servermodel) == [1, 2]
# servermodel = {'servermodeid': 3,
# 'servermodelname': 'name3'}
# await dispatcher.publish('v1',
# 'servermodel.created',
# fake_context,
# servermodel_id=3,
# servermodel_description='name3',
# release_id=1,
# servermodel_name='name3')
# assert list(config_module.servermodel) == [1, 2, 3]
# assert not list(await config_module.servermodel[3].config.parents())
# await delete_session()
#
#
#@pytest.mark.asyncio
@ -354,9 +286,9 @@ async def test_server_created_base():
## await config_module.on_join(fake_context)
## #
## config_module.servermodel[1].property.read_write()
## assert config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.get() == 'non'
## config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.set('oui')
## assert config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
## assert config_module.servermodel[1].option('configuration.general.mode_conteneur_actif').value.get() == 'non'
## config_module.servermodel[1].option('configuration.general.mode_conteneur_actif').value.set('oui')
## assert config_module.servermodel[1].option('configuration.general.mode_conteneur_actif').value.get() == 'oui'
## #
## await dispatcher.publish('v1',
## 'servermodel.updated',
@ -365,68 +297,192 @@ async def test_server_created_base():
## servermodel_name='name1-1',
## release_id=1,
## servermodel_description='name1-1')
## assert config_module.servermodel[1].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
## assert config_module.servermodel[1].option('configuration.general.mode_conteneur_actif').value.get() == 'oui'
## await delete_session()
#
#
###################################################################################################################################
# Server
###################################################################################################################################
@pytest.mark.asyncio
async def test_server_created_base():
await onjoin()
config_module = dispatcher.get_service('config')
fake_context = get_fake_context('config')
#
assert list(config_module.server) == []
await dispatcher.on_join(truncate=True)
server_name = 'dns.test.lan'
await dispatcher.publish('v1',
'infra.server.created',
fake_context,
server_name=server_name,
server_description='description_created',
servermodel_name='base',
release_distribution='last',
site_name='site_1',
zones_name=['zones'],
zones_ip=['1.1.1.1'],
)
assert list(config_module.server) == [server_name]
assert set(config_module.server[server_name]) == {'server', 'server_to_deploy', 'funcs_file'}
assert config_module.server[server_name]['funcs_file'] == '/var/cache/risotto/servermodel/last/base/funcs.py'
await delete_session()
@pytest.mark.asyncio
async def test_server_created_own_sm():
await onjoin()
config_module = dispatcher.get_service('config')
fake_context = get_fake_context('config')
await create_servermodel()
#
assert list(config_module.server) == []
await dispatcher.on_join(truncate=True)
server_name = 'dns.test.lan'
await dispatcher.publish('v1',
'infra.server.created',
fake_context,
server_name=server_name,
server_description='description_created',
servermodel_name=SERVERMODEL_NAME,
source_name=SOURCE_NAME,
release_distribution='last',
site_name='site_1',
zones_name=['zones'],
zones_ip=['1.1.1.1'],
)
assert list(config_module.server) == [server_name]
assert set(config_module.server[server_name]) == {'server', 'server_to_deploy', 'funcs_file'}
assert config_module.server[server_name]['funcs_file'] == '/var/cache/risotto/servermodel/last/sm1/funcs.py'
await delete_session()
#@pytest.mark.asyncio
#async def test_server_configuration_get():
#async def test_server_deleted():
# config_module = dispatcher.get_service('config')
# fake_context = get_fake_context('config')
# config_module.cache_root_path = 'tests/data'
# await config_module.on_join(fake_context)
# #
# await config_module.server[3]['server_to_deploy'].property.read_write()
# assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
# await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.set('oui')
# assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
# assert await config_module.server[3]['server'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
# #
# values = await dispatcher.call('v1',
# 'config.configuration.server.get',
# assert list(config_module.server) == [3]
# await dispatcher.publish('v1',
# 'server.created',
# fake_context,
# server_id=3)
# configuration = {'configuration':
# {'creole.general.mode_conteneur_actif': 'non',
# 'creole.general.master.master': [],
# 'creole.general.master.slave1': [],
# 'creole.general.master.slave2': [],
# 'containers.container0.files.file0.mkdir': False,
# 'containers.container0.files.file0.name': '/etc/mailname',
# 'containers.container0.files.file0.rm': False,
# 'containers.container0.files.file0.source': 'mailname',
# 'containers.container0.files.file0.activate': True},
# 'server_id': 3,
# 'deployed': True}
# assert values == configuration
# #
# values = await dispatcher.call('v1',
# 'config.configuration.server.get',
# server_id=4,
# server_name='name4',
# server_description='description4',
# server_servermodel_id=2)
# assert list(config_module.server) == [3, 4]
# await dispatcher.publish('v1',
# 'server.deleted',
# fake_context,
# server_id=3,
# deployed=False)
# configuration['configuration']['creole.general.mode_conteneur_actif'] = 'oui'
# configuration['deployed'] = False
# assert values == configuration
# await delete_session()
#
#
#@pytest.mark.asyncio
#async def test_config_deployed():
# config_module = dispatcher.get_service('config')
# fake_context = get_fake_context('config')
# config_module.cache_root_path = 'tests/data'
# await config_module.on_join(fake_context)
# #
# await config_module.server[3]['server_to_deploy'].property.read_write()
# assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
# await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.set('oui')
# assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
# assert await config_module.server[3]['server'].option('creole.general.mode_conteneur_actif').value.get() == 'non'
# values = await dispatcher.publish('v1',
# 'config.configuration.server.deploy',
# fake_context,
# server_id=3)
# assert await config_module.server[3]['server_to_deploy'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
# assert await config_module.server[3]['server'].option('creole.general.mode_conteneur_actif').value.get() == 'oui'
# server_id=4)
# assert list(config_module.server) == [3]
# await delete_session()
@pytest.mark.asyncio
async def test_server_configuration_get():
await onjoin()
config_module = dispatcher.get_service('config')
fake_context = get_fake_context('config')
await create_servermodel()
await dispatcher.on_join(truncate=True)
server_name = 'dns.test.lan'
await dispatcher.publish('v1',
'infra.server.created',
fake_context,
server_name=server_name,
server_description='description_created',
servermodel_name=SERVERMODEL_NAME,
source_name=SOURCE_NAME,
release_distribution='last',
site_name='site_1',
zones_name=['zones'],
zones_ip=['1.1.1.1'],
)
#
await config_module.server[server_name]['server'].property.read_write()
assert await config_module.server[server_name]['server'].option('configuration.general.number_of_interfaces').value.get() == 1
await config_module.server[server_name]['server'].option('configuration.general.number_of_interfaces').value.set(2)
assert await config_module.server[server_name]['server'].option('configuration.general.number_of_interfaces').value.get() == 2
assert await config_module.server[server_name]['server_to_deploy'].option('configuration.general.number_of_interfaces').value.get() == 1
#
configuration = {'server_name': server_name,
'deployed': False,
'configuration': {'configuration.general.number_of_interfaces': 1,
'configuration.general.interfaces_list': [0],
'configuration.interface_0.domain_name_eth0': 'dns.test.lan'
}
}
values = await dispatcher.call('v1',
'setting.config.configuration.server.get',
fake_context,
server_name=server_name,
deployed=False,
)
assert values == configuration
#
await delete_session()
@pytest.mark.asyncio
async def test_server_configuration_deployed():
await onjoin()
config_module = dispatcher.get_service('config')
fake_context = get_fake_context('config')
await create_servermodel()
await dispatcher.on_join(truncate=True)
server_name = 'dns.test.lan'
await dispatcher.publish('v1',
'infra.server.created',
fake_context,
server_name=server_name,
server_description='description_created',
servermodel_name=SERVERMODEL_NAME,
source_name=SOURCE_NAME,
release_distribution='last',
site_name='site_1',
zones_name=['zones'],
zones_ip=['1.1.1.1'],
)
#
await config_module.server[server_name]['server'].property.read_write()
assert await config_module.server[server_name]['server'].option('configuration.general.number_of_interfaces').value.get() == 1
await config_module.server[server_name]['server'].option('configuration.general.number_of_interfaces').value.set(2)
assert await config_module.server[server_name]['server'].option('configuration.general.number_of_interfaces').value.get() == 2
assert await config_module.server[server_name]['server_to_deploy'].option('configuration.general.number_of_interfaces').value.get() == 1
#
configuration = {'server_name': server_name,
'deployed': False,
'configuration': {'configuration.general.number_of_interfaces': 1,
'configuration.general.interfaces_list': [0],
'configuration.interface_0.domain_name_eth0': 'dns.test.lan'
}
}
try:
await dispatcher.call('v1',
'setting.config.configuration.server.get',
fake_context,
server_name=server_name,
)
except:
pass
else:
raise Exception('should raise propertyerror')
values = await dispatcher.call('v1',
'setting.config.configuration.server.deploy',
fake_context,
server_name=server_name,
)
assert values == {'server_name': 'dns.test.lan', 'deployed': True}
await dispatcher.call('v1',
'setting.config.configuration.server.get',
fake_context,
server_name=server_name,
)
#
await delete_session()