Compare commits

...

14 Commits

106 changed files with 6611 additions and 4436 deletions

View File

@ -1,3 +1,9 @@
Fri Jul 26 09:43:03 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
* version 3.0 rc9
* better todict support (especially for leadership
* can add display_name method to Config init to change the name a
option in errors
Mon Jun 5 14:49:27 2019 +0200 Emmanuel Garette <egarette@cadoles.com> Mon Jun 5 14:49:27 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
* version 3.0 rc7 * version 3.0 rc7
* retrieve metaconfig/mixconfig/config by name in a metaconfig/mixconfig * retrieve metaconfig/mixconfig/config by name in a metaconfig/mixconfig

View File

@ -12,7 +12,26 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.boolean": {
"clearable": true
},
"null": [ "null": [
{ {
"title": "Configurer", "title": "Configurer",

View File

@ -16,7 +16,26 @@
"readOnly": true "readOnly": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.boolean": {
"clearable": true
},
"null": [ "null": [
{ {
"title": "Configurer", "title": "Configurer",

View File

@ -17,8 +17,25 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.choice": { "options.choice": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"null": [ "null": [

View File

@ -21,8 +21,25 @@
"readOnly": true "readOnly": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.choice": { "options.choice": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"null": [ "null": [

View File

@ -57,17 +57,37 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.choice1.choice1": { "options.choice1.choice1": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"options.choice1.choice2": { "options.choice1.choice2": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"options.choice1.choice3": { "options.choice1.choice3": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"options.choice1.choice4": { "options.choice1.choice4": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"null": [ "null": [

View File

@ -58,22 +58,41 @@
}, },
"options.choice1.choice3": { "options.choice1.choice3": {
"null": { "null": {
"display": false, "display": false
"hidden": true
} }
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.choice1.choice1": { "options.choice1.choice1": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"options.choice1.choice2": { "options.choice1.choice2": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"options.choice1.choice3": { "options.choice1.choice3": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"options.choice1.choice4": { "options.choice1.choice4": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"null": [ "null": [

View File

@ -67,17 +67,37 @@
} }
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.choice1.choice1": { "options.choice1.choice1": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"options.choice1.choice2": { "options.choice1.choice2": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"options.choice1.choice3": { "options.choice1.choice3": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"options.choice1.choice4": { "options.choice1.choice4": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"null": [ "null": [

View File

@ -21,8 +21,25 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.choice": { "options.choice": {
"clearable": true,
"type": "choice" "type": "choice"
}, },
"null": [ "null": [

View File

@ -17,8 +17,25 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.choice": { "options.choice": {
"clearable": true,
"type": "choice", "type": "choice",
"displayed": { "displayed": {
"choice 1": "renamed 1", "choice 1": "renamed 1",

View File

@ -4,11 +4,11 @@
"properties": { "properties": {
"options.choice": { "options.choice": {
"type": "choice", "type": "choice",
"value": "hide",
"enum": [ "enum": [
"hide", "hide",
"show" "show"
], ],
"value": "hide",
"title": "Choice description" "title": "Choice description"
}, },
"options.unicode2": { "options.unicode2": {
@ -23,13 +23,29 @@
"model": { "model": {
"options.choice": { "options.choice": {
"required": true, "required": true,
"value": "hide", "value": "hide"
"owner": "default"
}, },
"options.unicode2": { "options.unicode2": {
"display": false,
"hidden": true "hidden": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.choice": { "options.choice": {
"clearable": true, "clearable": true,
@ -41,13 +57,13 @@
] ]
}, },
"expected": { "expected": {
"hide": { "show": {
"hide": [ "show": [
"options.unicode2" "options.unicode2"
] ]
}, },
"show": { "hide": {
"show": [ "hide": [
"options.unicode2" "options.unicode2"
] ]
} }
@ -55,6 +71,7 @@
} }
}, },
"options.unicode2": { "options.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -12,7 +12,27 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.date": {
"clearable": true,
"remote": true
},
"null": [ "null": [
{ {
"title": "Configurer", "title": "Configurer",

View File

@ -16,7 +16,27 @@
"readOnly": true "readOnly": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.date": {
"clearable": true,
"remote": true
},
"null": [ "null": [
{ {
"title": "Configurer", "title": "Configurer",

View File

@ -10,8 +10,25 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"usbpath": { "usbpath": {
"clearable": true,
"pattern": "^[a-zA-Z0-9\\-\\._~/+]+$", "pattern": "^[a-zA-Z0-9\\-\\._~/+]+$",
"type": "input" "type": "input"
}, },

View File

@ -24,20 +24,40 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.hostname1": { "options.hostname1": {
"clearable": true,
"pattern": "^((?!-)[a-z0-9-]{1,63}\\.){1,}[a-z0-9-]{1,63}$", "pattern": "^((?!-)[a-z0-9-]{1,63}\\.){1,}[a-z0-9-]{1,63}$",
"type": "input" "type": "input"
}, },
"options.hostname2": { "options.hostname2": {
"clearable": true,
"pattern": "^((?!-)[a-z0-9-]{0,63}\\.){0,}[a-z0-9-]{1,63}$", "pattern": "^((?!-)[a-z0-9-]{0,63}\\.){0,}[a-z0-9-]{1,63}$",
"type": "input" "type": "input"
}, },
"options.hostname3": { "options.hostname3": {
"clearable": true,
"pattern": "^(?:((?!-)[a-z0-9-]{1,63})|(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))$", "pattern": "^(?:((?!-)[a-z0-9-]{1,63})|(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))$",
"type": "input" "type": "input"
}, },
"options.hostname4": { "options.hostname4": {
"clearable": true,
"pattern": "^((?!-)[a-z0-9-]{1,15})$", "pattern": "^((?!-)[a-z0-9-]{1,15})$",
"type": "input" "type": "input"
}, },

View File

@ -12,9 +12,26 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.ip": { "options.ip": {
"pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", "clearable": true,
"remote": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -16,9 +16,26 @@
"readOnly": true "readOnly": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.ip": { "options.ip": {
"pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", "clearable": true,
"remote": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -12,8 +12,25 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.mail": { "options.mail": {
"clearable": true,
"pattern": "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$", "pattern": "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$",
"type": "input" "type": "input"
}, },

View File

@ -12,8 +12,25 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.integer": { "options.integer": {
"clearable": true,
"pattern": "^[0-9]+$", "pattern": "^[0-9]+$",
"type": "input" "type": "input"
}, },

View File

@ -16,8 +16,25 @@
"readOnly": true "readOnly": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.integer": { "options.integer": {
"clearable": true,
"pattern": "^[0-9]+$", "pattern": "^[0-9]+$",
"type": "input" "type": "input"
}, },

View File

@ -18,6 +18,22 @@
"owner": "user" "owner": "user"
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.integer": { "options.integer": {
"clearable": true, "clearable": true,

View File

@ -14,10 +14,25 @@
}, },
"model": { "model": {
"options.integer": { "options.integer": {
"value": 0, "value": 0
"owner": "default"
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.integer": { "options.integer": {
"clearable": true, "clearable": true,

View File

@ -12,8 +12,25 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -16,8 +16,25 @@
"readOnly": true "readOnly": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -35,22 +35,42 @@
}, },
"model": { "model": {
"options.unicode.unicode": { "options.unicode.unicode": {
"display": false,
"required": true, "required": true,
"display": false,
"hidden": true "hidden": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode.unicode": { "options.unicode.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -38,17 +38,37 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode.unicode": { "options.unicode.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -6,11 +6,11 @@
"properties": { "properties": {
"options.unicode.unicode": { "options.unicode.unicode": {
"type": "string", "type": "string",
"isMulti": true,
"value": [ "value": [
"val1", "val1",
"val2" "val2"
], ],
"isMulti": true,
"title": "Unicode leader" "title": "Unicode leader"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
@ -20,7 +20,7 @@
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"type": "string", "type": "string",
"default": "follower2", "defaultmulti": "follower2",
"isMulti": true, "isMulti": true,
"title": "Unicode follower 2 with default multi" "title": "Unicode follower 2 with default multi"
}, },
@ -44,26 +44,40 @@
"value": [ "value": [
"val1", "val1",
"val2" "val2"
], ]
"owner": "default"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"0": { "0": {
"value": "follower2", "value": "follower2"
"owner": "default"
}, },
"1": { "1": {
"value": "follower2", "value": "follower2"
"owner": "default"
} }
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode.unicode": { "options.unicode.unicode": {
"clearable": true, "clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
@ -71,6 +85,7 @@
"type": "input" "type": "input"
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -54,22 +54,41 @@
"hidden": true "hidden": true
}, },
"null": { "null": {
"display": false, "display": false
"hidden": true
} }
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode.unicode": { "options.unicode.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -37,17 +37,37 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode1": { "options.unicode1.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode2": { "options.unicode1.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode3": { "options.unicode1.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -38,28 +38,52 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode.unicode": { "options.unicode.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"options.unicode.unicode3" "options": [
] "options.unicode.unicode3"
} ]
}
]
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"options.unicode.unicode2" "options": [
] "options.unicode.unicode2"
} ]
}
]
}, },
"null": [ "null": [
{ {

View File

@ -38,14 +38,33 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode.unicode": { "options.unicode.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -63,6 +82,7 @@
} }
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -34,17 +34,36 @@
}, },
"model": { "model": {
"options.unicode1": { "options.unicode1": {
"display": false,
"properties": [ "properties": [
"hidden" "hidden"
], ]
"hidden": true
}, },
"options.unicode1.unicode1": { "options.unicode1.unicode1": {
"required": true "required": true,
"hidden": true,
"display": false
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -62,12 +81,15 @@
} }
}, },
"options.unicode1.unicode1": { "options.unicode1.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode2": { "options.unicode1.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode3": { "options.unicode1.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -33,8 +33,25 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1.unicode1": { "options.unicode1.unicode1": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -52,9 +69,11 @@
} }
}, },
"options.unicode1.unicode2": { "options.unicode1.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode3": { "options.unicode1.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -49,12 +49,30 @@
"owner": "user" "owner": "user"
}, },
"1": { "1": {
"display": false,
"hidden": true "hidden": true
} }
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1.unicode1": { "options.unicode1.unicode1": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -72,9 +90,11 @@
} }
}, },
"options.unicode1.unicode2": { "options.unicode1.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode3": { "options.unicode1.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -33,11 +33,29 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1.unicode1": { "options.unicode1.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode2": { "options.unicode1.unicode2": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -55,6 +73,7 @@
} }
}, },
"options.unicode1.unicode3": { "options.unicode1.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -34,17 +34,36 @@
}, },
"model": { "model": {
"options.unicode1": { "options.unicode1": {
"display": false,
"properties": [ "properties": [
"hidden" "hidden"
], ]
"hidden": true
}, },
"options.unicode1.unicode1": { "options.unicode1.unicode1": {
"required": true "required": true,
"hidden": true,
"display": false
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -62,12 +81,15 @@
} }
}, },
"options.unicode1.unicode1": { "options.unicode1.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode2": { "options.unicode1.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode1.unicode3": { "options.unicode1.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -64,14 +64,32 @@
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"1": { "1": {
"display": false,
"hidden": true, "hidden": true,
"value": "super", "value": "super",
"owner": "user" "owner": "user"
} }
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode.unicode": { "options.unicode.unicode": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -89,12 +107,15 @@
} }
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -39,17 +39,37 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode.unicode": { "options.unicode.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -6,11 +6,11 @@
"properties": { "properties": {
"options.unicode.unicode": { "options.unicode.unicode": {
"type": "string", "type": "string",
"isMulti": true,
"value": [ "value": [
"val1", "val1",
"val2" "val2"
], ],
"isMulti": true,
"title": "Unicode leader" "title": "Unicode leader"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
@ -20,7 +20,7 @@
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
"type": "string", "type": "string",
"default": "follower2", "defaultmulti": "follower2",
"isMulti": true, "isMulti": true,
"title": "Unicode follower 2 with default multi" "title": "Unicode follower 2 with default multi"
}, },
@ -74,12 +74,29 @@
} }
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode.unicode": { "options.unicode.unicode": {
"clearable": true, "clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode1": { "options.unicode.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode.unicode2": { "options.unicode.unicode2": {
@ -87,6 +104,7 @@
"type": "input" "type": "input"
}, },
"options.unicode.unicode3": { "options.unicode.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -2,10 +2,7 @@
"options.unicode.unicode1", "options.unicode.unicode1",
"options.unicode.unicode2", "options.unicode.unicode2",
"options.unicode.unicode3"], "options.unicode.unicode3"],
"model": {"options.unicode.unicode": {"owner": "default", "model": {"options.unicode.unicode": {"required": true,
"required": true,
"value": ["val1", "val2"]}, "value": ["val1", "val2"]},
"options.unicode.unicode2": {"0": {"owner": "default", "options.unicode.unicode2": {"0": {"value": "follower2"},
"value": "follower2"}, "1": {"value": "follower2"}}}}
"1": {"owner": "default",
"value": "follower2"}}}}

View File

@ -11,7 +11,6 @@
"owner": "user"}, "owner": "user"},
"1": {"value": "test", "1": {"value": "test",
"owner": "user"}, "owner": "user"},
"2": {"value": "follower2", "2": {"value": "follower2"}},
"owner": "default"}},
"options.unicode.unicode3": {"1": {"value": "super", "options.unicode.unicode3": {"1": {"value": "super",
"owner": "user"}}}} "owner": "user"}}}}

View File

@ -9,8 +9,7 @@
"value": "pas test"}, "value": "pas test"},
"1": {"owner": "user", "1": {"owner": "user",
"value": "test"}, "value": "test"},
"2": {"owner": "default", "2": {"value": "follower2"}},
"value": "follower2"}},
"options.unicode.unicode3": {"1": {"owner": "user", "options.unicode.unicode3": {"1": {"owner": "user",
"value": "super"}}}, "value": "super"}}},
"updates": ["options.unicode.unicode", "options.unicode.unicode2"]} "updates": ["options.unicode.unicode", "options.unicode.unicode2"]}

View File

@ -8,7 +8,6 @@
"owner": "user"}}, "owner": "user"}},
"options.unicode.unicode2": {"0": {"value": "pas test", "options.unicode.unicode2": {"0": {"value": "pas test",
"owner": "user"}, "owner": "user"},
"1": {"value": "follower2", "1": {"value": "follower2"}},
"owner": "default"}},
"options.unicode.unicode3": {"1": {"value": "super", "options.unicode.unicode3": {"1": {"value": "super",
"owner": "user"}}}} "owner": "user"}}}}

View File

@ -16,8 +16,25 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -17,8 +17,25 @@
"owner": "user" "owner": "user"
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -17,8 +17,25 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -14,13 +14,30 @@
}, },
"model": { "model": {
"options.unicode": { "options.unicode": {
"display": false,
"required": true, "required": true,
"display": false,
"hidden": true "hidden": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -18,8 +18,25 @@
"needs_len": true "needs_len": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -4,11 +4,11 @@
"properties": { "properties": {
"options.unicode": { "options.unicode": {
"type": "string", "type": "string",
"isMulti": true,
"value": [ "value": [
"a", "a",
"b" "b"
], ],
"isMulti": true,
"title": "String 1" "title": "String 1"
} }
}, },
@ -27,6 +27,22 @@
"owner": "user" "owner": "user"
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true, "clearable": true,

View File

@ -1,4 +1,3 @@
{"updates": ["options.unicode"], {"updates": ["options.unicode"],
"model": {"options.unicode": {"owner": "default", "model": {"options.unicode": {"required": true,
"required": true,
"value": ["a", "b"]}}} "value": ["a", "b"]}}}

View File

@ -24,11 +24,11 @@
}, },
"descr2.unicode2_multi": { "descr2.unicode2_multi": {
"type": "string", "type": "string",
"isMulti": true,
"value": [ "value": [
"a", "a",
"b" "b"
], ],
"isMulti": true,
"title": "Multi unicode 2" "title": "Multi unicode 2"
} }
}, },
@ -56,77 +56,107 @@
"required": true "required": true
}, },
"descr2.unicode2": { "descr2.unicode2": {
"value": "a", "value": "a"
"owner": "default"
}, },
"descr2.unicode2_multi": { "descr2.unicode2_multi": {
"required": true, "required": true,
"value": [ "value": [
"a", "a",
"b" "b"
], ]
"owner": "default"
}, },
"descr3.unicode3_multi": { "descr3.unicode3_multi": {
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"descr1.unicode1": { "descr1.unicode1": {
"clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"descr2.unicode2", "options": [
"descr3.unicode3" "descr2.unicode2",
] "descr3.unicode3"
} ]
}
]
}, },
"descr1.unicode1_multi": { "descr1.unicode1_multi": {
"clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"descr2.unicode2_multi", "options": [
"descr3.unicode3_multi" "descr2.unicode2_multi",
] "descr3.unicode3_multi"
} ]
}
]
}, },
"descr2.unicode2": { "descr2.unicode2": {
"clearable": true, "clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"descr1.unicode1", "options": [
"descr3.unicode3" "descr1.unicode1",
] "descr3.unicode3"
} ]
}
]
}, },
"descr2.unicode2_multi": { "descr2.unicode2_multi": {
"clearable": true, "clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"descr1.unicode1_multi", "options": [
"descr3.unicode3_multi" "descr1.unicode1_multi",
] "descr3.unicode3_multi"
} ]
}
]
}, },
"descr3.unicode3": { "descr3.unicode3": {
"clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"descr1.unicode1", "options": [
"descr2.unicode2" "descr1.unicode1",
] "descr2.unicode2"
} ]
}
]
}, },
"descr3.unicode3_multi": { "descr3.unicode3_multi": {
"clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"descr1.unicode1_multi", "options": [
"descr2.unicode2_multi" "descr1.unicode1_multi",
] "descr2.unicode2_multi"
} ]
}
]
}, },
"null": [ "null": [
{ {

View File

@ -19,11 +19,29 @@
"model": { "model": {
"options.unicode2": { "options.unicode2": {
"required": true, "required": true,
"display": false,
"hidden": true "hidden": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1": { "options.unicode1": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -41,6 +59,7 @@
} }
}, },
"options.unicode2": { "options.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -4,11 +4,11 @@
"properties": { "properties": {
"options.unicode": { "options.unicode": {
"type": "string", "type": "string",
"isMulti": true,
"value": [ "value": [
"a", "a",
"b" "b"
], ],
"isMulti": true,
"title": "String 1" "title": "String 1"
} }
}, },
@ -22,10 +22,25 @@
"value": [ "value": [
"a", "a",
"b" "b"
], ]
"owner": "default"
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true, "clearable": true,

View File

@ -16,22 +16,44 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1": { "options.unicode1": {
"clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"options.unicode2" "options": [
] "options.unicode2"
} ]
}
]
}, },
"options.unicode2": { "options.unicode2": {
"clearable": true,
"type": "input", "type": "input",
"not_equal": { "not_equal": [
"options": [ {
"options.unicode1" "options": [
] "options.unicode1"
} ]
}
]
}, },
"null": [ "null": [
{ {

View File

@ -27,14 +27,39 @@
}, },
"model": { "model": {
"unicode1": { "unicode1": {
"display": false,
"properties": [ "properties": [
"hidden" "hidden"
], ]
"hidden": true },
"unicode1.unicode2": {
"hidden": true,
"display": false
},
"unicode1.unicode3": {
"hidden": true,
"display": false
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1": { "options.unicode1": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -52,9 +77,11 @@
} }
}, },
"unicode1.unicode2": { "unicode1.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"unicode1.unicode3": { "unicode1.unicode3": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -17,11 +17,29 @@
}, },
"model": { "model": {
"options.unicode2": { "options.unicode2": {
"display": false,
"hidden": true "hidden": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1": { "options.unicode1": {
"clearable": true,
"type": "input", "type": "input",
"dependencies": { "dependencies": {
"default": { "default": {
@ -39,6 +57,7 @@
} }
}, },
"options.unicode2": { "options.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -14,14 +14,29 @@
}, },
"model": { "model": {
"options.unicode1": { "options.unicode1": {
"value": "word", "value": "word"
"owner": "default"
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1": { "options.unicode1": {
"type": "input", "clearable": true,
"clearable": true "type": "input"
}, },
"null": [ "null": [
{ {

View File

@ -16,11 +16,29 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1": { "options.unicode1": {
"clearable": true,
"type": "input" "type": "input"
}, },
"options.unicode2": { "options.unicode2": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -16,16 +16,33 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1": { "options.unicode1": {
"clearable": true,
"type": "input", "type": "input",
"copy": [ "copy": [
"options.unicode2" "options.unicode2"
] ]
}, },
"options.unicode2": { "options.unicode2": {
"type": "input", "clearable": true,
"clearable": true "type": "input"
}, },
"null": [ "null": [
{ {

View File

@ -25,16 +25,33 @@
"required": true "required": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1": { "options.unicode1": {
"clearable": true,
"type": "input", "type": "input",
"copy": [ "copy": [
"options.unicode2" "options.unicode2"
] ]
}, },
"options.unicode2": { "options.unicode2": {
"type": "input", "clearable": true,
"clearable": true "type": "input"
}, },
"null": [ "null": [
{ {

View File

@ -18,10 +18,25 @@
}, },
"model": { "model": {
"options.unicode1": { "options.unicode1": {
"value": "test", "value": "test"
"owner": "default"
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode1": { "options.unicode1": {
"clearable": true, "clearable": true,

View File

@ -17,8 +17,25 @@
"hidden": true "hidden": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -18,8 +18,25 @@
] ]
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -18,8 +18,25 @@
] ]
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.unicode": { "options.unicode": {
"clearable": true,
"type": "input" "type": "input"
}, },
"null": [ "null": [

View File

@ -12,8 +12,25 @@
} }
}, },
"model": {}, "model": {},
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.username": { "options.username": {
"clearable": true,
"pattern": "^[a-z_][a-z0-9_-]{0,30}[$a-z0-9_-]{0,1}$", "pattern": "^[a-z_][a-z0-9_-]{0,30}[$a-z0-9_-]{0,1}$",
"type": "input" "type": "input"
}, },

View File

@ -16,8 +16,25 @@
"readOnly": true "readOnly": true
} }
}, },
"global": {
"owner": "user",
"properties": [
"cache",
"demoting_error_warning",
"disabled",
"force_store_value",
"frozen",
"hidden",
"validator",
"warnings"
],
"permissives": [
"hidden"
]
},
"form": { "form": {
"options.username": { "options.username": {
"clearable": true,
"pattern": "^[a-z_][a-z0-9_-]{0,30}[$a-z0-9_-]{0,1}$", "pattern": "^[a-z_][a-z0-9_-]{0,30}[$a-z0-9_-]{0,1}$",
"type": "input" "type": "input"
}, },

View File

@ -4,6 +4,7 @@ from os import listdir
from os.path import dirname, abspath, join, normpath, splitext, isfile from os.path import dirname, abspath, join, normpath, splitext, isfile
import sys import sys
import warnings import warnings
import pytest
from tiramisu import OptionDescription, Config from tiramisu import OptionDescription, Config
from tiramisu.error import ValueWarning from tiramisu.error import ValueWarning
@ -22,7 +23,7 @@ def datapath():
def list_data(ext='.py'): def list_data(ext='.py'):
# return ['unicode1_leader_hidden_followers.py'] # return ['choice1_requires.py']
datadir = datapath() datadir = datapath()
filenames = listdir(datadir) filenames = listdir(datadir)
filenames.sort() filenames.sort()
@ -78,6 +79,17 @@ def del_property(expected, prop):
return new_form return new_form
def del_value_property(schema, form):
all_options = []
for key, root in schema.items():
if 'properties' in root:
del_value_property(root['properties'], form)
else:
is_remote = form.get(key) and form[key].get('remote', False)
if 'value' in root and is_remote:
del root['value']
def add_property(expected, prop, prop_value): def add_property(expected, prop, prop_value):
all_options = [] all_options = []
all_descroptions = [] all_descroptions = []
@ -112,7 +124,31 @@ def add_property(expected, prop, prop_value):
return ordered_form return ordered_form
def test_jsons():
LISTDATA = list_data()
LISTDATA_MOD = []
idx = 0
while True:
idx += 1
list_files = list_data('.mod{}'.format(idx))
if not list_files:
break
LISTDATA_MOD.extend(list_files)
@pytest.fixture(params=LISTDATA)
def filename(request):
return request.param
@pytest.fixture(params=LISTDATA_MOD)
def filename_mod(request):
return request.param
def test_jsons(filename):
debug = False debug = False
# debug = True # debug = True
datadir = datapath() datadir = datapath()
@ -126,248 +162,242 @@ def test_jsons():
for remote in ['minimum', 'none', 'all']: for remote in ['minimum', 'none', 'all']:
if debug: if debug:
print(' ==> remotable', remote) print(' ==> remotable', remote)
filenames = list_data() modulepath = splitext(filename)[0]
for filename in filenames: if debug:
modulepath = splitext(filename)[0] print(" {} (remote: {}, clearable: {})".format(filename, remote, clearable))
if debug: values = load_config(filename,
print(" {} (remote: {}, clearable: {})".format(filename, remote, clearable)) remote=remote,
values = load_config(filename, clearable=clearable)
remote=remote, #
clearable=clearable) if not isfile(join(datadir, modulepath + '.json')) and \
# clearable == 'minimum' and \
if not isfile(join(datadir, modulepath + '.json')) and \ remote == 'minimum':
clearable == 'minimum' and \ with open(join(datadir, modulepath + '.json'), 'w') as fh:
remote == 'minimum': dump(values, fh, indent=2)
with open(join(datadir, modulepath + '.json'), 'w') as fh: with open(join(datadir, modulepath + '.json'), 'r') as fh:
dump(values, fh, indent=2) expected = loads(fh.read())
with open(join(datadir, modulepath + '.json'), 'r') as fh: if clearable == 'none':
expected = loads(fh.read()) expected['form'] = del_property(expected, 'clearable')
if clearable == 'none': if remote == 'all':
expected['form'] = del_property(expected, 'clearable') if 'tiramisu' in expected:
if remote == 'none' and 'tiramisu' in expected:
del expected['tiramisu'] del expected['tiramisu']
if clearable == 'all': expected['form'] = del_property(expected, 'pattern')
expected['form'] = add_property(expected, 'clearable', True) if clearable == 'all':
if remote == 'all': expected['form'] = add_property(expected, 'clearable', True)
expected['form'] = add_property(expected, 'remote', True) if remote == 'all':
new_expected = {} expected['form'] = add_property(expected, 'remote', True)
for key, form in expected['form'].items(): new_expected = {}
if key != 'null' and form.get('remote', False): for key, form in expected['form'].items():
if 'dependencies' in form: if key != 'null' and form.get('remote', False):
del form['dependencies'] if 'dependencies' in form:
if 'copy' in form: del form['dependencies']
del form['copy'] if 'copy' in form:
if 'not_equal' in form: del form['copy']
del form['not_equal'] if 'not_equal' in form:
new_expected[key] = form del form['not_equal']
expected['form'] = new_expected new_expected[key] = form
expected['form'] = new_expected
# properties are unordered # properties are unordered
for model in expected['model']: for model in expected['model']:
if 'properties' in model: if 'properties' in model:
model['properties'] = set(model['properties']) model['properties'] = set(model['properties'])
for model in values['model']: for model in values['model']:
if 'properties' in model: if 'properties' in model:
model['properties'] = set(model['properties']) model['properties'] = set(model['properties'])
if debug: del_value_property(expected['schema'], expected['form'])
from pprint import pprint if debug:
pprint(values) from pprint import pprint
print('----------------') pprint(values)
pprint(expected) print('----------------')
assert values == expected, "error in file {}".format(filename) pprint(expected)
assert values == expected, "error in file {}".format(filename)
def test_jsons_subconfig(): def test_jsons_subconfig(filename):
debug = False debug = False
# debug = True # debug = True
datadir = datapath() datadir = datapath()
if debug: if debug:
print() print()
filenames = list_data() modulepath = splitext(filename)[0]
for filename in filenames: if debug:
modulepath = splitext(filename)[0] print(" ", filename)
if debug: values = load_config(filename, add_extra_od=True, root=modulepath)
print(" ", filename) #
values = load_config(filename, add_extra_od=True, root=modulepath) with open(join(datadir, modulepath + '.json'), 'r') as fh:
# expected = loads(fh.read())
with open(join(datadir, modulepath + '.json'), 'r') as fh: # properties are unordered
expected = loads(fh.read()) for model in expected['model'].values():
# properties are unordered if 'properties' in model:
for model in expected['model'].values(): model['properties'] = set(model['properties'])
if 'properties' in model: for model in values['model'].values():
model['properties'] = set(model['properties']) if 'properties' in model:
for model in values['model'].values(): model['properties'] = set(model['properties'])
if 'properties' in model: # add root
model['properties'] = set(model['properties'])
# add root
def change_key(schema): def change_key(schema):
new_schema = {} new_schema = {}
for key_schema, val_schema in schema.items(): for key_schema, val_schema in schema.items():
key = modulepath + '.' + key_schema key = modulepath + '.' + key_schema
# val_schema['name'] = key # val_schema['name'] = key
if 'opt_path' in val_schema: if 'opt_path' in val_schema:
val_schema['opt_path'] = modulepath + '.' + val_schema['opt_path'] val_schema['opt_path'] = modulepath + '.' + val_schema['opt_path']
if 'properties' in val_schema: if 'properties' in val_schema:
val_schema['properties'] = change_key(val_schema['properties']) val_schema['properties'] = change_key(val_schema['properties'])
new_schema[key] = val_schema new_schema[key] = val_schema
return new_schema return new_schema
expected['schema'] = change_key(expected['schema']) expected['schema'] = change_key(expected['schema'])
new_form_all = {} new_form_all = {}
for key, form in expected['form'].items(): for key, form in expected['form'].items():
if key != 'null': if key != 'null':
key = modulepath + '.' + key key = modulepath + '.' + key
new_form_all[key] = form new_form_all[key] = form
if 'copy' in form: if 'copy' in form:
for idx, noteq in enumerate(form['copy']): for idx, noteq in enumerate(form['copy']):
form['copy'][idx] = modulepath + '.' + noteq form['copy'][idx] = modulepath + '.' + noteq
if 'not_equal' in form: if 'not_equal' in form:
new_form = [] new_form = []
for noteq in form['not_equal']['options']: for idx, not_equal in enumerate(form['not_equal']):
for noteq in not_equal['options']:
new_form.append(modulepath + '.' + noteq) new_form.append(modulepath + '.' + noteq)
form['not_equal']['options'] = new_form form['not_equal'][idx]['options'] = new_form
if 'dependencies' in form: if 'dependencies' in form:
for dependency in form['dependencies'].values(): for dependency in form['dependencies'].values():
for val1 in dependency.values(): for val1 in dependency.values():
if isinstance(val1, list): if isinstance(val1, list):
for idx, lst in enumerate(val1): for idx, lst in enumerate(val1):
val1[idx] = modulepath + '.' + lst val1[idx] = modulepath + '.' + lst
else: else:
for val2 in val1.values(): for val2 in val1.values():
if isinstance(val2, list): if isinstance(val2, list):
for idx, lst in enumerate(val2): for idx, lst in enumerate(val2):
val2[idx] = modulepath + '.' + lst val2[idx] = modulepath + '.' + lst
expected['form'] = new_form_all expected['form'] = new_form_all
new_model = {} new_model = {}
for key, model in expected['model'].items(): for key, model in expected['model'].items():
new_model[modulepath + '.' + key] = model new_model[modulepath + '.' + key] = model
expected['model'] = new_model expected['model'] = new_model
if debug: if debug:
from pprint import pprint from pprint import pprint
pprint(values) pprint(values)
print('----------------') print('----------------')
pprint(expected) pprint(expected)
assert values == expected, "error in file {}".format(filename) assert values == expected, "error in file {}".format(filename)
def test_updates(): def test_updates(filename_mod):
debug = False debug = False
# debug = True # debug = True
datadir = datapath() datadir = datapath()
idx = 0 if debug:
while True: print("test/data/" + filename_mod)
idx += 1 for issub in [False, True]:
list_files = list_data('.mod{}'.format(idx)) idx = int(filename_mod[-1])
if not list_files: modulepath = splitext(filename_mod)[0]
break mod = __import__(modulepath)
for filename in list_files: descr = mod.get_description()
if debug: if issub:
print("test/data/" + filename) descr = OptionDescription('root', '', [descr])
for issub in [False, True]: root = modulepath
modulepath = splitext(filename)[0] else:
mod = __import__(modulepath) root = None
descr = mod.get_description() # dict before modification
if not isfile(join(datadir, modulepath + '.dict')):
dico_ori = None
else:
with open(join(datadir, modulepath + '.dict'), 'r') as fh:
dico_ori = loads(fh.read())
if issub: if issub:
descr = OptionDescription('root', '', [descr]) new_dico_ori = {}
root = modulepath for key, value in dico_ori.items():
else: key = modulepath + '.' + key
root = None new_dico_ori[key] = value
# dict before modification dico_ori = new_dico_ori
if not isfile(join(datadir, modulepath + '.dict')): # modify config
dico_ori = None with open(join(datadir, modulepath + '.mod{}'.format(idx)), 'r') as fh:
else: body = loads(fh.read())['body']
with open(join(datadir, modulepath + '.dict'), 'r') as fh: if issub:
dico_ori = loads(fh.read()) for value in body['updates']:
if issub: value['name'] = modulepath + '.' + value['name']
new_dico_ori = {} # returns of set_updates
for key, value in dico_ori.items(): if not isfile(join(datadir, modulepath + '.updates{}'.format(idx))):
key = modulepath + '.' + key values = None
new_dico_ori[key] = value else:
dico_ori = new_dico_ori with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'r') as fh:
# modify config values = loads(fh.read())
with open(join(datadir, modulepath + '.mod{}'.format(idx)), 'r') as fh: if issub:
body = loads(fh.read())['body'] for lidx, key in enumerate(values['updates']):
if issub: values['updates'][lidx] = modulepath + '.' + key
for value in body['updates']: if 'model' in values:
value['name'] = modulepath + '.' + value['name'] new_model = {}
# returns of set_updates for key, value in values['model'].items():
if not isfile(join(datadir, modulepath + '.updates{}'.format(idx))): new_model[modulepath + '.' + key] = value
values = None values['model'] = new_model
else: # dict after modification
with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'r') as fh: if not isfile(join(datadir, modulepath + '.dict{}'.format(idx))):
values = loads(fh.read()) dico_mod = None
if issub: else:
for lidx, key in enumerate(values['updates']): with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'r') as fh:
values['updates'][lidx] = modulepath + '.' + key dico_mod = loads(fh.read())
if 'model' in values: if issub:
new_model = {} new_dico = {}
for key, value in values['model'].items(): for key, value in dico_mod.items():
new_model[modulepath + '.' + key] = value key = modulepath + '.' + key
values['model'] = new_model new_dico[key] = value
# dict after modification dico_mod = new_dico
if not isfile(join(datadir, modulepath + '.dict{}'.format(idx))): if root is None:
dico_mod = None root_path = ''
else: else:
with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'r') as fh: root_path = '{}.'.format(root)
dico_mod = loads(fh.read()) for clearable in ['none', 'minimum', 'all']:
if issub: for remote in ['none', 'minimum', 'all']:
new_dico = {} if debug:
for key, value in dico_mod.items(): print(" (remote: {}, clearable: {}, issub {}, root {}, root_path {})".format(remote, clearable, issub, root, root_path))
key = modulepath + '.' + key for with_model in [False, True]:
new_dico[key] = value config = Config(descr)
dico_mod = new_dico config.property.add('demoting_error_warning')
if root is None: if 'get_values' in dir(mod):
root_path = '' mod.get_values(config, issub)
else: if isfile(join(datadir, modulepath + '.mod')):
root_path = '{}.'.format(root) with open(join(datadir, modulepath + '.mod'), 'r') as fh:
for clearable in ['none', 'minimum', 'all']: eval(fh.read())
for remote in ['none', 'minimum', 'all']: if dico_ori is None:
if debug: if clearable == 'minimum' and remote == 'minimum':
print(" (remote: {}, clearable: {}, issub {}, root {}, root_path {})".format(remote, clearable, issub, root, root_path)) with open(join(datadir, modulepath + '.dict'), 'w') as fh:
for with_model in [False, True]: dump(config.value.dict(), fh, indent=2)
config = Config(descr) else:
config.property.add('demoting_error_warning') assert config.value.dict() == dico_ori, "clearable {}, remote: {}, filename: {}".format(clearable, remote, filename_mod)
if 'get_values' in dir(mod): if root is None:
mod.get_values(config, issub) suboption = config.option
if isfile(join(datadir, modulepath + '.mod')): else:
with open(join(datadir, modulepath + '.mod'), 'r') as fh: suboption = config.option(root)
eval(fh.read()) if with_model:
if dico_ori is None: bodym = body.copy()
if clearable == 'minimum' and remote == 'minimum': bodym['model'] = loads(dumps(suboption.dict(remotable=remote, clearable=clearable)))['model']
with open(join(datadir, modulepath + '.dict'), 'w') as fh: else:
dump(config.value.dict(), fh, indent=2) suboption.dict(remotable=remote, clearable=clearable)
else: bodym = body
assert config.value.dict() == dico_ori, "clearable {}, remote: {}, filename: {}".format(clearable, remote, filename) if with_model:
if root is None: cal_values = suboption.updates(bodym)
suboption = config.option if values is None:
else: if clearable == 'minimum' and remote == 'minimum':
suboption = config.option(root) with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'w') as fh:
if with_model: dump(cal_values, fh, indent=2)
bodym = body.copy() else:
bodym['model'] = loads(dumps(suboption.dict(remotable=remote, clearable=clearable)))['model'] if debug:
else: from pprint import pprint
suboption.dict(remotable=remote, clearable=clearable) pprint(cal_values)
bodym = body print('------------')
if with_model: pprint(values)
cal_values = suboption.updates(bodym) assert cal_values == values
if values is None: else:
if clearable == 'minimum' and remote == 'minimum': assert suboption.updates(bodym) is None
with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'w') as fh: if dico_mod is None:
dump(cal_values, fh, indent=2) if clearable == 'minimum' and remote == 'minimum':
else: with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'w') as fh:
if debug: dump(config.value.dict(), fh, indent=2)
from pprint import pprint else:
pprint(cal_values) assert config.value.dict() == dico_mod
print('------------')
pprint(values)
assert cal_values == values
else:
assert suboption.updates(bodym) is None
if dico_mod is None:
if clearable == 'minimum' and remote == 'minimum':
with open(join(datadir, modulepath + '.dict{}'.format(idx)), 'w') as fh:
dump(config.value.dict(), fh, indent=2)
else:
assert config.value.dict() == dico_mod

View File

@ -3,12 +3,12 @@ from py.test import raises
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config, value_list, global_owner
from tiramisu.setting import owners from tiramisu.setting import owners
from tiramisu import ChoiceOption, StrOption, OptionDescription, Config from tiramisu import ChoiceOption, StrOption, OptionDescription, Config
from tiramisu.error import ConfigError from tiramisu.error import ConfigError
from tiramisu import undefined, Params, ParamValue, ParamOption from tiramisu import undefined, Params, ParamValue, ParamOption
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -32,12 +32,13 @@ def return_error(*args, **kwargs):
raise Exception('test') raise Exception('test')
def test_choiceoption(): def test_choiceoption(config_type):
choice = ChoiceOption('choice', '', values=('val1', 'val2')) choice = ChoiceOption('choice', '', values=('val1', 'val2'))
odesc = OptionDescription('od', '', [choice]) odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc) cfg = Config(odesc)
cfg.property.read_write() cfg.property.read_write()
owner = cfg.owner.get() cfg = get_config(cfg, config_type)
owner = global_owner(cfg, config_type)
assert cfg.option('choice').owner.get() == owners.default assert cfg.option('choice').owner.get() == owners.default
assert cfg.option('choice').owner.isdefault() assert cfg.option('choice').owner.isdefault()
# #
@ -53,15 +54,16 @@ def test_choiceoption():
assert cfg.option('choice').owner.get() == owners.default assert cfg.option('choice').owner.get() == owners.default
assert cfg.option('choice').owner.isdefault() assert cfg.option('choice').owner.isdefault()
# #
assert cfg.option('choice').value.list() == ('val1', 'val2') assert value_list(cfg.option('choice').value.list()) == ('val1', 'val2')
def test_choiceoption_function(): def test_choiceoption_function(config_type):
choice = ChoiceOption('choice', '', values=return_list) choice = ChoiceOption('choice', '', values=return_list)
odesc = OptionDescription('od', '', [choice]) odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc) cfg = Config(odesc)
cfg.property.read_write() cfg.property.read_write()
owner = cfg.owner.get() cfg = get_config(cfg, config_type)
owner = global_owner(cfg, config_type)
assert cfg.option('choice').owner.isdefault() assert cfg.option('choice').owner.isdefault()
# #
cfg.option('choice').value.set('val1') cfg.option('choice').value.set('val1')
@ -73,7 +75,7 @@ def test_choiceoption_function():
raises(ValueError, "cfg.option('choice').value.set('no')") raises(ValueError, "cfg.option('choice').value.set('no')")
assert cfg.option('choice').owner.isdefault() assert cfg.option('choice').owner.isdefault()
# #
assert cfg.option('choice').value.list() == ['val1', 'val2'] assert value_list(cfg.option('choice').value.list()) == ('val1', 'val2')
def test_choiceoption_function_error(): def test_choiceoption_function_error():
@ -100,12 +102,13 @@ def test_choiceoption_function_error_kwargs():
raises(ConfigError, "cfg.option('choice').value.set('val1')") raises(ConfigError, "cfg.option('choice').value.set('val1')")
def test_choiceoption_calc_function(): def test_choiceoption_calc_function(config_type):
choice = ChoiceOption('choice', "", values=return_calc_list, values_params=Params((ParamValue('val1'),))) choice = ChoiceOption('choice', "", values=return_calc_list, values_params=Params((ParamValue('val1'),)))
odesc = OptionDescription('od', '', [choice]) odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc) cfg = Config(odesc)
cfg.property.read_write() cfg.property.read_write()
owner = cfg.owner.get() cfg = get_config(cfg, config_type)
owner = global_owner(cfg, config_type)
assert cfg.option('choice').owner.isdefault() assert cfg.option('choice').owner.isdefault()
# #
cfg.option('choice').value.set('val1') cfg.option('choice').value.set('val1')
@ -118,7 +121,7 @@ def test_choiceoption_calc_function():
assert cfg.option('choice').owner.isdefault() assert cfg.option('choice').owner.isdefault()
def test_choiceoption_calc_opt_function(): def test_choiceoption_calc_opt_function(config_type):
str_ = StrOption('str', '', 'val1') str_ = StrOption('str', '', 'val1')
choice = ChoiceOption('choice', choice = ChoiceOption('choice',
"", "",
@ -128,6 +131,7 @@ def test_choiceoption_calc_opt_function():
cfg = Config(odesc) cfg = Config(odesc)
cfg.property.read_write() cfg.property.read_write()
owner = cfg.owner.get() owner = cfg.owner.get()
cfg = get_config(cfg, config_type)
assert cfg.option('choice').owner.isdefault() assert cfg.option('choice').owner.isdefault()
# #
cfg.option('choice').value.set('val1') cfg.option('choice').value.set('val1')
@ -149,13 +153,13 @@ def test_choiceoption_calc_opt_function_propertyerror():
odesc = OptionDescription('od', '', [str_, choice]) odesc = OptionDescription('od', '', [str_, choice])
cfg = Config(odesc) cfg = Config(odesc)
cfg.property.read_write() cfg.property.read_write()
if TIRAMISU_VERSION == 2: raises(ConfigError, "cfg.option('choice').value.set('no')")
raises(ValueError, "cfg.option('choice').value.set('no')")
else:
raises(ConfigError, "cfg.option('choice').value.set('no')")
#def test_choiceoption_calc_opt_multi_function(config_type):
def test_choiceoption_calc_opt_multi_function(): def test_choiceoption_calc_opt_multi_function():
# FIXME
config_type = 'tiramisu'
str_ = StrOption('str', '', ['val1'], multi=True) str_ = StrOption('str', '', ['val1'], multi=True)
choice = ChoiceOption('choice', choice = ChoiceOption('choice',
"", "",
@ -173,6 +177,7 @@ def test_choiceoption_calc_opt_multi_function():
cfg = Config(odesc) cfg = Config(odesc)
cfg.property.read_write() cfg.property.read_write()
owner = cfg.owner.get() owner = cfg.owner.get()
cfg = get_config(cfg, config_type, True)
assert cfg.option('choice').owner.isdefault() assert cfg.option('choice').owner.isdefault()
assert cfg.option('choice').value.get() == [] assert cfg.option('choice').value.get() == []
# #
@ -193,7 +198,7 @@ def test_choiceoption_calc_opt_multi_function():
raises(ValueError, "cfg.option('ch2').value.get()") raises(ValueError, "cfg.option('ch2').value.get()")
def test_choiceoption_calc_opt_multi_function_kwargs(): def test_choiceoption_calc_opt_multi_function_kwargs(config_type):
str_ = StrOption('str', '', ['val1'], multi=True) str_ = StrOption('str', '', ['val1'], multi=True)
choice = ChoiceOption('choice', choice = ChoiceOption('choice',
"", "",
@ -211,6 +216,7 @@ def test_choiceoption_calc_opt_multi_function_kwargs():
cfg = Config(odesc) cfg = Config(odesc)
cfg.property.read_write() cfg.property.read_write()
owner = cfg.owner.get() owner = cfg.owner.get()
# FIXME cfg = get_config(cfg, config_type)
assert cfg.option('choice').owner.isdefault() assert cfg.option('choice').owner.isdefault()
assert cfg.option('choice').value.get() == [] assert cfg.option('choice').value.get() == []
# #

View File

@ -7,6 +7,7 @@ import weakref
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config, value_list, global_owner
from tiramisu import Config from tiramisu import Config
from tiramisu.config import SubConfig from tiramisu.config import SubConfig
@ -44,13 +45,14 @@ def make_description():
return descr return descr
def test_base_config(): def test_base_config(config_type):
"""making a :class:`tiramisu.config.Config()` object """making a :class:`tiramisu.config.Config()` object
and a :class:`tiramisu.option.OptionDescription()` object and a :class:`tiramisu.option.OptionDescription()` object
""" """
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr) cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('dummy').value.get() is False assert cfg.option('dummy').value.get() is False
#dmo = cfg.unwrap_from_path('dummy') #dmo = cfg.unwrap_from_path('dummy')
#assert dmo.impl_getname() == 'dummy' #assert dmo.impl_getname() == 'dummy'
@ -87,9 +89,12 @@ def test_base_config_force_permissive():
def test_base_config_in_a_tree(): def test_base_config_in_a_tree():
# FIXME
config_type = 'tiramisu'
"how options are organized into a tree, see :ref:`tree`" "how options are organized into a tree, see :ref:`tree`"
descr = make_description() descr = make_description()
config = Config(descr) config = Config(descr)
config = get_config(config, config_type)
# #
config.option('bool').value.set(False) config.option('bool').value.set(False)
# #
@ -216,11 +221,12 @@ def test_get_modified_values():
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user')) assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user'))
def test_get_modified_values_not_modif(): def test_get_modified_values_not_modif(config_type):
g1 = StrOption('g1', '', multi=True) g1 = StrOption('g1', '', multi=True)
d1 = OptionDescription('od', '', [g1]) d1 = OptionDescription('od', '', [g1])
root = OptionDescription('root', '', [d1]) root = OptionDescription('root', '', [d1])
config = Config(root) config = Config(root)
config = get_config(config, config_type)
assert config.option('od.g1').value.get() == [] assert config.option('od.g1').value.get() == []
value = config.option('od.g1').value.get() value = config.option('od.g1').value.get()
value.append('val') value.append('val')
@ -249,12 +255,13 @@ def test_cannot_assign_value_to_option_description():
raises(APIError, "cfg.option('gc').value.set(3)") raises(APIError, "cfg.option('gc').value.set(3)")
def test_config_multi(): def test_config_multi(config_type):
i1 = IntOption('test1', '', multi=True) i1 = IntOption('test1', '', multi=True)
i2 = IntOption('test2', '', multi=True, default_multi=1) i2 = IntOption('test2', '', multi=True, default_multi=1)
i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1) i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1)
od = OptionDescription('test', '', [i1, i2, i3]) od = OptionDescription('test', '', [i1, i2, i3])
config = Config(od) config = Config(od)
config = get_config(config, config_type)
assert config.option('test1').value.get() == [] assert config.option('test1').value.get() == []
assert config.option('test2').value.get() == [] assert config.option('test2').value.get() == []
config.option('test2').value.set([undefined]) config.option('test2').value.set([undefined])
@ -282,20 +289,24 @@ def test_prefix_error():
def test_no_validation(): def test_no_validation():
# FIXME
config_type = 'tiramisu'
i1 = IntOption('test1', '') i1 = IntOption('test1', '')
od = OptionDescription('test', '', [i1]) od = OptionDescription('test', '', [i1])
config = Config(od) config = Config(od)
config.property.read_write() config.property.read_write()
config.option('test1').value.set(1) cfg = get_config(config, config_type)
raises(ValueError, "config.option('test1').value.set('yes')") cfg.option('test1').value.set(1)
assert config.option('test1').value.get() == 1 raises(ValueError, "cfg.option('test1').value.set('yes')")
assert cfg.option('test1').value.get() == 1
config.property.pop('validator') config.property.pop('validator')
config.option('test1').value.set('yes') cfg = get_config(config, config_type)
assert config.option('test1').value.get() == 'yes' cfg.option('test1').value.set('yes')
config.property.add('validator') assert cfg.option('test1').value.get() == 'yes'
raises(ValueError, "config.option('test1').value.get()") cfg.property.add('validator')
config.option('test1').value.reset() raises(ValueError, "cfg.option('test1').value.get()")
assert config.option('test1').value.get() is None cfg.option('test1').value.reset()
assert cfg.option('test1').value.get() is None
def test_subconfig(): def test_subconfig():
@ -325,30 +336,33 @@ def test_config_invalidsession():
raises(ValueError, 'Config(o2, session_id=2)') raises(ValueError, 'Config(o2, session_id=2)')
def test_config_od_name(): def test_config_od_name(config_type):
i = IntOption('i', '') i = IntOption('i', '')
s = SymLinkOption('s', i) s = SymLinkOption('s', i)
o = OptionDescription('val', '', [i, s]) o = OptionDescription('val', '', [i, s])
o2 = OptionDescription('val', '', [o]) o2 = OptionDescription('val', '', [o])
c = Config(o2) c = Config(o2)
c = get_config(c, config_type)
assert c.option('val.i').option.name() == 'i' assert c.option('val.i').option.name() == 'i'
assert c.option('val.s').option.name() == 's' assert c.option('val.s').option.name() == 's'
assert c.option('val.s').option.name(follow_symlink=True) == 'i' assert c.option('val.s').option.name(follow_symlink=True) == 'i'
def test_config_od_type(): def test_config_od_type(config_type):
i = IntOption('i', '') i = IntOption('i', '')
o = OptionDescription('val', '', [i]) o = OptionDescription('val', '', [i])
o2 = OptionDescription('val', '', [o]) o2 = OptionDescription('val', '', [o])
c = Config(o2) c = Config(o2)
c = get_config(c, config_type)
assert c.option('val.i').option.type() == 'integer' assert c.option('val.i').option.type() == 'integer'
def test_config_default(): def test_config_default(config_type):
i = IntOption('i', '', 8) i = IntOption('i', '', 8)
o = OptionDescription('val', '', [i]) o = OptionDescription('val', '', [i])
o2 = OptionDescription('val', '', [o]) o2 = OptionDescription('val', '', [o])
c = Config(o2) c = Config(o2)
c = get_config(c, config_type)
assert c.option('val.i').value.default() == 8 assert c.option('val.i').value.default() == 8
c.option('val.i').value.set(9) c.option('val.i').value.set(9)
assert c.option('val.i').value.get() == 9 assert c.option('val.i').value.get() == 9

View File

@ -3,6 +3,7 @@ from py.test import raises
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config, value_list, global_owner
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \ from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
BoolOption, FilenameOption, UnicodeOption, SymLinkOption, IPOption, \ BoolOption, FilenameOption, UnicodeOption, SymLinkOption, IPOption, \
@ -59,7 +60,7 @@ def test_str():
c # does not crash c # does not crash
def test_make_dict(): def test_make_dict(config_type):
"serialization of the whole config to a dict" "serialization of the whole config to a dict"
descr = OptionDescription("opt", "", [ descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [ OptionDescription("s1", "", [
@ -69,6 +70,7 @@ def test_make_dict():
config = Config(descr) config = Config(descr)
config.property.read_write() config.property.read_write()
config.permissive.set(frozenset(['hidden'])) config.permissive.set(frozenset(['hidden']))
config = get_config(config, config_type)
d = config.value.dict() d = config.value.dict()
assert d == {"s1.a": False, "int": 42} assert d == {"s1.a": False, "int": 42}
config.option('int').value.set(43) config.option('int').value.set(43)
@ -77,12 +79,14 @@ def test_make_dict():
assert d == {"s1.a": True, "int": 43} assert d == {"s1.a": True, "int": 43}
d2 = config.value.dict(flatten=True) d2 = config.value.dict(flatten=True)
assert d2 == {'a': True, 'int': 43} assert d2 == {'a': True, 'int': 43}
raises(ValueError, 'd2 = config.value.dict(withvalue="3")') if config_type == 'tiramisu':
d = config.forcepermissive.value.dict() # FIXME
assert d == {"s1.a": True, "s1.b": False, "int": 43} raises(ValueError, 'd2 = config.value.dict(withvalue="3")')
d = config.forcepermissive.value.dict()
assert d == {"s1.a": True, "s1.b": False, "int": 43}
def test_make_dict_with_disabled(): def test_make_dict_with_disabled(config_type):
descr = OptionDescription("opt", "", [ descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [ OptionDescription("s1", "", [
BoolOption("a", "", default=False), BoolOption("a", "", default=False),
@ -93,9 +97,11 @@ def test_make_dict_with_disabled():
IntOption("int", "", default=42)]) IntOption("int", "", default=42)])
config = Config(descr) config = Config(descr)
config.property.read_only() config.property.read_only()
config = get_config(config, config_type)
assert config.value.dict() == {"s1.a": False, "int": 42} assert config.value.dict() == {"s1.a": False, "int": 42}
assert config.forcepermissive.value.dict() == {"s1.a": False, "int": 42} if config_type == 'tiramisu':
assert config.unrestraint.value.dict() == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False} assert config.forcepermissive.value.dict() == {"s1.a": False, "int": 42}
assert config.unrestraint.value.dict() == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
def test_make_dict_with_disabled_withoption(): def test_make_dict_with_disabled_withoption():
@ -114,7 +120,7 @@ def test_make_dict_with_disabled_withoption():
assert config.unrestraint.value.dict(withoption="a") == {"s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False} assert config.unrestraint.value.dict(withoption="a") == {"s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
def test_make_dict_with_disabled_in_callback(): def test_make_dict_with_disabled_in_callback(config_type):
descr = OptionDescription("opt", "", [ descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [ OptionDescription("s1", "", [
BoolOption("a", "", default=False), BoolOption("a", "", default=False),
@ -125,11 +131,12 @@ def test_make_dict_with_disabled_in_callback():
IntOption("int", "", default=42)]) IntOption("int", "", default=42)])
config = Config(descr) config = Config(descr)
config.property.read_only() config.property.read_only()
config = get_config(config, config_type)
d = config.value.dict() d = config.value.dict()
assert d == {"s1.a": False, "int": 42} assert d == {"s1.a": False, "int": 42}
def test_make_dict_fullpath(): def test_make_dict_fullpath(config_type):
descr = OptionDescription("root", "", [ descr = OptionDescription("root", "", [
OptionDescription("opt", "", [ OptionDescription("opt", "", [
OptionDescription("s1", "", [ OptionDescription("s1", "", [
@ -142,10 +149,15 @@ def test_make_dict_fullpath():
IntOption("introot", "", default=42)]) IntOption("introot", "", default=42)])
config = Config(descr) config = Config(descr)
config.property.read_only() config.property.read_only()
config = get_config(config, config_type)
assert config.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42} assert config.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
assert config.option('opt').value.dict() == {"s1.a": False, "int": 42} if config_type == 'tiramisu':
# FIXME
assert config.option('opt').value.dict() == {"s1.a": False, "int": 42}
assert config.value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42} assert config.value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
assert config.option('opt').value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42} if config_type == 'tiramisu':
# FIXME
assert config.option('opt').value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
def test_find_in_config(): def test_find_in_config():
@ -273,10 +285,11 @@ def test_does_not_find_in_config():
raises(AttributeError, "list(conf.option.find('IDontExist'))") raises(AttributeError, "list(conf.option.find('IDontExist'))")
def test_filename(): def test_filename(config_type):
a = FilenameOption('a', '') a = FilenameOption('a', '')
o = OptionDescription('o', '', [a]) o = OptionDescription('o', '', [a])
cfg = Config(o) cfg = Config(o)
# FIXME cfg = get_config(cfg, config_type)
cfg.option('a').value.set('/') cfg.option('a').value.set('/')
cfg.option('a').value.set('/tmp') cfg.option('a').value.set('/tmp')
cfg.option('a').value.set('/tmp/') cfg.option('a').value.set('/tmp/')

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config, value_list, global_owner
import warnings, sys import warnings, sys
from py.test import raises from py.test import raises
@ -14,7 +15,7 @@ def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__) assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def test_domainname(): def test_domainname(config_type):
d = DomainnameOption('d', '') d = DomainnameOption('d', '')
f = DomainnameOption('f', '', allow_without_dot=True) f = DomainnameOption('f', '', allow_without_dot=True)
g = DomainnameOption('g', '', allow_ip=True) g = DomainnameOption('g', '', allow_ip=True)
@ -22,6 +23,7 @@ def test_domainname():
od = OptionDescription('a', '', [d, f, g, h]) od = OptionDescription('a', '', [d, f, g, h])
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
cfg.option('d').value.set('toto.com') cfg.option('d').value.set('toto.com')
raises(ValueError, "cfg.option('d').value.set('toto')") raises(ValueError, "cfg.option('d').value.set('toto')")
@ -40,7 +42,9 @@ def test_domainname():
cfg.option('f').value.set('d') cfg.option('f').value.set('d')
cfg.option('f').value.set('d.t') cfg.option('f').value.set('d.t')
# #
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')") if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')")
raises(ValueError, "cfg.option('f').value.set('192.168.1.0/24')") raises(ValueError, "cfg.option('f').value.set('192.168.1.0/24')")
# #
cfg.option('g').value.set('toto.com') cfg.option('g').value.set('toto.com')
@ -49,35 +53,42 @@ def test_domainname():
raises(ValueError, "cfg.option('g').value.set('192.168.1.0/24')") raises(ValueError, "cfg.option('g').value.set('192.168.1.0/24')")
# #
cfg.option('h').value.set('toto.com') cfg.option('h').value.set('toto.com')
raises(ValueError, "cfg.option('h').value.set('192.168.1.0')") if config_type != 'tiramisu-api':
raises(ValueError, "cfg.option('h').value.set('192.168.1.29')") # FIXME
raises(ValueError, "cfg.option('h').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('h').value.set('192.168.1.29')")
cfg.option('h').value.set('192.168.1.0/24') cfg.option('h').value.set('192.168.1.0/24')
def test_domainname_upper(): def test_domainname_upper(config_type):
d = DomainnameOption('d', '') d = DomainnameOption('d', '')
od = OptionDescription('a', '', [d]) od = OptionDescription('a', '', [d])
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('d').value.set('toto.com') cfg.option('d').value.set('toto.com')
msg = _('some characters are uppercase') msg = _('some characters are uppercase')
has_error = False has_error = False
try: try:
cfg.option('d').value.set('TOTO.COM') cfg.option('d').value.set('TOTO.COM')
except ValueError as err: except ValueError as err:
assert msg in str(err) if config_type != 'tiramisu-api':
# FIXME
assert msg in str(err)
has_error = True has_error = True
assert has_error is True assert has_error is True
has_error = False has_error = False
try: try:
cfg.option('d').value.set('toTo.com') cfg.option('d').value.set('toTo.com')
except ValueError as err: except ValueError as err:
assert msg in str(err) if config_type != 'tiramisu-api':
# FIXME
assert msg in str(err)
has_error = True has_error = True
assert has_error is True assert has_error is True
def test_domainname_warning(): def test_domainname_warning(config_type):
d = DomainnameOption('d', '', warnings_only=True) d = DomainnameOption('d', '', warnings_only=True)
f = DomainnameOption('f', '', allow_without_dot=True, warnings_only=True) f = DomainnameOption('f', '', allow_without_dot=True, warnings_only=True)
g = DomainnameOption('g', '', allow_ip=True, warnings_only=True) g = DomainnameOption('g', '', allow_ip=True, warnings_only=True)
@ -85,12 +96,15 @@ def test_domainname_warning():
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('d').value.set('toto.com') cfg.option('d').value.set('toto.com')
raises(ValueError, "cfg.option('d').value.set('toto')") raises(ValueError, "cfg.option('d').value.set('toto')")
cfg.option('d').value.set('toto3.com') cfg.option('d').value.set('toto3.com')
with warnings.catch_warnings(record=True) as w: if config_type != 'tiramisu-api':
cfg.option('d').value.set('toto_super.com') # FIXME
assert len(w) == 1 with warnings.catch_warnings(record=True) as w:
cfg.option('d').value.set('toto_super.com')
assert len(w) == 1
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
cfg.option('d').value.set('toto-.com') cfg.option('d').value.set('toto-.com')
assert len(w) == 0 assert len(w) == 0
@ -102,17 +116,21 @@ def test_domainname_warning():
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')") raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd') cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie') cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')") if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')")
cfg.option('f').value.set('d') cfg.option('f').value.set('d')
cfg.option('f').value.set('d.t') cfg.option('f').value.set('d.t')
# #
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')") if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('f').value.set('192.168.1.1')")
cfg.option('g').value.set('toto.com') cfg.option('g').value.set('toto.com')
cfg.option('g').value.set('192.168.1.0') cfg.option('g').value.set('192.168.1.0')
cfg.option('g').value.set('192.168.1.29') cfg.option('g').value.set('192.168.1.29')
def test_special_domain_name(): def test_special_domain_name(config_type):
"""domain name option that starts with a number or not """domain name option that starts with a number or not
""" """
d = DomainnameOption('d', '') d = DomainnameOption('d', '')
@ -120,39 +138,43 @@ def test_special_domain_name():
od = OptionDescription('a', '', [d, e]) od = OptionDescription('a', '', [d, e])
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('d').value.set('1toto.com') cfg.option('d').value.set('1toto.com')
cfg.option('d').value.set('123toto.com') cfg.option('d').value.set('123toto.com')
cfg.option('e').value.set('toto') cfg.option('e').value.set('toto')
cfg.option('e').value.set('1toto') cfg.option('e').value.set('1toto')
def test_domainname_netbios(): def test_domainname_netbios(config_type):
d = DomainnameOption('d', '', type_='netbios') d = DomainnameOption('d', '', type_='netbios')
e = DomainnameOption('e', '', "toto", type_='netbios') e = DomainnameOption('e', '', "toto", type_='netbios')
od = OptionDescription('a', '', [d, e]) od = OptionDescription('a', '', [d, e])
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('d').value.set('toto.com')") raises(ValueError, "cfg.option('d').value.set('toto.com')")
cfg.option('d').value.set('toto') cfg.option('d').value.set('toto')
raises(ValueError, "cfg.option('d').value.set('domainnametoolong')") raises(ValueError, "cfg.option('d').value.set('domainnametoolong')")
def test_domainname_hostname(): def test_domainname_hostname(config_type):
d = DomainnameOption('d', '', type_='hostname') d = DomainnameOption('d', '', type_='hostname')
e = DomainnameOption('e', '', "toto", type_='hostname') e = DomainnameOption('e', '', "toto", type_='hostname')
od = OptionDescription('a', '', [d, e]) od = OptionDescription('a', '', [d, e])
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('d').value.set('toto.com')") raises(ValueError, "cfg.option('d').value.set('toto.com')")
cfg.option('d').value.set('toto') cfg.option('d').value.set('toto')
cfg.option('d').value.set('domainnametoolong') cfg.option('d').value.set('domainnametoolong')
def test_email(): def test_email(config_type):
e = EmailOption('e', '') e = EmailOption('e', '')
od = OptionDescription('a', '', [e]) od = OptionDescription('a', '', [e])
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('e').value.set('foo-bar.baz@example.com') cfg.option('e').value.set('foo-bar.baz@example.com')
cfg.option('e').value.set('root@foo.com') cfg.option('e').value.set('root@foo.com')
cfg.option('e').value.set('root@domain') cfg.option('e').value.set('root@domain')
@ -161,25 +183,34 @@ def test_email():
raises(ValueError, "cfg.option('e').value.set('root[]@domain')") raises(ValueError, "cfg.option('e').value.set('root[]@domain')")
def test_url(): def test_url(config_type):
u = URLOption('u', '') u = URLOption('u', '')
od = OptionDescription('a', '', [u]) od = OptionDescription('a', '', [u])
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('u').value.set('http://foo.com') cfg.option('u').value.set('http://foo.com')
cfg.option('u').value.set('https://foo.com') cfg.option('u').value.set('https://foo.com')
cfg.option('u').value.set('https://foo.com/') cfg.option('u').value.set('https://foo.com/')
raises(ValueError, "cfg.option('u').value.set(1)") raises(ValueError, "cfg.option('u').value.set(1)")
raises(ValueError, "cfg.option('u').value.set('ftp://foo.com')") if config_type != 'tiramisu-api':
raises(ValueError, "cfg.option('u').value.set('foo.com')") # FIXME
raises(ValueError, "cfg.option('u').value.set(':/foo.com')") raises(ValueError, "cfg.option('u').value.set('ftp://foo.com')")
raises(ValueError, "cfg.option('u').value.set('foo.com/http://')") raises(ValueError, "cfg.option('u').value.set('foo.com')")
raises(ValueError, "cfg.option('u').value.set(':/foo.com')")
raises(ValueError, "cfg.option('u').value.set('foo.com/http://')")
cfg.option('u').value.set('https://foo.com/index.html') cfg.option('u').value.set('https://foo.com/index.html')
cfg.option('u').value.set('https://foo.com/index.html?var=value&var2=val2') cfg.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
raises(ValueError, "cfg.option('u').value.set('https://foo.com/index\\n.html')") if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('u').value.set('https://foo.com/index\\n.html')")
cfg.option('u').value.set('https://foo.com:8443') cfg.option('u').value.set('https://foo.com:8443')
cfg.option('u').value.set('https://foo.com:8443/') cfg.option('u').value.set('https://foo.com:8443/')
cfg.option('u').value.set('https://foo.com:8443/index.html') cfg.option('u').value.set('https://foo.com:8443/index.html')
raises(ValueError, "cfg.option('u').value.set('https://foo.com:84438989')") if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('u').value.set('https://foo.com:84438989')")
cfg.option('u').value.set('https://foo.com:8443/INDEX') cfg.option('u').value.set('https://foo.com:8443/INDEX')
raises(ValueError, "cfg.option('u').value.set('https://FOO.COM:8443')") if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('u').value.set('https://FOO.COM:8443')")

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config, value_list, global_owner
import warnings import warnings
from py.test import raises from py.test import raises
@ -13,29 +14,38 @@ def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__) assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def test_ip(): def test_ip(config_type):
a = IPOption('a', '') a = IPOption('a', '')
b = IPOption('b', '', private_only=True) b = IPOption('b', '', private_only=True)
d = IPOption('d', '', warnings_only=True, private_only=True) d = IPOption('d', '', warnings_only=True, private_only=True)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
od = OptionDescription('od', '', [a, b, d]) od = OptionDescription('od', '', [a, b, d])
config = Config(od) config = Config(od)
config = get_config(config, config_type)
config.option('a').value.set('192.168.1.1') config.option('a').value.set('192.168.1.1')
config.option('a').value.set('192.168.1.0') config.option('a').value.set('192.168.1.0')
config.option('a').value.set('88.88.88.88') config.option('a').value.set('88.88.88.88')
config.option('a').value.set('0.0.0.0') config.option('a').value.set('0.0.0.0')
raises(ValueError, "config.option('a').value.set('255.255.255.0')") if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "config.option('a').value.set('255.255.255.0')")
config.option('b').value.set('192.168.1.1') config.option('b').value.set('192.168.1.1')
config.option('b').value.set('192.168.1.0') config.option('b').value.set('192.168.1.0')
raises(ValueError, "config.option('b').value.set('88.88.88.88')") if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "config.option('b').value.set('88.88.88.88')")
config.option('b').value.set('0.0.0.0') config.option('b').value.set('0.0.0.0')
raises(ValueError, "config.option('b').value.set('255.255.255.0')") if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "config.option('b').value.set('255.255.255.0')")
raises(ValueError, "config.option('a').value.set('333.0.1.20')") raises(ValueError, "config.option('a').value.set('333.0.1.20')")
raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')") if config_type != 'tiramisu-api':
with warnings.catch_warnings(record=True) as w: # FIXME
config.option('d').value.set('88.88.88.88') raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')")
assert len(w) == 1 with warnings.catch_warnings(record=True) as w:
config.option('d').value.set('88.88.88.88')
assert len(w) == 1
def test_ip_cidr(): def test_ip_cidr():
@ -60,44 +70,55 @@ def test_ip_default():
c.option('a').value.get() == '88.88.88.88' c.option('a').value.get() == '88.88.88.88'
def test_ip_reserved(): def test_ip_reserved(config_type):
a = IPOption('a', '') a = IPOption('a', '')
b = IPOption('b', '', allow_reserved=True) b = IPOption('b', '', allow_reserved=True)
c = IPOption('c', '', warnings_only=True) c = IPOption('c', '', warnings_only=True)
od = OptionDescription('od', '', [a, b, c]) od = OptionDescription('od', '', [a, b, c])
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
cfg = Config(od) cfg = Config(od)
raises(ValueError, "cfg.option('a').value.set('240.94.1.1')") cfg = get_config(cfg, config_type)
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('a').value.set('240.94.1.1')")
cfg.option('b').value.set('240.94.1.1') cfg.option('b').value.set('240.94.1.1')
with warnings.catch_warnings(record=True) as w: if config_type != 'tiramisu-api':
cfg.option('c').value.set('240.94.1.1') # FIXME
assert len(w) == 1 with warnings.catch_warnings(record=True) as w:
cfg.option('c').value.set('240.94.1.1')
assert len(w) == 1
def test_network(): def test_network(config_type):
a = NetworkOption('a', '') a = NetworkOption('a', '')
b = NetworkOption('b', '', warnings_only=True) b = NetworkOption('b', '', warnings_only=True)
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
cfg = Config(od) cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('a').value.set('192.168.1.1') cfg.option('a').value.set('192.168.1.1')
cfg.option('a').value.set('192.168.1.0') cfg.option('a').value.set('192.168.1.0')
cfg.option('a').value.set('88.88.88.88') cfg.option('a').value.set('88.88.88.88')
cfg.option('a').value.set('0.0.0.0') cfg.option('a').value.set('0.0.0.0')
raises(ValueError, "cfg.option('a').value.set(1)") raises(ValueError, "cfg.option('a').value.set(1)")
raises(ValueError, "cfg.option('a').value.set('1.1.1.1.1')") raises(ValueError, "cfg.option('a').value.set('1.1.1.1.1')")
raises(ValueError, "cfg.option('a').value.set('255.255.255.0')") if config_type != 'tiramisu-api':
raises(ValueError, "cfg.option('a').value.set('192.168.001.0')") # FIXME
raises(ValueError, "cfg.option('a').value.set('255.255.255.0')")
raises(ValueError, "cfg.option('a').value.set('192.168.001.0')")
raises(ValueError, "cfg.option('a').value.set('333.168.1.1')") raises(ValueError, "cfg.option('a').value.set('333.168.1.1')")
with warnings.catch_warnings(record=True) as w: if config_type != 'tiramisu-api':
cfg.option('b').value.set('255.255.255.0') # FIXME
assert len(w) == 1 with warnings.catch_warnings(record=True) as w:
cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1
def test_network_cidr(): def test_network_cidr(config_type):
a = NetworkOption('a', '', cidr=True) a = NetworkOption('a', '', cidr=True)
od = OptionDescription('od', '', [a]) od = OptionDescription('od', '', [a])
cfg = Config(od) cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
cfg.option('a').value.set('192.168.1.1/32') cfg.option('a').value.set('192.168.1.1/32')
cfg.option('a').value.set('192.168.1.0/24') cfg.option('a').value.set('192.168.1.0/24')
cfg.option('a').value.set('88.88.88.88/32') cfg.option('a').value.set('88.88.88.88/32')
@ -111,24 +132,28 @@ def test_network_invalid():
raises(ValueError, "NetworkOption('a', '', default='toto')") raises(ValueError, "NetworkOption('a', '', default='toto')")
def test_netmask(): def test_netmask(config_type):
a = NetmaskOption('a', '') a = NetmaskOption('a', '')
od = OptionDescription('od', '', [a]) od = OptionDescription('od', '', [a])
cfg = Config(od) cfg = Config(od)
cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('192.168.1.1.1')") raises(ValueError, "cfg.option('a').value.set('192.168.1.1.1')")
raises(ValueError, "cfg.option('a').value.set('192.168.1.1')") if config_type != 'tiramisu-api':
raises(ValueError, "cfg.option('a').value.set('192.168.1.0')") # FIXME
raises(ValueError, "cfg.option('a').value.set('88.88.88.88')") raises(ValueError, "cfg.option('a').value.set('192.168.1.1')")
raises(ValueError, "cfg.option('a').value.set('255.255.255.000')") raises(ValueError, "cfg.option('a').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('a').value.set('88.88.88.88')")
raises(ValueError, "cfg.option('a').value.set('255.255.255.000')")
raises(ValueError, "cfg.option('a').value.set(2)") raises(ValueError, "cfg.option('a').value.set(2)")
cfg.option('a').value.set('0.0.0.0') cfg.option('a').value.set('0.0.0.0')
cfg.option('a').value.set('255.255.255.0') cfg.option('a').value.set('255.255.255.0')
def test_broadcast(): def test_broadcast(config_type):
a = BroadcastOption('a', '') a = BroadcastOption('a', '')
od = OptionDescription('od', '', [a]) od = OptionDescription('od', '', [a])
cfg = Config(od) cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('192.168.1.255.1')") raises(ValueError, "cfg.option('a').value.set('192.168.1.255.1')")
raises(ValueError, "cfg.option('a').value.set('192.168.001.255')") raises(ValueError, "cfg.option('a').value.set('192.168.001.255')")
raises(ValueError, "cfg.option('a').value.set('192.168.0.300')") raises(ValueError, "cfg.option('a').value.set('192.168.0.300')")
@ -139,7 +164,7 @@ def test_broadcast():
cfg.option('a').value.set('255.255.255.0') cfg.option('a').value.set('255.255.255.0')
def test_port(): def test_port(config_type):
a = PortOption('a', '') a = PortOption('a', '')
b = PortOption('b', '', allow_zero=True) b = PortOption('b', '', allow_zero=True)
c = PortOption('c', '', allow_zero=True, allow_registred=False) c = PortOption('c', '', allow_zero=True, allow_registred=False)
@ -148,6 +173,7 @@ def test_port():
f = PortOption('f', '', allow_private=True) f = PortOption('f', '', allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f]) od = OptionDescription('od', '', [a, b, c, d, e, f])
cfg = Config(od) cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('0')") raises(ValueError, "cfg.option('a').value.set('0')")
cfg.option('a').value.set('1') cfg.option('a').value.set('1')
cfg.option('a').value.set('1023') cfg.option('a').value.set('1023')
@ -202,7 +228,7 @@ def test_port():
raises(ValueError, "cfg.option('f').value.set('65536')") raises(ValueError, "cfg.option('f').value.set('65536')")
def test_port_range(): def test_port_range(config_type):
a = PortOption('a', '', allow_range=True) a = PortOption('a', '', allow_range=True)
b = PortOption('b', '', allow_range=True, allow_zero=True) b = PortOption('b', '', allow_range=True, allow_zero=True)
c = PortOption('c', '', allow_range=True, allow_zero=True, allow_registred=False) c = PortOption('c', '', allow_range=True, allow_zero=True, allow_registred=False)
@ -211,6 +237,7 @@ def test_port_range():
f = PortOption('f', '', allow_range=True, allow_private=True) f = PortOption('f', '', allow_range=True, allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f]) od = OptionDescription('od', '', [a, b, c, d, e, f])
cfg = Config(od) cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('0')") raises(ValueError, "cfg.option('a').value.set('0')")
cfg.option('a').value.set('1') cfg.option('a').value.set('1')
cfg.option('a').value.set('1023') cfg.option('a').value.set('1023')

View File

@ -1,10 +1,11 @@
# coding: utf-8 # coding: utf-8
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config, value_list, global_owner
from py.test import raises from py.test import raises
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetmaskOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetworkOption, NetmaskOption, \
StrOption, OptionDescription, Leadership, Config StrOption, OptionDescription, Leadership, Config
from tiramisu.error import LeadershipError, PropertiesOptionError, APIError, ConfigError from tiramisu.error import LeadershipError, PropertiesOptionError, APIError, ConfigError
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -61,30 +62,34 @@ def make_description():
return descr return descr
def test_base_config(): def test_base_config(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert api.option('creole.general.activer_proxy_client').value.get() is False cfg = get_config(cfg, config_type)
assert api.option('creole.general.nom_machine').value.get() == "eoleng" assert cfg.option('creole.general.activer_proxy_client').value.get() is False
assert api.option.find('nom_machine', first=True).value.get() == "eoleng" assert cfg.option('creole.general.nom_machine').value.get() == "eoleng"
if config_type != 'tiramisu-api':
assert cfg.option.find('nom_machine', first=True).value.get() == "eoleng"
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1, result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None, 'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris', 'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine': 'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
'eoleng', 'general.activer_proxy_client': False} 'eoleng', 'general.activer_proxy_client': False}
assert api.option('creole').value.dict() == result assert cfg.option('creole').value.dict() == result
result = {'serveur_ntp': [], 'mode_conteneur_actif': False, result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None, 'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client': 'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
False, 'nombre_interfaces': 1} False, 'nombre_interfaces': 1}
assert api.option('creole').value.dict(flatten=True) == result assert cfg.option('creole').value.dict(flatten=True) == result
if config_type == 'tiramisu-api':
cfg.send()
def test_make_dict_filter(): def test_make_dict_filter():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
subresult = {'numero_etab': None, 'nombre_interfaces': 1, subresult = {'numero_etab': None, 'nombre_interfaces': 1,
'serveur_ntp': [], 'mode_conteneur_actif': False, 'serveur_ntp': [], 'mode_conteneur_actif': False,
'time_zone': 'Paris', 'nom_machine': 'eoleng', 'time_zone': 'Paris', 'nom_machine': 'eoleng',
@ -92,17 +97,17 @@ def test_make_dict_filter():
result = {} result = {}
for key, value in subresult.items(): for key, value in subresult.items():
result['general.' + key] = value result['general.' + key] = value
assert api.option('creole').value.dict(withoption='numero_etab') == result assert cfg.option('creole').value.dict(withoption='numero_etab') == result
raises(AttributeError, "api.option('creole').value.dict(withoption='numero_etab', withvalue='toto')") raises(AttributeError, "cfg.option('creole').value.dict(withoption='numero_etab', withvalue='toto')")
assert api.option('creole').value.dict(withoption='numero_etab', withvalue=None) == result assert cfg.option('creole').value.dict(withoption='numero_etab', withvalue=None) == result
assert api.option('creole.general').value.dict(withoption='numero_etab') == subresult assert cfg.option('creole.general').value.dict(withoption='numero_etab') == subresult
def test_get_group_type(): def test_get_group_type():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
grp = api.option('creole.general') grp = cfg.option('creole.general')
assert grp.group_type() == groups.family assert grp.group_type() == groups.family
assert grp.group_type() == 'family' assert grp.group_type() == 'family'
assert isinstance(grp.group_type(), groups.GroupType) assert isinstance(grp.group_type(), groups.GroupType)
@ -110,55 +115,55 @@ def test_get_group_type():
def test_iter_on_groups(): def test_iter_on_groups():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
result = api.option('creole').list('optiondescription', result = cfg.option('creole').list('optiondescription',
group_type=groups.family) group_type=groups.family)
group_names = [res.option.name() for res in result] group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1'] assert group_names == ['general', 'interface1']
for i in api.option('creole').list('optiondescription', for i in cfg.option('creole').list('optiondescription',
group_type=groups.family): group_type=groups.family):
#test StopIteration #test StopIteration
break break
result = api.option('creole').list('option', result = cfg.option('creole').list('option',
group_type=groups.family) group_type=groups.family)
assert list(result) == [] assert list(result) == []
result = api.option('creole.general').list('optiondescription', result = cfg.option('creole.general').list('optiondescription',
group_type=groups.family) group_type=groups.family)
assert list(result) == [] assert list(result) == []
def test_list_recursive(): def test_list_recursive():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
result = api.option('creole').list('all') result = cfg.option('creole').list('all')
group_names = [res.option.name() for res in result] group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1'] assert group_names == ['general', 'interface1']
# #
result = api.option.list(recursive=True) result = cfg.option.list(recursive=True)
group_names = [res.option.name() for res in result] group_names = [res.option.name() for res in result]
assert group_names == ['numero_etab', 'nom_machine', 'nombre_interfaces', assert group_names == ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif', 'activer_proxy_client', 'mode_conteneur_actif',
'serveur_ntp', 'time_zone', 'ip_admin_eth0', 'serveur_ntp', 'time_zone', 'ip_admin_eth0',
'netmask_admin_eth0'] 'netmask_admin_eth0']
result = list(api.option.list(recursive=True, type='optiondescription')) result = list(cfg.option.list(recursive=True, type='optiondescription'))
group_names = [res.option.name() for res in result] group_names = [res.option.name() for res in result]
assert group_names == ['general', 'ip_admin_eth0', 'interface1', 'creole'] assert group_names == ['general', 'ip_admin_eth0', 'interface1', 'creole']
def test_iter_on_groups_force_permissive(): def test_iter_on_groups_force_permissive():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
result = api.forcepermissive.option('creole.general').list() result = cfg.forcepermissive.option('creole.general').list()
group_names = [res.option.name() for res in result] group_names = [res.option.name() for res in result]
ass = ['numero_etab', 'nom_machine', 'nombre_interfaces', ass = ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif', 'activer_proxy_client', 'mode_conteneur_actif',
'mode_conteneur_actif2', 'serveur_ntp', 'time_zone'] 'mode_conteneur_actif2', 'serveur_ntp', 'time_zone']
assert group_names == ass assert group_names == ass
# mode_conteneur_actif2 is not visible is not forcepermissive # mode_conteneur_actif2 is not visible is not forcepermissive
result = api.option('creole.general').list() result = cfg.option('creole.general').list()
group_names = [res.option.name() for res in result] group_names = [res.option.name() for res in result]
ass.remove('mode_conteneur_actif2') ass.remove('mode_conteneur_actif2')
assert group_names == ass assert group_names == ass
@ -166,10 +171,10 @@ def test_iter_on_groups_force_permissive():
def test_iter_group_on_groups_force_permissive(): def test_iter_group_on_groups_force_permissive():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
result = api.forcepermissive.option('creole').list(type='optiondescription', result = cfg.forcepermissive.option('creole').list(type='optiondescription',
group_type=groups.family) group_type=groups.family)
group_names = [res.option.name() for res in result] group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1', 'new'] assert group_names == ['general', 'interface1', 'new']
@ -177,27 +182,27 @@ def test_iter_group_on_groups_force_permissive():
def test_iter_on_groups_props(): def test_iter_on_groups_props():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.option('creole.interface1').property.add('disabled') cfg.option('creole.interface1').property.add('disabled')
result = api.option('creole').list(type='optiondescription', result = cfg.option('creole').list(type='optiondescription',
group_type=groups.family) group_type=groups.family)
group_names = [res.option.name() for res in result] group_names = [res.option.name() for res in result]
assert group_names == ['general'] assert group_names == ['general']
def test_iter_on_empty_group(): def test_iter_on_empty_group():
api = Config(OptionDescription("name", "descr", [])) cfg = Config(OptionDescription("name", "descr", []))
api.property.read_write() cfg.property.read_write()
result = list(api.option.list(type='optiondescription')) result = list(cfg.option.list(type='optiondescription'))
assert result == [] assert result == []
def test_iter_not_group(): def test_iter_not_group():
api = Config(OptionDescription("name", "descr", [])) cfg = Config(OptionDescription("name", "descr", []))
api.property.read_write() cfg.property.read_write()
try: try:
list(api.option.list(type='optiondescription', group_type='family')) list(cfg.option.list(type='optiondescription', group_type='family'))
except AssertionError: except AssertionError:
pass pass
else: else:
@ -211,28 +216,31 @@ def test_groups_with_leader():
assert interface1.impl_get_group_type() == groups.leadership assert interface1.impl_get_group_type() == groups.leadership
def test_groups_is_leader(): def test_groups_is_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, default_multi='value') netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, default_multi='value')
interface1 = Leadership('leadership', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('leadership', '', [ip_admin_eth0, netmask_admin_eth0])
var = StrOption('var', "ip réseau autorisé", multi=True) var = StrOption('var', "ip réseau autorisé", multi=True)
od2 = OptionDescription('od2', '', [var]) od2 = OptionDescription('od2', '', [var])
od1 = OptionDescription('od', '', [interface1, od2]) od1 = OptionDescription('od', '', [interface1, od2])
api = Config(od1) cfg = Config(od1)
assert not api.option('od2').option.isleadership() cfg = get_config(cfg, config_type)
assert api.option('leadership').option.isleadership() assert not cfg.option('od2').option.isleadership()
assert not api.option('od2.var').option.isleader() assert cfg.option('leadership').option.isleadership()
assert not api.option('od2.var').option.isfollower() assert not cfg.option('od2.var').option.isleader()
assert api.option('leadership.ip_admin_eth0').option.ismulti() assert not cfg.option('od2.var').option.isfollower()
assert api.option('leadership.netmask_admin_eth0').option.ismulti() assert cfg.option('leadership.ip_admin_eth0').option.ismulti()
assert not api.option('leadership.ip_admin_eth0').option.issubmulti() assert cfg.option('leadership.netmask_admin_eth0').option.ismulti()
assert not api.option('leadership.netmask_admin_eth0').option.issubmulti() assert not cfg.option('leadership.ip_admin_eth0').option.issubmulti()
assert api.option('leadership.ip_admin_eth0').option.isleader() assert not cfg.option('leadership.netmask_admin_eth0').option.issubmulti()
assert not api.option('leadership.ip_admin_eth0').option.isfollower() assert cfg.option('leadership.ip_admin_eth0').option.isleader()
assert not api.option('leadership.netmask_admin_eth0').option.isleader() assert not cfg.option('leadership.ip_admin_eth0').option.isfollower()
assert api.option('leadership.netmask_admin_eth0').option.isfollower() assert not cfg.option('leadership.netmask_admin_eth0').option.isleader()
assert api.option('leadership.netmask_admin_eth0').option.path() == 'leadership.netmask_admin_eth0' assert cfg.option('leadership.netmask_admin_eth0').option.isfollower()
assert api.option('leadership.netmask_admin_eth0').option.defaultmulti() == 'value' assert cfg.option('leadership.netmask_admin_eth0').option.path() == 'leadership.netmask_admin_eth0'
assert cfg.option('leadership.netmask_admin_eth0').option.defaultmulti() == 'value'
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_in_root(): def test_groups_with_leader_in_root():
@ -252,57 +260,70 @@ def test_groups_with_leader_in_config():
assert interface1.impl_get_group_type() == groups.leadership assert interface1.impl_get_group_type() == groups.leadership
def test_groups_with_leader_make_dict(): def test_groups_with_leader_make_dict(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1]) od = OptionDescription('root', '', [interface1])
api = Config(od) cfg = Config(od)
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []} cfg = get_config(cfg, config_type)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0 assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []}
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 0 if config_type != 'tiramisu-api':
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2']) # FIXME useful? already in leadership
assert api.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2 assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2 assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 0
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]} cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
if config_type != 'tiramisu-api':
# FIXME
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]}
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_default_value(): def test_groups_with_leader_default_value(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1]) od = OptionDescription('root', '', [interface1])
api = Config(od) cfg = Config(od)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.default() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2'] cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.default() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_default_value_2(): def test_groups_with_leader_default_value_2(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", ['ip1', 'ip2'], multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", ['ip1', 'ip2'], multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='netmask1', multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='netmask1', multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1]) od = OptionDescription('root', '', [interface1])
api = Config(od) cfg = Config(od)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2'] cfg = get_config(cfg, config_type)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip3', 'ip4']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip3', 'ip4'] cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip3', 'ip4'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip3', 'ip4']
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
# #
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask1' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('netmask2') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('netmask2')
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask2' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask2'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert api.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_hidden_in_config(): def test_groups_with_leader_hidden_in_config():
@ -310,14 +331,14 @@ def test_groups_with_leader_hidden_in_config():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1]) od = OptionDescription('root', '', [interface1])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
def test_groups_with_leader_hidden_in_config2(): def test_groups_with_leader_hidden_in_config2():
@ -325,53 +346,67 @@ def test_groups_with_leader_hidden_in_config2():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',)) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1]) od = OptionDescription('root', '', [interface1])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#del #del
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.property.pop('hidden') cfg.property.pop('hidden')
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
api.property.add('hidden') cfg.property.add('hidden')
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.property.pop('hidden') cfg.property.pop('hidden')
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
def test_groups_with_leader_reset_empty(): def test_groups_with_leader_reset_empty(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1]) od_ = OptionDescription('root', '', [interface1])
api = Config(od_) cfg = Config(od_)
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg = get_config(cfg, config_type)
raises(LeadershipError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()") cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) if config_type != 'tiramisu-api':
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset() raises(LeadershipError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_reset_out_of_range(): def test_groups_with_leader_reset_out_of_range(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1]) od_ = OptionDescription('root', '', [interface1])
api = Config(od_) cfg_ori = Config(od_)
api.property.read_write() cfg_ori.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) cfg = get_config(cfg_ori, config_type)
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset() if config_type == 'tiramisu-api':
raises(LeadershipError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.reset()") cfg.send()
raises(IndexError, "api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)") cfg_ori.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
if config_type != 'tiramisu-api':
# FIXME
raises(LeadershipError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.reset()")
raises(IndexError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)")
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_hidden_in_config3(): def test_groups_with_leader_hidden_in_config3():
@ -380,14 +415,14 @@ def test_groups_with_leader_hidden_in_config3():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1]) od = OptionDescription('root', '', [interface1])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
def test_allowed_groups(): def test_allowed_groups():
@ -398,20 +433,26 @@ def test_allowed_groups():
raises(ValueError, "interface1.impl_set_group_type('toto')") raises(ValueError, "interface1.impl_set_group_type('toto')")
def test_values_with_leader_disabled_leader(): def test_values_with_leader_disabled_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg_ori = Config(maconfig)
api.property.read_write() cfg_ori.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145']) cfg = get_config(cfg_ori, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145") cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset() cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.option('ip_admin_eth0.ip_admin_eth0').property.add('disabled') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')") cfg_ori.option('ip_admin_eth0.ip_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
if config_type != 'tiramisu-api':
# FIXME
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')")
if config_type == 'tiramisu-api':
cfg.send()
def test_sub_group_in_leader_group(): def test_sub_group_in_leader_group():
@ -428,48 +469,54 @@ def test_group_always_has_multis():
#____________________________________________________________ #____________________________________________________________
def test_values_with_leader_and_followers(): def test_values_with_leader_and_followers(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
owner = api.owner.get() owner = global_owner(cfg, config_type)
cfg = get_config(cfg, config_type)
assert interface1.impl_get_group_type() == groups.leadership assert interface1.impl_get_group_type() == groups.leadership
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])") if config_type != 'tiramisu-api':
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)") # FIXME
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])")
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)")
if config_type == 'tiramisu-api':
cfg.send()
def test_reset_values_with_leader_and_followers(): def test_reset_values_with_leader_and_followers(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
owner = api.owner.get() owner = global_owner(cfg, config_type)
cfg = Config(maconfig)
assert interface1.impl_get_group_type() == groups.leadership assert interface1.impl_get_group_type() == groups.leadership
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#reset #reset
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
def test_reset_values_with_leader_and_followers_default_value(): def test_reset_values_with_leader_and_followers_default_value():
@ -478,113 +525,129 @@ def test_reset_values_with_leader_and_followers_default_value():
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])") raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_reset_values_with_leader_and_followers_default(): def test_reset_values_with_leader_and_followers_default(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['192.168.230.145']) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['192.168.230.145'])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
owner = api.owner.get() owner = global_owner(cfg, config_type)
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() cfg = get_config(cfg, config_type)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_follower(): def test_values_with_leader_and_followers_follower(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(LeadershipError, cfg = get_config(cfg, config_type)
"api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')") if config_type != 'tiramisu-api':
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145']) raises(LeadershipError,
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
raises(APIError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)") if config_type != 'tiramisu-api':
# FIXME
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)")
#reset #reset
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
'192.168.230.145', '192.168.230.145',
'192.168.230.145']) '192.168.230.145'])
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_pop(): def test_values_with_leader_and_followers_pop(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145']) cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.146']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.146'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146'] cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.146'] cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.146']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_leader(): def test_values_with_leader_and_followers_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
raises(LeadershipError, "api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])") cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' if config_type != 'tiramisu-api':
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0' raises(LeadershipError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])")
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1) assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0' cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
if config_type == 'tiramisu-api':
cfg.send()
def test_values_with_leader_and_followers_leader_pop(): def test_values_with_leader_and_followers_leader_pop():
@ -592,97 +655,122 @@ def test_values_with_leader_and_followers_leader_pop():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"])
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (1,)), (('192.168.230.145', '192.168.230.146'), ('255.255.0.0',)), ('user', ('user',)))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (1,)), (('192.168.230.145', '192.168.230.146'), ('255.255.0.0',)), ('user', ('user',))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146',), ('255.255.0.0',)), ('user', ('user',)))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146',), ('255.255.0.0',)), ('user', ('user',))))
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.146"] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.146"]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"])
api.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0') cfg.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0')
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user')))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148", "192.168.230.149"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(5) cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(5)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user')))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 3, 4)), (('192.168.230.146', "192.168.230.145", "192.168.230.146", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2) cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2, 3)), (('192.168.230.146', "192.168.230.145", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user')))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2, 3)), (('192.168.230.146', "192.168.230.145", "192.168.230.147", "192.168.230.148"), ('255.255.0.0', '255.255.0.0', '255.255.0.0')), ('user', ('user', 'user', 'user'))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2) cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2)), (('192.168.230.146', "192.168.230.145", "192.168.230.148"), ('255.255.0.0', '255.255.0.0')), ('user', ('user', 'user')))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0, 2)), (('192.168.230.146', "192.168.230.145", "192.168.230.148"), ('255.255.0.0', '255.255.0.0')), ('user', ('user', 'user'))))
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(2) cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146', "192.168.230.145"), ('255.255.0.0',)), ('user', ('user',)))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'), (None, (0,)), (('192.168.230.146', "192.168.230.145"), ('255.255.0.0',)), ('user', ('user',))))
def test_values_with_leader_owner(): def test_values_with_leader_owner(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
owner = api.owner.get() owner = cfg.owner.get()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault() cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault() assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
def test_values_with_leader_disabled(): def test_values_with_leader_disabled(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg_ori = Config(maconfig)
api.property.read_write() cfg_ori.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) cfg = get_config(cfg_ori, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145") cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled') cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) if config_type == 'tiramisu-api':
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) cfg.send()
cfg_ori.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api':
cfg.send()
#delete with value in disabled var #delete with value in disabled var
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled') cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) cfg = get_config(cfg_ori, config_type)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145") cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0) if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
#append with value in disabled var ##append with value in disabled var
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled') if config_type == 'tiramisu-api':
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"]) cfg.send()
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145") cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
api.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled') cfg = get_config(cfg_ori, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", '192.168.230.43']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", '192.168.230.43'])
if config_type == 'tiramisu-api':
cfg.send()
def test_multi_non_valid_value(): def test_multi_non_valid_value(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
maconfig = OptionDescription('toto', '', [ip_admin_eth0]) maconfig = OptionDescription('toto', '', [ip_admin_eth0])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0').value.set(['a']) cfg = get_config(cfg, config_type)
raises(ValueError, "api.option('ip_admin_eth0').value.set([1])") cfg.option('ip_admin_eth0').value.set(['a'])
raises(ValueError, "cfg.option('ip_admin_eth0').value.set([1])")
if config_type == 'tiramisu-api':
cfg.send()
def test_multi_leader_default_follower(): def test_multi_leader_default_follower(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", default_multi="255.255.255.0", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", default_multi="255.255.255.0", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) cfg = get_config(cfg, config_type)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1'] cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
if config_type == 'tiramisu-api':
cfg.send()
def test_groups_with_leader_get_modified_value(): def test_groups_with_leader_get_modified_value():
@ -690,32 +778,35 @@ def test_groups_with_leader_get_modified_value():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
compare(api.value.exportation(), ((), (), (), ())) compare(cfg.value.exportation(), ((), (), (), ()))
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0',), (None,), (('192.168.1.1',),), ('user',))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0',), (None,), (('192.168.1.1',),), ('user',)))
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0,)), (('192.168.1.1',), ('255.255.255.255',)), ('user', ('user',)))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0,)), (('192.168.1.1',), ('255.255.255.255',)), ('user', ('user',))))
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
compare(api.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0, 1)), (('192.168.1.1', '192.168.1.1'), ('255.255.255.255', '255.255.255.255')), ('user', ('user', 'user')))) compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0, 1)), (('192.168.1.1', '192.168.1.1'), ('255.255.255.255', '255.255.255.255')), ('user', ('user', 'user'))))
def test_groups_with_leader_importation(): def test_groups_with_leader_importation(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) maconfig = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.value.importation((('ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0',), (None, (0, 1)), (('192.168.1.1', '192.168.1.0'), ('255.255.255.255', '255.255.255.0')), ('user', ('user', 'user')))) cfg.value.importation([['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'], [None, [0, 1]], [['192.168.1.1', '192.168.1.0'], ['255.255.255.255', '255.255.255.0']], ['user', ['user', 'user']]])
api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1', '192.168.1.0'] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.255' cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1', '192.168.1.0']
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0' cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.255'
api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == 'user' cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'user' cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == 'user'
api.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user' cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'user'
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user'
if config_type == 'tiramisu-api':
cfg.send()
def test_wrong_index(): def test_wrong_index():
@ -724,15 +815,15 @@ def test_wrong_index():
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface1]) od1 = OptionDescription('od', '', [interface1])
maconfig = OptionDescription('toto', '', [od1]) maconfig = OptionDescription('toto', '', [od1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('od.ip_admin_eth0.ip_admin_eth0').option.get() assert cfg.option('od.ip_admin_eth0.ip_admin_eth0').option.get()
raises(APIError, "api.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()") raises(APIError, "cfg.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()")
assert api.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get() assert cfg.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get()
assert api.option('od.ip_admin_eth0').option.get() assert cfg.option('od.ip_admin_eth0').option.get()
raises(APIError, "api.option('od.ip_admin_eth0', 0).option.get()") raises(APIError, "cfg.option('od.ip_admin_eth0', 0).option.get()")
assert api.option('od').option.get() assert cfg.option('od').option.get()
raises(APIError, "api.option('od', 0).option.get()") raises(APIError, "cfg.option('od', 0).option.get()")
def test_without_leader_or_follower(): def test_without_leader_or_follower():
@ -778,8 +869,24 @@ def test_follower_not_same_not_equal():
interface1 = Leadership('interface1', '', [ip_admin_eth1, netmask_admin_eth1]) interface1 = Leadership('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface0, interface1]) od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1]) maconfig = OptionDescription('toto', '', [od1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
def test_follower_consistency():
network_admin_eth1 = NetworkOption('network_admin_eth1', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth1 = NetmaskOption('netmask_admin_eth1', "masque du sous-réseau", multi=True)
netmask_admin_eth1.impl_add_consistency('network_netmask', network_admin_eth1)
interface1 = Leadership('interface1', '', [network_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface1])
maconfig = OptionDescription('toto', '', [od1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg.option('od.interface1.network_admin_eth1').value.set(['192.168.1.128', '192.168.2.0', '192.168.3.128'])
cfg.option('od.interface1.netmask_admin_eth1', 0).value.set('255.255.255.128')
cfg.option('od.interface1.netmask_admin_eth1', 1).value.set('255.255.255.0')
cfg.option('od.interface1.netmask_admin_eth1', 2).value.set('255.255.255.128')
cfg.option('od.interface1.network_admin_eth1').value.pop(0)
def test_follower_force_store_value(): def test_follower_force_store_value():

View File

@ -1,9 +1,9 @@
# coding: utf-8 # coding: utf-8
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
# FIXME from .config import config_type, get_config
from py.test import raises from py.test import raises
from tiramisu.api import TIRAMISU_VERSION
from tiramisu import Config from tiramisu import Config
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \ from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
SymLinkOption, Leadership, undefined, Params, ParamOption SymLinkOption, Leadership, undefined, Params, ParamOption
@ -78,71 +78,71 @@ def make_description3():
def test_mandatory_ro(): def test_mandatory_ro():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str1').value.get() cfg.option('str1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
api.property.read_write() cfg.property.read_write()
api.option('str1').value.set('yes') cfg.option('str1').value.set('yes')
api.property.read_only() cfg.property.read_only()
assert api.option('str1').value.get() == 'yes' assert cfg.option('str1').value.get() == 'yes'
def test_mandatory_ro_dict(): def test_mandatory_ro_dict():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.value.dict() cfg.value.dict()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
api.property.read_write() cfg.property.read_write()
api.option('str1').value.set('yes') cfg.option('str1').value.set('yes')
api.option('unicode2').value.set('yes') cfg.option('unicode2').value.set('yes')
api.property.read_only() cfg.property.read_only()
try: try:
api.value.dict() cfg.value.dict()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
api.property.read_write() cfg.property.read_write()
api.option('str3').value.set(['yes']) cfg.option('str3').value.set(['yes'])
api.property.read_only() cfg.property.read_only()
assert api.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'str4': [], 'unicode2': 'yes'} assert cfg.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'str4': [], 'unicode2': 'yes'}
def test_mandatory_rw(): def test_mandatory_rw():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
# not mandatory in rw # not mandatory in rw
api.option('str1').value.get() cfg.option('str1').value.get()
api.option('str1').value.set('yes') cfg.option('str1').value.set('yes')
assert api.option('str1').value.get() == 'yes' assert cfg.option('str1').value.get() == 'yes'
def test_mandatory_default(): def test_mandatory_default():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
#not mandatory in rw #not mandatory in rw
api.option('str').value.get() cfg.option('str').value.get()
api.property.read_write() cfg.property.read_write()
api.option('str').value.set('yes') cfg.option('str').value.set('yes')
api.property.read_only() cfg.property.read_only()
api.option('str').value.get() cfg.option('str').value.get()
api.property.read_write() cfg.property.read_write()
api.option('str').value.set(None) cfg.option('str').value.set(None)
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str').value.get() cfg.option('str').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
@ -150,40 +150,40 @@ def test_mandatory_default():
def test_mandatory_delete(): def test_mandatory_delete():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
api.option('str').value.get() cfg.option('str').value.get()
try: try:
api.option('str1').value.get() cfg.option('str1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
api.property.read_write() cfg.property.read_write()
api.option('str1').value.set('yes') cfg.option('str1').value.set('yes')
api.property.read_only() cfg.property.read_only()
assert api.option('str1').value.get() == 'yes' assert cfg.option('str1').value.get() == 'yes'
api.property.pop('everything_frozen') cfg.property.pop('everything_frozen')
prop = [] prop = []
try: try:
api.option('str1').value.reset() cfg.option('str1').value.reset()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
api.option('str').value.reset() cfg.option('str').value.reset()
assert api.option('str1').value.get() == 'yes' assert cfg.option('str1').value.get() == 'yes'
#valeur vide : None, '', u'', ... #valeur vide : None, '', u'', ...
def test_mandatory_none(): def test_mandatory_none():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str1').value.set(None) cfg.option('str1').value.set(None)
assert api.option('str1').owner.get() == 'user' assert cfg.option('str1').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str1').value.get() cfg.option('str1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
@ -191,13 +191,13 @@ def test_mandatory_none():
def test_mandatory_empty(): def test_mandatory_empty():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str1').value.set('') cfg.option('str1').value.set('')
assert api.option('str1').owner.get() == 'user' assert cfg.option('str1').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str1').value.get() cfg.option('str1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
@ -205,23 +205,23 @@ def test_mandatory_empty():
def test_mandatory_multi_none(): def test_mandatory_multi_none():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str3').value.set([None]) cfg.option('str3').value.set([None])
assert api.option('str3').owner.get() == 'user' assert cfg.option('str3').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str3').value.get() cfg.option('str3').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
api.property.read_write() cfg.property.read_write()
api.option('str3').value.set(['yes', None]) cfg.option('str3').value.set(['yes', None])
assert api.option('str3').owner.get() == 'user' assert cfg.option('str3').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str3').value.get() cfg.option('str3').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
@ -229,35 +229,35 @@ def test_mandatory_multi_none():
def test_mandatory_multi_empty(): def test_mandatory_multi_empty():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str3').value.set([]) cfg.option('str3').value.set([])
assert api.option('str3').owner.get() == 'user' assert cfg.option('str3').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str3').value.get() cfg.option('str3').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
# #
api.property.read_write() cfg.property.read_write()
api.option('str3').value.set(['']) cfg.option('str3').value.set([''])
assert api.option('str3').owner.get() == 'user' assert cfg.option('str3').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str3').value.get() cfg.option('str3').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
# #
api.property.read_write() cfg.property.read_write()
api.option('str3').value.set(['yes', '']) cfg.option('str3').value.set(['yes', ''])
assert api.option('str3').owner.get() == 'user' assert cfg.option('str3').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str3').value.get() cfg.option('str3').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
@ -265,31 +265,31 @@ def test_mandatory_multi_empty():
def test_mandatory_multi_empty_allow_empty_list(): def test_mandatory_multi_empty_allow_empty_list():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str4').value.set([]) cfg.option('str4').value.set([])
assert api.option('str4').owner.get() == 'user' assert cfg.option('str4').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
api.option('str4').value.get() cfg.option('str4').value.get()
# #
api.property.read_write() cfg.property.read_write()
api.option('str4').value.set(['']) cfg.option('str4').value.set([''])
assert api.option('str4').owner.get() == 'user' assert cfg.option('str4').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str4').value.get() cfg.option('str4').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
# #
api.property.read_write() cfg.property.read_write()
api.option('str4').value.set(['yes', '']) cfg.option('str4').value.set(['yes', ''])
assert api.option('str4').owner.get() == 'user' assert cfg.option('str4').owner.get() == 'user'
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('str4').value.get() cfg.option('str4').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
@ -297,47 +297,44 @@ def test_mandatory_multi_empty_allow_empty_list():
def test_mandatory_multi_append(): def test_mandatory_multi_append():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str3').value.set(['yes']) cfg.option('str3').value.set(['yes'])
api.property.read_write() cfg.property.read_write()
api.option('str3').value.get().append(None) cfg.option('str3').value.get().append(None)
def test_mandatory_disabled(): def test_mandatory_disabled():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str1').value.get() cfg.option('str1').value.get()
api.option('str1').property.add('disabled') cfg.option('str1').property.add('disabled')
api.property.read_only() cfg.property.read_only()
pop = [] pop = []
try: try:
api.option('str1').value.get() cfg.option('str1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
if TIRAMISU_VERSION == 2: search_prop = {'disabled'}
search_prop = {'disabled', 'mandatory'}
else:
search_prop = {'disabled'}
assert set(prop) == search_prop assert set(prop) == search_prop
def test_mandatory_unicode(): def test_mandatory_unicode():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('unicode2').value.get() cfg.option('unicode2').value.get()
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('unicode2').value.get() cfg.option('unicode2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
api.property.read_write() cfg.property.read_write()
api.option('unicode2').value.set(u'') cfg.option('unicode2').value.set(u'')
api.property.read_only() cfg.property.read_only()
prop = [] prop = []
try: try:
api.option('unicode2').value.get() cfg.option('unicode2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
@ -345,66 +342,66 @@ def test_mandatory_unicode():
def test_mandatory_warnings_ro(): def test_mandatory_warnings_ro():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str').value.set('') cfg.option('str').value.set('')
api.property.read_only() cfg.property.read_only()
proc = [] proc = []
try: try:
api.option('str').value.get() cfg.option('str').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'mandatory' in prop assert 'mandatory' in prop
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3'] assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
api.property.read_write() cfg.property.read_write()
api.option('str').value.set('a') cfg.option('str').value.set('a')
api.property.read_only() cfg.property.read_only()
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3'] assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_rw(): def test_mandatory_warnings_rw():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str').value.set('') cfg.option('str').value.set('')
api.property.read_write() cfg.property.read_write()
api.option('str').value.get() cfg.option('str').value.get()
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3'] assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
api.option('str').value.set('a') cfg.option('str').value.set('a')
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3'] assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_disabled(): def test_mandatory_warnings_disabled():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str').value.set('') cfg.option('str').value.set('')
api.property.read_write() cfg.property.read_write()
api.option('str').value.get() cfg.option('str').value.get()
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'} assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
api.option('str').property.add('disabled') cfg.option('str').property.add('disabled')
assert set(api.value.mandatory()) == {'str1', 'unicode2', 'str3'} assert set(cfg.value.mandatory()) == {'str1', 'unicode2', 'str3'}
def test_mandatory_warnings_hidden(): def test_mandatory_warnings_hidden():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str').value.set('') cfg.option('str').value.set('')
api.property.read_write() cfg.property.read_write()
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
api.option('str').value.get() cfg.option('str').value.get()
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'} assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
api.option('str').property.add('hidden') cfg.option('str').property.add('hidden')
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'} assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
def test_mandatory_warnings_frozen(): def test_mandatory_warnings_frozen():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.option('str').value.set('') cfg.option('str').value.set('')
api.property.read_write() cfg.property.read_write()
api.option('str').value.get() cfg.option('str').value.get()
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'} assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
api.option('str').property.add('frozen') cfg.option('str').property.add('frozen')
api.property.read_only() cfg.property.read_only()
assert set(api.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'} assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
def test_mandatory_leader(): def test_mandatory_leader():
@ -414,10 +411,10 @@ def test_mandatory_leader():
multi=True) multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1]) descr = OptionDescription('o', '', [interface1])
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.value.dict()") raises(PropertiesOptionError, "cfg.value.dict()")
def test_mandatory_warnings_leader(): def test_mandatory_warnings_leader():
@ -427,8 +424,8 @@ def test_mandatory_warnings_leader():
multi=True) multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1]) descr = OptionDescription('o', '', [interface1])
api = Config(descr) cfg = Config(descr)
assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0'] assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
def test_mandatory_leader_empty(): def test_mandatory_leader_empty():
@ -437,40 +434,40 @@ def test_mandatory_leader_empty():
multi=True) multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1]) descr = OptionDescription('o', '', [interface1])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
api.property.read_only() cfg.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [''] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
api.property.read_only() cfg.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.property.read_write() cfg.property.read_write()
# #
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
api.property.read_only() cfg.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
# #
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
api.property.read_only() cfg.property.read_only()
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.reset()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()")
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
def test_mandatory_warnings_leader_empty(): def test_mandatory_warnings_leader_empty():
@ -479,22 +476,22 @@ def test_mandatory_warnings_leader_empty():
multi=True) multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1]) descr = OptionDescription('o', '', [interface1])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0'] assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
api.option('ip_admin_eth0.ip_admin_eth0').value.reset() cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [''] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(api.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0'] assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
# #
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(api.value.mandatory()) == [] assert list(cfg.value.mandatory()) == []
def test_mandatory_follower(): def test_mandatory_follower():
@ -503,27 +500,27 @@ def test_mandatory_follower():
multi=True, properties=('mandatory', )) multi=True, properties=('mandatory', ))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1]) descr = OptionDescription('o', '', [interface1])
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
# #
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
api.property.read_only() cfg.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
api.property.read_only() cfg.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.property.read_write() cfg.property.read_write()
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
api.property.read_only() cfg.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
def test_mandatory_warnings_follower(): def test_mandatory_warnings_follower():
@ -532,43 +529,43 @@ def test_mandatory_warnings_follower():
multi=True, properties=('mandatory', )) multi=True, properties=('mandatory', ))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1]) descr = OptionDescription('o', '', [interface1])
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
# #
api.property.read_write() cfg.property.read_write()
assert list(api.value.mandatory()) == [] assert list(cfg.value.mandatory()) == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(api.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0'] assert list(cfg.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0']
def test_mandatory_warnings_symlink(): def test_mandatory_warnings_symlink():
descr = make_description_sym() descr = make_description_sym()
api = Config(descr) cfg = Config(descr)
api.option('str').value.set('') cfg.option('str').value.set('')
api.property.read_write() cfg.property.read_write()
api.option('str').value.get() cfg.option('str').value.get()
assert list(api.value.mandatory()) == ['str', 'str1', 'str3'] assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
api.option('str').property.add('frozen') cfg.option('str').property.add('frozen')
api.property.read_only() cfg.property.read_only()
assert list(api.value.mandatory()) == ['str', 'str1', 'str3'] assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
#def test_mandatory_warnings_validate(): #def test_mandatory_warnings_validate():
# descr = make_description3() # descr = make_description3()
# api = Config(descr) # cfg = Config(descr)
# api.option('str').value.set('') # cfg.option('str').value.set('')
# raises(ValueError, "list(api.value.mandatory())") # raises(ValueError, "list(cfg.value.mandatory())")
# api.option('str').value.set('test') # cfg.option('str').value.set('test')
# raises(ValueError, "list(api.value.mandatory())") # raises(ValueError, "list(cfg.value.mandatory())")
def test_mandatory_warnings_validate_empty(): def test_mandatory_warnings_validate_empty():
descr = make_description2() descr = make_description2()
api = Config(descr) cfg = Config(descr)
api.option('str').value.set('') cfg.option('str').value.set('')
api.property.read_only() cfg.property.read_only()
assert list(api.value.mandatory()) == ['str', 'str1', 'str3', 'unicode1'] assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
def test_mandatory_warnings_requires(): def test_mandatory_warnings_requires():
@ -580,16 +577,16 @@ def test_mandatory_warnings_requires():
properties=('mandatory', )) properties=('mandatory', ))
stroption3 = StrOption('str3', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}]) stroption3 = StrOption('str3', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3]) descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
api = Config(descr) cfg = Config(descr)
api.option('str').value.set('') cfg.option('str').value.set('')
api.property.read_write() cfg.property.read_write()
api.option('str').value.get() cfg.option('str').value.get()
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2'] assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
api.property.read_only() cfg.property.read_only()
assert list(api.value.mandatory()) == ['str', 'str1', 'unicode2'] assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
api.property.read_write() cfg.property.read_write()
api.option('str').value.set('yes') cfg.option('str').value.set('yes')
assert list(api.value.mandatory()) == ['str1', 'unicode2', 'str3'] assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
def test_mandatory_warnings_requires_leadership(): def test_mandatory_warnings_requires_leadership():
@ -599,12 +596,12 @@ def test_mandatory_warnings_requires_leadership():
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}]) stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
leadership = Leadership('leader', 'leadership', [stroption1, stroption2]) leadership = Leadership('leader', 'leadership', [stroption1, stroption2])
descr = OptionDescription('tiram', '', [stroption, leadership]) descr = OptionDescription('tiram', '', [stroption, leadership])
api = Config(descr) cfg = Config(descr)
api.option('str').value.set('') cfg.option('str').value.set('')
api.option('leader.str1').value.set(['str']) cfg.option('leader.str1').value.set(['str'])
assert list(api.value.mandatory()) == ['str'] assert list(cfg.value.mandatory()) == ['str']
api.option('str').value.set('yes') cfg.option('str').value.set('yes')
assert list(api.value.mandatory()) == ['leader.str2'] assert list(cfg.value.mandatory()) == ['leader.str2']
def test_mandatory_warnings_requires_leadership_follower(): def test_mandatory_warnings_requires_leadership_follower():
@ -613,18 +610,18 @@ def test_mandatory_warnings_requires_leadership_follower():
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption1, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}]) stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption1, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
leadership = Leadership('leader', 'leadership', [stroption, stroption1, stroption2]) leadership = Leadership('leader', 'leadership', [stroption, stroption1, stroption2])
descr = OptionDescription('tiram', '', [leadership]) descr = OptionDescription('tiram', '', [leadership])
api = Config(descr) cfg = Config(descr)
api.option('leader.str').value.set(['str']) cfg.option('leader.str').value.set(['str'])
assert list(api.value.mandatory()) == [] assert list(cfg.value.mandatory()) == []
api.option('leader.str1', 0).value.set('yes') cfg.option('leader.str1', 0).value.set('yes')
assert list(api.value.mandatory()) == ['leader.str2'] assert list(cfg.value.mandatory()) == ['leader.str2']
def test_mandatory_od_disabled(): def test_mandatory_od_disabled():
descr = make_description() descr = make_description()
descr = OptionDescription('od', '', [descr]) descr = OptionDescription('od', '', [descr])
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
assert list(api.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3'] assert list(cfg.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
api.option('tiram').property.add('disabled') cfg.option('tiram').property.add('disabled')
assert list(api.value.mandatory()) == [] assert list(cfg.value.mandatory()) == []

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
@ -9,7 +10,6 @@ from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \ StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \
undefined, Params, ParamOption, ParamValue, ParamContext, calc_value undefined, Params, ParamOption, ParamValue, ParamContext, calc_value
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError
from tiramisu.i18n import _ from tiramisu.i18n import _
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -79,8 +79,8 @@ def is_config(config, **kwargs):
def ret_from_config(config): def ret_from_config(config):
api = Config(config) cfg = Config(config)
return api.option('val1').value.get() return cfg.option('val1').value.get()
def return_raise(*arg): def return_raise(*arg):
@ -126,21 +126,24 @@ def test_identical_paths():
raises(ConflictError, "make_description_duplicates()") raises(ConflictError, "make_description_duplicates()")
def test_hidden_if_in(): def test_hidden_if_in2(config_type):
intoption = IntOption('int', 'Test int option', default=0) intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc", stroption = StrOption('str', 'Test string option', default="abc",
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},)) requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
descr = OptionDescription('constraints', '', [stroption, intoption]) descr = OptionDescription('constraints', '', [stroption, intoption])
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
assert not 'hidden' in api.option('str').property.get() cfg = get_config(cfg_ori, config_type)
api.option('int').value.set(1) assert not 'hidden' in cfg.option('str').property.get()
raises(PropertiesOptionError, "api.option('str').value.get()") cfg.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('str').value.set('uvw')") raises(PropertiesOptionError, "cfg.option('str').value.get()")
assert 'hidden' in api.unrestraint.option('str').property.get() raises(PropertiesOptionError, "cfg.option('str').value.set('uvw')")
if config_type == 'tiramisu-api':
cfg.send()
assert 'hidden' in cfg_ori.unrestraint.option('str').property.get()
def test_hidden_if_in_with_group(): def test_hidden_if_in_with_group(config_type):
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref') gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
@ -155,11 +158,14 @@ def test_hidden_if_in_with_group():
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},)) requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
descr = OptionDescription('constraints', '', [gcgroup, booloption, descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption]) objspaceoption, stroption, intoption])
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
assert not 'hidden' in api.option('str').property.get() cfg = get_config(cfg_ori, config_type)
api.option('int').value.set(1) assert not 'hidden' in cfg_ori.option('str').property.get()
raises(PropertiesOptionError, "api.option('gc.name').value.get()") cfg.option('int').value.set(1)
if config_type == 'tiramisu-api':
cfg.send()
raises(PropertiesOptionError, "cfg_ori.option('gc.name').value.get()")
def test_disabled_with_group(): def test_disabled_with_group():
@ -177,11 +183,11 @@ def test_disabled_with_group():
requires=({'option': intoption, 'expected': 1, 'action': 'disabled'},)) requires=({'option': intoption, 'expected': 1, 'action': 'disabled'},))
descr = OptionDescription('constraints', '', [gcgroup, booloption, descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption]) objspaceoption, stroption, intoption])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert api.option('gc.name').value.get() assert cfg.option('gc.name').value.get()
api.option('int').value.set(1) cfg.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('gc.name').value.get()") raises(PropertiesOptionError, "cfg.option('gc.name').value.get()")
#____________________________________________________________ #____________________________________________________________
@ -211,38 +217,40 @@ def make_description_callback():
def test_has_callback(): def test_has_callback():
descr = make_description_callback() descr = make_description_callback()
# here the owner is 'default' # here the owner is 'default'
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.option('bool').value.set(False) cfg.option('bool').value.set(False)
# because dummy has a callback # because dummy has a callback
api.property.add('freeze') cfg.property.add('freeze')
api.option('gc.dummy').property.add('frozen') cfg.option('gc.dummy').property.add('frozen')
raises(PropertiesOptionError, "api.option('gc.dummy').value.set(True)") raises(PropertiesOptionError, "cfg.option('gc.dummy').value.set(True)")
def test_freeze_and_has_callback(): def test_freeze_and_has_callback():
descr = make_description_callback() descr = make_description_callback()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.option('bool').value.set(False) cfg.option('bool').value.set(False)
api.property.add('freeze') cfg.property.add('freeze')
api.option('gc.dummy').property.add('frozen') cfg.option('gc.dummy').property.add('frozen')
raises(PropertiesOptionError, "api.option('gc.dummy').value.set(True)") raises(PropertiesOptionError, "cfg.option('gc.dummy').value.set(True)")
def test_callback(): def test_callback(config_type):
val1 = StrOption('val1', "", callback=return_val) val1 = StrOption('val1', "", callback=return_val)
val2 = StrOption('val2', "") val2 = StrOption('val2', "")
maconfig = OptionDescription('rootconfig', '', [val1, val2]) maconfig = OptionDescription('rootconfig', '', [val1, val2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1').option.callbacks() != (None, None) cfg = get_config(cfg, config_type)
assert api.option('val2').option.callbacks() == (None, None) if config_type != 'tiramisu-api':
assert api.option('val1').value.get() == 'val' assert cfg.option('val1').option.callbacks() != (None, None)
api.option('val1').value.set('new-val') assert cfg.option('val2').option.callbacks() == (None, None)
assert api.option('val1').value.get() == 'new-val' assert cfg.option('val1').value.get() == 'val'
api.option('val1').value.reset() cfg.option('val1').value.set('new-val')
assert api.option('val1').value.get() == 'val' assert cfg.option('val1').value.get() == 'new-val'
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == 'val'
def test_callback_params_without_callback(): def test_callback_params_without_callback():
@ -281,8 +289,8 @@ def test_callback_with_context():
params = Params((context,), {'value': value}) params = Params((context,), {'value': value})
val1 = StrOption("val1", "", callback=is_config, callback_params=params) val1 = StrOption("val1", "", callback=is_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig) cfg = Config(maconfig)
assert api.option('val1').value.get() == 'yes' assert cfg.option('val1').value.get() == 'yes'
def test_callback_with_context_named(): def test_callback_with_context_named():
@ -290,15 +298,16 @@ def test_callback_with_context_named():
params = Params(kwargs={'config': context}) params = Params(kwargs={'config': context})
val1 = StrOption("val1", "", callback=is_config, callback_params=params) val1 = StrOption("val1", "", callback=is_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig) cfg = Config(maconfig)
assert api.option('val1').value.get() == 'yes' assert cfg.option('val1').value.get() == 'yes'
def test_callback_with_error(): def test_callback_with_error(config_type):
val1 = StrOption("val1", "", callback=is_config, callback_params=Params(ParamValue('string'), kwargs={'value': ParamValue('string')})) val1 = StrOption("val1", "", callback=is_config, callback_params=Params(ParamValue('string'), kwargs={'value': ParamValue('string')}))
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig) cfg = Config(maconfig)
assert api.option('val1').value.get() == 'no' cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == 'no'
def test_callback_with_context_value(): def test_callback_with_context_value():
@ -307,66 +316,71 @@ def test_callback_with_context_value():
val1 = StrOption("val1", "") val1 = StrOption("val1", "")
val2 = StrOption("val2", "", callback=ret_from_config, callback_params=params) val2 = StrOption("val2", "", callback=ret_from_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1, val2]) maconfig = OptionDescription('rootconfig', '', [val1, val2])
api = Config(maconfig) cfg = Config(maconfig)
api.option('val1').value.set('yes') cfg.option('val1').value.set('yes')
assert api.option('val1').value.get() == 'yes' assert cfg.option('val1').value.get() == 'yes'
assert api.option('val2').value.get() == 'yes' assert cfg.option('val2').value.get() == 'yes'
api.option('val1').value.set('no') cfg.option('val1').value.set('no')
assert api.option('val1').value.get() == 'no' assert cfg.option('val1').value.get() == 'no'
assert api.option('val2').value.get() == 'no' assert cfg.option('val2').value.get() == 'no'
def test_callback_value(): def test_callback_value(config_type):
val1 = StrOption('val1', "", 'val') val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamValue('yes'))) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamValue('yes')))
val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)})) val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val5 = StrOption('val5', "", callback=return_value, callback_params=Params(ParamValue('yes'))) val5 = StrOption('val5', "", callback=return_value, callback_params=Params(ParamValue('yes')))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1').value.get() == 'val' cfg = get_config(cfg, config_type)
assert api.option('val2').value.get() == 'val' assert cfg.option('val1').value.get() == 'val'
assert api.option('val4').value.get() == 'val' assert cfg.option('val2').value.get() == 'val'
api.option('val1').value.set('new-val') assert cfg.option('val4').value.get() == 'val'
assert api.option('val1').value.get() == 'new-val' cfg.option('val1').value.set('new-val')
assert api.option('val2').value.get() == 'new-val' assert cfg.option('val1').value.get() == 'new-val'
assert api.option('val4').value.get() == 'new-val' assert cfg.option('val2').value.get() == 'new-val'
api.option('val1').value.reset() assert cfg.option('val4').value.get() == 'new-val'
assert api.option('val1').value.get() == 'val' cfg.option('val1').value.reset()
assert api.option('val2').value.get() == 'val' assert cfg.option('val1').value.get() == 'val'
assert api.option('val3').value.get() == 'yes' assert cfg.option('val2').value.get() == 'val'
assert api.option('val4').value.get() == 'val' assert cfg.option('val3').value.get() == 'yes'
assert api.option('val5').value.get() == 'yes' assert cfg.option('val4').value.get() == 'val'
assert cfg.option('val5').value.get() == 'yes'
def test_callback_value_tuple(): def test_callback_value_tuple(config_type):
val1 = StrOption('val1', "", 'val1') val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val2') val2 = StrOption('val2', "", 'val2')
val3 = StrOption('val3', "", callback=return_concat, callback_params=Params((ParamOption(val1), ParamOption(val2)))) val3 = StrOption('val3', "", callback=return_concat, callback_params=Params((ParamOption(val1), ParamOption(val2))))
val4 = StrOption('val4', "", callback=return_concat, callback_params=Params((ParamValue('yes'), ParamValue('no')))) val4 = StrOption('val4', "", callback=return_concat, callback_params=Params((ParamValue('yes'), ParamValue('no'))))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1').value.get() == 'val1' cfg = get_config(cfg, config_type)
assert api.option('val2').value.get() == 'val2' assert cfg.option('val1').value.get() == 'val1'
assert api.option('val3').value.get() == 'val1.val2' assert cfg.option('val2').value.get() == 'val2'
assert api.option('val4').value.get() == 'yes.no' assert cfg.option('val3').value.get() == 'val1.val2'
api.option('val1').value.set('new-val') assert cfg.option('val4').value.get() == 'yes.no'
assert api.option('val3').value.get() == 'new-val.val2' cfg.option('val1').value.set('new-val')
api.option('val1').value.reset() assert cfg.option('val3').value.get() == 'new-val.val2'
assert api.option('val3').value.get() == 'val1.val2' cfg.option('val1').value.reset()
assert cfg.option('val3').value.get() == 'val1.val2'
def test_callback_value_force_permissive(): def test_callback_value_force_permissive2(config_type):
val1 = StrOption('val1', "", 'val', properties=('disabled',)) val1 = StrOption('val1', "", 'val', properties=('disabled',))
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True))) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True)))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_only() cfg.property.read_only()
raises(ConfigError, "api.option('val2').value.get()") if config_type != 'tiramisu-api':
api.option('val3').value.get() is None raises(ConfigError, "cfg.option('val2').value.get()")
cfg.option('val3').value.get() is None
else:
raises(ConfigError, "get_config(cfg, config_type)")
def test_callback_value_force_permissive_kwargs(): def test_callback_value_force_permissive_kwargs():
@ -374,36 +388,37 @@ def test_callback_value_force_permissive_kwargs():
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(value=ParamOption(val1))) val2 = StrOption('val2', "", callback=return_value, callback_params=Params(value=ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(value=ParamOption(val1, True))) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(value=ParamOption(val1, True)))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_only() cfg.property.read_only()
raises(ConfigError, "api.option('val2').value.get()") raises(ConfigError, "cfg.option('val2').value.get()")
api.option('val3').value.get() is None cfg.option('val3').value.get() is None
def test_callback_symlink(): def test_callback_symlink(config_type):
val1 = StrOption('val1', "", 'val') val1 = StrOption('val1', "", 'val')
val2 = SymLinkOption('val2', val1) val2 = SymLinkOption('val2', val1)
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val2))) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val2)))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1').value.get() == 'val' cfg = get_config(cfg, config_type)
assert api.option('val2').value.get() == 'val' assert cfg.option('val1').value.get() == 'val'
assert api.option('val3').value.get() == 'val' assert cfg.option('val2').value.get() == 'val'
api.option('val1').value.set('new-val') assert cfg.option('val3').value.get() == 'val'
assert api.option('val1').value.get() == 'new-val' cfg.option('val1').value.set('new-val')
assert api.option('val3').value.get() == 'new-val' assert cfg.option('val1').value.get() == 'new-val'
api.option('val1').value.reset() assert cfg.option('val3').value.get() == 'new-val'
assert api.option('val1').value.get() == 'val' cfg.option('val1').value.reset()
assert api.option('val3').value.get() == 'val' assert cfg.option('val1').value.get() == 'val'
assert cfg.option('val3').value.get() == 'val'
def test_callback_list(): def test_callback_list():
val1 = StrOption('val1', "", callback=return_list) val1 = StrOption('val1', "", callback=return_list)
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(ValueError, "api.option('val1').value.get()") raises(ValueError, "cfg.option('val1').value.get()")
def test_callback_list2(): def test_callback_list2():
@ -411,28 +426,29 @@ def test_callback_list2():
#val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) #val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) # , 'forcepermissive': False}]}) val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) # , 'forcepermissive': False}]})
maconfig = OptionDescription('rootconfig', '', [val1, val2]) maconfig = OptionDescription('rootconfig', '', [val1, val2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(ValueError, "api.option('val1').value.get()") raises(ValueError, "cfg.option('val1').value.get()")
#cfg.val2 #cfg.val2
raises(ValueError, "api.option('val2').value.get()") raises(ValueError, "cfg.option('val2').value.get()")
def test_callback_multi(): def test_callback_multi(config_type):
val1 = StrOption('val1', "", callback=return_val, multi=True) val1 = StrOption('val1', "", callback=return_val, multi=True)
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1').value.get() == ['val'] cfg = get_config(cfg, config_type)
api.option('val1').value.set(['new-val']) assert cfg.option('val1').value.get() == ['val']
assert api.option('val1').value.get() == ['new-val'] cfg.option('val1').value.set(['new-val'])
api.option('val1').value.set(['new-val', 'new-val2']) assert cfg.option('val1').value.get() == ['new-val']
assert api.option('val1').value.get() == ['new-val', 'new-val2'] cfg.option('val1').value.set(['new-val', 'new-val2'])
api.option('val1').value.reset() assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
assert api.option('val1').value.get() == ['val'] cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == ['val']
def test_callback_multi_value(): def test_callback_multi_value(config_type):
val1 = StrOption('val1', "", ['val'], multi=True) val1 = StrOption('val1', "", ['val'], multi=True)
#val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1))) #val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
#val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamValue('yes'))) #val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamValue('yes')))
@ -446,136 +462,152 @@ def test_callback_multi_value():
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=params2) val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=params2)
val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params=params3) val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params=params3)
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1').value.get() == ['val'] cfg = get_config(cfg, config_type)
assert api.option('val2').value.get() == ['val'] assert cfg.option('val1').value.get() == ['val']
assert api.option('val4').value.get() == ['val', 'yes'] assert cfg.option('val2').value.get() == ['val']
api.option('val1').value.set(['new-val']) assert cfg.option('val4').value.get() == ['val', 'yes']
assert api.option('val1').value.get() == ['new-val'] cfg.option('val1').value.set(['new-val'])
assert api.option('val2').value.get() == ['new-val'] assert cfg.option('val1').value.get() == ['new-val']
assert api.option('val4').value.get() == ['new-val', 'yes'] assert cfg.option('val2').value.get() == ['new-val']
api.option('val1').value.set(['new-val', 'new-val2']) assert cfg.option('val4').value.get() == ['new-val', 'yes']
assert api.option('val1').value.get() == ['new-val', 'new-val2'] cfg.option('val1').value.set(['new-val', 'new-val2'])
assert api.option('val2').value.get() == ['new-val', 'new-val2'] assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
assert api.option('val4').value.get() == ['new-val', 'new-val2', 'yes'] assert cfg.option('val2').value.get() == ['new-val', 'new-val2']
api.option('val1').value.reset() assert cfg.option('val4').value.get() == ['new-val', 'new-val2', 'yes']
assert api.option('val1').value.get() == ['val'] cfg.option('val1').value.reset()
assert api.option('val2').value.get() == ['val'] assert cfg.option('val1').value.get() == ['val']
assert api.option('val3').value.get() == ['yes'] assert cfg.option('val2').value.get() == ['val']
assert api.option('val4').value.get() == ['val', 'yes'] assert cfg.option('val3').value.get() == ['yes']
api.option('val2').value.set(['val', 'new']) assert cfg.option('val4').value.get() == ['val', 'yes']
assert api.option('val1').value.get() == ['val'] cfg.option('val2').value.set(['val', 'new'])
assert api.option('val2').value.get() == ['val', 'new'] assert cfg.option('val1').value.get() == ['val']
assert cfg.option('val2').value.get() == ['val', 'new']
def test_callback_multi_list(): def test_callback_multi_list(config_type):
val1 = StrOption('val1', "", callback=return_list, multi=True) val1 = StrOption('val1', "", callback=return_list, multi=True)
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1').value.get() == ['val', 'val'] cfg = get_config(cfg, config_type)
api.option('val1').value.set(['new-val']) assert cfg.option('val1').value.get() == ['val', 'val']
assert api.option('val1').value.get() == ['new-val'] cfg.option('val1').value.set(['new-val'])
api.option('val1').value.set(['new-val', 'new-val2']) assert cfg.option('val1').value.get() == ['new-val']
assert api.option('val1').value.get() == ['new-val', 'new-val2'] cfg.option('val1').value.set(['new-val', 'new-val2'])
api.option('val1').value.reset() assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
assert api.option('val1').value.get() == ['val', 'val'] cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == ['val', 'val']
def test_callback_multi_list_extend(): def test_callback_multi_list_extend(config_type):
val1 = StrOption('val1', "", callback=return_list2, callback_params=Params((ParamValue(['1', '2', '3']), ParamValue(['4', '5']))), multi=True) val1 = StrOption('val1', "", callback=return_list2, callback_params=Params((ParamValue(['1', '2', '3']), ParamValue(['4', '5']))), multi=True)
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1').value.get() == ['1', '2', '3', '4', '5'] cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == ['1', '2', '3', '4', '5']
def test_callback_multi_callback(): def test_callback_multi_callback(config_type):
val1 = StrOption('val1', "", multi=True, callback=return_val) val1 = StrOption('val1', "", multi=True, callback=return_val)
interface1 = OptionDescription('val1', '', [val1]) interface1 = OptionDescription('val1', '', [val1])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1.val1').value.get() == ['val'] cfg = get_config(cfg, config_type)
api.option('val1.val1').value.set(['val1', undefined]) assert cfg.option('val1.val1').value.get() == ['val']
assert api.option('val1.val1').value.get() == ['val1', 'val'] cfg.option('val1.val1').value.set(['val1', undefined])
assert cfg.option('val1.val1').value.get() == ['val1', 'val']
def test_callback_leader_and_followers_leader(): def test_callback_leader_and_followers_leader(config_type):
val1 = StrOption('val1', "", multi=True, callback=return_val) val1 = StrOption('val1', "", multi=True, callback=return_val)
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1.val1').value.get() == ['val'] cfg = get_config(cfg, config_type)
api.option('val1.val1').value.set([undefined, undefined]) assert cfg.option('val1.val1').value.get() == ['val']
assert api.option('val1.val1').value.get() == ['val', 'val'] cfg.option('val1.val1').value.set([undefined, undefined])
assert api.option('val1.val2', 0).value.get() == None assert cfg.option('val1.val1').value.get() == ['val', 'val']
assert api.option('val1.val2', 1).value.get() == None assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == None
def test_callback_follower(): def test_callback_follower(config_type):
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params=Params(ParamValue(['string', 'new']))) val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params=Params(ParamValue(['string', 'new'])))
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.option('val1.val1').value.set(['val']) cfg = get_config(cfg, config_type)
assert api.option('val1.val2', 0).value.get() == 'string' cfg.option('val1.val1').value.set(['val'])
api.option('val1.val1').value.set(['val', 'val1']) assert cfg.option('val1.val2', 0).value.get() == 'string'
assert api.option('val1.val2', 0).value.get() == 'string' cfg.option('val1.val1').value.set(['val', 'val1'])
assert api.option('val1.val2', 1).value.get() == 'new' assert cfg.option('val1.val2', 0).value.get() == 'string'
api.option('val1.val1').value.set(['val', 'val1', 'val2']) assert cfg.option('val1.val2', 1).value.get() == 'new'
assert api.option('val1.val2', 0).value.get() == 'string' cfg.option('val1.val1').value.set(['val', 'val1', 'val2'])
assert api.option('val1.val2', 1).value.get() == 'new' assert cfg.option('val1.val2', 0).value.get() == 'string'
assert api.option('val1.val2', 2).value.get() == None assert cfg.option('val1.val2', 1).value.get() == 'new'
api.option('val1.val1').value.set(['val', 'val1', 'val2', 'val3']) assert cfg.option('val1.val2', 2).value.get() == None
assert api.option('val1.val2', 0).value.get() == 'string' cfg.option('val1.val1').value.set(['val', 'val1', 'val2', 'val3'])
assert api.option('val1.val2', 1).value.get() == 'new' assert cfg.option('val1.val2', 0).value.get() == 'string'
assert api.option('val1.val2', 2).value.get() == None assert cfg.option('val1.val2', 1).value.get() == 'new'
assert api.option('val1.val2', 3).value.get() == None assert cfg.option('val1.val2', 2).value.get() == None
assert cfg.option('val1.val2', 3).value.get() == None
def test_callback_leader_and_followers_leader2(): def test_callback_leader_and_followers_leader2(config_type):
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, default_multi='val2') val2 = StrOption('val2', "", multi=True, default_multi='val2')
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2))) val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3))) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = Leadership('val1', '', [val1, val2, val3, val4]) interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.option('val1.val1').value.set(['val']) cfg = get_config(cfg, config_type)
assert api.option('val1.val4', 0).value.get() == 'val2' cfg.option('val1.val1').value.set(['val'])
assert api.option('val1.val3', 0).value.get() == 'val2' assert cfg.option('val1.val4', 0).value.get() == 'val2'
assert api.option('val1.val2', 0).value.get() == 'val2' assert cfg.option('val1.val3', 0).value.get() == 'val2'
assert cfg.option('val1.val2', 0).value.get() == 'val2'
def test_callback_leader_and_followers_leader_mandatory(): def test_callback_leader_and_followers_leader_mandatory1(config_type):
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',)) val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',)) val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = Leadership('val1', '', [val1, val3, val4]) interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, interface1]) maconfig = OptionDescription('rootconfig', '', [val, interface1])
api = Config(maconfig) cfg_ori = Config(maconfig)
api.property.read_only() cfg_ori.property.read_only()
assert api.option('val1.val3', 0).value.get() == 'val' cfg = get_config(cfg_ori, config_type)
assert api.option('val1.val4', 0).value.get() == 'val' assert cfg.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val'] assert cfg.option('val1.val4', 0).value.get() == 'val'
api.property.read_write() assert cfg.option('val1.val1').value.get() == ['val']
api.option('val1.val1').value.set([undefined, 'val3']) if config_type == 'tiramisu-api':
api.property.read_only() cfg.send()
assert api.option('val1.val1').value.get() == ['val', 'val3'] cfg_ori.property.read_write()
assert api.option('val1.val3', 0).value.get() == 'val' cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "api.option('val1.val3', 1).value.get()") cfg.option('val1.val1').value.set([undefined, 'val3'])
raises(PropertiesOptionError, "api.option('val1.val4', 1).value.get()") if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val1').value.get() == ['val', 'val3']
assert cfg.option('val1.val3', 0).value.get() == 'val'
if config_type != 'tiramisu-api':
# FIXME
raises(PropertiesOptionError, "cfg.option('val1.val3', 1).value.get()")
raises(PropertiesOptionError, "cfg.option('val1.val4', 1).value.get()")
def test_callback_leader_and_followers_leader_mandatory2(): def test_callback_leader_and_followers_leader_mandatory2(config_type):
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val_ = StrOption('val_', "", default='val_') val_ = StrOption('val_', "", default='val_')
val1 = StrOption('val1', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val), {'val2': ParamOption(val_)}), properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val), {'val2': ParamOption(val_)}), properties=('mandatory',))
@ -583,27 +615,32 @@ def test_callback_leader_and_followers_leader_mandatory2():
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1), {'val2': ParamOption(val_)}), properties=('mandatory',)) val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1), {'val2': ParamOption(val_)}), properties=('mandatory',))
interface1 = Leadership('val1', '', [val1, val3, val4]) interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1]) maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
api = Config(maconfig) cfg_ori = Config(maconfig)
api.property.read_only() cfg_ori.property.read_only()
assert api.option('val1.val3', 0).value.get() == 'val' cfg = get_config(cfg_ori, config_type)
assert api.option('val1.val3', 1).value.get() == 'val_' assert cfg.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val4', 0).value.get() == 'val' assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert api.option('val1.val4', 1).value.get() == 'val_' assert cfg.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val', 'val_'] assert cfg.option('val1.val4', 1).value.get() == 'val_'
api.property.read_write() assert cfg.option('val1.val1').value.get() == ['val', 'val_']
api.option('val1.val1').value.set(['val', 'val_', 'val3']) cfg_ori.property.read_write()
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3'] cfg = get_config(cfg_ori, config_type)
api.property.read_only() cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
assert api.option('val1.val3', 0).value.get() == 'val' assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
assert api.option('val1.val3', 1).value.get() == 'val_' cfg_ori.property.read_only()
assert api.option('val1.val4', 0).value.get() == 'val' cfg = get_config(cfg_ori, config_type)
assert api.option('val1.val4', 1).value.get() == 'val_' assert cfg.option('val1.val3', 0).value.get() == 'val'
raises(PropertiesOptionError, "api.option('val1.val3', 2).value.get()") assert cfg.option('val1.val3', 1).value.get() == 'val_'
raises(PropertiesOptionError, "api.option('val1.val4', 2).value.get()") assert cfg.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3'] assert cfg.option('val1.val4', 1).value.get() == 'val_'
if config_type != 'tiramisu-api':
# FIXME
raises(PropertiesOptionError, "cfg.option('val1.val3', 2).value.get()")
raises(PropertiesOptionError, "cfg.option('val1.val4', 2).value.get()")
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
def test_callback_leader_and_followers_leader_mandatory3(): def test_callback_leader_and_followers_leader_mandatory3(config_type):
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val_ = StrOption('val_', "", default='val_') val_ = StrOption('val_', "", default='val_')
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val), {'val': ParamOption(val_)}), properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val), {'val': ParamOption(val_)}), properties=('mandatory',))
@ -611,46 +648,52 @@ def test_callback_leader_and_followers_leader_mandatory3():
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',)) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = Leadership('val1', '', [val1, val3, val4]) interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1]) maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
api = Config(maconfig) cfg_ori = Config(maconfig)
api.property.read_only() cfg_ori.property.read_only()
assert api.option('val1.val3', 0).value.get() == 'val' cfg = get_config(cfg_ori, config_type)
assert api.option('val1.val3', 1).value.get() == 'val_' assert cfg.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val4', 0).value.get() == 'val' assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert api.option('val1.val4', 1).value.get() == 'val_' assert cfg.option('val1.val4', 0).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val', 'val_'] assert cfg.option('val1.val4', 1).value.get() == 'val_'
api.property.read_write() assert cfg.option('val1.val1').value.get() == ['val', 'val_']
api.option('val1.val1').value.set(['val', 'val_', 'val3']) cfg_ori.property.read_write()
api.property.read_only() cfg = get_config(cfg_ori, config_type)
assert api.option('val1.val3', 0).value.get() == 'val' cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
assert api.option('val1.val3', 1).value.get() == 'val_' cfg_ori.property.read_only()
assert api.option('val1.val3', 2).value.get() == 'val3' cfg = get_config(cfg_ori, config_type)
assert api.option('val1.val4', 0).value.get() == 'val' assert cfg.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val4', 1).value.get() == 'val_' assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert api.option('val1.val4', 2).value.get() == 'val3' assert cfg.option('val1.val3', 2).value.get() == 'val3'
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3'] assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val4', 1).value.get() == 'val_'
assert cfg.option('val1.val4', 2).value.get() == 'val3'
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
def test_callback_leader_and_followers_leader_mandatory4(): def test_callback_leader_and_followers_leader_mandatory4(config_type):
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',)) val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',)) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = Leadership('val1', '', [val1, val3, val4]) interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, interface1]) maconfig = OptionDescription('rootconfig', '', [val, interface1])
api = Config(maconfig) cfg_ori = Config(maconfig)
api.property.read_only() cfg_ori.property.read_only()
#raises(IndexError, "api.option('val1.val3').value.get()") cfg = get_config(cfg_ori, config_type)
assert api.option('val1.val3', 0).value.get() == 'val' #raises(IndexError, "cfg.option('val1.val3').value.get()")
assert api.option('val1.val4', 0).value.get() == 'val' assert cfg.option('val1.val3', 0).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val'] assert cfg.option('val1.val4', 0).value.get() == 'val'
api.property.read_write() assert cfg.option('val1.val1').value.get() == ['val']
api.option('val1.val1').value.set(['val', 'val3']) cfg_ori.property.read_write()
api.property.read_only() cfg = get_config(cfg_ori, config_type)
assert api.option('val1.val1').value.get() == ['val', 'val3'] cfg.option('val1.val1').value.set(['val', 'val3'])
assert api.option('val1.val3', 0).value.get() == 'val' cfg_ori.property.read_only()
assert api.option('val1.val3', 1).value.get() == 'val3' cfg = get_config(cfg_ori, config_type)
assert api.option('val1.val4', 0).value.get() == 'val' assert cfg.option('val1.val1').value.get() == ['val', 'val3']
assert api.option('val1.val4', 1).value.get() == 'val3' assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val3'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val4', 1).value.get() == 'val3'
def test_callback_leader_and_followers_leader3(): def test_callback_leader_and_followers_leader3():
@ -660,9 +703,10 @@ def test_callback_leader_and_followers_leader3():
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3))) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = Leadership('val1', '', [val1, val2, val3, val4]) interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert list(api.value.mandatory()) == ['val1.val1'] # FIXME cfg = get_config(cfg, config_type)
assert list(cfg.value.mandatory()) == ['val1.val1']
def test_callback_leader_and_followers_leader4(): def test_callback_leader_and_followers_leader4():
@ -672,11 +716,12 @@ def test_callback_leader_and_followers_leader4():
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3))) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = Leadership('val1', '', [val1, val2, val3, val4]) interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.property.add('expert') # FIXME cfg = get_config(cfg, config_type)
api.permissive.set(frozenset(['expert'])) cfg.property.add('expert')
assert list(api.value.mandatory()) == [] cfg.permissive.set(frozenset(['expert']))
assert list(cfg.value.mandatory()) == []
def test_consistency_leader_and_followers_leader_mandatory_transitive(): def test_consistency_leader_and_followers_leader_mandatory_transitive():
@ -691,16 +736,17 @@ def test_consistency_leader_and_followers_leader_mandatory_transitive():
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
interface2 = Leadership('val3', '', [val3, val4]) interface2 = Leadership('val3', '', [val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1, interface2]) maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
try: try:
api.option('val1.val1').value.get() cfg.option('val1.val1').value.get()
except PropertiesOptionError as error: except PropertiesOptionError as error:
assert str(error) == str(_('cannot access to {0} "{1}" because "{2}" has {3} {4}').format('option', 'val1', 'val2', _('property'), '"disabled"')) assert str(error) == str(_('cannot access to {0} "{1}" because "{2}" has {3} {4}').format('option', 'val1', 'val2', _('property'), '"disabled"'))
else: else:
raise Exception('must raises') raise Exception('must raises')
raises(PropertiesOptionError, "api.option('val3.val3').value.get()") raises(PropertiesOptionError, "cfg.option('val3.val3').value.get()")
assert list(api.value.mandatory()) == [] assert list(cfg.value.mandatory()) == []
def test_consistency_leader_and_followers_leader_mandatory_non_transitive(): def test_consistency_leader_and_followers_leader_mandatory_non_transitive():
@ -715,88 +761,93 @@ def test_consistency_leader_and_followers_leader_mandatory_non_transitive():
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
interface2 = Leadership('val3', '', [val3, val4]) interface2 = Leadership('val3', '', [val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1, interface2]) maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
if TIRAMISU_VERSION == 2: # FIXME cfg = get_config(cfg, config_type)
assert list(api.value.mandatory()) == ["val1.val1", "val1.val2"] assert list(cfg.value.mandatory()) == ["val1.val1"]
else:
assert list(api.value.mandatory()) == ["val1.val1"]
def test_callback_leader_and_followers_leader_list(): def test_callback_leader_and_followers_leader_list(config_type):
val1 = StrOption('val1', "", multi=True, callback=return_list) val1 = StrOption('val1', "", multi=True, callback=return_list)
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1.val1').value.get() == ['val', 'val'] cfg = get_config(cfg, config_type)
assert api.option('val1.val2', 0).value.get() == None assert cfg.option('val1.val1').value.get() == ['val', 'val']
assert api.option('val1.val2', 1).value.get() == None assert cfg.option('val1.val2', 0).value.get() == None
api.option('val1.val1').value.set(['val', 'val', undefined]) assert cfg.option('val1.val2', 1).value.get() == None
assert api.option('val1.val1').value.get() == ['val', 'val', None] cfg.option('val1.val1').value.set(['val', 'val', undefined])
assert api.option('val1.val2', 0).value.get() == None assert cfg.option('val1.val1').value.get() == ['val', 'val', None]
assert api.option('val1.val2', 1).value.get() == None assert cfg.option('val1.val2', 0).value.get() == None
assert api.option('val1.val2', 1).value.get() == None assert cfg.option('val1.val2', 1).value.get() == None
api.option('val1.val1').value.reset() assert cfg.option('val1.val2', 2).value.get() == None
assert api.option('val1.val1').value.get() == ['val', 'val'] cfg.option('val1.val1').value.reset()
assert api.option('val1.val2', 0).value.get() == None assert cfg.option('val1.val1').value.get() == ['val', 'val']
assert api.option('val1.val2', 1).value.get() == None assert cfg.option('val1.val2', 0).value.get() == None
api.option('val1.val1').value.pop(1) assert cfg.option('val1.val2', 1).value.get() == None
assert api.option('val1.val1').value.get() == ['val'] cfg.option('val1.val1').value.pop(1)
assert api.option('val1.val2', 0).value.get() == None assert cfg.option('val1.val1').value.get() == ['val']
assert cfg.option('val1.val2', 0).value.get() == None
def test_callback_leader_and_followers_leader_follower_list(): def test_callback_leader_and_followers_leader_follower_list(config_type):
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_list) val2 = StrOption('val2', "", multi=True, callback=return_list)
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1.val1').value.get() == [] cfg = get_config(cfg, config_type)
api.option('val1.val1').value.set(['val1']) assert cfg.option('val1.val1').value.get() == []
raises(LeadershipError, "api.option('val1.val2', 0).value.get()") if config_type == 'tiramisu-api':
# when "tiramisu-api", raise when set and not in get function
raises(ConfigError, "cfg.option('val1.val1').value.set(['val1'])")
else:
cfg.option('val1.val1').value.set(['val1'])
raises(LeadershipError, "cfg.option('val1.val2', 0).value.get()")
def test_callback_leader_and_followers_follower(): def test_callback_leader_and_followers_follower(config_type):
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_val) val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1.val1').value.get() == [] cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == []
# #
api.option('val1.val1').value.set(['val1']) cfg.option('val1.val1').value.set(['val1'])
assert api.option('val1.val1').value.get() == ['val1'] assert cfg.option('val1.val1').value.get() == ['val1']
assert api.option('val1.val2', 0).value.get() == 'val' assert cfg.option('val1.val2', 0).value.get() == 'val'
# #
api.option('val1.val1').value.set(['val1', 'val2']) cfg.option('val1.val1').value.set(['val1', 'val2'])
assert api.option('val1.val1').value.get() == ['val1', 'val2'] assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert api.option('val1.val2', 0).value.get() == 'val' assert cfg.option('val1.val2', 0).value.get() == 'val'
assert api.option('val1.val2', 1).value.get() == 'val' assert cfg.option('val1.val2', 1).value.get() == 'val'
# #
api.option('val1.val1').value.set(['val1', 'val2', 'val3']) cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val1').value.get() == ['val1', 'val2', 'val3'] assert cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert api.option('val1.val2', 0).value.get() == 'val' assert cfg.option('val1.val2', 0).value.get() == 'val'
assert api.option('val1.val2', 1).value.get() == 'val' assert cfg.option('val1.val2', 1).value.get() == 'val'
assert api.option('val1.val2', 2).value.get() == 'val' assert cfg.option('val1.val2', 2).value.get() == 'val'
# #
api.option('val1.val1').value.pop(2) cfg.option('val1.val1').value.pop(2)
assert api.option('val1.val1').value.get() == ['val1', 'val2'] assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert api.option('val1.val2', 0).value.get() == 'val' assert cfg.option('val1.val2', 0).value.get() == 'val'
assert api.option('val1.val2', 1).value.get() == 'val' assert cfg.option('val1.val2', 1).value.get() == 'val'
# #
api.option('val1.val2', 0).value.set('val2') cfg.option('val1.val2', 0).value.set('val2')
api.option('val1.val2', 1).value.set('val2') cfg.option('val1.val2', 1).value.set('val2')
assert api.option('val1.val2', 0).value.get() == 'val2' assert cfg.option('val1.val2', 0).value.get() == 'val2'
assert api.option('val1.val2', 1).value.get() == 'val2' assert cfg.option('val1.val2', 1).value.get() == 'val2'
# #
api.option('val1.val1').value.set(['val1', 'val2', 'val3']) cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val2', 0).value.get() == 'val2' assert cfg.option('val1.val2', 0).value.get() == 'val2'
assert api.option('val1.val2', 1).value.get() == 'val2' assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val2', 2).value.get() == 'val' assert cfg.option('val1.val2', 2).value.get() == 'val'
def test_callback_leader_and_followers(): def test_callback_leader_and_followers():
@ -804,45 +855,50 @@ def test_callback_leader_and_followers():
val2 = StrOption('val2', "", multi=True, callback=return_val) val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
def test_callback_leader_and_followers_follower_cal(): def test_callback_leader_and_followers_follower_cal(config_type):
val3 = StrOption('val3', "", multi=True) val3 = StrOption('val3', "", multi=True)
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3))) val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
val2 = StrOption('val2', "", multi=True, callback=return_val) val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val3]) maconfig = OptionDescription('rootconfig', '', [interface1, val3])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
assert api.option('val3').value.get() == [] assert cfg.option('val3').value.get() == []
assert api.option('val1.val1').value.get() == [] assert cfg.option('val1.val1').value.get() == []
# #
api.option('val1.val1').value.set(['val1']) cfg.option('val1.val1').value.set(['val1'])
api.option('val3').value.set(['val1']) cfg.option('val3').value.set(['val1'])
assert api.option('val1.val1').value.get() == ['val1'] assert cfg.option('val1.val1').value.get() == ['val1']
assert api.option('val1.val2', 0).value.get() == 'val' assert cfg.option('val1.val2', 0).value.get() == 'val'
# #
api.option('val1.val1').value.reset() cfg.option('val1.val1').value.reset()
api.option('val1.val2', 0).value.set('val') cfg.option('val1.val2', 0).value.set('val')
# #
api.option('val3').value.set(['val1', 'val2']) cfg.option('val3').value.set(['val1', 'val2'])
assert api.option('val1.val2', 0).value.get() == 'val' assert cfg.option('val1.val2', 0).value.get() == 'val'
assert api.option('val1.val2', 1).value.get() == 'val' assert cfg.option('val1.val2', 1).value.get() == 'val'
assert api.option('val1.val1').value.get() == ['val1', 'val2'] assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
# len of follower is higher than leader's one # len of follower is higher than leader's one
api.option('val1.val2', 0).value.set('val1') cfg.option('val1.val2', 0).value.set('val1')
api.option('val1.val2', 1).value.set('val2') cfg.option('val1.val2', 1).value.set('val2')
api.option('val3').value.set(['val1']) if config_type == 'tiramisu-api':
assert api.option('val1.val1').value.get() == ['val1'] # when "tiramisu-api", raise when set and not in get function
raises(LeadershipError, "api.option('val1.val2', 0).value.get()") raises(ConfigError, "cfg.option('val3').value.set(['val1'])")
else:
cfg.option('val3').value.set(['val1'])
assert cfg.option('val1.val1').value.get() == ['val1']
raises(LeadershipError, "cfg.option('val1.val2', 0).value.get()")
# #
api.option('val3').value.set(['val1', 'val2', 'val3']) cfg.option('val3').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val2', 0).value.get() == 'val1' assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert api.option('val1.val2', 1).value.get() == 'val2' assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val2', 2).value.get() == 'val' assert cfg.option('val1.val2', 2).value.get() == 'val'
def test_callback_leader_and_followers_leader_disabled(): def test_callback_leader_and_followers_leader_disabled():
@ -851,11 +907,11 @@ def test_callback_leader_and_followers_leader_disabled():
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(PropertiesOptionError, "api.option('val1.val1').value.get()") raises(PropertiesOptionError, "cfg.option('val1.val1').value.get()")
raises(PropertiesOptionError, "api.option('val1.val1').value.set(['yes'])") raises(PropertiesOptionError, "cfg.option('val1.val1').value.set(['yes'])")
raises(PropertiesOptionError, "api.option('val1.val2', 0).value.get()") raises(PropertiesOptionError, "cfg.option('val1.val2', 0).value.get()")
def test_callback_leader_and_followers_leader_callback_disabled(): def test_callback_leader_and_followers_leader_callback_disabled():
@ -864,14 +920,14 @@ def test_callback_leader_and_followers_leader_callback_disabled():
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val0]) maconfig = OptionDescription('rootconfig', '', [interface1, val0])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(ConfigError, "api.option('val1.val1').value.get()") raises(ConfigError, "cfg.option('val1.val1').value.get()")
raises(ConfigError, "api.option('val1.val2').value.get()") raises(ConfigError, "cfg.option('val1.val2').value.get()")
api.property.pop('disabled') cfg.property.pop('disabled')
api.option('val1.val1').value.set([]) cfg.option('val1.val1').value.set([])
api.property.add('disabled') cfg.property.add('disabled')
assert api.option('val1.val1').value.get() == [] assert cfg.option('val1.val1').value.get() == []
def test_callback_leader_and_followers_follower_disabled(): def test_callback_leader_and_followers_follower_disabled():
@ -879,26 +935,25 @@ def test_callback_leader_and_followers_follower_disabled():
val2 = StrOption('val2', "", multi=True, properties=('disabled',)) val2 = StrOption('val2', "", multi=True, properties=('disabled',))
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1.val1').value.get() == [] assert cfg.option('val1.val1').value.get() == []
#raises(PropertiesOptionError, "api.option('val1.val2').value.get()") cfg.option('val1.val1').value.set(['yes'])
api.option('val1.val1').value.set(['yes']) assert cfg.option('val1.val1').value.get() == ['yes']
assert api.option('val1.val1').value.get() == ['yes'] cfg.property.pop('disabled')
api.property.pop('disabled') assert cfg.option('val1.val2', 0).value.get() == None
assert api.option('val1.val2', 0).value.get() == None cfg.option('val1.val2', 0).value.set('no')
api.option('val1.val2', 0).value.set('no') cfg.option('val1.val1').value.set(['yes', 'yes2', 'yes3'])
api.option('val1.val1').value.set(['yes', 'yes2', 'yes3']) cfg.option('val1.val2', 2).value.set('no1')
api.option('val1.val2', 2).value.set('no1') assert cfg.option('val1.val2', 0).value.get() == 'no'
assert api.option('val1.val2', 0).value.get() == 'no' assert cfg.option('val1.val2', 1).value.get() == None
assert api.option('val1.val2', 1).value.get() == None assert cfg.option('val1.val2', 2).value.get() == 'no1'
assert api.option('val1.val2', 2).value.get() == 'no1' cfg.property.add('disabled')
api.property.add('disabled') cfg.option('val1.val1').value.pop(0)
api.option('val1.val1').value.pop(0) assert cfg.option('val1.val1').value.get() == ['yes2', 'yes3']
assert api.option('val1.val1').value.get() == ['yes2', 'yes3'] cfg.property.pop('disabled')
api.property.pop('disabled') assert cfg.option('val1.val2', 0).value.get() == None
assert api.option('val1.val2', 0).value.get() == None assert cfg.option('val1.val2', 1).value.get() == 'no1'
assert api.option('val1.val2', 1).value.get() == 'no1'
def test_callback_leader_and_followers_follower_callback_disabled(): def test_callback_leader_and_followers_follower_callback_disabled():
@ -907,17 +962,17 @@ def test_callback_leader_and_followers_follower_callback_disabled():
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0))) val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val0]) maconfig = OptionDescription('rootconfig', '', [interface1, val0])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1.val1').value.get() == [] assert cfg.option('val1.val1').value.get() == []
api.option('val1.val1').value.set(['yes']) cfg.option('val1.val1').value.set(['yes'])
assert api.option('val1.val1').value.get() == ['yes'] assert cfg.option('val1.val1').value.get() == ['yes']
api.property.pop('disabled') cfg.property.pop('disabled')
api.option('val1.val2', 0).value.set('no') cfg.option('val1.val2', 0).value.set('no')
api.option('val1.val1').value.set(['yes', 'yes1']) cfg.option('val1.val1').value.set(['yes', 'yes1'])
assert api.option('val1.val2', 0).value.get() == 'no' assert cfg.option('val1.val2', 0).value.get() == 'no'
api.property.add('disabled') cfg.property.add('disabled')
api.option('val1.val1').value.pop(1) cfg.option('val1.val1').value.pop(1)
def test_callback_leader_and_followers_value(): def test_callback_leader_and_followers_value():
@ -929,10 +984,10 @@ def test_callback_leader_and_followers_value():
val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val5))) val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val5)))
interface1 = Leadership('val1', '', [val1, val2, val3, val5, val6]) interface1 = Leadership('val1', '', [val1, val2, val3, val5, val6])
maconfig = OptionDescription('rootconfig', '', [interface1, val4]) maconfig = OptionDescription('rootconfig', '', [interface1, val4])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.option('val4').value.get() == ['val10', 'val11'] cfg.option('val4').value.get() == ['val10', 'val11']
assert api.option('val1.val1').value.get() == [] assert cfg.option('val1.val1').value.get() == []
#raises(LeadershipError, "cfg.val1.val1") #raises(LeadershipError, "cfg.val1.val1")
#raises(LeadershipError, "cfg.val1.val2") #raises(LeadershipError, "cfg.val1.val2")
#raises(LeadershipError, "cfg.val1.val3") #raises(LeadershipError, "cfg.val1.val3")
@ -940,55 +995,55 @@ def test_callback_leader_and_followers_value():
#raises(LeadershipError, "cfg.val1.val6") #raises(LeadershipError, "cfg.val1.val6")
# #
#default calculation has greater length #default calculation has greater length
#raises(LeadershipError, "api.option('val1.val1').value.set(['val1']") #raises(LeadershipError, "cfg.option('val1.val1').value.set(['val1']")
# #
api.option('val1.val1').value.set(['val1', 'val2']) cfg.option('val1.val1').value.set(['val1', 'val2'])
assert api.option('val1.val1').value.get() == ['val1', 'val2'] assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert api.option('val1.val2', 0).value.get() == 'val1' assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert api.option('val1.val2', 1).value.get() == 'val2' assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val3', 0).value.get() == 'yes' assert cfg.option('val1.val3', 0).value.get() == 'yes'
assert api.option('val1.val3', 1).value.get() == 'yes' assert cfg.option('val1.val3', 1).value.get() == 'yes'
raises(LeadershipError, "api.option('val1.val5', 0).value.get()") raises(LeadershipError, "cfg.option('val1.val5', 0).value.get()")
raises(LeadershipError, "api.option('val1.val5', 1).value.get()") raises(LeadershipError, "cfg.option('val1.val5', 1).value.get()")
raises(LeadershipError, "api.option('val1.val6', 0).value.get()") raises(LeadershipError, "cfg.option('val1.val6', 0).value.get()")
raises(LeadershipError, "api.option('val1.val6', 1).value.get()") raises(LeadershipError, "cfg.option('val1.val6', 1).value.get()")
# #
api.option('val1.val1').value.set(['val1', 'val2', 'val3']) cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val1').value.get() == ['val1', 'val2', 'val3'] assert cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert api.option('val1.val2', 0).value.get() == 'val1' assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert api.option('val1.val2', 1).value.get() == 'val2' assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val2', 2).value.get() == 'val3' assert cfg.option('val1.val2', 2).value.get() == 'val3'
assert api.option('val1.val3', 0).value.get() == 'yes' assert cfg.option('val1.val3', 0).value.get() == 'yes'
assert api.option('val1.val3', 1).value.get() == 'yes' assert cfg.option('val1.val3', 1).value.get() == 'yes'
assert api.option('val1.val3', 2).value.get() == 'yes' assert cfg.option('val1.val3', 2).value.get() == 'yes'
raises(LeadershipError, "api.option('val1.val5', 2).value.get()") raises(LeadershipError, "cfg.option('val1.val5', 2).value.get()")
raises(LeadershipError, "api.option('val1.val6', 2).value.get()") raises(LeadershipError, "cfg.option('val1.val6', 2).value.get()")
# #
api.option('val1.val1').value.pop(2) cfg.option('val1.val1').value.pop(2)
assert api.option('val1.val1').value.get() == ['val1', 'val2'] assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert api.option('val1.val2', 0).value.get() == 'val1' assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert api.option('val1.val2', 1).value.get() == 'val2' assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val3', 0).value.get() == 'yes' assert cfg.option('val1.val3', 0).value.get() == 'yes'
assert api.option('val1.val3', 1).value.get() == 'yes' assert cfg.option('val1.val3', 1).value.get() == 'yes'
# #
api.option('val1.val2', 0).value.set('val2') cfg.option('val1.val2', 0).value.set('val2')
api.option('val1.val2', 1).value.set('val2') cfg.option('val1.val2', 1).value.set('val2')
api.option('val1.val3', 0).value.set('val2') cfg.option('val1.val3', 0).value.set('val2')
api.option('val1.val3', 1).value.set('val2') cfg.option('val1.val3', 1).value.set('val2')
api.option('val1.val5', 0).value.set('val2') cfg.option('val1.val5', 0).value.set('val2')
api.option('val1.val5', 1).value.set('val2') cfg.option('val1.val5', 1).value.set('val2')
assert api.option('val1.val2', 0).value.get() == 'val2' assert cfg.option('val1.val2', 0).value.get() == 'val2'
assert api.option('val1.val2', 1).value.get() == 'val2' assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert api.option('val1.val3', 0).value.get() == 'val2' assert cfg.option('val1.val3', 0).value.get() == 'val2'
assert api.option('val1.val3', 1).value.get() == 'val2' assert cfg.option('val1.val3', 1).value.get() == 'val2'
assert api.option('val1.val5', 0).value.get() == 'val2' assert cfg.option('val1.val5', 0).value.get() == 'val2'
assert api.option('val1.val5', 1).value.get() == 'val2' assert cfg.option('val1.val5', 1).value.get() == 'val2'
assert api.option('val1.val6', 0).value.get() == 'val2' assert cfg.option('val1.val6', 0).value.get() == 'val2'
assert api.option('val1.val6', 1).value.get() == 'val2' assert cfg.option('val1.val6', 1).value.get() == 'val2'
# #
api.option('val1.val1').value.set(['val1', 'val2', 'val3']) cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('val1.val2', 2).value.get() == 'val3' assert cfg.option('val1.val2', 2).value.get() == 'val3'
assert api.option('val1.val3', 2).value.get() == 'yes' assert cfg.option('val1.val3', 2).value.get() == 'yes'
def test_callback_leader(): def test_callback_leader():
@ -997,28 +1052,29 @@ def test_callback_leader():
raises(ValueError, "Leadership('val1', '', [val1, val2])") raises(ValueError, "Leadership('val1', '', [val1, val2])")
def test_callback_different_type(): def test_callback_different_type(config_type):
val = IntOption('val', "", default=2) val = IntOption('val', "", default=2)
val_ = IntOption('val_', "", default=3) val_ = IntOption('val_', "", default=3)
val1 = IntOption('val1', "", multi=True) val1 = IntOption('val1', "", multi=True)
val2 = IntOption('val2', "", multi=True, callback=return_calc, callback_params=Params((ParamOption(val), ParamOption(val1)), {'k': ParamOption(val_)})) val2 = IntOption('val2', "", multi=True, callback=return_calc, callback_params=Params((ParamOption(val), ParamOption(val1)), {'k': ParamOption(val_)}))
interface1 = Leadership('val1', '', [val1, val2]) interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val, val_]) maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val1.val1').value.get() == [] cfg = get_config(cfg, config_type)
api.option('val1.val1').value.set([1]) assert cfg.option('val1.val1').value.get() == []
assert api.option('val1.val1').value.get() == [1] cfg.option('val1.val1').value.set([1])
assert api.option('val1.val2', 0).value.get() == 6 assert cfg.option('val1.val1').value.get() == [1]
api.option('val1.val1').value.set([1, 3]) assert cfg.option('val1.val2', 0).value.get() == 6
assert api.option('val1.val1').value.get() == [1, 3] cfg.option('val1.val1').value.set([1, 3])
assert api.option('val1.val2', 0).value.get() == 6 assert cfg.option('val1.val1').value.get() == [1, 3]
assert api.option('val1.val2', 1).value.get() == 8 assert cfg.option('val1.val2', 0).value.get() == 6
api.option('val1.val1').value.set([1, 3, 5]) assert cfg.option('val1.val2', 1).value.get() == 8
assert api.option('val1.val1').value.get() == [1, 3, 5] cfg.option('val1.val1').value.set([1, 3, 5])
assert api.option('val1.val2', 0).value.get() == 6 assert cfg.option('val1.val1').value.get() == [1, 3, 5]
assert api.option('val1.val2', 1).value.get() == 8 assert cfg.option('val1.val2', 0).value.get() == 6
assert api.option('val1.val2', 2).value.get() == 10 assert cfg.option('val1.val2', 1).value.get() == 8
assert cfg.option('val1.val2', 2).value.get() == 10
def test_callback_hidden(): def test_callback_hidden():
@ -1027,11 +1083,11 @@ def test_callback_hidden():
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',)) od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()") raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
# do not raise, forcepermissive # do not raise, forcepermissive
api.option('od2.opt2').value.get() cfg.option('od2.opt2').value.get()
def test_callback_hidden_permissive(): def test_callback_hidden_permissive():
@ -1040,11 +1096,11 @@ def test_callback_hidden_permissive():
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',)) od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
api.property.read_write() cfg.property.read_write()
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()") raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
api.option('od2.opt2').value.get() cfg.option('od2.opt2').value.get()
def test_callback_hidden_permissive_callback(): def test_callback_hidden_permissive_callback():
@ -1053,10 +1109,10 @@ def test_callback_hidden_permissive_callback():
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',)) od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()") raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
api.option('od2.opt2').value.get() cfg.option('od2.opt2').value.get()
def test_callback_two_disabled(): def test_callback_two_disabled():
@ -1065,9 +1121,9 @@ def test_callback_two_disabled():
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()") raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
def test_callback_two_disabled2(): def test_callback_two_disabled2():
@ -1076,11 +1132,11 @@ def test_callback_two_disabled2():
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()") raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
assert api.forcepermissive.option('od2.opt2').owner.isdefault() assert cfg.forcepermissive.option('od2.opt2').owner.isdefault()
def test_callback_calculating_invalid(): def test_callback_calculating_invalid():
@ -1089,11 +1145,11 @@ def test_callback_calculating_invalid():
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(ValueError, "api.option('od2.opt2').value.get()") raises(ValueError, "cfg.option('od2.opt2').value.get()")
api.unrestraint.option('od2.opt2').property.add('disabled') cfg.unrestraint.option('od2.opt2').property.add('disabled')
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()") raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
def test_callback_calculating_disabled(): def test_callback_calculating_disabled():
@ -1102,9 +1158,9 @@ def test_callback_calculating_disabled():
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(ConfigError, "api.option('od2.opt2').value.get()") raises(ConfigError, "cfg.option('od2.opt2').value.get()")
def test_callback_calculating_mandatory(): def test_callback_calculating_mandatory():
@ -1113,9 +1169,9 @@ def test_callback_calculating_mandatory():
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_only() cfg.property.read_only()
raises(ConfigError, "api.option('od2.opt2').value.get()") raises(ConfigError, "cfg.option('od2.opt2').value.get()")
def test_callback_calculating_mandatory_multi(): def test_callback_calculating_mandatory_multi():
@ -1124,9 +1180,9 @@ def test_callback_calculating_mandatory_multi():
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_only() cfg.property.read_only()
raises(ConfigError, "api.option('od2.opt2').value.get()") raises(ConfigError, "cfg.option('od2.opt2').value.get()")
def test_callback_two_disabled_multi(): def test_callback_two_disabled_multi():
@ -1135,47 +1191,50 @@ def test_callback_two_disabled_multi():
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()") raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
def test_callback_multi_list_params(): def test_callback_multi_list_params(config_type):
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2']) val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(ParamOption(val1))) val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(ParamOption(val1)))
oval2 = OptionDescription('val2', '', [val2]) oval2 = OptionDescription('val2', '', [val2])
maconfig = OptionDescription('rootconfig', '', [val1, oval2]) maconfig = OptionDescription('rootconfig', '', [val1, oval2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val2.val2').value.get() == ['val', 'val'] cfg = get_config(cfg, config_type)
assert cfg.option('val2.val2').value.get() == ['val', 'val']
def test_callback_multi_list_params_key(): def test_callback_multi_list_params_key(config_type):
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2']) val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(kwargs={'value': ParamOption(val1)})) val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(kwargs={'value': ParamOption(val1)}))
oval2 = OptionDescription('val2', '', [val2]) oval2 = OptionDescription('val2', '', [val2])
maconfig = OptionDescription('rootconfig', '', [val1, oval2]) maconfig = OptionDescription('rootconfig', '', [val1, oval2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
assert api.option('val2.val2').value.get() == ['val', 'val'] cfg = get_config(cfg, config_type)
assert cfg.option('val2.val2').value.get() == ['val', 'val']
def test_leadership_callback_description(): def test_leadership_callback_description(config_type):
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(st1))) st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(st1)))
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = OptionDescription('st', '', [stm]) st = OptionDescription('st', '', [stm])
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) cfg = Config(od2)
owner = api.owner.get() cfg = get_config(cfg, config_type)
assert api.option('od.st.st1.st1').value.get() == [] owner = cfg.owner.get()
assert api.option('od.st.st1.st1').owner.isdefault() assert cfg.option('od.st.st1.st1').value.get() == []
assert cfg.option('od.st.st1.st1').owner.isdefault()
## ##
api.option('od.st.st1.st1').value.set(['yes']) cfg.option('od.st.st1.st1').value.set(['yes'])
api.option('od.st.st1.st2', 0).value.set('yes') cfg.option('od.st.st1.st2', 0).value.set('yes')
assert api.option('od.st.st1.st1').owner.get() == owner assert cfg.option('od.st.st1.st1').owner.get() == owner
assert api.option('od.st.st1.st2', 0).owner.get() == owner assert cfg.option('od.st.st1.st2', 0).owner.get() == owner
def test_callback_raise(): def test_callback_raise():
@ -1184,32 +1243,34 @@ def test_callback_raise():
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
api = Config(maconfig) cfg = Config(maconfig)
api.property.read_write() cfg.property.read_write()
try: try:
api.option('od1.opt1').value.get() cfg.option('od1.opt1').value.get()
except ConfigError as err: except ConfigError as err:
assert '"Option 1"' in str(err) assert '"Option 1"' in str(err)
try: try:
api.option('od2.opt2').value.get() cfg.option('od2.opt2').value.get()
except ConfigError as err: except ConfigError as err:
assert '"Option 2"' in str(err) assert '"Option 2"' in str(err)
def test_calc_value_simple(): def test_calc_value_simple(config_type):
val1 = StrOption('val1', '', 'val1') val1 = StrOption('val1', '', 'val1')
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1))) val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1)))
od = OptionDescription('root', '', [val1, val2]) od = OptionDescription('root', '', [val1, val2])
cfg = Config(od) cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'} assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
def test_calc_value_multi(): def test_calc_value_multi(config_type):
val1 = StrOption('val1', "", 'val1') val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val2') val2 = StrOption('val2', "", 'val2')
val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True))) val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True)))
od = OptionDescription('root', '', [val1, val2, val3]) od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od) cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']} assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']}
@ -1224,7 +1285,7 @@ def test_calc_value_disabled():
assert cfg.value.dict() == {'val2': 'default_value'} assert cfg.value.dict() == {'val2': 'default_value'}
def test_calc_value_condition(): def test_calc_value_condition(config_type):
boolean = BoolOption('boolean', '', True) boolean = BoolOption('boolean', '', True)
val1 = StrOption('val1', '', 'val1') val1 = StrOption('val1', '', 'val1')
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1, True), val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1, True),
@ -1234,35 +1295,39 @@ def test_calc_value_condition():
od = OptionDescription('root', '', [boolean, val1, val2]) od = OptionDescription('root', '', [boolean, val1, val2])
cfg = Config(od) cfg = Config(od)
cfg.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'boolean': True, 'val1': 'val1', 'val2': 'val1'} assert cfg.value.dict() == {'boolean': True, 'val1': 'val1', 'val2': 'val1'}
cfg.option('boolean').value.set(False) cfg.option('boolean').value.set(False)
assert cfg.value.dict() == {'boolean': False, 'val1': 'val1', 'val2': 'default_value'} assert cfg.value.dict() == {'boolean': False, 'val1': 'val1', 'val2': 'default_value'}
def test_calc_value_allow_none(): def test_calc_value_allow_none(config_type):
val1 = StrOption('val1', "", 'val1') val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "") val2 = StrOption('val2', "")
val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), allow_none=ParamValue(True))) val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), allow_none=ParamValue(True)))
od = OptionDescription('root', '', [val1, val2, val3]) od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od) cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]} assert cfg.value.dict() == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]}
def test_calc_value_remove_duplicate(): def test_calc_value_remove_duplicate(config_type):
val1 = StrOption('val1', "", 'val1') val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val1') val2 = StrOption('val2', "", 'val1')
val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), remove_duplicate_value=ParamValue(True))) val3 = StrOption('val3', "", multi=True, callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), remove_duplicate_value=ParamValue(True)))
od = OptionDescription('root', '', [val1, val2, val3]) od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od) cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']} assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']}
def test_calc_value_join(): def test_calc_value_join(config_type):
val1 = StrOption('val1', "", 'val1') val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val2') val2 = StrOption('val2', "", 'val2')
val3 = StrOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), join=ParamValue('.'))) val3 = StrOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), join=ParamValue('.')))
od = OptionDescription('root', '', [val1, val2, val3]) od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od) cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val1.val2'} assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val1.val2'}
@ -1279,10 +1344,11 @@ def test_calc_value_min():
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val4': ''} assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val4': ''}
def test_calc_value_add(): def test_calc_value_add(config_type):
val1 = IntOption('val1', "", 1) val1 = IntOption('val1', "", 1)
val2 = IntOption('val2', "", 2) val2 = IntOption('val2', "", 2)
val3 = IntOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), operator=ParamValue('add'))) val3 = IntOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), operator=ParamValue('add')))
od = OptionDescription('root', '', [val1, val2, val3]) od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od) cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 1, 'val2': 2, 'val3': 3} assert cfg.value.dict() == {'val1': 1, 'val2': 2, 'val3': 3}

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
@ -49,42 +50,44 @@ def test_consistency_warnings_only_default():
assert w != [] assert w != []
def test_consistency_warnings_only(): def test_consistency_warnings_only(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '') b = IntOption('b', '')
c = IntOption('c', '') c = IntOption('c', '')
od = OptionDescription('od', '', [a, b, c]) od = OptionDescription('od', '', [a, b, c])
a.impl_add_consistency('not_equal', b, warnings_only=True) a.impl_add_consistency('not_equal', b, warnings_only=True)
api = Config(od) cfg = Config(od)
assert api.option('a').option.consistencies() assert cfg.option('a').option.consistencies()
assert not api.option('b').option.consistencies() assert not cfg.option('b').option.consistencies()
assert not api.option('c').option.consistencies() assert not cfg.option('c').option.consistencies()
api.option('a').value.set(1) cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('b').value.set(1) cfg.option('b').value.set(1)
assert w != [] assert w != []
def test_consistency_warnings_only_more_option(): def test_consistency_warnings_only_more_option(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '') b = IntOption('b', '')
d = IntOption('d', '') d = IntOption('d', '')
od = OptionDescription('od', '', [a, b, d]) od = OptionDescription('od', '', [a, b, d])
a.impl_add_consistency('not_equal', b, d, warnings_only=True) a.impl_add_consistency('not_equal', b, d, warnings_only=True)
api = Config(od) cfg = Config(od)
api.option('a').value.set(1) cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('b').value.set(1) cfg.option('b').value.set(1)
assert w != [] assert w != []
assert len(w) == 1 assert len(w) == 1
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('d').value.get() cfg.option('d').value.get()
assert w != [] assert w != []
assert len(w) == 1 assert len(w) == 1
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('d').value.set(1) cfg.option('d').value.set(1)
assert w != [] assert w != []
assert len(w) == 1 assert len(w) == 1
@ -94,63 +97,71 @@ def test_consistency_error_prefix():
b = IntOption('b', '') b = IntOption('b', '')
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg = Config(od)
api.option('a').value.set(1) cfg.option('a').value.set(1)
try: try:
api.option('b').value.set(1) cfg.option('b').value.set(1)
except Exception as err: except Exception as err:
assert str(err) == _('"{0}" is an invalid {1} for "{2}"').format('1', _('integer'), 'b') + ', ' + _('must be different from the value of {}').format('"a"') assert str(err) == _('"{0}" is an invalid {1} for "{2}"').format('1', _('integer'), 'b') + ', ' + _('must be different from the value of {}').format('"a"')
try: try:
api.option('b').value.set(1) cfg.option('b').value.set(1)
except Exception as err: except Exception as err:
err.prefix = '' err.prefix = ''
assert str(err) == _('must be different from the value of {}').format('"a"') assert str(err) == _('must be different from the value of {}').format('"a"')
def test_consistency_warnings_only_option(): def test_consistency_warnings_only_option(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '', warnings_only=True) b = IntOption('b', '', warnings_only=True)
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg_ori = Config(od)
api.option('a').value.set(1) cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('b').value.set(1) cfg.option('b').value.set(1)
assert w != [] assert w != []
api.option('a').value.reset() cfg.option('a').value.reset()
api.option('b').value.set(1) cfg.option('b').value.set(1)
raises(ValueError, "api.option('a').value.set(1)") raises(ValueError, "cfg.option('a').value.set(1)")
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a').value.set(1) cfg.option('a').value.set(1)
assert len(w) == 1 assert len(w) == 1
def test_consistency_not_equal(): def test_consistency_not_equal(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '') b = IntOption('b', '')
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg_ori = Config(od)
assert api.option('a').value.get() is None cfg = get_config(cfg_ori, config_type)
assert api.option('b').value.get() is None assert cfg.option('a').value.get() is None
api.option('a').value.set(1) assert cfg.option('b').value.get() is None
api.option('a').value.reset() cfg.option('a').value.set(1)
api.option('a').value.set(1) cfg.option('a').value.reset()
raises(ValueError, "api.option('b').value.set(1)") cfg.option('a').value.set(1)
api.option('b').value.set(2) raises(ValueError, "cfg.option('b').value.set(1)")
cfg.option('b').value.set(2)
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('b').value.set(1) cfg.option('b').value.set(1)
assert len(w) == 1 assert len(w) == 1
def test_consistency_not_equal_many_opts(): def test_consistency_not_equal_many_opts(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '') b = IntOption('b', '')
c = IntOption('c', '') c = IntOption('c', '')
@ -159,38 +170,49 @@ def test_consistency_not_equal_many_opts():
f = IntOption('f', '') f = IntOption('f', '')
od = OptionDescription('od', '', [a, b, c, d, e, f]) od = OptionDescription('od', '', [a, b, c, d, e, f])
a.impl_add_consistency('not_equal', b, c, d, e, f) a.impl_add_consistency('not_equal', b, c, d, e, f)
api = Config(od) cfg_ori = Config(od)
assert api.option('a').value.get() is None cfg = get_config(cfg_ori, config_type)
assert api.option('b').value.get() is None assert cfg.option('a').value.get() is None
assert cfg.option('b').value.get() is None
# #
api.option('a').value.set(1) cfg.option('a').value.set(1)
api.option('a').value.reset() cfg.option('a').value.reset()
# #
api.option('a').value.set(1) cfg.option('a').value.set(1)
raises(ValueError, "api.option('b').value.set(1)") raises(ValueError, "cfg.option('b').value.set(1)")
assert cfg.option('b').value.get() == None
# #
api.option('b').value.set(2) cfg.option('b').value.set(2)
raises(ValueError, "api.option('f').value.set(2)") raises(ValueError, "cfg.option('f').value.set(2)")
raises(ValueError, "api.option('f').value.set(1)") assert cfg.option('f').value.get() is None
assert cfg.option('a').value.get() == 1
assert cfg.option('b').value.get() == 2
raises(ValueError, "cfg.option('f').value.set(1)")
assert cfg.option('f').value.get() is None
assert cfg.option('a').value.get() == 1
assert cfg.option('b').value.get() == 2
# #
api.option('d').value.set(3) cfg.option('d').value.set(3)
raises(ValueError, "api.option('f').value.set(3)") raises(ValueError, "cfg.option('f').value.set(3)")
raises(ValueError, "api.option('a').value.set(3)") raises(ValueError, "cfg.option('a').value.set(3)")
api.option('d').value.set(3) cfg.option('d').value.set(3)
raises(ValueError, "api.option('c').value.set(3)") raises(ValueError, "cfg.option('c').value.set(3)")
raises(ValueError, "api.option('e').value.set(3)") raises(ValueError, "cfg.option('e').value.set(3)")
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('c').value.set(3) cfg.option('c').value.set(3)
assert len(w) == 1 assert len(w) == 1
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('e').value.set(3) cfg.option('e').value.set(3)
assert len(w) == 1 assert len(w) == 1
def test_consistency_not_equal_many_opts_one_disabled(): def test_consistency_not_equal_many_opts_one_disabled(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '') b = IntOption('b', '')
c = IntOption('c', '') c = IntOption('c', '')
@ -200,30 +222,36 @@ def test_consistency_not_equal_many_opts_one_disabled():
g = IntOption('g', '', properties=('disabled',)) g = IntOption('g', '', properties=('disabled',))
od = OptionDescription('od', '', [a, b, c, d, e, f, g]) od = OptionDescription('od', '', [a, b, c, d, e, f, g])
a.impl_add_consistency('not_equal', b, c, d, e, f, g, transitive=False) a.impl_add_consistency('not_equal', b, c, d, e, f, g, transitive=False)
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
assert api.option('a').value.get() is None cfg = get_config(cfg_ori, config_type)
assert api.option('b').value.get() is None assert cfg.option('a').value.get() is None
assert cfg.option('b').value.get() is None
# #
api.option('a').value.set(1) cfg.option('a').value.set(1)
api.option('a').value.reset() cfg.option('a').value.reset()
# #
api.option('a').value.set(1) cfg.option('a').value.set(1)
raises(ValueError, "api.option('b').value.set(1)") raises(ValueError, "cfg.option('b').value.set(1)")
# #
api.option('b').value.set(2) cfg.option('b').value.set(2)
raises(ValueError, "api.option('f').value.set(2)") raises(ValueError, "cfg.option('f').value.set(2)")
raises(ValueError, "api.option('f').value.set(1)") raises(ValueError, "cfg.option('f').value.set(1)")
# #
api.option('d').value.set(3) cfg.option('d').value.set(3)
raises(ValueError, "api.option('f').value.set(3)") raises(ValueError, "cfg.option('f').value.set(3)")
raises(ValueError, "api.option('a').value.set(3)") raises(ValueError, "cfg.option('a').value.set(3)")
raises(ValueError, "api.option('c').value.set(3)") raises(ValueError, "cfg.option('c').value.set(3)")
raises(ValueError, "api.option('e').value.set(3)") raises(ValueError, "cfg.option('e').value.set(3)")
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('c').value.set(3) cfg.option('c').value.set(3)
assert len(w) == 1 assert len(w) == 1
@ -275,25 +303,29 @@ def test_consistency_not_equal_symlink():
c = SymLinkOption('c', a) c = SymLinkOption('c', a)
od = OptionDescription('od', '', [a, b, c]) od = OptionDescription('od', '', [a, b, c])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg = Config(od)
assert set(od._cache_consistencies.keys()) == set([a, b]) assert set(od._cache_consistencies.keys()) == set([a, b])
def test_consistency_mix(): def test_consistency_mix(config_type):
b = IntOption('b', '', multi=True) b = IntOption('b', '', multi=True)
c = IntOption('c', '', multi=True) c = IntOption('c', '', multi=True)
d = IntOption('d', '', multi=True) d = IntOption('d', '', multi=True)
od = Leadership('c', '', [c, d]) od = Leadership('c', '', [c, d])
od2 = OptionDescription('a', '', [b, od]) od2 = OptionDescription('a', '', [b, od])
c.impl_add_consistency('not_equal', b, d) c.impl_add_consistency('not_equal', b, d)
cfg = Config(od2) cfg_ori = Config(od2)
cfg = get_config(cfg_ori, config_type)
cfg.option('b').value.set([1, 2, 3]) cfg.option('b').value.set([1, 2, 3])
cfg.option('c.c').value.set([4, 5]) cfg.option('c.c').value.set([4, 5])
raises(ValueError, "cfg.option('c.c').value.set([1, 2])") raises(ValueError, "cfg.option('c.c').value.set([1, 2])")
raises(ValueError, "cfg.option('c.d', 0).value.set(1)") raises(ValueError, "cfg.option('c.d', 0).value.set(1)")
raises(ValueError, "cfg.option('c.d', 1).value.set(4)") raises(ValueError, "cfg.option('c.d', 1).value.set(4)")
# #
cfg.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
cfg.option('c.d', 1).value.set(4) cfg.option('c.d', 1).value.set(4)
assert len(w) == 1 assert len(w) == 1
@ -314,22 +346,23 @@ def test_consistency_not_equal_default_submulti():
raises(ConfigError, "a.impl_add_consistency('not_equal', b)") raises(ConfigError, "a.impl_add_consistency('not_equal', b)")
def test_consistency_not_equal_leadership(): def test_consistency_not_equal_leadership(config_type):
a = IntOption('a', '', multi=True) a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True) b = IntOption('b', '', multi=True)
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od]) od2 = OptionDescription('b', '', [od])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od2) cfg = Config(od2)
assert api.option('a.a').value.get() == [] cfg = get_config(cfg, config_type)
api.option('a.a').value.set([1]) assert cfg.option('a.a').value.get() == []
api.option('a.a').value.reset() cfg.option('a.a').value.set([1])
api.option('a.a').value.set([1]) cfg.option('a.a').value.reset()
raises(ValueError, "api.option('a.b', 0).value.set(1)") cfg.option('a.a').value.set([1])
api.option('a.b', 0).value.set(2) raises(ValueError, "cfg.option('a.b', 0).value.set(1)")
api.option('a.a').value.reset() cfg.option('a.b', 0).value.set(2)
api.option('a.a').value.set([1]) cfg.option('a.a').value.reset()
api.value.dict() cfg.option('a.a').value.set([1])
cfg.value.dict()
def test_consistency_not_equal_leadership_error_multi1(): def test_consistency_not_equal_leadership_error_multi1():
@ -391,39 +424,44 @@ def test_consistency_not_equal_leadership_default():
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
od2 = OptionDescription('a', '', [od]) od2 = OptionDescription('a', '', [od])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od2) cfg = Config(od2)
assert api.option('a.a').value.get() == [] # FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "api.option('a.a').value.set([1])") assert cfg.option('a.a').value.get() == []
api.option('a.a').value.set([2]) raises(ValueError, "cfg.option('a.a').value.set([1])")
api.option('a.a').value.reset() cfg.option('a.a').value.set([2])
cfg.option('a.a').value.reset()
# #
api.property.add('demoting_error_warning') cfg.property.add('demoting_error_warning')
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a.a').value.set([1]) cfg.option('a.a').value.set([1])
assert len(w) == 1 assert len(w) == 1
def test_consistency_not_equal_multi(): def test_consistency_not_equal_multi(config_type):
a = IntOption('a', '', multi=True) a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True) b = IntOption('b', '', multi=True)
od = OptionDescription('a', '', [a, b]) od = OptionDescription('a', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg_ori = Config(od)
assert api.option('a').value.get() == [] cfg = get_config(cfg_ori, config_type)
assert api.option('b').value.get() == [] assert cfg.option('a').value.get() == []
api.option('a').value.set([1]) assert cfg.option('b').value.get() == []
api.option('a').value.reset() cfg.option('a').value.set([1])
api.option('a').value.set([1]) cfg.option('a').value.reset()
raises(ValueError, "api.option('b').value.set([1])") cfg.option('a').value.set([1])
api.option('a').value.set([2]) raises(ValueError, "cfg.option('b').value.set([1])")
raises(ValueError, "api.option('b').value.set([2, 1])") cfg.option('a').value.set([2])
api.option('a').value.set([2, 3]) raises(ValueError, "cfg.option('b').value.set([2, 1])")
raises(ValueError, "api.option('a').value.set([2, 3, 3])") cfg.option('a').value.set([2, 3])
raises(ValueError, "api.option('b').value.set([2, 3])") raises(ValueError, "cfg.option('a').value.set([2, 3, 3])")
raises(ValueError, "cfg.option('b').value.set([2, 3])")
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('b').value.set([2, 3]) cfg.option('b').value.set([2, 3])
assert len(w) == 1 assert len(w) == 1
@ -442,34 +480,39 @@ def test_consistency_not_equal_multi_default2():
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
def test_consistency_not_equal_leader_default(): def test_consistency_not_equal_leader_default(config_type):
a = IntOption('a', '', multi=True, default=[2, 1]) a = IntOption('a', '', multi=True, default=[2, 1])
b = IntOption('b', '', multi=True, default_multi=1) b = IntOption('b', '', multi=True, default_multi=1)
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
od2 = OptionDescription('a', '', [od]) od2 = OptionDescription('a', '', [od])
api = Config(od2) cfg = Config(od2)
cfg = get_config(cfg, config_type)
# default_multi not tested # default_multi not tested
raises(ValueError, "api.option('a.b', 0).value.get()") raises(ValueError, "cfg.option('a.b', 0).value.get()")
api.option('a.b', 0).value.set(3) cfg.option('a.b', 0).value.set(3)
api.option('a.b', 1).value.set(3) cfg.option('a.b', 1).value.set(3)
assert api.option('a.b', 1).value.get() == 3 assert cfg.option('a.b', 1).value.get() == 3
def test_consistency_not_equal_multi_default_modif(): def test_consistency_not_equal_multi_default_modif(config_type):
a = IntOption('a', '', multi=True) a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True, default=[1, 2]) b = IntOption('b', '', multi=True, default=[1, 2])
od = OptionDescription('a', '', [a, b]) od = OptionDescription('a', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg_ori = Config(od)
assert api.option('a').value.get() == [] cfg = get_config(cfg_ori, config_type)
assert api.option('b').value.get() == [1, 2] assert cfg.option('a').value.get() == []
raises(ValueError, "api.option('a').value.set([1])") assert cfg.option('b').value.get() == [1, 2]
raises(ValueError, "api.option('b').value.set([1, 2, 1])") raises(ValueError, "cfg.option('a').value.set([1])")
raises(ValueError, "cfg.option('b').value.set([1, 2, 1])")
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('b').value.set([1, 2, 1]) cfg.option('b').value.set([1, 2, 1])
assert len(w) == 1 assert len(w) == 1
@ -495,42 +538,48 @@ def test_consistency_default_diff():
b = IntOption('b', '', 1) b = IntOption('b', '', 1)
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg = Config(od)
raises(ValueError, "api.option('a').value.set(1)") # FIXME cfg = get_config(cfg, config_type)
api.option('a').value.set(2) raises(ValueError, "cfg.option('a').value.set(1)")
api.option('b').value.set(3) cfg.option('a').value.set(2)
owner = api.owner.get() cfg.option('b').value.set(3)
assert api.option('a').owner.get() == owner owner = cfg.owner.get()
raises(ValueError, "api.option('a').value.reset()") assert cfg.option('a').owner.get() == owner
assert api.option('a').owner.get() == owner raises(ValueError, "cfg.option('a').value.reset()")
assert cfg.option('a').owner.get() == owner
# #
api.property.add('demoting_error_warning') cfg.property.add('demoting_error_warning')
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a').value.reset() cfg.option('a').value.reset()
assert len(w) == 1 assert len(w) == 1
def test_consistency_ip_netmask(): def test_consistency_ip_netmask(config_type):
a = IPOption('a', '') a = IPOption('a', '')
b = NetmaskOption('b', '') b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('ip_netmask', a) b.impl_add_consistency('ip_netmask', a)
api = Config(od) cfg_ori = Config(od)
api.option('a').value.set('192.168.1.1') cfg = cfg_ori
api.option('b').value.set('255.255.255.0') cfg = get_config(cfg_ori, config_type)
api.option('a').value.set('192.168.1.2') cfg.option('a').value.set('192.168.1.1')
api.option('b').value.set('255.255.255.128') cfg.option('b').value.set('255.255.255.0')
api.option('b').value.set('255.255.255.0') cfg.option('a').value.set('192.168.1.2')
raises(ValueError, "api.option('a').value.set('192.168.1.0')") cfg.option('b').value.set('255.255.255.128')
raises(ValueError, "api.option('a').value.set('192.168.1.255')") cfg.option('b').value.set('255.255.255.0')
api.option('a').value.reset() raises(ValueError, "cfg.option('a').value.set('192.168.1.0')")
api.option('b').value.reset() raises(ValueError, "cfg.option('a').value.set('192.168.1.255')")
api.option('a').value.set('192.168.1.255') cfg.option('a').value.reset()
raises(ValueError, "api.option('b').value.set('255.255.255.0')") cfg.option('b').value.reset()
cfg.option('a').value.set('192.168.1.255')
raises(ValueError, "cfg.option('b').value.set('255.255.255.0')")
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('b').value.set('255.255.255.0') cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1 assert len(w) == 1
@ -540,22 +589,26 @@ def test_consistency_ip_netmask_invalid():
raises(ConfigError, "b.impl_add_consistency('ip_netmask')") raises(ConfigError, "b.impl_add_consistency('ip_netmask')")
def test_consistency_network_netmask(): def test_consistency_network_netmask(config_type):
a = NetworkOption('a', '') a = NetworkOption('a', '')
b = NetmaskOption('b', '') b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
api = Config(od) cfg_ori = Config(od)
api.option('a').value.set('192.168.1.1') cfg = get_config(cfg_ori, config_type)
api.option('b').value.set('255.255.255.255') cfg.option('a').value.set('192.168.1.1')
api.option('b').value.reset() cfg.option('b').value.set('255.255.255.255')
api.option('a').value.set('192.168.1.0') cfg.option('b').value.reset()
api.option('b').value.set('255.255.255.0') cfg.option('a').value.set('192.168.1.0')
raises(ValueError, "api.option('a').value.set('192.168.1.1')") cfg.option('b').value.set('255.255.255.0')
raises(ValueError, "cfg.option('a').value.set('192.168.1.1')")
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.1.1') cfg.option('a').value.set('192.168.1.1')
assert len(w) == 1 assert len(w) == 1
@ -565,7 +618,7 @@ def test_consistency_network_netmask_invalid():
raises(ConfigError, "b.impl_add_consistency('network_netmask')") raises(ConfigError, "b.impl_add_consistency('network_netmask')")
def test_consistency_ip_in_network(): def test_consistency_ip_in_network(config_type):
a = NetworkOption('a', '') a = NetworkOption('a', '')
b = NetmaskOption('b', '') b = NetmaskOption('b', '')
c = IPOption('c', '') c = IPOption('c', '')
@ -574,19 +627,20 @@ def test_consistency_ip_in_network():
c.impl_add_consistency('in_network', a, b) c.impl_add_consistency('in_network', a, b)
d.impl_add_consistency('in_network', a, b, warnings_only=True) d.impl_add_consistency('in_network', a, b, warnings_only=True)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
api = Config(od) cfg = Config(od)
api.option('a').value.set('192.168.1.0') cfg = get_config(cfg, config_type)
api.option('b').value.set('255.255.255.0') cfg.option('a').value.set('192.168.1.0')
api.option('c').value.set('192.168.1.1') cfg.option('b').value.set('255.255.255.0')
raises(ValueError, "api.option('c').value.set('192.168.2.1')") cfg.option('c').value.set('192.168.1.1')
raises(ValueError, "api.option('c').value.set('192.168.1.0')") raises(ValueError, "cfg.option('c').value.set('192.168.2.1')")
raises(ValueError, "api.option('c').value.set('192.168.1.255')") raises(ValueError, "cfg.option('c').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('c').value.set('192.168.1.255')")
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('d').value.set('192.168.2.1') cfg.option('d').value.set('192.168.2.1')
assert len(w) == 1 assert len(w) == 1
def test_consistency_ip_in_network_cidr(): def test_consistency_ip_in_network_cidr(config_type):
a = NetworkOption('a', '', cidr=True) a = NetworkOption('a', '', cidr=True)
c = IPOption('c', '') c = IPOption('c', '')
d = IPOption('d', '') d = IPOption('d', '')
@ -594,14 +648,15 @@ def test_consistency_ip_in_network_cidr():
c.impl_add_consistency('in_network', a) c.impl_add_consistency('in_network', a)
d.impl_add_consistency('in_network', a, warnings_only=True) d.impl_add_consistency('in_network', a, warnings_only=True)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
api = Config(od) cfg = Config(od)
api.option('a').value.set('192.168.1.0/24') cfg = get_config(cfg, config_type)
api.option('c').value.set('192.168.1.1') cfg.option('a').value.set('192.168.1.0/24')
raises(ValueError, "api.option('c').value.set('192.168.2.1')") cfg.option('c').value.set('192.168.1.1')
raises(ValueError, "api.option('c').value.set('192.168.1.0')") raises(ValueError, "cfg.option('c').value.set('192.168.2.1')")
raises(ValueError, "api.option('c').value.set('192.168.1.255')") raises(ValueError, "cfg.option('c').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('c').value.set('192.168.1.255')")
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('d').value.set('192.168.2.1') cfg.option('d').value.set('192.168.2.1')
assert len(w) == 1 assert len(w) == 1
@ -621,74 +676,87 @@ def test_consistency_ip_netmask_error_multi():
raises(ConfigError, "b.impl_add_consistency('ip_netmask', a)") raises(ConfigError, "b.impl_add_consistency('ip_netmask', a)")
def test_consistency_ip_netmask_multi(): def test_consistency_ip_netmask_multi(config_type):
a = IPOption('a', '', multi=True) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a) b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg_ori = Config(od2)
api.option('a.a').value.set(['192.168.1.1']) cfg = get_config(cfg_ori, config_type)
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.a').value.set(['192.168.1.1'])
api.option('a.a').value.set(['192.168.1.2']) cfg.option('a.b', 0).value.set('255.255.255.0')
api.option('a.b', 0).value.set('255.255.255.128') cfg.option('a.a').value.set(['192.168.1.2'])
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.b', 0).value.set('255.255.255.128')
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])") cfg.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.0'])")
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a.a').value.set(['192.168.1.0']) cfg.option('a.a').value.set(['192.168.1.0'])
assert len(w) == 1 assert len(w) == 1
def test_consistency_network_netmask_multi(): def test_consistency_network_netmask_multi(config_type):
a = NetworkOption('a', '', multi=True) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) cfg = Config(od2)
api.option('a.a').value.set(['192.168.1.1']) cfg = get_config(cfg, config_type)
api.option('a.b', 0).value.set('255.255.255.255') cfg.option('a.a').value.set(['192.168.1.1'])
api.option('a.b', 0).value.reset() cfg.option('a.b', 0).value.set('255.255.255.255')
api.option('a.a').value.set(['192.168.1.0']) cfg.option('a.b', 0).value.reset()
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.a').value.set(['192.168.1.0'])
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])") cfg.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.1'])")
def test_consistency_network_netmask_multi_follower_default_multi(): def test_consistency_network_netmask_multi_follower_default_multi(config_type):
a = NetworkOption('a', '', default_multi=u'192.168.1.0', multi=True, properties=('mandatory',)) a = NetworkOption('a', '', default_multi=u'192.168.1.0', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',)) b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
api = Config(od2) cfg = Config(od2)
api.property.read_write() cfg.property.read_write()
api.option('a.a').value.set([undefined]) cfg = get_config(cfg, config_type)
assert api.option('a.a').value.get() == ['192.168.1.0'] cfg.option('a.a').value.set([undefined])
assert api.option('a.b', 0).value.get() == '255.255.255.0' assert cfg.option('a.a').value.get() == ['192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
def test_consistency_network_netmask_multi_follower_default(): def test_consistency_network_netmask_multi_follower_default(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',)) a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',)) b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg_ori = Config(od2)
api.property.read_write() cfg_ori.property.read_write()
api.property.pop('cache') cfg_ori.property.pop('cache')
assert api.option('a.a').value.get() == [] cfg = get_config(cfg_ori, config_type)
api.option('a.a').value.set(['192.168.1.0']) assert cfg.option('a.a').value.get() == []
api.property.read_only() cfg.option('a.a').value.set(['192.168.1.0'])
assert api.option('a.a').value.get() == [u'192.168.1.0'] if config_type == 'tiramisu-api':
assert api.option('a.b', 0).value.get() == u'255.255.255.0' cfg.send()
api.property.read_write() cfg_ori.property.read_only()
raises(ValueError, "api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])") cfg = get_config(cfg_ori, config_type)
api.option('a.a').value.set(['192.168.1.0', undefined]) assert cfg.option('a.a').value.get() == [u'192.168.1.0']
api.option('a.b', 0).value.set('255.255.255.0') assert cfg.option('a.b', 0).value.get() == u'255.255.255.0'
api.option('a.b', 1).value.set('255.255.255.255') if config_type == 'tiramisu-api':
api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1']) cfg.send()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
raises(ValueError, "cfg.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
cfg.option('a.a').value.set(['192.168.1.0', undefined])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.b', 1).value.set('255.255.255.255')
cfg.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])
def return_netmask(*args, **kwargs): def return_netmask(*args, **kwargs):
@ -704,86 +772,96 @@ def return_netmask2(leader):
return u'255.255.255.0' return u'255.255.255.0'
def test_consistency_network_netmask_multi_follower_callback(): def test_consistency_network_netmask_multi_follower_callback(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',)) a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask, multi=True, properties=('mandatory',)) b = NetmaskOption('b', '', callback=return_netmask, multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg_ori = Config(od2)
api.property.read_write() cfg_ori.property.read_write()
api.property.pop('cache') cfg_ori.property.pop('cache')
assert api.option('a.a').value.get() == [] cfg = get_config(cfg_ori, config_type)
api.option('a.a').value.set(['192.168.1.0']) assert cfg.option('a.a').value.get() == []
api.property.read_only() cfg.option('a.a').value.set(['192.168.1.0'])
assert api.option('a.a').value.get() == [u'192.168.1.0'] if config_type == 'tiramisu-api':
assert api.option('a.b', 0).value.get() == '255.255.255.0' cfg.send()
api.property.read_write() cfg_ori.property.read_only()
raises(ValueError, "assert api.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])") cfg = get_config(cfg_ori, config_type)
api.option('a.a').value.set(['192.168.1.0', undefined]) assert cfg.option('a.a').value.get() == [u'192.168.1.0']
api.option('a.b', 0).value.set('255.255.255.0') assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
api.option('a.b', 1).value.set('255.255.255.255') if config_type == 'tiramisu-api':
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1']) cfg.send()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
raises(ValueError, "assert cfg.option('a.a').value.set([u'192.168.1.0', u'192.168.1.1'])")
cfg.option('a.a').value.set(['192.168.1.0', undefined])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.b', 1).value.set('255.255.255.255')
cfg.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
def test_consistency_network_netmask_multi_follower_callback_value(): def test_consistency_network_netmask_multi_follower_callback_value(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',)) a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask2, callback_params=Params(ParamOption(a)), multi=True, properties=('mandatory',)) b = NetmaskOption('b', '', callback=return_netmask2, callback_params=Params(ParamOption(a)), multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg = Config(od2)
api.property.read_write() cfg.property.read_write()
api.property.pop('cache') cfg.property.pop('cache')
assert api.option('a.a').value.get() == [] cfg = get_config(cfg, config_type)
api.option('a.a').value.set(['192.168.1.0']) assert cfg.option('a.a').value.get() == []
assert api.option('a.a').value.get() == ['192.168.1.0'] cfg.option('a.a').value.set(['192.168.1.0'])
assert api.option('a.b', 0).value.get() == '255.255.255.0' assert cfg.option('a.a').value.get() == ['192.168.1.0']
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0', '192.168.2.1'])") assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
assert api.option('a.a').value.get() == [u'192.168.1.0'] raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.0', '192.168.2.1'])")
assert api.option('a.b', 0).value.get() == '255.255.255.0' assert cfg.option('a.a').value.get() == [u'192.168.1.0']
raises(ValueError, "api.option('a.a').value.set(['192.168.2.1'])") assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
assert api.option('a.a').value.get() == [u'192.168.1.0'] raises(ValueError, "cfg.option('a.a').value.set(['192.168.2.1'])")
assert api.option('a.b', 0).value.get() == '255.255.255.0' assert cfg.option('a.a').value.get() == [u'192.168.1.0']
api.option('a.a').value.set(['192.168.1.0', '192.168.1.1']) assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
api.option('a.b', 1).value.set('255.255.255.255') cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.b', 1).value.set('255.255.255.255')
def test_consistency_ip_netmask_multi_leader(): def test_consistency_ip_netmask_multi_leader(config_type):
a = IPOption('a', '', multi=True) a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a) b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg = Config(od2)
api.option('a.a').value.set(['192.168.1.1']) cfg = get_config(cfg, config_type)
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.a').value.set(['192.168.1.1'])
api.option('a.a').value.set(['192.168.1.2']) cfg.option('a.b', 0).value.set('255.255.255.0')
api.option('a.b', 0).value.set('255.255.255.128') cfg.option('a.a').value.set(['192.168.1.2'])
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.b', 0).value.set('255.255.255.128')
raises(ValueError, "api.option('a.a').value.set(['192.168.1.0'])") cfg.option('a.b', 0).value.set('255.255.255.0')
api.option('a.a').value.set(['192.168.1.128']) raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.0'])")
raises(ValueError, "api.option('a.b', 0).value.set('255.255.255.128')") cfg.option('a.a').value.set(['192.168.1.128'])
api.option('a.a').value.set(['192.168.1.2', '192.168.1.3']) raises(ValueError, "cfg.option('a.b', 0).value.set('255.255.255.128')")
cfg.option('a.a').value.set(['192.168.1.2', '192.168.1.3'])
def test_consistency_network_netmask_multi_leader(): def test_consistency_network_netmask_multi_leader(config_type):
a = NetworkOption('a', '', multi=True) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg = Config(od2)
api.option('a.a').value.set(['192.168.1.1']) cfg = get_config(cfg, config_type)
api.option('a.b', 0).value.set('255.255.255.255') cfg.option('a.a').value.set(['192.168.1.1'])
api.option('a.b', 0).value.reset() cfg.option('a.b', 0).value.set('255.255.255.255')
api.option('a.a').value.set(['192.168.1.0']) cfg.option('a.b', 0).value.reset()
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.a').value.set(['192.168.1.0'])
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])") cfg.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.1'])")
def test_consistency_broadcast(): def test_consistency_broadcast(config_type):
a = NetworkOption('a', '', multi=True) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True) c = BroadcastOption('c', '', multi=True)
@ -791,26 +869,27 @@ def test_consistency_broadcast():
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a, b) c.impl_add_consistency('broadcast', a, b)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg = Config(od2)
cfg = get_config(cfg, config_type)
#first, test network_netmask #first, test network_netmask
api.option('a.a').value.set(['192.168.1.128']) cfg.option('a.a').value.set(['192.168.1.128'])
raises(ValueError, "api.option('a.a').value.set(['255.255.255.0'])") raises(ValueError, "cfg.option('a.a').value.set(['255.255.255.0'])")
# #
api.option('a.a').value.set(['192.168.1.0']) cfg.option('a.a').value.set(['192.168.1.0'])
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.b', 0).value.set('255.255.255.0')
api.option('a.c', 0).value.set('192.168.1.255') cfg.option('a.c', 0).value.set('192.168.1.255')
raises(ValueError, "api.option('a.a').value.set(['192.168.1.1'])") raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.1'])")
# #
api.option('a.a').value.set(['192.168.1.0', '192.168.2.128']) cfg.option('a.a').value.set(['192.168.1.0', '192.168.2.128'])
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.b', 0).value.set('255.255.255.0')
api.option('a.b', 1).value.set('255.255.255.128') cfg.option('a.b', 1).value.set('255.255.255.128')
api.option('a.c', 0).value.set('192.168.1.255') cfg.option('a.c', 0).value.set('192.168.1.255')
api.option('a.c', 1).value.set('192.168.2.255') cfg.option('a.c', 1).value.set('192.168.2.255')
raises(ValueError, "api.option('a.c', 1).value.set('192.168.2.128')") raises(ValueError, "cfg.option('a.c', 1).value.set('192.168.2.128')")
api.option('a.c', 1).value.set('192.168.2.255') cfg.option('a.c', 1).value.set('192.168.2.255')
def test_consistency_broadcast_error(): def test_consistency_broadcast_error(config_type):
a = NetworkOption('a', '', multi=True) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True) c = BroadcastOption('c', '', multi=True)
@ -818,25 +897,30 @@ def test_consistency_broadcast_error():
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a) c.impl_add_consistency('broadcast', a)
api = Config(od2) cfg = Config(od2)
raises(ConfigError, "api.option('a.a').value.set(['192.168.1.0'])") cfg = get_config(cfg, config_type)
raises(ConfigError, "cfg.option('a.a').value.set(['192.168.1.0'])")
def test_consistency_broadcast_warnings(): def test_consistency_broadcast_warnings(config_type):
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
a = NetworkOption('a', '', properties=('mandatory', 'disabled')) a = NetworkOption('a', '', properties=('mandatory', 'disabled'))
b = NetmaskOption('b', '', properties=('mandatory', 'disabled')) b = NetmaskOption('b', '', properties=('mandatory', 'disabled'))
c = NetmaskOption('c', '', properties=('mandatory', 'disabled')) c = NetmaskOption('c', '', properties=('mandatory', 'disabled'))
od = OptionDescription('a', '', [a, b, c]) od = OptionDescription('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a, warnings_only=True) b.impl_add_consistency('network_netmask', a, warnings_only=True)
api = Config(od) cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.1.4') cfg.option('a').value.set('192.168.1.4')
api.option('b').value.set('255.255.255.0') cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1 assert len(w) == 1
api.property.read_write() if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
list(api.value.mandatory()) list(cfg.value.mandatory())
assert len(w) == 0 assert len(w) == 0
@ -858,7 +942,7 @@ def test_consistency_broadcast_default_2():
d.impl_add_consistency('broadcast', a, b) d.impl_add_consistency('broadcast', a, b)
def test_consistency_not_all(): def test_consistency_not_all(config_type):
#_cache_consistencies is not None by not options has consistencies #_cache_consistencies is not None by not options has consistencies
a = NetworkOption('a', '', multi=True) a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True) b = NetmaskOption('b', '', multi=True)
@ -866,44 +950,48 @@ def test_consistency_not_all():
od = Leadership('a', '', [a, b, c]) od = Leadership('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg = Config(od2)
api.option('a.a').value.set(['192.168.1.0']) cfg = get_config(cfg, config_type)
api.option('a.b', 0).value.set('255.255.255.0') cfg.option('a.a').value.set(['192.168.1.0'])
api.option('a.c', 0).value.set('192.168.1.255') cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.c', 0).value.set('192.168.1.255')
def test_consistency_permissive(): def test_consistency_permissive(config_type):
a = IntOption('a', '', 1) a = IntOption('a', '', 1)
b = IntOption('b', '', 2, properties=('hidden',)) b = IntOption('b', '', 2, properties=('hidden',))
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
api.option('a').value.set(1) cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
def test_consistency_disabled(): def test_consistency_disabled(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '', properties=('disabled',)) b = IntOption('b', '', properties=('disabled',))
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
raises(PropertiesOptionError, "api.option('a').value.set(1)") cfg = get_config(cfg, config_type)
raises(PropertiesOptionError, "cfg.option('a').value.set(1)")
def test_consistency_disabled_transitive(): def test_consistency_disabled_transitive(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '', properties=('disabled',)) b = IntOption('b', '', properties=('disabled',))
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b, transitive=False) a.impl_add_consistency('not_equal', b, transitive=False)
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('a').value.set(1) cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
def test_consistency_disabled_transitive_2(): def test_consistency_disabled_transitive_2(config_type):
a = IPOption('a', '') a = IPOption('a', '')
b = IPOption('b', '') b = IPOption('b', '')
c = NetworkOption('c', '', default='192.168.1.0') c = NetworkOption('c', '', default='192.168.1.0')
@ -911,19 +999,26 @@ def test_consistency_disabled_transitive_2():
od = OptionDescription('od', '', [a, b, c, d]) od = OptionDescription('od', '', [a, b, c, d])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
a.impl_add_consistency('in_network', c, d, transitive=False) a.impl_add_consistency('in_network', c, d, transitive=False)
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
api.option('a').value.set('192.168.1.1') cfg = get_config(cfg_ori, config_type)
raises(ValueError, "api.option('b').value.set('192.168.1.1')") cfg.option('a').value.set('192.168.1.1')
api.option('a').value.set('192.168.2.1') raises(ValueError, "cfg.option('b').value.set('192.168.1.1')")
cfg.option('a').value.set('192.168.2.1')
# #
api.option('a').value.set('192.168.1.1') cfg.option('a').value.set('192.168.1.1')
api.property.pop('disabled') if config_type == 'tiramisu-api':
raises(ValueError, "api.option('a').value.set('192.168.2.1')") cfg.send()
cfg_ori.property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
raises(ValueError, "cfg.option('a').value.set('192.168.2.1')")
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.2.1') cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1 assert len(w) == 1
@ -931,17 +1026,18 @@ def return_val(*args, **kwargs):
return '192.168.1.1' return '192.168.1.1'
def test_consistency_with_callback(): def test_consistency_with_callback(config_type):
a = NetworkOption('a', '', default='192.168.1.0') a = NetworkOption('a', '', default='192.168.1.0')
b = NetmaskOption('b', '', default='255.255.255.0') b = NetmaskOption('b', '', default='255.255.255.0')
c = IPOption('c', '', callback=return_val, callback_params=Params(ParamOption(a))) c = IPOption('c', '', callback=return_val, callback_params=Params(ParamOption(a)))
od = OptionDescription('od', '', [a, b, c]) od = OptionDescription('od', '', [a, b, c])
c.impl_add_consistency('in_network', a, b) c.impl_add_consistency('in_network', a, b)
api = Config(od) cfg = Config(od)
api.option('c').value.get() cfg = get_config(cfg, config_type)
cfg.option('c').value.get()
def test_consistency_warnings_only_options(): def test_consistency_warnings_only_options(config_type):
a = IPOption('a', '', warnings_only=True) a = IPOption('a', '', warnings_only=True)
b = IPOption('b', '') b = IPOption('b', '')
c = NetworkOption('c', '', default='192.168.1.0') c = NetworkOption('c', '', default='192.168.1.0')
@ -949,20 +1045,24 @@ def test_consistency_warnings_only_options():
od = OptionDescription('od', '', [a, b, c, d]) od = OptionDescription('od', '', [a, b, c, d])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
a.impl_add_consistency('in_network', c, d, transitive=False) a.impl_add_consistency('in_network', c, d, transitive=False)
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
api.option('a').value.set('192.168.1.1') cfg = get_config(cfg_ori, config_type)
raises(ValueError, "api.option('b').value.set('192.168.1.1')") cfg.option('a').value.set('192.168.1.1')
api.option('a').value.set('192.168.2.1') raises(ValueError, "cfg.option('b').value.set('192.168.1.1')")
cfg.option('a').value.set('192.168.2.1')
# #
api.option('a').value.set('192.168.1.1') cfg.option('a').value.set('192.168.1.1')
api.property.pop('disabled') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.2.1') cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1 assert len(w) == 1
def test_consistency_warnings_only_options_callback(): def test_consistency_warnings_only_options_callback(config_type):
a = IPOption('a', '', warnings_only=True) a = IPOption('a', '', warnings_only=True)
b = IPOption('b', '') b = IPOption('b', '')
c = NetworkOption('c', '', default='192.168.1.0') c = NetworkOption('c', '', default='192.168.1.0')
@ -970,22 +1070,26 @@ def test_consistency_warnings_only_options_callback():
od = OptionDescription('od', '', [a, b, c, d]) od = OptionDescription('od', '', [a, b, c, d])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
a.impl_add_consistency('in_network', c, d, transitive=False) a.impl_add_consistency('in_network', c, d, transitive=False)
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
api.option('a').value.set('192.168.1.1') cfg = get_config(cfg_ori, config_type)
raises(ValueError, "api.option('b').value.set('192.168.1.1')") cfg.option('a').value.set('192.168.1.1')
raises(ValueError, "cfg.option('b').value.set('192.168.1.1')")
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.2.1') cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1 assert len(w) == 1
# #
api.option('a').value.set('192.168.1.1') cfg.option('a').value.set('192.168.1.1')
api.property.pop('disabled') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('a').value.set('192.168.2.1') cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1 assert len(w) == 1
def test_consistency_double_warnings(): def test_consistency_double_warnings(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '', 1) b = IntOption('b', '', 1)
c = IntOption('c', '', 1) c = IntOption('c', '', 1)
@ -994,25 +1098,34 @@ def test_consistency_double_warnings():
a.impl_add_consistency('not_equal', b, warnings_only=True) a.impl_add_consistency('not_equal', b, warnings_only=True)
a.impl_add_consistency('not_equal', c, warnings_only=True) a.impl_add_consistency('not_equal', c, warnings_only=True)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg_ori = Config(od2)
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('od.a').value.set(1) cfg.option('od.a').value.set(1)
assert w != [] assert w != []
assert len(w) == 2 if config_type == 'tiramisu-api':
# in this case warnings is for '"a" and "b"'
assert len(w) == 1
else:
# in this cas one warnings is for "a" and the second for "b"
assert len(w) == 2
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('od.c').value.set(2) cfg.option('od.c').value.set(2)
assert len(w) == 0 assert len(w) == 0
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('od.a').value.set(2) cfg.option('od.a').value.set(2)
assert w != []
assert len(w) == 1 assert len(w) == 1
api.property.pop('warnings') #
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('warnings')
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('od.a').value.set(1) cfg.option('od.a').value.set(1)
assert w == [] assert w == []
def test_consistency_warnings_error(): def test_consistency_warnings_error(config_type):
a = IntOption('a', '') a = IntOption('a', '')
b = IntOption('b', '', 1) b = IntOption('b', '', 1)
c = IntOption('c', '', 1) c = IntOption('c', '', 1)
@ -1020,22 +1133,24 @@ def test_consistency_warnings_error():
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
a.impl_add_consistency('not_equal', b, warnings_only=True) a.impl_add_consistency('not_equal', b, warnings_only=True)
a.impl_add_consistency('not_equal', c) a.impl_add_consistency('not_equal', c)
api = Config(od) cfg = Config(od)
cfg = get_config(cfg, config_type)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
raises(ValueError, "api.option('a').value.set(1)") raises(ValueError, "cfg.option('a').value.set(1)")
assert w == [] assert w == []
def test_consistency_network_netmask_mandatory(): def test_consistency_network_netmask_mandatory(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',), default=[u'0.0.0.0']) a = NetworkOption('a', '', multi=True, properties=('mandatory',), default=[u'0.0.0.0'])
b = NetmaskOption('b', '', multi=True, properties=('mandatory',), default_multi=u'0.0.0.0') b = NetmaskOption('b', '', multi=True, properties=('mandatory',), default_multi=u'0.0.0.0')
od = Leadership('a', '', [a, b]) od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od]) od2 = OptionDescription('od2', '', [od])
api = Config(od2) cfg = Config(od2)
api.property.read_only() cfg.property.read_only()
api.property.pop('mandatory') cfg.property.pop('mandatory')
api.value.dict() cfg = get_config(cfg, config_type)
cfg.value.dict()
def test_consistency_has_dependency(): def test_consistency_has_dependency():
@ -1043,11 +1158,11 @@ def test_consistency_has_dependency():
b = NetmaskOption('b', '') b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('ip_netmask', a) b.impl_add_consistency('ip_netmask', a)
api = Config(od) cfg = Config(od)
assert api.option('a').option.has_dependency() is True assert cfg.option('a').option.has_dependency() is True
assert api.option('b').option.has_dependency() is True assert cfg.option('b').option.has_dependency() is True
assert api.option('a').option.has_dependency(False) is True assert cfg.option('a').option.has_dependency(False) is True
assert api.option('b').option.has_dependency(False) is True assert cfg.option('b').option.has_dependency(False) is True
def test_consistency_not_equal_has_dependency(): def test_consistency_not_equal_has_dependency():
@ -1055,8 +1170,8 @@ def test_consistency_not_equal_has_dependency():
b = IntOption('b', '') b = IntOption('b', '')
od = OptionDescription('od', '', [a, b]) od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b) a.impl_add_consistency('not_equal', b)
api = Config(od) cfg = Config(od)
assert api.option('a').option.has_dependency() is False assert cfg.option('a').option.has_dependency() is False
assert api.option('b').option.has_dependency() is False assert cfg.option('b').option.has_dependency() is False
assert api.option('a').option.has_dependency(False) is True assert cfg.option('a').option.has_dependency(False) is True
assert api.option('b').option.has_dependency(False) is True assert cfg.option('b').option.has_dependency(False) is True

View File

@ -1,6 +1,7 @@
"test all types of option default values for options, add new option in a descr" "test all types of option default values for options, add new option in a descr"
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
@ -11,6 +12,9 @@ from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
owners.addowner("frozenmultifollower")
def teardown_function(function): def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__) assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
@ -41,7 +45,7 @@ def make_description():
#____________________________________________________________ #____________________________________________________________
# default values # default values
def test_default_is_none(): def test_default_is_none(config_type):
""" """
Most constructors take a ``default`` argument that specifies the default Most constructors take a ``default`` argument that specifies the default
value of the option. If this argument is not supplied the default value is value of the option. If this argument is not supplied the default value is
@ -50,10 +54,11 @@ def test_default_is_none():
dummy1 = BoolOption('dummy1', 'doc dummy') dummy1 = BoolOption('dummy1', 'doc dummy')
dummy2 = BoolOption('dummy2', 'doc dummy') dummy2 = BoolOption('dummy2', 'doc dummy')
group = OptionDescription('group', '', [dummy1, dummy2]) group = OptionDescription('group', '', [dummy1, dummy2])
api = Config(group) cfg = Config(group)
cfg = get_config(cfg, config_type)
# so when the default value is not set, there is actually a default value # so when the default value is not set, there is actually a default value
assert api.option('dummy1').value.get() is None assert cfg.option('dummy1').value.get() is None
assert api.option('dummy2').value.get() is None assert cfg.option('dummy2').value.get() is None
def test_set_defaut_value_from_option_object(): def test_set_defaut_value_from_option_object():
@ -67,49 +72,73 @@ def test_force_default_on_freeze():
dummy1 = BoolOption('dummy1', 'doc dummy', default=False, properties=('force_default_on_freeze',)) dummy1 = BoolOption('dummy1', 'doc dummy', default=False, properties=('force_default_on_freeze',))
dummy2 = BoolOption('dummy2', 'doc dummy', default=True) dummy2 = BoolOption('dummy2', 'doc dummy', default=True)
group = OptionDescription('group', '', [dummy1, dummy2]) group = OptionDescription('group', '', [dummy1, dummy2])
api = Config(group) cfg_ori = Config(group)
api.property.read_write() cfg_ori.property.read_write()
owner = api.owner.get() cfg = cfg_ori
api.option('dummy1').value.set(True) # FIXME cfg = get_config(cfg_ori, config_type)
api.option('dummy2').value.set(False) owner = cfg.owner.get()
assert api.option('dummy1').owner.get() == owner cfg.option('dummy1').value.set(True)
assert api.option('dummy2').owner.get() == owner cfg.option('dummy2').value.set(False)
api.option('dummy1').property.add('frozen') assert cfg.option('dummy1').owner.get() == owner
api.option('dummy2').property.add('frozen') assert cfg.option('dummy2').owner.get() == owner
assert api.option('dummy1').value.get() is False # if config_type == 'tiramisu-api':
assert api.option('dummy2').value.get() is False # cfg.send()
assert api.option('dummy1').owner.isdefault() cfg_ori.option('dummy1').property.add('frozen')
assert api.option('dummy2').owner.get() == owner cfg_ori.option('dummy2').property.add('frozen')
raises(PropertiesOptionError, "api.option('dummy2').owner.set('frozen')") # cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "api.option('dummy1').value.reset()") assert cfg.option('dummy1').value.get() is False
api.option('dummy1').property.pop('frozen') assert cfg.option('dummy2').value.get() is False
api.option('dummy1').value.reset() assert cfg.option('dummy1').owner.isdefault()
api.option('dummy1').property.add('frozen') assert cfg.option('dummy2').owner.get() == owner
raises(PropertiesOptionError, "api.option('dummy2').owner.set('frozen')") # if config_type == 'tiramisu-api':
# cfg.send()
raises(PropertiesOptionError, "cfg_ori.option('dummy2').owner.set('frozen')")
# cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('dummy1').value.reset()")
# if config_type == 'tiramisu-api':
# cfg.send()
cfg_ori.option('dummy1').property.pop('frozen')
# cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1').value.reset()
# if config_type == 'tiramisu-api':
# cfg.send()
cfg.option('dummy1').property.add('frozen')
# cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('dummy2').owner.set('frozen')")
def test_force_default_on_freeze_multi(): def test_force_default_on_freeze_multi():
dummy1 = BoolOption('dummy1', 'doc dummy', default=[False], properties=('force_default_on_freeze',), multi=True) dummy1 = BoolOption('dummy1', 'doc dummy', default=[False], properties=('force_default_on_freeze',), multi=True)
dummy2 = BoolOption('dummy2', 'doc dummy', default=[True], multi=True) dummy2 = BoolOption('dummy2', 'doc dummy', default=[True], multi=True)
group = OptionDescription('group', '', [dummy1, dummy2]) group = OptionDescription('group', '', [dummy1, dummy2])
api = Config(group) cfg_ori = Config(group)
api.property.read_write() cfg_ori.property.read_write()
api.option('dummy1').value.set([undefined, True]) cfg = cfg_ori
api.option('dummy2').value.set([undefined, False]) # FIXME cfg = get_config(cfg_ori, config_type)
owner = api.owner.get() cfg.option('dummy1').value.set([undefined, True])
assert api.option('dummy1').owner.get() == owner cfg.option('dummy2').value.set([undefined, False])
assert api.option('dummy2').owner.get() == owner owner = cfg.owner.get()
api.option('dummy1').property.add('frozen') assert cfg.option('dummy1').owner.get() == owner
api.option('dummy2').property.add('frozen') assert cfg.option('dummy2').owner.get() == owner
assert api.option('dummy1').value.get() == [False] # if config_type == 'tiramisu-api':
assert api.option('dummy2').value.get() == [True, False] # cfg.send()
assert api.option('dummy1').owner.isdefault() cfg_ori.option('dummy1').property.add('frozen')
assert api.option('dummy2').owner.get() == owner cfg_ori.option('dummy2').property.add('frozen')
raises(PropertiesOptionError, "api.option('dummy2').owner.set('owner')") # cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "api.option('dummy2').value.reset()") assert cfg.option('dummy1').value.get() == [False]
api.option('dummy1').property.pop('frozen') assert cfg.option('dummy2').value.get() == [True, False]
api.option('dummy1').value.reset() assert cfg.option('dummy1').owner.isdefault()
api.option('dummy1').property.add('frozen') assert cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# cfg.send()
raises(PropertiesOptionError, "cfg_ori.option('dummy2').owner.set('owner')")
# cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('dummy2').value.reset()")
# if config_type == 'tiramisu-api':
# cfg.send()
cfg_ori.option('dummy1').property.pop('frozen')
# cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1').value.reset()
def test_force_default_on_freeze_leader(): def test_force_default_on_freeze_leader():
@ -133,8 +162,8 @@ def test_force_default_on_freeze_leader_frozen():
dummy2 = BoolOption('dummy2', 'Test string option', multi=True) dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = Leadership("dummy1", "", [dummy1, dummy2]) descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr]) descr = OptionDescription("root", "", [descr])
api = Config(descr) cfg = Config(descr)
raises(ConfigError, "api.option('dummy1.dummy1').property.pop('frozen')") raises(ConfigError, "cfg.option('dummy1.dummy1').property.pop('frozen')")
def test_force_metaconfig_on_freeze_leader_frozen(): def test_force_metaconfig_on_freeze_leader_frozen():
@ -142,75 +171,93 @@ def test_force_metaconfig_on_freeze_leader_frozen():
dummy2 = BoolOption('dummy2', 'Test string option', multi=True) dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = Leadership("dummy1", "", [dummy1, dummy2]) descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr]) descr = OptionDescription("root", "", [descr])
api = Config(descr) cfg = Config(descr)
raises(ConfigError, "api.option('dummy1.dummy1').property.pop('frozen')") raises(ConfigError, "cfg.option('dummy1.dummy1').property.pop('frozen')")
def test_force_default_on_freeze_follower(): def test_force_default_on_freeze_follower(config_type):
dummy1 = BoolOption('dummy1', 'Test int option', multi=True) dummy1 = BoolOption('dummy1', 'Test int option', multi=True)
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',)) dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',))
descr = Leadership("dummy1", "", [dummy1, dummy2]) descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr]) descr = OptionDescription("root", "", [descr])
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
owners.addowner("frozenmultifollower2") cfg = get_config(cfg_ori, config_type)
api.option('dummy1.dummy1').value.set([True]) cfg.option('dummy1.dummy1').value.set([True])
api.option('dummy1.dummy2', 0).value.set(False) cfg.option('dummy1.dummy2', 0).value.set(False)
assert api.option('dummy1.dummy1').value.get() == [True] assert cfg.option('dummy1.dummy1').value.get() == [True]
assert api.option('dummy1.dummy2', 0).value.get() == False assert cfg.option('dummy1.dummy2', 0).value.get() == False
assert api.option('dummy1.dummy1').owner.get() == 'user' assert cfg.option('dummy1.dummy1').owner.get() == 'user'
assert api.option('dummy1.dummy2', 0).owner.get() == 'user' assert cfg.option('dummy1.dummy2', 0).owner.get() == 'user'
# #
api.option('dummy1.dummy2').property.add('frozen') if config_type == 'tiramisu-api':
assert api.option('dummy1.dummy1').value.get() == [True] cfg.send()
assert api.option('dummy1.dummy2', 0).value.get() == None cfg_ori.option('dummy1.dummy2').property.add('frozen')
assert api.option('dummy1.dummy1').owner.get() == 'user' cfg = get_config(cfg_ori, config_type)
assert api.option('dummy1.dummy2', 0).owner.isdefault() assert cfg.option('dummy1.dummy1').value.get() == [True]
raises(PropertiesOptionError, "api.option('dummy1.dummy2', 0).owner.set('frozenmultifollower2')") assert cfg.option('dummy1.dummy2', 0).value.get() == None
assert cfg.option('dummy1.dummy1').owner.get() == 'user'
assert cfg.option('dummy1.dummy2', 0).owner.isdefault()
if config_type == 'tiramisu-api':
cfg.send()
raises(PropertiesOptionError, "cfg_ori.option('dummy1.dummy2', 0).owner.set('frozenmultifollower')")
cfg = get_config(cfg_ori, config_type)
# #
api.option('dummy1.dummy2').property.pop('frozen') if config_type == 'tiramisu-api':
api.option('dummy1.dummy1').value.set([True, True]) cfg.send()
api.option('dummy1.dummy2', 1).value.set(False) cfg_ori.option('dummy1.dummy2').property.pop('frozen')
assert api.option('dummy1.dummy1').value.get() == [True, True] cfg = get_config(cfg_ori, config_type)
assert api.option('dummy1.dummy2', 0).value.get() == False cfg.option('dummy1.dummy1').value.set([True, True])
assert api.option('dummy1.dummy2', 1).value.get() == False cfg.option('dummy1.dummy2', 1).value.set(False)
assert cfg.option('dummy1.dummy1').value.get() == [True, True]
assert cfg.option('dummy1.dummy2', 0).value.get() == False
assert cfg.option('dummy1.dummy2', 1).value.get() == False
# #
api.option('dummy1.dummy2').property.add('frozen') if config_type == 'tiramisu-api':
assert api.option('dummy1.dummy1').value.get() == [True, True] cfg.send()
assert api.option('dummy1.dummy2', 0).value.get() == None cfg_ori.option('dummy1.dummy2').property.add('frozen')
assert api.option('dummy1.dummy2', 1).value.get() == None cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1.dummy1').value.get() == [True, True]
assert cfg.option('dummy1.dummy2', 0).value.get() == None
assert cfg.option('dummy1.dummy2', 1).value.get() == None
# #
api.option('dummy1.dummy1').value.pop(1) cfg.option('dummy1.dummy1').value.pop(1)
assert api.option('dummy1.dummy1').value.get() == [True] assert cfg.option('dummy1.dummy1').value.get() == [True]
assert api.option('dummy1.dummy2', 0).value.get() == None assert cfg.option('dummy1.dummy2', 0).value.get() == None
# #
api.option('dummy1.dummy2').property.pop('frozen') if config_type == 'tiramisu-api':
assert api.option('dummy1.dummy1').value.get() == [True] cfg.send()
assert api.option('dummy1.dummy2', 0).value.get() == False cfg_ori.option('dummy1.dummy2').property.pop('frozen')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1.dummy1').value.get() == [True]
assert cfg.option('dummy1.dummy2', 0).value.get() == False
# #
api.option('dummy1.dummy1').value.set([True, True]) cfg.option('dummy1.dummy1').value.set([True, True])
assert api.option('dummy1.dummy2', 0).value.get() == False assert cfg.option('dummy1.dummy2', 0).value.get() == False
assert api.option('dummy1.dummy2', 1).value.get() == None assert cfg.option('dummy1.dummy2', 1).value.get() == None
def test_overrides_changes_option_value(): def test_overrides_changes_option_value(config_type):
"with config.override(), the default is changed and the value is changed" "with config.override(), the default is changed and the value is changed"
descr = OptionDescription("test", "", [ descr = OptionDescription("test", "", [
BoolOption("b", "", default=False)]) BoolOption("b", "", default=False)])
api = Config(descr) cfg = Config(descr)
api.option('b').value.set(True) cfg = get_config(cfg, config_type)
cfg.option('b').value.set(True)
def test_choice_with_no_default(): def test_choice_with_no_default(config_type):
descr = OptionDescription("test", "", [ descr = OptionDescription("test", "", [
ChoiceOption("backend", "", ("c", "cli"))]) ChoiceOption("backend", "", ("c", "cli"))])
api = Config(descr) cfg = Config(descr)
assert api.option('backend').value.get() is None cfg = get_config(cfg, config_type)
api.option('backend').value.set('c') assert cfg.option('backend').value.get() is None
cfg.option('backend').value.set('c')
def test_choice_with_default(): def test_choice_with_default(config_type):
descr = OptionDescription("test", "", [ descr = OptionDescription("test", "", [
ChoiceOption("backend", "", ("c", "cli"), default="cli")]) ChoiceOption("backend", "", ("c", "cli"), default="cli")])
api = Config(descr) cfg = Config(descr)
assert api.option('backend').value.get() == 'cli' cfg = get_config(cfg, config_type)
assert cfg.option('backend').value.get() == 'cli'

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
@ -10,6 +11,10 @@ from tiramisu.error import ConfigError, ConstError, PropertiesOptionError, APIEr
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
owners.addowner("readonly2")
owners.addowner("new2")
def teardown_function(function): def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__) assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
@ -36,41 +41,46 @@ def make_description():
return descr return descr
def test_default_owner(): def test_default_owner(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr) cfg = Config(descr)
assert api.option('dummy').value.get() is False cfg = get_config(cfg, config_type)
assert api.option('dummy').owner.get() == 'default' assert cfg.option('dummy').value.get() is False
api.option('dummy').value.set(True) assert cfg.option('dummy').owner.get() == 'default'
owner = api.owner.get() cfg.option('dummy').value.set(True)
assert api.option('dummy').owner.get() == owner owner = cfg.owner.get()
assert cfg.option('dummy').owner.get() == owner
def test_hidden_owner(): def test_hidden_owner():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('hidden',)) gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('hidden',))
descr = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.get()") #raises(PropertiesOptionError, "cfg.forcepermissive.option('dummy').owner.get()")
#raises(PropertiesOptionError, "api.option('dummy').owner.isdefault()") #raises(PropertiesOptionError, "cfg.option('dummy').owner.isdefault()")
#raises(PropertiesOptionError, "api.forcepermissive.option('dummy').owner.isdefault()") #raises(PropertiesOptionError, "cfg.forcepermissive.option('dummy').owner.isdefault()")
api.permissive.set(frozenset(['hidden'])) cfg.permissive.set(frozenset(['hidden']))
api.forcepermissive.option('dummy').value.get() cfg.forcepermissive.option('dummy').value.get()
api.forcepermissive.option('dummy').owner.isdefault() cfg.forcepermissive.option('dummy').owner.isdefault()
def test_addowner(): def test_addowner(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr) cfg_ori = Config(descr)
assert api.option('dummy').value.get() is False cfg = get_config(cfg_ori, config_type)
assert api.option('dummy').owner.get() == 'default' assert cfg.option('dummy').value.get() is False
assert api.option('dummy').owner.isdefault() assert cfg.option('dummy').owner.get() == 'default'
api.owner.set('gen_config') assert cfg.option('dummy').owner.isdefault()
api.option('dummy').value.set(True) if config_type == 'tiramisu-api':
assert api.option('dummy').owner.get() == owners.gen_config cfg.send()
assert not api.option('dummy').owner.isdefault() cfg_ori.owner.set('gen_config')
cfg = get_config(cfg_ori, config_type)
cfg.option('dummy').value.set(True)
assert cfg.option('dummy').owner.get() == owners.gen_config
assert not cfg.option('dummy').owner.isdefault()
def test_addowner_multiple_time(): def test_addowner_multiple_time():
@ -83,102 +93,129 @@ def test_delete_owner():
raises(ConstError, 'del(owners.deleted2)') raises(ConstError, 'del(owners.deleted2)')
def test_owner_is_not_a_string(): def test_owner_is_not_a_string(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr) cfg = Config(descr)
assert api.option('dummy').value.get() is False cfg = get_config(cfg, config_type)
assert api.option('dummy').owner.get() == owners.default assert cfg.option('dummy').value.get() is False
assert api.option('dummy').owner.get() == 'default' assert cfg.option('dummy').owner.get() == owners.default
assert isinstance(api.option('dummy').owner.get(), owners.Owner) assert cfg.option('dummy').owner.get() == 'default'
api.option('dummy').value.set(True) if config_type == 'tiramisu':
assert api.option('dummy').owner.get() == 'user' assert isinstance(cfg.option('dummy').owner.get(), owners.Owner)
cfg.option('dummy').value.set(True)
assert cfg.option('dummy').owner.get() == 'user'
def test_setowner_without_valid_owner(): def test_setowner_without_valid_owner(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr) cfg = Config(descr)
assert api.option('dummy').value.get() is False cfg = get_config(cfg, config_type)
assert api.option('dummy').owner.get() == 'default' assert cfg.option('dummy').value.get() is False
assert cfg.option('dummy').owner.get() == 'default'
def test_setowner_for_value(): def test_setowner_for_value(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr) cfg_ori = Config(descr)
assert api.option('dummy').value.get() is False cfg = get_config(cfg_ori, config_type)
assert api.option('dummy').owner.get() == 'default' assert cfg.option('dummy').value.get() is False
owners.addowner("new2") assert cfg.option('dummy').owner.get() == 'default'
raises(ConfigError, "api.option('dummy').owner.set('new2')") if config_type == 'tiramisu-api':
api.option('dummy').value.set(False) cfg.send()
assert api.option('dummy').owner.get() == owners.user raises(ConfigError, "cfg_ori.option('dummy').owner.set('new2')")
api.option('dummy').owner.set('new2') cfg = get_config(cfg_ori, config_type)
assert api.option('dummy').owner.get() == owners.new2 cfg.option('dummy').value.set(False)
assert cfg.option('dummy').owner.get() == owners.user
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('dummy').owner.set('new2')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy').owner.get() == owners.new2
def test_setowner_forbidden(): def test_setowner_forbidden(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr) cfg_ori = Config(descr)
assert api.option('dummy').value.get() is False cfg = get_config(cfg_ori, config_type)
assert api.option('dummy').owner.get() == 'default' assert cfg.option('dummy').value.get() is False
raises(ValueError, "api.owner.set('default')") assert cfg.option('dummy').owner.get() == 'default'
api.option('dummy').value.set(False) if config_type == 'tiramisu-api':
raises(ValueError, "api.option('dummy').owner.set('default')") cfg.send()
raises(ValueError, "cfg_ori.owner.set('default')")
cfg = get_config(cfg_ori, config_type)
cfg.option('dummy').value.set(False)
if config_type == 'tiramisu-api':
cfg.send()
raises(ValueError, "cfg_ori.option('dummy').owner.set('default')")
cfg = get_config(cfg_ori, config_type)
def test_setowner_read_only(): def test_setowner_read_only(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy]) descr = OptionDescription('tiramisu', '', [gcdummy])
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
assert api.option('dummy').value.get() is False cfg = get_config(cfg_ori, config_type)
assert api.option('dummy').owner.get() == 'default' assert cfg.option('dummy').value.get() is False
owners.addowner("readonly2") assert cfg.option('dummy').owner.get() == 'default'
api.option('dummy').value.set(False) cfg.option('dummy').value.set(False)
assert api.option('dummy').owner.get() == owners.user assert cfg.option('dummy').owner.get() == owners.user
api.property.read_only() if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_only()
raises(PropertiesOptionError, raises(PropertiesOptionError,
"api.option('dummy').owner.set('readonly2')") "cfg_ori.option('dummy').owner.set('readonly2')")
assert api.option('dummy').owner.get() == owners.user cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy').owner.get() == owners.user
def test_setowner_optiondescription(): def test_setowner_optiondescription(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
descr1 = OptionDescription('tiramisu', '', [gcdummy]) descr1 = OptionDescription('tiramisu', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [descr1]) descr = OptionDescription('tiramisu', '', [descr1])
api = Config(descr) cfg = Config(descr)
raises(APIError, "api.option('tiramisu').owner.get()") cfg = get_config(cfg, config_type)
raises(APIError, "api.option('tiramisu').owner.set('user')") raises(APIError, "cfg.option('tiramisu').owner.get()")
raises(APIError, "cfg.option('tiramisu').owner.set('user')")
def test_setowner_symlinkoption(): def test_setowner_symlinkoption(config_type):
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
s = SymLinkOption('symdummy', gcdummy) s = SymLinkOption('symdummy', gcdummy)
descr1 = OptionDescription('tiramisu', '', [gcdummy, s]) descr1 = OptionDescription('tiramisu', '', [gcdummy, s])
descr = OptionDescription('tiramisu', '', [descr1]) descr = OptionDescription('tiramisu', '', [descr1])
api = Config(descr) cfg_ori = Config(descr)
assert api.option('tiramisu.symdummy').owner.isdefault() cfg = get_config(cfg_ori, config_type)
api.option('tiramisu.dummy').value.set(True) assert cfg.option('tiramisu.symdummy').owner.isdefault()
assert not api.option('tiramisu.symdummy').owner.isdefault() cfg.option('tiramisu.dummy').value.set(True)
raises(ConfigError, "api.option('tiramisu.symdummy').owner.set('user')") assert not cfg.option('tiramisu.symdummy').owner.isdefault()
if config_type == 'tiramisu-api':
cfg.send()
raises(ConfigError, "cfg_ori.option('tiramisu.symdummy').owner.set('user')")
def test_owner_leadership(): def test_owner_leadership(config_type):
b = IntOption('int', 'Test int option', default=[0], multi=True) b = IntOption('int', 'Test int option', default=[0], multi=True)
c = StrOption('str', 'Test string option', multi=True) c = StrOption('str', 'Test string option', multi=True)
descr = Leadership("int", "", [b, c]) descr = Leadership("int", "", [b, c])
od = OptionDescription('od', '', [descr]) od = OptionDescription('od', '', [descr])
api = Config(od) cfg_ori = Config(od)
raises(ConfigError, "api.option('int.str', 0).owner.set('user')") raises(ConfigError, "cfg_ori.option('int.str', 0).owner.set('user')")
cfg = get_config(cfg_ori, config_type)
api.option('int.int').value.set([0, 1]) cfg.option('int.int').value.set([0, 1])
api.option('int.str', 0).value.set('yes') cfg.option('int.str', 0).value.set('yes')
assert not api.option('int.str', 0).owner.isdefault() assert not cfg.option('int.str', 0).owner.isdefault()
assert api.option('int.str', 1).owner.isdefault() assert cfg.option('int.str', 1).owner.isdefault()
api.option('int.str', 0).owner.set('user') if config_type == 'tiramisu-api':
assert api.option('int.str', 0).owner.get() == owners.user cfg.send()
assert api.option('int.str', 1).owner.isdefault() cfg_ori.option('int.str', 0).owner.set('user')
assert api.option('int.str', 0).value.get() == 'yes' cfg = get_config(cfg_ori, config_type)
assert api.option('int.str', 1).value.get() == None assert cfg.option('int.str', 0).owner.get() == owners.user
assert cfg.option('int.str', 1).owner.isdefault()
assert cfg.option('int.str', 0).value.get() == 'yes'
assert cfg.option('int.str', 1).value.get() == None

View File

@ -1,6 +1,7 @@
"config.set() or config.setoption() or option.setoption()" "config.set() or config.setoption() or option.setoption()"
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
@ -40,14 +41,15 @@ def make_description():
#____________________________________________________________ #____________________________________________________________
# change with __setattr__ # change with __setattr__
def test_attribute_access(): def test_attribute_access(config_type):
"Once set, option values can't be changed again by attribute access" "Once set, option values can't be changed again by attribute access"
s = StrOption("string", "", default="string") s = StrOption("string", "", default="string")
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
cfg = get_config(cfg, config_type)
# let's try to change it again # let's try to change it again
api.option('string').value.set('foo') cfg.option('string').value.set('foo')
assert api.option('string').value.get() == 'foo' assert cfg.option('string').value.get() == 'foo'
def test_mod_read_only_write(): def test_mod_read_only_write():
@ -76,14 +78,13 @@ def test_mod_read_only_write():
'mandatory', 'mandatory',
'empty'} 'empty'}
# #
config.property.setdefault({'cache'}) config.property.setdefault(frozenset(['cache']))
config.property.setdefault(type='read_only', when='append', properties={'disabled'}) config.property.setdefault(type='read_only', when='append', properties=frozenset(['disabled']))
config.property.setdefault(type='read_only', when='remove', properties={'hidden'}) config.property.setdefault(type='read_only', when='remove', properties=frozenset(['hidden']))
config.property.setdefault(type='read_write', when='append', properties={'disabled', config.property.setdefault(type='read_write', when='append', properties=frozenset(['disabled', 'hidden']))
'hidden'}) config.property.setdefault(type='read_write', when='remove', properties=frozenset([]))
config.property.setdefault(type='read_write', when='remove', properties=set([])) raises(ValueError, "config.property.setdefault(type='unknown', when='append', properties=frozenset(['disabled']))")
raises(ValueError, "config.property.setdefault(type='unknown', when='append', properties={'disabled'})") raises(ValueError, "config.property.setdefault(type='read_only', when='unknown', properties=frozenset(['disabled']))")
raises(ValueError, "config.property.setdefault(type='read_only', when='unknown', properties={'disabled'})")
raises(TypeError, "config.property.setdefault(type='read_only', when='append', properties=['disabled'])") raises(TypeError, "config.property.setdefault(type='read_only', when='append', properties=['disabled'])")
assert config.property.getdefault() == {'cache'} assert config.property.getdefault() == {'cache'}
@ -123,42 +124,45 @@ def test_mod_read_only_write():
raises(ValueError, "config2.property.getdefault('read_write', 'unknown')") raises(ValueError, "config2.property.getdefault('read_write', 'unknown')")
def test_setitem(): def test_setitem(config_type):
s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True) s = StrOption("string", "", default=["string", "sdfsdf"], default_multi="prout", multi=True)
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
api.option('string').value.set([undefined, 'foo']) cfg = get_config(cfg, config_type)
assert api.option('string').value.get() == ['string', 'foo'] cfg.option('string').value.set([undefined, 'foo'])
assert cfg.option('string').value.get() == ['string', 'foo']
def test_reset(): def test_reset(config_type):
"if value is None, resets to default owner" "if value is None, resets to default owner"
s = StrOption("string", "", default="string") s = StrOption("string", "", default="string")
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
api.option('string').value.set('foo') cfg = get_config(cfg, config_type)
assert api.option('string').value.get() == "foo" cfg.option('string').value.set('foo')
assert api.option('string').owner.get() ==owners.user assert cfg.option('string').value.get() == "foo"
api.option('string').value.reset() assert cfg.option('string').owner.get() ==owners.user
assert api.option('string').value.get() == 'string' cfg.option('string').value.reset()
assert api.option('string').owner.get() ==owners.default assert cfg.option('string').value.get() == 'string'
assert cfg.option('string').owner.get() ==owners.default
def test_reset_with_multi(): def test_reset_with_multi(config_type):
s = StrOption("string", "", default=["string"], default_multi="string", multi=True) s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
# api.option('string').value.set([]) cfg = get_config(cfg, config_type)
api.option('string').value.reset() # cfg.option('string').value.set([])
assert api.option('string').value.get() == ["string"] cfg.option('string').value.reset()
assert api.option('string').owner.get() =='default' assert cfg.option('string').value.get() == ["string"]
api.option('string').value.set(["eggs", "spam", "foo"]) assert cfg.option('string').owner.get() =='default'
assert api.option('string').owner.get() =='user' cfg.option('string').value.set(["eggs", "spam", "foo"])
api.option('string').value.set([]) assert cfg.option('string').owner.get() =='user'
api.option('string').value.reset() cfg.option('string').value.set([])
# assert api.option('string').value.get() == ["string"] cfg.option('string').value.reset()
assert api.option('string').owner.get() =='default' # assert cfg.option('string').value.get() == ["string"]
raises(ValueError, "api.option('string').value.set(None)") assert cfg.option('string').owner.get() =='default'
raises(ValueError, "cfg.option('string').value.set(None)")
def test_property_only_raises(): def test_property_only_raises():
@ -167,58 +171,61 @@ def test_property_only_raises():
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("options", "", [s, intoption, stroption]) descr = OptionDescription("options", "", [s, intoption, stroption])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert api.option('str').property.get() == {'empty'} assert cfg.option('str').property.get() == {'empty'}
assert api.option('str').property.get(only_raises=True) == set() assert cfg.option('str').property.get(only_raises=True) == set()
def test_default_with_multi(): def test_default_with_multi():
"default with multi is a list" "default with multi is a list"
s = StrOption("string", "", default=[], default_multi="string", multi=True) s = StrOption("string", "", default=[], default_multi="string", multi=True)
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
assert api.option('string').value.get() == [] assert cfg.option('string').value.get() == []
s = StrOption("string", "", default=None, default_multi="string", multi=True) s = StrOption("string", "", default=None, default_multi="string", multi=True)
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
assert api.option('string').value.get() == [] assert cfg.option('string').value.get() == []
def test_idontexist(): def test_idontexist():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.value.dict() cfg.value.dict()
raises(AttributeError, "api.option('idontexist').value.get()") raises(AttributeError, "cfg.option('idontexist').value.get()")
# ____________________________________________________________ # ____________________________________________________________
def test_attribute_access_with_multi(): def test_attribute_access_with_multi(config_type):
s = StrOption("string", "", default=["string"], default_multi="string", multi=True) s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
api.option('string').value.set(["foo", "bar"]) cfg = get_config(cfg, config_type)
assert api.option('string').value.get() == ["foo", "bar"] cfg.option('string').value.set(["foo", "bar"])
assert cfg.option('string').value.get() == ["foo", "bar"]
def test_item_access_with_multi(): def test_item_access_with_multi(config_type):
s = StrOption("string", "", default=["string"], multi=True) s = StrOption("string", "", default=["string"], multi=True)
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
api.option('string').value.set(["foo", "bar"]) cfg = get_config(cfg, config_type)
assert api.option('string').value.get() == ["foo", "bar"] cfg.option('string').value.set(["foo", "bar"])
api.option('string').value.set(["changetest", "bar"]) assert cfg.option('string').value.get() == ["foo", "bar"]
assert api.option('string').value.get() == ["changetest", "bar"] cfg.option('string').value.set(["changetest", "bar"])
assert cfg.option('string').value.get() == ["changetest", "bar"]
def test_access_with_multi_default(): def test_access_with_multi_default(config_type):
s = StrOption("string", "", default=["string"], multi=True) s = StrOption("string", "", default=["string"], multi=True)
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
assert api.option('string').owner.get() =='default' cfg = get_config(cfg, config_type)
api.option('string').value.set(["foo", "bar"]) assert cfg.option('string').owner.get() =='default'
assert api.option('string').value.get() == ["foo", "bar"] cfg.option('string').value.set(["foo", "bar"])
assert api.option('string').owner.get() =='user' assert cfg.option('string').value.get() == ["foo", "bar"]
assert cfg.option('string').owner.get() =='user'
def test_multi_with_requires(): def test_multi_with_requires():
@ -227,12 +234,12 @@ def test_multi_with_requires():
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("options", "", [s, intoption, stroption]) descr = OptionDescription("options", "", [s, intoption, stroption])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert not 'hidden' in api.option('str').property.get() assert not 'hidden' in cfg.option('str').property.get()
api.option('int').value.set(1) cfg.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('str').value.set(['a', 'b'])") raises(PropertiesOptionError, "cfg.option('str').value.set(['a', 'b'])")
assert 'hidden' in api.forcepermissive.option('str').property.get() assert 'hidden' in cfg.forcepermissive.option('str').property.get()
def test__requires_with_inverted(): def test__requires_with_inverted():
@ -241,10 +248,10 @@ def test__requires_with_inverted():
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc", stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
requires=[{'option': intoption, 'expected': 1, 'action': 'hide', 'inverse': True}], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'hide', 'inverse': True}], multi=True)
descr = OptionDescription("options", "", [s, intoption, stroption]) descr = OptionDescription("options", "", [s, intoption, stroption])
api = Config(descr) cfg = Config(descr)
assert not 'hidden' in api.option('str').property.get() assert not 'hidden' in cfg.option('str').property.get()
api.option('int').value.set(1) cfg.option('int').value.set(1)
assert not 'hidden' in api.option('str').property.get() assert not 'hidden' in cfg.option('str').property.get()
def test_multi_with_requires_in_another_group(): def test_multi_with_requires_in_another_group():
@ -254,12 +261,12 @@ def test_multi_with_requires_in_another_group():
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("opt", "", [stroption]) descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr]) descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2) cfg = Config(descr2)
api.property.read_write() cfg.property.read_write()
assert not 'hidden' in api.option('opt.str').property.get() assert not 'hidden' in cfg.option('opt.str').property.get()
api.option('int').value.set(1) cfg.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])") raises(PropertiesOptionError, "cfg.option('opt.str').value.set(['a', 'b'])")
assert 'hidden' in api.forcepermissive.option('opt.str').property.get() assert 'hidden' in cfg.forcepermissive.option('opt.str').property.get()
def test_multi_with_requires_in_another_group_inverse(): def test_multi_with_requires_in_another_group_inverse():
@ -269,12 +276,12 @@ def test_multi_with_requires_in_another_group_inverse():
requires=[{'option': intoption, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True) requires=[{'option': intoption, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True)
descr = OptionDescription("opt", "", [stroption]) descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr]) descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2) cfg = Config(descr2)
api.property.read_write() cfg.property.read_write()
assert not 'hidden' in api.option('opt.str').property.get() assert not 'hidden' in cfg.option('opt.str').property.get()
api.option('int').value.set(1) cfg.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])") raises(PropertiesOptionError, "cfg.option('opt.str').value.set(['a', 'b'])")
assert 'hidden' in api.forcepermissive.option('opt.str').property.get() assert 'hidden' in cfg.forcepermissive.option('opt.str').property.get()
def test_apply_requires_from_config(): def test_apply_requires_from_config():
@ -284,14 +291,14 @@ def test_apply_requires_from_config():
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
descr = OptionDescription("opt", "", [stroption]) descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr]) descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2) cfg = Config(descr2)
api.property.read_write() cfg.property.read_write()
assert not 'hidden' in api.option('opt.str').property.get() assert not 'hidden' in cfg.option('opt.str').property.get()
api.option('int').value.set(1) cfg.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.get()") raises(PropertiesOptionError, "cfg.option('opt.str').value.get()")
assert 'hidden' in api.forcepermissive.option('opt.str').property.get() assert 'hidden' in cfg.forcepermissive.option('opt.str').property.get()
assert 'hidden' not in api.forcepermissive.option('opt.str').option.properties() assert 'hidden' not in cfg.forcepermissive.option('opt.str').option.properties()
assert 'hidden' not in api.forcepermissive.option('opt.str').option.properties(only_raises=True) assert 'hidden' not in cfg.forcepermissive.option('opt.str').option.properties(only_raises=True)
def test_apply_requires_with_disabled(): def test_apply_requires_with_disabled():
@ -301,14 +308,14 @@ def test_apply_requires_with_disabled():
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
descr = OptionDescription("opt", "", [stroption]) descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr]) descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2) cfg = Config(descr2)
api.property.read_write() cfg.property.read_write()
assert not 'disabled' in api.option('opt.str').property.get() assert not 'disabled' in cfg.option('opt.str').property.get()
api.option('int').value.set(1) cfg.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.get()") raises(PropertiesOptionError, "cfg.option('opt.str').value.get()")
assert 'disabled' not in api.unrestraint.option('opt.str').option.properties() assert 'disabled' not in cfg.unrestraint.option('opt.str').option.properties()
assert 'disabled' not in api.unrestraint.option('opt.str').option.properties(only_raises=True) assert 'disabled' not in cfg.unrestraint.option('opt.str').option.properties(only_raises=True)
assert 'disabled' in api.unrestraint.option('opt.str').property.get() assert 'disabled' in cfg.unrestraint.option('opt.str').property.get()
def test_multi_with_requires_with_disabled_in_another_group(): def test_multi_with_requires_with_disabled_in_another_group():
@ -318,12 +325,12 @@ def test_multi_with_requires_with_disabled_in_another_group():
requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True) requires=[{'option': intoption, 'expected': 1, 'action': 'disabled'}], multi=True)
descr = OptionDescription("opt", "", [stroption]) descr = OptionDescription("opt", "", [stroption])
descr2 = OptionDescription("opt2", "", [intoption, s, descr]) descr2 = OptionDescription("opt2", "", [intoption, s, descr])
api = Config(descr2) cfg = Config(descr2)
api.property.read_write() cfg.property.read_write()
assert not 'disabled' in api.option('opt.str').property.get() assert not 'disabled' in cfg.option('opt.str').property.get()
api.option('int').value.set(1) cfg.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.set(['a', 'b'])") raises(PropertiesOptionError, "cfg.option('opt.str').value.set(['a', 'b'])")
assert 'disabled' in api.unrestraint.option('opt.str').property.get() assert 'disabled' in cfg.unrestraint.option('opt.str').property.get()
def test_multi_with_requires_that_is_multi(): def test_multi_with_requires_that_is_multi():
@ -362,24 +369,24 @@ def test_multi_with_requires_that_is_leadership_follower():
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True) d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': '1', 'action': 'hidden'}], multi=True)
descr = Leadership("int", "", [b, c, d]) descr = Leadership("int", "", [b, c, d])
descr2 = OptionDescription('od', '', [descr]) descr2 = OptionDescription('od', '', [descr])
api = Config(descr2) cfg = Config(descr2)
api.property.read_write() cfg.property.read_write()
assert api.option('int.int').value.get() == [0] assert cfg.option('int.int').value.get() == [0]
assert api.option('int.str', 0).value.get() == None assert cfg.option('int.str', 0).value.get() == None
assert api.option('int.str1', 0).value.get() == None assert cfg.option('int.str1', 0).value.get() == None
api.option('int.int').value.set([0, 1]) cfg.option('int.int').value.set([0, 1])
assert api.option('int.int').value.get() == [0, 1] assert cfg.option('int.int').value.get() == [0, 1]
assert api.option('int.str', 0).value.get() == None assert cfg.option('int.str', 0).value.get() == None
assert api.option('int.str', 1).value.get() == None assert cfg.option('int.str', 1).value.get() == None
assert api.option('int.str1', 0).value.get() == None assert cfg.option('int.str1', 0).value.get() == None
assert api.option('int.str1', 1).value.get() == None assert cfg.option('int.str1', 1).value.get() == None
api.option('int.str', 1).value.set('1') cfg.option('int.str', 1).value.set('1')
api.property.read_only() cfg.property.read_only()
assert api.option('int.str1', 0).value.get() == None assert cfg.option('int.str1', 0).value.get() == None
assert api.option('int.str1', 1).value.get() == None assert cfg.option('int.str1', 1).value.get() == None
api.property.read_write() cfg.property.read_write()
assert api.option('int.str1', 0).value.get() == None assert cfg.option('int.str1', 0).value.get() == None
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()") raises(PropertiesOptionError, "cfg.option('int.str1', 1).value.get()")
def test_multi_with_requires_that_is_leadership_follower_inverse(): def test_multi_with_requires_that_is_leadership_follower_inverse():
@ -388,24 +395,24 @@ def test_multi_with_requires_that_is_leadership_follower_inverse():
d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True) d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True)
descr = Leadership("int", "", [b, c, d]) descr = Leadership("int", "", [b, c, d])
descr2 = OptionDescription('od', '', [descr]) descr2 = OptionDescription('od', '', [descr])
api = Config(descr2) cfg = Config(descr2)
api.property.read_write() cfg.property.read_write()
assert api.option('int.int').value.get() == [0] assert cfg.option('int.int').value.get() == [0]
assert api.option('int.str', 0).value.get() is None assert cfg.option('int.str', 0).value.get() is None
assert api.option('int.str1', 0).value.get() is None assert cfg.option('int.str1', 0).value.get() is None
api.option('int.int').value.set([0, 1]) cfg.option('int.int').value.set([0, 1])
assert api.option('int.int').value.get() == [0, 1] assert cfg.option('int.int').value.get() == [0, 1]
assert api.option('int.str', 0).value.get() is None assert cfg.option('int.str', 0).value.get() is None
assert api.option('int.str', 1).value.get() is None assert cfg.option('int.str', 1).value.get() is None
assert api.option('int.str1', 0).value.get() is None assert cfg.option('int.str1', 0).value.get() is None
assert api.option('int.str1', 1).value.get() is None assert cfg.option('int.str1', 1).value.get() is None
api.option('int.str', 1).value.set('1') cfg.option('int.str', 1).value.set('1')
api.property.read_only() cfg.property.read_only()
assert api.option('int.str1', 0).value.get() is None assert cfg.option('int.str1', 0).value.get() is None
assert api.option('int.str1', 1).value.get() is None assert cfg.option('int.str1', 1).value.get() is None
api.property.read_write() cfg.property.read_write()
assert api.option('int.str1', 0).value.get() is None assert cfg.option('int.str1', 0).value.get() is None
raises(PropertiesOptionError, "api.option('int.str1', 1).value.get()") raises(PropertiesOptionError, "cfg.option('int.str1', 1).value.get()")
def test_multi_with_requires_that_is_not_same_leadership(): def test_multi_with_requires_that_is_not_same_leadership():
@ -423,32 +430,32 @@ def test_multi_with_requires_that_is_not_same_leadership():
def test_multi_with_bool(): def test_multi_with_bool():
s = BoolOption("bool", "", default=[False], multi=True) s = BoolOption("bool", "", default=[False], multi=True)
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
api.option('bool').value.set([True, False]) cfg.option('bool').value.set([True, False])
assert api.option('bool').value.get() == [True, False] assert cfg.option('bool').value.get() == [True, False]
def test_choice_access_with_multi(): def test_choice_access_with_multi():
ch = ChoiceOption("t1", "", ("a", "b"), default=["a"], multi=True) ch = ChoiceOption("t1", "", ("a", "b"), default=["a"], multi=True)
descr = OptionDescription("options", "", [ch]) descr = OptionDescription("options", "", [ch])
api = Config(descr) cfg = Config(descr)
api.option('t1').value.set(["a", "b", "a", "b"]) cfg.option('t1').value.set(["a", "b", "a", "b"])
assert api.option('t1').value.get() == ["a", "b", "a", "b"] assert cfg.option('t1').value.get() == ["a", "b", "a", "b"]
#____________________________________________________________ #____________________________________________________________
def test_accepts_multiple_changes_from_option(): def test_accepts_multiple_changes_from_option():
s = StrOption("string", "", default="string") s = StrOption("string", "", default="string")
descr = OptionDescription("options", "", [s]) descr = OptionDescription("options", "", [s])
api = Config(descr) cfg = Config(descr)
api.option('string').value.set("egg") cfg.option('string').value.set("egg")
assert api.option('string').option.default() == "string" assert cfg.option('string').option.default() == "string"
assert api.option('string').value.get() == "egg" assert cfg.option('string').value.get() == "egg"
api.option('string').value.set('blah') cfg.option('string').value.set('blah')
assert api.option('string').option.default() == "string" assert cfg.option('string').option.default() == "string"
assert api.option('string').value.get() == "blah" assert cfg.option('string').value.get() == "blah"
api.option('string').value.set('bol') cfg.option('string').value.set('bol')
assert api.option('string').value.get() == 'bol' assert cfg.option('string').value.get() == 'bol'
def test_allow_multiple_changes_from_config(): def test_allow_multiple_changes_from_config():
@ -460,21 +467,21 @@ def test_allow_multiple_changes_from_config():
s2 = StrOption("string2", "", default="string") s2 = StrOption("string2", "", default="string")
suboption = OptionDescription("bip", "", [s2]) suboption = OptionDescription("bip", "", [s2])
descr = OptionDescription("options", "", [s, suboption]) descr = OptionDescription("options", "", [s, suboption])
api = Config(descr) cfg = Config(descr)
api.option('string').value.set("oh") cfg.option('string').value.set("oh")
assert api.option('string').value.get() == "oh" assert cfg.option('string').value.get() == "oh"
api.option('string').value.set("blah") cfg.option('string').value.set("blah")
assert api.option('string').value.get() == "blah" assert cfg.option('string').value.get() == "blah"
# ____________________________________________________________ # ____________________________________________________________
# accessing a value by the get method # accessing a value by the get method
def test_access_by_get(): def test_access_by_get():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
raises(AttributeError, "list(api.option.find('idontexist'))") raises(AttributeError, "list(cfg.option.find('idontexist'))")
assert api.option.find('wantref', first=True).value.get() is False assert cfg.option.find('wantref', first=True).value.get() is False
assert api.option.find('dummy', first=True).value.get() is False assert cfg.option.find('dummy', first=True).value.get() is False
def test_access_by_get_whith_hide(): def test_access_by_get_whith_hide():
@ -485,74 +492,74 @@ def test_access_by_get_whith_hide():
BoolOption("d1", "")]), BoolOption("d1", "")]),
BoolOption("b2", ""), BoolOption("b2", ""),
BoolOption("d1", "")]) BoolOption("d1", "")])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(AttributeError, "api.option.find('b1').value.get()") raises(AttributeError, "cfg.option.find('b1').value.get()")
def test_append_properties(): def test_append_properties():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
assert api.option('gc.dummy').property.get() == set() assert cfg.option('gc.dummy').property.get() == set()
api.option('gc.dummy').property.add('test') cfg.option('gc.dummy').property.add('test')
assert api.option('gc.dummy').property.get() == {'test'} assert cfg.option('gc.dummy').property.get() == {'test'}
raises(ConfigError, "api.option('gc.dummy').property.add('force_store_value')") raises(ConfigError, "cfg.option('gc.dummy').property.add('force_store_value')")
assert api.option('gc.dummy').property.get() == {'test'} assert cfg.option('gc.dummy').property.get() == {'test'}
def test_reset_properties(): def test_reset_properties():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
assert api.option('gc.dummy').property.get() == set() assert cfg.option('gc.dummy').property.get() == set()
api.option('gc.dummy').property.add('frozen') cfg.option('gc.dummy').property.add('frozen')
assert api.option('gc.dummy').property.get() == {'frozen'} assert cfg.option('gc.dummy').property.get() == {'frozen'}
api.option('gc.dummy').property.reset() cfg.option('gc.dummy').property.reset()
assert api.option('gc.dummy').property.get() == set() assert cfg.option('gc.dummy').property.get() == set()
def test_properties_cached(): def test_properties_cached():
b1 = BoolOption("b1", "", properties=('test',)) b1 = BoolOption("b1", "", properties=('test',))
descr = OptionDescription("opt", "", [OptionDescription("sub", "", [b1])]) descr = OptionDescription("opt", "", [OptionDescription("sub", "", [b1])])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert api.option('sub.b1').property.get() == {'test'} assert cfg.option('sub.b1').property.get() == {'test'}
def test_append_properties_force_store_value(): def test_append_properties_force_store_value():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',)) gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
gcgroup = OptionDescription('gc', '', [gcdummy]) gcgroup = OptionDescription('gc', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [gcgroup]) descr = OptionDescription('tiramisu', '', [gcgroup])
api = Config(descr) cfg = Config(descr)
assert api.option('gc.dummy').property.get() == {'force_store_value'} assert cfg.option('gc.dummy').property.get() == {'force_store_value'}
api.option('gc.dummy').property.add('test') cfg.option('gc.dummy').property.add('test')
assert api.option('gc.dummy').property.get() == {'force_store_value', 'test'} assert cfg.option('gc.dummy').property.get() == {'force_store_value', 'test'}
def test_reset_properties_force_store_value(): def test_reset_properties_force_store_value():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',)) gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
gcgroup = OptionDescription('gc', '', [gcdummy]) gcgroup = OptionDescription('gc', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [gcgroup]) descr = OptionDescription('tiramisu', '', [gcgroup])
api = Config(descr) cfg = Config(descr)
assert api.property.exportation() == {} assert cfg.property.exportation() == {}
api.property.add('frozen') cfg.property.add('frozen')
assert api.property.exportation() == \ assert cfg.property.exportation() == \
{None: set(('frozen', 'cache', 'validator', 'warnings'))} {None: set(('frozen', 'cache', 'validator', 'warnings'))}
api.property.reset() cfg.property.reset()
assert api.property.exportation() == {} assert cfg.property.exportation() == {}
api.option('gc.dummy').property.add('test') cfg.option('gc.dummy').property.add('test')
assert api.property.exportation() == {'gc.dummy': set(('test', 'force_store_value'))} assert cfg.property.exportation() == {'gc.dummy': set(('test', 'force_store_value'))}
api.property.reset() cfg.property.reset()
assert api.property.exportation() == {'gc.dummy': set(('test', 'force_store_value'))} assert cfg.property.exportation() == {'gc.dummy': set(('test', 'force_store_value'))}
api.property.add('frozen') cfg.property.add('frozen')
assert api.property.exportation() == \ assert cfg.property.exportation() == \
{None: set(('frozen', 'validator', 'cache', 'warnings')), {None: set(('frozen', 'validator', 'cache', 'warnings')),
'gc.dummy': set(('test', 'force_store_value'))} 'gc.dummy': set(('test', 'force_store_value'))}
api.property.add('frozen') cfg.property.add('frozen')
assert api.property.exportation() == \ assert cfg.property.exportation() == \
{None: set(('frozen', 'validator', 'cache', 'warnings')), {None: set(('frozen', 'validator', 'cache', 'warnings')),
'gc.dummy': set(('test', 'force_store_value'))} 'gc.dummy': set(('test', 'force_store_value'))}
api.option('gc.dummy').property.add('test') cfg.option('gc.dummy').property.add('test')
assert api.property.exportation() == \ assert cfg.property.exportation() == \
{None: set(('frozen', 'validator', 'cache', 'warnings')), {None: set(('frozen', 'validator', 'cache', 'warnings')),
'gc.dummy': set(('test', 'force_store_value'))} 'gc.dummy': set(('test', 'force_store_value'))}
@ -581,10 +588,10 @@ def test_set_modified_value():
gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',)) gcdummy = BoolOption('dummy', 'dummy', default=False, properties=('force_store_value',))
gcgroup = OptionDescription('gc', '', [gcdummy]) gcgroup = OptionDescription('gc', '', [gcdummy])
descr = OptionDescription('tiramisu', '', [gcgroup]) descr = OptionDescription('tiramisu', '', [gcgroup])
api = Config(descr) cfg = Config(descr)
assert api.property.exportation() == {} assert cfg.property.exportation() == {}
api.property.importation({None: set(('frozen', 'cache', 'validator', 'warnings'))}) cfg.property.importation({None: set(('frozen', 'cache', 'validator', 'warnings'))})
assert api.property.exportation() == \ assert cfg.property.exportation() == \
{None: set(('frozen', 'cache', 'validator', 'warnings'))} {None: set(('frozen', 'cache', 'validator', 'warnings'))}
@ -612,12 +619,12 @@ def test_pprint():
val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}]) val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}])
descr = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3]) descr = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.option('int').value.set(1) cfg.option('int').value.set(1)
err = None err = None
try: try:
api.option('str').value.get() cfg.option('str').value.get()
except PropertiesOptionError as error: except PropertiesOptionError as error:
err = error err = error
@ -628,7 +635,7 @@ def test_pprint():
err = None err = None
try: try:
api.option('options.val2').value.get() cfg.option('options.val2').value.get()
except PropertiesOptionError as error: except PropertiesOptionError as error:
err = error err = error
@ -636,7 +643,7 @@ def test_pprint():
#err = None #err = None
#try: #try:
# api.option('val3').value.get() # cfg.option('val3').value.get()
#except PropertiesOptionError as error: #except PropertiesOptionError as error:
# err = error # err = error
@ -649,7 +656,7 @@ def test_pprint():
err = None err = None
try: try:
api.option('string').value.get() cfg.option('string').value.get()
except Exception as error: except Exception as error:
err = error err = error
@ -658,7 +665,7 @@ def test_pprint():
err = None err = None
try: try:
api.option('string3').value.get() cfg.option('string3').value.get()
except Exception as error: except Exception as error:
err = error err = error

View File

@ -2,6 +2,7 @@
"frozen and hidden values" "frozen and hidden values"
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
@ -45,95 +46,122 @@ def make_description():
# ____________________________________________________________ # ____________________________________________________________
def test_is_hidden(): def test_is_hidden(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert not 'frozen' in api.forcepermissive.option('gc.dummy').property.get() assert not 'frozen' in cfg.forcepermissive.option('gc.dummy').property.get()
cfg = get_config(cfg, config_type)
# setattr # setattr
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False") raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get() == False")
# getattr # getattr
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()") raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get()")
def test_group_is_hidden(): def test_group_is_hidden(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
api.option('gc').property.add('hidden') cfg_ori.option('gc').property.add('hidden')
raises(PropertiesOptionError, "api.option('gc.dummy').value.get()") cfg = get_config(cfg_ori, config_type)
assert 'hidden' in api.forcepermissive.option('gc').property.get() raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get()")
raises(PropertiesOptionError, "api.option('gc.float').value.get()") if config_type == 'tiramisu-api':
cfg.send()
assert 'hidden' in cfg_ori.forcepermissive.option('gc').property.get()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('gc.float').value.get()")
# manually set the subconfigs to "show" # manually set the subconfigs to "show"
api.forcepermissive.option('gc').property.pop('hidden') if config_type == 'tiramisu-api':
assert not 'hidden' in api.option('gc').property.get() cfg.send()
assert api.option('gc.float').value.get() == 2.3 cfg_ori.forcepermissive.option('gc').property.pop('hidden')
cfg = get_config(cfg_ori, config_type)
assert not 'hidden' in cfg.option('gc').property.get()
assert cfg.option('gc.float').value.get() == 2.3
#dummy est en hide #dummy est en hide
prop = [] prop = []
try: try:
api.option('gc.dummy').value.set(False) cfg.option('gc.dummy').value.set(False)
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'hidden' in prop if config_type == 'tiramisu-api':
assert 'disabled' in prop
else:
assert 'hidden' in prop
def test_group_is_hidden_multi(): def test_group_is_hidden_multi(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
api.option('objspace').property.add('hidden') cfg_ori.option('objspace').property.add('hidden')
raises(PropertiesOptionError, "api.option('objspace').value.get()") cfg = get_config(cfg_ori, config_type)
assert 'hidden' in api.forcepermissive.option('objspace').property.get() raises(PropertiesOptionError, "cfg.option('objspace').value.get()")
if config_type == 'tiramisu-api':
cfg.send()
assert 'hidden' in cfg_ori.forcepermissive.option('objspace').property.get()
cfg = get_config(cfg_ori, config_type)
prop = [] prop = []
try: try:
api.option('objspace').value.set(['std']) cfg.option('objspace').value.set(['std'])
except PropertiesOptionError as err: except PropertiesOptionError as err:
prop = err.proptype prop = err.proptype
assert 'hidden' in prop if config_type == 'tiramisu-api':
api.forcepermissive.option('objspace').property.pop('hidden') assert 'disabled' in prop
assert not 'hidden' in api.option('objspace').property.get() else:
api.option('objspace').value.set(['std', 'std']) assert 'hidden' in prop
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('objspace').property.pop('hidden')
cfg = get_config(cfg_ori, config_type)
assert not 'hidden' in cfg.option('objspace').property.get()
cfg.option('objspace').value.set(['std', 'std'])
def test_global_show(): def test_global_show(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.forcepermissive.option('gc.dummy').property.add('hidden') cfg.forcepermissive.option('gc.dummy').property.add('hidden')
assert 'hidden' in api.forcepermissive.option('gc.dummy').property.get() assert 'hidden' in cfg.forcepermissive.option('gc.dummy').property.get()
raises(PropertiesOptionError, "api.option('gc.dummy').value.get() == False") cfg = get_config(cfg, config_type)
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.get() == False")
def test_with_many_subgroups(): def test_with_many_subgroups(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
#booltwo = config.unwrap_from_path('gc.subgroup.booltwo') #booltwo = config.unwrap_from_path('gc.subgroup.booltwo')
#setting = config.cfgimpl_get_settings() #setting = config.cfgimpl_get_settings()
assert not 'hidden' in api.option('gc.subgroup.booltwo').property.get() cfg = get_config(cfg_ori, config_type)
assert api.option('gc.subgroup.booltwo').value.get() is False assert not 'hidden' in cfg.option('gc.subgroup.booltwo').property.get()
api.option('gc.subgroup.booltwo').property.add('hidden') assert cfg.option('gc.subgroup.booltwo').value.get() is False
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('gc.subgroup.booltwo').property.add('hidden')
def test_password_option(): def test_password_option(config_type):
o = PasswordOption('o', '') o = PasswordOption('o', '')
d = OptionDescription('d', '', [o]) d = OptionDescription('d', '', [o])
api = Config(d) cfg = Config(d)
cfg = get_config(cfg, config_type)
api.option('o').value.set('a_valid_password') cfg.option('o').value.set('a_valid_password')
raises(ValueError, "api.option('o').value.set(1)") raises(ValueError, "cfg.option('o').value.set(1)")
def test_date_option(): def test_date_option(config_type):
o = DateOption('o', '') o = DateOption('o', '')
d = OptionDescription('d', '', [o]) d = OptionDescription('d', '', [o])
api = Config(d) cfg = Config(d)
cfg = get_config(cfg, config_type)
api.option('o').value.set('2017-02-04') cfg.option('o').value.set('2017-02-04')
api.option('o').value.set('2017-2-4') cfg.option('o').value.set('2017-2-4')
raises(ValueError, "api.option('o').value.set(1)") raises(ValueError, "cfg.option('o').value.set(1)")
raises(ValueError, "api.option('o').value.set('2017-13-20')") raises(ValueError, "cfg.option('o').value.set('2017-13-20')")
raises(ValueError, "api.option('o').value.set('2017-11-31')") raises(ValueError, "cfg.option('o').value.set('2017-11-31')")
raises(ValueError, "api.option('o').value.set('2017-12-32')") raises(ValueError, "cfg.option('o').value.set('2017-12-32')")
raises(ValueError, "api.option('o').value.set('2017-2-29')") raises(ValueError, "cfg.option('o').value.set('2017-2-29')")
raises(ValueError, "api.option('o').value.set('2-2-2017')") raises(ValueError, "cfg.option('o').value.set('2-2-2017')")
raises(ValueError, "api.option('o').value.set('2017/2/2')") raises(ValueError, "cfg.option('o').value.set('2017/2/2')")

View File

@ -1,5 +1,6 @@
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
import warnings import warnings
from py.test import raises from py.test import raises
@ -39,9 +40,9 @@ def return_if_val(value):
def is_context(value, context): def is_context(value, context):
api = Config(context) cfg = Config(context)
api.property.pop('validator') cfg.property.pop('validator')
if not isinstance(api, Config): if not isinstance(cfg, Config):
raise ValueError('not context') raise ValueError('not context')
@ -96,114 +97,138 @@ def value_empty(value, empty, values):
def valid_from_config(value, config): def valid_from_config(value, config):
api = Config(config) cfg = Config(config)
if api.option('opt1').value.get() != u'yes': if cfg.option('opt1').value.get() != u'yes':
raise ValueError("c'est une erreur") raise ValueError("c'est une erreur")
def test_validator(): def test_validator(config_type):
opt1 = StrOption('opt1', '', validator=return_true, default='val') opt1 = StrOption('opt1', '', validator=return_true, default='val')
raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')") raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')")
opt2 = StrOption('opt2', '', validator=return_false) opt2 = StrOption('opt2', '', validator=return_false)
root = OptionDescription('root', '', [opt1, opt2]) root = OptionDescription('root', '', [opt1, opt2])
api = Config(root) cfg_ori = Config(root)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg_ori, config_type)
raises(ValueError, "api.option('opt2').value.set('val')") assert cfg.option('opt1').value.get() == 'val'
raises(ValueError, "cfg.option('opt2').value.set('val')")
try: try:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
except ValueError as err: except ValueError as err:
msg = _('"{0}" is an invalid {1} for "{2}"').format('val', _('string'), 'opt2') + ', ' + _('test error return_false') msg = _('"{0}" is an invalid {1} for "{2}"').format('val', _('string'), 'opt2') + ', ' + _('test error return_false')
assert str(err) == msg assert str(err) == msg
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
msg = _('"{0}" is an invalid {1} for "{2}"').format('val', 'string', 'opt2') + ', ' + _('test error return_false')
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
assert len(w) == 1
assert str(w[0].message) == msg
with warnings.catch_warnings(record=True) as w:
cfg.option('opt2').value.get()
assert len(w) == 1
assert str(w[0].message) == msg
with warnings.catch_warnings(record=True) as w:
cfg.option('opt2').value.get()
assert len(w) == 1 assert len(w) == 1
assert str(w[0].message) == msg assert str(w[0].message) == msg
def test_validator_params(): def test_validator_params(config_type):
opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamValue('yes')), default='val') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamValue('yes')), default='val')
raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')), default='val')") raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')), default='val')")
opt2 = StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes'))) opt2 = StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')))
root = OptionDescription('root', '', [opt1, opt2]) root = OptionDescription('root', '', [opt1, opt2])
api = Config(root) cfg_ori = Config(root)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg_ori, config_type)
raises(ValueError, "api.option('opt2').value.set('val')") assert cfg.option('opt1').value.get() == 'val'
api.property.add('demoting_error_warning') raises(ValueError, "cfg.option('opt2').value.set('val')")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
assert len(w) == 1 assert len(w) == 1
def test_validator_params_value_values(): def test_validator_params_value_values(config_type):
opt1 = StrOption('opt1', '', validator=value_values, default=['val'], multi=True) opt1 = StrOption('opt1', '', validator=value_values, default=['val'], multi=True)
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == ['val'] cfg = get_config(cfg, config_type)
api.option('opt1').value.set(['val1', 'val2']) assert cfg.option('opt1').value.get() == ['val']
cfg.option('opt1').value.set(['val1', 'val2'])
def test_validator_params_value_values_index(): def test_validator_params_value_values_index(config_type):
opt1 = StrOption('opt1', '', validator=value_values_index, default=['val'], multi=True) opt1 = StrOption('opt1', '', validator=value_values_index, default=['val'], multi=True)
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == ['val'] cfg = get_config(cfg, config_type)
api.option('opt1').value.set(['val1', 'val2']) assert cfg.option('opt1').value.get() == ['val']
cfg.option('opt1').value.set(['val1', 'val2'])
def test_validator_params_value_values_leader(): def test_validator_params_value_values_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
def test_validator_params_value_values_index_leader(): def test_validator_params_value_values_index_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values_index) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, validator=value_values_index)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
def test_validator_params_value_values_follower(): def test_validator_params_value_values_follower(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_value_values_index_follower(): def test_validator_params_value_values_index_follower(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values_index) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-reseau", multi=True, validator=value_values_index)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_value_values_notmulti(): def test_validator_params_value_values_notmulti():
raises(ConfigError, "opt1 = StrOption('opt1', '', validator=value_values, default='val')") raises(ConfigError, "opt1 = StrOption('opt1', '', validator=value_values, default='val')")
def test_validator_params_value_values_kwargs_empty(): def test_validator_params_value_values_kwargs_empty(config_type):
v = BoolOption('v', '', default=False) v = BoolOption('v', '', default=False)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"]) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
@ -213,14 +238,15 @@ def test_validator_params_value_values_kwargs_empty():
validator_params=Params(ParamOption(v))) validator_params=Params(ParamOption(v)))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [v, interface1]) root = OptionDescription('root', '', [v, interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
#cfg.ip_admin_eth0.ip_admin_eth0.append('val') #cfg.ip_admin_eth0.ip_admin_eth0.append('val')
#cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2' #cfg.ip_admin_eth0.netmask_admin_eth0[1] = 'val2'
def test_validator_params_value_values_kwargs(): def test_validator_params_value_values_kwargs(config_type):
v = BoolOption('v', '', default=False) v = BoolOption('v', '', default=False)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"]) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True, default=["ip"])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
@ -230,14 +256,15 @@ def test_validator_params_value_values_kwargs():
validator_params=Params(kwargs={'auto': ParamOption(v)})) validator_params=Params(kwargs={'auto': ParamOption(v)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [v, interface1]) root = OptionDescription('root', '', [v, interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip'] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_value_values_kwargs_values(): def test_validator_params_value_values_kwargs_values(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
@ -246,15 +273,16 @@ def test_validator_params_value_values_kwargs_values():
validator_params=Params(kwargs={'values': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'values': ParamOption(ip_admin_eth0)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_value_values_kwargs2(): def test_validator_params_value_values_kwargs2(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
@ -263,14 +291,15 @@ def test_validator_params_value_values_kwargs2():
validator_params=Params(ParamValue(['val1']), {'index': ParamOption(ip_admin_eth0)})) validator_params=Params(ParamValue(['val1']), {'index': ParamOption(ip_admin_eth0)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
def test_validator_params_value_values_kwargs_index(): def test_validator_params_value_values_kwargs_index(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
@ -279,158 +308,181 @@ def test_validator_params_value_values_kwargs_index():
validator_params=Params(kwargs={'index': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'index': ParamOption(ip_admin_eth0)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val2')
def test_validator_params_context(): def test_validator_params_context():
opt1 = StrOption('opt1', '', validator=is_context, validator_params=Params(ParamContext()), default='val') opt1 = StrOption('opt1', '', validator=is_context, validator_params=Params(ParamContext()), default='val')
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg = Config(root)
assert 'validator' in api.property.get() # cfg = get_config(cfg, config_type) # ParamContext not supported
assert api.option('opt1').value.get() == 'val' assert 'validator' in cfg.property.get()
assert 'validator' in api.property.get() assert cfg.option('opt1').value.get() == 'val'
assert 'validator' in cfg.property.get()
def test_validator_params_context_value(): def test_validator_params_context_value():
opt1 = StrOption('opt1', '', 'yes') opt1 = StrOption('opt1', '', 'yes')
opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params=Params(ParamContext()), default='val') opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params=Params(ParamContext()), default='val')
root = OptionDescription('root', '', [opt1, opt2]) root = OptionDescription('root', '', [opt1, opt2])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == 'yes' # cfg = get_config(cfg_ori, config_type) # ParamContext not supported
assert api.option('opt2').value.get() == 'val' assert cfg.option('opt1').value.get() == 'yes'
api.option('opt1').value.set('no') assert cfg.option('opt2').value.get() == 'val'
raises(ValueError, "assert api.option('opt2').value.get()") cfg.option('opt1').value.set('no')
api.property.add('demoting_error_warning') raises(ValueError, "assert cfg.option('opt2').value.get()")
if config_type == 'tiramisu-api':
cfg.send()
cfg.property.add('demoting_error_warning')
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.get() cfg.option('opt2').value.get()
assert len(w) == 1 assert len(w) == 1
def test_validator_params_key(): def test_validator_params_key(config_type):
opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(kwargs={'param': ParamValue('yes')}), default='val') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(kwargs={'param': ParamValue('yes')}), default='val')
raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params=Params(kwargs={'param_unknown': ParamValue('yes')}), default='val')") raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params=Params(kwargs={'param_unknown': ParamValue('yes')}), default='val')")
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg, config_type)
assert cfg.option('opt1').value.get() == 'val'
def test_validator_params_option(): def test_validator_params_option(config_type):
opt0 = StrOption('opt0', '', default='yes') opt0 = StrOption('opt0', '', default='yes')
opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamOption(opt0)), default='val') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamOption(opt0)), default='val')
r = OptionDescription('root', '', [opt0, opt1]) r = OptionDescription('root', '', [opt0, opt1])
api = Config(r) cfg_ori = Config(r)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg_ori, config_type)
api.option('opt0').value.set('val') assert cfg.option('opt1').value.get() == 'val'
raises(ValueError, "api.option('opt1').value.get()") cfg.option('opt0').value.set('val')
api.property.add('demoting_error_warning') raises(ValueError, "cfg.option('opt1').value.get()")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt1').value.get() cfg.option('opt1').value.get()
assert len(w) == 1 assert len(w) == 1
def test_validator_multi(): def test_validator_multi(config_type):
opt1 = StrOption('opt1', '', validator=return_if_val, multi=True) opt1 = StrOption('opt1', '', validator=return_if_val, multi=True)
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = Config(root) cfg_ori = Config(root)
assert api.option('opt1').value.get() == [] cfg = get_config(cfg_ori, config_type)
api.option('opt1').value.set(['val']) assert cfg.option('opt1').value.get() == []
assert api.option('opt1').value.get() == ['val'] cfg.option('opt1').value.set(['val'])
raises(ValueError, "api.option('opt1').value.set(['val', 'val1'])") assert cfg.option('opt1').value.get() == ['val']
api.property.add('demoting_error_warning') raises(ValueError, "cfg.option('opt1').value.set(['val', 'val1'])")
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.add('demoting_error_warning')
cfg = get_config(cfg_ori, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt1').value.set(['val', 'val1']) cfg.option('opt1').value.set(['val', 'val1'])
assert len(w) == 1 assert len(w) == 1
def test_validator_warning(): def test_validator_warning(config_type):
opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True) opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True)
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True) opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True) opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
root = OptionDescription('root', '', [opt1, opt2, opt3]) root = OptionDescription('root', '', [opt1, opt2, opt3])
api = Config(root) cfg = Config(root)
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg, config_type)
assert cfg.option('opt1').value.get() == 'val'
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt1').value.set('val') cfg.option('opt1').value.set('val')
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
assert len(w) == 1 assert len(w) == 1
assert w[0].message.opt() == opt2 if config_type != 'tiramisu-api':
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false' assert w[0].message.opt() == opt2
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt3').value.set(['val']) cfg.option('opt3').value.set(['val'])
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt3').value.set(['val', 'val1']) cfg.option('opt3').value.set(['val', 'val1'])
assert len(w) == 1 assert len(w) == 1
assert w[0].message.opt() == opt3 if config_type != 'tiramisu-api':
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error' assert w[0].message.opt() == opt3
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
raises(ValueError, "api.option('opt2').value.set(1)") raises(ValueError, "cfg.option('opt2').value.set(1)")
assert len(w) == 0 assert len(w) == 0
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
api.option('opt3').value.set(['val', 'val1', 'val']) cfg.option('opt3').value.set(['val', 'val1', 'val'])
assert len(w) == 2 assert len(w) == 2
assert w[0].message.opt() == opt2 if config_type != 'tiramisu-api':
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false' assert w[0].message.opt() == opt2
assert w[1].message.opt() == opt3 assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2') + ', ' + 'test error return_false'
assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error' assert w[1].message.opt() == opt3
assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3') + ', ' + 'test error'
def test_validator_warning_disabled(): def test_validator_warning_disabled(config_type):
opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True) opt1 = StrOption('opt1', '', validator=return_true, default='val', warnings_only=True)
opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True) opt2 = StrOption('opt2', '', validator=return_false, warnings_only=True)
opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True) opt3 = StrOption('opt3', '', validator=return_if_val, multi=True, warnings_only=True)
root = OptionDescription('root', '', [opt1, opt2, opt3]) root = OptionDescription('root', '', [opt1, opt2, opt3])
api = Config(root) cfg_ori = Config(root)
api.property.pop('warnings') cfg_ori.property.pop('warnings')
assert api.option('opt1').value.get() == 'val' cfg = get_config(cfg_ori, config_type)
assert cfg.option('opt1').value.get() == 'val'
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt1').value.set('val') cfg.option('opt1').value.set('val')
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt3').value.set(['val']) cfg.option('opt3').value.set(['val'])
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt3').value.set(['val', 'val1']) cfg.option('opt3').value.set(['val', 'val1'])
assert w == [] assert w == []
raises(ValueError, "api.option('opt2').value.set(1)") raises(ValueError, "cfg.option('opt2').value.set(1)")
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') cfg.option('opt2').value.set('val')
api.option('opt3').value.set(['val', 'val1', 'val']) cfg.option('opt3').value.set(['val', 'val1', 'val'])
assert w == [] assert w == []
# #
api.property.add('demoting_error_warning') if config_type == 'tiramisu-api':
warnings.simplefilter("always", ValueWarning) cfg.send()
with warnings.catch_warnings(record=True) as w: cfg_ori.property.add('demoting_error_warning')
api.option('opt2').value.set(1) cfg = get_config(cfg_ori, config_type)
assert len(w) == 1 if config_type != 'tiramisu-api':
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
cfg.option('opt2').value.set(1)
assert len(w) == 1
def test_validator_warning_leadership(): def test_validator_warning_leadership(config_type):
display_name_ip = "ip reseau autorise" display_name_ip = "ip reseau autorise"
display_name_netmask = "masque du sous-reseau" display_name_netmask = "masque du sous-reseau"
ip_admin_eth0 = StrOption('ip_admin_eth0', display_name_ip, multi=True, validator=return_false, warnings_only=True) ip_admin_eth0 = StrOption('ip_admin_eth0', display_name_ip, multi=True, validator=return_false, warnings_only=True)
@ -438,48 +490,55 @@ def test_validator_warning_leadership():
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert interface1.impl_get_group_type() == groups.leadership assert interface1.impl_get_group_type() == groups.leadership
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
cfg = get_config(cfg, config_type)
warnings.simplefilter("always", ValueWarning) warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set([None]) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([None])
assert w == [] assert w == []
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
assert len(w) == 1 assert len(w) == 1
assert w[0].message.opt() == netmask_admin_eth0 if config_type != 'tiramisu-api':
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask) + ', test error' assert w[0].message.opt() == netmask_admin_eth0
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask) + ', test error'
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
assert len(w) == 1 if config_type != 'tiramisu-api':
assert w[0].message.opt() == ip_admin_eth0 assert w[0].message.opt() == ip_admin_eth0
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false' assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
else:
assert len(w) == 2
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1'])
#FIXME if config_type != 'tiramisu-api':
#assert len(w) == 1 assert w[0].message.opt() == ip_admin_eth0
assert w[0].message.opt() == ip_admin_eth0 assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false' else:
assert len(w) == 3
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1'])
#FIXME if config_type != 'tiramisu-api':
#assert len(w) == 1 assert w[0].message.opt() == ip_admin_eth0
assert w[0].message.opt() == ip_admin_eth0 assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false' else:
assert len(w) == 3
# #
warnings.resetwarnings() warnings.resetwarnings()
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val'])
#FIXME if config_type != 'tiramisu-api':
#assert len(w) == 1 assert w[0].message.opt() == ip_admin_eth0
assert w[0].message.opt() == ip_admin_eth0 assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false'
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip) + ', test error return_false' else:
assert len(w) == 3
def test_validator_follower_param(): def test_validator_follower_param(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip reseau autorise", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
@ -488,12 +547,13 @@ def test_validator_follower_param():
validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)}))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes'])
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes', 'yes']) cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val')
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val') cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['yes', 'yes'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val')
def test_validator_dependencies(): def test_validator_dependencies():
@ -504,11 +564,11 @@ def test_validator_dependencies():
validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)})) validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)}))
opt2 = StrOption('opt2', '', validator=return_false) opt2 = StrOption('opt2', '', validator=return_false)
root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2]) root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2])
api = Config(root) cfg = Config(root)
assert api.option('ip_admin_eth0').option.has_dependency() is False assert cfg.option('ip_admin_eth0').option.has_dependency() is False
assert api.option('netmask_admin_eth0').option.has_dependency() is True assert cfg.option('netmask_admin_eth0').option.has_dependency() is True
assert api.option('opt2').option.has_dependency() is False assert cfg.option('opt2').option.has_dependency() is False
# #
assert api.option('ip_admin_eth0').option.has_dependency(False) is True assert cfg.option('ip_admin_eth0').option.has_dependency(False) is True
assert api.option('netmask_admin_eth0').option.has_dependency(False) is False assert cfg.option('netmask_admin_eth0').option.has_dependency(False) is False
assert api.option('opt2').option.has_dependency(False) is False assert cfg.option('opt2').option.has_dependency(False) is False

View File

@ -1,6 +1,7 @@
#this test is much more to test that **it's there** and answers attribute access #this test is much more to test that **it's there** and answers attribute access
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
@ -36,17 +37,18 @@ def make_description():
return descr return descr
def test_root_config_answers_ok(): def test_root_config_answers_ok(config_type):
"if you hide the root config, the options in this namespace behave normally" "if you hide the root config, the options in this namespace behave normally"
gcdummy = BoolOption('dummy', 'dummy', default=False) gcdummy = BoolOption('dummy', 'dummy', default=False)
boolop = BoolOption('boolop', 'Test boolean option op', default=True) boolop = BoolOption('boolop', 'Test boolean option op', default=True)
descr = OptionDescription('tiramisu', '', [gcdummy, boolop]) descr = OptionDescription('tiramisu', '', [gcdummy, boolop])
api = Config(descr) cfg = Config(descr)
cfg = get_config(cfg, config_type)
#settings = cfg.cfgimpl_get_settings() #settings = cfg.cfgimpl_get_settings()
#settings.append('hidden') #settings.append('hidden')
assert api.option('dummy').value.get() is False assert cfg.option('dummy').value.get() is False
assert api.option('boolop').value.get() is True assert cfg.option('boolop').value.get() is True
#def test_optname_shall_not_start_with_numbers(): #def test_optname_shall_not_start_with_numbers():
@ -54,9 +56,10 @@ def test_root_config_answers_ok():
# raises(ValueError, "descr = OptionDescription('123tiramisu', '', [])") # raises(ValueError, "descr = OptionDescription('123tiramisu', '', [])")
# #
# #
def test_option_has_an_api_name(): def test_option_has_an_api_name(config_type):
b = BoolOption('impl_has_dependency', 'dummy', default=True) b = BoolOption('impl_has_dependency', 'dummy', default=True)
descr = OptionDescription('tiramisu', '', [b]) descr = OptionDescription('tiramisu', '', [b])
api = Config(descr) cfg = Config(descr)
assert api.option('impl_has_dependency').value.get() is True cfg = get_config(cfg, config_type)
assert cfg.option('impl_has_dependency').value.get() is True
assert b.impl_has_dependency() is False assert b.impl_has_dependency() is False

View File

@ -1,12 +1,12 @@
# coding: utf-8 # coding: utf-8
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from py.test import raises from py.test import raises
from tiramisu import IntOption, UnicodeOption, OptionDescription, Config from tiramisu import IntOption, UnicodeOption, OptionDescription, Config
from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.storage import list_sessions, delete_session from tiramisu.storage import list_sessions, delete_session
@ -20,61 +20,81 @@ def make_description():
return OptionDescription('od1', '', [u1, u2]) return OptionDescription('od1', '', [u1, u2])
def test_permissive(): def test_permissive(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
api.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.permissive.set(frozenset(['disabled'])) if config_type == 'tiramisu-api':
assert api.unrestraint.permissive.get() == frozenset(['disabled']) cfg.send()
cfg_ori.unrestraint.permissive.set(frozenset(['disabled']))
assert cfg_ori.unrestraint.permissive.get() == frozenset(['disabled'])
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.add('permissive') if config_type == 'tiramisu-api':
api.option('u1').value.get() cfg.send()
api.property.pop('permissive') cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
def test_permissive_add(): def test_permissive_add(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
api.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.permissive.add('disabled') if config_type == 'tiramisu-api':
assert api.unrestraint.permissive.get() == frozenset(['hidden', 'disabled']) cfg.send()
cfg_ori.unrestraint.permissive.add('disabled')
assert cfg_ori.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.add('permissive') if config_type == 'tiramisu-api':
api.option('u1').value.get() cfg.send()
api.property.pop('permissive') cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
@ -82,22 +102,22 @@ def test_permissive_add():
def test_permissive_pop(): def test_permissive_pop():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.property.read_write() cfg.property.read_write()
props = frozenset() props = frozenset()
try: try:
api.forcepermissive.option('u1').value.get() cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.permissive.add('disabled') cfg.unrestraint.permissive.add('disabled')
assert api.unrestraint.permissive.get() == frozenset(['hidden', 'disabled']) assert cfg.unrestraint.permissive.get() == frozenset(['hidden', 'disabled'])
api.forcepermissive.option('u1').value.get() cfg.forcepermissive.option('u1').value.get()
api.unrestraint.permissive.pop('disabled') cfg.unrestraint.permissive.pop('disabled')
props = frozenset() props = frozenset()
try: try:
api.forcepermissive.option('u1').value.get() cfg.forcepermissive.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
@ -105,140 +125,138 @@ def test_permissive_pop():
def test_permissive_reset(): def test_permissive_reset():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert api.unrestraint.permissive.get() == frozenset(['hidden']) assert cfg.unrestraint.permissive.get() == frozenset(['hidden'])
# #
api.unrestraint.permissive.set(frozenset(['disabled'])) cfg.unrestraint.permissive.set(frozenset(['disabled']))
assert api.unrestraint.permissive.get() == frozenset(['disabled']) assert cfg.unrestraint.permissive.get() == frozenset(['disabled'])
# #
api.unrestraint.permissive.reset() cfg.unrestraint.permissive.reset()
assert api.unrestraint.permissive.get() == frozenset() assert cfg.unrestraint.permissive.get() == frozenset()
def test_permissive_mandatory(): def test_permissive_mandatory():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2: assert frozenset(props) == frozenset(['disabled'])
assert frozenset(props) == frozenset(['disabled', 'mandatory']) cfg.unrestraint.permissive.set(frozenset(['mandatory', 'disabled']))
else: assert cfg.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled'])
assert frozenset(props) == frozenset(['disabled']) cfg.property.add('permissive')
api.unrestraint.permissive.set(frozenset(['mandatory', 'disabled'])) cfg.option('u1').value.get()
assert api.unrestraint.permissive.get() == frozenset(['mandatory', 'disabled']) cfg.property.pop('permissive')
api.property.add('permissive')
api.option('u1').value.get()
api.property.pop('permissive')
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2: assert frozenset(props) == frozenset(['disabled'])
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled'])
def test_permissive_frozen(): def test_permissive_frozen():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.unrestraint.permissive.set(frozenset(['frozen', 'disabled'])) cfg.unrestraint.permissive.set(frozenset(['frozen', 'disabled']))
assert api.unrestraint.permissive.get() == frozenset(['frozen', 'disabled']) assert cfg.unrestraint.permissive.get() == frozenset(['frozen', 'disabled'])
assert api.permissive.get() == frozenset(['frozen', 'disabled']) assert cfg.permissive.get() == frozenset(['frozen', 'disabled'])
try: try:
api.option('u1').value.set(1) cfg.option('u1').value.set(1)
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2: assert frozenset(props) == frozenset(['disabled'])
assert frozenset(props) == frozenset(['disabled', 'frozen']) cfg.property.add('permissive')
else: cfg.option('u1').value.set(1)
assert frozenset(props) == frozenset(['disabled']) assert cfg.option('u1').value.get() == 1
api.property.add('permissive') cfg.property.pop('permissive')
api.option('u1').value.set(1)
assert api.option('u1').value.get() == 1
api.property.pop('permissive')
try: try:
api.option('u1').value.set(1) cfg.option('u1').value.set(1)
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2: assert frozenset(props) == frozenset(['disabled'])
assert frozenset(props) == frozenset(['disabled', 'frozen'])
else:
assert frozenset(props) == frozenset(['disabled'])
def test_invalid_permissive(): def test_invalid_permissive():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(TypeError, "api.unrestraint.permissive.set(['frozen', 'disabled'])") raises(TypeError, "cfg.unrestraint.permissive.set(['frozen', 'disabled'])")
def test_forbidden_permissive(): def test_forbidden_permissive():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(ConfigError, "api.permissive.set(frozenset(['force_default_on_freeze']))") raises(ConfigError, "cfg.permissive.set(frozenset(['force_default_on_freeze']))")
raises(ConfigError, "api.permissive.set(frozenset(['force_metaconfig_on_freeze']))") raises(ConfigError, "cfg.permissive.set(frozenset(['force_metaconfig_on_freeze']))")
def test_permissive_option(): def test_permissive_option(config_type):
descr = make_description() descr = make_description()
api = Config(descr) cfg_ori = Config(descr)
api.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.option('u1').permissive.set(frozenset(['disabled'])) if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset() assert frozenset(props) == frozenset()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.add('permissive') if config_type == 'tiramisu-api':
api.option('u1').value.get() cfg.send()
cfg_ori.property.add('permissive')
cfg = get_config(cfg_ori, config_type)
cfg.option('u1').value.get()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.pop('permissive') if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.pop('permissive')
cfg = get_config(cfg_ori, config_type)
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset() assert frozenset(props) == frozenset()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
@ -246,55 +264,55 @@ def test_permissive_option():
def test_permissive_option_cache(): def test_permissive_option_cache():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.unrestraint.option('u1').permissive.set(frozenset(['disabled'])) cfg.unrestraint.option('u1').permissive.set(frozenset(['disabled']))
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset() assert frozenset(props) == frozenset()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.add('permissive') cfg.property.add('permissive')
api.option('u1').value.get() cfg.option('u1').value.get()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
api.property.pop('permissive') cfg.property.pop('permissive')
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset() assert frozenset(props) == frozenset()
props = frozenset() props = frozenset()
try: try:
api.option('u2').value.get() cfg.option('u2').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == {'disabled'} assert set(props) == {'disabled'}
@ -302,78 +320,85 @@ def test_permissive_option_cache():
def test_permissive_option_mandatory(): def test_permissive_option_mandatory():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_only() cfg.property.read_only()
props = frozenset() props = frozenset()
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2: assert frozenset(props) == frozenset(['disabled'])
assert frozenset(props) == frozenset(['disabled', 'mandatory']) cfg.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled']))
else: assert cfg.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled'])
assert frozenset(props) == frozenset(['disabled']) cfg.property.add('permissive')
api.unrestraint.option('u1').permissive.set(frozenset(['mandatory', 'disabled'])) cfg.option('u1').value.get()
assert api.unrestraint.option('u1').permissive.get() == frozenset(['mandatory', 'disabled']) cfg.property.pop('permissive')
api.property.add('permissive')
api.option('u1').value.get()
api.property.pop('permissive')
try: try:
api.option('u1').value.get() cfg.option('u1').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2: assert frozenset(props) == frozenset(['disabled'])
assert frozenset(props) == frozenset(['disabled', 'mandatory'])
else:
assert frozenset(props) == frozenset(['disabled'])
def test_permissive_option_frozen(): def test_permissive_option_frozen():
descr = make_description() descr = make_description()
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled'])) cfg.unrestraint.option('u1').permissive.set(frozenset(['frozen', 'disabled']))
api.option('u1').value.set(1) cfg.option('u1').value.set(1)
assert api.option('u1').value.get() == 1 assert cfg.option('u1').value.get() == 1
api.property.add('permissive') cfg.property.add('permissive')
assert api.option('u1').value.get() == 1 assert cfg.option('u1').value.get() == 1
api.property.pop('permissive') cfg.property.pop('permissive')
assert api.option('u1').value.get() == 1 assert cfg.option('u1').value.get() == 1
if TIRAMISU_VERSION == 3: def test_invalid_option_permissive():
def test_invalid_option_permissive(): descr = make_description()
descr = make_description() cfg = Config(descr)
api = Config(descr) cfg.property.read_write()
api.property.read_write() raises(TypeError, "cfg.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])")
raises(TypeError, "api.unrestraint.option('u1').permissive.set(['frozen', 'disabled'])")
def test_remove_option_permissive(): def test_remove_option_permissive(config_type):
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',)) var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
od1 = OptionDescription('od1', '', [var1]) od1 = OptionDescription('od1', '', [var1])
rootod = OptionDescription('rootod', '', [od1]) rootod = OptionDescription('rootod', '', [od1])
api = Config(rootod) cfg_ori = Config(rootod)
api.property.read_write() cfg_ori.property.read_write()
raises(PropertiesOptionError, "api.option('od1.var1').value.get()") cfg = get_config(cfg_ori, config_type)
api.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden'])) raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden']) if config_type == 'tiramisu-api':
assert api.option('od1.var1').value.get() == 'value' cfg.send()
api.forcepermissive.option('od1.var1').permissive.set(frozenset()) cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset() assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
raises(PropertiesOptionError, "api.option('od1.var1').value.get()") cfg = get_config(cfg_ori, config_type)
assert cfg.option('od1.var1').value.get() == 'value'
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset())
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
def test_reset_option_permissive(): def test_reset_option_permissive(config_type):
var1 = UnicodeOption('var1', '', u'value', properties=('hidden',)) var1 = UnicodeOption('var1', '', u'value', properties=('hidden',))
od1 = OptionDescription('od1', '', [var1]) od1 = OptionDescription('od1', '', [var1])
rootod = OptionDescription('rootod', '', [od1]) rootod = OptionDescription('rootod', '', [od1])
api = Config(rootod) cfg_ori = Config(rootod)
api.property.read_write() cfg_ori.property.read_write()
raises(PropertiesOptionError, "api.option('od1.var1').value.get()") cfg = get_config(cfg_ori, config_type)
api.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden'])) raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden']) if config_type == 'tiramisu-api':
assert api.option('od1.var1').value.get() == 'value' cfg.send()
api.forcepermissive.option('od1.var1').permissive.reset() cfg_ori.forcepermissive.option('od1.var1').permissive.set(frozenset(['hidden']))
assert api.forcepermissive.option('od1.var1').permissive.get() == frozenset() assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset(['hidden'])
raises(PropertiesOptionError, "api.option('od1.var1').value.get()") cfg = get_config(cfg_ori, config_type)
assert cfg.option('od1.var1').value.get() == 'value'
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.forcepermissive.option('od1.var1').permissive.reset()
assert cfg_ori.forcepermissive.option('od1.var1').permissive.get() == frozenset()
cfg = get_config(cfg_ori, config_type)
raises(PropertiesOptionError, "cfg.option('od1.var1').value.get()")

View File

@ -1,6 +1,7 @@
# coding: utf-8 # coding: utf-8
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from copy import copy from copy import copy
from tiramisu.i18n import _ from tiramisu.i18n import _
@ -9,7 +10,7 @@ from tiramisu import setting
setting.expires_time = 1 setting.expires_time = 1
from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \ from tiramisu import IPOption, OptionDescription, BoolOption, IntOption, StrOption, \
Leadership, Config, calc_value, Params, ParamOption Leadership, Config, calc_value, Params, ParamOption
from tiramisu.error import PropertiesOptionError, RequirementError from tiramisu.error import PropertiesOptionError, RequirementError, ConfigError
from py.test import raises from py.test import raises
from tiramisu.storage import list_sessions, delete_session from tiramisu.storage import list_sessions, delete_session
@ -18,133 +19,147 @@ def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__) assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def test_properties(): def test_properties(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', properties=('disabled',)) b = IPOption('ip_address_service', '', properties=('disabled',))
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.unrestraint.option('ip_address_service').property.pop('disabled') if config_type == 'tiramisu-api':
api.option('ip_address_service').value.get() cfg.send()
api.unrestraint.option('ip_address_service').property.add('disabled') cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_address_service').value.get()
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_address_service').property.add('disabled')
cfg = get_config(cfg_ori, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# pop twice # pop twice
api.unrestraint.option('ip_address_service').property.pop('disabled') if config_type == 'tiramisu-api':
api.unrestraint.option('ip_address_service').property.pop('disabled') cfg.send()
cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
cfg_ori.unrestraint.option('ip_address_service').property.pop('disabled')
def test_requires(): def test_requires(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert not api.option('activate_service').option.requires() assert not cfg.option('activate_service').option.requires()
assert api.option('ip_address_service').option.requires() assert cfg.option('ip_address_service').option.requires()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_callback(): def test_requires_callback(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert not api.option('activate_service').option.requires() assert not cfg.option('activate_service').option.requires()
assert api.option('ip_address_service').option.requires() assert cfg.option('ip_address_service').option.requires()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_inverse(): def test_requires_inverse(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': True}]) requires=[{'option': a, 'expected': False, 'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_self(): def test_requires_self(config_type):
a = StrOption('ip_address_service', '', a = StrOption('ip_address_service', '',
requires=[{'option': 'self', 'expected': 'b', 'action': 'disabled'}]) requires=[{'option': 'self', 'expected': 'b', 'action': 'disabled'}])
od = OptionDescription('service', '', [a]) od = OptionDescription('service', '', [a])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_address_service').value.get() == None cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.set('a') assert cfg.option('ip_address_service').value.get() == None
assert api.option('ip_address_service').value.get() == 'a' cfg.option('ip_address_service').value.set('a')
api.option('ip_address_service').value.set('b') assert cfg.option('ip_address_service').value.get() == 'a'
cfg.option('ip_address_service').value.set('b')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_with_requires(): def test_requires_with_requires(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('ip_address_service').property.add('test') cfg.option('ip_address_service').property.add('test')
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_invalid(): def test_requires_invalid():
@ -162,7 +177,7 @@ def test_requires_invalid():
raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])") raises(ValueError, "IPOption('ip_address_service', '', requires=[{'option': a, 'expected': 'string', 'action': 'disabled'}])")
def test_requires_same_action(): def test_requires_same_action(config_type):
activate_service = BoolOption('activate_service', '', True) activate_service = BoolOption('activate_service', '', True)
activate_service_web = BoolOption('activate_service_web', '', True, activate_service_web = BoolOption('activate_service_web', '', True,
requires=[{'option': activate_service, 'expected': False, requires=[{'option': activate_service, 'expected': False,
@ -173,34 +188,42 @@ def test_requires_same_action():
'action': 'disabled', 'inverse': False, 'action': 'disabled', 'inverse': False,
'transitive': True, 'same_action': False}]) 'transitive': True, 'same_action': False}])
od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web]) od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web])
api = Config(od1) cfg = Config(od1)
api.property.read_write() cfg.property.read_write()
api.property.add('new') cfg.property.add('new')
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['new']) if config_type == 'tiramisu':
assert frozenset(props) == frozenset(['new'])
else:
assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
submsg = '"disabled" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')' submsg = '"disabled" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')'
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) if config_type == 'tiramisu':
#access to cache assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) #access to cache
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
else:
# FIXME
assert str(err) == 'error'
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_same_action_callback(): def test_requires_same_action_callback(config_type):
activate_service = BoolOption('activate_service', '', True) activate_service = BoolOption('activate_service', '', True)
activate_service_web = BoolOption('activate_service_web', '', True, activate_service_web = BoolOption('activate_service_web', '', True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate_service)), 'expected': False, requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate_service)), 'expected': False,
@ -211,151 +234,175 @@ def test_requires_same_action_callback():
'action': 'disabled', 'inverse': False, 'action': 'disabled', 'inverse': False,
'transitive': True, 'same_action': False}]) 'transitive': True, 'same_action': False}])
od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web]) od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web])
api = Config(od1) cfg = Config(od1)
api.property.read_write() cfg.property.read_write()
api.property.add('new') cfg.property.add('new')
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['new']) if config_type == 'tiramisu':
assert frozenset(props) == frozenset(['new'])
else:
assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
submsg = '"disabled" (' + _('the calculated value is {0}').format('"False"') + ')' submsg = '"disabled" (' + _('the calculated value is {0}').format('"False"') + ')'
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) if config_type == 'tiramisu':
#access to cache assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg)) #access to cache
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', _('property'), submsg))
else:
# FIXME
assert str(err) == 'error'
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_multiple_requires(): def test_multiple_requires(config_type):
a = StrOption('activate_service', '') a = StrOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'}, requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
{'option': a, 'expected': 'ok', 'action': 'disabled'}]) {'option': a, 'expected': 'ok', 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set('yes') cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set('yes')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set('ok') cfg.option('activate_service').value.set('ok')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set('no') cfg.option('activate_service').value.set('no')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_multiple_requires_cumulative(): def test_multiple_requires_cumulative(config_type):
a = StrOption('activate_service', '') a = StrOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'}, requires=[{'option': a, 'expected': 'yes', 'action': 'disabled'},
{'option': a, 'expected': 'yes', 'action': 'hidden'}]) {'option': a, 'expected': 'yes', 'action': 'hidden'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service').value.set('yes') cfg.option('ip_address_service').value.get()
cfg.option('activate_service').value.set('yes')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == set(['hidden', 'disabled']) if config_type == 'tiramisu':
assert set(props) == {'hidden', 'disabled'}
else:
assert set(props) == {'disabled'}
api.option('activate_service').value.set('ok') cfg.option('activate_service').value.set('ok')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set('no') cfg.option('activate_service').value.set('no')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_multiple_requires_cumulative_inverse(): def test_multiple_requires_cumulative_inverse(config_type):
a = StrOption('activate_service', '') a = StrOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True}, requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
{'option': a, 'expected': 'yes', 'action': 'hidden', 'inverse': True}]) {'option': a, 'expected': 'yes', 'action': 'hidden', 'inverse': True}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == set(['hidden', 'disabled']) if config_type == 'tiramisu':
api.option('activate_service').value.set('yes') assert set(props) == {'hidden', 'disabled'}
api.option('ip_address_service').value.get() else:
assert set(props) == {'disabled'}
cfg.option('activate_service').value.set('yes')
cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set('ok') cfg.option('activate_service').value.set('ok')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == set(['hidden', 'disabled']) if config_type == 'tiramisu':
assert set(props) == {'hidden', 'disabled'}
else:
assert set(props) == {'disabled'}
api.option('activate_service').value.set('no') cfg.option('activate_service').value.set('no')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert set(props) == set(['hidden', 'disabled']) if config_type == 'tiramisu':
assert set(props) == {'hidden', 'disabled'}
else:
assert set(props) == {'disabled'}
def test_multiple_requires_inverse(): def test_multiple_requires_inverse(config_type):
a = StrOption('activate_service', '') a = StrOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True}, requires=[{'option': a, 'expected': 'yes', 'action': 'disabled', 'inverse': True},
{'option': a, 'expected': 'ok', 'action': 'disabled', 'inverse': True}]) {'option': a, 'expected': 'ok', 'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set('yes') cfg.option('activate_service').value.set('yes')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set('ok') cfg.option('activate_service').value.set('ok')
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set('no') cfg.option('activate_service').value.set('no')
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_transitive(): def test_requires_transitive(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -363,29 +410,30 @@ def test_requires_transitive():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_transitive_callback(): def test_requires_transitive_callback(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': False, 'action': 'disabled'}])
@ -393,29 +441,30 @@ def test_requires_transitive_callback():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_transitive_unrestraint(): def test_requires_transitive_unrestraint(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -423,18 +472,21 @@ def test_requires_transitive_unrestraint():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg_ori, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
assert api.unrestraint.option('activate_service_web').property.get() == {'disabled'} if config_type == 'tiramisu-api':
assert api.unrestraint.option('ip_address_service_web').property.get() == {'disabled'} cfg.send()
assert cfg_ori.unrestraint.option('activate_service_web').property.get() == {'disabled'}
assert cfg_ori.unrestraint.option('ip_address_service_web').property.get() == {'disabled'}
def test_requires_transitive_owner(): def test_requires_transitive_owner(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -442,23 +494,24 @@ def test_requires_transitive_owner():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
cfg.option('ip_address_service_web').value.get()
#no more default value #no more default value
api.option('ip_address_service_web').value.set('1.1.1.1') cfg.option('ip_address_service_web').value.set('1.1.1.1')
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_transitive_bis(): def test_requires_transitive_bis(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
abis = BoolOption('activate_service_bis', '', True) abis = BoolOption('activate_service_bis', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
@ -467,23 +520,24 @@ def test_requires_transitive_bis():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}]) requires=[{'option': b, 'expected': True, 'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, abis, b, d]) od = OptionDescription('service', '', [a, abis, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# #
props = [] props = []
try: try:
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
@ -496,40 +550,45 @@ def test_requires_transitive_hidden_permissive():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() # FIXME permissive cfg = get_config(cfg, config_type)
api.option('ip_address_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
def test_requires_transitive_hidden_disabled(): def test_requires_transitive_hidden_disabled(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'hidden'}]) requires=[{'option': a, 'expected': False, 'action': 'hidden'}])
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'disabled'}]) requires=[{'option': b, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['hidden']) if config_type == 'tiramisu-api':
api.option('ip_address_service_web').value.get() assert frozenset(props) == frozenset(['disabled'])
else:
assert frozenset(props) == frozenset(['hidden'])
cfg.option('ip_address_service_web').value.get()
def test_requires_transitive_hidden_disabled_multiple(): def test_requires_transitive_hidden_disabled_multiple(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'hidden'}, requires=[{'option': a, 'expected': False, 'action': 'hidden'},
@ -537,41 +596,62 @@ def test_requires_transitive_hidden_disabled_multiple():
d = IPOption('ip_address_service_web', '', d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False, 'action': 'mandatory'}]) requires=[{'option': b, 'expected': False, 'action': 'mandatory'}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg_ori, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
#
props = []
try:
api.option('activate_service_web').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert set(props) == {'disabled', 'hidden'}
del props
#
req = None req = None
try: if config_type == 'tiramisu-api':
api.option('ip_address_service_web').value.get() try:
except RequirementError as err: cfg.option('activate_service').value.set(False)
req = err except ConfigError as err:
req = err
error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"')))
else:
cfg.option('activate_service').value.set(False)
#
props = []
try:
cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err:
props = err.proptype
if config_type == 'tiramisu-api':
assert set(props) == {'disabled',}
else:
assert set(props) == {'disabled', 'hidden'}
del props
#
try:
cfg.option('ip_address_service_web').value.get()
except RequirementError as err:
req = err
error_msg = str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"'))
assert req, "ip_address_service_web should raise RequirementError" assert req, "ip_address_service_web should raise RequirementError"
assert str(req) == str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('property'), '"disabled"')) assert str(req) == error_msg
del req del req
# #
api.permissive.set(frozenset()) cfg_ori.permissive.set(frozenset())
try: if config_type == 'tiramisu-api':
api.option('ip_address_service_web').value.get() try:
except RequirementError as err: cfg = get_config(cfg_ori, config_type)
req = err except ConfigError as err:
req = err
error_msg = str(_('unable to transform tiramisu object to dict: {}').format(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and')))))
else:
cfg = get_config(cfg_ori, config_type)
try:
cfg.option('ip_address_service_web').value.get()
except RequirementError as err:
req = err
error_msg = str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and'))))
assert req, "ip_address_service_web should raise RequirementError" assert req, "ip_address_service_web should raise RequirementError"
assert str(req) == str(_('cannot access to option "{0}" because required option "{1}" has {2} {3}').format('ip_address_service_web', 'activate_service_web', _('properties'), '"disabled" {} "hidden"'.format(_('and')))) assert str(req) == error_msg
del req del req
def test_requires_not_transitive(): def test_requires_not_transitive(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -579,24 +659,25 @@ def test_requires_not_transitive():
requires=[{'option': b, 'expected': False, requires=[{'option': b, 'expected': False,
'action': 'disabled', 'transitive': False}]) 'action': 'disabled', 'transitive': False}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
cfg.option('activate_service').value.set(False)
# #
props = [] props = []
try: try:
api.option('activate_service_web').value.get() cfg.option('activate_service_web').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
# #
api.option('ip_address_service_web').value.get() cfg.option('ip_address_service_web').value.get()
def test_requires_not_transitive_not_same_action(): def test_requires_not_transitive_not_same_action(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True, b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
@ -604,154 +685,162 @@ def test_requires_not_transitive_not_same_action():
requires=[{'option': b, 'expected': False, requires=[{'option': b, 'expected': False,
'action': 'hidden', 'transitive': False}]) 'action': 'hidden', 'transitive': False}])
od = OptionDescription('service', '', [a, b, d]) od = OptionDescription('service', '', [a, b, d])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
api.option('activate_service').value.get() cfg = get_config(cfg, config_type)
api.option('activate_service_web').value.get() cfg.option('activate_service').value.get()
api.option('ip_address_service_web').value.get() cfg.option('activate_service_web').value.get()
api.option('activate_service').value.set(False) cfg.option('ip_address_service_web').value.get()
# if config_type == 'tiramisu-api':
props = [] raises(ConfigError, "cfg.option('activate_service').value.set(False)")
try: else:
api.option('activate_service_web').value.get() cfg.option('activate_service').value.set(False)
except PropertiesOptionError as err: #
props = err.proptype props = []
assert frozenset(props) == frozenset(['disabled']) try:
# cfg.option('activate_service_web').value.get()
raises(RequirementError, "api.option('ip_address_service_web').value.get()") except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
#
raises(RequirementError, "cfg.option('ip_address_service_web').value.get()")
def test_requires_None(): def test_requires_None(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': None, 'action': 'disabled'}]) requires=[{'option': a, 'expected': None, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_multi_disabled(): def test_requires_multi_disabled(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': True, 'action': 'disabled'}, requires=[{'option': a, 'expected': True, 'action': 'disabled'},
{'option': b, 'expected': 1, 'action': 'disabled'}]) {'option': b, 'expected': 1, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_multi_disabled_callback(): def test_requires_multi_disabled_callback(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': True, 'action': 'disabled'}, requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(a)), 'expected': True, 'action': 'disabled'},
{'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': 1, 'action': 'disabled'}]) {'callback': calc_value, 'callback_params': Params(ParamOption(b)), 'expected': 1, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_multi_disabled_new_format(): def test_requires_multi_disabled_new_format(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled'}]) requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
@ -781,84 +870,92 @@ def test_requires_unvalid():
'action': 'disabled', 'operator': 'and'}])""") 'action': 'disabled', 'operator': 'and'}])""")
def test_requires_multi_disabled_new_format_and(): def test_requires_multi_disabled_new_format_and(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}]) requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert props == [] assert props == []
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert props == [] assert props == []
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_multi_disabled_new_format_and_2(): def test_requires_multi_disabled_new_format_and_2(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'}, requires=[{'expected': [{'option': a, 'value': True}, {'option': b, 'value': 1}], 'action': 'disabled', 'operator': 'and'},
{'expected': [{'option': a, 'value': False}, {'option': b, 'value': 1}], 'action': 'expert'}]) {'expected': [{'option': a, 'value': False}, {'option': b, 'value': 1}], 'action': 'expert'}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.add('expert') cfg.property.add('expert')
api.property.read_write() cfg.property.read_write()
api.option('ip_address_service').value.get() cfg = get_config(cfg, config_type)
cfg.option('ip_address_service').value.get()
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert props == [] assert props == []
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['expert']) if config_type == 'tiramisu-api':
assert frozenset(props) == frozenset(['disabled'])
else:
assert frozenset(props) == frozenset(['expert'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled', 'expert']) if config_type == 'tiramisu-api':
assert frozenset(props) == frozenset(['disabled'])
else:
assert frozenset(props) == frozenset(['disabled', 'expert'])
def test_requires_multi_disabled_inverse(): def test_requires_multi_disabled_inverse(config_type):
a = BoolOption('activate_service', '') a = BoolOption('activate_service', '')
b = IntOption('num_service', '') b = IntOption('num_service', '')
c = IPOption('ip_address_service', '', c = IPOption('ip_address_service', '',
@ -867,45 +964,46 @@ def test_requires_multi_disabled_inverse():
{'option': b, 'expected': 1, {'option': b, 'expected': 1,
'action': 'disabled', 'inverse': True}]) 'action': 'disabled', 'inverse': True}])
od = OptionDescription('service', '', [a, b, c]) od = OptionDescription('service', '', [a, b, c])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(False) cfg.option('activate_service').value.set(False)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('num_service').value.set(1) cfg.option('num_service').value.set(1)
props = [] props = []
try: try:
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
api.option('activate_service').value.set(True) cfg.option('activate_service').value.set(True)
api.option('ip_address_service').value.get() cfg.option('ip_address_service').value.get()
def test_requires_multi_disabled_2(): def test_requires_multi_disabled_2(config_type):
a = BoolOption('a', '') a = BoolOption('a', '')
b = BoolOption('b', '') b = BoolOption('b', '')
c = BoolOption('c', '') c = BoolOption('c', '')
@ -927,32 +1025,33 @@ def test_requires_multi_disabled_2():
y = copy(list_bools) y = copy(list_bools)
y.append(z) y.append(z)
od = OptionDescription('service', '', y) od = OptionDescription('service', '', y)
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
api.option('z').value.get() cfg.option('z').value.get()
for boo in list_bools: for boo in list_bools:
api.option(boo.impl_getname()).value.set(True) cfg.option(boo.impl_getname()).value.set(True)
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
for boo in list_bools: for boo in list_bools:
api.option(boo.impl_getname()).value.set(False) cfg.option(boo.impl_getname()).value.set(False)
if boo == m: if boo == m:
api.option('z').value.get() cfg.option('z').value.get()
else: else:
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_multi_disabled_inverse_2(): def test_requires_multi_disabled_inverse_2(config_type):
a = BoolOption('a', '') a = BoolOption('a', '')
b = BoolOption('b', '') b = BoolOption('b', '')
c = BoolOption('c', '') c = BoolOption('c', '')
@ -975,93 +1074,106 @@ def test_requires_multi_disabled_inverse_2():
y = copy(list_bools) y = copy(list_bools)
y.append(z) y.append(z)
od = OptionDescription('service', '', y) od = OptionDescription('service', '', y)
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
for boo in list_bools: for boo in list_bools:
api.option(boo.impl_getname()).value.set(True) cfg.option(boo.impl_getname()).value.set(True)
if boo == m: if boo == m:
api.option('z').value.get() cfg.option('z').value.get()
else: else:
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
for boo in list_bools: for boo in list_bools:
api.option(boo.impl_getname()).value.set(False) cfg.option(boo.impl_getname()).value.set(False)
props = [] props = []
try: try:
api.option('z').value.get() cfg.option('z').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
assert frozenset(props) == frozenset(['disabled']) assert frozenset(props) == frozenset(['disabled'])
def test_requires_requirement_append(): def test_requires_requirement_append(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg_ori = Config(od)
api.property.read_write() cfg_ori.property.read_write()
api.property.get() cfg = get_config(cfg_ori, config_type)
api.option('ip_address_service').property.get() cfg.property.get()
raises(ValueError, "api.option('ip_address_service').property.add('disabled')") cfg.option('ip_address_service').property.get()
api.option('activate_service').value.set(False) if config_type == 'tiramisu-api':
cfg.send()
raises(ValueError, "cfg_ori.option('ip_address_service').property.add('disabled')")
cfg = get_config(cfg_ori, config_type)
cfg.option('activate_service').value.set(False)
# disabled is now set, test to remove disabled before store in storage # disabled is now set, test to remove disabled before store in storage
api.unrestraint.option('ip_address_service').property.add("test") if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_address_service').property.add("test")
def test_requires_different_inverse(): def test_requires_different_inverse(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', requires=[ b = IPOption('ip_address_service', '', requires=[
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': True, 'action': 'disabled', 'inverse': True},
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}]) {'option': a, 'expected': True, 'action': 'disabled', 'inverse': False}])
od = OptionDescription('service', '', [a, b]) od = OptionDescription('service', '', [a, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg.option('activate_service').value.set(False)
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
def test_requires_different_inverse_unicode(): def test_requires_different_inverse_unicode(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
d = StrOption('activate_other_service', '', 'val2') d = StrOption('activate_other_service', '', 'val2')
b = IPOption('ip_address_service', '', requires=[ b = IPOption('ip_address_service', '', requires=[
{'option': a, 'expected': True, 'action': 'disabled', 'inverse': True}, {'option': a, 'expected': True, 'action': 'disabled', 'inverse': True},
{'option': d, 'expected': 'val1', 'action': 'disabled', 'inverse': False}]) {'option': d, 'expected': 'val1', 'action': 'disabled', 'inverse': False}])
od = OptionDescription('service', '', [a, d, b]) od = OptionDescription('service', '', [a, d, b])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_address_service').value.get() == None cfg = get_config(cfg, config_type)
api.option('activate_service').value.set(False) assert cfg.option('ip_address_service').value.get() == None
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg.option('activate_service').value.set(False)
api.option('activate_service').value.set(True) raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
assert api.option('ip_address_service').value.get() == None cfg.option('activate_service').value.set(True)
api.option('activate_other_service').value.set('val1') assert cfg.option('ip_address_service').value.get() == None
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg.option('activate_other_service').value.set('val1')
api.option('activate_service').value.set(False) raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
raises(PropertiesOptionError, "api.option('ip_address_service').value.get()") cfg.option('activate_service').value.set(False)
raises(PropertiesOptionError, "cfg.option('ip_address_service').value.get()")
def test_requires_recursive_path(): def test_requires_recursive_path(config_type):
a = BoolOption('activate_service', '', True) a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '', b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}]) od1 = OptionDescription('service', '', [a, b], requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('base', '', [od1]) od = OptionDescription('base', '', [od1])
api = Config(od) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
raises(RequirementError, "api.option('service.a').value.get()") if config_type == 'tiramisu-api':
raises(ConfigError, "get_config(cfg, config_type)")
else:
cfg = get_config(cfg, config_type)
raises(RequirementError, "cfg.option('service.a').value.get()")
def test_optiondescription_requires(): def test_optiondescription_requires():
@ -1085,35 +1197,36 @@ def test_properties_conflict():
raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])") raises(ValueError, "od1 = OptionDescription('service', '', [a], properties=('disabled',), requires=[{'option': a, 'expected': False, 'action': 'disabled'}])")
def test_leadership_requires(): def test_leadership_requires(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'option': ip_admin_eth0, 'expected': '192.168.1.1', 'action': 'disabled'}])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) od = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'], assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']} 'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']}
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
ret = api.value.dict() ret = cfg.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -1123,8 +1236,8 @@ def test_leadership_requires():
del ret['ip_admin_eth0.netmask_admin_eth0'][0] del ret['ip_admin_eth0.netmask_admin_eth0'][0]
del ret['ip_admin_eth0.netmask_admin_eth0'] del ret['ip_admin_eth0.netmask_admin_eth0']
# #
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
ret = api.value.dict() ret = cfg.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -1135,35 +1248,36 @@ def test_leadership_requires():
del ret['ip_admin_eth0.netmask_admin_eth0'] del ret['ip_admin_eth0.netmask_admin_eth0']
def test_leadership_requires_callback(): def test_leadership_requires_callback(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(ip_admin_eth0)), 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(ip_admin_eth0)), 'expected': '192.168.1.1', 'action': 'disabled'}])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1]) od = OptionDescription('toto', '', [interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'], assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']} 'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']}
# #
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
ret = api.value.dict() ret = cfg.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -1173,8 +1287,8 @@ def test_leadership_requires_callback():
del ret['ip_admin_eth0.netmask_admin_eth0'][0] del ret['ip_admin_eth0.netmask_admin_eth0'][0]
del ret['ip_admin_eth0.netmask_admin_eth0'] del ret['ip_admin_eth0.netmask_admin_eth0']
# #
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255') cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
ret = api.value.dict() ret = cfg.value.dict()
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0']) assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2 assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
@ -1219,174 +1333,184 @@ def test_leadership_requires_properties():
requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}]) requires=[{'option': ip_admin, 'expected': '192.168.1.1', 'action': 'disabled'}])
def test_leadership_requires_leader(): def test_leadership_requires_leader(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}]) requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
# #
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.option('activate').value.set(True) cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.value.dict() == {'activate': False} assert cfg.value.dict() == {'activate': False}
def test_leadership_requires_leader_callback(): def test_leadership_requires_leader_callback(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.option('activate').value.set(True) cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.value.dict() == {'activate': False} assert cfg.value.dict() == {'activate': False}
def test_leadership_requires_leadership(): def test_leadership_requires_leadership(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0],
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}]) requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") if config_type != 'tiramisu-api':
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") # FIXME
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.option('activate').value.set(True) cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") if config_type != 'tiramisu-api':
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") # FIXME
assert api.value.dict() == {'activate': False} raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert cfg.value.dict() == {'activate': False}
def test_leadership_requires_leadership_callback(): def test_leadership_requires_leadership_callback(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0],
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
cfg = get_config(cfg, config_type)
# #
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
# #
api.option('activate').value.set(True) cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
# #
api.option('activate').value.set(False) cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.value.dict() == {'activate': False} assert cfg.value.dict() == {'activate': False}
def test_leadership_requires_no_leader(): def test_leadership_requires_no_leader(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}]) requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.option('activate').value.set(False) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('activate').value.set(False)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1'] cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.option('activate').value.set(True) raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
api.option('activate').value.set(False) assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False} raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False}
def test_leadership_requires_no_leader_callback(): def test_leadership_requires_no_leader_callback(config_type):
activate = BoolOption('activate', "Activer l'accès au réseau", True) activate = BoolOption('activate', "Activer l'accès au réseau", True)
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True,
requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}]) requires=[{'callback': calc_value, 'callback_params': Params(ParamOption(activate)), 'expected': False, 'action': 'disabled'}])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [activate, interface1]) od = OptionDescription('toto', '', [activate, interface1])
api = Config(maconfig) cfg = Config(od)
api.property.read_write() cfg.property.read_write()
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [] cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2']) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2'] assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.option('activate').value.set(False) assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1']) cfg.option('activate').value.set(False)
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1'] cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2', '192.168.1.1']
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
api.option('activate').value.set(True) raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None cfg.option('activate').value.set(True)
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255') assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255' cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
api.option('activate').value.set(False) assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()") cfg.option('activate').value.set(False)
raises(PropertiesOptionError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()") raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
dico = api.value.dict() raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()")
dico = cfg.value.dict()
assert set(dico.keys()) == {'activate', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'} assert set(dico.keys()) == {'activate', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'}
dico['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1'] dico['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
dico['activate'] == False dico['activate'] == False
@ -1394,8 +1518,8 @@ def test_leadership_requires_no_leader_callback():
del dico['ip_admin_eth0.netmask_admin_eth0'][0] del dico['ip_admin_eth0.netmask_admin_eth0'][0]
def test_leadership_requires_complet(): def test_leadership_requires_complet(config_type):
optiontoto = StrOption('unicodetoto', "Unicode leader") optiontoto = StrOption('unicodetoto', "Unicode")
option = StrOption('unicode', "Unicode leader", multi=True) option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True) option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Values 'test' must show 'Unicode follower 3'", multi=True) option2 = StrOption('unicode2', "Values 'test' must show 'Unicode follower 3'", multi=True)
@ -1436,11 +1560,12 @@ def test_leadership_requires_complet():
[option, option1, option2, option3, option4, option5, option6, option7]) [option, option1, option2, option3, option4, option5, option6, option7])
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto]) descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr]) descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr])
config = Config(descr) cfg = Config(descr)
config.property.read_write() cfg.property.read_write()
config.option('options.unicode.unicode').value.set(['test', 'trah']) cfg = get_config(cfg, config_type)
config.option('options.unicode.unicode2', 0).value.set('test') cfg.option('options.unicode.unicode').value.set(['test', 'trah'])
dico = config.value.dict() cfg.option('options.unicode.unicode2', 0).value.set('test')
dico = cfg.value.dict()
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']) assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'])
assert dico['options.unicode.unicode'] == ['test', 'trah'] assert dico['options.unicode.unicode'] == ['test', 'trah']
assert dico['options.unicode.unicode1'] == [None, None] assert dico['options.unicode.unicode1'] == [None, None]
@ -1455,8 +1580,8 @@ def test_leadership_requires_complet():
del dico['options.unicode.unicode4'][1] del dico['options.unicode.unicode4'][1]
del dico['options.unicode.unicode4'] del dico['options.unicode.unicode4']
# #
config.option('options.unicodetoto').value.set('test') cfg.option('options.unicodetoto').value.set('test')
dico = config.value.dict() dico = cfg.value.dict()
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto']) assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
assert dico['options.unicode.unicode'] == ['test', 'trah'] assert dico['options.unicode.unicode'] == ['test', 'trah']
assert dico['options.unicode.unicode1'] == [None, None] assert dico['options.unicode.unicode1'] == [None, None]
@ -1481,7 +1606,7 @@ def test_leadership_requires_complet():
del dico['options.unicode.unicode7'] del dico['options.unicode.unicode7']
def test_leadership_requires_complet_callback(): def test_leadership_requires_complet_callback(config_type):
optiontoto = StrOption('unicodetoto', "Unicode leader") optiontoto = StrOption('unicodetoto', "Unicode leader")
option = StrOption('unicode', "Unicode leader", multi=True) option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True) option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
@ -1530,11 +1655,12 @@ def test_leadership_requires_complet_callback():
[option, option1, option2, option3, option4, option5, option6, option7]) [option, option1, option2, option3, option4, option5, option6, option7])
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto]) descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr]) descr = OptionDescription("unicode1_leadership_requires", "Leader followers with Unicode follower 3 hidden when Unicode follower 2 is test", [descr])
config = Config(descr) cfg = Config(descr)
config.property.read_write() cfg.property.read_write()
config.option('options.unicode.unicode').value.set(['test', 'trah']) cfg = get_config(cfg, config_type)
config.option('options.unicode.unicode2', 0).value.set('test') cfg.option('options.unicode.unicode').value.set(['test', 'trah'])
dico = config.value.dict() cfg.option('options.unicode.unicode2', 0).value.set('test')
dico = cfg.value.dict()
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto']) assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
assert dico['options.unicode.unicode'] == ['test', 'trah'] assert dico['options.unicode.unicode'] == ['test', 'trah']
assert dico['options.unicode.unicode1'] == [None, None] assert dico['options.unicode.unicode1'] == [None, None]
@ -1555,8 +1681,8 @@ def test_leadership_requires_complet_callback():
del dico['options.unicode.unicode7'][0] del dico['options.unicode.unicode7'][0]
del dico['options.unicode.unicode7'][0] del dico['options.unicode.unicode7'][0]
# #
config.option('options.unicodetoto').value.set('test') cfg.option('options.unicodetoto').value.set('test')
dico = config.value.dict() dico = cfg.value.dict()
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto']) assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
assert dico['options.unicode.unicode'] == ['test', 'trah'] assert dico['options.unicode.unicode'] == ['test', 'trah']
assert dico['options.unicode.unicode1'] == [None, None] assert dico['options.unicode.unicode1'] == [None, None]
@ -1581,8 +1707,8 @@ def test_leadership_requires_complet_callback():
del dico['options.unicode.unicode7'] del dico['options.unicode.unicode7']
def test_leadership_requires_transitive(): def test_leadership_requires_transitive1(config_type):
optiontoto = StrOption('unicodetoto', "Unicode leader") optiontoto = StrOption('unicodetoto', "Simple unicode")
option = StrOption('unicode', "Unicode leader", multi=True) option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True) option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2", requires=[{'option': optiontoto, option2 = StrOption('unicode2', "Unicode follower 2", requires=[{'option': optiontoto,
@ -1607,15 +1733,16 @@ def test_leadership_requires_transitive():
[option, option1, option2, option3, option4]) [option, option1, option2, option3, option4])
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto]) descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
descr = OptionDescription("unicode1", "", [descr]) descr = OptionDescription("unicode1", "", [descr])
config = Config(descr) cfg = Config(descr)
config.property.read_write() cfg.property.read_write()
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None} cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None}
# #
config.option('options.unicodetoto').value.set('test') cfg.option('options.unicodetoto').value.set('test')
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'} assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'}
# #
config.option('options.unicode.unicode').value.set(['a', 'b', 'c']) cfg.option('options.unicode.unicode').value.set(['a', 'b', 'c'])
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1634,9 +1761,9 @@ def test_leadership_requires_transitive():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicode.unicode2', 1).value.set('test')
config.option('options.unicode.unicode3', 1).value.set('test') cfg.option('options.unicode.unicode3', 1).value.set('test')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1655,8 +1782,8 @@ def test_leadership_requires_transitive():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('rah') cfg.option('options.unicode.unicode2', 1).value.set('rah')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1675,9 +1802,9 @@ def test_leadership_requires_transitive():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicode.unicode2', 1).value.set('test')
config.option('options.unicodetoto').value.set('rah') cfg.option('options.unicodetoto').value.set('rah')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'rah' assert dico['options.unicodetoto'] == 'rah'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1696,7 +1823,7 @@ def test_leadership_requires_transitive():
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
def test_leadership_requires_transitive_callback(): def test_leadership_requires_transitive_callback(config_type):
optiontoto = StrOption('unicodetoto', "Unicode leader") optiontoto = StrOption('unicodetoto', "Unicode leader")
option = StrOption('unicode', "Unicode leader", multi=True) option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True) option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
@ -1725,15 +1852,16 @@ def test_leadership_requires_transitive_callback():
[option, option1, option2, option3, option4]) [option, option1, option2, option3, option4])
descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto]) descr = OptionDescription("options", "Common configuration 2", [descr1, optiontoto])
descr = OptionDescription("unicode1", "", [descr]) descr = OptionDescription("unicode1", "", [descr])
config = Config(descr) cfg = Config(descr)
config.property.read_write() cfg.property.read_write()
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None} cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None}
# #
config.option('options.unicodetoto').value.set('test') cfg.option('options.unicodetoto').value.set('test')
assert config.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'} assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'}
# #
config.option('options.unicode.unicode').value.set(['a', 'b', 'c']) cfg.option('options.unicode.unicode').value.set(['a', 'b', 'c'])
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1752,9 +1880,9 @@ def test_leadership_requires_transitive_callback():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicode.unicode2', 1).value.set('test')
config.option('options.unicode.unicode3', 1).value.set('test') cfg.option('options.unicode.unicode3', 1).value.set('test')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1773,8 +1901,8 @@ def test_leadership_requires_transitive_callback():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('rah') cfg.option('options.unicode.unicode2', 1).value.set('rah')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'test' assert dico['options.unicodetoto'] == 'test'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
@ -1793,9 +1921,9 @@ def test_leadership_requires_transitive_callback():
del (dico['options.unicode.unicode4'][1]) del (dico['options.unicode.unicode4'][1])
del (dico['options.unicode.unicode4'][0]) del (dico['options.unicode.unicode4'][0])
# #
config.option('options.unicode.unicode2', 1).value.set('test') cfg.option('options.unicode.unicode2', 1).value.set('test')
config.option('options.unicodetoto').value.set('rah') cfg.option('options.unicodetoto').value.set('rah')
dico = config.value.dict() dico = cfg.value.dict()
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto'] assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
assert dico['options.unicodetoto'] == 'rah' assert dico['options.unicodetoto'] == 'rah'
assert dico['options.unicode.unicode'] == ['a', 'b', 'c'] assert dico['options.unicode.unicode'] == ['a', 'b', 'c']

View File

@ -2,12 +2,12 @@
from py.test import raises from py.test import raises
from .autopath import do_autopath from .autopath import do_autopath
do_autopath() do_autopath()
from .config import config_type, get_config
from tiramisu import BoolOption, StrOption, SymLinkOption, \ from tiramisu import BoolOption, StrOption, SymLinkOption, \
OptionDescription, Leadership, Config OptionDescription, Leadership, Config
from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.storage import list_sessions from tiramisu.storage import list_sessions
@ -20,52 +20,55 @@ def return_value():
#____________________________________________________________ #____________________________________________________________
def test_symlink_option(): def test_symlink_option(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.option('s1.b').value.get() is False cfg = get_config(cfg, config_type)
api.option("s1.b").value.set(True) assert cfg.option('s1.b').value.get() is False
api.option("s1.b").value.set(False) cfg.option("s1.b").value.set(True)
assert api.option('s1.b').value.get() is False cfg.option("s1.b").value.set(False)
assert api.option('c').value.get() is False assert cfg.option('s1.b').value.get() is False
api.option('s1.b').value.set(True) assert cfg.option('c').value.get() is False
assert api.option('s1.b').value.get() is True cfg.option('s1.b').value.set(True)
assert api.option('c').value.get() is True assert cfg.option('s1.b').value.get() is True
api.option('s1.b').value.set(False) assert cfg.option('c').value.get() is True
assert api.option('s1.b').value.get() is False cfg.option('s1.b').value.set(False)
assert api.option('c').value.get() is False assert cfg.option('s1.b').value.get() is False
assert cfg.option('c').value.get() is False
def test_symlink_assign_option(): def test_symlink_assign_option(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
raises(ConfigError, "api.option('c').value.set(True)") cfg = get_config(cfg, config_type)
raises(ConfigError, "cfg.option('c').value.set(True)")
def test_symlink_del_option(): def test_symlink_del_option(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
raises(TypeError, "api.option('c').value.reset()") cfg = get_config(cfg, config_type)
raises(ConfigError, "cfg.option('c').value.reset()")
def test_symlink_addproperties(): def test_symlink_addproperties():
boolopt = BoolOption('b', '', default=True, properties=('test',)) boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(TypeError, "api.option('c').property.add('new')") raises(TypeError, "cfg.option('c').property.add('new')")
try: try:
api.option('c').property.reset() cfg.option('c').property.reset()
except AssertionError: except AssertionError:
pass pass
else: else:
@ -76,21 +79,21 @@ def test_symlink_getpermissive():
boolopt = BoolOption('b', '', default=True, properties=('test',)) boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
api.option('b').permissive.set(frozenset(['perm'])) cfg.option('b').permissive.set(frozenset(['perm']))
api.option('c').permissive.get() == frozenset(['perm']) cfg.option('c').permissive.get() == frozenset(['perm'])
def test_symlink_addpermissives(): def test_symlink_addpermissives():
boolopt = BoolOption('b', '', default=True, properties=('test',)) boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
raises(TypeError, "api.option('c').permissive.set(frozenset(['new']))") raises(TypeError, "cfg.option('c').permissive.set(frozenset(['new']))")
try: try:
api.option('c').permissive.reset() cfg.option('c').permissive.reset()
except AssertionError: except AssertionError:
pass pass
else: else:
@ -101,12 +104,9 @@ def test_symlink_getproperties():
boolopt = BoolOption('b', '', default=True, properties=('test',)) boolopt = BoolOption('b', '', default=True, properties=('test',))
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
if TIRAMISU_VERSION == 2: assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == {'test'}
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == ('test',)
else:
assert boolopt.impl_getproperties() == linkopt.impl_getproperties() == {'test'}
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == False assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == False
@ -114,89 +114,86 @@ def test_symlink_getcallback():
boolopt = BoolOption('b', '', callback=return_value) boolopt = BoolOption('b', '', callback=return_value)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription('opt', '', [boolopt, linkopt]) descr = OptionDescription('opt', '', [boolopt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True
assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, None) assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, None)
def test_symlink_requires(): def test_symlink_requires(config_type):
boolopt = BoolOption('b', '', default=True) boolopt = BoolOption('b', '', default=True)
stropt = StrOption('s', '', requires=[{'option': boolopt, stropt = StrOption('s', '', requires=[{'option': boolopt,
'expected': False, 'expected': False,
'action': 'disabled'}]) 'action': 'disabled'}])
linkopt = SymLinkOption("c", stropt) linkopt = SymLinkOption("c", stropt)
descr = OptionDescription('opt', '', [boolopt, stropt, linkopt]) descr = OptionDescription('opt', '', [boolopt, stropt, linkopt])
api = Config(descr) cfg = Config(descr)
api.property.read_write() cfg.property.read_write()
assert api.option('b').value.get() is True cfg = get_config(cfg, config_type)
assert api.option('s').value.get() is None assert cfg.option('b').value.get() is True
assert api.option('c').value.get() is None assert cfg.option('s').value.get() is None
api.option('b').value.set(False) assert cfg.option('c').value.get() is None
cfg.option('b').value.set(False)
# #
props = [] props = []
try: try:
api.option('s').value.get() cfg.option('s').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2: assert props == {'disabled'}
assert props == ['disabled']
else:
assert props == {'disabled'}
# #
props = [] props = []
try: try:
api.option('c').value.get() cfg.option('c').value.get()
except PropertiesOptionError as err: except PropertiesOptionError as err:
props = err.proptype props = err.proptype
if TIRAMISU_VERSION == 2: assert props == {'disabled'}
assert props == ['disabled']
else:
assert props == {'disabled'}
def test_symlink_multi(): def test_symlink_multi(config_type):
boolopt = BoolOption("b", "", default=[False], multi=True) boolopt = BoolOption("b", "", default=[False], multi=True)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.option('s1.b').value.get() == [False] cfg = get_config(cfg, config_type)
assert api.option('c').value.get() == [False] assert cfg.option('s1.b').value.get() == [False]
api.option('s1.b').value.set([True]) assert cfg.option('c').value.get() == [False]
assert api.option('s1.b').value.get() == [True] cfg.option('s1.b').value.set([True])
assert api.option('c').value.get() == [True] assert cfg.option('s1.b').value.get() == [True]
api.option('s1.b').value.set([False]) assert cfg.option('c').value.get() == [True]
assert api.option('s1.b').value.get() == [False] cfg.option('s1.b').value.set([False])
assert api.option('c').value.get() == [False] assert cfg.option('s1.b').value.get() == [False]
api.option('s1.b').value.set([False, True]) assert cfg.option('c').value.get() == [False]
assert api.option('s1.b').value.get() == [False, True] cfg.option('s1.b').value.set([False, True])
assert api.option('c').value.get() == [False, True] assert cfg.option('s1.b').value.get() == [False, True]
assert cfg.option('c').value.get() == [False, True]
assert boolopt.impl_is_multi() is True assert boolopt.impl_is_multi() is True
assert linkopt.impl_is_multi() is True assert linkopt.impl_is_multi() is True
def test_symlink_assign(): def test_symlink_assign(config_type):
if TIRAMISU_VERSION != 2:
boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr)
raises(ConfigError, "api.option('c').value.set(True)")
def test_symlink_owner():
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.option('s1.b').owner.isdefault() cfg = get_config(cfg, config_type)
assert api.option('c').owner.isdefault() raises(ConfigError, "cfg.option('c').value.set(True)")
api.option('s1.b').value.set(True)
assert not api.option('s1.b').owner.isdefault()
assert not api.option('c').owner.isdefault() def test_symlink_owner(config_type):
boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])])
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('s1.b').owner.isdefault()
assert cfg.option('c').owner.isdefault()
cfg.option('s1.b').value.set(True)
assert not cfg.option('s1.b').owner.isdefault()
assert not cfg.option('c').owner.isdefault()
def test_symlink_get_information(): def test_symlink_get_information():
@ -224,41 +221,43 @@ def test_symlink_followers():
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])") raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
def test_symlink_with_leader(): def test_symlink_with_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
leader = SymLinkOption('leader', ip_admin_eth0) leader = SymLinkOption('leader', ip_admin_eth0)
od = OptionDescription('root', '', [interface1, leader]) od = OptionDescription('root', '', [interface1, leader])
api = Config(od) cfg = Config(od)
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'leader': []} cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'leader': []}
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'leader': ['val1', 'val2']} cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'leader': ['val1', 'val2']}
def test_symlink_with_follower(): def test_symlink_with_follower(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True) netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
follower = SymLinkOption('follower', netmask_admin_eth0) follower = SymLinkOption('follower', netmask_admin_eth0)
od = OptionDescription('root', '', [interface1, follower]) od = OptionDescription('root', '', [interface1, follower])
api = Config(od) cfg = Config(od)
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'follower': []} cfg = get_config(cfg, config_type)
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2']) assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'follower': []}
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'follower': [None, None]} cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'follower': [None, None]}
# #
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
assert api.option('follower', 0).value.get() == None assert cfg.option('follower', 0).value.get() == None
assert api.option('follower', 1).value.get() == None assert cfg.option('follower', 1).value.get() == None
# #
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3') cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3')
assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'follower': [None, 'val3']} assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'follower': [None, 'val3']}
# #
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3' assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3'
assert api.option('follower', 0).value.get() == None assert cfg.option('follower', 0).value.get() == None
assert api.option('follower', 1).value.get() == 'val3' assert cfg.option('follower', 1).value.get() == 'val3'
#____________________________________________________________ #____________________________________________________________
@ -267,36 +266,38 @@ def test_symlink_dependency():
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.option('s1.b').option.has_dependency() is False assert cfg.option('s1.b').option.has_dependency() is False
assert api.option('c').option.has_dependency() is True assert cfg.option('c').option.has_dependency() is True
assert api.option('s1.b').option.has_dependency(False) is True assert cfg.option('s1.b').option.has_dependency(False) is True
assert api.option('c').option.has_dependency(False) is False assert cfg.option('c').option.has_dependency(False) is False
def test_symlink_makedict(): def test_symlink_makedict(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
assert api.value.dict() == {'c': False, 's1.b': False} cfg = get_config(cfg, config_type)
api.option('s1.b').value.set(True) assert cfg.value.dict() == {'c': False, 's1.b': False}
assert api.value.dict() == {'c': True, 's1.b': True} cfg.option('s1.b').value.set(True)
assert cfg.value.dict() == {'c': True, 's1.b': True}
def test_symlink_list(): def test_symlink_list(config_type):
boolopt = BoolOption("b", "", default=False) boolopt = BoolOption("b", "", default=False)
linkopt = SymLinkOption("c", boolopt) linkopt = SymLinkOption("c", boolopt)
descr = OptionDescription("opt", "", descr = OptionDescription("opt", "",
[linkopt, OptionDescription("s1", "", [boolopt])]) [linkopt, OptionDescription("s1", "", [boolopt])])
api = Config(descr) cfg = Config(descr)
cfg = get_config(cfg, config_type)
list_opt = [] list_opt = []
for opt in api.option.list(): for opt in cfg.option.list():
list_opt.append(opt.option.path()) list_opt.append(opt.option.path())
assert list_opt == ['c'] assert list_opt == ['c']
# #
list_opt = [] list_opt = []
for opt in api.option.list(recursive=True): for opt in cfg.option.list(recursive=True):
list_opt.append(opt.option.path()) list_opt.append(opt.option.path())
assert list_opt == ['c', 's1.b'] assert list_opt == ['c', 's1.b']

View File

@ -45,4 +45,4 @@ allfuncs.extend(all_options)
del(all_options) del(all_options)
__all__ = tuple(allfuncs) __all__ = tuple(allfuncs)
del(allfuncs) del(allfuncs)
__version__ = "3.0rc7" __version__ = "3.0rc9"

View File

@ -19,7 +19,7 @@ from time import time
from typing import List, Set, Any, Optional, Callable, Union, Dict from typing import List, Set, Any, Optional, Callable, Union, Dict
from .error import APIError, ConfigError, LeadershipError, PropertiesOptionError from .error import APIError, ConfigError, LeadershipError, PropertiesOptionError, ValueErrorWarning
from .i18n import _ from .i18n import _
from .setting import ConfigBag, OptionBag, owners, groups, Undefined, undefined, \ from .setting import ConfigBag, OptionBag, owners, groups, Undefined, undefined, \
FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES, EXPIRATION_TIME FORBIDDEN_SET_PROPERTIES, SPECIAL_PROPERTIES, EXPIRATION_TIME
@ -101,12 +101,12 @@ class CommonTiramisu(TiramisuHelp):
raise APIError('index must be set only with a follower option') raise APIError('index must be set only with a follower option')
self._length = self._subconfig.cfgimpl_get_length_leadership(self._option_bag) self._length = self._subconfig.cfgimpl_get_length_leadership(self._option_bag)
if index >= self._length: if index >= self._length:
raise LeadershipError(_('index "{}" is higher than the leadership length "{}" ' raise LeadershipError(_('index "{}" is greater than the leadership length "{}" '
'for option "{}"').format(index, 'for option "{}"').format(index,
self._length, self._length,
option.impl_get_display_name())) option.impl_get_display_name()))
if not self._allow_optiondescription and option.impl_is_optiondescription(): if not self._allow_optiondescription and option.impl_is_optiondescription():
raise APIError(_('option must not be an optiondescription')) raise APIError(_('option must not be an optiondescription'))
return option return option
@ -118,7 +118,8 @@ class CommonTiramisuOption(CommonTiramisu):
def __init__(self, def __init__(self,
name: str, name: str,
subconfig: Union[KernelConfig, SubConfig], subconfig: Union[KernelConfig, SubConfig],
option_bag: OptionBag) -> None: option_bag: OptionBag,
config: 'Config'=None) -> None:
self._option_bag = option_bag self._option_bag = option_bag
self._name = name self._name = name
self._subconfig = subconfig self._subconfig = subconfig
@ -136,13 +137,22 @@ class CommonTiramisuOption(CommonTiramisu):
raise APIError(_('index must be set with the follower option "{}"').format(self._option_bag.path)) raise APIError(_('index must be set with the follower option "{}"').format(self._option_bag.path))
def __getattr__(self, name): def __getattr__(self, name):
raise APIError(_('unknown method {}').format(name)) raise APIError(_('unknown method {} in {}').format(name, self.__class__.__name__))
class _TiramisuOptionOptionDescription(CommonTiramisuOption): class _TiramisuOptionOptionDescription(CommonTiramisuOption):
"""Manage option""" """Manage option"""
_allow_optiondescription = True _allow_optiondescription = True
_follower_need_index = False _follower_need_index = False
_validate_properties = False
def __init__(self,
name: str,
subconfig: Union[KernelConfig, SubConfig],
option_bag: OptionBag,
config: "Subconfig") -> None:
super().__init__(name, subconfig, option_bag)
self._config = config
def get(self): def get(self):
"""Get Tiramisu option""" """Get Tiramisu option"""
@ -195,27 +205,22 @@ class _TiramisuOptionOptionDescription(CommonTiramisuOption):
only_raises=False): only_raises=False):
"""Get properties for an option""" """Get properties for an option"""
settings = self._option_bag.config_bag.context.cfgimpl_get_settings() settings = self._option_bag.config_bag.context.cfgimpl_get_settings()
properties = settings.getproperties(self._option_bag,
apply_requires=False)
if not only_raises: if not only_raises:
return properties return settings.getproperties(self._option_bag,
apply_requires=False)
# do not check cache properties/permissives which are not save (unrestraint, ...) # do not check cache properties/permissives which are not save (unrestraint, ...)
return settings.calc_raises_properties(properties, return settings.calc_raises_properties(self._option_bag,
settings.get_context_properties(), apply_requires=False)
settings.get_context_properties())
def __call__(self, def __call__(self,
path: str, name: str,
index: Optional[int]=None) -> 'TiramisuOption': index: Optional[int]=None) -> 'TiramisuOption':
"""Select an option by path""" """Select an option by path"""
subpath = self._option_bag.option.impl_getname() + '.' + path path = self._option_bag.path + '.' + name
subconfig, name = self._subconfig.cfgimpl_get_home_by_path(subpath,
self._option_bag.config_bag)
path = self._option_bag.path + '.' + path
return TiramisuOption(name, return TiramisuOption(name,
path, path,
index, index,
subconfig, self._config,
self._option_bag.config_bag) self._option_bag.config_bag)
@ -253,7 +258,16 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
def defaultmulti(self): def defaultmulti(self):
"""Get default value when added a value for a multi option (not for optiondescription)""" """Get default value when added a value for a multi option (not for optiondescription)"""
option = self._option_bag.option option = self._option_bag.option
return option.impl_getdefault_multi() ret = option.impl_getdefault_multi()
if ret is None and option.impl_is_multi() and option.impl_has_callback() and not self.isfollower():
callback, callback_params = option.impl_get_callback()
values = self._option_bag.config_bag.context.cfgimpl_get_values()
value = values.carry_out_calculation(self._option_bag,
callback,
callback_params)
if not isinstance(value, list):
ret = value
return ret
def consistencies(self): def consistencies(self):
"""Get consistencies for an option (not for optiondescription)""" """Get consistencies for an option (not for optiondescription)"""
@ -265,6 +279,11 @@ class _TiramisuOptionOption(_TiramisuOptionOptionDescription):
option = self._option_bag.option option = self._option_bag.option
return option.impl_get_callback() return option.impl_get_callback()
def validator(self):
"""Get validator for an option (not for optiondescription)"""
option = self._option_bag.option
return option.impl_get_validator()
def pattern(self) -> str: def pattern(self) -> str:
option = self._option_bag.option option = self._option_bag.option
type = option.get_type() type = option.get_type()
@ -288,18 +307,18 @@ class TiramisuOptionOption(CommonTiramisuOption):
def __new__(cls, def __new__(cls,
name, name,
subconfig, subconfig,
option_bag): option_bag,
option = subconfig.cfgimpl_get_description().get_child(name, config):
option_bag.config_bag, if option_bag.option.impl_is_optiondescription():
subconfig.cfgimpl_get_path())
if option.impl_is_optiondescription():
return _TiramisuOptionOptionDescription(name=name, return _TiramisuOptionOptionDescription(name=name,
subconfig=subconfig, subconfig=subconfig,
option_bag=option_bag) option_bag=option_bag,
config=config)
else: else:
return _TiramisuOptionOption(name=name, return _TiramisuOptionOption(name=name,
subconfig=subconfig, subconfig=subconfig,
option_bag=option_bag) option_bag=option_bag,
config=config)
class TiramisuOptionOwner(CommonTiramisuOption): class TiramisuOptionOwner(CommonTiramisuOption):
@ -309,7 +328,8 @@ class TiramisuOptionOwner(CommonTiramisuOption):
def __init__(self, def __init__(self,
name: str, name: str,
subconfig: Union[KernelConfig, SubConfig], subconfig: Union[KernelConfig, SubConfig],
option_bag: OptionBag) -> None: option_bag: OptionBag,
config: Optional['SubConfig']) -> None:
super().__init__(name, super().__init__(name,
subconfig, subconfig,
@ -348,7 +368,8 @@ class TiramisuOptionProperty(CommonTiramisuOption):
def __init__(self, def __init__(self,
name: str, name: str,
subconfig: Union[KernelConfig, SubConfig], subconfig: Union[KernelConfig, SubConfig],
option_bag: OptionBag) -> None: option_bag: OptionBag,
config: Optional['SubConfig']) -> None:
super().__init__(name, super().__init__(name,
subconfig, subconfig,
option_bag) option_bag)
@ -359,14 +380,11 @@ class TiramisuOptionProperty(CommonTiramisuOption):
only_raises=False): only_raises=False):
"""Get properties for an option""" """Get properties for an option"""
option = self._option_bag.option option = self._option_bag.option
self._test_follower_index() #self._test_follower_index()
properties = self._option_bag.properties
if not only_raises: if not only_raises:
return properties return self._option_bag.properties
# do not check cache properties/permissives which are not save (unrestraint, ...) # do not check cache properties/permissives which are not save (unrestraint, ...)
return self._settings.calc_raises_properties(properties, return self._settings.calc_raises_properties(self._option_bag)
self._settings.get_context_properties(),
self._settings.get_context_properties())
def add(self, prop): def add(self, prop):
"""Add new property for an option""" """Add new property for an option"""
@ -406,7 +424,8 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
def __init__(self, def __init__(self,
name: str, name: str,
subconfig: Union[KernelConfig, SubConfig], subconfig: Union[KernelConfig, SubConfig],
option_bag: OptionBag) -> None: option_bag: OptionBag,
config: Optional['SubConfig']) -> None:
super().__init__(name, super().__init__(name,
subconfig, subconfig,
option_bag) option_bag)
@ -511,6 +530,17 @@ class _TiramisuOptionValueOption:
else: else:
return values.getdefaultvalue(self._option_bag) return values.getdefaultvalue(self._option_bag)
def valid(self):
try:
with warnings.catch_warnings(record=True) as warns:
self.get()
for warn in warns:
if isinstance(warns.message, ValueErrorWarning):
return False
except ValueError:
return False
return True
class _TiramisuOptionValueLeader: class _TiramisuOptionValueLeader:
def pop(self, index): def pop(self, index):
@ -552,8 +582,14 @@ class _TiramisuOptionValueChoiceOption:
option = self._option_bag.option option = self._option_bag.option
return option.impl_get_values(self._option_bag) return option.impl_get_values(self._option_bag)
def callbacks(self):
"""Get callbacks for a values"""
option = self._option_bag.option
return option.get_callback()
class _TiramisuOptionValueOptionDescription: class _TiramisuOptionValueOptionDescription:
def dict(self, def dict(self,
flatten=False, flatten=False,
withvalue=undefined, withvalue=undefined,
@ -583,32 +619,35 @@ class TiramisuOptionValue(CommonTiramisuOption):
def __new__(cls, def __new__(cls,
name, name,
subconfig, subconfig,
option_bag): option_bag,
if subconfig is not None: config):
types = [CommonTiramisuOption]
if option_bag.option and option_bag.option.impl_is_optiondescription():
types.append(_TiramisuOptionValueOptionDescription)
elif subconfig is not None:
option = subconfig.cfgimpl_get_description().get_child(name, option = subconfig.cfgimpl_get_description().get_child(name,
option_bag.config_bag, option_bag.config_bag,
subconfig.cfgimpl_get_path()) subconfig.cfgimpl_get_path())
else: types.append(_TiramisuOptionValueOption)
option = None if isinstance(option, ChoiceOption):
types = [CommonTiramisuOption] types.append(_TiramisuOptionValueChoiceOption)
if option: if option.impl_is_leader():
if option.impl_is_optiondescription(): types.append(_TiramisuOptionValueLeader)
types.append(_TiramisuOptionValueOptionDescription) elif option.impl_is_follower():
else: types.append(_TiramisuOptionValueFollower)
types.append(_TiramisuOptionValueOption)
if isinstance(option, ChoiceOption):
types.append(_TiramisuOptionValueChoiceOption)
if option.impl_is_leader():
types.append(_TiramisuOptionValueLeader)
elif option.impl_is_follower():
types.append(_TiramisuOptionValueFollower)
if option_bag.config_bag.context.impl_type == 'group': if option_bag.config_bag.context.impl_type == 'group':
types.append(_TiramisuOptionValueGroup) types.append(_TiramisuOptionValueGroup)
new_type_dict = {'_allow_optiondescription': cls._allow_optiondescription, new_type_dict = {'_allow_optiondescription': cls._allow_optiondescription,
'_follower_need_index': cls._follower_need_index} '_follower_need_index': cls._follower_need_index}
new_type = type('TiramisuOptionValue', tuple(types), new_type_dict)(name=name, if option_bag.option and option_bag.option.impl_is_optiondescription():
subconfig=subconfig, new_type = type('TiramisuOptionValue', tuple(types), new_type_dict)(name=name,
option_bag=option_bag) subconfig=subconfig,
option_bag=option_bag,
config=config)
else:
new_type = type('TiramisuOptionValue', tuple(types), new_type_dict)(name=name,
subconfig=subconfig,
option_bag=option_bag)
new_type.__doc__ = cls.__doc__ new_type.__doc__ = cls.__doc__
return new_type return new_type
@ -625,6 +664,7 @@ def _registers(_registers: Dict[str, type],
class _TiramisuOption(CommonTiramisu): class _TiramisuOption(CommonTiramisu):
"""Manage selected option""" """Manage selected option"""
_validate_properties = False
_registers = {} _registers = {}
def __init__(self, def __init__(self,
name: Optional[str], name: Optional[str],
@ -642,14 +682,30 @@ class _TiramisuOption(CommonTiramisu):
self._option_bag.index = self._index self._option_bag.index = self._index
self._option_bag.config_bag = self._config_bag self._option_bag.config_bag = self._config_bag
self._tiramisu_dict = None self._tiramisu_dict = None
self._config = None
if not self._registers: if not self._registers:
_registers(self._registers, 'TiramisuOption') _registers(self._registers, 'TiramisuOption')
def _get_config(self):
if self._config is None and self._subconfig is not None:
self._config = self._subconfig.get_subconfig(self._option_bag)
return self._config
def __getattr__(self, subfunc: str) -> Any: def __getattr__(self, subfunc: str) -> Any:
if subfunc in self._registers: if subfunc in self._registers:
subconfig = self._subconfig
if subconfig:
option = self._get_option()
if option.impl_is_optiondescription() and subfunc == 'option':
config = self._get_config()
else:
config = None
else:
config = None
return self._registers[subfunc](self._name, return self._registers[subfunc](self._name,
self._subconfig, subconfig,
self._option_bag) self._option_bag,
config)
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) # pragma: no cover raise APIError(_('please specify a valid sub function ({})').format(subfunc)) # pragma: no cover
@ -694,52 +750,54 @@ class _TiramisuOptionDescription(_TiramisuOption):
def _filter(self, def _filter(self,
opt, opt,
subconfig): subconfig,
if self._config_bag.properties: config_bag):
name = opt.impl_getname() option_bag = OptionBag()
path = subconfig._get_subpath(name) option_bag.set_option(opt,
option_bag = OptionBag() opt.impl_getpath(),
option_bag.set_option(opt, None,
path, config_bag)
None, if opt.impl_is_optiondescription():
self._config_bag) config_bag.context.cfgimpl_get_settings().validate_properties(option_bag)
if opt.impl_is_optiondescription(): return subconfig.get_subconfig(option_bag)
self._subconfig.get_subconfig(option_bag) subconfig.getattr(opt.impl_getname(),
else: option_bag)
subconfig.getattr(name,
option_bag)
def list(self, def list(self,
type='option', type='option',
group_type=None): group_type=None):
"""List options in an optiondescription (only for optiondescription)""" """List options (by default list only option)"""
assert type in ('all', 'option', 'optiondescription'), _('unknown list type {}').format(type) assert type in ('all', 'option', 'optiondescription'), _('unknown list type {}').format(type)
assert group_type is None or isinstance(group_type, groups.GroupType), \ assert group_type is None or isinstance(group_type, groups.GroupType), \
_("unknown group_type: {0}").format(group_type) _("unknown group_type: {0}").format(group_type)
config_bag = self._config_bag
if config_bag.properties and 'warnings' in config_bag.properties:
config_bag = config_bag.copy()
config_bag.remove_warnings()
option = self._get_option() option = self._get_option()
name = option.impl_getname()
path = self._subconfig._get_subpath(name)
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(option, option_bag.set_option(option,
path, option.impl_getpath(),
None, None,
self._config_bag) config_bag)
subconfig = self._subconfig.get_subconfig(option_bag) subconfig = self._subconfig.get_subconfig(option_bag)
for opt in option.get_children(self._config_bag): for opt in option.get_children(config_bag):
try: try:
self._filter(opt, self._filter(opt,
subconfig) subconfig,
config_bag)
except PropertiesOptionError: except PropertiesOptionError:
continue continue
if opt.impl_is_optiondescription(): if opt.impl_is_optiondescription():
if type == 'option' or (type == 'optiondescription' and group_type and \ if type == 'option' or (type == 'optiondescription' and \
opt.impl_get_group_type() != group_type): group_type and opt.impl_get_group_type() != group_type):
continue continue
elif type == 'optiondescription': elif type == 'optiondescription':
continue continue
name = opt.impl_getname() name = opt.impl_getname()
path = opt.impl_getpath()
yield TiramisuOption(name, yield TiramisuOption(name,
subconfig._get_subpath(name), path,
None, None,
subconfig, subconfig,
self._config_bag) self._config_bag)
@ -747,9 +805,10 @@ class _TiramisuOptionDescription(_TiramisuOption):
def dict(self, def dict(self,
clearable: str="all", clearable: str="all",
remotable: str="minimum", remotable: str="minimum",
form: List=[]) -> Dict: form: List=[],
force: bool=False) -> Dict:
"""convert config and option to tiramisu format""" """convert config and option to tiramisu format"""
if self._tiramisu_dict is None: if force or self._tiramisu_dict is None:
option = self._get_option() option = self._get_option()
name = option.impl_getname() name = option.impl_getname()
root = self._subconfig._get_subpath(name) root = self._subconfig._get_subpath(name)
@ -777,9 +836,13 @@ class TiramisuOption(CommonTiramisuOption):
subconfig: Union[None, KernelConfig, SubConfig]=None, subconfig: Union[None, KernelConfig, SubConfig]=None,
config_bag: Optional[ConfigBag]=None) -> None: config_bag: Optional[ConfigBag]=None) -> None:
if subconfig: if subconfig:
# not for groupconfig
if '.' in name:
subconfig, name = config_bag.context.cfgimpl_get_home_by_path(path,
config_bag)
option = subconfig.cfgimpl_get_description().get_child(name, option = subconfig.cfgimpl_get_description().get_child(name,
config_bag, config_bag,
subconfig.cfgimpl_get_path()) subconfig.cfgimpl_get_path())
if option.impl_is_optiondescription(): if option.impl_is_optiondescription():
return _TiramisuOptionDescription(name=name, return _TiramisuOptionDescription(name=name,
path=path, path=path,
@ -1022,8 +1085,8 @@ class TiramisuContextProperty(TiramisuContext):
properties: Set[str], properties: Set[str],
type: Optional[str]=None, type: Optional[str]=None,
when: Optional[str]=None) -> None: when: Optional[str]=None) -> None:
if not isinstance(properties, set): if not isinstance(properties, frozenset):
raise TypeError(_('properties must be a set')) raise TypeError(_('properties must be a frozenset'))
setting = self._config_bag.context.cfgimpl_get_settings() setting = self._config_bag.context.cfgimpl_get_settings()
if type is None and when is None: if type is None and when is None:
setting.default_properties = properties setting.default_properties = properties
@ -1174,13 +1237,12 @@ class TiramisuContextOption(TiramisuContext):
continue continue
if opt.impl_is_optiondescription(): if opt.impl_is_optiondescription():
if recursive: if recursive:
for toption in self._walk(opt, yield from self._walk(opt,
recursive, recursive,
type_, type_,
group_type, group_type,
config_bag, config_bag,
subsubconfig): subsubconfig)
yield toption
if type_ == 'option' or (type_ == 'optiondescription' and \ if type_ == 'option' or (type_ == 'optiondescription' and \
group_type and opt.impl_get_group_type() != group_type): group_type and opt.impl_get_group_type() != group_type):
continue continue
@ -1207,20 +1269,20 @@ class TiramisuContextOption(TiramisuContext):
config_bag = config_bag.copy() config_bag = config_bag.copy()
config_bag.remove_warnings() config_bag.remove_warnings()
option = config_bag.context.cfgimpl_get_description() option = config_bag.context.cfgimpl_get_description()
for toption in self._walk(option, yield from self._walk(option,
recursive, recursive,
type, type,
group_type, group_type,
config_bag, config_bag,
config_bag.context): config_bag.context)
yield toption
def dict(self, def dict(self,
clearable="all", clearable="all",
remotable="minimum", remotable="minimum",
form=[]): form=[],
force=False):
"""convert config and option to tiramisu format""" """convert config and option to tiramisu format"""
if self._tiramisu_dict is None: if force or self._tiramisu_dict is None:
self._tiramisu_dict = TiramisuDict(Config(self._config_bag.context), self._tiramisu_dict = TiramisuDict(Config(self._config_bag.context),
root=None, root=None,
clearable=clearable, clearable=clearable,
@ -1240,7 +1302,7 @@ class _TiramisuContextConfigReset():
"""Remove all datas to current config (informations, values, properties, ...)""" """Remove all datas to current config (informations, values, properties, ...)"""
# Option's values # Option's values
context_owner = self._config_bag.context.cfgimpl_get_values().get_context_owner() context_owner = self._config_bag.context.cfgimpl_get_values().get_context_owner()
self._config_bag.context.cfgimpl_get_values()._p_.importation((tuple(), tuple(), tuple(), tuple())) self._config_bag.context.cfgimpl_get_values()._p_.importation(([], [], [], []))
self._config_bag.context.cfgimpl_get_values()._p_.setvalue(None, self._config_bag.context.cfgimpl_get_values()._p_.setvalue(None,
None, None,
context_owner, context_owner,
@ -1454,14 +1516,16 @@ class Config(TiramisuAPI):
descr: OptionDescription, descr: OptionDescription,
session_id: str=None, session_id: str=None,
persistent: bool=False, persistent: bool=False,
storage=None) -> None: storage=None,
display_name=None) -> None:
if isinstance(descr, KernelConfig): if isinstance(descr, KernelConfig):
config = descr config = descr
else: else:
config = KernelConfig(descr, config = KernelConfig(descr,
session_id=session_id, session_id=session_id,
persistent=persistent, persistent=persistent,
storage=storage) storage=storage,
display_name=display_name)
super().__init__(config) super().__init__(config)
@ -1471,7 +1535,8 @@ class MetaConfig(TiramisuAPI):
children, children,
session_id: Union[str, None]=None, session_id: Union[str, None]=None,
persistent: bool=False, persistent: bool=False,
optiondescription: Optional[OptionDescription]=None) -> None: optiondescription: Optional[OptionDescription]=None,
display_name=None) -> None:
if isinstance(children, KernelMetaConfig): if isinstance(children, KernelMetaConfig):
config = children config = children
else: else:
@ -1485,7 +1550,8 @@ class MetaConfig(TiramisuAPI):
config = KernelMetaConfig(_children, config = KernelMetaConfig(_children,
session_id=session_id, session_id=session_id,
persistent=persistent, persistent=persistent,
optiondescription=optiondescription) optiondescription=optiondescription,
display_name=display_name)
super().__init__(config) super().__init__(config)
@ -1495,7 +1561,8 @@ class MixConfig(TiramisuAPI):
optiondescription: OptionDescription, optiondescription: OptionDescription,
children: List[Config], children: List[Config],
session_id: Optional[str]=None, session_id: Optional[str]=None,
persistent: bool=False) -> None: persistent: bool=False,
display_name: Callable=None) -> None:
if isinstance(children, KernelMixConfig): if isinstance(children, KernelMixConfig):
config = children config = children
else: else:
@ -1509,7 +1576,8 @@ class MixConfig(TiramisuAPI):
config = KernelMixConfig(optiondescription, config = KernelMixConfig(optiondescription,
_children, _children,
session_id=session_id, session_id=session_id,
persistent=persistent) persistent=persistent,
display_name=display_name)
super().__init__(config) super().__init__(config)

View File

@ -43,7 +43,7 @@ def manager_callback(callbk: Union[ParamOption, ParamValue],
if config_bag is undefined: if config_bag is undefined:
return undefined return undefined
if isinstance(callbk, ParamContext): if isinstance(callbk, ParamContext):
#Not an option, set full context # Not an option, set full context
return config_bag.context.duplicate(force_values=get_default_values_storages(), return config_bag.context.duplicate(force_values=get_default_values_storages(),
force_settings=get_default_settings_storages()) force_settings=get_default_settings_storages())
opt = callbk.option opt = callbk.option
@ -254,18 +254,20 @@ def carry_out_calculation(option,
if isinstance(ret, list) and not option.impl_is_dynoptiondescription() and \ if isinstance(ret, list) and not option.impl_is_dynoptiondescription() and \
option.impl_is_follower(): option.impl_is_follower():
if args or kwargs: if args or kwargs:
raise LeadershipError(_('function "{}" with arguments "{}" and "{}" ' raise LeadershipError(_('the "{}" function with positional arguments "{}" '
'return the list "{}" for the follower option "{}"' 'and keyword arguments "{}" must not return '
'a list ("{}") for the follower option "{}"'
'').format(callback.__name__, '').format(callback.__name__,
args, args,
kwargs, kwargs,
ret, ret,
option.impl_get_display_name())) option.impl_get_display_name()))
else: else:
raise LeadershipError(_('function "{}" return the list "{}" for the follower option "{}"' raise LeadershipError(_('the "{}" function must not return a list ("{}") '
'for the follower option "{}"'
'').format(callback.__name__, '').format(callback.__name__,
ret, ret,
option.impl_getname())) option.impl_get_display_name()))
return ret return ret

View File

@ -249,7 +249,7 @@ class SubConfig(object):
_commit=True): _commit=True):
option = option_bag.option option = option_bag.option
if option.impl_is_symlinkoption(): if option.impl_is_symlinkoption():
raise TypeError(_("can't delete a SymLinkOption")) raise ConfigError(_("can't delete a SymLinkOption"))
values = self.cfgimpl_get_values() values = self.cfgimpl_get_values()
if option_bag.index is not None: if option_bag.index is not None:
values.reset_follower(option_bag, values.reset_follower(option_bag,
@ -281,7 +281,8 @@ class SubConfig(object):
def getattr(self, def getattr(self,
name, name,
option_bag): option_bag,
from_follower=False):
""" """
attribute notation mechanism for accessing the value of an option attribute notation mechanism for accessing the value of an option
:param name: attribute name :param name: attribute name
@ -310,17 +311,18 @@ class SubConfig(object):
return context.getattr(soption_bag.path, return context.getattr(soption_bag.path,
soption_bag) soption_bag)
self.cfgimpl_get_settings().validate_properties(option_bag) if not from_follower or option_bag.option.impl_getrequires():
self.cfgimpl_get_settings().validate_properties(option_bag)
if option.impl_is_follower(): if option.impl_is_follower() and not from_follower:
length = self.cfgimpl_get_length_leadership(option_bag) length = self.cfgimpl_get_length_leadership(option_bag)
follower_len = self.cfgimpl_get_values()._p_.get_max_length(option_bag.path) follower_len = self.cfgimpl_get_values()._p_.get_max_length(option_bag.path)
if follower_len > length: if follower_len > length:
raise LeadershipError(_('follower option "{}" has higher length "{}" than the leader ' raise LeadershipError(_('the follower option "{}" has greater length ({}) than the leader '
'length "{}"').format(option.impl_get_display_name(), 'length ({})').format(option.impl_get_display_name(),
follower_len, follower_len,
length, length,
option_bag.index)) option_bag.index))
if option.impl_is_follower() and option_bag.index is None: if option.impl_is_follower() and option_bag.index is None:
value = [] value = []
for idx in range(length): for idx in range(length):
@ -332,7 +334,8 @@ class SubConfig(object):
soption_bag.fromconsistency = option_bag.fromconsistency.copy() soption_bag.fromconsistency = option_bag.fromconsistency.copy()
try: try:
value.append(self.getattr(name, value.append(self.getattr(name,
soption_bag)) soption_bag,
from_follower=True))
except PropertiesOptionError as err: except PropertiesOptionError as err:
value.append(err) value.append(err)
else: else:
@ -612,7 +615,7 @@ class _CommonConfig(SubConfig):
def _impl_build_all_caches(self): def _impl_build_all_caches(self):
descr = self.cfgimpl_get_description() descr = self.cfgimpl_get_description()
if not descr.impl_already_build_caches(): if not descr.impl_already_build_caches():
descr._build_cache() descr._build_cache(display_name=self._display_name)
config_bag = ConfigBag(context=self) config_bag = ConfigBag(context=self)
descr.impl_build_force_store_values(config_bag) descr.impl_build_force_store_values(config_bag)
@ -649,7 +652,8 @@ class _CommonConfig(SubConfig):
fake_config = KernelConfig(self._impl_descr, fake_config = KernelConfig(self._impl_descr,
persistent=False, persistent=False,
force_values=get_default_values_storages(), force_values=get_default_values_storages(),
force_settings=self.cfgimpl_get_settings()) force_settings=self.cfgimpl_get_settings(),
display_name=self._display_name)
fake_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation()) fake_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
return fake_config return fake_config
@ -670,7 +674,8 @@ class _CommonConfig(SubConfig):
force_values=force_values, force_values=force_values,
force_settings=force_settings, force_settings=force_settings,
persistent=persistent, persistent=persistent,
storage=storage) storage=storage,
display_name=self._display_name)
else: else:
if session_id is None and metaconfig_prefix is not None: if session_id is None and metaconfig_prefix is not None:
session_id = metaconfig_prefix + self.impl_getname() session_id = metaconfig_prefix + self.impl_getname()
@ -679,12 +684,18 @@ class _CommonConfig(SubConfig):
optiondescription=self._impl_descr, optiondescription=self._impl_descr,
session_id=session_id, session_id=session_id,
persistent=persistent, persistent=persistent,
storage=storage) storage=storage,
display_name=self._display_name)
duplicated_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation()) duplicated_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
properties = self.cfgimpl_get_settings()._p_.exportation() properties = self.cfgimpl_get_settings()._p_.exportation()
duplicated_config.cfgimpl_get_settings()._p_.importation(properties) duplicated_config.cfgimpl_get_settings()._p_.importation(properties)
duplicated_config.cfgimpl_get_settings()._pp_.importation(self.cfgimpl_get_settings( duplicated_config.cfgimpl_get_settings()._pp_.importation(self.cfgimpl_get_settings(
)._pp_.exportation()) )._pp_.exportation())
duplicated_config.cfgimpl_get_settings().ro_append = self.cfgimpl_get_settings().ro_append
duplicated_config.cfgimpl_get_settings().rw_append = self.cfgimpl_get_settings().rw_append
duplicated_config.cfgimpl_get_settings().ro_remove = self.cfgimpl_get_settings().ro_remove
duplicated_config.cfgimpl_get_settings().rw_remove = self.cfgimpl_get_settings().rw_remove
duplicated_config.cfgimpl_get_settings().default_properties = self.cfgimpl_get_settings().default_properties
duplicated_config.cfgimpl_reset_cache(None, None) duplicated_config.cfgimpl_reset_cache(None, None)
if child is not None: if child is not None:
duplicated_config._impl_children.append(child) duplicated_config._impl_children.append(child)
@ -706,7 +717,8 @@ class _CommonConfig(SubConfig):
class KernelConfig(_CommonConfig): class KernelConfig(_CommonConfig):
"main configuration management entry" "main configuration management entry"
__slots__ = ('__weakref__', __slots__ = ('__weakref__',
'_impl_name') '_impl_name',
'_display_name')
impl_type = 'config' impl_type = 'config'
def __init__(self, def __init__(self,
@ -715,6 +727,7 @@ class KernelConfig(_CommonConfig):
persistent=False, persistent=False,
force_values=None, force_values=None,
force_settings=None, force_settings=None,
display_name=None,
_duplicate=False, _duplicate=False,
storage=None): storage=None):
""" Configuration option management class """ Configuration option management class
@ -730,6 +743,7 @@ class KernelConfig(_CommonConfig):
:type persistent: `boolean` :type persistent: `boolean`
""" """
self._impl_meta = None self._impl_meta = None
self._display_name = display_name
if isinstance(descr, Leadership): if isinstance(descr, Leadership):
raise ConfigError(_('cannot set leadership object has root optiondescription')) raise ConfigError(_('cannot set leadership object has root optiondescription'))
if isinstance(descr, DynOptionDescription): if isinstance(descr, DynOptionDescription):
@ -968,7 +982,7 @@ class KernelGroupConfig(_CommonConfig):
class KernelMixConfig(KernelGroupConfig): class KernelMixConfig(KernelGroupConfig):
__slots__ = tuple() __slots__ = ('_display_name',)
impl_type = 'mix' impl_type = 'mix'
def __init__(self, def __init__(self,
@ -977,8 +991,10 @@ class KernelMixConfig(KernelGroupConfig):
session_id=None, session_id=None,
persistent=False, persistent=False,
storage=None, storage=None,
display_name=None,
_duplicate=False): _duplicate=False):
# FIXME _duplicate # FIXME _duplicate
self._display_name = display_name
for child in children: for child in children:
if not isinstance(child, _CommonConfig): if not isinstance(child, _CommonConfig):
try: try:
@ -1202,8 +1218,10 @@ class KernelMetaConfig(KernelMixConfig):
persistent=False, persistent=False,
optiondescription=None, optiondescription=None,
storage=None, storage=None,
display_name=None,
_duplicate=False): _duplicate=False):
descr = None descr = None
self._display_name = display_name
if optiondescription is not None: if optiondescription is not None:
if not _duplicate: if not _duplicate:
new_children = [] new_children = []
@ -1213,7 +1231,8 @@ class KernelMetaConfig(KernelMixConfig):
'not {}').format(child_session_id) 'not {}').format(child_session_id)
new_children.append(KernelConfig(optiondescription, new_children.append(KernelConfig(optiondescription,
persistent=persistent, persistent=persistent,
session_id=child_session_id)) session_id=child_session_id,
display_name=self._display_name))
children = new_children children = new_children
descr = optiondescription descr = optiondescription
for child in children: for child in children:
@ -1251,21 +1270,29 @@ class KernelMetaConfig(KernelMixConfig):
if type_ == 'config': if type_ == 'config':
config = KernelConfig(self._impl_descr, config = KernelConfig(self._impl_descr,
session_id=session_id, session_id=session_id,
persistent=persistent) persistent=persistent,
display_name=self._display_name)
elif type_ == 'metaconfig': elif type_ == 'metaconfig':
config = KernelMetaConfig([], config = KernelMetaConfig([],
optiondescription=self._impl_descr, optiondescription=self._impl_descr,
session_id=session_id, session_id=session_id,
persistent=persistent) persistent=persistent,
display_name=self._display_name)
elif type_ == 'mixconfig': elif type_ == 'mixconfig':
config = KernelMixConfig(children=[], config = KernelMixConfig(children=[],
optiondescription=self._impl_descr, optiondescription=self._impl_descr,
session_id=session_id, session_id=session_id,
persistent=persistent) persistent=persistent,
display_name=self._display_name)
# Copy context properties/permissives # Copy context properties/permissives
if new: if new:
config.cfgimpl_get_settings().set_context_properties(self.cfgimpl_get_settings().get_context_properties(), config) config.cfgimpl_get_settings().set_context_properties(self.cfgimpl_get_settings().get_context_properties(), config)
config.cfgimpl_get_settings().set_context_permissives(self.cfgimpl_get_settings().get_context_permissives()) config.cfgimpl_get_settings().set_context_permissives(self.cfgimpl_get_settings().get_context_permissives())
config.cfgimpl_get_settings().ro_append = self.cfgimpl_get_settings().ro_append
config.cfgimpl_get_settings().rw_append = self.cfgimpl_get_settings().rw_append
config.cfgimpl_get_settings().ro_remove = self.cfgimpl_get_settings().ro_remove
config.cfgimpl_get_settings().rw_remove = self.cfgimpl_get_settings().rw_remove
config.cfgimpl_get_settings().default_properties = self.cfgimpl_get_settings().default_properties
config._impl_meta = weakref.ref(self) config._impl_meta = weakref.ref(self)
self._impl_children.append(config) self._impl_children.append(config)

View File

@ -78,15 +78,17 @@ class PropertiesOptionError(AttributeError):
self.proptype = proptype self.proptype = proptype
self._settings = settings self._settings = settings
self.msg = None self.msg = None
super(PropertiesOptionError, self).__init__(None) super().__init__(None)
def set_orig_opt(self, opt): def set_orig_opt(self, opt):
self._orig_opt = opt self._orig_opt = opt
def __str__(self): def __str__(self):
#this part is a bit slow, so only execute when display #this part is a bit slow, so only execute when display
if self.msg: if self.msg is not None:
return self.msg return self.msg
if self._settings is None:
return 'error'
req = self._settings.apply_requires(self._option_bag, req = self._settings.apply_requires(self._option_bag,
True) True)
#if req != {} or self._orig_opt is not None: #if req != {} or self._orig_opt is not None:
@ -168,6 +170,7 @@ class _CommonError:
self.val = val self.val = val
self.display_type = display_type self.display_type = display_type
self.opt = weakref.ref(opt) self.opt = weakref.ref(opt)
self.name = opt.impl_get_display_name()
self.err_msg = err_msg self.err_msg = err_msg
self.index = index self.index = index
super().__init__(self.err_msg) super().__init__(self.err_msg)
@ -178,7 +181,7 @@ class _CommonError:
except AttributeError: except AttributeError:
self.prefix = self.tmpl.format(self.val, self.prefix = self.tmpl.format(self.val,
self.display_type, self.display_type,
self.opt().impl_get_display_name()) self.name)
msg = self.prefix msg = self.prefix
if self.err_msg: if self.err_msg:
if msg: if msg:

View File

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Tiramisu\n" "Project-Id-Version: Tiramisu\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-13 21:34+CEST\n" "POT-Creation-Date: 2019-07-26 09:35+CEST\n"
"PO-Revision-Date: \n" "PO-Revision-Date: \n"
"Last-Translator: Emmanuel Garette <egarette@cadoles.com>\n" "Last-Translator: Emmanuel Garette <egarette@cadoles.com>\n"
"Language-Team: Tiramisu's team <egarette@cadoles.com>\n" "Language-Team: Tiramisu's team <egarette@cadoles.com>\n"
@ -10,7 +10,7 @@ msgstr ""
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.1\n" "X-Generator: Poedit 2.2.3\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-SourceCharset: UTF-8\n"
@ -36,56 +36,60 @@ msgstr "Commandes :"
#: tiramisu/api.py:104 #: tiramisu/api.py:104
msgid "" msgid ""
"index \"{}\" is higher than the leadership length \"{}\" for option \"{}\"" "index \"{}\" is greater than the leadership length \"{}\" for option \"{}\""
msgstr "" msgstr ""
"l'index \"{}\" est supérieur à la longueur de l'option leadership \"{}\" " "l'index \"{}\" est supérieur à la longueur de la leadership \"{}\" pour "
"pour l'option \"{}\"" "l'option \"{}\""
#: tiramisu/api.py:109 #: tiramisu/api.py:109
msgid "option must not be an optiondescription" msgid "option must not be an optiondescription"
msgstr "option ne doit pas être une optiondescription" msgstr "option ne doit pas être une optiondescription"
#: tiramisu/api.py:136 #: tiramisu/api.py:137
msgid "index must be set with the follower option \"{}\"" msgid "index must be set with the follower option \"{}\""
msgstr "l'index est obligatoire pour l'option suiveuse \"{}\"" msgstr "l'index est obligatoire pour l'option suiveuse \"{}\""
#: tiramisu/api.py:139 #: tiramisu/api.py:140
msgid "unknown method {}" msgid "unknown method {} in {}"
msgstr "méthode {} inconnue" msgstr "méthode {} inconnue dans {}"
#: tiramisu/api.py:361 #: tiramisu/api.py:393
msgid "cannot add this property: \"{0}\"" msgid "cannot add this property: \"{0}\""
msgstr "ne peut pas ajouter cette propriété : \"{0}\"" msgstr "ne peut pas ajouter cette propriété : \"{0}\""
#: tiramisu/api.py:505 tiramisu/config.py:252 #: tiramisu/api.py:549 tiramisu/config.py:252
msgid "can't delete a SymLinkOption" msgid "can't delete a SymLinkOption"
msgstr "ne peut supprimer une valeur à une SymLinkOption" msgstr "ne peut supprimer une valeur à une SymLinkOption"
#: tiramisu/api.py:639 tiramisu/api.py:1375 #: tiramisu/api.py:709 tiramisu/api.py:1487
msgid "please specify a valid sub function ({})" msgid "please specify a valid sub function ({})"
msgstr "veuillez spécifier une sous fonction valide ({})" msgstr "veuillez spécifier une sous fonction valide ({})"
#: tiramisu/api.py:702 tiramisu/api.py:1176 #: tiramisu/api.py:770 tiramisu/api.py:1264
msgid "unknown list type {}" msgid "unknown list type {}"
msgstr "type de liste inconnue {}" msgstr "type de liste inconnue {}"
#: tiramisu/api.py:704 tiramisu/api.py:1178 #: tiramisu/api.py:772 tiramisu/api.py:1266
msgid "unknown group_type: {0}" msgid "unknown group_type: {0}"
msgstr "group_type inconnu: {0}" msgstr "group_type inconnu: {0}"
#: tiramisu/api.py:753 tiramisu/api.py:1208 #: tiramisu/api.py:826 tiramisu/api.py:1296
msgid "please use .dict() before .updates()" msgid "please use .dict() before .updates()"
msgstr "faire .dico() avant .updates()" msgstr "faire .dict() avant .updates()"
#: tiramisu/api.py:1000 #: tiramisu/api.py:878
msgid "properties must be a set" msgid "unknown config type {}"
msgstr "une propriété doit être de type set" msgstr "type de config {} inconnue"
#: tiramisu/api.py:1006 tiramisu/api.py:1028 #: tiramisu/api.py:1089
msgid "properties must be a frozenset"
msgstr "une propriété doit être de type frozenset"
#: tiramisu/api.py:1095 tiramisu/api.py:1117
msgid "unknown when {} (must be in append or remove)" msgid "unknown when {} (must be in append or remove)"
msgstr "value {} inconsistent (doit être append ou remove)" msgstr "value {} inconsistent (doit être append ou remove)"
#: tiramisu/api.py:1018 tiramisu/api.py:1040 tiramisu/config.py:1249 #: tiramisu/api.py:1107 tiramisu/api.py:1129 tiramisu/config.py:1268
msgid "unknown type {}" msgid "unknown type {}"
msgstr "type inconnu {}" msgstr "type inconnu {}"
@ -95,18 +99,22 @@ msgstr "impossible d'effectuer le calcul pour \"{}\", {}"
#: tiramisu/autolib.py:257 #: tiramisu/autolib.py:257
msgid "" msgid ""
"function \"{}\" with arguments \"{}\" and \"{}\" return the list \"{}\" for " "the \"{}\" function with positional arguments \"{}\" and keyword arguments "
"the follower option \"{}\"" "\"{}\" must not return a list (\"{}\") for the follower option \"{}\""
msgstr "" msgstr ""
"la fonction \"{}\" avec les arguments \"{}\" et \"{}\" retourne la liste " "la fonction \"{}\" avec les arguments positionnels \"{}\" et les arguments "
"\"{}\" pour l'option suiveuse \"{}\"" "nommés \"{}\" ne doit pas retourner une liste (\"{}\") pour l'option "
"suiveuse \"{}\""
#: tiramisu/autolib.py:265 #: tiramisu/autolib.py:266
msgid "function \"{}\" return the list \"{}\" for the follower option \"{}\"" msgid ""
"the \"{}\" function must not return a list (\"{}\") for the follower option "
"\"{}\""
msgstr "" msgstr ""
"fonction \"{}\" retourne une liste \"{}\" pour l'option suiveuse \"{}\"" "la fonction \"{}\" ne doit pas retourner une liste (\"{}\") pour l'option "
"suiveuse \"{}\""
#: tiramisu/autolib.py:293 #: tiramisu/autolib.py:295
msgid "" msgid ""
"unexpected error \"{0}\" in function \"{1}\" with arguments \"{3}\" and " "unexpected error \"{0}\" in function \"{1}\" with arguments \"{3}\" and "
"\"{4}\" for option \"{2}\"" "\"{4}\" for option \"{2}\""
@ -114,7 +122,7 @@ msgstr ""
"erreur inattendue \"{0}\" dans la fonction \"{1}\" avec les arguments " "erreur inattendue \"{0}\" dans la fonction \"{1}\" avec les arguments "
"\"{3}\" et \"{4}\" pour l'option \"{2}\"" "\"{3}\" et \"{4}\" pour l'option \"{2}\""
#: tiramisu/autolib.py:300 #: tiramisu/autolib.py:302
msgid "unexpected error \"{0}\" in function \"{1}\" for option \"{2}\"" msgid "unexpected error \"{0}\" in function \"{1}\" for option \"{2}\""
msgstr "" msgstr ""
"erreur inattendue \"{0}\" dans la fonction \"{1}\" pour l'option \"{2}\"" "erreur inattendue \"{0}\" dans la fonction \"{1}\" pour l'option \"{2}\""
@ -141,73 +149,74 @@ msgstr "ne peut assigner une valeur à une SymLinkOption"
msgid "cannot reduce length of a leader \"{}\"" msgid "cannot reduce length of a leader \"{}\""
msgstr "il est impossible de réduire la longueur de l'option leader \"{}\"" msgstr "il est impossible de réduire la longueur de l'option leader \"{}\""
#: tiramisu/config.py:319 #: tiramisu/config.py:321
msgid "" msgid ""
"follower option \"{}\" has higher length \"{}\" than the leader length \"{}\"" "the follower option \"{}\" has greater length ({}) than the leader length "
"({})"
msgstr "" msgstr ""
"l'option suiveuse \"{}\" a une longueur supérieur \"{}\" à la longueur de " "l'option suiveuse \"{}\" a une longueur supérieur ({}) à la longueur de "
"l'option leader \"{}\"" "l'option leader ({})"
#: tiramisu/config.py:415 #: tiramisu/config.py:418
msgid "no option found in config with these criteria" msgid "no option found in config with these criteria"
msgstr "aucune option trouvée dans la config avec ces critères" msgstr "aucune option trouvée dans la config avec ces critères"
#: tiramisu/config.py:465 #: tiramisu/config.py:468
msgid "make_dict can't filtering with value without option" msgid "make_dict can't filtering with value without option"
msgstr "make_dict ne peut filtrer sur une valeur mais sans option" msgstr "make_dict ne peut filtrer sur une valeur mais sans option"
#: tiramisu/config.py:518 #: tiramisu/config.py:521
msgid "unexpected path \"{0}\", should start with \"{1}\"" msgid "unexpected path \"{0}\", should start with \"{1}\""
msgstr "chemin inconsistant \"{0}\", devrait commencé par \"{1}\"" msgstr "chemin inconsistant \"{0}\", devrait commencé par \"{1}\""
#: tiramisu/config.py:665 #: tiramisu/config.py:669
msgid "cannot duplicate {}" msgid "cannot duplicate {}"
msgstr "ne peut dupliquer : {0}" msgstr "ne peut dupliquer : {0}"
#: tiramisu/config.py:734 #: tiramisu/config.py:748
msgid "cannot set leadership object has root optiondescription" msgid "cannot set leadership object has root optiondescription"
msgstr "ne peut assigner un objet leadership comme optiondescription racine" msgstr "ne peut assigner un objet leadership comme optiondescription racine"
#: tiramisu/config.py:736 #: tiramisu/config.py:750
msgid "cannot set dynoptiondescription object has root optiondescription" msgid "cannot set dynoptiondescription object has root optiondescription"
msgstr "" msgstr ""
"ne peut assigner un objet dynoptiondescription comme optiondescription racine" "ne peut assigner un objet dynoptiondescription comme optiondescription racine"
#: tiramisu/config.py:750 tiramisu/config.py:797 #: tiramisu/config.py:764 tiramisu/config.py:811
msgid "invalid session ID: {0} for config" msgid "invalid session ID: {0} for config"
msgstr "ID de session invalide : {0} pour une config" msgstr "ID de session invalide : {0} pour une config"
#: tiramisu/config.py:781 #: tiramisu/config.py:795
msgid "groupconfig's children must be a list" msgid "groupconfig's children must be a list"
msgstr "enfants d'une groupconfig doit être une liste" msgstr "enfants d'une groupconfig doit être une liste"
#: tiramisu/config.py:785 #: tiramisu/config.py:799
msgid "groupconfig's children must be Config, MetaConfig or GroupConfig" msgid "groupconfig's children must be Config, MetaConfig or GroupConfig"
msgstr "" msgstr ""
"les enfants d'un groupconfig doivent être des Config, MetaConfig ou " "les enfants d'un groupconfig doivent être des Config, MetaConfig ou "
"GroupConfig" "GroupConfig"
#: tiramisu/config.py:792 #: tiramisu/config.py:806
msgid "config name must be uniq in groupconfig for \"{0}\"" msgid "config name must be uniq in groupconfig for \"{0}\""
msgstr "le nom d'un config doit être unique dans un groupconfig pour \"{0}\"" msgstr "le nom d'un config doit être unique dans un groupconfig pour \"{0}\""
#: tiramisu/config.py:962 #: tiramisu/config.py:976
msgid "unknown config \"{}\"" msgid "unknown config \"{}\""
msgstr "config \"{}\" inconnue" msgstr "config \"{}\" inconnue"
#: tiramisu/config.py:987 tiramisu/config.py:1224 #: tiramisu/config.py:1003 tiramisu/config.py:1243
msgid "{}config's children should be config, not {}" msgid "{}config's children should be config, not {}"
msgstr "enfants d'un {}config doit être une config, pas {}" msgstr "enfants d'un {}config doit être une config, pas {}"
#: tiramisu/config.py:992 #: tiramisu/config.py:1008
msgid "child must be a Config, MixConfig or MetaConfig" msgid "child must be a Config, MixConfig or MetaConfig"
msgstr "l'enfant doit être une Config, MixConfig ou MetaConfig" msgstr "l'enfant doit être une Config, MixConfig ou MetaConfig"
#: tiramisu/config.py:994 #: tiramisu/config.py:1010
msgid "child has already a {}config's" msgid "child has already a {}config's"
msgstr "enfant a déjà un {}config" msgstr "enfant a déjà un {}config"
#: tiramisu/config.py:1023 #: tiramisu/config.py:1039
msgid "" msgid ""
"force_default, force_default_if_same or force_dont_change_value cannot be " "force_default, force_default_if_same or force_dont_change_value cannot be "
"set with only_config" "set with only_config"
@ -215,58 +224,58 @@ msgstr ""
"force_default, force_default_if_same ou force_dont_change_value ne peuvent " "force_default, force_default_if_same ou force_dont_change_value ne peuvent "
"pas être spécifié avec only_config" "pas être spécifié avec only_config"
#: tiramisu/config.py:1045 #: tiramisu/config.py:1061
msgid "force_default and force_dont_change_value cannot be set together" msgid "force_default and force_dont_change_value cannot be set together"
msgstr "" msgstr ""
"force_default et force_dont_change_value ne peuvent pas être mis ensemble" "force_default et force_dont_change_value ne peuvent pas être mis ensemble"
#: tiramisu/config.py:1176 #: tiramisu/config.py:1192
msgid "config is already in a metaconfig" msgid "config is already in a metaconfig"
msgstr "la config est déjà dans une metaconfig" msgstr "la config est déjà dans une metaconfig"
#: tiramisu/config.py:1178 tiramisu/config.py:1247 #: tiramisu/config.py:1194 tiramisu/config.py:1266
msgid "config name must be uniq in groupconfig for {0}" msgid "config name must be uniq in groupconfig for {0}"
msgstr "le nom de la config doit être unique dans un groupconfig pour {0}" msgstr "le nom de la config doit être unique dans un groupconfig pour {0}"
#: tiramisu/config.py:1192 #: tiramisu/config.py:1208
msgid "cannot find the config {}" msgid "cannot find the config {}"
msgstr "ne peut pas trouver la config {0}" msgstr "ne peut pas trouver la config {0}"
#: tiramisu/config.py:1211 #: tiramisu/config.py:1229
msgid "MetaConfig with optiondescription must have string has child, not {}" msgid "MetaConfig with optiondescription must have string has child, not {}"
msgstr "" msgstr ""
"MetaConfig avec une optiondescription doit avoir un nom comme enfant, pas {}" "MetaConfig avec une optiondescription doit avoir un nom comme enfant, pas {}"
#: tiramisu/config.py:1230 #: tiramisu/config.py:1249
msgid "child must be a Config or MetaConfig" msgid "child must be a Config or MetaConfig"
msgstr "enfant doit être une une Config ou une MetaConfig" msgstr "enfant doit être une une Config ou une MetaConfig"
#: tiramisu/config.py:1234 #: tiramisu/config.py:1253
msgid "all config in metaconfig must have the same optiondescription" msgid "all config in metaconfig must have the same optiondescription"
msgstr "" msgstr ""
"toutes les configs d'une metaconfig doivent avoir la même optiondescription" "toutes les configs d'une metaconfig doivent avoir la même optiondescription"
#: tiramisu/config.py:1272 #: tiramisu/config.py:1304
msgid "metaconfig must have the same optiondescription" msgid "metaconfig must have the same optiondescription"
msgstr "metaconfig doivent avoir la même optiondescription" msgstr "metaconfig doivent avoir la même optiondescription"
#: tiramisu/error.py:26 #: tiramisu/error.py:24
msgid "and" msgid "and"
msgstr "et" msgstr "et"
#: tiramisu/error.py:28 #: tiramisu/error.py:26
msgid "or" msgid "or"
msgstr "ou" msgstr "ou"
#: tiramisu/error.py:52 #: tiramisu/error.py:50
msgid " {} " msgid " {} "
msgstr " {} " msgstr " {} "
#: tiramisu/error.py:105 tiramisu/setting.py:579 #: tiramisu/error.py:105 tiramisu/setting.py:599
msgid "property" msgid "property"
msgstr "de la propriété" msgstr "de la propriété"
#: tiramisu/error.py:107 tiramisu/setting.py:581 #: tiramisu/error.py:107 tiramisu/setting.py:601
msgid "properties" msgid "properties"
msgstr "des propriétés" msgstr "des propriétés"
@ -278,15 +287,15 @@ msgstr "ne peut accéder à {0} \"{1}\" parce que \"{2}\" a {3} {4}"
msgid "cannot access to {0} \"{1}\" because has {2} {3}" msgid "cannot access to {0} \"{1}\" because has {2} {3}"
msgstr "ne peut accéder à l'{0} \"{1}\" a cause {2} {3}" msgstr "ne peut accéder à l'{0} \"{1}\" a cause {2} {3}"
#: tiramisu/error.py:191 #: tiramisu/error.py:192
msgid "invalid value" msgid "invalid value"
msgstr "valeur invalide" msgstr "valeur invalide"
#: tiramisu/error.py:196 #: tiramisu/error.py:197
msgid "attention, \"{0}\" could be an invalid {1} for \"{2}\"" msgid "attention, \"{0}\" could be an invalid {1} for \"{2}\""
msgstr "attention, \"{0}\" peut être un {1} invalide pour \"{2}\"" msgstr "attention, \"{0}\" peut être un {1} invalide pour \"{2}\""
#: tiramisu/error.py:200 tiramisu/error.py:204 #: tiramisu/error.py:201 tiramisu/error.py:205
msgid "\"{0}\" is an invalid {1} for \"{2}\"" msgid "\"{0}\" is an invalid {1} for \"{2}\""
msgstr "\"{0}\" est une valeur invalide pour l'option \"{2}\" de type {1}" msgstr "\"{0}\" est une valeur invalide pour l'option \"{2}\" de type {1}"
@ -352,7 +361,7 @@ msgstr ""
"paramètres définis pour la fonction de callback mais aucun callback défini " "paramètres définis pour la fonction de callback mais aucun callback défini "
"pour l'option \"{0}\"" "pour l'option \"{0}\""
#: tiramisu/option/baseoption.py:350 tiramisu/storage/dictionary/value.py:275 #: tiramisu/option/baseoption.py:350 tiramisu/storage/dictionary/value.py:258
#: tiramisu/storage/sqlite3/value.py:201 #: tiramisu/storage/sqlite3/value.py:201
msgid "information's item not found: {0}" msgid "information's item not found: {0}"
msgstr "item '{0}' dans les informations non trouvée" msgstr "item '{0}' dans les informations non trouvée"
@ -369,11 +378,11 @@ msgstr "\"{}\" ({}) l'attribut de l'objet \"{}\" est en lecture seule"
msgid "\"{}\" not part of any Config" msgid "\"{}\" not part of any Config"
msgstr "\"{}\" ne fait pas parti d'une Config" msgstr "\"{}\" ne fait pas parti d'une Config"
#: tiramisu/option/baseoption.py:453 #: tiramisu/option/baseoption.py:459
msgid "malformed requirements must be an option in option {0}" msgid "malformed requirements must be an option in option {0}"
msgstr "requirements mal formés doit être une option dans l'option {0}" msgstr "requirements mal formés doit être une option dans l'option {0}"
#: tiramisu/option/baseoption.py:456 #: tiramisu/option/baseoption.py:462
msgid "" msgid ""
"malformed requirements multi option must not set as requires of non multi " "malformed requirements multi option must not set as requires of non multi "
"option {0}" "option {0}"
@ -381,59 +390,59 @@ msgstr ""
"requirements mal formés une option multiple ne doit pas être spécifié comme " "requirements mal formés une option multiple ne doit pas être spécifié comme "
"pré-requis à l'option non multiple {0}" "pré-requis à l'option non multiple {0}"
#: tiramisu/option/baseoption.py:495 #: tiramisu/option/baseoption.py:501
msgid "" msgid ""
"malformed requirements expected must have option and value for option {0}" "malformed requirements expected must have option and value for option {0}"
msgstr "" msgstr ""
"expected mal formés pour le requirements, doit avoir une option et une " "expected mal formés pour le requirements, doit avoir une option et une "
"valeur pour l'option {0}" "valeur pour l'option {0}"
#: tiramisu/option/baseoption.py:502 tiramisu/option/baseoption.py:518 #: tiramisu/option/baseoption.py:508 tiramisu/option/baseoption.py:524
msgid "malformed requirements expected value must be valid for option {0}: {1}" msgid "malformed requirements expected value must be valid for option {0}: {1}"
msgstr "" msgstr ""
"valeur de \"expected\" malformé, doit être valide pour l'option {0} : {1}" "valeur de \"expected\" malformé, doit être valide pour l'option {0} : {1}"
#: tiramisu/option/baseoption.py:532 #: tiramisu/option/baseoption.py:538
msgid "" msgid ""
"malformed requirements for option: {0} action cannot be force_store_value" "malformed requirements for option: {0} action cannot be force_store_value"
msgstr "" msgstr ""
"requirements mal formés pour l'option : {0} action ne peut pas être " "requirements mal formés pour l'option : {0} action ne peut pas être "
"force_store_value" "force_store_value"
#: tiramisu/option/baseoption.py:540 #: tiramisu/option/baseoption.py:546
msgid "malformed requirements for option: {0} inverse must be boolean" msgid "malformed requirements for option: {0} inverse must be boolean"
msgstr "" msgstr ""
"requirements mal formés pour l'option : {0} inverse doit être un booléen" "requirements mal formés pour l'option : {0} inverse doit être un booléen"
#: tiramisu/option/baseoption.py:547 #: tiramisu/option/baseoption.py:553
msgid "malformed requirements for option: {0} transitive must be boolean" msgid "malformed requirements for option: {0} transitive must be boolean"
msgstr "" msgstr ""
"requirements mal formés pour l'option : {0} transitive doit être booléen" "requirements mal formés pour l'option : {0} transitive doit être booléen"
#: tiramisu/option/baseoption.py:554 #: tiramisu/option/baseoption.py:560
msgid "malformed requirements for option: {0} same_action must be boolean" msgid "malformed requirements for option: {0} same_action must be boolean"
msgstr "" msgstr ""
"requirements mal formés pour l'option : {0} same_action doit être un booléen" "requirements mal formés pour l'option : {0} same_action doit être un booléen"
#: tiramisu/option/baseoption.py:561 #: tiramisu/option/baseoption.py:567
msgid "" msgid ""
"malformed requirements for option: \"{0}\" operator must be \"or\" or \"and\"" "malformed requirements for option: \"{0}\" operator must be \"or\" or \"and\""
msgstr "" msgstr ""
"requirements mal formés pour l'option : \"{0}\" l'opérateur doit être \"or\" " "requirements mal formés pour l'option : \"{0}\" l'opérateur doit être \"or\" "
"ou \"and\"" "ou \"and\""
#: tiramisu/option/baseoption.py:574 #: tiramisu/option/baseoption.py:580
msgid "malformed requirements type for option: {0}, must be a dict" msgid "malformed requirements type for option: {0}, must be a dict"
msgstr "" msgstr ""
"type requirements malformé pour l'option : {0}, doit être un dictionnaire" "type requirements malformé pour l'option : {0}, doit être un dictionnaire"
#: tiramisu/option/baseoption.py:580 #: tiramisu/option/baseoption.py:586
msgid "malformed requirements for option: {0} unknown keys {1}, must only {2}" msgid "malformed requirements for option: {0} unknown keys {1}, must only {2}"
msgstr "" msgstr ""
"requirements mal formés pour l'option : {0} clefs inconnues {1}, doit " "requirements mal formés pour l'option : {0} clefs inconnues {1}, doit "
"seulement avoir {2}" "seulement avoir {2}"
#: tiramisu/option/baseoption.py:592 #: tiramisu/option/baseoption.py:598
msgid "" msgid ""
"malformed requirements for option: {0} require must have option, expected " "malformed requirements for option: {0} require must have option, expected "
"and action keys" "and action keys"
@ -447,10 +456,10 @@ msgstr "booléen"
#: tiramisu/option/broadcastoption.py:32 #: tiramisu/option/broadcastoption.py:32
msgid "broadcast address" msgid "broadcast address"
msgstr "adresse broadcast" msgstr "adresse de broadcast"
#: tiramisu/option/broadcastoption.py:39 tiramisu/option/dateoption.py:38 #: tiramisu/option/broadcastoption.py:39 tiramisu/option/dateoption.py:38
#: tiramisu/option/domainnameoption.py:118 tiramisu/option/ipoption.py:83 #: tiramisu/option/domainnameoption.py:126 tiramisu/option/ipoption.py:83
#: tiramisu/option/netmaskoption.py:42 tiramisu/option/networkoption.py:68 #: tiramisu/option/netmaskoption.py:42 tiramisu/option/networkoption.py:68
#: tiramisu/option/passwordoption.py:39 tiramisu/option/portoption.py:107 #: tiramisu/option/passwordoption.py:39 tiramisu/option/portoption.py:107
#: tiramisu/option/urloption.py:41 #: tiramisu/option/urloption.py:41
@ -458,8 +467,9 @@ msgid "invalid string"
msgstr "invalide caractère" msgstr "invalide caractère"
#: tiramisu/option/broadcastoption.py:57 #: tiramisu/option/broadcastoption.py:57
msgid "invalid len for vals" msgid "invalid broadcast consistency, a network and a netmask are needed"
msgstr "longueur invalide pour vals" msgstr ""
"adresse de broadcast inconsistente, un réseau et un masque sont nécessaires."
#: tiramisu/option/broadcastoption.py:62 #: tiramisu/option/broadcastoption.py:62
msgid "broadcast \"{4}\" invalid with network {0}/{1} (\"{2}\"/\"{3}\")" msgid "broadcast \"{4}\" invalid with network {0}/{1} (\"{2}\"/\"{3}\")"
@ -478,15 +488,15 @@ msgstr "values n'est pas une fonction, donc values_params doit être None"
msgid "values must be a tuple or a function for {0}" msgid "values must be a tuple or a function for {0}"
msgstr "values doit être un tuple ou une fonction pour {0}" msgstr "values doit être un tuple ou une fonction pour {0}"
#: tiramisu/option/choiceoption.py:101 #: tiramisu/option/choiceoption.py:108
msgid "calculated values for {0} is not a list" msgid "calculated values for {0} is not a list"
msgstr "valeurs calculées for {0} n'est pas une liste" msgstr "valeurs calculées for {0} n'est pas une liste"
#: tiramisu/option/choiceoption.py:114 #: tiramisu/option/choiceoption.py:123
msgid "only \"{0}\" is allowed" msgid "only \"{0}\" is allowed"
msgstr "seul \"{0}\" est autorisé" msgstr "seul \"{0}\" est autorisé"
#: tiramisu/option/choiceoption.py:117 #: tiramisu/option/choiceoption.py:126
msgid "only {0} are allowed" msgid "only {0} are allowed"
msgstr "seul {0} sont autorisés" msgstr "seul {0} sont autorisés"
@ -510,34 +520,55 @@ msgstr "allow_ip doit être un booléen"
msgid "allow_without_dot must be a boolean" msgid "allow_without_dot must be a boolean"
msgstr "allow_without_dot doit être un booléen" msgstr "allow_without_dot doit être un booléen"
#: tiramisu/option/domainnameoption.py:112 #: tiramisu/option/domainnameoption.py:73
msgid "only lowercase, number, \"-\" and \".\" are characters are allowed"
msgstr ""
"seuls les caractères en minuscule, les nombres, \"-\" et \".\" sont autorisés"
#: tiramisu/option/domainnameoption.py:74
msgid "only lowercase, number, \"-\" and \".\" are characters are recommanded"
msgstr ""
"seuls les caractères en minuscule, les nombres, \"-\" et \".\" sont "
"recommandés"
#: tiramisu/option/domainnameoption.py:77
msgid "only lowercase, number and - are characters are allowed"
msgstr "seuls les caractères en minuscule, les nombres et \"-\" sont autorisés"
#: tiramisu/option/domainnameoption.py:78
msgid "only lowercase, number and \"-\" are characters are recommanded"
msgstr ""
"seuls les caractères en minuscule, les nombres et \"-\" sont recommandés"
#: tiramisu/option/domainnameoption.py:80
#: tiramisu/option/domainnameoption.py:81
msgid "could be a IP, otherwise {}"
msgstr "peut être une IP, autrement {}"
#: tiramisu/option/domainnameoption.py:120
msgid "invalid length (min 1)" msgid "invalid length (min 1)"
msgstr "longueur invalide (min 1)" msgstr "longueur invalide (min 1)"
#: tiramisu/option/domainnameoption.py:114 #: tiramisu/option/domainnameoption.py:122
msgid "invalid length (max {0})" msgid "invalid length (max {0})"
msgstr "longueur invalide (max {0})" msgstr "longueur invalide (max {0})"
#: tiramisu/option/domainnameoption.py:125 #: tiramisu/option/domainnameoption.py:133
msgid "must not be an IP" msgid "must not be an IP"
msgstr "ne doit pas être une IP" msgstr "ne doit pas être une IP"
#: tiramisu/option/domainnameoption.py:131 #: tiramisu/option/domainnameoption.py:139
msgid "must have dot" msgid "must have dot"
msgstr "doit avec un point" msgstr "doit avec un point"
#: tiramisu/option/domainnameoption.py:133 #: tiramisu/option/domainnameoption.py:141
msgid "invalid length (max 255)" msgid "invalid length (max 255)"
msgstr "longueur invalide (max 255)" msgstr "longueur invalide (max 255)"
#: tiramisu/option/domainnameoption.py:141 #: tiramisu/option/domainnameoption.py:149
msgid "some characters are uppercase" msgid "some characters are uppercase"
msgstr "des caractères sont en majuscule" msgstr "des caractères sont en majuscule"
#: tiramisu/option/domainnameoption.py:144
msgid "some characters may cause problems"
msgstr "des caractères peuvent poser problèmes"
#: tiramisu/option/dynoptiondescription.py:56 #: tiramisu/option/dynoptiondescription.py:56
msgid "cannot set optiondescription in a dynoptiondescription" msgid "cannot set optiondescription in a dynoptiondescription"
msgstr "ne peut mettre une optiondescription dans une dynoptiondescription" msgstr "ne peut mettre une optiondescription dans une dynoptiondescription"
@ -615,16 +646,32 @@ msgid "must be private IP"
msgstr "doit être une IP privée" msgstr "doit être une IP privée"
#: tiramisu/option/ipoption.py:147 #: tiramisu/option/ipoption.py:147
msgid "\"{0}\" is not in network \"{1}\" (\"{2}\")" msgid "IP not in network \"{0}\" (\"{1}\")"
msgstr "\"{0}\" n'est pas dans le réseau \"{1}\" (\"{2}\")" msgstr "l'IP n'est pas dans le réseau \"{0}\" (\"{1}\")"
#: tiramisu/option/ipoption.py:163 #: tiramisu/option/ipoption.py:162
msgid "ip_network needs an IP, a network and a netmask" msgid "ip_network needs an IP, a network and a netmask"
msgstr "ip_network nécessite une IP, un réseau et un masque de réseau" msgstr "ip_network nécessite une IP, un réseau et un masque de réseau"
#: tiramisu/option/ipoption.py:169 #: tiramisu/option/ipoption.py:169
msgid "\"{4}\" is not in network \"{0}\"/\"{1}\" (\"{2}\"/\"{3}\")" msgid "IP not in network \"{2}\"/\"{4}\" (\"{3}\"/\"{5}\")"
msgstr "\"{4}\" n'est pas dans le réseau \"{0}\"/\"{1}\" (\"{2}\"/\"{3}\")" msgstr "l'IP n'est pas dans le réseau \"{2}\"/\"{4}\" (\"{3}\"/\"{5}\")"
#: tiramisu/option/ipoption.py:171
msgid ""
"the network doest not match with IP \"{0}\" (\"{1}\") and network "
"\"{4}\" (\"{5}\")"
msgstr ""
"le réseau ne correspond pas à l'IP \"{0}\" (\"{1}\") et au réseau "
"\"{4}\" (\"{5}\")"
#: tiramisu/option/ipoption.py:173
msgid ""
"the netmask does not match with IP \"{0}\" (\"{1}\") and broadcast "
"\"{2}\" (\"{3}\")"
msgstr ""
"le masque de réseau ne correspond pas à l'IP \"{0}\" (\"{1}\") et au "
"broadcast \"{2}\" (\"{3}\")"
#: tiramisu/option/leadership.py:57 #: tiramisu/option/leadership.py:57
msgid "a leader and a follower are mandatories in leadership \"{}\"" msgid "a leader and a follower are mandatories in leadership \"{}\""
@ -682,12 +729,12 @@ msgid "network_netmask needs a network and a netmask"
msgstr "network_netmask nécessite un réseau et un masque de réseau" msgstr "network_netmask nécessite un réseau et un masque de réseau"
#: tiramisu/option/netmaskoption.py:69 #: tiramisu/option/netmaskoption.py:69
msgid "with netmask \"{0}\" (\"{1}\")" msgid "the netmask \"{0}\" (\"{1}\") does not match"
msgstr "avec le masque \"{0}\" (\"{1}\")" msgstr "le masque \"{0}\" (\"{1}\") ne correspond pas"
#: tiramisu/option/netmaskoption.py:72 #: tiramisu/option/netmaskoption.py:72
msgid "with network \"{0}\" (\"{1}\")" msgid "the network \"{0}\" (\"{1}\") does not match"
msgstr "avec le réseau \"{0}\" (\"{1}\")" msgstr "le réseau \"{0}\" (\"{1}\") ne correspond pas"
#: tiramisu/option/netmaskoption.py:83 #: tiramisu/option/netmaskoption.py:83
msgid "ip_netmask needs an IP and a netmask" msgid "ip_netmask needs an IP and a netmask"
@ -820,38 +867,38 @@ msgstr ""
"longueur inconsistante pour \"{}\" dans le test de consistence \"{}\", " "longueur inconsistante pour \"{}\" dans le test de consistence \"{}\", "
"devrait être \"{}\"" "devrait être \"{}\""
#: tiramisu/option/option.py:716 #: tiramisu/option/option.py:715
msgid "should be different from the value of {}" msgid "should be different from the value of {}"
msgstr "devrait être différent de la valeur de {}" msgstr "devrait être différent de la valeur de {}"
#: tiramisu/option/option.py:718 #: tiramisu/option/option.py:717
msgid "must be different from the value of {}" msgid "must be different from the value of {}"
msgstr "doit être différent de la valeur de {}" msgstr "doit être différent de la valeur de {}"
#: tiramisu/option/option.py:721 #: tiramisu/option/option.py:720
msgid "value for {} should be different" msgid "value for {} should be different"
msgstr "valeur pour {} devrait être différent" msgstr "valeur pour {} devrait être différent"
#: tiramisu/option/option.py:723 #: tiramisu/option/option.py:722
msgid "value for {} must be different" msgid "value for {} must be different"
msgstr "valeur pour {} doit être différent" msgstr "valeur pour {} doit être différent"
#: tiramisu/option/optiondescription.py:62 #: tiramisu/option/optiondescription.py:63
#: tiramisu/option/optiondescription.py:177 #: tiramisu/option/optiondescription.py:181
msgid "option description seems to be part of an other config" msgid "option description seems to be part of an other config"
msgstr "l'option description semble faire parti d'une autre config" msgstr "l'option description semble faire parti d'une autre config"
#: tiramisu/option/optiondescription.py:85 #: tiramisu/option/optiondescription.py:87
msgid "the follower \"{0}\" cannot have \"force_store_value\" property" msgid "the follower \"{0}\" cannot have \"force_store_value\" property"
msgstr "" msgstr ""
"l'option suiveuse \"{0}\" ne doit pas avoir la propriété \"force_store_value" "l'option suiveuse \"{0}\" ne doit pas avoir la propriété \"force_store_value"
"\"" "\""
#: tiramisu/option/optiondescription.py:89 #: tiramisu/option/optiondescription.py:91
msgid "the dynoption \"{0}\" cannot have \"force_store_value\" property" msgid "the dynoption \"{0}\" cannot have \"force_store_value\" property"
msgstr "la dynoption \"{0}\" ne peut avoir la propriété \"force_store_value\"" msgstr "la dynoption \"{0}\" ne peut avoir la propriété \"force_store_value\""
#: tiramisu/option/optiondescription.py:97 tiramisu/setting.py:665 #: tiramisu/option/optiondescription.py:99 tiramisu/setting.py:687
msgid "" msgid ""
"a leader ({0}) cannot have \"force_default_on_freeze\" or " "a leader ({0}) cannot have \"force_default_on_freeze\" or "
"\"force_metaconfig_on_freeze\" property without \"frozen\"" "\"force_metaconfig_on_freeze\" property without \"frozen\""
@ -859,70 +906,70 @@ msgstr ""
"une option leader ({0}) ne peut avoir de propriété \"force_default_on_freeze" "une option leader ({0}) ne peut avoir de propriété \"force_default_on_freeze"
"\" sans \"frozen\"" "\" sans \"frozen\""
#: tiramisu/option/optiondescription.py:106 #: tiramisu/option/optiondescription.py:108
msgid "malformed consistency option \"{0}\" must be in same leadership" msgid "malformed consistency option \"{0}\" must be in same leadership"
msgstr "" msgstr ""
"test de consistance mal formé pour l'option \"{0}\" doit être dans la même " "test de consistance mal formé pour l'option \"{0}\" doit être dans la même "
"option leadership" "option leadership"
#: tiramisu/option/optiondescription.py:114 #: tiramisu/option/optiondescription.py:116
msgid "malformed consistency option \"{0}\" must not be a multi for \"{1}\"" msgid "malformed consistency option \"{0}\" must not be a multi for \"{1}\""
msgstr "" msgstr ""
"test de consistence mal formé pour l'option \"{0}\" ne doit doit pas être " "test de consistence mal formé pour l'option \"{0}\" ne doit doit pas être "
"une liste pour \"{1}\"" "une liste pour \"{1}\""
#: tiramisu/option/optiondescription.py:118 #: tiramisu/option/optiondescription.py:120
msgid "" msgid ""
"malformed consistency option \"{0}\" must be in same leadership as \"{1}\"" "malformed consistency option \"{0}\" must be in same leadership as \"{1}\""
msgstr "" msgstr ""
"test de consistance mal formé pour l'option \"{0}\" doit être dans la même " "test de consistance mal formé pour l'option \"{0}\" doit être dans la même "
"option leadership que \"{1}\"" "option leadership que \"{1}\""
#: tiramisu/option/optiondescription.py:149 #: tiramisu/option/optiondescription.py:151
msgid "" msgid ""
"malformed requirements option \"{0}\" must be in same leadership for \"{1}\"" "malformed requirements option \"{0}\" must be in same leadership for \"{1}\""
msgstr "" msgstr ""
"requirements mal formé pour l'option \"{0}\" doit être dans la même option " "requirements mal formé pour l'option \"{0}\" doit être dans la même option "
"leadership que \"{1}\"" "leadership que \"{1}\""
#: tiramisu/option/optiondescription.py:153 #: tiramisu/option/optiondescription.py:155
msgid "malformed requirements option \"{0}\" must not be a multi for \"{1}\"" msgid "malformed requirements option \"{0}\" must not be a multi for \"{1}\""
msgstr "" msgstr ""
"requirement mal formés pour l'option \"{0}\" ne doit pas être une valeur " "requirement mal formés pour l'option \"{0}\" ne doit pas être une valeur "
"multiple pour \"{1}\"" "multiple pour \"{1}\""
#: tiramisu/option/optiondescription.py:157 #: tiramisu/option/optiondescription.py:159
msgid "duplicate option: {0}" msgid "duplicate option: {0}"
msgstr "option dupliquée : {0}" msgstr "option dupliquée : {0}"
#: tiramisu/option/optiondescription.py:166 #: tiramisu/option/optiondescription.py:170
msgid "consistency with option {0} which is not in Config" msgid "consistency with option {0} which is not in Config"
msgstr "consistency avec l'option {0} qui n'est pas dans une Config" msgstr "consistency avec l'option {0} qui n'est pas dans une Config"
#: tiramisu/option/optiondescription.py:221 #: tiramisu/option/optiondescription.py:225
msgid "unknown option \"{0}\" in optiondescription \"{1}\"" msgid "unknown option \"{0}\" in optiondescription \"{1}\""
msgstr "option \"{0}\" inconnue dans l'optiondescription \"{1}\"" msgstr "option \"{0}\" inconnue dans l'optiondescription \"{1}\""
#: tiramisu/option/optiondescription.py:275 #: tiramisu/option/optiondescription.py:279
msgid "children in optiondescription \"{}\" must be a list" msgid "children in optiondescription \"{}\" must be a list"
msgstr "les enfants d'une optiondescription \"{}\" doit être une liste" msgstr "les enfants d'une optiondescription \"{}\" doit être une liste"
#: tiramisu/option/optiondescription.py:299 #: tiramisu/option/optiondescription.py:303
msgid "duplicate option name: \"{0}\"" msgid "duplicate option name: \"{0}\""
msgstr "nom de l'option dupliqué : \"{0}\"" msgstr "nom de l'option dupliqué : \"{0}\""
#: tiramisu/option/optiondescription.py:304 #: tiramisu/option/optiondescription.py:308
msgid "" msgid ""
"the option's name \"{}\" start as the dynoptiondescription's name \"{}\"" "the option's name \"{}\" start as the dynoptiondescription's name \"{}\""
msgstr "" msgstr ""
"le nom de l'option \"{}\" commence comme le nom du dynoptiondescription " "le nom de l'option \"{}\" commence comme le nom du dynoptiondescription "
"\"{}\"" "\"{}\""
#: tiramisu/option/optiondescription.py:329 #: tiramisu/option/optiondescription.py:333
msgid "cannot change group_type if already set (old {0}, new {1})" msgid "cannot change group_type if already set (old {0}, new {1})"
msgstr "ne peut changer group_type si déjà spécifié (ancien {0}, nouveau {1})" msgstr "ne peut changer group_type si déjà spécifié (ancien {0}, nouveau {1})"
#: tiramisu/option/optiondescription.py:333 #: tiramisu/option/optiondescription.py:337
msgid "group_type: {0} not allowed" msgid "group_type: {0} not allowed"
msgstr "group_type : {0} non autorisé" msgstr "group_type : {0} non autorisé"
@ -986,15 +1033,15 @@ msgstr "doit finir par un nom de ressource valide"
msgid "username" msgid "username"
msgstr "nom d'utilisateur" msgstr "nom d'utilisateur"
#: tiramisu/setting.py:250 #: tiramisu/setting.py:262
msgid "can't rebind {0}" msgid "can't rebind {0}"
msgstr "ne peut redéfinir ({0})" msgstr "ne peut redéfinir ({0})"
#: tiramisu/setting.py:255 #: tiramisu/setting.py:267
msgid "can't unbind {0}" msgid "can't unbind {0}"
msgstr "ne peut supprimer ({0})" msgstr "ne peut supprimer ({0})"
#: tiramisu/setting.py:519 #: tiramisu/setting.py:539
msgid "" msgid ""
"malformed requirements imbrication detected for option: '{0}' with " "malformed requirements imbrication detected for option: '{0}' with "
"requirement on: '{1}'" "requirement on: '{1}'"
@ -1002,56 +1049,56 @@ msgstr ""
"imbrication de requirements mal formés detectée pour l'option : '{0}' avec " "imbrication de requirements mal formés detectée pour l'option : '{0}' avec "
"requirement sur : '{1}'" "requirement sur : '{1}'"
#: tiramisu/setting.py:582 #: tiramisu/setting.py:602
msgid "" msgid ""
"cannot access to option \"{0}\" because required option \"{1}\" has {2} {3}" "cannot access to option \"{0}\" because required option \"{1}\" has {2} {3}"
msgstr "" msgstr ""
"ne peut accéder à l'option \"{0}\" parce que l'option requise \"{1}\" a {2} " "ne peut accéder à l'option \"{0}\" parce que l'option requise \"{1}\" a {2} "
"{3}" "{3}"
#: tiramisu/setting.py:608 #: tiramisu/setting.py:630
msgid "the calculated value is {0}" msgid "the calculated value is {0}"
msgstr "valeurs calculées est {0}" msgstr "valeurs calculées est {0}"
#: tiramisu/setting.py:610 #: tiramisu/setting.py:632
msgid "the calculated value is not {0}" msgid "the calculated value is not {0}"
msgstr "valeurs calculées n'est pas {0}" msgstr "valeurs calculées n'est pas {0}"
#: tiramisu/setting.py:614 #: tiramisu/setting.py:636
msgid "the value of \"{0}\" is {1}" msgid "the value of \"{0}\" is {1}"
msgstr "la valeur de \"{0}\" est {1}" msgstr "la valeur de \"{0}\" est {1}"
#: tiramisu/setting.py:616 #: tiramisu/setting.py:638
msgid "the value of \"{0}\" is not {1}" msgid "the value of \"{0}\" is not {1}"
msgstr "la valeur de \"{0}\" n'est pas {1}" msgstr "la valeur de \"{0}\" n'est pas {1}"
#: tiramisu/setting.py:655 #: tiramisu/setting.py:677
msgid "cannot set property {} for option \"{}\" this property is calculated" msgid "cannot set property {} for option \"{}\" this property is calculated"
msgstr "" msgstr ""
"ne peut ajouter la propriété {} pour l'option \"{}\" cette propriété est " "ne peut ajouter la propriété {} pour l'option \"{}\" cette propriété est "
"calculée" "calculée"
#: tiramisu/setting.py:660 #: tiramisu/setting.py:682
msgid "can't assign property to the symlinkoption \"{}\"" msgid "can't assign property to the symlinkoption \"{}\""
msgstr "ne peut assigner une propriété à une symlinkoption \"{}\"" msgstr "ne peut assigner une propriété à une symlinkoption \"{}\""
#: tiramisu/setting.py:692 #: tiramisu/setting.py:714
msgid "permissive must be a frozenset" msgid "permissive must be a frozenset"
msgstr "une permissive doit être de type frozenset" msgstr "une permissive doit être de type frozenset"
#: tiramisu/setting.py:696 #: tiramisu/setting.py:718
msgid "can't assign permissive to the symlinkoption \"{}\"" msgid "can't assign permissive to the symlinkoption \"{}\""
msgstr "ne peut assigner une permissive à la symlinkoption \"{}\"" msgstr "ne peut assigner une permissive à la symlinkoption \"{}\""
#: tiramisu/setting.py:703 #: tiramisu/setting.py:725
msgid "cannot add those permissives: {0}" msgid "cannot add those permissives: {0}"
msgstr "ne peut ajouter ces permissives : {0}" msgstr "ne peut ajouter ces permissives : {0}"
#: tiramisu/setting.py:720 #: tiramisu/setting.py:742
msgid "can't reset properties to the symlinkoption \"{}\"" msgid "can't reset properties to the symlinkoption \"{}\""
msgstr "ne peut réinitialiser les propriétés de la symlinkoption \"{}\"" msgstr "ne peut réinitialiser les propriétés de la symlinkoption \"{}\""
#: tiramisu/setting.py:735 #: tiramisu/setting.py:757
msgid "can't reset permissives to the symlinkoption \"{}\"" msgid "can't reset permissives to the symlinkoption \"{}\""
msgstr "ne peut réinitialiser les permissive de la symlinkoption \"{}\"" msgstr "ne peut réinitialiser les permissive de la symlinkoption \"{}\""
@ -1072,12 +1119,12 @@ msgstr "session \"{}\" en court d'utilisation"
msgid "a dictionary cannot be persistent" msgid "a dictionary cannot be persistent"
msgstr "un espace de stockage dictionary ne peut être persistant" msgstr "un espace de stockage dictionary ne peut être persistant"
#: tiramisu/storage/dictionary/value.py:284 #: tiramisu/storage/dictionary/value.py:267
#: tiramisu/storage/sqlite3/value.py:213 #: tiramisu/storage/sqlite3/value.py:213
msgid "information's item not found {0}" msgid "information's item not found {0}"
msgstr "l'information de l'objet ne sont pas trouvé {0}" msgstr "l'information de l'objet ne sont pas trouvé {0}"
#: tiramisu/storage/dictionary/value.py:303 #: tiramisu/storage/dictionary/value.py:286
msgid "cannot delete none persistent session" msgid "cannot delete none persistent session"
msgstr "ne peut supprimer une session non persistante" msgstr "ne peut supprimer une session non persistante"
@ -1085,46 +1132,57 @@ msgstr "ne peut supprimer une session non persistante"
msgid "cannot change setting when connexion is already opened" msgid "cannot change setting when connexion is already opened"
msgstr "ne peut changer les paramètres quand une connexion est déjà ouverte" msgstr "ne peut changer les paramètres quand une connexion est déjà ouverte"
#: tiramisu/todict.py:66 #: tiramisu/todict.py:67 tiramisu/todict.py:563
msgid "context is not supported from now for {}" msgid "context is not supported from now for {}"
msgstr "context n'est pas supporté maintenant pour {}" msgstr "context n'est pas supporté maintenant pour {}"
#: tiramisu/todict.py:82 tiramisu/todict.py:91 #: tiramisu/todict.py:345
msgid "option {} only works when remotable is not \"none\"" msgid "option {} only works when remotable is not \"none\""
msgstr "l'option {} ne fonctionne que si remotable is \"none\"" msgstr "l'option {} ne fonctionne que si remotable n'est pas \"none\""
#: tiramisu/todict.py:706 tiramisu/todict.py:839 #: tiramisu/todict.py:489
msgid "unable to transform tiramisu object to dict: {}"
msgstr "impossible de transformer l'objet tiramisu en dict : {}"
#: tiramisu/todict.py:794 tiramisu/todict.py:926
msgid "unknown form {}" msgid "unknown form {}"
msgstr "form {} inconnu" msgstr "form {} inconnu"
#: tiramisu/todict.py:751 #: tiramisu/todict.py:839
msgid "not in current area" msgid "not in current area"
msgstr "n'est pas dans l'espace courant" msgstr "n'est pas dans l'espace courant"
#: tiramisu/todict.py:771 #: tiramisu/todict.py:859
msgid "only multi option can have action \"add\", but \"{}\" is not a multi" msgid "only multi option can have action \"add\", but \"{}\" is not a multi"
msgstr "" msgstr ""
"seules des options multiples peuvent avoir l'action \"add\", mais \"{}\" " "seules des options multiples peuvent avoir l'action \"add\", mais \"{}\" "
"n'est pas une valeur multiple" "n'est pas une valeur multiple"
#: tiramisu/todict.py:773 #: tiramisu/todict.py:861
msgid "unknown action" msgid "unknown action"
msgstr "action inconnue" msgstr "action inconnue"
#: tiramisu/value.py:427 #: tiramisu/value.py:428
msgid "can't set owner for the symlinkoption \"{}\"" msgid "can't set owner for the symlinkoption \"{}\""
msgstr "ne peut spécifier d'utilisateur à la symlinkoption \"{}\"" msgstr "ne peut spécifier d'utilisateur à la symlinkoption \"{}\""
#: tiramisu/value.py:430 tiramisu/value.py:642 #: tiramisu/value.py:431 tiramisu/value.py:641
msgid "set owner \"{0}\" is forbidden" msgid "set owner \"{0}\" is forbidden"
msgstr "assigner l'utilisateur \"{0}\" est interdit" msgstr "assigner l'utilisateur \"{0}\" est interdit"
#: tiramisu/value.py:433 #: tiramisu/value.py:434
msgid "no value for {0} cannot change owner to {1}" msgid "no value for {0} cannot change owner to {1}"
msgstr "pas de valeur pour {0} ne peut changer d'utilisateur pour {1}" msgstr "pas de valeur pour {0} ne peut changer d'utilisateur pour {1}"
#: tiramisu/value.py:511 #: tiramisu/value.py:512
msgid "index \"{}\" is higher than the length \"{}\" for option \"{}\"" msgid "index {} is greater than the length {} for option \"{}\""
msgstr "" msgstr "l'index {} est supérieur à la longueur \"{}\" pour l'option \"{}\""
"l'index \"{}\" est supérieur à la longueur de l'option \"{}\" pour l'option "
"\"{}\"" #~ msgid "some characters may cause problems"
#~ msgstr "des caractères peuvent poser problèmes"
#~ msgid "\"{0}\" is not in network \"{1}\" (\"{2}\")"
#~ msgstr "\"{0}\" n'est pas dans le réseau \"{1}\" (\"{2}\")"
#~ msgid "invalid len for vals"
#~ msgstr "longueur invalide pour vals"

View File

@ -5,7 +5,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2019-04-13 21:34+CEST\n" "POT-Creation-Date: 2019-07-26 09:35+CEST\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -36,54 +36,58 @@ msgid "Commands:"
msgstr "" msgstr ""
#: tiramisu/api.py:104 #: tiramisu/api.py:104
msgid "index \"{}\" is higher than the leadership length \"{}\" for option \"{}\"" msgid "index \"{}\" is greater than the leadership length \"{}\" for option \"{}\""
msgstr "" msgstr ""
#: tiramisu/api.py:109 #: tiramisu/api.py:109
msgid "option must not be an optiondescription" msgid "option must not be an optiondescription"
msgstr "" msgstr ""
#: tiramisu/api.py:136 #: tiramisu/api.py:137
msgid "index must be set with the follower option \"{}\"" msgid "index must be set with the follower option \"{}\""
msgstr "" msgstr ""
#: tiramisu/api.py:139 #: tiramisu/api.py:140
msgid "unknown method {}" msgid "unknown method {} in {}"
msgstr "" msgstr ""
#: tiramisu/api.py:361 #: tiramisu/api.py:393
msgid "cannot add this property: \"{0}\"" msgid "cannot add this property: \"{0}\""
msgstr "" msgstr ""
#: tiramisu/api.py:505 tiramisu/config.py:252 #: tiramisu/api.py:549 tiramisu/config.py:252
msgid "can't delete a SymLinkOption" msgid "can't delete a SymLinkOption"
msgstr "" msgstr ""
#: tiramisu/api.py:639 tiramisu/api.py:1375 #: tiramisu/api.py:709 tiramisu/api.py:1487
msgid "please specify a valid sub function ({})" msgid "please specify a valid sub function ({})"
msgstr "" msgstr ""
#: tiramisu/api.py:702 tiramisu/api.py:1176 #: tiramisu/api.py:770 tiramisu/api.py:1264
msgid "unknown list type {}" msgid "unknown list type {}"
msgstr "" msgstr ""
#: tiramisu/api.py:704 tiramisu/api.py:1178 #: tiramisu/api.py:772 tiramisu/api.py:1266
msgid "unknown group_type: {0}" msgid "unknown group_type: {0}"
msgstr "" msgstr ""
#: tiramisu/api.py:753 tiramisu/api.py:1208 #: tiramisu/api.py:826 tiramisu/api.py:1296
msgid "please use .dict() before .updates()" msgid "please use .dict() before .updates()"
msgstr "" msgstr ""
#: tiramisu/api.py:1000 #: tiramisu/api.py:878
msgid "properties must be a set" msgid "unknown config type {}"
msgstr "" msgstr ""
#: tiramisu/api.py:1006 tiramisu/api.py:1028 #: tiramisu/api.py:1089
msgid "properties must be a frozenset"
msgstr ""
#: tiramisu/api.py:1095 tiramisu/api.py:1117
msgid "unknown when {} (must be in append or remove)" msgid "unknown when {} (must be in append or remove)"
msgstr "" msgstr ""
#: tiramisu/api.py:1018 tiramisu/api.py:1040 tiramisu/config.py:1249 #: tiramisu/api.py:1107 tiramisu/api.py:1129 tiramisu/config.py:1268
msgid "unknown type {}" msgid "unknown type {}"
msgstr "" msgstr ""
@ -92,18 +96,18 @@ msgid "unable to carry out a calculation for \"{}\", {}"
msgstr "" msgstr ""
#: tiramisu/autolib.py:257 #: tiramisu/autolib.py:257
msgid "function \"{}\" with arguments \"{}\" and \"{}\" return the list \"{}\" for the follower option \"{}\"" msgid "the \"{}\" function with positional arguments \"{}\" and keyword arguments \"{}\" must not return a list (\"{}\") for the follower option \"{}\""
msgstr "" msgstr ""
#: tiramisu/autolib.py:265 #: tiramisu/autolib.py:266
msgid "function \"{}\" return the list \"{}\" for the follower option \"{}\"" msgid "the \"{}\" function must not return a list (\"{}\") for the follower option \"{}\""
msgstr "" msgstr ""
#: tiramisu/autolib.py:293 #: tiramisu/autolib.py:295
msgid "unexpected error \"{0}\" in function \"{1}\" with arguments \"{3}\" and \"{4}\" for option \"{2}\"" msgid "unexpected error \"{0}\" in function \"{1}\" with arguments \"{3}\" and \"{4}\" for option \"{2}\""
msgstr "" msgstr ""
#: tiramisu/autolib.py:300 #: tiramisu/autolib.py:302
msgid "unexpected error \"{0}\" in function \"{1}\" for option \"{2}\"" msgid "unexpected error \"{0}\" in function \"{1}\" for option \"{2}\""
msgstr "" msgstr ""
@ -127,119 +131,119 @@ msgstr ""
msgid "cannot reduce length of a leader \"{}\"" msgid "cannot reduce length of a leader \"{}\""
msgstr "" msgstr ""
#: tiramisu/config.py:319 #: tiramisu/config.py:321
msgid "follower option \"{}\" has higher length \"{}\" than the leader length \"{}\"" msgid "the follower option \"{}\" has greater length ({}) than the leader length ({})"
msgstr "" msgstr ""
#: tiramisu/config.py:415 #: tiramisu/config.py:418
msgid "no option found in config with these criteria" msgid "no option found in config with these criteria"
msgstr "" msgstr ""
#: tiramisu/config.py:465 #: tiramisu/config.py:468
msgid "make_dict can't filtering with value without option" msgid "make_dict can't filtering with value without option"
msgstr "" msgstr ""
#: tiramisu/config.py:518 #: tiramisu/config.py:521
msgid "unexpected path \"{0}\", should start with \"{1}\"" msgid "unexpected path \"{0}\", should start with \"{1}\""
msgstr "" msgstr ""
#: tiramisu/config.py:665 #: tiramisu/config.py:669
msgid "cannot duplicate {}" msgid "cannot duplicate {}"
msgstr "" msgstr ""
#: tiramisu/config.py:734 #: tiramisu/config.py:748
msgid "cannot set leadership object has root optiondescription" msgid "cannot set leadership object has root optiondescription"
msgstr "" msgstr ""
#: tiramisu/config.py:736 #: tiramisu/config.py:750
msgid "cannot set dynoptiondescription object has root optiondescription" msgid "cannot set dynoptiondescription object has root optiondescription"
msgstr "" msgstr ""
#: tiramisu/config.py:750 tiramisu/config.py:797 #: tiramisu/config.py:764 tiramisu/config.py:811
msgid "invalid session ID: {0} for config" msgid "invalid session ID: {0} for config"
msgstr "" msgstr ""
#: tiramisu/config.py:781 #: tiramisu/config.py:795
msgid "groupconfig's children must be a list" msgid "groupconfig's children must be a list"
msgstr "" msgstr ""
#: tiramisu/config.py:785 #: tiramisu/config.py:799
msgid "groupconfig's children must be Config, MetaConfig or GroupConfig" msgid "groupconfig's children must be Config, MetaConfig or GroupConfig"
msgstr "" msgstr ""
#: tiramisu/config.py:792 #: tiramisu/config.py:806
msgid "config name must be uniq in groupconfig for \"{0}\"" msgid "config name must be uniq in groupconfig for \"{0}\""
msgstr "" msgstr ""
#: tiramisu/config.py:962 #: tiramisu/config.py:976
msgid "unknown config \"{}\"" msgid "unknown config \"{}\""
msgstr "" msgstr ""
#: tiramisu/config.py:987 tiramisu/config.py:1224 #: tiramisu/config.py:1003 tiramisu/config.py:1243
msgid "{}config's children should be config, not {}" msgid "{}config's children should be config, not {}"
msgstr "" msgstr ""
#: tiramisu/config.py:992 #: tiramisu/config.py:1008
msgid "child must be a Config, MixConfig or MetaConfig" msgid "child must be a Config, MixConfig or MetaConfig"
msgstr "" msgstr ""
#: tiramisu/config.py:994 #: tiramisu/config.py:1010
msgid "child has already a {}config's" msgid "child has already a {}config's"
msgstr "" msgstr ""
#: tiramisu/config.py:1023 #: tiramisu/config.py:1039
msgid "force_default, force_default_if_same or force_dont_change_value cannot be set with only_config" msgid "force_default, force_default_if_same or force_dont_change_value cannot be set with only_config"
msgstr "" msgstr ""
#: tiramisu/config.py:1045 #: tiramisu/config.py:1061
msgid "force_default and force_dont_change_value cannot be set together" msgid "force_default and force_dont_change_value cannot be set together"
msgstr "" msgstr ""
#: tiramisu/config.py:1176 #: tiramisu/config.py:1192
msgid "config is already in a metaconfig" msgid "config is already in a metaconfig"
msgstr "" msgstr ""
#: tiramisu/config.py:1178 tiramisu/config.py:1247 #: tiramisu/config.py:1194 tiramisu/config.py:1266
msgid "config name must be uniq in groupconfig for {0}" msgid "config name must be uniq in groupconfig for {0}"
msgstr "" msgstr ""
#: tiramisu/config.py:1192 #: tiramisu/config.py:1208
msgid "cannot find the config {}" msgid "cannot find the config {}"
msgstr "" msgstr ""
#: tiramisu/config.py:1211 #: tiramisu/config.py:1229
msgid "MetaConfig with optiondescription must have string has child, not {}" msgid "MetaConfig with optiondescription must have string has child, not {}"
msgstr "" msgstr ""
#: tiramisu/config.py:1230 #: tiramisu/config.py:1249
msgid "child must be a Config or MetaConfig" msgid "child must be a Config or MetaConfig"
msgstr "" msgstr ""
#: tiramisu/config.py:1234 #: tiramisu/config.py:1253
msgid "all config in metaconfig must have the same optiondescription" msgid "all config in metaconfig must have the same optiondescription"
msgstr "" msgstr ""
#: tiramisu/config.py:1272 #: tiramisu/config.py:1304
msgid "metaconfig must have the same optiondescription" msgid "metaconfig must have the same optiondescription"
msgstr "" msgstr ""
#: tiramisu/error.py:26 #: tiramisu/error.py:24
msgid "and" msgid "and"
msgstr "" msgstr ""
#: tiramisu/error.py:28 #: tiramisu/error.py:26
msgid "or" msgid "or"
msgstr "" msgstr ""
#: tiramisu/error.py:52 #: tiramisu/error.py:50
msgid " {} " msgid " {} "
msgstr "" msgstr ""
#: tiramisu/error.py:105 tiramisu/setting.py:579 #: tiramisu/error.py:105 tiramisu/setting.py:599
msgid "property" msgid "property"
msgstr "" msgstr ""
#: tiramisu/error.py:107 tiramisu/setting.py:581 #: tiramisu/error.py:107 tiramisu/setting.py:601
msgid "properties" msgid "properties"
msgstr "" msgstr ""
@ -251,15 +255,15 @@ msgstr ""
msgid "cannot access to {0} \"{1}\" because has {2} {3}" msgid "cannot access to {0} \"{1}\" because has {2} {3}"
msgstr "" msgstr ""
#: tiramisu/error.py:191 #: tiramisu/error.py:192
msgid "invalid value" msgid "invalid value"
msgstr "" msgstr ""
#: tiramisu/error.py:196 #: tiramisu/error.py:197
msgid "attention, \"{0}\" could be an invalid {1} for \"{2}\"" msgid "attention, \"{0}\" could be an invalid {1} for \"{2}\""
msgstr "" msgstr ""
#: tiramisu/error.py:200 tiramisu/error.py:204 #: tiramisu/error.py:201 tiramisu/error.py:205
msgid "\"{0}\" is an invalid {1} for \"{2}\"" msgid "\"{0}\" is an invalid {1} for \"{2}\""
msgstr "" msgstr ""
@ -319,7 +323,7 @@ msgstr ""
msgid "params defined for a callback function but no callback defined yet for option \"{0}\"" msgid "params defined for a callback function but no callback defined yet for option \"{0}\""
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:350 tiramisu/storage/dictionary/value.py:275 #: tiramisu/option/baseoption.py:350 tiramisu/storage/dictionary/value.py:258
#: tiramisu/storage/sqlite3/value.py:201 #: tiramisu/storage/sqlite3/value.py:201
msgid "information's item not found: {0}" msgid "information's item not found: {0}"
msgstr "" msgstr ""
@ -336,51 +340,51 @@ msgstr ""
msgid "\"{}\" not part of any Config" msgid "\"{}\" not part of any Config"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:453 #: tiramisu/option/baseoption.py:459
msgid "malformed requirements must be an option in option {0}" msgid "malformed requirements must be an option in option {0}"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:456 #: tiramisu/option/baseoption.py:462
msgid "malformed requirements multi option must not set as requires of non multi option {0}" msgid "malformed requirements multi option must not set as requires of non multi option {0}"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:495 #: tiramisu/option/baseoption.py:501
msgid "malformed requirements expected must have option and value for option {0}" msgid "malformed requirements expected must have option and value for option {0}"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:502 tiramisu/option/baseoption.py:518 #: tiramisu/option/baseoption.py:508 tiramisu/option/baseoption.py:524
msgid "malformed requirements expected value must be valid for option {0}: {1}" msgid "malformed requirements expected value must be valid for option {0}: {1}"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:532 #: tiramisu/option/baseoption.py:538
msgid "malformed requirements for option: {0} action cannot be force_store_value" msgid "malformed requirements for option: {0} action cannot be force_store_value"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:540 #: tiramisu/option/baseoption.py:546
msgid "malformed requirements for option: {0} inverse must be boolean" msgid "malformed requirements for option: {0} inverse must be boolean"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:547 #: tiramisu/option/baseoption.py:553
msgid "malformed requirements for option: {0} transitive must be boolean" msgid "malformed requirements for option: {0} transitive must be boolean"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:554 #: tiramisu/option/baseoption.py:560
msgid "malformed requirements for option: {0} same_action must be boolean" msgid "malformed requirements for option: {0} same_action must be boolean"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:561 #: tiramisu/option/baseoption.py:567
msgid "malformed requirements for option: \"{0}\" operator must be \"or\" or \"and\"" msgid "malformed requirements for option: \"{0}\" operator must be \"or\" or \"and\""
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:574 #: tiramisu/option/baseoption.py:580
msgid "malformed requirements type for option: {0}, must be a dict" msgid "malformed requirements type for option: {0}, must be a dict"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:580 #: tiramisu/option/baseoption.py:586
msgid "malformed requirements for option: {0} unknown keys {1}, must only {2}" msgid "malformed requirements for option: {0} unknown keys {1}, must only {2}"
msgstr "" msgstr ""
#: tiramisu/option/baseoption.py:592 #: tiramisu/option/baseoption.py:598
msgid "malformed requirements for option: {0} require must have option, expected and action keys" msgid "malformed requirements for option: {0} require must have option, expected and action keys"
msgstr "" msgstr ""
@ -393,7 +397,7 @@ msgid "broadcast address"
msgstr "" msgstr ""
#: tiramisu/option/broadcastoption.py:39 tiramisu/option/dateoption.py:38 #: tiramisu/option/broadcastoption.py:39 tiramisu/option/dateoption.py:38
#: tiramisu/option/domainnameoption.py:118 tiramisu/option/ipoption.py:83 #: tiramisu/option/domainnameoption.py:126 tiramisu/option/ipoption.py:83
#: tiramisu/option/netmaskoption.py:42 tiramisu/option/networkoption.py:68 #: tiramisu/option/netmaskoption.py:42 tiramisu/option/networkoption.py:68
#: tiramisu/option/passwordoption.py:39 tiramisu/option/portoption.py:107 #: tiramisu/option/passwordoption.py:39 tiramisu/option/portoption.py:107
#: tiramisu/option/urloption.py:41 #: tiramisu/option/urloption.py:41
@ -401,7 +405,7 @@ msgid "invalid string"
msgstr "" msgstr ""
#: tiramisu/option/broadcastoption.py:57 #: tiramisu/option/broadcastoption.py:57
msgid "invalid len for vals" msgid "invalid broadcast consistency, a network and a netmask are needed"
msgstr "" msgstr ""
#: tiramisu/option/broadcastoption.py:62 #: tiramisu/option/broadcastoption.py:62
@ -420,15 +424,15 @@ msgstr ""
msgid "values must be a tuple or a function for {0}" msgid "values must be a tuple or a function for {0}"
msgstr "" msgstr ""
#: tiramisu/option/choiceoption.py:101 #: tiramisu/option/choiceoption.py:108
msgid "calculated values for {0} is not a list" msgid "calculated values for {0} is not a list"
msgstr "" msgstr ""
#: tiramisu/option/choiceoption.py:114 #: tiramisu/option/choiceoption.py:123
msgid "only \"{0}\" is allowed" msgid "only \"{0}\" is allowed"
msgstr "" msgstr ""
#: tiramisu/option/choiceoption.py:117 #: tiramisu/option/choiceoption.py:126
msgid "only {0} are allowed" msgid "only {0} are allowed"
msgstr "" msgstr ""
@ -452,34 +456,51 @@ msgstr ""
msgid "allow_without_dot must be a boolean" msgid "allow_without_dot must be a boolean"
msgstr "" msgstr ""
#: tiramisu/option/domainnameoption.py:112 #: tiramisu/option/domainnameoption.py:73
msgid "only lowercase, number, \"-\" and \".\" are characters are allowed"
msgstr ""
#: tiramisu/option/domainnameoption.py:74
msgid "only lowercase, number, \"-\" and \".\" are characters are recommanded"
msgstr ""
#: tiramisu/option/domainnameoption.py:77
msgid "only lowercase, number and - are characters are allowed"
msgstr ""
#: tiramisu/option/domainnameoption.py:78
msgid "only lowercase, number and \"-\" are characters are recommanded"
msgstr ""
#: tiramisu/option/domainnameoption.py:80
#: tiramisu/option/domainnameoption.py:81
msgid "could be a IP, otherwise {}"
msgstr ""
#: tiramisu/option/domainnameoption.py:120
msgid "invalid length (min 1)" msgid "invalid length (min 1)"
msgstr "" msgstr ""
#: tiramisu/option/domainnameoption.py:114 #: tiramisu/option/domainnameoption.py:122
msgid "invalid length (max {0})" msgid "invalid length (max {0})"
msgstr "" msgstr ""
#: tiramisu/option/domainnameoption.py:125 #: tiramisu/option/domainnameoption.py:133
msgid "must not be an IP" msgid "must not be an IP"
msgstr "" msgstr ""
#: tiramisu/option/domainnameoption.py:131 #: tiramisu/option/domainnameoption.py:139
msgid "must have dot" msgid "must have dot"
msgstr "" msgstr ""
#: tiramisu/option/domainnameoption.py:133 #: tiramisu/option/domainnameoption.py:141
msgid "invalid length (max 255)" msgid "invalid length (max 255)"
msgstr "" msgstr ""
#: tiramisu/option/domainnameoption.py:141 #: tiramisu/option/domainnameoption.py:149
msgid "some characters are uppercase" msgid "some characters are uppercase"
msgstr "" msgstr ""
#: tiramisu/option/domainnameoption.py:144
msgid "some characters may cause problems"
msgstr ""
#: tiramisu/option/dynoptiondescription.py:56 #: tiramisu/option/dynoptiondescription.py:56
msgid "cannot set optiondescription in a dynoptiondescription" msgid "cannot set optiondescription in a dynoptiondescription"
msgstr "" msgstr ""
@ -553,15 +574,23 @@ msgid "must be private IP"
msgstr "" msgstr ""
#: tiramisu/option/ipoption.py:147 #: tiramisu/option/ipoption.py:147
msgid "\"{0}\" is not in network \"{1}\" (\"{2}\")" msgid "IP not in network \"{0}\" (\"{1}\")"
msgstr "" msgstr ""
#: tiramisu/option/ipoption.py:163 #: tiramisu/option/ipoption.py:162
msgid "ip_network needs an IP, a network and a netmask" msgid "ip_network needs an IP, a network and a netmask"
msgstr "" msgstr ""
#: tiramisu/option/ipoption.py:169 #: tiramisu/option/ipoption.py:169
msgid "\"{4}\" is not in network \"{0}\"/\"{1}\" (\"{2}\"/\"{3}\")" msgid "IP not in network \"{2}\"/\"{4}\" (\"{3}\"/\"{5}\")"
msgstr ""
#: tiramisu/option/ipoption.py:171
msgid "the network doest not match with IP \"{0}\" (\"{1}\") and network \"{4}\" (\"{5}\")"
msgstr ""
#: tiramisu/option/ipoption.py:173
msgid "the netmask does not match with IP \"{0}\" (\"{1}\") and broadcast \"{2}\" (\"{3}\")"
msgstr "" msgstr ""
#: tiramisu/option/leadership.py:57 #: tiramisu/option/leadership.py:57
@ -605,11 +634,11 @@ msgid "network_netmask needs a network and a netmask"
msgstr "" msgstr ""
#: tiramisu/option/netmaskoption.py:69 #: tiramisu/option/netmaskoption.py:69
msgid "with netmask \"{0}\" (\"{1}\")" msgid "the netmask \"{0}\" (\"{1}\") does not match"
msgstr "" msgstr ""
#: tiramisu/option/netmaskoption.py:72 #: tiramisu/option/netmaskoption.py:72
msgid "with network \"{0}\" (\"{1}\")" msgid "the network \"{0}\" (\"{1}\") does not match"
msgstr "" msgstr ""
#: tiramisu/option/netmaskoption.py:83 #: tiramisu/option/netmaskoption.py:83
@ -728,88 +757,88 @@ msgstr ""
msgid "unexpected length of \"{}\" in constency \"{}\", should be \"{}\"" msgid "unexpected length of \"{}\" in constency \"{}\", should be \"{}\""
msgstr "" msgstr ""
#: tiramisu/option/option.py:716 #: tiramisu/option/option.py:715
msgid "should be different from the value of {}" msgid "should be different from the value of {}"
msgstr "" msgstr ""
#: tiramisu/option/option.py:718 #: tiramisu/option/option.py:717
msgid "must be different from the value of {}" msgid "must be different from the value of {}"
msgstr "" msgstr ""
#: tiramisu/option/option.py:721 #: tiramisu/option/option.py:720
msgid "value for {} should be different" msgid "value for {} should be different"
msgstr "" msgstr ""
#: tiramisu/option/option.py:723 #: tiramisu/option/option.py:722
msgid "value for {} must be different" msgid "value for {} must be different"
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:62 #: tiramisu/option/optiondescription.py:63
#: tiramisu/option/optiondescription.py:177 #: tiramisu/option/optiondescription.py:181
msgid "option description seems to be part of an other config" msgid "option description seems to be part of an other config"
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:85 #: tiramisu/option/optiondescription.py:87
msgid "the follower \"{0}\" cannot have \"force_store_value\" property" msgid "the follower \"{0}\" cannot have \"force_store_value\" property"
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:89 #: tiramisu/option/optiondescription.py:91
msgid "the dynoption \"{0}\" cannot have \"force_store_value\" property" msgid "the dynoption \"{0}\" cannot have \"force_store_value\" property"
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:97 tiramisu/setting.py:665 #: tiramisu/option/optiondescription.py:99 tiramisu/setting.py:687
msgid "a leader ({0}) cannot have \"force_default_on_freeze\" or \"force_metaconfig_on_freeze\" property without \"frozen\"" msgid "a leader ({0}) cannot have \"force_default_on_freeze\" or \"force_metaconfig_on_freeze\" property without \"frozen\""
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:106 #: tiramisu/option/optiondescription.py:108
msgid "malformed consistency option \"{0}\" must be in same leadership" msgid "malformed consistency option \"{0}\" must be in same leadership"
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:114 #: tiramisu/option/optiondescription.py:116
msgid "malformed consistency option \"{0}\" must not be a multi for \"{1}\"" msgid "malformed consistency option \"{0}\" must not be a multi for \"{1}\""
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:118 #: tiramisu/option/optiondescription.py:120
msgid "malformed consistency option \"{0}\" must be in same leadership as \"{1}\"" msgid "malformed consistency option \"{0}\" must be in same leadership as \"{1}\""
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:149 #: tiramisu/option/optiondescription.py:151
msgid "malformed requirements option \"{0}\" must be in same leadership for \"{1}\"" msgid "malformed requirements option \"{0}\" must be in same leadership for \"{1}\""
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:153 #: tiramisu/option/optiondescription.py:155
msgid "malformed requirements option \"{0}\" must not be a multi for \"{1}\"" msgid "malformed requirements option \"{0}\" must not be a multi for \"{1}\""
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:157 #: tiramisu/option/optiondescription.py:159
msgid "duplicate option: {0}" msgid "duplicate option: {0}"
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:166 #: tiramisu/option/optiondescription.py:170
msgid "consistency with option {0} which is not in Config" msgid "consistency with option {0} which is not in Config"
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:221 #: tiramisu/option/optiondescription.py:225
msgid "unknown option \"{0}\" in optiondescription \"{1}\"" msgid "unknown option \"{0}\" in optiondescription \"{1}\""
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:275 #: tiramisu/option/optiondescription.py:279
msgid "children in optiondescription \"{}\" must be a list" msgid "children in optiondescription \"{}\" must be a list"
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:299 #: tiramisu/option/optiondescription.py:303
msgid "duplicate option name: \"{0}\"" msgid "duplicate option name: \"{0}\""
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:304 #: tiramisu/option/optiondescription.py:308
msgid "the option's name \"{}\" start as the dynoptiondescription's name \"{}\"" msgid "the option's name \"{}\" start as the dynoptiondescription's name \"{}\""
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:329 #: tiramisu/option/optiondescription.py:333
msgid "cannot change group_type if already set (old {0}, new {1})" msgid "cannot change group_type if already set (old {0}, new {1})"
msgstr "" msgstr ""
#: tiramisu/option/optiondescription.py:333 #: tiramisu/option/optiondescription.py:337
msgid "group_type: {0} not allowed" msgid "group_type: {0} not allowed"
msgstr "" msgstr ""
@ -873,63 +902,63 @@ msgstr ""
msgid "username" msgid "username"
msgstr "" msgstr ""
#: tiramisu/setting.py:250 #: tiramisu/setting.py:262
msgid "can't rebind {0}" msgid "can't rebind {0}"
msgstr "" msgstr ""
#: tiramisu/setting.py:255 #: tiramisu/setting.py:267
msgid "can't unbind {0}" msgid "can't unbind {0}"
msgstr "" msgstr ""
#: tiramisu/setting.py:519 #: tiramisu/setting.py:539
msgid "malformed requirements imbrication detected for option: '{0}' with requirement on: '{1}'" msgid "malformed requirements imbrication detected for option: '{0}' with requirement on: '{1}'"
msgstr "" msgstr ""
#: tiramisu/setting.py:582 #: tiramisu/setting.py:602
msgid "cannot access to option \"{0}\" because required option \"{1}\" has {2} {3}" msgid "cannot access to option \"{0}\" because required option \"{1}\" has {2} {3}"
msgstr "" msgstr ""
#: tiramisu/setting.py:608 #: tiramisu/setting.py:630
msgid "the calculated value is {0}" msgid "the calculated value is {0}"
msgstr "" msgstr ""
#: tiramisu/setting.py:610 #: tiramisu/setting.py:632
msgid "the calculated value is not {0}" msgid "the calculated value is not {0}"
msgstr "" msgstr ""
#: tiramisu/setting.py:614 #: tiramisu/setting.py:636
msgid "the value of \"{0}\" is {1}" msgid "the value of \"{0}\" is {1}"
msgstr "" msgstr ""
#: tiramisu/setting.py:616 #: tiramisu/setting.py:638
msgid "the value of \"{0}\" is not {1}" msgid "the value of \"{0}\" is not {1}"
msgstr "" msgstr ""
#: tiramisu/setting.py:655 #: tiramisu/setting.py:677
msgid "cannot set property {} for option \"{}\" this property is calculated" msgid "cannot set property {} for option \"{}\" this property is calculated"
msgstr "" msgstr ""
#: tiramisu/setting.py:660 #: tiramisu/setting.py:682
msgid "can't assign property to the symlinkoption \"{}\"" msgid "can't assign property to the symlinkoption \"{}\""
msgstr "" msgstr ""
#: tiramisu/setting.py:692 #: tiramisu/setting.py:714
msgid "permissive must be a frozenset" msgid "permissive must be a frozenset"
msgstr "" msgstr ""
#: tiramisu/setting.py:696 #: tiramisu/setting.py:718
msgid "can't assign permissive to the symlinkoption \"{}\"" msgid "can't assign permissive to the symlinkoption \"{}\""
msgstr "" msgstr ""
#: tiramisu/setting.py:703 #: tiramisu/setting.py:725
msgid "cannot add those permissives: {0}" msgid "cannot add those permissives: {0}"
msgstr "" msgstr ""
#: tiramisu/setting.py:720 #: tiramisu/setting.py:742
msgid "can't reset properties to the symlinkoption \"{}\"" msgid "can't reset properties to the symlinkoption \"{}\""
msgstr "" msgstr ""
#: tiramisu/setting.py:735 #: tiramisu/setting.py:757
msgid "can't reset permissives to the symlinkoption \"{}\"" msgid "can't reset permissives to the symlinkoption \"{}\""
msgstr "" msgstr ""
@ -950,12 +979,12 @@ msgstr ""
msgid "a dictionary cannot be persistent" msgid "a dictionary cannot be persistent"
msgstr "" msgstr ""
#: tiramisu/storage/dictionary/value.py:284 #: tiramisu/storage/dictionary/value.py:267
#: tiramisu/storage/sqlite3/value.py:213 #: tiramisu/storage/sqlite3/value.py:213
msgid "information's item not found {0}" msgid "information's item not found {0}"
msgstr "" msgstr ""
#: tiramisu/storage/dictionary/value.py:303 #: tiramisu/storage/dictionary/value.py:286
msgid "cannot delete none persistent session" msgid "cannot delete none persistent session"
msgstr "" msgstr ""
@ -963,43 +992,47 @@ msgstr ""
msgid "cannot change setting when connexion is already opened" msgid "cannot change setting when connexion is already opened"
msgstr "" msgstr ""
#: tiramisu/todict.py:66 #: tiramisu/todict.py:67 tiramisu/todict.py:563
msgid "context is not supported from now for {}" msgid "context is not supported from now for {}"
msgstr "" msgstr ""
#: tiramisu/todict.py:82 tiramisu/todict.py:91 #: tiramisu/todict.py:345
msgid "option {} only works when remotable is not \"none\"" msgid "option {} only works when remotable is not \"none\""
msgstr "" msgstr ""
#: tiramisu/todict.py:706 tiramisu/todict.py:839 #: tiramisu/todict.py:489
msgid "unable to transform tiramisu object to dict: {}"
msgstr ""
#: tiramisu/todict.py:794 tiramisu/todict.py:926
msgid "unknown form {}" msgid "unknown form {}"
msgstr "" msgstr ""
#: tiramisu/todict.py:751 #: tiramisu/todict.py:839
msgid "not in current area" msgid "not in current area"
msgstr "" msgstr ""
#: tiramisu/todict.py:771 #: tiramisu/todict.py:859
msgid "only multi option can have action \"add\", but \"{}\" is not a multi" msgid "only multi option can have action \"add\", but \"{}\" is not a multi"
msgstr "" msgstr ""
#: tiramisu/todict.py:773 #: tiramisu/todict.py:861
msgid "unknown action" msgid "unknown action"
msgstr "" msgstr ""
#: tiramisu/value.py:427 #: tiramisu/value.py:428
msgid "can't set owner for the symlinkoption \"{}\"" msgid "can't set owner for the symlinkoption \"{}\""
msgstr "" msgstr ""
#: tiramisu/value.py:430 tiramisu/value.py:642 #: tiramisu/value.py:431 tiramisu/value.py:641
msgid "set owner \"{0}\" is forbidden" msgid "set owner \"{0}\" is forbidden"
msgstr "" msgstr ""
#: tiramisu/value.py:433 #: tiramisu/value.py:434
msgid "no value for {0} cannot change owner to {1}" msgid "no value for {0} cannot change owner to {1}"
msgstr "" msgstr ""
#: tiramisu/value.py:511 #: tiramisu/value.py:512
msgid "index \"{}\" is higher than the length \"{}\" for option \"{}\"" msgid "index {} is greater than the length {} for option \"{}\""
msgstr "" msgstr ""

View File

@ -373,7 +373,7 @@ class BaseOption(Base):
in options that have to be set only once, it is of course done in the in options that have to be set only once, it is of course done in the
__setattr__ method __setattr__ method
""" """
__slots__ = tuple() __slots__ = ('_display_name_function',)
def __getstate__(self): def __getstate__(self):
raise NotImplementedError() raise NotImplementedError()
@ -407,8 +407,8 @@ class BaseOption(Base):
"to know if a callback has been defined or not" "to know if a callback has been defined or not"
return self.impl_get_callback()[0] is not None return self.impl_get_callback()[0] is not None
def impl_get_display_name(self, def _impl_get_display_name(self,
dyn_name: Base=None) -> str: dyn_name: Base=None) -> str:
name = self.impl_get_information('doc') name = self.impl_get_information('doc')
if name is None or name == '': if name is None or name == '':
if dyn_name is not None: if dyn_name is not None:
@ -417,6 +417,12 @@ class BaseOption(Base):
name = self.impl_getname() name = self.impl_getname()
return name return name
def impl_get_display_name(self,
dyn_name: Base=None) -> str:
if hasattr(self, '_display_name_function'):
return self._display_name_function(self, dyn_name)
return self._impl_get_display_name(dyn_name)
def reset_cache(self, def reset_cache(self,
path: str, path: str,
values: Values, values: Values,

View File

@ -54,7 +54,7 @@ class BroadcastOption(Option):
warnings_only, warnings_only,
context): context):
if len(vals) != 3: if len(vals) != 3:
raise ConfigError(_('invalid len for vals')) raise ConfigError(_('invalid broadcast consistency, a network and a netmask are needed'))
if None in vals: if None in vals:
return return
broadcast, network, netmask = vals broadcast, network, netmask = vals

View File

@ -81,25 +81,34 @@ class ChoiceOption(Option):
properties=properties, properties=properties,
warnings_only=warnings_only) warnings_only=warnings_only)
def get_callback(self):
values = self._choice_values
if isinstance(values, FunctionType):
return (values, getattr(self, '_choice_values_params', {}))
else:
return (None, None)
def impl_get_values(self, def impl_get_values(self,
option_bag, option_bag,
current_opt=undefined): current_opt=undefined):
if current_opt is undefined: if current_opt is undefined:
current_opt = self current_opt = self
values = self._choice_values values, values_params = self.get_callback()
if isinstance(values, FunctionType): if values is not None:
if option_bag is undefined: if option_bag is undefined:
values = undefined values = undefined
else: else:
values = carry_out_calculation(current_opt, values = carry_out_calculation(current_opt,
callback=values, callback=values,
callback_params=getattr(self, '_choice_values_params', {}), callback_params=values_params,
index=None, index=None,
config_bag=option_bag.config_bag, config_bag=option_bag.config_bag,
fromconsistency=[]) fromconsistency=[])
if values is not undefined and not isinstance(values, list): if values is not undefined and not isinstance(values, list):
raise ConfigError(_('calculated values for {0} is not a list' raise ConfigError(_('calculated values for {0} is not a list'
'').format(self.impl_getname())) '').format(self.impl_getname()))
else:
values = self._choice_values
return values return values

View File

@ -70,9 +70,15 @@ class DomainnameOption(IPOption):
else: else:
min_time = 1 min_time = 1
regexp = r'((?!-)[a-z0-9-]{{{1},{0}}}\.){{{1},}}[a-z0-9-]{{1,{0}}}'.format(self._get_len(type_), min_time) regexp = r'((?!-)[a-z0-9-]{{{1},{0}}}\.){{{1},}}[a-z0-9-]{{1,{0}}}'.format(self._get_len(type_), min_time)
msg = _('only lowercase, number, "-" and "." are characters are allowed')
msg_warning = _('only lowercase, number, "-" and "." are characters are recommanded')
else: else:
regexp = r'((?!-)[a-z0-9-]{{1,{0}}})'.format(self._get_len(type_)) regexp = r'((?!-)[a-z0-9-]{{1,{0}}})'.format(self._get_len(type_))
msg = _('only lowercase, number and - are characters are allowed')
msg_warning = _('only lowercase, number and "-" are characters are recommanded')
if allow_ip: if allow_ip:
msg = _('could be a IP, otherwise {}').format(msg)
msg_warning = _('could be a IP, otherwise {}').format(msg_warning)
if not cidr: if not cidr:
regexp = r'^(?:{0}|(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){{3}}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))$'.format(regexp) regexp = r'^(?:{0}|(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){{3}}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))$'.format(regexp)
else: else:
@ -80,6 +86,8 @@ class DomainnameOption(IPOption):
else: else:
regexp = r'^{0}$'.format(regexp) regexp = r'^{0}$'.format(regexp)
extra['_domain_re'] = re.compile(regexp) extra['_domain_re'] = re.compile(regexp)
extra['_domain_re_message'] = msg
extra['_domain_re_message_warning'] = msg_warning
extra['_has_upper'] = re.compile('[A-Z]') extra['_has_upper'] = re.compile('[A-Z]')
super().__init__(name, super().__init__(name,
@ -141,6 +149,6 @@ class DomainnameOption(IPOption):
raise ValueError(_('some characters are uppercase')) raise ValueError(_('some characters are uppercase'))
if not self.impl_get_extra('_domain_re').search(value): if not self.impl_get_extra('_domain_re').search(value):
if warnings_only: if warnings_only:
raise ValueError(_('some characters may cause problems')) raise ValueError(self.impl_get_extra('_domain_re_message_warning'))
else: else:
raise ValueError() raise ValueError(self.impl_get_extra('_domain_re_message'))

View File

@ -144,9 +144,8 @@ class IPOption(StrOption):
ip, network = vals ip, network = vals
network_obj = ip_network(network) network_obj = ip_network(network)
if ip_interface(ip) not in network_obj: if ip_interface(ip) not in network_obj:
msg = _('"{0}" is not in network "{1}" ("{2}")') msg = _('IP not in network "{0}" ("{1}")')
raise ValueError(msg.format(ip, raise ValueError(msg.format(network,
network,
opts[1].impl_get_display_name())) opts[1].impl_get_display_name()))
# test if ip is not network/broadcast IP # test if ip is not network/broadcast IP
netmask = NetmaskOption(self.impl_getname(), netmask = NetmaskOption(self.impl_getname(),
@ -166,12 +165,18 @@ class IPOption(StrOption):
ip, network, netmask = vals ip, network, netmask = vals
if ip_interface(ip) not in ip_network('{0}/{1}'.format(network, if ip_interface(ip) not in ip_network('{0}/{1}'.format(network,
netmask)): netmask)):
msg = _('"{4}" is not in network "{0}"/"{1}" ("{2}"/"{3}")') if current_opt == opts[0]:
raise ValueError(msg.format(network, msg = _('IP not in network "{2}"/"{4}" ("{3}"/"{5}")')
netmask, elif current_opt == opts[1]:
msg = _('the network doest not match with IP "{0}" ("{1}") and network "{4}" ("{5}")')
else:
msg = _('the netmask does not match with IP "{0}" ("{1}") and broadcast "{2}" ("{3}")')
raise ValueError(msg.format(ip,
opts[0].impl_get_display_name(),
network,
opts[1].impl_get_display_name(), opts[1].impl_get_display_name(),
opts[2].impl_get_display_name(), netmask,
ip)) opts[2].impl_get_display_name()))
# test if ip is not network/broadcast IP # test if ip is not network/broadcast IP
opts[2]._cons_ip_netmask(current_opt, opts[2]._cons_ip_netmask(current_opt,
(opts[2], opts[0]), (opts[2], opts[0]),

View File

@ -66,11 +66,11 @@ class NetmaskOption(StrOption):
ip_network('{0}/{1}'.format(val_network, val_netmask)) ip_network('{0}/{1}'.format(val_network, val_netmask))
except ValueError: except ValueError:
if current_opt == opt_network: if current_opt == opt_network:
raise ValueError(_('with netmask "{0}" ("{1}")').format(val_netmask, raise ValueError(_('the netmask "{0}" ("{1}") does not match').format(val_netmask,
opt_netmask.impl_get_display_name())) opt_netmask.impl_get_display_name()))
else: else:
raise ValueError(_('with network "{0}" ("{1}")').format(val_network, raise ValueError(_('the network "{0}" ("{1}") does not match').format(val_network,
opt_network.impl_get_display_name())) opt_network.impl_get_display_name()))
def _cons_ip_netmask(self, def _cons_ip_netmask(self,
current_opt: Option, current_opt: Option,

View File

@ -359,10 +359,10 @@ class Option(BaseOption):
'{0}'.format(err), '{0}'.format(err),
err_index) err_index)
warnings.warn_explicit(ValueErrorWarning(val, warnings.warn_explicit(ValueErrorWarning(val,
self._display_name, self._display_name,
option_bag.ori_option, option_bag.ori_option,
'{0}'.format(err), '{0}'.format(err),
err_index), err_index),
ValueErrorWarning, ValueErrorWarning,
self.__class__.__name__, 0) self.__class__.__name__, 0)
@ -707,9 +707,8 @@ class Option(BaseOption):
for opt_ in [opts[idx_inf], opts[idx_inf + idx_sup + 1]]: for opt_ in [opts[idx_inf], opts[idx_inf + idx_sup + 1]]:
if opt_ == current_opt: if opt_ == current_opt:
is_current = True is_current = True
else: elif opt_ not in equal:
if opt_ not in equal: equal.append(opt_)
equal.append(opt_)
if equal: if equal:
if is_current: if is_current:
if warnings_only: if warnings_only:

View File

@ -43,7 +43,8 @@ class CacheOptionDescription(BaseOption):
_consistencies_id=0, _consistencies_id=0,
currpath: List[str]=None, currpath: List[str]=None,
cache_option=None, cache_option=None,
force_store_values=None) -> None: force_store_values=None,
display_name=None) -> None:
"""validate options and set option has readonly option """validate options and set option has readonly option
""" """
# _consistencies is None only when we start to build cache # _consistencies is None only when we start to build cache
@ -73,7 +74,8 @@ class CacheOptionDescription(BaseOption):
_consistencies_id, _consistencies_id,
sub_currpath, sub_currpath,
cache_option, cache_option,
force_store_values) force_store_values,
display_name)
else: else:
is_multi = option.impl_is_multi() is_multi = option.impl_is_multi()
if not option.impl_is_symlinkoption(): if not option.impl_is_symlinkoption():
@ -155,6 +157,8 @@ class CacheOptionDescription(BaseOption):
require_opt.impl_getname(), option.impl_getname())) require_opt.impl_getname(), option.impl_getname()))
if option.impl_is_readonly(): if option.impl_is_readonly():
raise ConflictError(_('duplicate option: {0}').format(option)) raise ConflictError(_('duplicate option: {0}').format(option))
if not self.impl_is_readonly() and display_name:
option._display_name_function = display_name
option._path = subpath option._path = subpath
option._set_readonly() option._set_readonly()
if init: if init:

Some files were not shown because too many files have changed in this diff Show More