def test_param_Param_init(): name = '1/2/3' kp = '6/7/8' fp = 'q/w/e' for _kp in (kp, Path(kp), KeyPath(kp)): assert Param(name, _kp) == Param(name, PillarKey(kp)) assert Param(name, (kp, fp)) == Param(name, PillarKey(kp, fp))
def test_inputs_ParamsList_from_args(param_spec_mocked): params = [ param_spec_mocked['some_param_gr/attr2'], Param(param_spec_mocked['some/dict/item1'].name / 'key1', ('some-pi-key3/key1', 'some-pi-path3')) ] assert ParamsList.from_args(*[str(p) for p in params]).params == params assert ParamsList.from_args(*[p for p in params]).params == params assert ParamsList.from_args(*[str(p) for p in params], *[p for p in params]).params == params + params
def test_inputs_ParamDictItemInputBaseparam_spec(param_spec_mocked): test = SomeParamDictItem(some_key_attr='1234', some_value_attr=5) assert test.param_spec() == Param('some/dict/item1/1234', ('some-pi-key3/1234', 'some-pi-path3'))
from provisioner import inputs from provisioner.param import (Param, ParamDictItem) from provisioner.inputs import (METADATA_PARAM_GROUP_KEY, METADATA_ARGPARSER, AttrParserArgs, InputAttrParserArgs, PillarKeysList, PillarInputBase, ParamsList, ParamGroupInputBase, NTP, Network, NetworkParams, ParamDictItemInputBase, SWUpdateRepo, ParserFiller) from provisioner.pillar import PillarKey from provisioner.api_spec import param_spec as _param_spec # HELPERS and FIXTURES test_param_spec = { 'some_param_gr/attr1': Param('some_param_gr/attr1', ('some-pi-key1', 'some-pi-path1')), 'some_param_gr/attr2': Param('some_param_gr/attr2', ('some-pi-key2', 'some-pi-path2')), 'some/dict/item1': ParamDictItem('some/dict/item1', ('some-pi-key3', 'some-pi-path3'), 'some_key_attr', 'some_value_attr') } @attr.s(auto_attribs=True) class SomeParamGroup(ParamGroupInputBase): _param_group = 'some_param_gr' attr1: str = ParamGroupInputBase._attr_ib(_param_group) attr2: int = ParamGroupInputBase._attr_ib(_param_group, default=1)
def test_pillar_resolver(test_pillar): param1 = Param('some-param', ('1/2/3', 'aaa.sls')) param2 = Param('some-param2', ('1/2/5', 'aaa.sls')) param3 = Param('some-param2', ('1/di_parent/8', 'aaa.sls')) _iter = iter(test_pillar) minion_id_1 = next(_iter) minion_id_2 = next(_iter) pr = PillarResolver() assert pr.pillar is test_pillar res = pr.get([param1]) assert res == { minion_id_1: { param1: test_pillar[minion_id_1]['1']['2']['3'] }, minion_id_2: { param1: test_pillar[minion_id_2]['1']['2']['3'] } } res = pr.get([param2]) assert res == { minion_id_1: { param2: test_pillar[minion_id_1]['1']['2']['5'] }, minion_id_2: { param2: test_pillar[minion_id_2]['1']['2']['5'] } } res = pr.get([param3]) assert res == { minion_id_1: { param3: MISSED }, minion_id_2: { param3: test_pillar[minion_id_2]['1']['di_parent']['8'] } } res = pr.get([param1, param2, param3]) assert res == { minion_id_1: { param1: test_pillar[minion_id_1]['1']['2']['3'], param2: test_pillar[minion_id_1]['1']['2']['5'], param3: MISSED }, minion_id_2: { param1: test_pillar[minion_id_2]['1']['2']['3'], param2: test_pillar[minion_id_2]['1']['2']['5'], param3: test_pillar[minion_id_2]['1']['di_parent']['8'] } } pr = PillarResolver(targets=minion_id_1) assert pr.pillar == { k: v for k, v in test_pillar.items() if k == minion_id_1 } res = pr.get([param1, param2, param3]) assert res == { minion_id_1: { param1: test_pillar[minion_id_1]['1']['2']['3'], param2: test_pillar[minion_id_1]['1']['2']['5'], param3: MISSED } }
def test_param_Param_is_hashable(): hash(Param('1', ('2', '3')))
def test_param_Param_to_str(): name = '1/2/3' kp = '6/7/8' assert str(Param(name, kp)) == name