Compare commits

..

126 Commits

Author SHA1 Message Date
c58620a024 Merge branch 'develop' into dist/risotto/risotto-2.8.0/develop 2021-05-18 18:54:46 +02:00
ce0a46232d Merge remote-tracking branch 'official/master' into develop 2021-05-18 18:54:36 +02:00
64017d5cd4 import/export informations 2021-05-18 18:53:14 +02:00
b0462a1e80 . is no more unvalable 2021-05-18 18:52:42 +02:00
c51f221409 Merge branch 'develop' into dist/risotto/risotto-2.8.0/develop 2021-05-16 06:52:51 +02:00
8b4af12217 Merge remote-tracking branch 'official/master' into develop 2021-05-16 06:52:38 +02:00
a5b6352188 calc_value: join with multi 2021-05-16 06:51:33 +02:00
1f74767712 Merge branch 'develop' into dist/risotto/risotto-2.8.0/develop 2021-04-12 15:05:47 +02:00
75a073455e Merge remote-tracking branch 'official/master' into develop 2021-04-12 15:05:32 +02:00
87093da974 add test about deepcopy with multi parents 2021-04-03 20:38:08 +02:00
f7721a9775 manage force_store_value with dynoption 2021-04-03 20:24:27 +02:00
c3674a8f7e Merge branch 'develop' into dist/risotto/risotto-2.8.0/develop 2021-03-29 10:36:21 +02:00
33f9cbdc64 allow caching with the demoting_error_warning property 2021-03-29 10:35:56 +02:00
6084487d08 add test to dyn optiondescription 2021-03-29 10:35:56 +02:00
9576809543 dict with leader_to_list parameter 2021-03-29 10:35:56 +02:00
af2d3eb3ce calculation with submulti 2021-03-29 10:35:56 +02:00
b76db42204 better error when value not in a choice 2021-03-29 10:35:56 +02:00
5858bcc00b Calculation to non-leader option with leader parameter is now possible 2021-03-29 10:35:56 +02:00
200562d23c manage callback with unrestraint 2021-03-29 10:35:56 +02:00
2f173af70f Add ParamSelfInformation 2021-03-29 10:35:56 +02:00
9a4faf391e 2020/2021 2021-03-29 10:35:56 +02:00
e2d5a1c8aa filename must be a full path 2021-03-29 10:35:56 +02:00
0bb066a8b8 exected could be a list 2021-03-29 10:35:56 +02:00
d3d4de7ae3 wrong leadership name in dict() 2021-03-29 10:35:56 +02:00
f0be02b80f better error message 2021-03-29 10:35:55 +02:00
b9107867c9 do not remove notempty and notunique properties 2021-03-29 10:35:55 +02:00
3b1dccd844 allow caching with the demoting_error_warning property 2021-03-21 14:51:12 +01:00
12174045a2 add test to dyn optiondescription 2021-03-18 09:00:28 +01:00
8972e796db dict with leader_to_list parameter 2021-03-18 09:00:04 +01:00
29282d8ea3 calculation with submulti 2021-03-18 08:57:22 +01:00
668ed3ad37 better error when value not in a choice 2021-03-18 08:54:59 +01:00
da946baba6 Calculation to non-leader option with leader parameter is now possible 2021-03-18 08:52:22 +01:00
0167f4e2d0 manage callback with unrestraint 2021-03-08 06:39:40 +01:00
acc86bc49f Add ParamSelfInformation 2021-03-06 19:23:35 +01:00
7ebad5724e 2020/2021 2021-02-24 20:30:04 +01:00
385160cabd filename must be a full path 2021-02-17 09:50:36 +01:00
99a422dad7 exected could be a list 2021-02-06 15:18:28 +01:00
bfed49a11f wrong leadership name in dict() 2021-01-11 22:40:25 +01:00
c9e166f1d4 better error message 2020-11-21 19:26:50 +01:00
da87f40f12 do not remove notempty and notunique properties 2020-11-03 22:34:57 +01:00
29ca5d18fa Merge branch 'develop' into dist/risotto/risotto-2.8.0/develop 2020-10-14 22:32:08 +02:00
3e0e7244ef Merge remote-tracking branch 'official/master' into develop 2020-10-14 22:31:54 +02:00
e1fef11465 refactor 2020-10-05 21:16:41 +02:00
a269cbcc93 copy/deepcopy should duplicate informations 2020-10-05 20:27:17 +02:00
cd50225bad Merge remote-tracking branch 'official/master' into develop 2020-10-03 16:18:21 +02:00
6910371779 Add ParamInformation and callback can be a coroutine 2020-10-03 14:29:15 +02:00
afeedc1db6 config_bag and name not already exists 2020-08-15 00:23:48 +02:00
2db305b1f0 Merge branch 'develop' into dist/risotto/risotto-2.8.0/develop 2020-08-12 12:01:20 +02:00
ba23a144ce Merge remote-tracking branch 'official/master' into develop 2020-08-12 11:59:50 +02:00
baa56616bd tiramisu => python3-tiramisu3 2020-08-12 11:59:34 +02:00
50d42624cc better support of PACKAGE_DST environment variable 2020-08-12 11:55:55 +02:00
b82480f5d6 Rename lib to tiramisu3 2020-08-07 17:15:35 +02:00
659243ba8f better support for warnings_only 2020-08-04 16:49:21 +02:00
dc8010f0af calc_value with join parameter now work if an option is empty 2020-08-04 16:43:40 +02:00
96c76286db get dependencies in API 2020-08-04 16:35:40 +02:00
5c1d4afd56 remove unconsistent test 2020-08-04 16:35:10 +02:00
c4572ec409 remove codeset to i18n 2020-08-04 16:34:43 +02:00
2f125cfc8c better error for IP like 192.168.001.1 => 192.168.1.1 2020-08-04 16:33:52 +02:00
b8465c40ad Delete changelog 2020-07-29 16:27:53 +02:00
c5ac64ec5b Add debian folder to packaging branch 2020-07-29 16:27:38 +02:00
4b3ac5f350 New release candidate 3.0 rc16 2020-07-29 16:25:01 +02:00
2d7729612b can load old session 2020-04-21 19:19:04 +02:00
86a48ce9f1 support callback with submulti 2020-04-21 17:13:25 +02:00
f437bb78f3 add a test with default_multi for a submulti follower 2020-04-21 09:16:29 +02:00
f7bd6e3a47 add support in calculation when option is in a dynoptiondescription 2020-04-11 13:13:35 +02:00
d71018a88e release 3.0rc16 2020-04-01 11:49:18 +02:00
2d2e8a63fb add new argument in config.new() 2020-03-16 15:38:41 +01:00
6929d2740d do not raise error if setting is not changed 2020-03-14 22:31:42 +01:00
f1651848d2 can create a config with a mix_config 2020-03-04 15:39:47 +01:00
ad6ed0a648 storage in groupconfig 2020-02-18 22:10:33 +01:00
6b33bddbac validate value before validate unique value 2020-02-18 22:09:53 +01:00
91c44b38bc ip_in_network without all information 2020-02-18 22:08:52 +01:00
3bef45c9db New Postgres storage 2020-01-30 16:10:54 +01:00
746fa0134f add tiramisu/asyncinit.py file 2020-01-17 14:15:57 +01:00
1861dc59d4 add leader_to_list to dict message 2019-12-28 12:30:32 +01:00
52ddd76b1a corrections in dict and todict 2019-12-25 20:44:56 +01:00
503d4b2cca async version of tiramisu 2019-12-24 15:25:12 +01:00
76e7fd93b2 can convert suffix to build path for dynoptiondescription 2019-12-21 18:29:21 +01:00
0cb69f7a85 empty follower without empty property is valid 2019-12-19 17:18:09 +01:00
fb93c0cf6f updates tests 2019-12-08 09:09:48 +01:00
4e04082cec error should be returned in todict 2019-12-08 08:15:47 +01:00
d958b9dfad do not init storage before first used 2019-12-08 08:15:14 +01:00
d9c0b18404 'new' config allow storage 2019-12-08 08:14:36 +01:00
9cc4518087 copy value before store it 2019-12-02 10:42:17 +01:00
cdcb155acc support of todict 2019-12-02 10:41:43 +01:00
27838e67a3 support of sqlite3 2019-12-02 10:41:16 +01:00
8345a4651d can get uncalculated property 2019-12-02 10:40:17 +01:00
b6c11c08db add MacOption, remove UnicodeOption 2019-12-02 10:39:10 +01:00
358a49c0e2 can get uncalculated property + can add storage when init mixconfig 2019-12-02 10:37:21 +01:00
212fd5f16d easy way to add a group 2019-11-29 12:07:43 +01:00
323d1b83d6 hack to make a dict without all none implemented feature 2019-11-29 12:07:18 +01:00
709c0bf228 force_store_value for follower 2019-11-20 08:29:45 +01:00
1bcad4d7ed corrections in has_index 2019-11-20 08:28:26 +01:00
13c0c0e256 better error message 2019-11-20 08:27:33 +01:00
ce297ed804 better unique support 2019-11-20 08:26:41 +01:00
973b81d339 add GroupnameOption 2019-11-20 08:25:16 +01:00
9d5bae9305 better follower properties 2019-11-20 08:24:13 +01:00
8fa91abefb calc_value: inverse_condition => reverse_condition 2019-11-20 08:22:12 +01:00
d3e99cc9a5 notunique and notempty support 2019-11-19 18:52:20 +01:00
6b77b0c5ad DomainnameOption add network support 2019-11-19 18:48:13 +01:00
c5d8e0055b force_store_value for follower 2019-11-19 18:46:05 +01:00
7325f6e12f add index to properties/permissives 2019-11-19 18:39:44 +01:00
15669372db add GroupnameOption 2019-11-19 18:31:48 +01:00
74e604478e _validation, _second_level_validation => validation, second_level_validation 2019-11-19 08:26:42 +01:00
5c3a133928 consistency is now simple validation 2019-10-27 16:53:25 +01:00
e62268c46a Merge branch 'master' into develop 2019-10-20 08:26:06 +02:00
c75425c03a Merge branch 'master' into develop 2019-10-20 08:24:48 +02:00
a7e4399ae5 get information with default attribute when information is set to an option 2019-10-16 07:42:18 +02:00
ba5cc57166 get_type not exists for optiondescription, change it to impl_get_group_type 2019-10-16 07:34:03 +02:00
280d2ebd0a better error message if option that does not exists is in root optiondescription 2019-10-16 07:31:52 +02:00
42291aec51 DynOptionDescription accept only suffixes attributes with Calculation, no more callback/callback_params 2019-10-15 17:45:21 +02:00
fd50913466 add Calculation to values 2019-09-28 16:32:48 +02:00
f976c31233 Changelog 2019-09-16 07:56:34 +02:00
06ad839468 add parents method to MetaConfig 2019-09-02 14:11:36 +02:00
bb2ecc94d9 add Calculation to properties 2019-09-01 09:41:53 +02:00
7c641961d3 better validation with parent + deepconfig 2019-08-28 15:55:10 +02:00
4321bde399 prefix metaconfig_prefix with current name 2019-08-26 17:04:46 +02:00
c15dac8093 unrestraint in subconfig 2019-08-24 08:14:54 +02:00
82a91db16e prefix metaconfig_prefix with current name 2019-08-21 16:24:50 +02:00
5ff47ac5c9 rc 11 2019-08-19 14:13:56 +02:00
a9ca9fdb6a add multi parents tests 2019-08-07 08:40:23 +02:00
b6ec77aa23 better way to manage follower in MetaConfig 2019-08-07 08:38:32 +02:00
2d7d237e19 Config could have multiple parents 2019-08-05 22:31:56 +02:00
113b7a3410 todict works with Metaconfig 2019-08-03 21:03:23 +02:00
1691e38db5 separate Cache from values and settings 2019-08-01 18:22:18 +02:00
c5ce9be699 doc + description + can updates with dict 2019-07-29 22:13:04 +02:00
170 changed files with 21939 additions and 18360 deletions

View File

@ -1,5 +1,29 @@
Mon Apr 1 11:47:30 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
* version 3.0 rc16
* tiramisu is now async
* add postgresql storage
Mon Sep 2 14:10:40 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
* version 3.0 rc15
* add parents method to MetaConfig
Wed Aug 28 15:50:30 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
* version 3.0 rc14
* correction in metaconfig_prefix
* correction in validation with parent
Mon Aug 21 14:24:42 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
* version 3.0 rc12
* prefix metaconfig_prefix with current name
Mon Aug 19 08:02:27 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
* version 3.0 rc11
* Config could have multiple parents
* todict works with Metaconfig
* separate Cache from values and settings
Fri Jul 26 09:43:03 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
* version 3.0 rc9
* version 3.0 rc9 and rc10
* better todict support (especially for leadership
* can add display_name method to Config init to change the name a
option in errors

662
debian/agpl-3 vendored Normal file
View File

@ -0,0 +1,662 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
11

14
debian/control vendored Normal file
View File

@ -0,0 +1,14 @@
Source: python3-tiramisu3
Section: admin
Priority: extra
Maintainer: Cadoles <contact@cadoles.com>
Build-depends: debhelper (>=11), python3-all, python3-setuptools, dh-python
Standards-Version: 3.9.4
Homepage: https://framagit.org/tiramisu/tiramisu.git
Package: python3-tiramisu3
Architecture: any
Pre-Depends: dpkg, python3, ${misc:Pre-Depends}
Depends: ${python:Depends}, ${misc:Depends}
Description: configuration manager

22
debian/copyright vendored Normal file
View File

@ -0,0 +1,22 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: risotto
Upstream-Contact: Cadoles <contact@cadoles.com>
Source: https://forge.cadoles.com/Infra/risotto
Files: *
Copyright: 2019-2020 Cadoles <contact@cadoles.com>
License: AGPL-3+
License: AGPL-3+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

11
debian/rules vendored Normal file
View File

@ -0,0 +1,11 @@
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#DH_VERBOSE = 1
export PACKAGE_DST=tiramisu3
export PYBUILD_NAME=python3-tiramisu3
export PYBUILD_DISABLE_python3=test
%:
dh $@ --with python3 --buildsystem=pybuild

1
debian/source/format vendored Normal file
View File

@ -0,0 +1 @@
3.0 (quilt)

View File

@ -1,17 +0,0 @@
[build-system]
requires = ["flit"]
build-backend = "flit.buildapi"
[tool.flit.metadata]
module = "tiramisu"
author = "Emmanuel Garette"
author-email = "gnunux@gnunux.info"
home-page = "https://framagit.org/tiramisu/tiramisu"
classifiers = [
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
"Programming Language :: Python :: 3",
"Natural Language :: English",
"Natural Language :: French",
"Operating System :: OS Independent",
]
requires-python = ">=3.5"

View File

@ -1,13 +1,17 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
from os.path import dirname, abspath, join, normpath, isdir
from os import listdir
from setuptools import setup
import os
from tiramisu import __version__
PACKAGE_NAME = os.environ.get('PACKAGE_DST', 'tiramisu')
ORI_PACKAGE_NAME = 'tiramisu'
PACKAGE_NAME = os.environ.get('PACKAGE_DST', ORI_PACKAGE_NAME)
if PACKAGE_NAME != ORI_PACKAGE_NAME:
package_dir = {PACKAGE_NAME: ORI_PACKAGE_NAME}
else:
package_dir = None
setup(
version=__version__,
@ -17,6 +21,7 @@ setup(
description='an options controller tool',
url='https://framagit.org/tiramisu/tiramisu',
license='GNU Library or Lesser General Public License (LGPL)',
provides=['tiramisu_api'],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
@ -41,5 +46,6 @@ producing flexible and fast options access.
This version requires Python 3.5 or later.
""",
include_package_data=True,
packages=find_packages(include=['tiramisu'])
package_dir=package_dir,
packages=[PACKAGE_NAME],
)

View File

@ -10,7 +10,7 @@ from .autopath import do_autopath
do_autopath()
from tiramisu import Config, MetaConfig, \
StrOption, SymLinkOption, OptionDescription, Leadership, DynOptionDescription, \
submulti, undefined, owners, Params, ParamOption
submulti, undefined, owners, Params, ParamOption, Calculation
from tiramisu.error import PropertiesOptionError, APIError, ConfigError, LeadershipError
ICON = u'\u2937'
@ -191,8 +191,9 @@ def _getproperties(multi, isfollower, kwargs):
# define properties
properties = copy(PROPERTIES_LIST)
if multi and not isfollower:
default_props = ['empty']
default_props = ['empty', 'unique']
properties.append('empty')
properties.append('unique')
else:
default_props = []
extra_properties = kwargs.get('extra_properties')
@ -248,8 +249,9 @@ def _property_permissive(cfg, mcfg, pathread, pathwrite, confread, confwrite, **
# define properties
properties = copy(PROPERTIES_LIST)
if multi and not isfollower:
default_props = ['empty']
default_props = ['empty', 'unique']
properties.append('empty')
properties.append('unique')
else:
default_props = []
extra_properties = kwargs.get('extra_properties')
@ -662,8 +664,11 @@ def autocheck_append_value(cfg, mcfg, pathread, pathwrite, confread, confwrite,
with warnings.catch_warnings(record=True) as w:
if not kwargs.get('propertyerror', False):
leader_value = cfg_.forcepermissive.option(pathread).value.get()
v3 = cfg_.forcepermissive.option(pathread).value.get()
len_value = len(leader_value)
leader_value.append(undefined)
print('debut', leader_value, cfg_._config_bag.context._impl_values_cache._cache['odleader.first'][None][0])
print(id(leader_value), id(cfg_._config_bag.context._impl_values_cache._cache['odleader.first'][None][0]))
assert len(cfg_.forcepermissive.option(pathread).value.get()) == len_value
with warnings.catch_warnings(record=True) as w:
cfg2_.forcepermissive.option(pathread).value.set(leader_value)
@ -683,7 +688,12 @@ def autocheck_append_value(cfg, mcfg, pathread, pathwrite, confread, confwrite,
value = 'value'
else:
value = ['value']
print('==>>>')
print(leader_value, cfg_._config_bag.context._impl_values_cache._cache['odleader.first'][None][0])
print(id(leader_value), id(cfg_._config_bag.context._impl_values_cache._cache['odleader.first'][None][0]))
leader_value.append(value)
print(leader_value, cfg_._config_bag.context._impl_values_cache._cache['odleader.first'][None][0])
print(id(leader_value), id(cfg_._config_bag.context._impl_values_cache._cache['odleader.first'][None][0]))
assert len(cfg_.forcepermissive.option(pathread).value.get()) == len(new_leader_value)
cfg2_.forcepermissive.option(pathread).value.set(leader_value)
assert cfg_.forcepermissive.option(pathread).value.get()[-1] == value
@ -949,8 +959,6 @@ def autocheck_default_owner_with_value_permissive(cfg, mcfg, pathread, pathwrite
else:
assert cfg_.forcepermissive.option(pathread, 0).owner.isdefault() is True
assert cfg_.forcepermissive.option(pathread, 1).owner.isdefault() is False
#FIXME else:
# raises(PropertiesOptionError, "cfg.config(conf).forcepermissive.option(pathread).owner.isdefault()")
do(confwrite)
if confwrite != confread:
do(confread)
@ -1194,7 +1202,7 @@ def autocheck_find(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs
do(confwrite)
def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, consistency, callback, symlink, weakrefs, **kwargs):
def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, callback, symlink, weakrefs, **kwargs):
def _build_make_dict():
dico = {}
dico_value = {}
@ -1286,31 +1294,6 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
if symlink:
dico['extraoptrequirelink'] = 'value'
dico_value['extraoptrequirelink'] = 'value'
if consistency and has_value:
cpath = list(dico.keys())[0]
if "." in cpath:
cpath = cpath.rsplit('.', 1)[0] + '.'
else:
cpath = ''
if multi:
value = []
else:
value = None
if is_dyn:
dico[cpath + 'extraoptconsistencyval1'] = value
dico_value[cpath + 'extraoptconsistencyval1'] = value
if is_leader:
spath = cpath.split('.')
spath[-2] = spath[-2][:-1] + '2'
spath[-3] = spath[-3][:-1] + '2'
npath = '.'.join(spath) + 'extraoptconsistencyval2'
else:
npath = cpath[:-2] + '2.' + 'extraoptconsistencyval2'
dico[npath] = value
dico_value[npath] = value
else:
dico[cpath + 'extraoptconsistency'] = value
dico_value[cpath + 'extraoptconsistency'] = value
if is_leader:
for cpath in list(paths_.keys())[len(dyns):]:
if cpath.endswith('.first') or cpath.endswith('.firstval1') or cpath.endswith('.firstval2'):
@ -1374,8 +1357,6 @@ def check_all(cfg, paths_, path, meta, multi, default, default_multi, require, c
text += u' with default multi'
if require:
text += u' with requirement'
if consistency:
text += u' with consistency'
text += u', kwargs: {}'.format(kwargs)
print(text)
if not require:
@ -1530,7 +1511,7 @@ def check_deref(weakrefs):
assert wrf() is None
def make_conf(options, multi, default, default_multi, require, consistency, callback, symlink):
def make_conf(options, multi, default, default_multi, require, callback, symlink):
weakrefs = []
dyn = []
goptions = []
@ -1593,7 +1574,8 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
if callback:
largs = [path + 'call', "{}'s callback option".format(path)]
objcall = tiramisu_option(*largs, **call_kwargs)
kwargs['callback_params'] = Params(ParamOption(objcall))
kwargs['default'] = Calculation(kwargs['callback'], Params(ParamOption(objcall)))
del kwargs['callback']
else:
objcall = None
if symlink and not path.endswith('extraoptconsistency'):
@ -1603,16 +1585,8 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
tiramisu_option = SymLinkOption
else:
sobj = None
print(args, kwargs)
obj = tiramisu_option(*args, **kwargs)
if not 'extraopt' in path and consistency:
if require:
if symlink:
gopt = goptions[2]
else:
gopt = goptions[1]
else:
gopt = goptions[0]
obj.impl_add_consistency('not_equal', gopt, warnings_only=True, transitive=False)
return obj, objcall, sobj
def make_optiondescriptions(path, collected):
@ -1632,7 +1606,7 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
if symlink:
return
optiondescription = DynOptionDescription
kwargs['callback'] = return_list
kwargs['suffixes'] = Calculation(return_list)
dyn.append(path)
options = []
if 'options' in collected:
@ -1651,17 +1625,10 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
return obj
collect_options = {}
if require or consistency:
if require:
noptions = OrderedDict()
if require:
noptions['extraoptrequire'] = {}
if consistency:
subpath = list(options.keys())[0]
if '.' in subpath:
subpath = subpath.rsplit('.', 1)[0] + '.'
else:
subpath = ''
noptions[subpath + 'extraoptconsistency'] = {}
noptions.update(options)
else:
noptions = options
@ -1812,53 +1779,48 @@ def test_options(paths):
lpaths = list(paths.keys())
for meta in (False, True):
for callback in (False, True):
for consistency in (False, True):
for require in (False, True):
for default_multi in (False, True):
for symlink in (False, True):
if callback and default_multi:
continue
for default in (False, True):
for multi in (False, True, submulti):
pass
# for meta in (True,):
# for callback in (False,):
# for consistency in (True,):
# for require in (True,):
# for default_multi in (True,):
# for symlink in (False,):
# if callback and default_multi:
# continue
# for default in (True,):
# for multi in (submulti,):
if multi is submulti and default:
continue
if multi is submulti and consistency:
continue
if multi is False and default_multi:
continue
cfg, weakrefs, dyn = make_conf(paths, multi, default, default_multi, require, consistency, callback, symlink)
if cfg is None:
continue
if dyn:
cnt = 0
idx = 0
for index, lpath in enumerate(lpaths):
if paths[lpath]:
cnt += 1
else:
check_all(cfg, paths, lpaths[index], meta, multi, default,
default_multi, require, consistency, callback, symlink,
weakrefs, **get_kwargs(lpaths[idx]))
idx += 1
if idx == cnt:
idx = 0
else:
for lpath in lpaths:
check_all(cfg, paths, lpath, meta, multi, default,
default_multi, require, consistency, callback, symlink,
weakrefs, **get_kwargs(lpath))
del cfg
check_deref(weakrefs)
# for meta in (False, True):
# for callback in (False, True):
# for require in (False, True):
# for default_multi in (False, True):
# for symlink in (False, True):
# if callback and default_multi:
# continue
# for default in (False, True):
# for multi in (False, True, submulti):
for meta in (False,):
for callback in (False,):
for require in (False,):
for default_multi in (False,):
for symlink in (False,):
if callback and default_multi:
continue
for default in (False,):
for multi in (True,):
if multi is submulti and default:
continue
if multi is False and default_multi:
continue
cfg, weakrefs, dyn = make_conf(paths, multi, default, default_multi, require, callback, symlink)
if cfg is None:
continue
if dyn:
cnt = 0
idx = 0
for index, lpath in enumerate(lpaths):
if paths[lpath]:
cnt += 1
else:
check_all(cfg, paths, lpaths[index], meta, multi, default,
default_multi, require, callback, symlink,
weakrefs, **get_kwargs(lpaths[idx]))
idx += 1
if idx == cnt:
idx = 0
else:
for lpath in lpaths:
check_all(cfg, paths, lpath, meta, multi, default,
default_multi, require, callback, symlink,
weakrefs, **get_kwargs(lpath))
del cfg
check_deref(weakrefs)

85
tests/config.py Normal file
View File

@ -0,0 +1,85 @@
# from json import dumps, loads
import asyncio
from os import environ
try:
from tiramisu_api import Config
class TestConfig(Config):
def __init__(self,
config):
self.test_option = config.option
json = self.test_option.dict()
# assert json == loads(dumps(json))
super().__init__(json)
def send_data(self,
updates):
return self.updates_data(self.test_option.updates(updates))
PARAMS = ['tiramisu', 'tiramisu-api']
except:
PARAMS = ['tiramisu']
import pytest
async def get_config(config, type, error=False):
if type == 'tiramisu':
return config
if error:
await config.property.add('demoting_error_warning')
return TestConfig(config)
def value_list(values):
if values[0] == '':
del values[0]
return tuple(values)
async def global_owner(config, config_type):
return await config.owner.get()
@pytest.fixture(params=PARAMS)
def config_type(request):
return request.param
LOOP = None
@pytest.fixture(scope='session')
def event_loop(request):
"""Create an instance of the default event loop for each test case."""
global LOOP
if LOOP is None:
LOOP = asyncio.get_event_loop_policy().new_event_loop()
return LOOP
async def _delete_sessions(meta):
if await meta.config.type() != 'config':
for conf in await meta.config.list():
await _delete_sessions(conf)
await meta.session.reset()
async def delete_sessions(confs):
if not isinstance(confs, list):
confs = [confs]
for conf in confs:
await _delete_sessions(conf)
if environ.get('TIRAMISU_STORAGE') == 'postgres':
async with confs[0]._config_bag.context.getconnection() as connection:
assert await connection.fetchrow('SELECT * FROM session') is None
assert await connection.fetchrow('SELECT * FROM value') is None
assert await connection.fetchrow('SELECT * FROM information') is None
assert await connection.fetchrow('SELECT * FROM property') is None
assert await connection.fetchrow('SELECT * FROM permissive') is None
elif environ.get('TIRAMISU_STORAGE') == 'sqlite3':
async with confs[0]._config_bag.context.getconnection() as connection:
assert await connection.select('SELECT * FROM session') is None
assert await connection.select('SELECT * FROM value') is None
assert await connection.select('SELECT * FROM information') is None
assert await connection.select('SELECT * FROM property') is None
assert await connection.select('SELECT * FROM permissive') is None
else:
from tiramisu import list_sessions
assert not await list_sessions()

View File

@ -54,7 +54,10 @@
},
"model": {
"options.choice1.choice1": {
"required": true
"required": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -54,7 +54,10 @@
},
"model": {
"options.choice1.choice1": {
"required": true
"required": true,
"properties": [
"unique"
]
},
"options.choice1.choice3": {
"null": {

View File

@ -55,6 +55,9 @@
"model": {
"options.choice1.choice1": {
"required": true,
"properties": [
"unique"
],
"value": [
"choice 2"
],

View File

@ -16,10 +16,10 @@ def get_description():
return descr
def get_values(api, allpath=False):
async def get_values(api, allpath=False):
if allpath:
root = 'choice1_leadership_value.'
else:
root = ''
api.option(root + 'options.choice1.choice1').value.set(['choice 2'])
api.option(root + 'options.choice1.choice2', 0).value.set('choice 4')
await api.option(root + 'options.choice1.choice1').value.set(['choice 2'])
await api.option(root + 'options.choice1.choice2', 0).value.set('choice 4')

View File

@ -18,7 +18,10 @@
},
"model": {
"options.choice": {
"required": true
"required": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -1,12 +1,14 @@
from tiramisu.option import ChoiceOption, StrOption, OptionDescription
from tiramisu import ChoiceOption, StrOption, OptionDescription, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option1 = ChoiceOption('choice', "Choice description", ("hide", "show"), default='hide', properties=('mandatory',))
option2 = StrOption('unicode2', "Unicode 2", requires=[{'option': option1,
'expected': 'hide',
'action': 'hidden'}])
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option1, todict=True),
'expected': ParamValue('hide')}))
option2 = StrOption('unicode2', "Unicode 2", properties=(hidden_property,))
descr1 = OptionDescription("options", "Common configuration", [option1, option2])
descr = OptionDescription("choice1_requires", "Choice with requirement", [descr1])
return descr

View File

@ -5,8 +5,8 @@ def get_description():
"""
option1 = DomainnameOption('hostname1', "Domainname Description")
option2 = DomainnameOption('hostname2', "Domainname without dot Description", allow_without_dot=True)
option3 = DomainnameOption('hostname3', "Hostname or IP Description", type_='hostname', allow_ip=True)
option4 = DomainnameOption('hostname4', "Netbios Description", type_='netbios')
option3 = DomainnameOption('hostname3', "Hostname or IP Description", type='hostname', allow_ip=True)
option4 = DomainnameOption('hostname4', "Netbios Description", type='netbios')
descr1 = OptionDescription("options", "Common configuration", [option1, option2, option3, option4])
descr = OptionDescription("hostname1", "Simple hostnames", [descr1])
return descr

View File

@ -10,9 +10,9 @@ def get_description():
return descr
def get_values(api, allpath=False):
async def get_values(api, allpath=False):
if allpath:
root = 'number1_mod_value.'
else:
root = ''
api.option(root + 'options.integer').value.set(3)
await api.option(root + 'options.integer').value.set(3)

View File

@ -34,10 +34,19 @@
}
},
"model": {
"options.unicode": {
"display": false,
"properties": [
"hidden"
]
},
"options.unicode.unicode": {
"required": true,
"display": false,
"hidden": true
"properties": [
"unique"
],
"hidden": true,
"display": false
}
},
"global": {

View File

@ -1,15 +1,15 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
from tiramisu import Leadership
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode leader", multi=True, properties=('hidden',))
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 2", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 3", multi=True)
option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2", multi=True)
option3 = StrOption('unicode3', "Unicode follower 3", multi=True)
descr1 = Leadership("unicode", "Common configuration",
[option, option1, option2, option3])
[option, option1, option2, option3], properties=('hidden',))
descr = OptionDescription("options", "Common configuration", [descr1])
descr = OptionDescription("unicode1_leader_hidden_followers", "Leader follower with unicode and hidden leader", [descr])
return descr

View File

@ -35,7 +35,10 @@
},
"model": {
"options.unicode.unicode": {
"required": true
"required": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -1,13 +1,13 @@
from tiramisu.option import UnicodeOption, OptionDescription, Leadership
from tiramisu.option import StrOption, OptionDescription, Leadership
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode leader", multi=True)
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 2", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 3", multi=True)
option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2", multi=True)
option3 = StrOption('unicode3', "Unicode follower 3", multi=True)
descr1 = Leadership("unicode", "Common configuration 1",
[option, option1, option2, option3])
descr = OptionDescription("options", "Common configuration 2", [descr1])

View File

@ -41,6 +41,9 @@
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val1",
"val2"

View File

@ -1,14 +1,14 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
from tiramisu import Leadership
from tiramisu.setting import groups
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode leader", ['val1', 'val2'], multi=True)
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 2 with default multi", default_multi="follower2", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 3", multi=True)
option = StrOption('unicode', "Unicode leader", ['val1', 'val2'], multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2 with default multi", default_multi="follower2", multi=True)
option3 = StrOption('unicode3', "Unicode follower 3", multi=True)
descr1 = Leadership("unicode", "Common configuration 1",
[option, option1, option2, option3])
descr = OptionDescription("options", "Common configuration 2", [descr1])

View File

@ -36,6 +36,9 @@
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val1",
"val2"

View File

@ -1,14 +1,14 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
from tiramisu import Leadership
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode leader", multi=True)
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 2 hidden", multi=True, properties=('hidden',))
option3 = UnicodeOption('unicode3', "Unicode follower 3", multi=True)
option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2 hidden", multi=True, properties=('hidden',))
option3 = StrOption('unicode3', "Unicode follower 3", multi=True)
descr1 = Leadership("unicode", "Common configuration",
[option, option1, option2, option3])
descr = OptionDescription("options", "Common configuration", [descr1])
@ -16,10 +16,10 @@ def get_description():
return descr
def get_values(api, allpath=False):
async def get_values(api, allpath=False):
if allpath:
root = 'unicode1_leadership_hidden.'
else:
root = ''
api.option(root + 'options.unicode.unicode').value.set([u'val1', u'val2'])
api.option(root + 'options.unicode.unicode2', 0).value.set(u'super')
await api.option(root + 'options.unicode.unicode').value.set([u'val1', u'val2'])
await api.option(root + 'options.unicode.unicode2', 0).value.set(u'super')

View File

@ -34,7 +34,10 @@
},
"model": {
"options.unicode1.unicode1": {
"required": true
"required": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -1,14 +1,14 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
from tiramisu import Leadership
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode leader")
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 2", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 3", multi=True)
option = StrOption('unicode', "Unicode leader")
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2", multi=True)
option3 = StrOption('unicode3', "Unicode follower 3", multi=True)
descr1 = Leadership("unicode1", "Common configuration",
[option1, option2, option3])
descr = OptionDescription("options", "Common configuration", [option, descr1])

View File

@ -1,14 +1,14 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
from tiramisu import Leadership
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode leader", multi=True)
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 2 not equal", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 3 not equal", multi=True)
option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2 not equal", multi=True)
option3 = StrOption('unicode3', "Unicode follower 3 not equal", multi=True)
option2.impl_add_consistency('not_equal', option3)
descr1 = Leadership("unicode", "Common configuration 1",
[option, option1, option2, option3])

View File

@ -35,7 +35,10 @@
},
"model": {
"options.unicode.unicode": {
"required": true
"required": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -1,18 +1,17 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu import Leadership
from tiramisu import StrOption, OptionDescription, Leadership, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode leader", multi=True)
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Values 'test' must show 'Unicode follower 3'", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 3", requires=[{'option': option2,
'expected': u'test',
'action': 'hidden',
'inverse': True}],
multi=True)
option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Values 'test' must show 'Unicode follower 3'", multi=True)
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option2, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
option3 = StrOption('unicode3', "Unicode follower 3", properties=(hidden_property,), multi=True)
descr1 = Leadership("unicode", "Common configuration 1",
[option, option1, option2, option3])
descr = OptionDescription("options", "Common configuration 2", [descr1])

View File

@ -34,13 +34,15 @@
},
"model": {
"options.unicode1": {
"display": false,
"properties": [
"hidden"
]
},
"options.unicode1.unicode1": {
"required": true,
"properties": [
"unique"
],
"hidden": true,
"display": false
}

View File

@ -1,19 +1,20 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu import Leadership
from tiramisu import StrOption, OptionDescription, Leadership, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Value 'test' must show Leadership")
option1 = UnicodeOption('unicode1', "Unicode leader", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 1", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 2", multi=True)
option = StrOption('unicode', "Value 'test' must show Leadership")
option1 = StrOption('unicode1', "Unicode leader", multi=True)
option2 = StrOption('unicode2', "Unicode follower 1", multi=True)
option3 = StrOption('unicode3', "Unicode follower 2", multi=True)
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
descr1 = Leadership("unicode1", "Common configuration",
[option1, option2, option3], requires=[{'option': option,
'expected': u'test',
'action': 'hidden',
'inverse': True}])
[option1, option2, option3], properties=(hidden_property,))
descr = OptionDescription("options", "Common configuration", [option, descr1])
descr = OptionDescription("unicode1_leadership_requires_all", "Leader follower with requirement", [descr])
return descr

View File

@ -3,46 +3,75 @@
"options": {
"properties": {
"options.unicode": {
"type": "string",
"title": "Value 'test' must show leader"
},
"options.unicode1": {
"properties": {
"options.unicode1.unicode1": {
"options.unicode.unicode": {
"type": "string",
"isMulti": true,
"title": "Unicode leader"
"title": "Values 'test' must show 'Unicode follower 3'"
},
"options.unicode1.unicode2": {
"options.unicode.unicode1": {
"type": "string",
"isMulti": true,
"title": "Unicode follower 1"
},
"options.unicode1.unicode3": {
"options.unicode.unicode2": {
"type": "string",
"isMulti": true,
"title": "Unicode follower 2"
},
"options.unicode.unicode3": {
"type": "string",
"isMulti": true,
"title": "Unicode follower 3"
}
},
"type": "array",
"title": "Common configuration"
"title": "Common configuration 1"
}
},
"type": "object",
"title": "Common configuration"
"title": "Common configuration 2"
}
},
"model": {
"options.unicode1": {
"display": false,
"properties": [
"hidden"
]
},
"options.unicode1.unicode1": {
"options.unicode.unicode": {
"required": true,
"hidden": true,
"display": false
"properties": [
"unique"
],
"value": [
"test",
"val2"
],
"owner": "user"
},
"options.unicode.unicode1": {
"0": {
"value": "super1",
"owner": "user"
},
"1": {
"value": "super2",
"owner": "user"
}
},
"options.unicode.unicode2": {
"0": {
"value": "pas test",
"owner": "user"
},
"1": {
"value": "test",
"owner": "user"
}
},
"options.unicode.unicode3": {
"1": {
"hidden": true,
"display": false,
"value": "super",
"owner": "user"
}
}
},
"global": {
@ -62,33 +91,33 @@
]
},
"form": {
"options.unicode": {
"options.unicode.unicode": {
"clearable": true,
"type": "input",
"dependencies": {
"default": {
"hide": [
"options.unicode1"
"options.unicode.unicode3"
]
},
"expected": {
"test": {
"show": [
"options.unicode1"
"options.unicode.unicode3"
]
}
}
}
},
"options.unicode1.unicode1": {
"options.unicode.unicode1": {
"clearable": true,
"type": "input"
},
"options.unicode1.unicode2": {
"options.unicode.unicode2": {
"clearable": true,
"type": "input"
},
"options.unicode1.unicode3": {
"options.unicode.unicode3": {
"clearable": true,
"type": "input"
},

View File

@ -0,0 +1,33 @@
from tiramisu import StrOption, OptionDescription, Leadership, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option = StrOption('unicode', "Values 'test' must show 'Unicode follower 3'", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2", multi=True)
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(option, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
option3 = StrOption('unicode3', "Unicode follower 3", properties=(disabled_property,), multi=True)
descr1 = Leadership("unicode", "Common configuration 1",
[option, option1, option2, option3])
descr = OptionDescription("options", "Common configuration 2", [descr1])
descr = OptionDescription("unicode1_leadership_requires_disabled_value", "Leader followers with Unicode follower 3 disabled when Unicode follower 2 is test and modified value", [descr])
return descr
async def get_values(api, allpath=False):
if allpath:
root = 'unicode1_leadership_requires_disabled_value.'
else:
root = ''
await api.option(root + 'options.unicode.unicode').value.set([u'test', u'val2'])
await api.option(root + 'options.unicode.unicode1', 0).value.set(u'super1')
await api.option(root + 'options.unicode.unicode1', 1).value.set(u'super2')
await api.option(root + 'options.unicode.unicode2', 0).value.set(u'pas test')
await api.option(root + 'options.unicode.unicode2', 1).value.set(u'test')
await api.option(root + 'options.unicode.unicode3', 1).value.set(u'super')

View File

@ -30,7 +30,10 @@
},
"model": {
"options.unicode1.unicode1": {
"required": true
"required": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -1,17 +1,17 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu import Leadership
from tiramisu import StrOption, OptionDescription, Leadership, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option1 = UnicodeOption('unicode1', "Values 'test' must show 'Unicode follower 2'", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 1", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 2", multi=True,
requires=[{'option': option1,
'expected': u'test',
'action': 'hidden',
'inverse': True}])
option1 = StrOption('unicode1', "Values 'test' must show 'Unicode follower 2'", multi=True)
option2 = StrOption('unicode2', "Unicode follower 1", multi=True)
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option1, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
option3 = StrOption('unicode3', "Unicode follower 2", multi=True, properties=(hidden_property,))
descr1 = Leadership("unicode1", "Common configuration",
[option1, option2, option3])
descr = OptionDescription("options", "Common configuration", [descr1])

View File

@ -31,6 +31,9 @@
"model": {
"options.unicode1.unicode1": {
"required": true,
"properties": [
"unique"
],
"value": [
"test",
"pas test"
@ -49,8 +52,8 @@
"owner": "user"
},
"1": {
"display": false,
"hidden": true
"hidden": true,
"display": false
}
}
},

View File

@ -1,29 +1,29 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu import Leadership
from tiramisu import StrOption, OptionDescription, Leadership, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option1 = UnicodeOption('unicode1', "Values 'test' must show 'Unicode follower 2'", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 1", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 2", multi=True,
requires=[{'option': option1,
'expected': u'test',
'action': 'hidden',
'inverse': True}])
option1 = StrOption('unicode1', "Values 'test' must show 'Unicode follower 2'", multi=True)
option2 = StrOption('unicode2', "Unicode follower 1", multi=True)
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option1, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
option3 = StrOption('unicode3', "Unicode follower 2", multi=True, properties=(hidden_property,))
descr1 = Leadership("unicode1", "Common configuration",
[option1, option2, option3])
descr = OptionDescription("options", "Common configuration", [descr1])
descr = OptionDescription("unicode1_leadership_requires_follower_value", "Leader follower requires follower with leader value", [descr])
descr = OptionDescription("unicode1_leadership_requires_follower_value", "Leader follower requires follower with leader", [descr])
return descr
def get_values(api, allpath=False):
async def get_values(api, allpath=False):
if allpath:
root = 'unicode1_leadership_requires_follower_value.'
else:
root = ''
api.option(root + 'options.unicode1.unicode1').value.set([u'test', u'pas test'])
api.option(root + 'options.unicode1.unicode2', 0).value.set(u'super1')
api.option(root + 'options.unicode1.unicode3', 0).value.set(u'super1')
await api.option(root + 'options.unicode1.unicode1').value.set([u'test', u'pas test'])
await api.option(root + 'options.unicode1.unicode2', 0).value.set(u'super1')
await api.option(root + 'options.unicode1.unicode3', 0).value.set(u'super1')

View File

@ -30,7 +30,10 @@
},
"model": {
"options.unicode1.unicode1": {
"required": true
"required": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -1,17 +1,17 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu import Leadership
from tiramisu import StrOption, OptionDescription, Leadership, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option1 = UnicodeOption('unicode1', "Unicode leader", multi=True)
option2 = UnicodeOption('unicode2', "Values 'test' must show 'Unicode follower 2'", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 2", multi=True,
requires=[{'option': option2,
'expected': u'test',
'action': 'hidden',
'inverse': True}])
option1 = StrOption('unicode1', "Unicode leader", multi=True)
option2 = StrOption('unicode2', "Values 'test' must show 'Unicode follower 2'", multi=True)
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option2, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
option3 = StrOption('unicode3', "Unicode follower 2", multi=True, properties=(hidden_property,))
descr1 = Leadership("unicode1", "Common configuration",
[option1, option2, option3])
descr = OptionDescription("options", "Common configuration", [descr1])

View File

@ -1,19 +0,0 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu import Leadership
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Value 'test' must show leader")
option1 = UnicodeOption('unicode1', "Unicode leader", multi=True, requires=[{'option': option,
'expected': u'test',
'action': 'hidden',
'inverse': True}])
option2 = UnicodeOption('unicode2', "Unicode follower 1", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 2", multi=True)
descr1 = Leadership("unicode1", "Common configuration",
[option1, option2, option3])
descr = OptionDescription("options", "Common configuration", [option, descr1])
descr = OptionDescription("unicode1_leadership_requires_leader", "Leader follower with requirement on leader", [descr])
return descr

View File

@ -36,6 +36,9 @@
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"test",
"val2"
@ -64,8 +67,8 @@
},
"options.unicode.unicode3": {
"1": {
"display": false,
"hidden": true,
"display": false,
"value": "super",
"owner": "user"
}

View File

@ -1,18 +1,18 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu import Leadership
from tiramisu import StrOption, OptionDescription, Leadership, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Values 'test' must show 'Unicode follower 3'", multi=True)
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 2", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 3", requires=[{'option': option,
'expected': u'test',
'action': 'hidden',
'inverse': True}],
multi=True)
option = StrOption('unicode', "Values 'test' must show 'Unicode follower 3'", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2", multi=True)
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
option3 = StrOption('unicode3', "Unicode follower 3", properties=(hidden_property,), multi=True)
descr1 = Leadership("unicode", "Common configuration 1",
[option, option1, option2, option3])
descr = OptionDescription("options", "Common configuration 2", [descr1])
@ -20,14 +20,14 @@ def get_description():
return descr
def get_values(api, allpath=False):
async def get_values(api, allpath=False):
if allpath:
root = 'unicode1_leadership_requires_value.'
else:
root = ''
api.option(root + 'options.unicode.unicode').value.set([u'test', u'val2'])
api.option(root + 'options.unicode.unicode1', 0).value.set(u'super1')
api.option(root + 'options.unicode.unicode1', 1).value.set(u'super2')
api.option(root + 'options.unicode.unicode2', 0).value.set(u'pas test')
api.option(root + 'options.unicode.unicode2', 1).value.set(u'test')
api.option(root + 'options.unicode.unicode3', 1).value.set(u'super')
await api.option(root + 'options.unicode.unicode').value.set([u'test', u'val2'])
await api.option(root + 'options.unicode.unicode1', 0).value.set(u'super1')
await api.option(root + 'options.unicode.unicode1', 1).value.set(u'super2')
await api.option(root + 'options.unicode.unicode2', 0).value.set(u'pas test')
await api.option(root + 'options.unicode.unicode2', 1).value.set(u'test')
await api.option(root + 'options.unicode.unicode3', 1).value.set(u'super')

View File

@ -36,7 +36,10 @@
},
"model": {
"options.unicode.unicode": {
"required": true
"required": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -1,14 +1,14 @@
from tiramisu.option import UnicodeOption, OptionDescription, submulti
from tiramisu.option import StrOption, OptionDescription, submulti
from tiramisu import Leadership
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode leader", multi=True)
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 2 submulti", multi=submulti)
option3 = UnicodeOption('unicode3', "Unicode follower 3", multi=True)
option = StrOption('unicode', "Unicode leader", multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2 submulti", multi=submulti)
option3 = StrOption('unicode3', "Unicode follower 3", multi=True)
descr1 = Leadership("unicode", "Common configuration 1",
[option, option1, option2, option3])
descr = OptionDescription("options", "Common configuration 2", [descr1])

View File

@ -41,6 +41,9 @@
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val3",
"val4"

View File

@ -1,14 +1,14 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
from tiramisu import Leadership
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode leader", ['val1', 'val2'], multi=True)
option1 = UnicodeOption('unicode1', "Unicode follower 1", multi=True)
option2 = UnicodeOption('unicode2', "Unicode follower 2 with default multi", default_multi="follower2", multi=True)
option3 = UnicodeOption('unicode3', "Unicode follower 3", multi=True)
option = StrOption('unicode', "Unicode leader", ['val1', 'val2'], multi=True)
option1 = StrOption('unicode1', "Unicode follower 1", multi=True)
option2 = StrOption('unicode2', "Unicode follower 2 with default multi", default_multi="follower2", multi=True)
option3 = StrOption('unicode3', "Unicode follower 3", multi=True)
descr1 = Leadership("unicode", "Common configuration 1",
[option, option1, option2, option3])
descr = OptionDescription("options", "Common configuration 2", [descr1])
@ -16,14 +16,14 @@ def get_description():
return descr
def get_values(api, allpath=False):
async def get_values(api, allpath=False):
if allpath:
root = 'unicode1_leadership_value.'
else:
root = ''
api.option(root + 'options.unicode.unicode').value.set([u'val3', u'val4'])
api.option(root + 'options.unicode.unicode1', 0).value.set(u'super1')
api.option(root + 'options.unicode.unicode1', 1).value.set(u'super2')
api.option(root + 'options.unicode.unicode2', 0).value.set(u'pas test')
api.option(root + 'options.unicode.unicode2', 1).value.set(u'test')
api.option(root + 'options.unicode.unicode3', 1).value.set(u'super')
await api.option(root + 'options.unicode.unicode').value.set([u'val3', u'val4'])
await api.option(root + 'options.unicode.unicode1', 0).value.set(u'super1')
await api.option(root + 'options.unicode.unicode1', 1).value.set(u'super2')
await api.option(root + 'options.unicode.unicode2', 0).value.set(u'pas test')
await api.option(root + 'options.unicode.unicode2', 1).value.set(u'test')
await api.option(root + 'options.unicode.unicode3', 1).value.set(u'super')

View File

@ -1,8 +1,28 @@
{"updates": ["options.unicode.unicode",
"options.unicode.unicode1",
"options.unicode.unicode2",
"options.unicode.unicode3"],
"model": {"options.unicode.unicode": {"required": true,
"value": ["val1", "val2"]},
"options.unicode.unicode2": {"0": {"value": "follower2"},
"1": {"value": "follower2"}}}}
{
"updates": [
"options.unicode.unicode",
"options.unicode.unicode1",
"options.unicode.unicode2",
"options.unicode.unicode3"
],
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val1",
"val2"
]
},
"options.unicode.unicode2": {
"0": {
"value": "follower2"
},
"1": {
"value": "follower2"
}
}
}
}

View File

@ -1,11 +1,32 @@
{"updates": ["options.unicode.unicode",
"options.unicode.unicode1",
"options.unicode.unicode2",
"options.unicode.unicode3"],
"model": {"options.unicode.unicode": {"required": true,
"value": ["val3"],
"owner": "user"},
"options.unicode.unicode1": {"0": {"value": "super1",
"owner": "user"}},
"options.unicode.unicode2": {"0": {"value": "pas test",
"owner": "user"}}}}
{
"updates": [
"options.unicode.unicode",
"options.unicode.unicode1",
"options.unicode.unicode2",
"options.unicode.unicode3"
],
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val3"
],
"owner": "user"
},
"options.unicode.unicode1": {
"0": {
"value": "super1",
"owner": "user"
}
},
"options.unicode.unicode2": {
"0": {
"value": "pas test",
"owner": "user"
}
}
}
}

View File

@ -1,16 +1,49 @@
{"updates": ["options.unicode.unicode",
"options.unicode.unicode2"],
"model": {"options.unicode.unicode": {"required": true,
"value": ["val3", "val4", "val5"],
"owner": "user"},
"options.unicode.unicode1": {"0": {"value": "super1",
"owner": "user"},
"1": {"value": "super2",
"owner": "user"}},
"options.unicode.unicode2": {"0": {"value": "pas test",
"owner": "user"},
"1": {"value": "test",
"owner": "user"},
"2": {"value": "follower2"}},
"options.unicode.unicode3": {"1": {"value": "super",
"owner": "user"}}}}
{
"updates": [
"options.unicode.unicode",
"options.unicode.unicode2"
],
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val3",
"val4",
"val5"
],
"owner": "user"
},
"options.unicode.unicode1": {
"0": {
"value": "super1",
"owner": "user"
},
"1": {
"value": "super2",
"owner": "user"
}
},
"options.unicode.unicode2": {
"0": {
"value": "pas test",
"owner": "user"
},
"1": {
"value": "test",
"owner": "user"
},
"2": {
"value": "follower2"
}
},
"options.unicode.unicode3": {
"1": {
"value": "super",
"owner": "user"
}
}
}
}

View File

@ -1,15 +1,49 @@
{"model": {"options.unicode.unicode": {"owner": "user",
"required": true,
"value": ["val3", "val4", "val5"]},
"options.unicode.unicode1": {"0": {"owner": "user",
"value": "super1"},
"1": {"owner": "user",
"value": "super2"}},
"options.unicode.unicode2": {"0": {"owner": "user",
"value": "pas test"},
"1": {"owner": "user",
"value": "test"},
"2": {"value": "follower2"}},
"options.unicode.unicode3": {"1": {"owner": "user",
"value": "super"}}},
"updates": ["options.unicode.unicode", "options.unicode.unicode2"]}
{
"updates": [
"options.unicode.unicode",
"options.unicode.unicode2"
],
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val3",
"val4",
"val5"
],
"owner": "user"
},
"options.unicode.unicode1": {
"0": {
"value": "super1",
"owner": "user"
},
"1": {
"value": "super2",
"owner": "user"
}
},
"options.unicode.unicode2": {
"0": {
"value": "pas test",
"owner": "user"
},
"1": {
"value": "test",
"owner": "user"
},
"2": {
"value": "follower2"
}
},
"options.unicode.unicode3": {
"1": {
"value": "super",
"owner": "user"
}
}
}
}

View File

@ -1,13 +1,43 @@
{"updates": ["options.unicode.unicode2"],
"model": {"options.unicode.unicode": {"required": true,
"value": ["val3", "val4"],
"owner": "user"},
"options.unicode.unicode1": {"0": {"value": "super1",
"owner": "user"},
"1": {"value": "super2",
"owner": "user"}},
"options.unicode.unicode2": {"0": {"value": "pas test",
"owner": "user"},
"1": {"value": "follower2"}},
"options.unicode.unicode3": {"1": {"value": "super",
"owner": "user"}}}}
{
"updates": [
"options.unicode.unicode2"
],
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val3",
"val4"
],
"owner": "user"
},
"options.unicode.unicode1": {
"0": {
"value": "super1",
"owner": "user"
},
"1": {
"value": "super2",
"owner": "user"
}
},
"options.unicode.unicode2": {
"0": {
"value": "pas test",
"owner": "user"
},
"1": {
"value": "follower2"
}
},
"options.unicode.unicode3": {
"1": {
"value": "super",
"owner": "user"
}
}
}
}

View File

@ -1,14 +1,44 @@
{"updates": ["options.unicode.unicode2"],
"model": {"options.unicode.unicode": {"required": true,
"value": ["val3", "val4"],
"owner": "user"},
"options.unicode.unicode1": {"0": {"value": "super1",
"owner": "user"},
"1": {"value": "super2",
"owner": "user"}},
"options.unicode.unicode2": {"0": {"value": "pas test",
"owner": "user"},
"1": {"value": "test2",
"owner": "user"}},
"options.unicode.unicode3": {"1": {"value": "super",
"owner": "user"}}}}
{
"updates": [
"options.unicode.unicode2"
],
"model": {
"options.unicode.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val3",
"val4"
],
"owner": "user"
},
"options.unicode.unicode1": {
"0": {
"value": "super1",
"owner": "user"
},
"1": {
"value": "super2",
"owner": "user"
}
},
"options.unicode.unicode2": {
"0": {
"value": "pas test",
"owner": "user"
},
"1": {
"value": "test2",
"owner": "user"
}
},
"options.unicode.unicode3": {
"1": {
"value": "super",
"owner": "user"
}
}
}
}

View File

@ -1,11 +1,11 @@
"""just a multi unicode option
"""
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode 1", properties=('mandatory',))
option = StrOption('unicode', "Unicode 1", properties=('mandatory',))
descr1 = OptionDescription("options", "Common configuration", [option])
descr = OptionDescription("unicode1_mandatory", "Mandatory unicode", [descr1])
return descr

View File

@ -11,9 +11,9 @@ def get_description():
return descr
def get_values(api, allpath=False):
async def get_values(api, allpath=False):
if allpath:
root = 'unicode1_mod_value.'
else:
root = ''
api.option(root + 'options.unicode').value.set('a')
await api.option(root + 'options.unicode').value.set('a')

View File

@ -14,7 +14,10 @@
},
"model": {
"options.unicode": {
"required": true
"required": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -1,11 +1,11 @@
"""just a multi unicode option
"""
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Multi string 1", multi=True)
option = StrOption('unicode', "Multi string 1", multi=True)
descr1 = OptionDescription("options", "Common configuration", [option])
descr = OptionDescription("unicode1_multi", "Multi unicode", [descr1])
return descr

View File

@ -1,4 +1,17 @@
{"updates": ["options.unicode"],
"model": {"options.unicode": {"owner": "user",
"required": true,
"value": ["val"]}}}
{
"updates": [
"options.unicode"
],
"model": {
"options.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"val"
],
"owner": "user"
}
}
}

View File

@ -15,6 +15,9 @@
"model": {
"options.unicode": {
"required": true,
"properties": [
"unique"
],
"display": false,
"hidden": true
}

View File

@ -1,11 +1,11 @@
"""just a multi unicode option
"""
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode 1", properties=('hidden',), multi=True)
option = StrOption('unicode', "Unicode 1", properties=('hidden',), multi=True)
descr1 = OptionDescription("options", "Common configuration", [option])
descr = OptionDescription("unicode1_multi_hidden", "Hidden multi unicode", [descr1])
return descr

View File

@ -15,7 +15,10 @@
"model": {
"options.unicode": {
"required": true,
"needs_len": true
"needs_len": true,
"properties": [
"unique"
]
}
},
"global": {

View File

@ -1,11 +1,11 @@
"""just a multi unicode option
"""
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode 1", multi=True, properties=('mandatory',))
option = StrOption('unicode', "Unicode 1", multi=True, properties=('mandatory',))
descr1 = OptionDescription("options", "Common configuration", [option])
descr = OptionDescription("unicode1_multi_mandatory", "Mandatory multi Unicode", [descr1])
return descr

View File

@ -19,6 +19,9 @@
"model": {
"options.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"c",
"d",

View File

@ -11,9 +11,9 @@ def get_description():
return descr
def get_values(api, allpath=False):
async def get_values(api, allpath=False):
if allpath:
root = 'unicode1_multi_mod_value.'
else:
root = ''
api.option(root + 'options.unicode').value.set(['c', 'd', 'e'])
await api.option(root + 'options.unicode').value.set(['c', 'd', 'e'])

View File

@ -1,3 +1,17 @@
{"updates": ["options.unicode"],
"model": {"options.unicode": {"required": true,
"value": ["a", "b"]}}}
{
"updates": [
"options.unicode"
],
"model": {
"options.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"a",
"b"
]
}
}
}

View File

@ -1,4 +1,19 @@
{"updates": ["options.unicode"],
"model": {"options.unicode": {"owner": "user",
"required": true,
"value": ["c", "f", "e"]}}}
{
"updates": [
"options.unicode"
],
"model": {
"options.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"c",
"f",
"e"
],
"owner": "user"
}
}
}

View File

@ -1,14 +1,14 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option1 = UnicodeOption('unicode1', "Unicode 1, not equal to 'a'")
option2 = UnicodeOption('unicode1_multi', "Multi unicode 1, not equal to 'a' or 'b'", multi=True)
option3 = UnicodeOption('unicode2', "Unicode 2", default='a')
option4 = UnicodeOption('unicode2_multi', "Multi unicode 2", multi=True, default=['a', 'b'])
option5 = UnicodeOption('unicode3', "Unicode 3")
option6 = UnicodeOption('unicode3_multi', "Multi unicode 3", multi=True)
option1 = StrOption('unicode1', "Unicode 1, not equal to 'a'")
option2 = StrOption('unicode1_multi', "Multi unicode 1, not equal to 'a' or 'b'", multi=True)
option3 = StrOption('unicode2', "Unicode 2", default='a')
option4 = StrOption('unicode2_multi', "Multi unicode 2", multi=True, default=['a', 'b'])
option5 = StrOption('unicode3', "Unicode 3")
option6 = StrOption('unicode3_multi', "Multi unicode 3", multi=True)
#option1.impl_add_consistency('not_equal', option3, option5)
#option2.impl_add_consistency('not_equal', option4, option6)
option3.impl_add_consistency('not_equal', option1)

View File

@ -19,8 +19,11 @@
"model": {
"options.unicode2": {
"required": true,
"display": false,
"hidden": true
"properties": [
"unique"
],
"hidden": true,
"display": false
}
},
"global": {

View File

@ -1,15 +1,16 @@
from tiramisu.option import StrOption, OptionDescription
from tiramisu import StrOption, OptionDescription, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option1 = StrOption('unicode1', "Value 'test' must show Unicode 2")
option2 = StrOption('unicode2', "Unicode 2", requires=[{'option': option1,
'expected': u'test',
'action': 'hidden',
'inverse': True}],
multi=True)
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option1, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
option2 = StrOption('unicode2', "Unicode 2", properties=(hidden_property,), multi=True)
descr1 = OptionDescription("options", "Common configuration", [option1, option2])
descr = OptionDescription("unicode1_multi_requires", "Unicode multi with requirement", [descr1])
return descr

View File

@ -19,6 +19,9 @@
"model": {
"options.unicode": {
"required": true,
"properties": [
"unique"
],
"value": [
"a",
"b"

View File

@ -1,11 +1,11 @@
"""just a multi unicode option
"""
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "String 1", ['a', 'b'], multi=True)
option = StrOption('unicode', "String 1", ['a', 'b'], multi=True)
descr1 = OptionDescription("options", "Common configuration", [option])
descr = OptionDescription("unicode1_multi_value", "Multi unicode with default value 'a' and 'b'", [descr1])
return descr

View File

@ -1,10 +1,10 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option1 = UnicodeOption('unicode1', "Unicode 1")
option2 = UnicodeOption('unicode2', "Unicode 2")
option1 = StrOption('unicode1', "Unicode 1")
option2 = StrOption('unicode2', "Unicode 2")
option2.impl_add_consistency('not_equal', option1)
descr1 = OptionDescription("options", "Common configuration", [option1, option2])
descr = OptionDescription("unicode1_not_equal", "Unicode 1 and unicode 2 not equal", [descr1])

View File

@ -27,7 +27,6 @@
},
"model": {
"unicode1": {
"display": false,
"properties": [
"hidden"
]

View File

@ -1,17 +1,18 @@
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu import StrOption, OptionDescription, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option1 = UnicodeOption('unicode1', "Value 'test' must show OptionDescription")
option1 = StrOption('unicode1', "Value 'test' must show OptionDescription")
descr1 = OptionDescription("options", "Common configuration", [option1])
option2 = UnicodeOption('unicode2', "Unicode 2")
option3 = UnicodeOption('unicode3', "Unicode 3")
descr2 = OptionDescription("unicode1", "OptionDescription with 2 options",
[option2, option3], requires=[{'option': option1,
'expected': u'test',
'action': 'hidden',
'inverse': True}])
option2 = StrOption('unicode2', "Unicode 2")
option3 = StrOption('unicode3', "Unicode 3")
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option1, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
descr2 = OptionDescription("unicode1", "OptionDescription with 2 options", [option2, option3], properties=(hidden_property,))
descr = OptionDescription("unicode1_optiondescription_requires", "OptionDesciption with requirement", [descr1, descr2])
return descr

View File

@ -1,14 +1,16 @@
from tiramisu.option import StrOption, OptionDescription
from tiramisu import StrOption, OptionDescription, Calculation, ParamValue, ParamOption, Params, calc_value
def get_description():
"""generate description for this test
"""
option1 = StrOption('unicode1', "Value 'test' must show Unicode 2")
option2 = StrOption('unicode2', "Unicode 2", requires=[{'option': option1,
'expected': u'test',
'action': 'hidden',
'inverse': True}])
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(option1, todict=True),
'expected': ParamValue('test'),
'reverse_condition': ParamValue(True)}))
option2 = StrOption('unicode2', "Unicode 2", properties=(hidden_property,))
descr1 = OptionDescription("options", "Common configuration", [option1, option2])
descr = OptionDescription("unicode1_requires", "Unicode with requirement", [descr1])
return descr

View File

@ -1,11 +1,11 @@
"""just an unicode option
"""
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Unicode 1", properties=('hidden',))
option = StrOption('unicode', "Unicode 1", properties=('hidden',))
descr1 = OptionDescription("options", "Common configuration", [option])
descr = OptionDescription("unicode_hidden", "Hidden unicode", [descr1])
return descr

View File

@ -1,11 +1,11 @@
"""just an unicode option
"""
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Expert unicode", properties=('expert',))
option = StrOption('unicode', "Expert unicode", properties=('expert',))
descr1 = OptionDescription("options", "Common configuration", [option])
descr = OptionDescription("unicode_property", "Hidden because expert", [descr1])
return descr

View File

@ -1,11 +1,11 @@
"""just an unicode option
"""
from tiramisu.option import UnicodeOption, OptionDescription
from tiramisu.option import StrOption, OptionDescription
def get_description():
"""generate description for this test
"""
option = UnicodeOption('unicode', "Expert unicode")
option = StrOption('unicode', "Expert unicode")
descr1 = OptionDescription("options", "Common configuration", [option], properties=('expert',))
descr = OptionDescription("unicode_property_optiondescription", "OptionDescription hidden because expert", [descr1])
return descr

View File

@ -23,41 +23,43 @@ def datapath():
def list_data(ext='.py'):
# return ['choice1_requires.py']
# if ext == '.py':
# return ['choice1_leadership_hidden.py']
datadir = datapath()
filenames = listdir(datadir)
filenames.sort()
ret = []
for filename in filenames:
if filename.endswith(ext) and not filename.startswith('__'):
# if filename.endswith(ext) and not filename.startswith('__'):
if filename.endswith(ext) and not filename.startswith('__') and not 'not_equal' in filename and not 'callback' in filename and not filename == 'unicode2_copy.py' and not filename == 'unicode2_multi_copy.py':
ret.append(filename)
return ret
def load_config(filename,
add_extra_od=False,
remote='minimum',
clearable='minimum',
root=None):
async def load_config(filename,
add_extra_od=False,
remote='minimum',
clearable='minimum',
root=None):
modulepath = splitext(filename)[0]
mod = __import__(modulepath)
descr = mod.get_description()
if add_extra_od:
descr = OptionDescription('root', '', [descr])
config = Config(descr)
config.property.add('demoting_error_warning')
config = await Config(descr)
await config.property.add('demoting_error_warning')
if 'get_values' in dir(mod):
mod.get_values(config, add_extra_od)
await mod.get_values(config, add_extra_od)
form = [{'title': 'Configurer',
'type': 'submit'}]
if 'get_form' in dir(mod):
form.extend(mod.get_form(add_extra_od))
config.property.read_write()
await config.property.read_write()
if root is None:
values = loads(dumps(config.option.dict(remotable=remote, clearable=clearable, form=form)))
values = loads(dumps(await config.option.dict(remotable=remote, clearable=clearable, form=form)))
else:
values = loads(dumps(config.option(root).dict(remotable=remote, clearable=clearable, form=form)))
values = loads(dumps(await config.option(root).dict(remotable=remote, clearable=clearable, form=form)))
return values
@ -148,7 +150,8 @@ def filename_mod(request):
return request.param
def test_jsons(filename):
@pytest.mark.asyncio
async def test_jsons(filename):
debug = False
# debug = True
datadir = datapath()
@ -165,9 +168,9 @@ def test_jsons(filename):
modulepath = splitext(filename)[0]
if debug:
print(" {} (remote: {}, clearable: {})".format(filename, remote, clearable))
values = load_config(filename,
remote=remote,
clearable=clearable)
values = await load_config(filename,
remote=remote,
clearable=clearable)
#
if not isfile(join(datadir, modulepath + '.json')) and \
clearable == 'minimum' and \
@ -214,7 +217,8 @@ def test_jsons(filename):
assert values == expected, "error in file {}".format(filename)
def test_jsons_subconfig(filename):
@pytest.mark.asyncio
async def test_jsons_subconfig(filename):
debug = False
# debug = True
datadir = datapath()
@ -223,7 +227,7 @@ def test_jsons_subconfig(filename):
modulepath = splitext(filename)[0]
if debug:
print(" ", filename)
values = load_config(filename, add_extra_od=True, root=modulepath)
values = await load_config(filename, add_extra_od=True, root=modulepath)
#
with open(join(datadir, modulepath + '.json'), 'r') as fh:
expected = loads(fh.read())
@ -288,7 +292,8 @@ def test_jsons_subconfig(filename):
assert values == expected, "error in file {}".format(filename)
def test_updates(filename_mod):
@pytest.mark.asyncio
async def test_updates(filename_mod):
debug = False
# debug = True
datadir = datapath()
@ -357,31 +362,31 @@ def test_updates(filename_mod):
if debug:
print(" (remote: {}, clearable: {}, issub {}, root {}, root_path {})".format(remote, clearable, issub, root, root_path))
for with_model in [False, True]:
config = Config(descr)
config.property.add('demoting_error_warning')
config = await Config(descr)
await config.property.add('demoting_error_warning')
if 'get_values' in dir(mod):
mod.get_values(config, issub)
await mod.get_values(config, issub)
if isfile(join(datadir, modulepath + '.mod')):
with open(join(datadir, modulepath + '.mod'), 'r') as fh:
eval(fh.read())
await eval(fh.read())
if dico_ori is None:
if clearable == 'minimum' and remote == 'minimum':
with open(join(datadir, modulepath + '.dict'), 'w') as fh:
dump(config.value.dict(), fh, indent=2)
dump(await config.value.dict(), fh, indent=2)
else:
assert config.value.dict() == dico_ori, "clearable {}, remote: {}, filename: {}".format(clearable, remote, filename_mod)
assert await config.value.dict() == dico_ori, "clearable {}, remote: {}, filename: {}".format(clearable, remote, filename_mod)
if root is None:
suboption = config.option
else:
suboption = config.option(root)
if with_model:
bodym = body.copy()
bodym['model'] = loads(dumps(suboption.dict(remotable=remote, clearable=clearable)))['model']
bodym['model'] = loads(dumps(await suboption.dict(remotable=remote, clearable=clearable)))['model']
else:
suboption.dict(remotable=remote, clearable=clearable)
await suboption.dict(remotable=remote, clearable=clearable)
bodym = body
if with_model:
cal_values = suboption.updates(bodym)
cal_values = await suboption.updates(bodym)
if values is None:
if clearable == 'minimum' and remote == 'minimum':
with open(join(datadir, modulepath + '.updates{}'.format(idx)), 'w') as fh:
@ -394,10 +399,10 @@ def test_updates(filename_mod):
pprint(values)
assert cal_values == values
else:
assert suboption.updates(bodym) is None
assert await suboption.updates(bodym) == {}
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)
dump(await config.value.dict(), fh, indent=2)
else:
assert config.value.dict() == dico_mod
assert await config.value.dict() == dico_mod

View File

@ -1,27 +1,16 @@
# coding: utf-8
from time import sleep, time
from py.test import raises
import pytest
from .autopath import do_autopath
do_autopath()
from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDescription, Leadership
from tiramisu import Config
from tiramisu import BoolOption, IPOption, IntOption, StrOption, OptionDescription, Leadership, Config, \
undefined, Calculation, Params, ParamValue, ParamOption, \
list_sessions, default_storage, delete_session, calc_value
from tiramisu.error import ConfigError, PropertiesOptionError
from tiramisu.setting import groups
from tiramisu import undefined, Params, ParamValue, ParamOption, \
list_sessions, default_storage, delete_session
def teardown_function(function):
if default_storage.is_persistent:
sessions = list_sessions()
if not sessions:
return
assert len(sessions) == 1
delete_session(sessions[0])
else:
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
from .config import event_loop
global incr
@ -32,10 +21,6 @@ def return_incr():
return int(incr/2) + 1
def return_value(val):
return val
def make_description():
u1 = IntOption('u1', '', multi=True)
u2 = IntOption('u2', '')
@ -43,260 +28,279 @@ def make_description():
return OptionDescription('od1', '', [u1, u2, u3])
def test_cache_config():
@pytest.mark.asyncio
async def test_cache_config():
od1 = make_description()
assert od1.impl_already_build_caches() is False
c = Config(od1)
assert od1.impl_already_build_caches() is True
c
async with await Config(od1) as cfg:
assert od1.impl_already_build_caches() is True
cfg
assert not await list_sessions()
def test_cache():
@pytest.mark.asyncio
async def test_cache():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
cfg.option('u2').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' in values._p_.get_cached()
assert 'u2' in settings._p_.get_cached()
async with await Config(od1) as cfg:
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
await cfg.option('u1').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
await cfg.option('u2').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' in values.get_cached()
assert 'u2' in settings.get_cached()
assert not await list_sessions()
def test_cache_importation():
@pytest.mark.asyncio
async def test_cache_importation():
od1 = make_description()
cfg = Config(od1)
cfg.option('u2').value.set(1)
export = cfg.value.exportation()
assert cfg.value.dict() == {'u1': [], 'u2': 1, 'u3': []}
cfg.option('u2').value.set(2)
assert cfg.value.dict() == {'u1': [], 'u2': 2, 'u3': []}
cfg.value.importation(export)
assert cfg.value.dict() == {'u1': [], 'u2': 1, 'u3': []}
async with await Config(od1) as cfg:
await cfg.option('u2').value.set(1)
export = await cfg.value.exportation()
assert await cfg.value.dict() == {'u1': [], 'u2': 1, 'u3': []}
await cfg.option('u2').value.set(2)
assert await cfg.value.dict() == {'u1': [], 'u2': 2, 'u3': []}
await cfg.value.importation(export)
assert await cfg.value.dict() == {'u1': [], 'u2': 1, 'u3': []}
assert not await list_sessions()
def test_cache_importation_property():
@pytest.mark.asyncio
async def test_cache_importation_property():
od1 = make_description()
cfg = Config(od1)
cfg.option('u2').property.add('prop')
export = cfg.property.exportation()
assert cfg.option('u2').property.get() == {'prop'}
cfg.option('u2').property.add('prop2')
assert cfg.option('u2').property.get() == {'prop', 'prop2'}
cfg.property.importation(export)
assert cfg.option('u2').property.get() == {'prop'}
async with await Config(od1) as cfg:
await cfg.option('u2').property.add('prop')
export = await cfg.property.exportation()
assert await cfg.option('u2').property.get() == {'prop'}
await cfg.option('u2').property.add('prop2')
assert await cfg.option('u2').property.get() == {'prop', 'prop2'}
await cfg.property.importation(export)
assert await cfg.option('u2').property.get() == {'prop'}
assert not await list_sessions()
def test_cache_importation_permissive():
@pytest.mark.asyncio
async def test_cache_importation_permissive():
od1 = make_description()
cfg = Config(od1)
cfg.option('u2').permissive.set(frozenset(['prop']))
export = cfg.permissive.exportation()
assert cfg.option('u2').permissive.get() == {'prop'}
cfg.option('u2').permissive.set(frozenset(['prop', 'prop2']))
assert cfg.option('u2').permissive.get() == {'prop', 'prop2'}
cfg.permissive.importation(export)
assert cfg.option('u2').permissive.get() == {'prop'}
async with await Config(od1) as cfg:
await cfg.option('u2').permissive.set(frozenset(['prop']))
export = await cfg.permissive.exportation()
assert await cfg.option('u2').permissive.get() == {'prop'}
await cfg.option('u2').permissive.set(frozenset(['prop', 'prop2']))
assert await cfg.option('u2').permissive.get() == {'prop', 'prop2'}
await cfg.permissive.importation(export)
assert await cfg.option('u2').permissive.get() == {'prop'}
assert not await list_sessions()
def test_cache_reset():
@pytest.mark.asyncio
async def test_cache_reset():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
#when change a value
cfg.option('u1').value.get()
cfg.option('u2').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' in values._p_.get_cached()
assert 'u2' in settings._p_.get_cached()
assert 'u1' in values._p_.get_cached()
cfg.option('u2').value.set(1)
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
#when remove a value
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
cfg.option('u2').value.reset()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
#when add/del property
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
cfg.option('u2').property.add('test')
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
cfg.option('u2').property.pop('test')
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
#when enable/disabled property
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
cfg.property.add('test')
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
cfg.property.pop('test')
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
async with await Config(od1) as cfg:
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
#when change a value
await cfg.option('u1').value.get()
await cfg.option('u2').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' in values.get_cached()
assert 'u2' in settings.get_cached()
assert 'u1' in values.get_cached()
settings.get_cached()
await cfg.option('u2').value.set(1)
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' in values.get_cached()
assert 'u2' not in settings.get_cached()
#when remove a value
await cfg.option('u1').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
await cfg.option('u2').value.reset()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' not in values.get_cached()
assert 'u2' not in settings.get_cached()
#when add/del property
await cfg.option('u1').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
await cfg.option('u2').property.add('test')
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' not in values.get_cached()
assert 'u2' not in settings.get_cached()
await cfg.option('u1').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
await cfg.option('u2').property.pop('test')
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' not in values.get_cached()
assert 'u2' not in settings.get_cached()
#when enable/disabled property
await cfg.option('u1').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
await cfg.property.add('test')
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
await cfg.option('u1').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
await cfg.property.pop('test')
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
assert not await list_sessions()
def test_cache_reset_multi():
@pytest.mark.asyncio
async def test_cache_reset_multi():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.option('u1').value.get()
cfg.option('u3').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
#when change a value
cfg.option('u3').value.set([1])
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
#when append value
cfg.option('u1').value.get()
cfg.option('u3').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
cfg.option('u3').value.set([1, 1])
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
#when pop value
cfg.option('u1').value.get()
cfg.option('u3').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' in values._p_.get_cached()
assert 'u3' in settings._p_.get_cached()
cfg.option('u3').value.set([1])
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
#when remove a value
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
cfg.option('u3').value.reset()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u3' not in values._p_.get_cached()
assert 'u3' not in settings._p_.get_cached()
async with await Config(od1) as cfg:
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
await cfg.option('u1').value.get()
await cfg.option('u3').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' in values.get_cached()
assert 'u3' in settings.get_cached()
#when change a value
await cfg.option('u3').value.set([1])
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' in values.get_cached()
assert 'u3' not in settings.get_cached()
#when append value
await cfg.option('u1').value.get()
await cfg.option('u3').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' in values.get_cached()
assert 'u3' in settings.get_cached()
await cfg.option('u3').value.set([1, 2])
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' in values.get_cached()
assert 'u3' not in settings.get_cached()
#when pop value
await cfg.option('u1').value.get()
await cfg.option('u3').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' in values.get_cached()
assert 'u3' in settings.get_cached()
await cfg.option('u3').value.set([1])
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' in values.get_cached()
assert 'u3' not in settings.get_cached()
#when remove a value
await cfg.option('u1').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
await cfg.option('u3').value.reset()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u3' not in values.get_cached()
assert 'u3' not in settings.get_cached()
assert not await list_sessions()
def test_reset_cache():
@pytest.mark.asyncio
async def test_reset_cache():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
cfg.cache.reset()
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
cfg.option('u1').value.get()
cfg.option('u2').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
assert 'u2' in values._p_.get_cached()
assert 'u2' in settings._p_.get_cached()
cfg.cache.reset()
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
assert 'u2' not in settings._p_.get_cached()
async with await Config(od1) as cfg:
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
await cfg.option('u1').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
await cfg.cache.reset()
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
await cfg.option('u1').value.get()
await cfg.option('u2').value.get()
assert 'u1' in values.get_cached()
assert 'u1' in settings.get_cached()
assert 'u2' in values.get_cached()
assert 'u2' in settings.get_cached()
await cfg.cache.reset()
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
assert 'u2' not in values.get_cached()
assert 'u2' not in settings.get_cached()
assert not await list_sessions()
def test_cache_not_cache():
@pytest.mark.asyncio
async def test_cache_not_cache():
od1 = make_description()
cfg = Config(od1)
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.property.pop('cache')
cfg.option('u1').value.get()
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
async with await Config(od1) as cfg:
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
await cfg.property.pop('cache')
await cfg.option('u1').value.get()
assert 'u1' not in values.get_cached()
assert 'u1' not in settings.get_cached()
assert not await list_sessions()
def test_cache_leadership():
@pytest.mark.asyncio
async def test_cache_leadership():
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
cache = cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached()
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2']
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
cache = cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached()
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0])
#
cfg.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.get()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
cache = cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached()
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2', '192.168.1.1']
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
#assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None
cache = cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached()
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0, 1])
#DEL, insert, ...
def return_value(value=None):
return value
od1 = OptionDescription('toto', '', [interface1])
async with await Config(od1) as cfg:
await cfg.property.read_write()
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
assert values.get_cached() == {}
#assert settings.get_cached() == {}
#
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
cache = values.get_cached()
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2']
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
cache = settings.get_cached()
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([0, None])
#
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
cache = values.get_cached()
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
assert cache['ip_admin_eth0.ip_admin_eth0'][None][0] == ['192.168.1.2', '192.168.1.1']
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
#assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None
cache = settings.get_cached()
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None, 0, 1])
#DEL, insert, ...
assert not await list_sessions()
def compare(calculated, expected):
@ -308,275 +312,299 @@ def compare(calculated, expected):
assert calculated[calculated_key][calculated_subkey][0] == expected[calculated_key][calculated_subkey][0]
def test_cache_callback():
@pytest.mark.asyncio
async def test_cache_callback():
val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", callback=return_value, callback_params=Params((ParamOption(val1),)), properties=('mandatory',))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params((ParamValue('yes'),)))
val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val5 = StrOption('val5', "", callback=return_value, callback_params=Params(kwargs={'value': ParamValue('yes')}), multi=True)
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
cfg = Config(maconfig)
cfg.property.read_write()
cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('val', None)},
'val2': {None: ('val', None)},
'val3': {None: ('yes', None)},
'val4': {None: ('val', None)},
'val5': {None: (['yes'], None)}})
cfg.option('val1').value.set('new')
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val3': {None: ('yes', None)},
'val5': {None: (['yes'], None)}})
cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('yes', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
cfg.option('val3').value.set('new2')
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
cfg.option('val4').value.set('new3')
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val5': {None: (['yes'], None)}})
cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)},
'val5': {None: (['yes'], None)}})
cfg.option('val5').value.set([undefined, 'new4'])
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)},
# 'val5': {None: (set(['empty']), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}})
cfg.value.dict()
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)},
# 'val5': {None: (set(['empty']), None)}}
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)},
'val5': {None: (['yes', 'new4'], None)}})
val2 = StrOption('val2', "", Calculation(calc_value, Params(ParamOption(val1))), properties=('mandatory',))
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamValue('yes'))))
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val1))))
val5 = StrOption('val5', "", [Calculation(calc_value, Params(ParamValue('yes')))], multi=True)
od1 = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
async with await Config(od1) as cfg:
await cfg.property.read_write()
await cfg.value.dict()
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
compare(values.get_cached(), {'val1': {None: ('val', None)},
'val2': {None: ('val', None)},
'val3': {None: ('yes', None)},
'val4': {None: ('val', None)},
'val5': {None: (['yes'], None)}})
await cfg.option('val1').value.set('new')
compare(values.get_cached(), {'val3': {None: ('yes', None)},
'val1': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
await cfg.value.dict()
compare(values.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('yes', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
await cfg.option('val3').value.set('new2')
compare(values.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val4': {None: ('new', None)},
'val1': {None: ('new', None)},
'val3': {None: ('new2', None, True)},
'val5': {None: (['yes'], None)}})
await cfg.value.dict()
compare(values.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
await cfg.option('val4').value.set('new3')
compare(values.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None, True)},
'val5': {None: (['yes'], None)}})
await cfg.value.dict()
compare(values.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)},
'val5': {None: (['yes'], None)}})
await cfg.option('val5').value.set([undefined, 'new4'])
compare(values.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)},
'val5': {None: (['yes', 'new4'], None)}})
await cfg.value.dict()
compare(values.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)},
'val5': {None: (['yes', 'new4'], None)}})
assert not await list_sessions()
def test_cache_leader_and_followers():
@pytest.mark.asyncio
async def test_cache_leader_and_followers():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg.value.dict()
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
val1_props = []
val1_val1_props = ['empty']
val1_val2_props = []
global_props = frozenset(global_props)
val1_props = frozenset(val1_props)
val1_val1_props = frozenset(val1_val1_props)
val1_val2_props = frozenset(val1_val2_props)
#None because no value
idx_val2 = None
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': {idx_val2: (val1_val2_props, None)}})
# len is 0 so don't get any value
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
#
cfg.option('val1.val1').value.set([undefined])
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(global_props), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.value.dict()
#has value
idx_val2 = 0
val_val2 = None
val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)}
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': val_val2_props})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([None], None)},
'val1.val2': {idx_val2: (val_val2, None)}})
cfg.option('val1.val1').value.set([undefined, undefined])
cfg.value.dict()
cfg.option('val1.val2', 1).value.set('oui')
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)}
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
# 'val1': {None: (val1_props, None)},
# 'val1.val1': {None: (val1_val1_props, None)},
# 'val1.val2': val1_val2_props}
#if TIRAMISU_VERSION == 2:
# assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
# 'val1.val2': {None: ([None, 'oui'], None)}}
#else:
# assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
# 'val1.val2': {0: (None, None), 1: ('oui', None)}}
od1 = OptionDescription('rootconfig', '', [interface1])
async with await Config(od1) as cfg:
await cfg.property.read_write()
await cfg.value.dict()
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
val1_props = []
val1_val1_props = ['empty', 'unique']
val1_val2_props = []
global_props = frozenset(global_props)
val1_props = frozenset(val1_props)
val1_val1_props = frozenset(val1_val1_props)
val1_val2_props = frozenset(val1_val2_props)
#None because no value
idx_val2 = None
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
compare(settings.get_cached(), {None: {None: (global_props, None)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': {idx_val2: (val1_val2_props, None)}})
# len is 0 so don't get any value
compare(values.get_cached(), {'val1.val1': {None: ([], None)}})
#
await cfg.option('val1.val1').value.set([undefined])
val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)}
compare(settings.get_cached(), {None: {None: (set(global_props), None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': val_val2_props})
compare(values.get_cached(), {'val1.val1': {None: ([None], None, True)}})
await cfg.value.dict()
#has value
idx_val2 = 0
val_val2 = None
val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)}
compare(settings.get_cached(), {None: {None: (global_props, None)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': val_val2_props})
compare(values.get_cached(), {'val1.val1': {None: ([None], None)},
'val1.val2': {idx_val2: (val_val2, None)}})
await cfg.option('val1.val1').value.set([undefined, undefined])
await cfg.value.dict()
await cfg.option('val1.val2', 1).value.set('oui')
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
compare(values.get_cached(), {'val1.val2': {1: ('oui', None, True)}})
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)}
assert not await list_sessions()
def test_cache_leader_callback():
@pytest.mark.asyncio
async def test_cache_leader_callback():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val2 = StrOption('val2', "", Calculation(calc_value, Params(kwargs={'value': ParamOption(val1)})), multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg.value.dict()
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
val1_props = []
val1_val1_props = ['empty']
val1_val2_props = []
global_props = frozenset(global_props)
val1_props = frozenset(val1_props)
val1_val1_props = frozenset(val1_val1_props)
val1_val2_props = frozenset(val1_val2_props)
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': {None: (val1_val2_props, None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
cfg.option('val1.val1').value.set([undefined])
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(global_props), None)}})
od1 = OptionDescription('rootconfig', '', [interface1])
async with await Config(od1) as cfg:
await cfg.property.read_write()
await cfg.value.dict()
global_props = ['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']
val1_props = []
val1_val1_props = ['empty', 'unique']
val1_val2_props = []
global_props = frozenset(global_props)
val1_props = frozenset(val1_props)
val1_val1_props = frozenset(val1_val1_props)
val1_val2_props = frozenset(val1_val2_props)
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
compare(settings.get_cached(), {None: {None: (global_props, None)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': {None: (val1_val2_props, None)}})
compare(values.get_cached(), {'val1.val1': {None: ([], None)}})
await cfg.option('val1.val1').value.set([undefined])
compare(settings.get_cached(), {None: {None: (set(global_props), None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': {None: (val1_val2_props, None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.value.dict()
#FIXMEassert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}}
#FIXMEassert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
# 'val1.val2': {None: ([None], None)}
# }
compare(values.get_cached(), {'val1.val1': {None: ([None], None, True)}})
await cfg.value.dict()
assert not await list_sessions()
def test_cache_requires():
@pytest.mark.asyncio
async def test_cache_requires():
a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b])
cfg = Config(od)
cfg.property.read_write()
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(a),
'expected': ParamValue(False),
'default': ParamValue(None)}))
b = IPOption('ip_address_service', '', properties=(disabled_property,))
od1 = OptionDescription('service', '', [a, b])
async with await Config(od1) as cfg:
await cfg.property.read_write()
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
assert values.get_cached() == {}
assert await cfg.option('ip_address_service').value.get() == None
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
cfg.value.dict()
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
compare(values.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
await cfg.value.dict()
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
cfg.option('ip_address_service').value.set('1.1.1.1')
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}})
compare(values.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
await cfg.option('ip_address_service').value.set('1.1.1.1')
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}})
cfg.value.dict()
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
compare(values.get_cached(), {'activate_service': {None: (True, None)}, 'ip_address_service': {None: ('1.1.1.1', None, True)}})
await cfg.value.dict()
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)},
'activate_service': {None: (True, None)}})
cfg.option('activate_service').value.set(False)
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
compare(values.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)},
'activate_service': {None: (True, None)}})
await cfg.option('activate_service').value.set(False)
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.value.dict()
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set(['disabled']), None)}})
compare(values.get_cached(), {'activate_service': {None: (False, None)}})
await cfg.value.dict()
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set(['disabled']), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (False, None)}})
compare(values.get_cached(), {'activate_service': {None: (False, None)}})
assert not await list_sessions()
def test_cache_global_properties():
@pytest.mark.asyncio
async def test_cache_global_properties():
a = BoolOption('activate_service', '', True)
b = IPOption('ip_address_service', '',
requires=[{'option': a, 'expected': False, 'action': 'disabled'}])
od = OptionDescription('service', '', [a, b])
cfg = Config(od)
cfg.property.read_write()
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(a),
'expected': ParamValue(False),
'default': ParamValue(None)}))
b = IPOption('ip_address_service', '', properties=(disabled_property,))
od1 = OptionDescription('service', '', [a, b])
async with await Config(od1) as cfg:
await cfg.property.read_write()
values = cfg._config_bag.context._impl_values_cache
settings = cfg._config_bag.context._impl_properties_cache
assert values.get_cached() == {}
assert await cfg.option('ip_address_service').value.get() == None
compare(settings.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
cfg.property.pop('disabled')
assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
cfg.property.add('test')
assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
compare(values.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
await cfg.property.pop('disabled')
assert await cfg.option('ip_address_service').value.get() == None
compare(settings.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
await cfg.property.add('test')
assert await cfg.option('ip_address_service').value.get() == None
compare(settings.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test', 'force_store_value']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
assert not await list_sessions()
def test_callback_value_incr():
val1 = IntOption('val1', "", callback=return_incr, properties=('expire',))
val2 = IntOption('val2', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
maconfig = OptionDescription('rootconfig', '', [val1, val2])
cfg = Config(maconfig)
assert cfg.cache.get_expiration_time() == 5
cfg.cache.set_expiration_time(1)
assert cfg.cache.get_expiration_time() == 1
cfg.property.read_write()
assert cfg.option('val1').value.get() == 1
sleep(1)
assert cfg.option('val2').value.get() == 1
sleep(1)
assert cfg.option('val1').value.get() == 1
assert cfg.option('val2').value.get() == 1
sleep(2)
assert cfg.option('val1').value.get() == 2
assert cfg.option('val2').value.get() == 2
assert cfg.option('val1').value.get() == 2
assert cfg.option('val2').value.get() == 2
@pytest.mark.asyncio
async def test_callback_value_incr():
global incr
incr = -1
val1 = IntOption('val1', "", Calculation(return_incr), properties=('expire',))
val2 = IntOption('val2', "", Calculation(calc_value, Params(ParamOption(val1))))
od1 = OptionDescription('rootconfig', '', [val1, val2])
async with await Config(od1) as cfg:
assert await cfg.cache.get_expiration_time() == 5
await cfg.cache.set_expiration_time(1)
assert await cfg.cache.get_expiration_time() == 1
await cfg.property.read_write()
assert await cfg.option('val1').value.get() == 1
sleep(1)
assert await cfg.option('val2').value.get() == 1
sleep(1)
assert await cfg.option('val1').value.get() == 1
assert await cfg.option('val2').value.get() == 1
sleep(2)
assert await cfg.option('val1').value.get() == 2
assert await cfg.option('val2').value.get() == 2
assert await cfg.option('val1').value.get() == 2
assert await cfg.option('val2').value.get() == 2
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_value_incr_demoting():
global incr
incr = -1
val1 = IntOption('val1', "", Calculation(return_incr), properties=('expire',))
val2 = IntOption('val2', "", Calculation(calc_value, Params(ParamOption(val1))))
od1 = OptionDescription('rootconfig', '', [val1, val2])
async with await Config(od1) as cfg:
await cfg.property.add('demoting_error_warning')
assert await cfg.cache.get_expiration_time() == 5
await cfg.cache.set_expiration_time(1)
assert await cfg.cache.get_expiration_time() == 1
await cfg.property.read_write()
assert await cfg.option('val1').value.get() == 1
sleep(1)
assert await cfg.option('val2').value.get() == 1
sleep(1)
assert await cfg.option('val1').value.get() == 1
assert await cfg.option('val2').value.get() == 1
sleep(2)
assert await cfg.option('val1').value.get() == 2
assert await cfg.option('val2').value.get() == 2
assert await cfg.option('val1').value.get() == 2
assert await cfg.option('val2').value.get() == 2
assert not await list_sessions()

View File

@ -1,19 +1,14 @@
# coding: utf-8
from py.test import raises
import pytest
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from .config import config_type, get_config, value_list, global_owner, event_loop
from tiramisu.setting import owners
from tiramisu import ChoiceOption, StrOption, OptionDescription, Config
from tiramisu import ChoiceOption, StrOption, OptionDescription, Config, owners, Calculation, \
undefined, Params, ParamValue, ParamOption, list_sessions
from tiramisu.error import ConfigError
from tiramisu import undefined, Params, ParamValue, ParamOption
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def return_val(val):
@ -32,228 +27,250 @@ def return_error(*args, **kwargs):
raise Exception('test')
def test_choiceoption(config_type):
@pytest.mark.asyncio
async def test_choiceoption(config_type):
choice = ChoiceOption('choice', '', values=('val1', 'val2'))
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
cfg.property.read_write()
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.isdefault()
#
cfg.option('choice').value.set('val1')
assert cfg.option('choice').owner.get() == owner
assert not cfg.option('choice').owner.isdefault()
#
cfg.option('choice').value.reset()
assert cfg.option('choice').owner.get() == owners.default
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('choice').value.set('no')")
assert cfg.option('choice').owner.get() == owners.default
assert cfg.option('choice').owner.isdefault()
#
assert value_list(cfg.option('choice').value.list()) == ('val1', 'val2')
async with await Config(odesc) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
owner = await global_owner(cfg, config_type)
assert await cfg.option('choice').owner.get() == owners.default
assert await cfg.option('choice').owner.isdefault()
#
await cfg.option('choice').value.set('val1')
assert await cfg.option('choice').owner.get() == owner
assert not await cfg.option('choice').owner.isdefault()
#
await cfg.option('choice').value.reset()
assert await cfg.option('choice').owner.get() == owners.default
assert await cfg.option('choice').owner.isdefault()
#
with pytest.raises(ValueError):
await cfg.option('choice').value.set('no')
assert await cfg.option('choice').owner.get() == owners.default
assert await cfg.option('choice').owner.isdefault()
#
assert value_list(await cfg.option('choice').value.list()) == ('val1', 'val2')
assert not await list_sessions()
def test_choiceoption_function(config_type):
choice = ChoiceOption('choice', '', values=return_list)
@pytest.mark.asyncio
async def test_choiceoption_function(config_type):
choice = ChoiceOption('choice', '', values=Calculation(return_list))
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
owner = global_owner(cfg, config_type)
assert cfg.option('choice').owner.isdefault()
#
cfg.option('choice').value.set('val1')
assert cfg.option('choice').owner.get() == owner
#
cfg.option('choice').value.reset()
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('choice').value.set('no')")
assert cfg.option('choice').owner.isdefault()
#
assert value_list(cfg.option('choice').value.list()) == ('val1', 'val2')
async with await Config(odesc) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
owner = await global_owner(cfg, config_type)
assert await cfg.option('choice').owner.isdefault()
#
await cfg.option('choice').value.set('val1')
assert await cfg.option('choice').owner.get() == owner
#
await cfg.option('choice').value.reset()
assert await cfg.option('choice').owner.isdefault()
#
with pytest.raises(ValueError):
await cfg.option('choice').value.set('no')
assert await cfg.option('choice').owner.isdefault()
#
assert value_list(await cfg.option('choice').value.list()) == ('val1', 'val2')
assert not await list_sessions()
def test_choiceoption_function_error():
choice = ChoiceOption('choice', '', values=return_error)
@pytest.mark.asyncio
async def test_choiceoption_function_error():
choice = ChoiceOption('choice', '', values=Calculation(return_error))
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
cfg.property.read_write()
raises(ConfigError, "cfg.option('choice').value.set('val1')")
async with await Config(odesc) as cfg:
await cfg.property.read_write()
with pytest.raises(ConfigError):
await cfg.option('choice').value.set('val1')
assert not await list_sessions()
def test_choiceoption_function_error_args():
choice = ChoiceOption('choice', '', values=return_error, values_params=Params((ParamValue('val1'),)))
@pytest.mark.asyncio
async def test_choiceoption_function_error_args():
choice = ChoiceOption('choice', '', values=Calculation(return_error, Params(ParamValue('val1'))))
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
cfg.property.read_write()
raises(ConfigError, "cfg.option('choice').value.set('val1')")
async with await Config(odesc) as cfg:
await cfg.property.read_write()
with pytest.raises(ConfigError):
await cfg.option('choice').value.set('val1')
assert not await list_sessions()
def test_choiceoption_function_error_kwargs():
choice = ChoiceOption('choice', '', values=return_error, values_params=Params(kwargs={'kwargs': ParamValue('val1')}))
@pytest.mark.asyncio
async def test_choiceoption_function_error_kwargs():
choice = ChoiceOption('choice', '', values=Calculation(return_error, Params(kwargs={'kwargs': ParamValue('val1')})))
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
cfg.property.read_write()
raises(ConfigError, "cfg.option('choice').value.set('val1')")
async with await Config(odesc) as cfg:
await cfg.property.read_write()
with pytest.raises(ConfigError):
await cfg.option('choice').value.set('val1')
assert not await list_sessions()
def test_choiceoption_calc_function(config_type):
choice = ChoiceOption('choice', "", values=return_calc_list, values_params=Params((ParamValue('val1'),)))
@pytest.mark.asyncio
async def test_choiceoption_calc_function(config_type):
choice = ChoiceOption('choice', "", values=Calculation(return_calc_list, Params(ParamValue('val1'))))
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
owner = global_owner(cfg, config_type)
assert cfg.option('choice').owner.isdefault()
#
cfg.option('choice').value.set('val1')
assert cfg.option('choice').owner.get() == owner
#
cfg.option('choice').value.reset()
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('choice').value.set('no')")
assert cfg.option('choice').owner.isdefault()
async with await Config(odesc) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
owner = await global_owner(cfg, config_type)
assert await cfg.option('choice').owner.isdefault()
#
await cfg.option('choice').value.set('val1')
assert await cfg.option('choice').owner.get() == owner
#
await cfg.option('choice').value.reset()
assert await cfg.option('choice').owner.isdefault()
#
with pytest.raises(ValueError):
await cfg.option('choice').value.set('no')
assert await cfg.option('choice').owner.isdefault()
assert not await list_sessions()
def test_choiceoption_calc_opt_function(config_type):
@pytest.mark.asyncio
async def test_choiceoption_calc_opt_function(config_type):
str_ = StrOption('str', '', 'val1')
choice = ChoiceOption('choice',
"",
values=return_calc_list,
values_params=Params((ParamOption(str_),)))
values=Calculation(return_calc_list, Params(ParamOption(str_))))
odesc = OptionDescription('od', '', [str_, choice])
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type)
assert cfg.option('choice').owner.isdefault()
#
cfg.option('choice').value.set('val1')
assert cfg.option('choice').owner.get() == owner
#
cfg.option('choice').value.reset()
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('choice').value.set('no')")
assert cfg.option('choice').owner.isdefault()
async with await Config(odesc) as cfg:
await cfg.property.read_write()
owner = await cfg.owner.get()
cfg = await get_config(cfg, config_type)
assert await cfg.option('choice').owner.isdefault()
#
await cfg.option('choice').value.set('val1')
assert await cfg.option('choice').owner.get() == owner
#
await cfg.option('choice').value.reset()
assert await cfg.option('choice').owner.isdefault()
#
with pytest.raises(ValueError):
await cfg.option('choice').value.set('no')
assert await cfg.option('choice').owner.isdefault()
assert not await list_sessions()
def test_choiceoption_calc_opt_function_propertyerror():
@pytest.mark.asyncio
async def test_choiceoption_calc_opt_function_propertyerror():
str_ = StrOption('str', '', 'val1', properties=('disabled',))
choice = ChoiceOption('choice',
"",
values=return_calc_list,
values_params=Params((ParamOption(str_),)))
values=Calculation(return_calc_list, Params(ParamOption(str_))))
odesc = OptionDescription('od', '', [str_, choice])
cfg = Config(odesc)
cfg.property.read_write()
raises(ConfigError, "cfg.option('choice').value.set('no')")
async with await Config(odesc) as cfg:
await cfg.property.read_write()
with pytest.raises(ConfigError):
await cfg.option('choice').value.set('no')
assert not await list_sessions()
#def test_choiceoption_calc_opt_multi_function(config_type):
def test_choiceoption_calc_opt_multi_function():
@pytest.mark.asyncio
async def test_choiceoption_calc_opt_multi_function():
# FIXME
config_type = 'tiramisu'
str_ = StrOption('str', '', ['val1'], multi=True)
choice = ChoiceOption('choice',
"",
default_multi='val2',
values=return_val,
values_params=Params((ParamOption(str_),)),
values=Calculation(return_val, Params(ParamOption(str_))),
multi=True)
ch2 = ChoiceOption('ch2',
"",
default=['val2'],
values=return_val,
values_params=Params((ParamOption(str_),)),
values=Calculation(return_val, Params(ParamOption(str_))),
multi=True)
odesc = OptionDescription('od', '', [str_, choice, ch2])
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type, True)
assert cfg.option('choice').owner.isdefault()
assert cfg.option('choice').value.get() == []
#
cfg.option('choice').value.set(['val1'])
assert cfg.option('choice').owner.get() == owner
#
raises(ValueError, "cfg.option('choice').value.set([undefined])")
#
cfg.option('choice').value.set(['val1'])
assert cfg.option('choice').owner.get() == owner
#
cfg.option('choice').value.reset()
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('choice').value.set('no')")
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('ch2').value.get()")
async with await Config(odesc) as cfg:
await cfg.property.read_write()
owner = await cfg.owner.get()
cfg = await get_config(cfg, config_type, True)
assert await cfg.option('choice').owner.isdefault()
assert await cfg.option('choice').value.get() == []
#
await cfg.option('choice').value.set(['val1'])
assert await cfg.option('choice').owner.get() == owner
#
with pytest.raises(ValueError):
await cfg.option('choice').value.set([undefined])
#
await cfg.option('choice').value.set(['val1'])
assert await cfg.option('choice').owner.get() == owner
#
await cfg.option('choice').value.reset()
assert await cfg.option('choice').owner.isdefault()
#
with pytest.raises(ValueError):
await cfg.option('choice').value.set('no')
assert await cfg.option('choice').owner.isdefault()
#
with pytest.raises(ValueError):
await cfg.option('ch2').value.get()
assert not await list_sessions()
def test_choiceoption_calc_opt_multi_function_kwargs(config_type):
@pytest.mark.asyncio
async def test_choiceoption_calc_opt_multi_function_kwargs(config_type):
str_ = StrOption('str', '', ['val1'], multi=True)
choice = ChoiceOption('choice',
"",
default_multi='val2',
values=return_val,
values_params=Params(kwargs={'val': ParamOption(str_)}),
values=Calculation(return_val, Params(kwargs={'val': ParamOption(str_)})),
multi=True)
ch2 = ChoiceOption('ch2',
"",
default=['val2'],
values=return_val,
values_params=Params(kwargs={'val': ParamOption(str_)}),
values=Calculation(return_val, Params(kwargs={'val': ParamOption(str_)})),
multi=True)
odesc = OptionDescription('od', '', [str_, choice, ch2])
cfg = Config(odesc)
cfg.property.read_write()
owner = cfg.owner.get()
# FIXME cfg = get_config(cfg, config_type)
assert cfg.option('choice').owner.isdefault()
assert cfg.option('choice').value.get() == []
#
cfg.option('choice').value.set(['val1'])
assert cfg.option('choice').owner.get() == owner
#
raises(ValueError, "cfg.option('choice').value.set([undefined])")
#
cfg.option('choice').value.set(['val1'])
assert cfg.option('choice').owner.get() == owner
#
cfg.option('choice').value.reset()
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('choice').value.set('no')")
assert cfg.option('choice').owner.isdefault()
#
raises(ValueError, "cfg.option('ch2').value.get()")
async with await Config(odesc) as cfg:
await cfg.property.read_write()
owner = await cfg.owner.get()
# FIXME cfg = await get_config(cfg, config_type)
assert await cfg.option('choice').owner.isdefault()
assert await cfg.option('choice').value.get() == []
#
await cfg.option('choice').value.set(['val1'])
assert await cfg.option('choice').owner.get() == owner
#
with pytest.raises(ValueError):
await cfg.option('choice').value.set([undefined])
#
await cfg.option('choice').value.set(['val1'])
assert await cfg.option('choice').owner.get() == owner
#
await cfg.option('choice').value.reset()
assert await cfg.option('choice').owner.isdefault()
#
with pytest.raises(ValueError):
await cfg.option('choice').value.set('no')
assert await cfg.option('choice').owner.isdefault()
#
with pytest.raises(ValueError):
await cfg.option('ch2').value.get()
assert not await list_sessions()
def test_choiceoption_calc_invalid():
str_ = StrOption('str', '', ['val1'], multi=True)
str_
raises(ValueError,
"choice = ChoiceOption('choice', '', default_multi='val2', values=[1, 2, 3], \
values_params=Params((ParamOption(str_),)), multi=True)")
def test_choiceoption_calc_not_list():
@pytest.mark.asyncio
async def test_choiceoption_calc_not_list():
str_ = StrOption('str', '', 'val1')
choice = ChoiceOption('choice',
"",
default_multi='val2',
values=return_val,
values_params=Params((ParamOption(str_),)),
values=Calculation(return_val, Params(ParamOption(str_))),
multi=True)
odesc = OptionDescription('od', '', [str_, choice])
cfg = Config(odesc)
cfg.property.read_write()
raises(ConfigError, "cfg.option('choice').value.set(['val1'])")
async with await Config(odesc) as cfg:
await cfg.property.read_write()
with pytest.raises(ConfigError):
await cfg.option('choice').value.set(['val1'])
assert not await list_sessions()

View File

@ -2,26 +2,22 @@
"""theses tests are much more to test that config, option description, vs...
**it's there** and answers via attribute access"""
from py.test import raises
import weakref
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from .config import config_type, get_config, value_list, global_owner, event_loop
import pytest
from tiramisu import Config
from tiramisu.config import SubConfig
from tiramisu.i18n import _
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
BoolOption, UnicodeOption, SymLinkOption, OptionDescription, undefined
from tiramisu import Config, IntOption, FloatOption, ChoiceOption, \
BoolOption, StrOption, SymLinkOption, OptionDescription, undefined, delete_session
from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError, APIError
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def make_description():
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
@ -45,325 +41,391 @@ def make_description():
return descr
def test_base_config(config_type):
@pytest.mark.asyncio
async def test_base_config(config_type):
"""making a :class:`tiramisu.config.Config()` object
and a :class:`tiramisu.option.OptionDescription()` object
"""
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('dummy').value.get() is False
#dmo = cfg.unwrap_from_path('dummy')
#assert dmo.impl_getname() == 'dummy'
async with await Config(descr) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('dummy').value.get() is False
#dmo = await cfg.unwrap_from_path('dummy')
#assert dmo.impl_getname() == 'dummy'
assert not await list_sessions()
def test_base_config_name():
@pytest.mark.asyncio
async def test_base_config_name():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
cfg = Config(descr, session_id='cfg')
cfg.config.name() == 'cfg'
#raises(ValueError, "Config(descr, session_id='unvalid name')")
async with await Config(descr, session_id='cfg') as cfg:
await cfg.session.id() == 'cfg'
#raises(ValueError, "Config(descr, session_id='unvalid name')")
assert not await list_sessions()
#
#
#def test_not_config():
#@pytest.mark.asyncio
#async def test_not_config():
# assert raises(TypeError, "Config('str')")
def test_base_path():
@pytest.mark.asyncio
async def test_base_path():
gcdummy = BoolOption('dummy', 'dummy', default=False)
descr = OptionDescription('tiramisu', '', [gcdummy])
Config(descr)
base = OptionDescription('config', '', [descr])
base
raises(ConfigError, "Config(base)")
async with await Config(descr) as cfg:
base = OptionDescription('config', '', [descr])
with pytest.raises(ConfigError):
async with await Config(base, session_id='error'):
pass
await delete_session('error')
assert not await list_sessions()
def test_base_config_force_permissive():
@pytest.mark.asyncio
async def test_base_config_force_permissive():
descr = make_description()
config = Config(descr)
config.property.read_write()
config.permissive.set(frozenset(['hidden']))
raises(PropertiesOptionError, "config.option('boolop').value.get()")
assert config.forcepermissive.option('boolop').value.get() is True
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.permissive.add('hidden')
with pytest.raises(PropertiesOptionError):
await cfg.option('boolop').value.get()
assert await cfg.forcepermissive.option('boolop').value.get() is True
assert not await list_sessions()
def test_base_config_in_a_tree():
@pytest.mark.asyncio
async def test_base_config_in_a_tree():
# FIXME
config_type = 'tiramisu'
"how options are organized into a tree, see :ref:`tree`"
descr = make_description()
config = Config(descr)
config = get_config(config, config_type)
#
config.option('bool').value.set(False)
#
assert config.option('gc.name').value.get() == 'ref'
config.option('gc.name').value.set('framework')
assert config.option('gc.name').value.get() == 'framework'
#
assert config.option('objspace').value.get() == 'std'
config.option('objspace').value.set('thunk')
assert config.option('objspace').value.get() == 'thunk'
#
assert config.option('gc.float').value.get() == 2.3
config.option('gc.float').value.set(3.4)
assert config.option('gc.float').value.get() == 3.4
#
assert config.option('int').value.get() == 0
config.option('int').value.set(123)
assert config.option('int').value.get() == 123
#
assert config.option('wantref').value.get() is False
config.option('wantref').value.set(True)
assert config.option('wantref').value.get() is True
#
assert config.option('str').value.get() == 'abc'
config.option('str').value.set('def')
assert config.option('str').value.get() == 'def'
#
raises(AttributeError, "config.option('gc.foo').value.get()")
##
config = Config(descr)
assert config.option('bool').value.get() is True
assert config.option('gc.name').value.get() == 'ref'
assert config.option('wantframework').value.get() is False
async with await Config(descr) as cfg:
cfg = await get_config(cfg, config_type)
#
await cfg.option('bool').value.set(False)
#
assert await cfg.option('gc.name').value.get() == 'ref'
await cfg.option('gc.name').value.set('framework')
assert await cfg.option('gc.name').value.get() == 'framework'
#
assert await cfg.option('objspace').value.get() == 'std'
await cfg.option('objspace').value.set('thunk')
assert await cfg.option('objspace').value.get() == 'thunk'
#
assert await cfg.option('gc.float').value.get() == 2.3
await cfg.option('gc.float').value.set(3.4)
assert await cfg.option('gc.float').value.get() == 3.4
#
assert await cfg.option('int').value.get() == 0
await cfg.option('int').value.set(123)
assert await cfg.option('int').value.get() == 123
#
assert await cfg.option('wantref').value.get() is False
await cfg.option('wantref').value.set(True)
assert await cfg.option('wantref').value.get() is True
#
assert await cfg.option('str').value.get() == 'abc'
await cfg.option('str').value.set('def')
assert await cfg.option('str').value.get() == 'def'
#
with pytest.raises(AttributeError):
await cfg.option('gc.foo').value.get()
##
async with await Config(descr) as cfg:
assert await cfg.option('bool').value.get() is True
assert await cfg.option('gc.name').value.get() == 'ref'
assert await cfg.option('wantframework').value.get() is False
assert not await list_sessions()
def test_not_valid_properties():
raises(TypeError, "stroption = StrOption('str', 'Test string option', default='abc', properties=['mandatory',])")
@pytest.mark.asyncio
async def test_not_valid_properties():
with pytest.raises(AssertionError):
stroption = StrOption('str', 'Test string option', default='abc', properties='mandatory')
assert not await list_sessions()
def test_information_config():
@pytest.mark.asyncio
async def test_information_config():
descr = make_description()
config = Config(descr)
string = 'some informations'
#
assert list(config.information.list()) == []
config.information.set('info', string)
assert config.information.get('info') == string
assert list(config.information.list()) == ['info']
#
raises(ValueError, "config.information.get('noinfo')")
assert config.information.get('noinfo', 'default') == 'default'
config.information.reset('info')
raises(ValueError, "config.information.get('info')")
raises(ValueError, "config.information.reset('noinfo')")
assert list(config.information.list()) == []
async with await Config(descr) as cfg:
string = 'some informations'
#
assert list(await cfg.information.list()) == []
await cfg.information.set('info', string)
assert await cfg.information.get('info') == string
assert list(await cfg.information.list()) == ['info']
#
with pytest.raises(ValueError):
await cfg.information.get('noinfo')
assert await cfg.information.get('noinfo', 'default') == 'default'
await cfg.information.reset('info')
with pytest.raises(ValueError):
await cfg.information.get('info')
with pytest.raises(ValueError):
await cfg.information.reset('noinfo')
assert list(await cfg.information.list()) == []
assert not await list_sessions()
def test_information_option():
@pytest.mark.asyncio
async def test_information_option():
descr = make_description()
config = Config(descr)
string = 'some informations'
#
list(config.option('gc.name').information.list()) == []
config.option('gc.name').information.set('info', string)
assert config.option('gc.name').information.get('info') == string
list(config.option('gc.name').information.list()) == ['info']
#
raises(ValueError, "config.option('gc.name').information.get('noinfo')")
assert config.option('gc.name').information.get('noinfo', 'default') == 'default'
config.option('gc.name').information.reset('info')
raises(ValueError, "config.option('gc.name').information.get('info')")
raises(ValueError, "config.option('gc.name').information.reset('noinfo')")
list(config.option('gc.name').information.list()) == []
#
assert config.option('wantref').information.get('info') == 'default value'
config.option('wantref').information.set('info', 'default value')
assert config.option('wantref').information.get('info') == 'default value'
config.option('wantref').information.reset('info')
assert config.option('wantref').information.get('info') == 'default value'
async with await Config(descr) as cfg:
string = 'some informations'
#
list(await cfg.option('gc.name').information.list()) == []
await cfg.option('gc.name').information.set('info', string)
assert await cfg.option('gc.name').information.get('info') == string
list(await cfg.option('gc.name').information.list()) == ['info']
#
with pytest.raises(ValueError):
await cfg.option('gc.name').information.get('noinfo')
assert await cfg.option('gc.name').information.get('noinfo', 'default') == 'default'
await cfg.option('gc.name').information.reset('info')
with pytest.raises(ValueError):
await cfg.option('gc.name').information.get('info')
with pytest.raises(ValueError):
await cfg.option('gc.name').information.reset('noinfo')
list(await cfg.option('gc.name').information.list()) == []
#
assert await cfg.option('wantref').information.get('info') == 'default value'
await cfg.option('wantref').information.set('info', 'default value')
assert await cfg.option('wantref').information.get('info') == 'default value'
await cfg.option('wantref').information.reset('info')
assert await cfg.option('wantref').information.get('info') == 'default value'
assert not await list_sessions()
def to_tuple(val):
ret = []
for v in val:
t = []
for w in v:
if isinstance(w, list):
t.append(tuple(w))
else:
t.append(w)
ret.append(tuple(t))
return tuple(ret)
def compare(val1, val2):
assert len(val1[0]) == len(val2[0])
for idx1, val_1 in enumerate(val1[0]):
idx2 = val2[0].index(val_1)
assert val1[0][idx1] == val2[0][idx2]
assert val1[1][idx1] == val2[1][idx2]
if isinstance(val2[2][idx2], tuple):
assert val2[2][idx2] == tuple(val1[2][idx1])
else:
assert val2[2][idx2] == val1[2][idx1]
assert val1[3][idx1] == val2[3][idx2]
def test_get_modified_values():
@pytest.mark.asyncio
async def test_get_modified_values():
g1 = IntOption('g1', '', 1)
g2 = StrOption('g2', '', 'héhé')
g3 = UnicodeOption('g3', '', u'héhé')
g3 = StrOption('g3', '', 'héhé')
g4 = BoolOption('g4', '', True)
g5 = StrOption('g5', '')
g6 = StrOption('g6', '', multi=True)
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5, g6])
root = OptionDescription('root', '', [d1])
config = Config(root)
assert to_tuple(config.value.exportation()) == ((), (), (), ())
assert not config.option('od.g5').option.ismulti()
assert not config.option('od.g5').option.issubmulti()
config.option('od.g5').value.set('yes')
assert to_tuple(config.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',))
config.option('od.g4').value.set(False)
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g4'), (None, None), ('yes', False), ('user', 'user'))
config.option('od.g4').value.set(undefined)
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g4'), (None, None), ('yes', True), ('user', 'user'))
config.option('od.g4').value.reset()
assert to_tuple(config.value.exportation()) == (('od.g5',), (None,), ('yes',), ('user',))
assert config.option('od.g6').option.ismulti()
config.option('od.g6').value.set([undefined])
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', (None,)), ('user', 'user'))
config.option('od.g6').value.set([])
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user'))
config.option('od.g6').value.set(['3'])
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', ('3',)), ('user', 'user'))
config.option('od.g6').value.set([])
assert to_tuple(config.value.exportation()) == (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user'))
async with await Config(root) as cfg:
compare(await cfg.value.exportation(), ((), (), (), ()))
assert not await cfg.option('od.g5').option.ismulti()
assert not await cfg.option('od.g5').option.issubmulti()
await cfg.option('od.g5').value.set('yes')
compare(await cfg.value.exportation(), (('od.g5',), (None,), ('yes',), ('user',)))
await cfg.option('od.g4').value.set(False)
compare(await cfg.value.exportation(), (('od.g5', 'od.g4'), (None, None), ('yes', False), ('user', 'user')))
await cfg.option('od.g4').value.set(undefined)
compare(await cfg.value.exportation(), (('od.g5', 'od.g4'), (None, None), ('yes', True), ('user', 'user')))
await cfg.option('od.g4').value.reset()
compare(await cfg.value.exportation(), (('od.g5',), (None,), ('yes',), ('user',)))
assert await cfg.option('od.g6').option.ismulti()
await cfg.option('od.g6').value.set([undefined])
compare(await cfg.value.exportation(), (('od.g5', 'od.g6'), (None, None), ('yes', (None,)), ('user', 'user')))
await cfg.option('od.g6').value.set([])
compare(await cfg.value.exportation(), (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user')))
await cfg.option('od.g6').value.set(['3'])
compare(await cfg.value.exportation(), (('od.g5', 'od.g6'), (None, None), ('yes', ('3',)), ('user', 'user')))
await cfg.option('od.g6').value.set([])
compare(await cfg.value.exportation(), (('od.g5', 'od.g6'), (None, None), ('yes', tuple()), ('user', 'user')))
assert not await list_sessions()
def test_get_modified_values_not_modif(config_type):
@pytest.mark.asyncio
async def test_get_modified_values_not_modif(config_type):
g1 = StrOption('g1', '', multi=True)
d1 = OptionDescription('od', '', [g1])
root = OptionDescription('root', '', [d1])
config = Config(root)
config = get_config(config, config_type)
assert config.option('od.g1').value.get() == []
value = config.option('od.g1').value.get()
value.append('val')
assert config.option('od.g1').value.get() == []
async with await Config(root) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('od.g1').value.get() == []
value = await cfg.option('od.g1').value.get()
value.append('val')
assert await cfg.option('od.g1').value.get() == []
assert not await list_sessions()
def test_duplicated_option():
@pytest.mark.asyncio
async def test_duplicated_option():
g1 = IntOption('g1', '', 1)
g1
#in same OptionDescription
raises(ConflictError, "d1 = OptionDescription('od', '', [g1, g1])")
with pytest.raises(ConflictError):
d1 = OptionDescription('od', '', [g1, g1])
assert not await list_sessions()
def test_duplicated_option_diff_od():
@pytest.mark.asyncio
async def test_duplicated_option_diff_od():
g1 = IntOption('g1', '', 1)
d1 = OptionDescription('od1', '', [g1])
#in different OptionDescription
d2 = OptionDescription('od2', '', [g1, d1])
d2
raises(ConflictError, 'Config(d2)')
with pytest.raises(ConflictError):
await Config(d2, session_id='error')
await delete_session('error')
assert not await list_sessions()
def test_cannot_assign_value_to_option_description():
@pytest.mark.asyncio
async def test_cannot_assign_value_to_option_description():
descr = make_description()
cfg = Config(descr)
raises(APIError, "cfg.option('gc').value.set(3)")
async with await Config(descr) as cfg:
with pytest.raises(APIError):
await cfg.option('gc').value.set(3)
assert not await list_sessions()
def test_config_multi(config_type):
@pytest.mark.asyncio
async def test_config_multi(config_type):
i1 = IntOption('test1', '', multi=True)
i2 = IntOption('test2', '', multi=True, default_multi=1)
i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1)
od = OptionDescription('test', '', [i1, i2, i3])
config = Config(od)
config = get_config(config, config_type)
assert config.option('test1').value.get() == []
assert config.option('test2').value.get() == []
config.option('test2').value.set([undefined])
assert config.option('test2').value.get() == [1]
assert config.option('test3').value.get() == [2]
config.option('test3').value.set([undefined, undefined])
assert config.option('test3').value.get() == [2, 1]
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('test1').value.get() == []
assert await cfg.option('test2').value.get() == []
await cfg.option('test2').value.set([undefined])
assert await cfg.option('test2').value.get() == [1]
assert await cfg.option('test3').value.get() == [2]
await cfg.option('test3').value.set([undefined, undefined])
assert await cfg.option('test3').value.get() == [2, 1]
assert not await list_sessions()
def test_prefix_error():
@pytest.mark.asyncio
async def test_prefix_error():
i1 = IntOption('test1', '')
od = OptionDescription('test', '', [i1])
config = Config(od)
config.property.read_write()
config.option('test1').value.set(1)
try:
config.option('test1').value.set('yes')
except Exception as err:
assert str(err) == _('"{0}" is an invalid {1} for "{2}"').format('yes', _('integer'), 'test1')
try:
config.option('test1').value.set('yes')
except Exception as err:
err.prefix = ''
assert str(err) == _('invalid value')
async with await Config(od) as cfg:
await cfg.property.read_write()
await cfg.option('test1').value.set(1)
try:
await cfg.option('test1').value.set('yes')
except Exception as err:
assert str(err) == _('"{0}" is an invalid {1} for "{2}"').format('yes', _('integer'), 'test1')
try:
await cfg.option('test1').value.set('yes')
except Exception as err:
err.prefix = ''
assert str(err) == _('invalid value')
assert not await list_sessions()
def test_no_validation():
@pytest.mark.asyncio
async def test_no_validation():
# FIXME
config_type = 'tiramisu'
i1 = IntOption('test1', '')
od = OptionDescription('test', '', [i1])
config = Config(od)
config.property.read_write()
cfg = get_config(config, config_type)
cfg.option('test1').value.set(1)
raises(ValueError, "cfg.option('test1').value.set('yes')")
assert cfg.option('test1').value.get() == 1
config.property.pop('validator')
cfg = get_config(config, config_type)
cfg.option('test1').value.set('yes')
assert cfg.option('test1').value.get() == 'yes'
cfg.property.add('validator')
raises(ValueError, "cfg.option('test1').value.get()")
cfg.option('test1').value.reset()
assert cfg.option('test1').value.get() is None
async with await Config(od) as config:
await config.property.read_write()
cfg = await get_config(config, config_type)
await cfg.option('test1').value.set(1)
with pytest.raises(ValueError):
await cfg.option('test1').value.set('yes')
assert await cfg.option('test1').value.get() == 1
await config.property.pop('validator')
cfg = await get_config(config, config_type)
await cfg.option('test1').value.set('yes')
assert await cfg.option('test1').value.get() == 'yes'
await cfg.property.add('validator')
with pytest.raises(ValueError):
await cfg.option('test1').value.get()
await cfg.option('test1').value.reset()
assert await cfg.option('test1').value.get() is None
assert not await list_sessions()
def test_subconfig():
@pytest.mark.asyncio
async def test_subconfig():
i = IntOption('i', '')
o = OptionDescription('val', '', [i])
o2 = OptionDescription('val', '', [o])
c = Config(o2)
c
raises(TypeError, "SubConfig(i, weakref.ref(c))")
async with await Config(o2) as cfg:
cfg
with pytest.raises(TypeError):
await SubConfig(i, weakref.ref(cfg))
assert not await list_sessions()
def test_config_subconfig():
@pytest.mark.asyncio
async def test_config_subconfig():
i1 = IntOption('i1', '')
i2 = IntOption('i2', '', default=1)
i3 = IntOption('i3', '')
i4 = IntOption('i4', '', default=2)
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, session_id='conf1')
raises(ConfigError, "conf2 = Config(od1, session_id='conf2')")
async with await Config(od2, session_id='conf1') as cfg:
with pytest.raises(ConfigError):
conf2 = await Config(od1, session_id='conf2')
await delete_session('conf2')
assert not await list_sessions()
def test_config_invalidsession():
@pytest.mark.asyncio
async def test_config_invalidsession():
i = IntOption('i', '')
o = OptionDescription('val', '', [i])
o2 = OptionDescription('val', '', [o])
raises(ValueError, 'Config(o2, session_id=2)')
with pytest.raises(ValueError):
await Config(o2, session_id=2)
assert not await list_sessions()
def test_config_od_name(config_type):
@pytest.mark.asyncio
async def test_config_od_name(config_type):
i = IntOption('i', '')
s = SymLinkOption('s', i)
o = OptionDescription('val', '', [i, s])
o2 = OptionDescription('val', '', [o])
c = Config(o2)
c = get_config(c, config_type)
assert c.option('val.i').option.name() == 'i'
assert c.option('val.s').option.name() == 's'
assert c.option('val.s').option.name(follow_symlink=True) == 'i'
async with await Config(o2) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('val.i').option.name() == 'i'
assert await cfg.option('val.s').option.name() == 's'
assert await cfg.option('val.s').option.name(follow_symlink=True) == 'i'
assert not await list_sessions()
def test_config_od_type(config_type):
@pytest.mark.asyncio
async def test_config_od_type(config_type):
i = IntOption('i', '')
o = OptionDescription('val', '', [i])
o2 = OptionDescription('val', '', [o])
c = Config(o2)
c = get_config(c, config_type)
assert c.option('val.i').option.type() == 'integer'
async with await Config(o2) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('val.i').option.type() == 'integer'
assert not await list_sessions()
def test_config_default(config_type):
@pytest.mark.asyncio
async def test_config_default(config_type):
i = IntOption('i', '', 8)
o = OptionDescription('val', '', [i])
o2 = OptionDescription('val', '', [o])
c = Config(o2)
c = get_config(c, config_type)
assert c.option('val.i').value.default() == 8
c.option('val.i').value.set(9)
assert c.option('val.i').value.get() == 9
assert c.option('val.i').value.default() == 8
async with await Config(o2) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('val.i').value.default() == 8
await cfg.option('val.i').value.set(9)
assert await cfg.option('val.i').value.get() == 9
assert await cfg.option('val.i').value.default() == 8
assert not await list_sessions()

View File

@ -1,20 +1,23 @@
"configuration objects global API"
from py.test import raises
import pytest
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from .config import config_type, get_config, value_list, global_owner, event_loop
from tiramisu import Config, IntOption, FloatOption, StrOption, ChoiceOption, \
BoolOption, FilenameOption, UnicodeOption, SymLinkOption, IPOption, \
BoolOption, FilenameOption, SymLinkOption, IPOption, \
PortOption, NetworkOption, NetmaskOption, BroadcastOption, \
DomainnameOption, OptionDescription
from tiramisu.error import PropertiesOptionError
from tiramisu.error import PropertiesOptionError, ValueWarning
from tiramisu.storage import list_sessions
import warnings
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
#def teardown_function(function):
# # test_od_not_list emit a warnings because of doesn't create a Config
# with warnings.catch_warnings(record=True) as w:
# assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def make_description():
@ -49,44 +52,49 @@ def _is_same_opt(opt1, opt2):
assert opt1 == opt2
def test_od_not_list():
@pytest.mark.asyncio
async def test_od_not_list():
b = BoolOption('bool', '', multi=True)
raises(AssertionError, "OptionDescription('od', '', b)")
with pytest.raises(AssertionError):
OptionDescription('od', '', b)
assert not await list_sessions()
def test_str():
@pytest.mark.asyncio
async def test_str():
descr = make_description()
c = Config(descr)
c # does not crash
async with await Config(descr) as cfg:
cfg # does not crash
assert not await list_sessions()
def test_make_dict(config_type):
@pytest.mark.asyncio
async def test_make_dict(config_type):
"serialization of the whole config to a dict"
descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [
BoolOption("a", "", default=False),
BoolOption("b", "", default=False, properties=('hidden',))]),
IntOption("int", "", default=42)])
config = Config(descr)
config.property.read_write()
config.permissive.set(frozenset(['hidden']))
config = get_config(config, config_type)
d = config.value.dict()
assert d == {"s1.a": False, "int": 42}
config.option('int').value.set(43)
config.option('s1.a').value.set(True)
d = config.value.dict()
assert d == {"s1.a": True, "int": 43}
d2 = config.value.dict(flatten=True)
assert d2 == {'a': True, 'int': 43}
if config_type == 'tiramisu':
# FIXME
raises(ValueError, 'd2 = config.value.dict(withvalue="3")')
d = config.forcepermissive.value.dict()
assert d == {"s1.a": True, "s1.b": False, "int": 43}
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.permissive.add('hidden')
cfg = await get_config(cfg, config_type)
d = await cfg.value.dict()
assert d == {"s1.a": False, "int": 42}
await cfg.option('int').value.set(43)
await cfg.option('s1.a').value.set(True)
d = await cfg.value.dict()
assert d == {"s1.a": True, "int": 43}
d2 = await cfg.value.dict(flatten=True)
assert d2 == {'a': True, 'int': 43}
if config_type == 'tiramisu':
assert await cfg.forcepermissive.value.dict() == {"s1.a": True, "s1.b": False, "int": 43}
assert not await list_sessions()
def test_make_dict_with_disabled(config_type):
@pytest.mark.asyncio
async def test_make_dict_with_disabled(config_type):
descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [
BoolOption("a", "", default=False),
@ -95,16 +103,18 @@ def test_make_dict_with_disabled(config_type):
BoolOption("a", "", default=False),
BoolOption("b", "", default=False)], properties=('disabled',)),
IntOption("int", "", default=42)])
config = Config(descr)
config.property.read_only()
config = get_config(config, config_type)
assert config.value.dict() == {"s1.a": False, "int": 42}
if config_type == 'tiramisu':
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}
async with await Config(descr) as cfg:
await cfg.property.read_only()
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {"s1.a": False, "int": 42}
if config_type == 'tiramisu':
assert await cfg.forcepermissive.value.dict() == {"s1.a": False, "int": 42}
assert await cfg.unrestraint.value.dict() == {"int": 42, "s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
assert not await list_sessions()
def test_make_dict_with_disabled_withoption():
@pytest.mark.asyncio
async def test_make_dict_with_disabled_in_callback(config_type):
descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [
BoolOption("a", "", default=False),
@ -113,30 +123,16 @@ def test_make_dict_with_disabled_withoption():
BoolOption("a", "", default=False),
BoolOption("b", "", default=False)], properties=('disabled',)),
IntOption("int", "", default=42)])
config = Config(descr)
config.property.read_only()
assert config.value.dict(withoption="a") == {"s1.a": False}
assert config.forcepermissive.value.dict(withoption="a") == {"s1.a": False}
assert config.unrestraint.value.dict(withoption="a") == {"s1.a": False, "s1.b": False, "s2.a": False, "s2.b": False}
async with await Config(descr) as cfg:
await cfg.property.read_only()
cfg = await get_config(cfg, config_type)
d = await cfg.value.dict()
assert d == {"s1.a": False, "int": 42}
assert not await list_sessions()
def test_make_dict_with_disabled_in_callback(config_type):
descr = OptionDescription("opt", "", [
OptionDescription("s1", "", [
BoolOption("a", "", default=False),
BoolOption("b", "", default=False, properties=('disabled',))]),
OptionDescription("s2", "", [
BoolOption("a", "", default=False),
BoolOption("b", "", default=False)], properties=('disabled',)),
IntOption("int", "", default=42)])
config = Config(descr)
config.property.read_only()
config = get_config(config, config_type)
d = config.value.dict()
assert d == {"s1.a": False, "int": 42}
def test_make_dict_fullpath(config_type):
@pytest.mark.asyncio
async def test_make_dict_fullpath(config_type):
descr = OptionDescription("root", "", [
OptionDescription("opt", "", [
OptionDescription("s1", "", [
@ -147,249 +143,326 @@ def test_make_dict_fullpath(config_type):
BoolOption("b", "", default=False)], properties=('disabled',)),
IntOption("int", "", default=42)]),
IntOption("introot", "", default=42)])
config = Config(descr)
config.property.read_only()
config = get_config(config, config_type)
assert config.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 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}
if config_type == 'tiramisu':
# FIXME
assert config.option('opt').value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
async with await Config(descr) as cfg:
await cfg.property.read_only()
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
if config_type == 'tiramisu':
# FIXME
assert await cfg.option('opt').value.dict() == {"s1.a": False, "int": 42}
assert await cfg.value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
if config_type == 'tiramisu':
# FIXME
assert await cfg.option('opt').value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
assert not await list_sessions()
def test_find_in_config():
@pytest.mark.asyncio
async def test_find_in_config():
"finds option in config"
descr = make_description()
conf = Config(descr)
conf.property.read_only()
conf.permissive.set(frozenset(['hidden']))
ret = list(conf.option.find('dummy'))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.option('gc.dummy').option.get())
#
ret = conf.option.find('dummy', first=True).option.get()
_is_same_opt(ret, conf.option('gc.dummy').option.get())
#
ret = list(conf.option.find('float'))
assert len(ret) == 2
_is_same_opt(ret[0].option.get(), conf.option('gc.float').option.get())
_is_same_opt(ret[1].option.get(), conf.option('float').option.get())
#
_is_same_opt(conf.option.find('bool', first=True).option.get(), conf.option('gc.gc2.bool').option.get())
_is_same_opt(conf.option.find('bool', value=True, first=True).option.get(), conf.option('bool').option.get())
_is_same_opt(conf.option.find('dummy', first=True).option.get(), conf.option('gc.dummy').option.get())
_is_same_opt(conf.option.find('float', first=True).option.get(), conf.option('gc.float').option.get())
#FIXME cannot find an option without name
#ret = conf.find(bytype=ChoiceOption)
#assert len(ret) == 2
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.name'))
#_is_same_opt(ret[1], conf.unwrap_from_path('objspace'))
#
#_is_same_opt(conf.find_first(bytype=ChoiceOption), conf.unwrap_from_path('gc.name'))
#ret = conf.find(byvalue='ref')
#assert len(ret) == 1
#_is_same_opt(ret[0], conf.unwrap_from_path('gc.name'))
#_is_same_opt(conf.find_first(byvalue='ref'), conf.unwrap_from_path('gc.name'))
#
ret = list(conf.option.find('prop'))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.option('gc.prop').option.get())
#
ret = list(conf.option.find('prop', value=None))
assert len(ret) == 1
ret = list(conf.option.find('prop'))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.option('gc.prop').option.get())
#
conf.property.read_write()
raises(AttributeError, "assert conf.option.find('prop').option.get()")
ret = list(conf.unrestraint.option.find(name='prop'))
assert len(ret) == 2
_is_same_opt(ret[0].option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
_is_same_opt(ret[1].option.get(), conf.forcepermissive.option('gc.prop').option.get())
#
ret = list(conf.forcepermissive.option.find('prop'))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.forcepermissive.option('gc.prop').option.get())
#
_is_same_opt(conf.forcepermissive.option.find('prop', first=True).option.get(), conf.forcepermissive.option('gc.prop').option.get())
# combinaison of filters
ret = list(conf.unrestraint.option.find('prop', type=BoolOption))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
_is_same_opt(conf.unrestraint.option.find('prop', type=BoolOption, first=True).option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
#
ret = list(conf.option.find('dummy', value=False))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.option('gc.dummy').option.get())
#
_is_same_opt(conf.option.find('dummy', value=False, first=True).option.get(), conf.option('gc.dummy').option.get())
#subconfig
ret = list(conf.option('gc').find('dummy'))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.option('gc.dummy').option.get())
#
ret = list(conf.option('gc').find('float'))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.option('gc.float').option.get())
#
ret = list(conf.option('gc').find('bool'))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.option('gc.gc2.bool').option.get())
_is_same_opt(conf.option('gc').find('bool', value=False, first=True).option.get(), conf.option('gc.gc2.bool').option.get())
#
raises(AttributeError, "assert conf.option('gc').find('bool', value=True, first=True).option.get()")
#
raises(AttributeError, "conf.option('gc').find('wantref').option.get()")
#
ret = list(conf.unrestraint.option('gc').find('prop'))
assert len(ret) == 2
_is_same_opt(ret[0].option.get(), conf.unrestraint.option('gc.gc2.prop').option.get())
_is_same_opt(ret[1].option.get(), conf.forcepermissive.option('gc.prop').option.get())
#
conf.property.read_only()
ret = list(conf.option('gc').find('prop'))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), conf.option('gc.prop').option.get())
# not OptionDescription
raises(AttributeError, "conf.option.find('gc', first=True)")
raises(AttributeError, "conf.option.find('gc2', first=True)")
async with await Config(descr) as cfg:
await cfg.property.read_only()
await cfg.permissive.add('hidden')
ret = list(await cfg.option.find('dummy'))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.dummy').option.get())
#
ret_find = await cfg.option.find('dummy', first=True)
ret = await ret_find.option.get()
_is_same_opt(ret, await cfg.option('gc.dummy').option.get())
#
ret = list(await cfg.option.find('float'))
assert len(ret) == 2
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.float').option.get())
_is_same_opt(await ret[1].option.get(), await cfg.option('float').option.get())
#
ret = await cfg.option.find('bool', first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.gc2.bool').option.get())
ret = await cfg.option.find('bool', value=True, first=True)
_is_same_opt(await ret.option.get(), await cfg.option('bool').option.get())
ret = await cfg.option.find('dummy', first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.dummy').option.get())
ret = await cfg.option.find('float', first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.float').option.get())
#FIXME cannot find an option without name
#ret = await cfg.find(bytype=ChoiceOption)
#assert len(ret) == 2
#_is_same_opt(ret[0], await cfg.unwrap_from_path('gc.name'))
#_is_same_opt(ret[1], await cfg.unwrap_from_path('objspace'))
#
#_is_same_opt(await cfg.find_first(bytype=ChoiceOption), await cfg.unwrap_from_path('gc.name'))
#ret = await cfg.find(byvalue='ref')
#assert len(ret) == 1
#_is_same_opt(ret[0], await cfg.unwrap_from_path('gc.name'))
#_is_same_opt(await cfg.find_first(byvalue='ref'), await cfg.unwrap_from_path('gc.name'))
#
ret = list(await cfg.option.find('prop'))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.prop').option.get())
#
ret = list(await cfg.option.find('prop', value=None))
assert len(ret) == 1
ret = list(await cfg.option.find('prop'))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.prop').option.get())
#
await cfg.property.read_write()
with pytest.raises(AttributeError):
ret = await cfg.option.find('prop')
assert await ret.option.get()
ret = list(await cfg.unrestraint.option.find(name='prop'))
assert len(ret) == 2
_is_same_opt(await ret[0].option.get(), await cfg.unrestraint.option('gc.gc2.prop').option.get())
_is_same_opt(await ret[1].option.get(), await cfg.forcepermissive.option('gc.prop').option.get())
#
ret = list(await cfg.forcepermissive.option.find('prop'))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.forcepermissive.option('gc.prop').option.get())
#
ret = await cfg.forcepermissive.option.find('prop', first=True)
_is_same_opt(await ret.option.get(), await cfg.forcepermissive.option('gc.prop').option.get())
# combinaison of filters
ret = list(await cfg.unrestraint.option.find('prop', type=BoolOption))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.unrestraint.option('gc.gc2.prop').option.get())
ret = await cfg.unrestraint.option.find('prop', type=BoolOption, first=True)
_is_same_opt(await ret.option.get(), await cfg.unrestraint.option('gc.gc2.prop').option.get())
#
ret = list(await cfg.option.find('dummy', value=False))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.dummy').option.get())
#
ret = await cfg.option.find('dummy', value=False, first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.dummy').option.get())
#subcfgig
ret = list(await cfg.option('gc').find('dummy'))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.dummy').option.get())
#
ret = list(await cfg.option('gc').find('float'))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.float').option.get())
#
ret = list(await cfg.option('gc').find('bool'))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.gc2.bool').option.get())
ret = await cfg.option('gc').find('bool', value=False, first=True)
_is_same_opt(await ret.option.get(), await cfg.option('gc.gc2.bool').option.get())
#
with pytest.raises(AttributeError):
ret = await cfg.option('gc').find('bool', value=True, first=True)
assert await ret.option.get()
#
with pytest.raises(AttributeError):
ret = await cfg.option('gc').find('wantref')
await ret.option.get()
#
ret = list(await cfg.unrestraint.option('gc').find('prop'))
assert len(ret) == 2
_is_same_opt(await ret[0].option.get(), await cfg.unrestraint.option('gc.gc2.prop').option.get())
_is_same_opt(await ret[1].option.get(), await cfg.forcepermissive.option('gc.prop').option.get())
#
await cfg.property.read_only()
ret = list(await cfg.option('gc').find('prop'))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), await cfg.option('gc.prop').option.get())
# not OptionDescription
with pytest.raises(AttributeError):
await cfg.option.find('gc', first=True)
with pytest.raises(AttributeError):
await cfg.option.find('gc2', first=True)
assert not await list_sessions()
def test_find_multi():
b = BoolOption('bool', '', multi=True)
@pytest.mark.asyncio
async def test_find_multi():
b = BoolOption('bool', '', multi=True, properties=('notunique',))
o = OptionDescription('od', '', [b])
conf = Config(o)
#
raises(AttributeError, "list(conf.option.find('bool', value=True))")
raises(AttributeError, "list(conf.option.find('bool', value=True, first=True))")
conf.option('bool').value.set([False])
raises(AttributeError, "list(conf.option.find('bool', value=True))")
raises(AttributeError, "list(conf.option.find('bool', value=True, first=True))")
conf.option('bool').value.set([False, False])
raises(AttributeError, "list(conf.option.find('bool', value=True))")
raises(AttributeError, "list(conf.option.find('bool', value=True, first=True))")
conf.option('bool').value.set([False, False, True])
ret = list(conf.option.find('bool', value=True))
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), b)
_is_same_opt(conf.option.find('bool', value=True, first=True).option.get(), b)
async with await Config(o) as cfg:
#
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True))
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True, first=True))
await cfg.option('bool').value.set([False])
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True))
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True, first=True))
await cfg.option('bool').value.set([False, False])
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True))
with pytest.raises(AttributeError):
list(await cfg.option.find('bool', value=True, first=True))
await cfg.option('bool').value.set([False, False, True])
ret = list(await cfg.option.find('bool', value=True))
assert len(ret) == 1
_is_same_opt(await ret[0].option.get(), b)
ret = await cfg.option.find('bool', value=True, first=True)
_is_same_opt(await ret.option.get(), b)
assert not await list_sessions()
def test_does_not_find_in_config():
@pytest.mark.asyncio
async def test_does_not_find_in_config():
descr = make_description()
conf = Config(descr)
raises(AttributeError, "list(conf.option.find('IDontExist'))")
async with await Config(descr) as cfg:
with pytest.raises(AttributeError):
list(await cfg.option.find('IDontExist'))
assert not await list_sessions()
def test_filename(config_type):
@pytest.mark.asyncio
async def test_filename(config_type):
a = FilenameOption('a', '')
o = OptionDescription('o', '', [a])
cfg = Config(o)
# FIXME cfg = get_config(cfg, config_type)
cfg.option('a').value.set('/')
cfg.option('a').value.set('/tmp')
cfg.option('a').value.set('/tmp/')
cfg.option('a').value.set('/tmp/text.txt')
cfg.option('a').value.set('tmp')
cfg.option('a').value.set('tmp/')
cfg.option('a').value.set('tmp/text.txt')
raises(ValueError, "cfg.option('a').value.set('/tmp/with space.txt')")
raises(ValueError, "cfg.option('a').value.set('/tmp/with$.txt')")
async with await Config(o) as cfg:
# FIXME cfg = await get_config(cfg, config_type)
await cfg.option('a').value.set('/')
await cfg.option('a').value.set('/tmp')
await cfg.option('a').value.set('/tmp/')
await cfg.option('a').value.set('/tmp/text.txt')
await cfg.option('a').value.set('/tmp/with space.txt')
await cfg.option('a').value.set('/tmp/with$.txt')
with pytest.raises(ValueError):
await cfg.option('a').value.set('not starts with /')
assert not await list_sessions()
def test_invalid_option():
@pytest.mark.asyncio
async def test_invalid_option():
ChoiceOption('a', '', ('1', '2'))
raises(TypeError, "ChoiceOption('a', '', [1, 2])")
raises(TypeError, "ChoiceOption('a', '', 1)")
raises(ValueError, "ChoiceOption('a', '', (1,), 3)")
with pytest.raises(TypeError):
ChoiceOption('a', '', [1, 2])
with pytest.raises(TypeError):
ChoiceOption('a', '', 1)
with pytest.raises(ValueError):
ChoiceOption('a', '', (1,), 3)
FloatOption('a', '')
raises(ValueError, "FloatOption('a', '', 'string')")
UnicodeOption('a', '')
raises(ValueError, "UnicodeOption('a', '', 1)")
u = UnicodeOption('a', '')
with pytest.raises(ValueError):
FloatOption('a', '', 'string')
StrOption('a', '')
with pytest.raises(ValueError):
StrOption('a', '', 1)
u = StrOption('a', '')
SymLinkOption('a', u)
raises(ValueError, "SymLinkOption('a', 'string')")
with pytest.raises(ValueError):
SymLinkOption('a', 'string')
IPOption('a', '')
raises(ValueError, "IPOption('a', '', 1)")
raises(ValueError, "IPOption('a', '', 'string')")
with pytest.raises(ValueError):
IPOption('a', '', 1)
with pytest.raises(ValueError):
IPOption('a', '', 'string')
PortOption('a', '')
raises(ValueError, "PortOption('a', '', 'string')")
raises(ValueError, "PortOption('a', '', '11:12:13', allow_range=True)")
raises(ValueError, "PortOption('a', '', 11111111111111111111)")
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=False)")
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=True, allow_registred=False, allow_private=True)")
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=False, allow_private=True)")
raises(ValueError, "PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=True)")
raises(ValueError, "PortOption('a', '', allow_zero=False, allow_wellknown=False, allow_registred=False, allow_private=False)")
with pytest.raises(ValueError):
PortOption('a', '', 'string')
with pytest.raises(ValueError):
PortOption('a', '', '11:12:13', allow_range=True)
with pytest.raises(ValueError):
PortOption('a', '', 11111111111111111111)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=False)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=True, allow_wellknown=True, allow_registred=False, allow_private=True)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=False, allow_private=True)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=True, allow_wellknown=False, allow_registred=True, allow_private=True)
with pytest.raises(ValueError):
PortOption('a', '', allow_zero=False, allow_wellknown=False, allow_registred=False, allow_private=False)
NetworkOption('a', '')
raises(ValueError, "NetworkOption('a', '', 'string')")
with pytest.raises(ValueError):
NetworkOption('a', '', 'string')
NetmaskOption('a', '')
raises(ValueError, "NetmaskOption('a', '', 'string')")
with pytest.raises(ValueError):
NetmaskOption('a', '', 'string')
BroadcastOption('a', '')
raises(ValueError, "BroadcastOption('a', '', 'string')")
with pytest.raises(ValueError):
BroadcastOption('a', '', 'string')
DomainnameOption('a', '')
raises(ValueError, "DomainnameOption('a', '', 'string')")
raises(ValueError, "DomainnameOption('a', '', type_='string')")
raises(ValueError, "DomainnameOption('a', '', allow_ip='string')")
raises(ValueError, "DomainnameOption('a', '', allow_without_dot='string')")
raises(ValueError, "DomainnameOption('a', '', 1)")
with pytest.raises(ValueError):
DomainnameOption('a', '', 'string')
with pytest.raises(ValueError):
DomainnameOption('a', '', type='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', allow_ip='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', allow_without_dot='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', 1)
#
ChoiceOption('a', '', (1,), multi=True, default_multi=1)
raises(ValueError, "ChoiceOption('a', '', (1,), default_multi=1)")
raises(ValueError, "ChoiceOption('a', '', (1,), multi=True, default=[1,], default_multi=2)")
raises(ValueError, "FloatOption('a', '', multi=True, default_multi='string')")
raises(ValueError, "UnicodeOption('a', '', multi=True, default_multi=1)")
raises(ValueError, "IPOption('a', '', multi=True, default_multi=1)")
raises(ValueError, "IPOption('a', '', multi=True, default_multi='string')")
raises(ValueError, "PortOption('a', '', multi=True, default_multi='string')")
raises(ValueError, "PortOption('a', '', multi=True, default_multi='11:12:13', allow_range=True)")
raises(ValueError, "PortOption('a', '', multi=True, default_multi=11111111111111111111)")
raises(ValueError, "NetworkOption('a', '', multi=True, default_multi='string')")
raises(ValueError, "NetmaskOption('a', '', multi=True, default_multi='string')")
raises(ValueError, "BroadcastOption('a', '', multi=True, default_multi='string')")
raises(ValueError, "DomainnameOption('a', '', multi=True, default_multi='string')")
raises(ValueError, "DomainnameOption('a', '', multi=True, default_multi=1)")
with pytest.raises(ValueError):
ChoiceOption('a', '', (1,), default_multi=1)
with pytest.raises(ValueError):
ChoiceOption('a', '', (1,), multi=True, default=[1,], default_multi=2)
with pytest.raises(ValueError):
FloatOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
StrOption('a', '', multi=True, default_multi=1)
with pytest.raises(ValueError):
IPOption('a', '', multi=True, default_multi=1)
with pytest.raises(ValueError):
IPOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
PortOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
PortOption('a', '', multi=True, default_multi='11:12:13', allow_range=True)
with pytest.raises(ValueError):
PortOption('a', '', multi=True, default_multi=11111111111111111111)
with pytest.raises(ValueError):
NetworkOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
NetmaskOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
BroadcastOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', multi=True, default_multi='string')
with pytest.raises(ValueError):
DomainnameOption('a', '', multi=True, default_multi=1)
assert not await list_sessions()
def test_help():
@pytest.mark.asyncio
async def test_help():
stro = StrOption('s', '', multi=True)
od1 = OptionDescription('o', '', [stro])
od2 = OptionDescription('o', '', [od1])
cfg = Config(od2)
cfg.help(_display=False)
cfg.config.help(_display=False)
cfg.option.help(_display=False)
#FIXMEcfg.option('o').help(_display=False)
cfg.option('o.s').help(_display=False)
async with await Config(od2) as cfg:
cfg.help(_display=False)
cfg.config.help(_display=False)
cfg.option.help(_display=False)
cfg.option('o').help(_display=False)
cfg.option('o.s').help(_display=False)
assert not await list_sessions()
def test_config_reset():
@pytest.mark.asyncio
async def test_config_reset():
descr = make_description()
c = Config(descr)
c.owner.set('test')
assert c.owner.get() == 'test'
assert not c.option('gc.gc2.bool').value.get()
assert not c.option('boolop').property.get()
assert not c.option('boolop').permissive.get()
assert not c.option('wantref').information.get('info', None)
#
c.option('gc.gc2.bool').value.set(True)
c.option('boolop').property.add('test')
c.option('float').permissive.set(frozenset(['test']))
c.option('wantref').information.set('info', 'info')
assert c.option('gc.gc2.bool').value.get()
assert c.option('boolop').property.get()
assert c.option('float').permissive.get()
assert c.option('wantref').information.get('info', None)
#
assert c.owner.get() == 'test'
c.config.reset()
assert c.owner.get() == 'test'
assert not c.option('gc.gc2.bool').value.get()
assert not c.option('boolop').property.get()
assert not c.option('float').permissive.get()
assert not c.option('wantref').information.get('info', None)
async with await Config(descr) as cfg:
await cfg.owner.set('test')
assert await cfg.owner.get() == 'test'
assert not await cfg.option('gc.gc2.bool').value.get()
assert not await cfg.option('boolop').property.get()
assert not await cfg.option('boolop').permissive.get()
assert not await cfg.option('wantref').information.get('info', None)
#
await cfg.option('gc.gc2.bool').value.set(True)
await cfg.option('boolop').property.add('test')
await cfg.option('float').permissive.set(frozenset(['test']))
await cfg.option('wantref').information.set('info', 'info')
assert await cfg.option('gc.gc2.bool').value.get()
assert await cfg.option('boolop').property.get()
assert await cfg.option('float').permissive.get()
assert await cfg.option('wantref').information.get('info', None)
#
assert await cfg.owner.get() == 'test'
await cfg.config.reset()
assert await cfg.owner.get() == 'test'
assert not await cfg.option('gc.gc2.bool').value.get()
assert not await cfg.option('boolop').property.get()
assert not await cfg.option('float').permissive.get()
assert not await cfg.option('wantref').information.get('info', None)
assert not await list_sessions()

View File

@ -3,214 +3,260 @@ do_autopath()
from .config import config_type, get_config, value_list, global_owner
import warnings, sys
from py.test import raises
import pytest
from tiramisu import Config, DomainnameOption, EmailOption, URLOption, OptionDescription
from tiramisu.error import ValueWarning
from tiramisu.i18n import _
from tiramisu.storage import list_sessions
from .config import event_loop
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def test_domainname(config_type):
@pytest.mark.asyncio
async def test_domainname(config_type):
d = DomainnameOption('d', '')
f = DomainnameOption('f', '', allow_without_dot=True)
g = DomainnameOption('g', '', allow_ip=True)
h = DomainnameOption('h', '', allow_ip=True, cidr=True)
h = DomainnameOption('h', '', allow_cidr_network=True)
od = OptionDescription('a', '', [d, f, g, h])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
#
cfg.option('d').value.set('toto.com')
raises(ValueError, "cfg.option('d').value.set('toto')")
cfg.option('d').value.set('toto3.com')
raises(ValueError, "cfg.option('d').value.set('toto_super.com')")
cfg.option('d').value.set('toto-.com')
raises(ValueError, "cfg.option('d').value.set('toto..com')")
#
cfg.option('f').value.set('toto.com')
cfg.option('f').value.set('toto')
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
raises(ValueError, "cfg.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')")
cfg.option('f').value.set('d')
cfg.option('f').value.set('d.t')
#
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')")
#
cfg.option('g').value.set('toto.com')
cfg.option('g').value.set('192.168.1.0')
cfg.option('g').value.set('192.168.1.29')
raises(ValueError, "cfg.option('g').value.set('192.168.1.0/24')")
#
cfg.option('h').value.set('toto.com')
if config_type != 'tiramisu-api':
# 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')
async with await Config(od) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
#
await cfg.option('d').value.set('toto.com')
with pytest.raises(ValueError):
await cfg.option('d').value.set('toto')
await cfg.option('d').value.set('toto3.com')
with pytest.raises(ValueError):
await cfg.option('d').value.set('toto_super.com')
await cfg.option('d').value.set('toto-.com')
with pytest.raises(ValueError):
await cfg.option('d').value.set('toto..com')
#
await cfg.option('f').value.set('toto.com')
await cfg.option('f').value.set('toto')
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
with pytest.raises(ValueError):
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
with pytest.raises(ValueError):
await cfg.option('d').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowien')
await cfg.option('f').value.set('d')
await cfg.option('f').value.set('d.t')
#
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('f').value.set('192.168.1.1')
with pytest.raises(ValueError):
await cfg.option('f').value.set('192.168.1.0/24')
#
await cfg.option('g').value.set('toto.com')
await cfg.option('g').value.set('192.168.1.0')
await cfg.option('g').value.set('192.168.1.29')
with pytest.raises(ValueError):
await cfg.option('g').value.set('192.168.1.0/24')
#
await cfg.option('h').value.set('toto.com')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('h').value.set('192.168.1.0')
with pytest.raises(ValueError):
await cfg.option('h').value.set('192.168.1.29')
# it's a network address
await cfg.option('h').value.set('192.168.1.0/24')
# but not here
with pytest.raises(ValueError):
await cfg.option('h').value.set('192.168.1.1/24')
assert not await list_sessions()
def test_domainname_upper(config_type):
@pytest.mark.asyncio
async def test_domainname_upper(config_type):
d = DomainnameOption('d', '')
od = OptionDescription('a', '', [d])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('d').value.set('toto.com')
msg = _('some characters are uppercase')
has_error = False
try:
cfg.option('d').value.set('TOTO.COM')
except ValueError as err:
if config_type != 'tiramisu-api':
# FIXME
assert msg in str(err)
has_error = True
assert has_error is True
has_error = False
try:
cfg.option('d').value.set('toTo.com')
except ValueError as err:
if config_type != 'tiramisu-api':
# FIXME
assert msg in str(err)
has_error = True
assert has_error is True
async with await Config(od) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('d').value.set('toto.com')
msg = _('some characters are uppercase')
has_error = False
try:
await cfg.option('d').value.set('TOTO.COM')
except ValueError as err:
if config_type != 'tiramisu-api':
# FIXME
assert msg in str(err)
has_error = True
assert has_error is True
has_error = False
try:
await cfg.option('d').value.set('toTo.com')
except ValueError as err:
if config_type != 'tiramisu-api':
# FIXME
assert msg in str(err)
has_error = True
assert has_error is True
assert not await list_sessions()
def test_domainname_warning(config_type):
@pytest.mark.asyncio
async def test_domainname_warning(config_type):
d = DomainnameOption('d', '', warnings_only=True)
f = DomainnameOption('f', '', allow_without_dot=True, warnings_only=True)
g = DomainnameOption('g', '', allow_ip=True, warnings_only=True)
od = OptionDescription('a', '', [d, f, g])
warnings.simplefilter("always", ValueWarning)
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('d').value.set('toto.com')
raises(ValueError, "cfg.option('d').value.set('toto')")
cfg.option('d').value.set('toto3.com')
if config_type != 'tiramisu-api':
# FIXME
async with await Config(od) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('d').value.set('toto.com')
with pytest.raises(ValueError):
await cfg.option('d').value.set('toto')
await cfg.option('d').value.set('toto3.com')
if config_type != 'tiramisu-api':
# FIXME
with warnings.catch_warnings(record=True) as w:
await cfg.option('d').value.set('toto_super.com')
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:
cfg.option('d').value.set('toto-.com')
assert len(w) == 0
raises(ValueError, "cfg.option('d').value.set('toto..com')")
#
cfg.option('f').value.set('toto.com')
cfg.option('f').value.set('toto')
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
raises(ValueError, "cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')")
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
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.t')
#
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('192.168.1.0')
cfg.option('g').value.set('192.168.1.29')
await cfg.option('d').value.set('toto-.com')
assert len(w) == 0
with pytest.raises(ValueError):
await cfg.option('d').value.set('toto..com')
#
await cfg.option('f').value.set('toto.com')
await cfg.option('f').value.set('toto')
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea')
with pytest.raises(ValueError):
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamean')
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nd')
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainnamea.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnameto.olongthathavemorethanmaximumsizeforatruedomainnameanditsnoteas.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('f').value.set('domainnametoolongthathavemorethanmaximumsizeforatruedomainname.nditsnoteasytogeneratesolongdomainnamewithoutrepeatdomainnamet.olongthathavemorethanmaximumsizeforatruedomainnameanditsnotea.ytogeneratesolongdomainnamewithoutrepeatbutimnotabletodoitnowie.xxxx')
await cfg.option('f').value.set('d')
await cfg.option('f').value.set('d.t')
#
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('f').value.set('192.168.1.1')
await cfg.option('g').value.set('toto.com')
await cfg.option('g').value.set('192.168.1.0')
await cfg.option('g').value.set('192.168.1.29')
assert not await list_sessions()
def test_special_domain_name(config_type):
@pytest.mark.asyncio
async def test_special_domain_name(config_type):
"""domain name option that starts with a number or not
"""
d = DomainnameOption('d', '')
e = DomainnameOption('e', '', type_='netbios')
e = DomainnameOption('e', '', type='netbios')
od = OptionDescription('a', '', [d, e])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('d').value.set('1toto.com')
cfg.option('d').value.set('123toto.com')
cfg.option('e').value.set('toto')
cfg.option('e').value.set('1toto')
async with await Config(od) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('d').value.set('1toto.com')
await cfg.option('d').value.set('123toto.com')
await cfg.option('e').value.set('toto')
await cfg.option('e').value.set('1toto')
assert not await list_sessions()
def test_domainname_netbios(config_type):
d = DomainnameOption('d', '', type_='netbios')
e = DomainnameOption('e', '', "toto", type_='netbios')
@pytest.mark.asyncio
async def test_domainname_netbios(config_type):
d = DomainnameOption('d', '', type='netbios')
e = DomainnameOption('e', '', "toto", type='netbios')
od = OptionDescription('a', '', [d, e])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('d').value.set('toto.com')")
cfg.option('d').value.set('toto')
raises(ValueError, "cfg.option('d').value.set('domainnametoolong')")
async with await Config(od) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
with pytest.raises(ValueError):
await cfg.option('d').value.set('toto.com')
await cfg.option('d').value.set('toto')
with pytest.raises(ValueError):
await cfg.option('d').value.set('domainnametoolong')
assert not await list_sessions()
def test_domainname_hostname(config_type):
d = DomainnameOption('d', '', type_='hostname')
e = DomainnameOption('e', '', "toto", type_='hostname')
@pytest.mark.asyncio
async def test_domainname_hostname(config_type):
d = DomainnameOption('d', '', type='hostname')
e = DomainnameOption('e', '', "toto", type='hostname')
od = OptionDescription('a', '', [d, e])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('d').value.set('toto.com')")
cfg.option('d').value.set('toto')
cfg.option('d').value.set('domainnametoolong')
async with await Config(od) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
with pytest.raises(ValueError):
await cfg.option('d').value.set('toto.com')
await cfg.option('d').value.set('toto')
await cfg.option('d').value.set('domainnametoolong')
assert not await list_sessions()
def test_email(config_type):
@pytest.mark.asyncio
async def test_email(config_type):
e = EmailOption('e', '')
od = OptionDescription('a', '', [e])
cfg = Config(od)
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('root@foo.com')
cfg.option('e').value.set('root@domain')
raises(ValueError, "cfg.option('e').value.set(1)")
raises(ValueError, "cfg.option('e').value.set('root')")
raises(ValueError, "cfg.option('e').value.set('root[]@domain')")
async with await Config(od) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('e').value.set('foo-bar.baz@example.com')
await cfg.option('e').value.set('root@foo.com')
await cfg.option('e').value.set('root@domain')
with pytest.raises(ValueError):
await cfg.option('e').value.set(1)
with pytest.raises(ValueError):
await cfg.option('e').value.set('root')
with pytest.raises(ValueError):
await cfg.option('e').value.set('root[]@domain')
assert not await list_sessions()
def test_url(config_type):
@pytest.mark.asyncio
async def test_url(config_type):
u = URLOption('u', '')
od = OptionDescription('a', '', [u])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('u').value.set('http://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)")
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('u').value.set('ftp://foo.com')")
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?var=value&var2=val2')
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/index.html')
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')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('u').value.set('https://FOO.COM:8443')")
async with await Config(od) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('u').value.set('http://foo.com')
await cfg.option('u').value.set('https://foo.com')
await cfg.option('u').value.set('https://foo.com/')
with pytest.raises(ValueError):
await cfg.option('u').value.set(1)
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('u').value.set('ftp://foo.com')
with pytest.raises(ValueError):
await cfg.option('u').value.set('foo.com')
with pytest.raises(ValueError):
await cfg.option('u').value.set(':/foo.com')
with pytest.raises(ValueError):
await cfg.option('u').value.set('foo.com/http://')
await cfg.option('u').value.set('https://foo.com/index.html')
await cfg.option('u').value.set('https://foo.com/index.html?var=value&var2=val2')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('u').value.set('https://foo.com/index\\n.html')
await cfg.option('u').value.set('https://foo.com:8443')
await cfg.option('u').value.set('https://foo.com:8443/')
await cfg.option('u').value.set('https://foo.com:8443/index.html')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('u').value.set('https://foo.com:84438989')
await cfg.option('u').value.set('https://foo.com:8443/INDEX')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('u').value.set('https://FOO.COM:8443')
assert not await list_sessions()

View File

@ -1,170 +1,215 @@
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from .config import config_type, get_config, value_list, global_owner, event_loop
import warnings
from py.test import raises
import pytest
from tiramisu import Config, IPOption, NetworkOption, NetmaskOption, \
PortOption, BroadcastOption, OptionDescription
from tiramisu.error import ValueWarning
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def test_ip(config_type):
@pytest.mark.asyncio
async def test_ip(config_type):
a = IPOption('a', '')
b = IPOption('b', '', private_only=True)
d = IPOption('d', '', warnings_only=True, private_only=True)
warnings.simplefilter("always", ValueWarning)
od = OptionDescription('od', '', [a, b, d])
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.0')
config.option('a').value.set('88.88.88.88')
config.option('a').value.set('0.0.0.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.0')
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')
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')")
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
await cfg.option('a').value.set('192.168.1.1')
await cfg.option('a').value.set('192.168.1.0')
await cfg.option('a').value.set('88.88.88.88')
await cfg.option('a').value.set('0.0.0.0')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('a').value.set('255.255.255.0')
await cfg.option('b').value.set('192.168.1.1')
await cfg.option('b').value.set('192.168.1.0')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('b').value.set('88.88.88.88')
await cfg.option('b').value.set('0.0.0.0')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('b').value.set('255.255.255.0')
with pytest.raises(ValueError):
await cfg.option('a').value.set('333.0.1.20')
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "IPOption('a', 'ip', default='192.000.023.01')")
with warnings.catch_warnings(record=True) as w:
config.option('d').value.set('88.88.88.88')
assert len(w) == 1
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
IPOption('a', 'ip', default='192.000.023.01')
with warnings.catch_warnings(record=True) as w:
await cfg.option('d').value.set('88.88.88.88')
assert len(w) == 1
assert not await list_sessions()
def test_ip_cidr():
@pytest.mark.asyncio
async def test_ip_cidr():
b = IPOption('b', '', private_only=True, cidr=True)
c = IPOption('c', '', private_only=True)
warnings.simplefilter("always", ValueWarning)
od = OptionDescription('od', '', [b, c])
config = Config(od)
raises(ValueError, "config.option('b').value.set('192.168.1.1')")
config.option('b').value.set('192.168.1.1/24')
raises(ValueError, "config.option('b').value.set('192.168.1.1/32')")
#
config.option('c').value.set('192.168.1.1')
raises(ValueError, "config.option('c').value.set('192.168.1.1/24')")
raises(ValueError, "config.option('c').value.set('192.168.1.1/32')")
async with await Config(od) as cfg:
with pytest.raises(ValueError):
await cfg.option('b').value.set('192.168.1.1')
await cfg.option('b').value.set('192.168.1.1/24')
with pytest.raises(ValueError):
await cfg.option('b').value.set('192.168.1.1/32')
#
await cfg.option('c').value.set('192.168.1.1')
with pytest.raises(ValueError):
await cfg.option('c').value.set('192.168.1.1/24')
with pytest.raises(ValueError):
await cfg.option('c').value.set('192.168.1.1/32')
assert not await list_sessions()
def test_ip_default():
@pytest.mark.asyncio
async def test_ip_default():
a = IPOption('a', '', '88.88.88.88')
od = OptionDescription('od', '', [a])
c = Config(od)
c.option('a').value.get() == '88.88.88.88'
async with await Config(od) as cfg:
await cfg.option('a').value.get() == '88.88.88.88'
assert not await list_sessions()
def test_ip_reserved(config_type):
@pytest.mark.asyncio
async def test_ip_reserved(config_type):
a = IPOption('a', '')
b = IPOption('b', '', allow_reserved=True)
c = IPOption('c', '', warnings_only=True)
od = OptionDescription('od', '', [a, b, c])
warnings.simplefilter("always", ValueWarning)
cfg = Config(od)
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')
if config_type != 'tiramisu-api':
# FIXME
with warnings.catch_warnings(record=True) as w:
cfg.option('c').value.set('240.94.1.1')
assert len(w) == 1
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('a').value.set('240.94.1.1')
await cfg.option('b').value.set('240.94.1.1')
if config_type != 'tiramisu-api':
# FIXME
with warnings.catch_warnings(record=True) as w:
await cfg.option('c').value.set('240.94.1.1')
assert len(w) == 1
assert not await list_sessions()
def test_network(config_type):
@pytest.mark.asyncio
async def test_network(config_type):
a = NetworkOption('a', '')
b = NetworkOption('b', '', warnings_only=True)
od = OptionDescription('od', '', [a, b])
warnings.simplefilter("always", ValueWarning)
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.0')
cfg.option('a').value.set('88.88.88.88')
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.1.1.1.1')")
if config_type != 'tiramisu-api':
# 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')")
if config_type != 'tiramisu-api':
# FIXME
with warnings.catch_warnings(record=True) as w:
cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
await cfg.option('a').value.set('192.168.1.1')
await cfg.option('a').value.set('192.168.1.0')
await cfg.option('a').value.set('88.88.88.88')
await cfg.option('a').value.set('0.0.0.0')
with pytest.raises(ValueError):
await cfg.option('a').value.set(1)
with pytest.raises(ValueError):
await cfg.option('a').value.set('1.1.1.1.1')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('a').value.set('255.255.255.0')
with pytest.raises(ValueError):
await cfg.option('a').value.set('192.168.001.0')
with pytest.raises(ValueError):
await cfg.option('a').value.set('333.168.1.1')
if config_type != 'tiramisu-api':
# FIXME
with warnings.catch_warnings(record=True) as w:
await cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1
assert not await list_sessions()
def test_network_cidr(config_type):
@pytest.mark.asyncio
async def test_network_cidr(config_type):
a = NetworkOption('a', '', cidr=True)
od = OptionDescription('od', '', [a])
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.0/24')
cfg.option('a').value.set('88.88.88.88/32')
cfg.option('a').value.set('0.0.0.0/0')
raises(ValueError, "cfg.option('a').value.set('192.168.1.1')")
raises(ValueError, "cfg.option('a').value.set('192.168.1.1/24')")
raises(ValueError, "cfg.option('a').value.set('2001:db00::0/24')")
async with await Config(od) as cfg:
# FIXME cfg = await get_config(cfg, config_type)
await cfg.option('a').value.set('192.168.1.1/32')
await cfg.option('a').value.set('192.168.1.0/24')
await cfg.option('a').value.set('88.88.88.88/32')
await cfg.option('a').value.set('0.0.0.0/0')
with pytest.raises(ValueError):
await cfg.option('a').value.set('192.168.1.1')
with pytest.raises(ValueError):
await cfg.option('a').value.set('192.168.1.1/24')
with pytest.raises(ValueError):
await cfg.option('a').value.set('2001:db00::0/24')
assert not await list_sessions()
def test_network_invalid():
raises(ValueError, "NetworkOption('a', '', default='toto')")
@pytest.mark.asyncio
async def test_network_invalid():
with pytest.raises(ValueError):
NetworkOption('a', '', default='toto')
def test_netmask(config_type):
@pytest.mark.asyncio
async def test_netmask(config_type):
a = NetmaskOption('a', '')
od = OptionDescription('od', '', [a])
cfg = Config(od)
cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('192.168.1.1.1')")
if config_type != 'tiramisu-api':
# FIXME
raises(ValueError, "cfg.option('a').value.set('192.168.1.1')")
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)")
cfg.option('a').value.set('0.0.0.0')
cfg.option('a').value.set('255.255.255.0')
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
with pytest.raises(ValueError):
await cfg.option('a').value.set('192.168.1.1.1')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(ValueError):
await cfg.option('a').value.set('192.168.1.1')
with pytest.raises(ValueError):
await cfg.option('a').value.set('192.168.1.0')
with pytest.raises(ValueError):
await cfg.option('a').value.set('88.88.88.88')
with pytest.raises(ValueError):
await cfg.option('a').value.set('255.255.255.000')
with pytest.raises(ValueError):
await cfg.option('a').value.set(2)
await cfg.option('a').value.set('0.0.0.0')
await cfg.option('a').value.set('255.255.255.0')
assert not await list_sessions()
def test_broadcast(config_type):
@pytest.mark.asyncio
async def test_broadcast(config_type):
a = BroadcastOption('a', '')
od = OptionDescription('od', '', [a])
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.001.255')")
raises(ValueError, "cfg.option('a').value.set('192.168.0.300')")
raises(ValueError, "cfg.option('a').value.set(1)")
raises(ValueError, "cfg.option('a').value.set(2)")
raises(ValueError, "cfg.option('a').value.set('2001:db8::1')")
cfg.option('a').value.set('0.0.0.0')
cfg.option('a').value.set('255.255.255.0')
async with await Config(od) as cfg:
# FIXME cfg = await get_config(cfg, config_type)
with pytest.raises(ValueError):
await cfg.option('a').value.set('192.168.1.255.1')
with pytest.raises(ValueError):
await cfg.option('a').value.set('192.168.001.255')
with pytest.raises(ValueError):
await cfg.option('a').value.set('192.168.0.300')
with pytest.raises(ValueError):
await cfg.option('a').value.set(1)
with pytest.raises(ValueError):
await cfg.option('a').value.set(2)
with pytest.raises(ValueError):
await cfg.option('a').value.set('2001:db8::1')
await cfg.option('a').value.set('0.0.0.0')
await cfg.option('a').value.set('255.255.255.0')
assert not await list_sessions()
def test_port(config_type):
@pytest.mark.asyncio
async def test_port(config_type):
a = PortOption('a', '')
b = PortOption('b', '', allow_zero=True)
c = PortOption('c', '', allow_zero=True, allow_registred=False)
@ -172,63 +217,86 @@ def test_port(config_type):
e = PortOption('e', '', allow_zero=True, allow_private=True)
f = PortOption('f', '', allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f])
cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('0')")
cfg.option('a').value.set('1')
cfg.option('a').value.set('1023')
cfg.option('a').value.set('1024')
cfg.option('a').value.set('49151')
raises(ValueError, "cfg.option('a').value.set('49152')")
raises(ValueError, "cfg.option('a').value.set('65535')")
raises(ValueError, "cfg.option('a').value.set('65536')")
async with await Config(od) as cfg:
# FIXME cfg = await get_config(cfg, config_type)
with pytest.raises(ValueError):
await cfg.option('a').value.set('0')
await cfg.option('a').value.set('1')
await cfg.option('a').value.set('1023')
await cfg.option('a').value.set('1024')
await cfg.option('a').value.set('49151')
with pytest.raises(ValueError):
await cfg.option('a').value.set('49152')
with pytest.raises(ValueError):
await cfg.option('a').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('a').value.set('65536')
cfg.option('b').value.set('0')
cfg.option('b').value.set('1')
cfg.option('b').value.set('1023')
cfg.option('b').value.set('1024')
cfg.option('b').value.set('49151')
raises(ValueError, "cfg.option('b').value.set('49152')")
raises(ValueError, "cfg.option('b').value.set('65535')")
raises(ValueError, "cfg.option('b').value.set('65536')")
await cfg.option('b').value.set('0')
await cfg.option('b').value.set('1')
await cfg.option('b').value.set('1023')
await cfg.option('b').value.set('1024')
await cfg.option('b').value.set('49151')
with pytest.raises(ValueError):
await cfg.option('b').value.set('49152')
with pytest.raises(ValueError):
await cfg.option('b').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('b').value.set('65536')
cfg.option('c').value.set('0')
cfg.option('c').value.set('1')
cfg.option('c').value.set('1023')
raises(ValueError, "cfg.option('c').value.set('1024')")
raises(ValueError, "cfg.option('c').value.set('49151')")
raises(ValueError, "cfg.option('c').value.set('49152')")
raises(ValueError, "cfg.option('c').value.set('65535')")
raises(ValueError, "cfg.option('c').value.set('65536')")
await cfg.option('c').value.set('0')
await cfg.option('c').value.set('1')
await cfg.option('c').value.set('1023')
with pytest.raises(ValueError):
await cfg.option('c').value.set('1024')
with pytest.raises(ValueError):
await cfg.option('c').value.set('49151')
with pytest.raises(ValueError):
await cfg.option('c').value.set('49152')
with pytest.raises(ValueError):
await cfg.option('c').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('c').value.set('65536')
cfg.option('d').value.set('0')
raises(ValueError, "cfg.option('d').value.set('1')")
raises(ValueError, "cfg.option('d').value.set('1023')")
raises(ValueError, "cfg.option('d').value.set('1024')")
raises(ValueError, "cfg.option('d').value.set('49151')")
raises(ValueError, "cfg.option('d').value.set('49152')")
raises(ValueError, "cfg.option('d').value.set('65535')")
raises(ValueError, "cfg.option('d').value.set('65536')")
await cfg.option('d').value.set('0')
with pytest.raises(ValueError):
await cfg.option('d').value.set('1')
with pytest.raises(ValueError):
await cfg.option('d').value.set('1023')
with pytest.raises(ValueError):
await cfg.option('d').value.set('1024')
with pytest.raises(ValueError):
await cfg.option('d').value.set('49151')
with pytest.raises(ValueError):
await cfg.option('d').value.set('49152')
with pytest.raises(ValueError):
await cfg.option('d').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('d').value.set('65536')
cfg.option('e').value.set('0')
cfg.option('e').value.set('1')
cfg.option('e').value.set('1023')
cfg.option('e').value.set('1024')
cfg.option('e').value.set('49151')
cfg.option('e').value.set('49152')
cfg.option('e').value.set('65535')
await cfg.option('e').value.set('0')
await cfg.option('e').value.set('1')
await cfg.option('e').value.set('1023')
await cfg.option('e').value.set('1024')
await cfg.option('e').value.set('49151')
await cfg.option('e').value.set('49152')
await cfg.option('e').value.set('65535')
raises(ValueError, "cfg.option('f').value.set('0')")
cfg.option('f').value.set('1')
cfg.option('f').value.set('1023')
cfg.option('f').value.set('1024')
cfg.option('f').value.set('49151')
cfg.option('f').value.set('49152')
cfg.option('f').value.set('65535')
raises(ValueError, "cfg.option('f').value.set('65536')")
with pytest.raises(ValueError):
await cfg.option('f').value.set('0')
await cfg.option('f').value.set('1')
await cfg.option('f').value.set('1023')
await cfg.option('f').value.set('1024')
await cfg.option('f').value.set('49151')
await cfg.option('f').value.set('49152')
await cfg.option('f').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('f').value.set('65536')
assert not await list_sessions()
def test_port_range(config_type):
@pytest.mark.asyncio
async def test_port_range(config_type):
a = PortOption('a', '', allow_range=True)
b = PortOption('b', '', allow_range=True, allow_zero=True)
c = PortOption('c', '', allow_range=True, allow_zero=True, allow_registred=False)
@ -236,72 +304,103 @@ def test_port_range(config_type):
e = PortOption('e', '', allow_range=True, allow_zero=True, allow_private=True)
f = PortOption('f', '', allow_range=True, allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f])
cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set('0')")
cfg.option('a').value.set('1')
cfg.option('a').value.set('1023')
cfg.option('a').value.set('1024')
cfg.option('a').value.set('49151')
raises(ValueError, "cfg.option('a').value.set('49152')")
raises(ValueError, "cfg.option('a').value.set('65535')")
raises(ValueError, "cfg.option('a').value.set('65536')")
cfg.option('a').value.set('1:49151')
raises(ValueError, "cfg.option('a').value.set('0:49151')")
raises(ValueError, "cfg.option('a').value.set('1:49152')")
async with await Config(od) as cfg:
# FIXME cfg = await get_config(cfg, config_type)
with pytest.raises(ValueError):
await cfg.option('a').value.set('0')
await cfg.option('a').value.set('1')
await cfg.option('a').value.set('1023')
await cfg.option('a').value.set('1024')
await cfg.option('a').value.set('49151')
with pytest.raises(ValueError):
await cfg.option('a').value.set('49152')
with pytest.raises(ValueError):
await cfg.option('a').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('a').value.set('65536')
await cfg.option('a').value.set('1:49151')
with pytest.raises(ValueError):
await cfg.option('a').value.set('0:49151')
with pytest.raises(ValueError):
await cfg.option('a').value.set('1:49152')
cfg.option('b').value.set('0')
cfg.option('b').value.set('1')
cfg.option('b').value.set('1023')
cfg.option('b').value.set('1024')
cfg.option('b').value.set('49151')
raises(ValueError, "cfg.option('b').value.set('49152')")
raises(ValueError, "cfg.option('b').value.set('65535')")
raises(ValueError, "cfg.option('b').value.set('65536')")
cfg.option('b').value.set('0:49151')
raises(ValueError, "cfg.option('b').value.set('0:49152')")
await cfg.option('b').value.set('0')
await cfg.option('b').value.set('1')
await cfg.option('b').value.set('1023')
await cfg.option('b').value.set('1024')
await cfg.option('b').value.set('49151')
with pytest.raises(ValueError):
await cfg.option('b').value.set('49152')
with pytest.raises(ValueError):
await cfg.option('b').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('b').value.set('65536')
await cfg.option('b').value.set('0:49151')
with pytest.raises(ValueError):
await cfg.option('b').value.set('0:49152')
cfg.option('c').value.set('0')
cfg.option('c').value.set('1')
cfg.option('c').value.set('1023')
raises(ValueError, "cfg.option('c').value.set('1024')")
raises(ValueError, "cfg.option('c').value.set('49151')")
raises(ValueError, "cfg.option('c').value.set('49152')")
raises(ValueError, "cfg.option('c').value.set('65535')")
raises(ValueError, "cfg.option('c').value.set('65536')")
cfg.option('c').value.set('0:1023')
raises(ValueError, "cfg.option('c').value.set('0:1024')")
await cfg.option('c').value.set('0')
await cfg.option('c').value.set('1')
await cfg.option('c').value.set('1023')
with pytest.raises(ValueError):
await cfg.option('c').value.set('1024')
with pytest.raises(ValueError):
await cfg.option('c').value.set('49151')
with pytest.raises(ValueError):
await cfg.option('c').value.set('49152')
with pytest.raises(ValueError):
await cfg.option('c').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('c').value.set('65536')
await cfg.option('c').value.set('0:1023')
with pytest.raises(ValueError):
await cfg.option('c').value.set('0:1024')
cfg.option('d').value.set('0')
raises(ValueError, "cfg.option('d').value.set('1')")
raises(ValueError, "cfg.option('d').value.set('1023')")
raises(ValueError, "cfg.option('d').value.set('1024')")
raises(ValueError, "cfg.option('d').value.set('49151')")
raises(ValueError, "cfg.option('d').value.set('49152')")
raises(ValueError, "cfg.option('d').value.set('65535')")
raises(ValueError, "cfg.option('d').value.set('65536')")
raises(ValueError, "cfg.option('d').value.set('0:0')")
raises(ValueError, "cfg.option('d').value.set('0:1')")
await cfg.option('d').value.set('0')
with pytest.raises(ValueError):
await cfg.option('d').value.set('1')
with pytest.raises(ValueError):
await cfg.option('d').value.set('1023')
with pytest.raises(ValueError):
await cfg.option('d').value.set('1024')
with pytest.raises(ValueError):
await cfg.option('d').value.set('49151')
with pytest.raises(ValueError):
await cfg.option('d').value.set('49152')
with pytest.raises(ValueError):
await cfg.option('d').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('d').value.set('65536')
with pytest.raises(ValueError):
await cfg.option('d').value.set('0:0')
with pytest.raises(ValueError):
await cfg.option('d').value.set('0:1')
cfg.option('e').value.set('0')
cfg.option('e').value.set('1')
cfg.option('e').value.set('1023')
cfg.option('e').value.set('1024')
cfg.option('e').value.set('49151')
cfg.option('e').value.set('49152')
cfg.option('e').value.set('65535')
cfg.option('e').value.set('0:65535')
raises(ValueError, "cfg.option('e').value.set('0:65536')")
await cfg.option('e').value.set('0')
await cfg.option('e').value.set('1')
await cfg.option('e').value.set('1023')
await cfg.option('e').value.set('1024')
await cfg.option('e').value.set('49151')
await cfg.option('e').value.set('49152')
await cfg.option('e').value.set('65535')
await cfg.option('e').value.set('0:65535')
with pytest.raises(ValueError):
await cfg.option('e').value.set('0:65536')
raises(ValueError, "cfg.option('f').value.set('0')")
cfg.option('f').value.set('1')
cfg.option('f').value.set('1023')
cfg.option('f').value.set('1024')
cfg.option('f').value.set('49151')
cfg.option('f').value.set('49152')
cfg.option('f').value.set('65535')
raises(ValueError, "cfg.option('f').value.set('65536')")
cfg.option('f').value.set('1:65535')
cfg.option('f').value.set('3:4')
raises(ValueError, "cfg.option('f').value.set('0:65535')")
raises(ValueError, "cfg.option('f').value.set('4:3')")
with pytest.raises(ValueError):
await cfg.option('f').value.set('0')
await cfg.option('f').value.set('1')
await cfg.option('f').value.set('1023')
await cfg.option('f').value.set('1024')
await cfg.option('f').value.set('49151')
await cfg.option('f').value.set('49152')
await cfg.option('f').value.set('65535')
with pytest.raises(ValueError):
await cfg.option('f').value.set('65536')
await cfg.option('f').value.set('1:65535')
await cfg.option('f').value.set('3:4')
with pytest.raises(ValueError):
await cfg.option('f').value.set('0:65535')
with pytest.raises(ValueError):
await cfg.option('f').value.set('4:3')
assert not await list_sessions()

View File

@ -2,15 +2,13 @@
from .autopath import do_autopath
do_autopath()
import weakref
import pytest
from tiramisu import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \
SymLinkOption, OptionDescription, DynOptionDescription, submulti, \
Config, GroupConfig, MetaConfig, Params, ParamOption
Config, GroupConfig, MetaConfig, Params, ParamOption, Calculation
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
from .config import event_loop
IS_DEREFABLE = True
@ -20,43 +18,52 @@ def funcname(*args, **kwargs):
return value
def test_deref_storage():
@pytest.mark.asyncio
async def test_deref_storage():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c._config_bag.context.cfgimpl_get_values()._p_)
del(c)
async with await Config(o) as cfg:
w = weakref.ref(cfg._config_bag.context.cfgimpl_get_values()._p_)
del cfg
assert w() is None
assert not await list_sessions()
def test_deref_value():
@pytest.mark.asyncio
async def test_deref_value():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c._config_bag.context.cfgimpl_get_values())
del(c)
async with await Config(o) as cfg:
w = weakref.ref(cfg._config_bag.context.cfgimpl_get_values())
del cfg
assert w() is None
assert not await list_sessions()
def test_deref_setting():
@pytest.mark.asyncio
async def test_deref_setting():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c._config_bag.context.cfgimpl_get_settings())
del(c)
async with await Config(o) as cfg:
w = weakref.ref(cfg._config_bag.context.cfgimpl_get_settings())
del cfg
assert w() is None
assert not await list_sessions()
def test_deref_config():
@pytest.mark.asyncio
async def test_deref_config():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c)
del(c)
async with await Config(o) as cfg:
w = weakref.ref(cfg)
del cfg
assert w() is None
assert not await list_sessions()
def test_deref_option():
@pytest.mark.asyncio
async def test_deref_option():
global IS_DEREFABLE
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
@ -69,9 +76,11 @@ def test_deref_option():
return
del(o)
assert w() is None
assert not await list_sessions()
def test_deref_optiondescription():
@pytest.mark.asyncio
async def test_deref_optiondescription():
if not IS_DEREFABLE:
return
b = BoolOption('b', '')
@ -81,259 +90,202 @@ def test_deref_optiondescription():
assert w() is not None
del(o)
assert w() is None
assert not await list_sessions()
def test_deref_option_cache():
@pytest.mark.asyncio
async def test_deref_option_cache():
if not IS_DEREFABLE:
return
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
o._build_cache()
await o._build_cache()
w = weakref.ref(b)
del(b)
assert w() is not None
del(o)
assert w() is None
assert not await list_sessions()
def test_deref_optiondescription_cache():
@pytest.mark.asyncio
async def test_deref_optiondescription_cache():
if not IS_DEREFABLE:
return
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
o._build_cache()
await o._build_cache()
w = weakref.ref(o)
del(b)
assert w() is not None
del(o)
assert w() is None
assert not await list_sessions()
def test_deref_option_config():
@pytest.mark.asyncio
async def test_deref_option_config():
if not IS_DEREFABLE:
return
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(b)
del(b)
assert w() is not None
del(o)
assert w() is not None
del(c)
async with await Config(o) as cfg:
w = weakref.ref(b)
del(b)
assert w() is not None
del(o)
assert w() is not None
del cfg
assert w() is None
assert not await list_sessions()
def test_deref_optiondescription_config():
@pytest.mark.asyncio
async def test_deref_optiondescription_config():
if not IS_DEREFABLE:
return
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(o)
del(b)
assert w() is not None
del(o)
assert w() is not None
del(c)
async with await Config(o) as cfg:
w = weakref.ref(o)
del(b)
assert w() is not None
del(o)
assert w() is not None
del cfg
assert w() is None
assert not await list_sessions()
#def test_deref_groupconfig():
# if not IS_DEREFABLE:
# return
# i1 = IntOption('i1', '')
# od1 = OptionDescription('od1', '', [i1])
# od2 = OptionDescription('od2', '', [od1])
# conf1 = Config(od2, 'conf1')
# conf2 = Config(od2, 'conf2')
# meta = GroupConfig([conf1, conf2])
# w = weakref.ref(conf1)
# del(conf1)
# assert w() is not None
# del(meta)
# assert w() is None
#def test_deref_metaconfig():
# if not IS_DEREFABLE:
# return
# i1 = IntOption('i1', '')
# od1 = OptionDescription('od1', '', [i1])
# od2 = OptionDescription('od2', '', [od1])
# conf1 = Config(od2, 'conf1')
# conf2 = Config(od2, 'conf2')
# meta = MetaConfig([conf1, conf2])
# w = weakref.ref(conf1)
# del(conf1)
# assert w() is not None
# del(meta)
# assert w() is None
def test_deref_consistency():
if not IS_DEREFABLE:
return
a = IPOption('a', '')
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
cfg = Config(od)
w = weakref.ref(a)
x = weakref.ref(b)
y = weakref.ref(od)
z = weakref.ref(cfg)
assert w() is not None
assert x() is not None
assert y() is not None
assert z() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert y() is not None
assert z() is not None
del(od)
assert w() is not None
assert x() is not None
assert y() is not None
assert z() is not None
del(cfg)
assert y() is None
assert z() is None
#assert w() is None
#assert x() is None
def test_deref_validator():
@pytest.mark.asyncio
async def test_deref_validator():
if not IS_DEREFABLE:
return
a = StrOption('a', '', default='yes')
b = StrOption('b', '', validator=funcname, validator_params=Params((ParamOption(a),)), default='val')
b = StrOption('b', '', validators=[Calculation(funcname, Params(ParamOption(a)))], default='val')
od = OptionDescription('root', '', [a, b])
cfg = Config(od)
w = weakref.ref(a)
x = weakref.ref(b)
y = weakref.ref(od)
z = weakref.ref(cfg)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(od)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(cfg)
async with await Config(od) as cfg:
w = weakref.ref(a)
x = weakref.ref(b)
y = weakref.ref(od)
z = weakref.ref(cfg)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(od)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del cfg
assert y() is None
assert z() is None
#assert w() is None
#assert x() is None
assert not await list_sessions()
def test_deref_callback():
@pytest.mark.asyncio
async def test_deref_callback():
if not IS_DEREFABLE:
return
a = StrOption('a', "", 'val')
b = StrOption('b', "", callback=funcname, callback_params=Params((ParamOption(a),)))
b = StrOption('b', "", Calculation(funcname, Params((ParamOption(a),))))
od = OptionDescription('root', '', [a, b])
cfg = Config(od)
w = weakref.ref(a)
x = weakref.ref(b)
y = weakref.ref(od)
z = weakref.ref(cfg)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(od)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(cfg)
async with await Config(od) as cfg:
w = weakref.ref(a)
x = weakref.ref(b)
y = weakref.ref(od)
z = weakref.ref(cfg)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(od)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del cfg
assert y() is None
assert z() is None
#assert w() is None
#assert x() is None
assert not await list_sessions()
def test_deref_symlink():
@pytest.mark.asyncio
async def test_deref_symlink():
if not IS_DEREFABLE:
return
a = BoolOption("a", "", default=False)
b = SymLinkOption("b", a)
od = OptionDescription('root', '', [a, b])
cfg = Config(od)
w = weakref.ref(a)
x = weakref.ref(b)
y = weakref.ref(od)
z = weakref.ref(cfg)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(od)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(cfg)
#assert w() is None
#assert x() is None
async with await Config(od) as cfg:
w = weakref.ref(a)
x = weakref.ref(b)
y = weakref.ref(od)
z = weakref.ref(cfg)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(od)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del cfg
assert y() is None
assert z() is None
assert not await list_sessions()
def test_deref_dyn():
@pytest.mark.asyncio
async def test_deref_dyn():
if not IS_DEREFABLE:
return
a = StrOption('a', '', ['val1', 'val2'], multi=True)
b = StrOption('b', '')
dod = DynOptionDescription('dod', '', [b], callback=funcname, callback_params=Params((ParamOption(a),)))
dod = DynOptionDescription('dod', '', [b], suffixes=Calculation(funcname, Params((ParamOption(a),))))
od = OptionDescription('od', '', [dod, a])
cfg = Config(od)
w = weakref.ref(a)
x = weakref.ref(b)
y = weakref.ref(od)
z = weakref.ref(cfg)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(od)
del(dod)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(cfg)
#assert w() is None
#assert x() is None
async with await Config(od) as cfg:
w = weakref.ref(a)
x = weakref.ref(b)
y = weakref.ref(od)
z = weakref.ref(cfg)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(a)
del(b)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del(od)
del(dod)
assert w() is not None
assert x() is not None
assert w() is not None
assert x() is not None
del cfg
assert y() is None
assert z() is None
assert not await list_sessions()

View File

@ -1,18 +1,13 @@
# coding: utf-8
from .autopath import do_autopath
do_autopath()
from py.test import raises
import pytest
from tiramisu.setting import groups
from tiramisu import Config, MetaConfig
from tiramisu import ChoiceOption, BoolOption, IntOption, \
StrOption, OptionDescription
from .test_state import _diff_opts, _diff_conf
from tiramisu import Config, MetaConfig, ChoiceOption, BoolOption, IntOption, \
StrOption, OptionDescription, groups
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
from .config import event_loop
def make_description():
@ -37,63 +32,73 @@ def make_description():
leader = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [leader])
interface1.impl_set_group_type(groups.family)
general = OptionDescription('general', '', [numero_etab, nom_machine,
nombre_interfaces, activer_proxy_client,
mode_conteneur_actif, mode_conteneur_actif2,
adresse_serveur_ntp, time_zone, wantref_option])
general.impl_set_group_type(groups.family)
new = OptionDescription('new', '', [], properties=('hidden',))
new.impl_set_group_type(groups.family)
creole = OptionDescription('creole', 'first tiramisu configuration', [general, interface1, new])
descr = OptionDescription('baseconfig', 'baseconifgdescr', [creole])
return descr
def test_copy():
cfg = Config(make_description())
ncfg = cfg.config.copy()
assert cfg.option('creole.general.numero_etab').value.get() == None
cfg.option('creole.general.numero_etab').value.set('oui')
assert cfg.option('creole.general.numero_etab').value.get() == 'oui'
assert ncfg.option('creole.general.numero_etab').value.get() == None
# _diff_opts(cfg.cfgimpl_get_description(), ncfg.cfgimpl_get_description())
# _diff_conf(cfg, ncfg)
# cfg.creole.general.numero_etab = 'oui'
# raises(AssertionError, "_diff_conf(cfg, ncfg)")
# ncfg.creole.general.numero_etab = 'oui'
# _diff_conf(cfg, ncfg)
def to_tuple(val):
return tuple([tuple(v) for v in val])
def test_copy_force_store_value():
descr = make_description()
conf = Config(descr)
conf2 = Config(descr)
assert to_tuple(conf.value.exportation()) == ((), (), (), ())
assert to_tuple(conf2.value.exportation()) == ((), (), (), ())
#
conf.property.read_write()
assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(conf2.value.exportation()) == ((), (), (), ())
#
conf2.property.read_only()
assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
#
conf.option('creole.general.wantref').value.set(True)
assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (True,), ('user',))
assert to_tuple(conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
@pytest.mark.asyncio
async def test_copy():
od = make_description()
async with await Config(od) as cfg:
async with await cfg.config.copy() as ncfg:
assert await cfg.option('creole.general.numero_etab').value.get() == None
await cfg.option('creole.general.numero_etab').value.set('oui')
assert await cfg.option('creole.general.numero_etab').value.get() == 'oui'
assert await ncfg.option('creole.general.numero_etab').value.get() == None
assert not await list_sessions()
def test_copy_force_store_value_metaconfig():
@pytest.mark.asyncio
async def test_copy_information():
od = make_description()
async with await Config(od) as cfg:
await cfg.information.set('key', 'value')
async with await cfg.config.copy() as ncfg:
assert await ncfg.information.get('key') == 'value'
assert not await list_sessions()
@pytest.mark.asyncio
async def test_copy_force_store_value():
od = make_description()
async with await Config(od) as conf:
async with await Config(od) as conf2:
assert to_tuple(await conf.value.exportation()) == ((), (), (), ())
assert to_tuple(await conf2.value.exportation()) == ((), (), (), ())
#
await conf.property.read_write()
assert to_tuple(await conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(await conf2.value.exportation()) == ((), (), (), ())
#
await conf2.property.read_only()
assert to_tuple(await conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(await conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
#
await conf.option('creole.general.wantref').value.set(True)
assert to_tuple(await conf.value.exportation()) == (('creole.general.wantref',), (None,), (True,), ('user',))
assert to_tuple(await conf2.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert not await list_sessions()
@pytest.mark.asyncio
async def test_copy_force_store_value_metaconfig():
descr = make_description()
meta = MetaConfig([], optiondescription=descr)
conf = meta.config.new(session_id='conf')
assert meta.property.get() == conf.property.get()
assert meta.permissive.get() == conf.permissive.get()
conf.property.read_write()
assert to_tuple(conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(meta.value.exportation()) == ((), (), (), ())
async with await MetaConfig([], optiondescription=descr) as meta:
async with await meta.config.new(session_id='conf') as conf:
assert await meta.property.get() == await conf.property.get()
assert await meta.permissive.get() == await conf.permissive.get()
await conf.property.read_write()
assert to_tuple(await conf.value.exportation()) == (('creole.general.wantref',), (None,), (False,), ('forced',))
assert to_tuple(await meta.value.exportation()) == ((), (), (), ())
assert not await list_sessions()

View File

@ -1,21 +1,27 @@
# coding: utf-8
from .autopath import do_autopath
do_autopath()
from py.test import raises
import pytest
from tiramisu.setting import groups, owners
from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \
NetworkOption, NetmaskOption, IntOption, FloatOption, \
UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \
StrOption, PortOption, BroadcastOption, DomainnameOption, \
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
OptionDescription, DynOptionDescription, SynDynOption, submulti, Leadership, \
Config, Params, ParamOption, ParamValue
Config, \
Params, ParamOption, ParamValue, ParamSuffix, ParamSelfOption, ParamDynOption, ParamIndex, \
Calculation, calc_value, \
delete_session
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError
from tiramisu.storage import list_sessions
from .config import event_loop
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
class ConvertDynOptionDescription(DynOptionDescription):
def convert_suffix_to_path(self, suffix):
# remove dot with is illegal
return suffix.replace('.', '')
def return_true(value, param=None, suffix=None):
@ -28,7 +34,7 @@ def return_dynval(value='val', suffix=None):
return value
def return_list2(suffix=None):
def return_list2(suffix):
return [str(suffix), 'val2']
@ -39,6 +45,10 @@ def return_list(val=None, suffix=None):
return ['val1', 'val2']
def return_list_dot(val=None, suffix=None):
return ['val.1', 'val.2']
def return_same_list(*args, **kwargs):
return ['val1', 'val1']
@ -55,770 +65,932 @@ def return_str(*args, **kwargs):
return 'str'
def test_build_dyndescription():
@pytest.mark.asyncio
async def test_build_dyndescription():
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_list)
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [dod])
cfg = Config(od1)
assert cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None}
async with await Config(od1) as cfg:
assert await cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None}
assert not await list_sessions()
def test_build_dyndescription_raise():
@pytest.mark.asyncio
async def test_build_dyndescription_raise():
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_raise)
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_raise))
od1 = OptionDescription('od', '', [dod])
cfg = Config(od1)
raises(ConfigError, "cfg.value.dict()")
async with await Config(od1) as cfg:
with pytest.raises(ConfigError):
await cfg.value.dict()
assert not await list_sessions()
def test_build_dyndescription_not_list():
@pytest.mark.asyncio
async def test_build_dyndescription_not_list():
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_str)
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_str))
od1 = OptionDescription('od', '', [dod])
cfg = Config(od1)
raises(ValueError, "cfg.value.dict()")
async with await Config(od1) as cfg:
with pytest.raises(ValueError):
await cfg.value.dict()
assert not await list_sessions()
def test_subpath_dyndescription():
@pytest.mark.asyncio
async def test_subpath_dyndescription():
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_list)
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1])
api = Config(od2)
assert api.value.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None}
async with await Config(od2) as cfg:
assert await cfg.value.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None}
assert not await list_sessions()
def test_list_dyndescription():
@pytest.mark.asyncio
async def test_list_dyndescription():
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
async with await Config(od2) as cfg:
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
assert not await list_sessions()
def test_unknown_dyndescription():
@pytest.mark.asyncio
async def test_unknown_dyndescription():
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
raises(AttributeError, "api.option('od.dodval3').value.get()")
raises(AttributeError, "api.option('od.dodval1.novalue').value.get()")
raises(AttributeError, "api.option('od.dodval1.stnoval1').value.get()")
async with await Config(od2) as cfg:
with pytest.raises(AttributeError):
await cfg.option('od.dodval3').value.get()
with pytest.raises(AttributeError):
await cfg.option('od.dodval1.novalue').value.get()
with pytest.raises(AttributeError):
await cfg.option('od.dodval1.stnoval1').value.get()
assert not await list_sessions()
def test_getdoc_dyndescription():
@pytest.mark.asyncio
async def test_getdoc_dyndescription():
st1 = StrOption('st', 'doc1')
dod = DynOptionDescription('dod', 'doc2', [st1], callback=return_list)
dod = DynOptionDescription('dod', 'doc2', [st1], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1])
api = Config(od2)
assert api.option('od.dodval1.stval1').option.name() == 'stval1'
assert api.option('od.dodval2.stval2').option.name() == 'stval2'
assert api.option('od.dodval1').option.name() == 'dodval1'
assert api.option('od.dodval2').option.name() == 'dodval2'
assert api.option('od.dodval1.stval1').option.doc() == 'doc1'
assert api.option('od.dodval2.stval2').option.doc() == 'doc1'
assert api.option('od.dodval1').option.doc() == 'doc2val1'
assert api.option('od.dodval2').option.doc() == 'doc2val2'
async with await Config(od2) as cfg:
assert await cfg.option('od.dodval1.stval1').option.name() == 'stval1'
assert await cfg.option('od.dodval2.stval2').option.name() == 'stval2'
assert await cfg.option('od.dodval1').option.name() == 'dodval1'
assert await cfg.option('od.dodval2').option.name() == 'dodval2'
assert await cfg.option('od.dodval1.stval1').option.doc() == 'doc1val1'
assert await cfg.option('od.dodval2.stval2').option.doc() == 'doc1val2'
assert await cfg.option('od.dodval1').option.doc() == 'doc2val1'
assert await cfg.option('od.dodval2').option.doc() == 'doc2val2'
assert not await list_sessions()
def test_mod_dyndescription():
@pytest.mark.asyncio
async def test_mod_dyndescription():
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
#
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.isdefault()
#
api.option('od.dodval1.stval1').value.set('yes')
assert api.option('od.dodval1.stval1').value.get() == 'yes'
assert api.option('od.dodval2.stval2').value.get() is None
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.isdefault()
#
api.option('od.dodval2.stval2').value.set('no')
assert api.option('od.dodval1.stval1').value.get() == 'yes'
assert api.option('od.dodval2.stval2').value.get() == 'no'
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.get() == owner
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
#
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
#
await cfg.option('od.dodval1.stval1').value.set('yes')
assert await cfg.option('od.dodval1.stval1').value.get() == 'yes'
assert await cfg.option('od.dodval2.stval2').value.get() is None
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
#
await cfg.option('od.dodval2.stval2').value.set('no')
assert await cfg.option('od.dodval1.stval1').value.get() == 'yes'
assert await cfg.option('od.dodval2.stval2').value.get() == 'no'
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.get() == owner
assert not await list_sessions()
def test_del_dyndescription():
@pytest.mark.asyncio
async def test_del_dyndescription():
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
api.option('od.dodval1.stval1').value.set('yes')
assert api.option('od.dodval1.stval1').owner.get() == owner
api.option('od.dodval1.stval1').value.reset()
assert api.option('od.dodval1.stval1').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
await cfg.option('od.dodval1.stval1').value.set('yes')
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
await cfg.option('od.dodval1.stval1').value.reset()
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert not await list_sessions()
def test_multi_dyndescription():
@pytest.mark.asyncio
async def test_multi_dyndescription():
st = StrOption('st', '', multi=True)
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
assert api.option('od.dodval1.stval1').value.get() == []
assert api.option('od.dodval2.stval2').value.get() == []
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval1.stval1').value.set(['yes'])
assert api.option('od.dodval1.stval1').value.get() == ['yes']
assert api.option('od.dodval2.stval2').value.get() == []
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval2.stval2').value.set(['no'])
assert api.option('od.dodval1.stval1').value.get() == ['yes']
assert api.option('od.dodval2.stval2').value.get() == ['no']
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.get() == owner
api.option('od.dodval1.stval1').value.set(['yes', 'yes'])
assert api.option('od.dodval1.stval1').value.get() == ['yes', 'yes']
api.option('od.dodval1.stval1').value.set(['yes'])
assert api.option('od.dodval1.stval1').value.get() == ['yes']
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.option('od.dodval1.stval1').value.get() == []
assert await cfg.option('od.dodval2.stval2').value.get() == []
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval1.stval1').value.set(['yes'])
assert await cfg.option('od.dodval1.stval1').value.get() == ['yes']
assert await cfg.option('od.dodval2.stval2').value.get() == []
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval2.stval2').value.set(['no'])
assert await cfg.option('od.dodval1.stval1').value.get() == ['yes']
assert await cfg.option('od.dodval2.stval2').value.get() == ['no']
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.get() == owner
await cfg.option('od.dodval1.stval1').value.set(['yes', 'no'])
assert await cfg.option('od.dodval1.stval1').value.get() == ['yes', 'no']
await cfg.option('od.dodval1.stval1').value.set(['yes'])
assert await cfg.option('od.dodval1.stval1').value.get() == ['yes']
assert not await list_sessions()
def test_prop_dyndescription():
@pytest.mark.asyncio
async def test_prop_dyndescription():
st = StrOption('st', '', properties=('test',))
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
assert set(api.option('od.dodval1.stval1').property.get()) == set(['test'])
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test'])
api.option('od.dodval2.stval2').property.add('test2')
assert set(api.option('od.dodval1.stval1').property.get()) == set(['test'])
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test', 'test2'])
api.option('od.dodval1.stval1').property.pop('test')
assert set(api.option('od.dodval1.stval1').property.get()) == set([])
#
assert set(api.option('od.dodval1').property.get()) == set([])
assert set(api.option('od.dodval2').property.get()) == set([])
api.option('od.dodval1').property.add('test1')
assert set(api.option('od.dodval1').property.get()) == set(['test1'])
assert set(api.option('od.dodval2').property.get()) == set([])
api.option('od.dodval1').property.pop('test1')
assert set(api.option('od.dodval1').property.get()) == set([])
assert set(api.option('od.dodval2').property.get()) == set([])
async with await Config(od2) as cfg:
assert set(await cfg.option('od.dodval1.stval1').property.get()) == set(['test'])
assert set(await cfg.option('od.dodval2.stval2').property.get()) == set(['test'])
await cfg.option('od.dodval2.stval2').property.add('test2')
assert set(await cfg.option('od.dodval1.stval1').property.get()) == set(['test'])
assert set(await cfg.option('od.dodval2.stval2').property.get()) == set(['test', 'test2'])
await cfg.option('od.dodval1.stval1').property.pop('test')
assert set(await cfg.option('od.dodval1.stval1').property.get()) == set([])
#
assert set(await cfg.option('od.dodval1').property.get()) == set([])
assert set(await cfg.option('od.dodval2').property.get()) == set([])
await cfg.option('od.dodval1').property.add('test1')
assert set(await cfg.option('od.dodval1').property.get()) == set(['test1'])
assert set(await cfg.option('od.dodval2').property.get()) == set([])
await cfg.option('od.dodval1').property.pop('test1')
assert set(await cfg.option('od.dodval1').property.get()) == set([])
assert set(await cfg.option('od.dodval2').property.get()) == set([])
assert not await list_sessions()
def test_prop_dyndescription_force_store_value():
@pytest.mark.asyncio
async def test_prop_dyndescription_force_store_value():
st = StrOption('st', '', properties=('force_store_value',))
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
raises(ConfigError, "Config(od2)")
async with await Config(od2) as cfg:
await cfg.property.read_write()
assert await cfg.value.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None}
assert not await list_sessions()
def test_callback_dyndescription():
st = StrOption('st', '', callback=return_dynval)
dod = DynOptionDescription('dod', '', [st], callback=return_list)
@pytest.mark.asyncio
async def test_prop_dyndescription_force_store_value_calculation_prefix():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', Calculation(return_list, Params(ParamSuffix())) , properties=('force_store_value',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst))))
od = OptionDescription('od', '', [dod, lst])
od2 = OptionDescription('od', '', [od])
async with await Config(od2) as cfg:
await cfg.property.read_write()
assert await cfg.option('od.dodval1.stval1').owner.isdefault() == False
assert await cfg.option('od.dodval2.stval2').owner.isdefault() == False
assert await cfg.value.dict() == {'od.lst': ['val1', 'val2'], 'od.dodval1.stval1': 'val1', 'od.dodval2.stval2': 'val2'}
#
await cfg.option('od.lst').value.set(['val1', 'val2', 'val3'])
assert await cfg.option('od.dodval3.stval3').owner.isdefault() == False
assert await cfg.option('od.dodval1.stval1').owner.isdefault() == False
assert await cfg.option('od.dodval2.stval2').owner.isdefault() == False
assert await cfg.value.dict() == {'od.lst': ['val1', 'val2', 'val3'], 'od.dodval1.stval1': 'val1', 'od.dodval2.stval2': 'val2', 'od.dodval3.stval3': 'val3'}
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_dyndescription():
st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
assert api.option('od.dodval1.stval1').value.get() == 'val'
assert api.option('od.dodval2.stval2').value.get() == 'val'
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval1.stval1').value.set('val2')
assert api.option('od.dodval1.stval1').value.get() == 'val2'
assert api.option('od.dodval2.stval2').value.get() == 'val'
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval1.stval1').value.reset()
assert api.option('od.dodval1.stval1').value.get() == 'val'
assert api.option('od.dodval2.stval2').value.get() == 'val'
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.option('od.dodval1.stval1').value.get() == 'val'
assert await cfg.option('od.dodval2.stval2').value.get() == 'val'
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval1.stval1').value.set('val2')
assert await cfg.option('od.dodval1.stval1').value.get() == 'val2'
assert await cfg.option('od.dodval2.stval2').value.get() == 'val'
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval1.stval1').value.reset()
assert await cfg.option('od.dodval1.stval1').value.get() == 'val'
assert await cfg.option('od.dodval2.stval2').value.get() == 'val'
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
assert not await list_sessions()
def test_callback_list_dyndescription():
st = StrOption('st', '', callback=return_list2, multi=True)
dod = DynOptionDescription('dod', '', [st], callback=return_list)
@pytest.mark.asyncio
async def test_callback_dyndescription_outside_wrong_param():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst))))
out = StrOption('out', '', Calculation(return_dynval, Params(ParamOption(st))))
od = OptionDescription('od', '', [dod, out])
od2 = OptionDescription('od', '', [od, lst])
async with await Config(od2) as cfg:
with pytest.raises(ConfigError):
await cfg.value.dict()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_dyndescription_outside1():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst))))
out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, 'val1', dod))))
od = OptionDescription('od', '', [dod, out])
od2 = OptionDescription('od', '', [od, lst])
async with await Config(od2) as cfg:
assert await cfg.value.dict() == {'od.dodval1.stval1': 'val', 'od.dodval2.stval2': 'val', 'od.out': 'val', 'lst': ['val1', 'val2']}
await cfg.option('od.dodval1.stval1').value.set('val1')
await cfg.option('od.dodval2.stval2').value.set('val2')
assert await cfg.value.dict() == {'od.dodval1.stval1': 'val1', 'od.dodval2.stval2': 'val2', 'od.out': 'val1', 'lst': ['val1', 'val2']}
await cfg.option('lst').value.set(['val2'])
with pytest.raises(ConfigError):
await cfg.value.dict()
await cfg.option('lst').value.set(['val1'])
assert await cfg.value.dict() == {'od.dodval1.stval1': 'val1', 'od.out': 'val1', 'lst': ['val1']}
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_dyndescription_outside2():
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
out = StrOption('out', '')
st = StrOption('st', '', Calculation(return_dynval, Params(ParamOption(out))))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst))))
od = OptionDescription('od', '', [dod, out])
od2 = OptionDescription('od', '', [od, lst])
async with await Config(od2) as cfg:
assert await cfg.value.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None, 'od.out': None, 'lst': ['val1', 'val2']}
await cfg.option('od.out').value.set('val1')
assert await cfg.value.dict() == {'od.dodval1.stval1': 'val1', 'od.dodval2.stval2': 'val1', 'od.out': 'val1', 'lst': ['val1', 'val2']}
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_list_dyndescription():
st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
assert api.option('od.dodval1.stval1').value.get() == ['val1', 'val2']
assert api.option('od.dodval2.stval2').value.get() == ['val2', 'val2']
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval1.stval1').value.set(['val3', 'val2'])
assert api.option('od.dodval1.stval1').value.get() == ['val3', 'val2']
assert api.option('od.dodval2.stval2').value.get() == ['val2', 'val2']
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.option('od.dodval1.stval1').value.get() == ['val1', 'val2']
assert await cfg.option('od.dodval2.stval2').value.get() == ['val2', 'val2']
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval1.stval1').value.set(['val3', 'val2'])
assert await cfg.option('od.dodval1.stval1').value.get() == ['val3', 'val2']
assert await cfg.option('od.dodval2.stval2').value.get() == ['val2', 'val2']
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
assert not await list_sessions()
def test_mandatory_dyndescription():
@pytest.mark.asyncio
async def test_mandatory_dyndescription():
st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
api.property.read_only()
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()")
api.property.read_write()
api.option('od.dodval1.stval1').value.set('val')
api.property.read_only()
assert api.option('od.dodval1.stval1').value.get() == 'val'
raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()")
api.property.read_write()
api.option('od.dodval1.stval1').value.reset()
api.property.read_only()
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
assert list(api.value.mandatory()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
async with await Config(od2) as cfg:
await cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
await cfg.option('od.dodval1.stval1').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('od.dodval2.stval2').value.get()
await cfg.property.read_write()
await cfg.option('od.dodval1.stval1').value.set('val')
await cfg.property.read_only()
assert await cfg.option('od.dodval1.stval1').value.get() == 'val'
with pytest.raises(PropertiesOptionError):
await cfg.option('od.dodval2.stval2').value.get()
await cfg.property.read_write()
await cfg.option('od.dodval1.stval1').value.reset()
await cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
await cfg.option('od.dodval1.stval1').value.get()
assert list(await cfg.value.mandatory()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
assert not await list_sessions()
def test_build_dyndescription_context():
@pytest.mark.asyncio
async def test_build_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params=Params(ParamOption(val1)))
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od1 = OptionDescription('od', '', [dod, val1])
cfg = Config(od1)
assert cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None, 'val1': ['val1', 'val2']}
async with await Config(od1) as cfg:
assert await cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None, 'val1': ['val1', 'val2']}
assert not await list_sessions()
def test_subpath_dyndescription_context():
@pytest.mark.asyncio
async def test_subpath_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params=Params(ParamOption(val1)))
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od1 = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od1])
api = Config(od2)
assert api.value.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None, 'od.val1': ['val1', 'val2']}
async with await Config(od2) as cfg:
assert await cfg.value.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None, 'od.val1': ['val1', 'val2']}
assert not await list_sessions()
def test_list_dyndescription_context():
@pytest.mark.asyncio
async def test_list_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
raises(AttributeError, "api.option('od.dodval3').value.get()")
async with await Config(od2) as cfg:
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
with pytest.raises(AttributeError):
await cfg.option('od.dodval3').value.get()
assert not await list_sessions()
def test_mod_dyndescription_context():
@pytest.mark.asyncio
async def test_mod_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval1.stval1').value.set('yes')
assert api.option('od.dodval1.stval1').value.get() == 'yes'
assert api.option('od.dodval2.stval2').value.get() is None
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval2.stval2').value.set('no')
assert api.option('od.dodval1.stval1').value.get() == 'yes'
assert api.option('od.dodval2.stval2').value.get() == 'no'
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.get() == owner
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval1.stval1').value.set('yes')
assert await cfg.option('od.dodval1.stval1').value.get() == 'yes'
assert await cfg.option('od.dodval2.stval2').value.get() is None
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval2.stval2').value.set('no')
assert await cfg.option('od.dodval1.stval1').value.get() == 'yes'
assert await cfg.option('od.dodval2.stval2').value.get() == 'no'
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.get() == owner
assert not await list_sessions()
def test_del_dyndescription_context():
@pytest.mark.asyncio
async def test_del_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
api.option('od.dodval1.stval1').value.set('yes')
assert api.option('od.dodval1.stval1').owner.get() == owner
api.option('od.dodval1.stval1').value.reset()
assert api.option('od.dodval1.stval1').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
await cfg.option('od.dodval1.stval1').value.set('yes')
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
await cfg.option('od.dodval1.stval1').value.reset()
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert not await list_sessions()
def test_multi_dyndescription_context():
@pytest.mark.asyncio
async def test_multi_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', multi=True)
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
st = StrOption('st', '', multi=True, properties=('notunique',))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
assert api.option('od.dodval1.stval1').value.get() == []
assert api.option('od.dodval2.stval2').value.get() == []
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval1.stval1').value.set(['yes'])
assert api.option('od.dodval1.stval1').value.get() == ['yes']
assert api.option('od.dodval2.stval2').value.get() == []
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval2.stval2').value.set(['no'])
assert api.option('od.dodval1.stval1').value.get() == ['yes']
assert api.option('od.dodval2.stval2').value.get() == ['no']
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.get() == owner
api.option('od.dodval1.stval1').value.set(['yes', 'yes'])
assert api.option('od.dodval1.stval1').value.get() == ['yes', 'yes']
api.option('od.dodval1.stval1').value.set(['yes'])
assert api.option('od.dodval1.stval1').value.get() == ['yes']
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.option('od.dodval1.stval1').value.get() == []
assert await cfg.option('od.dodval2.stval2').value.get() == []
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval1.stval1').value.set(['yes'])
assert await cfg.option('od.dodval1.stval1').value.get() == ['yes']
assert await cfg.option('od.dodval2.stval2').value.get() == []
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval2.stval2').value.set(['no'])
assert await cfg.option('od.dodval1.stval1').value.get() == ['yes']
assert await cfg.option('od.dodval2.stval2').value.get() == ['no']
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.get() == owner
await cfg.option('od.dodval1.stval1').value.set(['yes', 'yes'])
assert await cfg.option('od.dodval1.stval1').value.get() == ['yes', 'yes']
await cfg.option('od.dodval1.stval1').value.set(['yes'])
assert await cfg.option('od.dodval1.stval1').value.get() == ['yes']
assert not await list_sessions()
def test_prop_dyndescription_context():
@pytest.mark.asyncio
async def test_prop_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('test',))
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
assert set(api.option('od.dodval1.stval1').property.get()) == set(['test'])
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test'])
api.option('od.dodval2.stval2').property.add('test2')
assert set(api.option('od.dodval1.stval1').property.get()) == set(['test'])
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test', 'test2'])
api.option('od.dodval1.stval1').property.pop('test')
assert set(api.option('od.dodval1.stval1').property.get()) == set([])
assert set(api.option('od.dodval2.stval2').property.get()) == set(['test', 'test2'])
async with await Config(od2) as cfg:
assert set(await cfg.option('od.dodval1.stval1').property.get()) == set(['test'])
assert set(await cfg.option('od.dodval2.stval2').property.get()) == set(['test'])
await cfg.option('od.dodval2.stval2').property.add('test2')
assert set(await cfg.option('od.dodval1.stval1').property.get()) == set(['test'])
assert set(await cfg.option('od.dodval2.stval2').property.get()) == set(['test', 'test2'])
await cfg.option('od.dodval1.stval1').property.pop('test')
assert set(await cfg.option('od.dodval1.stval1').property.get()) == set([])
assert set(await cfg.option('od.dodval2.stval2').property.get()) == set(['test', 'test2'])
assert not await list_sessions()
def test_callback_dyndescription_context():
@pytest.mark.asyncio
async def test_callback_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', callback=return_dynval)
dod = DynOptionDescription('dod', '', [st], callback=return_list)
st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
assert api.option('od.dodval1.stval1').value.get() == 'val'
assert api.option('od.dodval2.stval2').value.get() == 'val'
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval1.stval1').value.set('val2')
assert api.option('od.dodval1.stval1').value.get() == 'val2'
assert api.option('od.dodval2.stval2').value.get() == 'val'
assert api.option('od.dodval1.stval1').owner.get() == owner
assert api.option('od.dodval2.stval2').owner.isdefault()
api.option('od.dodval1.stval1').value.reset()
assert api.option('od.dodval1.stval1').value.get() == 'val'
assert api.option('od.dodval2.stval2').value.get() == 'val'
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.option('od.dodval1.stval1').value.get() == 'val'
assert await cfg.option('od.dodval2.stval2').value.get() == 'val'
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval1.stval1').value.set('val2')
assert await cfg.option('od.dodval1.stval1').value.get() == 'val2'
assert await cfg.option('od.dodval2.stval2').value.get() == 'val'
assert await cfg.option('od.dodval1.stval1').owner.get() == owner
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
await cfg.option('od.dodval1.stval1').value.reset()
assert await cfg.option('od.dodval1.stval1').value.get() == 'val'
assert await cfg.option('od.dodval2.stval2').value.get() == 'val'
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.isdefault()
assert not await list_sessions()
def test_mandatory_dyndescription_context():
@pytest.mark.asyncio
async def test_mandatory_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
api.property.read_only()
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()")
api.property.read_write()
api.option('od.dodval1.stval1').value.set('val')
api.property.read_only()
assert api.option('od.dodval1.stval1').value.get() == 'val'
raises(PropertiesOptionError, "api.option('od.dodval2.stval2').value.get()")
api.property.read_write()
api.option('od.dodval1.stval1').value.reset()
api.property.read_only()
raises(PropertiesOptionError, "api.option('od.dodval1.stval1').value.get()")
assert list(api.value.mandatory()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
async with await Config(od2) as cfg:
await cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
await cfg.option('od.dodval1.stval1').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('od.dodval2.stval2').value.get()
await cfg.property.read_write()
await cfg.option('od.dodval1.stval1').value.set('val')
await cfg.property.read_only()
assert await cfg.option('od.dodval1.stval1').value.get() == 'val'
with pytest.raises(PropertiesOptionError):
await cfg.option('od.dodval2.stval2').value.get()
await cfg.property.read_write()
await cfg.option('od.dodval1.stval1').value.reset()
await cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
await cfg.option('od.dodval1.stval1').value.get()
assert list(await cfg.value.mandatory()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
assert not await list_sessions()
def test_increase_dyndescription_context():
@pytest.mark.asyncio
async def test_increase_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
api.property.read_write()
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
raises(AttributeError, "api.option('od.dodval3.stval3').value.get()")
api.option('od.val1').value.set(['val1', 'val2', 'val3'])
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
assert api.option('od.dodval3.stval3').value.get() is None
async with await Config(od2) as cfg:
await cfg.property.read_write()
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
with pytest.raises(AttributeError):
await cfg.option('od.dodval3.stval3').value.get()
await cfg.option('od.val1').value.set(['val1', 'val2', 'val3'])
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
assert await cfg.option('od.dodval3.stval3').value.get() is None
assert not await list_sessions()
def test_decrease_dyndescription_context():
@pytest.mark.asyncio
async def test_decrease_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
api.property.read_write()
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
api.option('od.dodval2.stval2').value.set('yes')
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() == 'yes'
assert api.option('od.dodval1.stval1').owner.isdefault()
assert api.option('od.dodval2.stval2').owner.get() == owner
raises(AttributeError, "api.option('od.dodval3').value.get()")
api.option('od.val1').value.set(['val1'])
assert api.option('od.dodval1.stval1').value.get() is None
raises(AttributeError, "api.option('od.dodval2').value.get()")
raises(AttributeError, "api.option('od.dodval3').value.get()")
assert api.option('od.dodval1.stval1').owner.isdefault()
raises(AttributeError, "api.option('od.dodval2.stval2').owner.get()")
raises(AttributeError, "api.option('od.dodval2.stval2').value.get()")
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
await cfg.property.read_write()
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
await cfg.option('od.dodval2.stval2').value.set('yes')
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() == 'yes'
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
assert await cfg.option('od.dodval2.stval2').owner.get() == owner
with pytest.raises(AttributeError):
await cfg.option('od.dodval3').value.get()
await cfg.option('od.val1').value.set(['val1'])
assert await cfg.option('od.dodval1.stval1').value.get() is None
with pytest.raises(AttributeError):
await cfg.option('od.dodval2').value.get()
with pytest.raises(AttributeError):
await cfg.option('od.dodval3').value.get()
assert await cfg.option('od.dodval1.stval1').owner.isdefault()
with pytest.raises(AttributeError):
await cfg.option('od.dodval2.stval2').owner.get()
with pytest.raises(AttributeError):
await cfg.option('od.dodval2.stval2').value.get()
assert not await list_sessions()
def test_dyndescription_root():
@pytest.mark.asyncio
async def test_dyndescription_root():
boolean = BoolOption('boolean', '', True)
st1 = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
'action': 'disabled'}])
dod = DynOptionDescription('dod', '', [boolean, st1], callback=return_list)
raises(ConfigError, "Config(dod)")
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean),
'expected': ParamValue(False),
'default': ParamValue(None)}))
st1 = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [boolean, st1], suffixes=Calculation(return_list))
with pytest.raises(ConfigError):
await Config(dod, session_id='error')
await delete_session('error')
assert not await list_sessions()
def test_requires_dyndescription():
@pytest.mark.asyncio
async def test_dyndescription_disable_suffix_root():
boolean = BoolOption('boolean', '', True)
st1 = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
'action': 'disabled'}])
dod = DynOptionDescription('dod', '', [st1], callback=return_list)
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean),
'expected': ParamValue(False),
'default': ParamValue(None)}))
val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True)
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,))
od = OptionDescription('root', 'root', [boolean, val, dod])
config = await Config(od, session_id='test')
await config.property.read_write()
assert await config.value.dict() == {'boolean': True, 'val': ['ext1', 'ext2'], 'dodext1.stext1': None, 'dodext2.stext2': None}
#
await config.option('boolean').value.set(False)
assert await config.value.dict() == {'boolean': False}
await delete_session('test')
assert not await list_sessions()
@pytest.mark.asyncio
async def test_dyndescription_disable_suffix_root_2():
boolean = BoolOption('boolean', '', False)
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean),
'expected': ParamValue(False),
'default': ParamValue(None)}))
val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True)
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,))
od = OptionDescription('root', 'root', [boolean, val, dod])
config = await Config(od, session_id='test')
await config.property.read_write()
assert await config.value.dict() == {'boolean': False}
#
await config.option('boolean').value.set(True)
assert await config.value.dict() == {'boolean': True, 'val': ['ext1', 'ext2'], 'dodext1.stext1': None, 'dodext2.stext2': None}
await delete_session('test')
assert not await list_sessions()
@pytest.mark.asyncio
async def test_dyndescription_disable_suffix():
boolean = BoolOption('boolean', '', True)
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean),
'expected': ParamValue(False),
'default': ParamValue(None)}))
val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True)
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,))
od = OptionDescription('root', 'root', [boolean, val, dod])
od2 = OptionDescription('root', 'root', [od])
config = await Config(od2, session_id='test')
await config.property.read_write()
assert await config.value.dict() == {'root.boolean': True, 'root.val': ['ext1', 'ext2'], 'root.dodext1.stext1': None, 'root.dodext2.stext2': None}
#
await config.option('root.boolean').value.set(False)
assert await config.value.dict() == {'root.boolean': False}
await delete_session('test')
assert not await list_sessions()
@pytest.mark.asyncio
async def test_requires_dyndescription():
boolean = BoolOption('boolean', '', True)
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
'expected': ParamValue(False),
'default': ParamValue(None)}))
st1 = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1, boolean])
api = Config(od2)
api.property.read_write()
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
#
api.option('boolean').value.set(False)
props = []
try:
api.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
props = []
try:
api.option('od.dodval2.stval2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
#
api.option('boolean').value.set(True)
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
#transitive
api.option('boolean').property.add('disabled')
props = []
try:
api.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
props = []
try:
api.option('od.dodval2.stval2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
async with await Config(od2) as cfg:
await cfg.property.read_write()
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
#
await cfg.option('boolean').value.set(False)
props = []
try:
await cfg.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
props = []
try:
await cfg.option('od.dodval2.stval2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
#
await cfg.option('boolean').value.set(True)
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
#transitive
await cfg.option('boolean').property.add('disabled')
props = []
try:
await cfg.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
props = []
try:
await cfg.option('od.dodval2.stval2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
assert not await list_sessions()
def test_requires_dyndescription_boolean():
@pytest.mark.asyncio
async def test_requires_dyndescription_boolean():
boolean1 = BoolOption('boolean1', '', True)
boolean = BoolOption('boolean', '', True, requires=[{'option': boolean1,
'expected': False,
'action': 'disabled'}])
st = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
'action': 'disabled'}])
dod = DynOptionDescription('dod', '', [st], callback=return_list)
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean1, raisepropertyerror=True),
'expected': ParamValue(False),
'default': ParamValue(None)}))
boolean = BoolOption('boolean', '', True, properties=(disabled_property,))
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
'expected': ParamValue(False),
'default': ParamValue(None)}))
st = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od, boolean1, boolean])
cfg = Config(od2)
cfg.property.read_write()
assert cfg.value.dict() == {'boolean1': True,
'boolean': True,
'od.dodval1.stval1': None,
'od.dodval2.stval2': None}
#
cfg.option('boolean').value.set(False)
assert cfg.value.dict() == {'boolean1': True,
'boolean': False}
#
cfg.option('boolean').value.set(True)
assert cfg.value.dict() == {'boolean1': True,
'boolean': True,
'od.dodval1.stval1': None,
'od.dodval2.stval2': None}
#
cfg.option('boolean1').value.set(False)
assert cfg.value.dict() == {'boolean1': False}
async with await Config(od2) as cfg:
await cfg.property.read_write()
assert await cfg.value.dict() == {'boolean1': True,
'boolean': True,
'od.dodval1.stval1': None,
'od.dodval2.stval2': None}
#
await cfg.option('boolean').value.set(False)
assert await cfg.value.dict() == {'boolean1': True,
'boolean': False}
#
await cfg.option('boolean').value.set(True)
assert await cfg.value.dict() == {'boolean1': True,
'boolean': True,
'od.dodval1.stval1': None,
'od.dodval2.stval2': None}
#
await cfg.option('boolean1').value.set(False)
assert await cfg.value.dict() == {'boolean1': False}
assert not await list_sessions()
def test_requires_dyndescription_in_dyn():
@pytest.mark.asyncio
async def test_requires_dyndescription_in_dyn():
boolean = BoolOption('boolean', '', True)
st = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
'action': 'disabled'}])
dod = DynOptionDescription('dod', '', [boolean, st], callback=return_list)
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
'expected': ParamValue(False),
'default': ParamValue(None)}))
st = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [boolean, st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
cfg.property.read_write()
async with await Config(od2) as cfg:
await cfg.property.read_write()
assert cfg.option('od.dodval1.stval1').value.get() is None
assert cfg.option('od.dodval2.stval2').value.get() is None
#
cfg.option('od.dodval1.booleanval1').value.set(False)
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
#
await cfg.option('od.dodval1.booleanval1').value.set(False)
props = []
try:
cfg.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset(['disabled'])
props = []
cfg.option('od.dodval2.stval2').value.get()
#
cfg.option('od.dodval1.booleanval1').value.set(True)
assert cfg.option('od.dodval1.stval1').value.get() is None
assert cfg.option('od.dodval2.stval2').value.get() is None
props = []
try:
await cfg.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset(['disabled'])
props = []
await cfg.option('od.dodval2.stval2').value.get()
#
await cfg.option('od.dodval1.booleanval1').value.set(True)
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
assert not await list_sessions()
def test_requires_dyndescription2():
@pytest.mark.asyncio
async def test_requires_dyndescription2():
boolean = BoolOption('boolean', '', True)
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_list,
requires=[{'option': boolean, 'expected': False,
'action': 'disabled'}])
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
'expected': ParamValue(False),
'default': ParamValue(None)}))
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list), properties=(disabled_property,))
od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1, boolean])
api = Config(od2)
api.property.read_write()
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
#
api.option('boolean').value.set(False)
props = []
try:
api.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
props = []
try:
api.option('od.dodval2.stval2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
#
api.option('boolean').value.set(True)
assert api.option('od.dodval1.stval1').value.get() is None
assert api.option('od.dodval2.stval2').value.get() is None
#transitive
api.option('boolean').property.add('disabled')
props = []
try:
api.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
props = []
try:
api.option('od.dodval2.stval2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
async with await Config(od2) as cfg:
await cfg.property.read_write()
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
#
await cfg.option('boolean').value.set(False)
props = []
try:
await cfg.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
props = []
try:
await cfg.option('od.dodval2.stval2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
#
await cfg.option('boolean').value.set(True)
assert await cfg.option('od.dodval1.stval1').value.get() is None
assert await cfg.option('od.dodval2.stval2').value.get() is None
#transitive
await cfg.option('boolean').property.add('disabled')
props = []
try:
await cfg.option('od.dodval1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
props = []
try:
await cfg.option('od.dodval2.stval2').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert frozenset(props) == frozenset(['disabled'])
assert not await list_sessions()
def test_validator_dyndescription():
@pytest.mark.asyncio
async def test_validator_dyndescription():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', validator=return_true, validator_params=Params((ParamValue('yes'),)), default='val')
dod = DynOptionDescription('dod', '', [st], callback=return_list)
st = StrOption('st', '', validators=[Calculation(return_true, Params((ParamSelfOption(), ParamValue('yes'))))], default='val')
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
assert api.option('od.dodval1.stval1').value.get() == 'val'
raises(ValueError, "api.option('od.dodval1.stval1').value.set('no')")
api.option('od.dodval1.stval1').value.set('val')
async with await Config(od2) as cfg:
assert await cfg.option('od.dodval1.stval1').value.get() == 'val'
with pytest.raises(ValueError):
await cfg.option('od.dodval1.stval1').value.set('no')
await cfg.option('od.dodval1.stval1').value.set('val')
assert not await list_sessions()
def test_makedict_dyndescription_context():
@pytest.mark.asyncio
async def test_makedict_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
api.option('od.dodval1.stval1').value.set('yes')
assert api.value.dict() == {'od.val1': ['val1', 'val2'], 'od.dodval1.stval1': 'yes', 'od.dodval2.stval2': None}
assert api.value.dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None}
assert api.value.dict(withoption='stval1') == {'od.dodval1.stval1': 'yes'}
assert api.option('od').value.dict(withoption='stval1') == {'dodval1.stval1': 'yes'}
assert api.option('od.dodval1').value.dict(withoption='stval1') == {'stval1': 'yes'}
async with await Config(od2) as cfg:
await cfg.option('od.dodval1.stval1').value.set('yes')
assert await cfg.value.dict() == {'od.val1': ['val1', 'val2'], 'od.dodval1.stval1': 'yes', 'od.dodval2.stval2': None}
assert await cfg.value.dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None}
assert not await list_sessions()
def test_find_dyndescription_context():
@pytest.mark.asyncio
async def test_find_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
api.option('od.dodval1.stval1').value.set('yes')
assert api.option.find('stval1', first=True).value.get() == "yes"
assert isinstance(api.option.find('stval1', first=True).option.get(), SynDynOption)
#assert api.option.find(bytype=StrOption, type='path') == ['od.dodval1.stval1', 'od.dodval2.stval2', 'od.val1']
#opts = api.option.find(byvalue='yes')
#assert len(opts) == 1
#assert isinstance(opts[0], SynDynOption)
#assert opts[0].impl_getname() == 'stval1'
raises(AttributeError, "list(api.option.find('strnotexists'))")
async with await Config(od2) as cfg:
await cfg.option('od.dodval1.stval1').value.set('yes')
ret = await cfg.option.find('stval1', first=True)
assert await ret.value.get() == "yes"
ret = await cfg.option.find('stval1', first=True)
assert isinstance(await ret.option.get(), SynDynOption)
#assert await cfg.option.find(bytype=StrOption, type='path') == ['od.dodval1.stval1', 'od.dodval2.stval2', 'od.val1']
#opts = await cfg.option.find(byvalue='yes')
#assert len(opts) == 1
#assert isinstance(opts[0], SynDynOption)
#assert opts[0].impl_getname() == 'stval1'
with pytest.raises(AttributeError):
list(await cfg.option.find('strnotexists'))
assert not await list_sessions()
def test_information_dyndescription_context():
@pytest.mark.asyncio
async def test_information_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od])
dod.impl_set_information('testod', 'val1')
st.impl_set_information('testst', 'val2')
api = Config(od2)
api.information.set('testcfgod', 'val3')
assert api.option('od.dodval1').information.get('testod') == 'val1'
assert api.option('od.dodval2').information.get('testod') == 'val1'
assert api.option('od.dodval1.stval1').information.get('testst') == 'val2'
assert api.option('od.dodval2.stval2').information.get('testst') == 'val2'
assert api.information.get('testcfgod') == 'val3'
async with await Config(od2) as cfg:
await cfg.information.set('testcfgod', 'val3')
assert await cfg.option('od.dodval1').information.get('testod') == 'val1'
assert await cfg.option('od.dodval2').information.get('testod') == 'val1'
assert await cfg.option('od.dodval1.stval1').information.get('testst') == 'val2'
assert await cfg.option('od.dodval2.stval2').information.get('testst') == 'val2'
assert await cfg.information.get('testcfgod') == 'val3'
assert not await list_sessions()
def test_consistency_dyndescription():
st1 = StrOption('st', '')
st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list)
od1 = OptionDescription('od', '', [dod])
st1.impl_add_consistency('not_equal', st2)
od2 = OptionDescription('od', '', [od1])
api = Config(od2)
api.option('od.dodval1.stval1').value.set('yes')
raises(ValueError, "api.option('od.dodval1.st2val1').value.set('yes')")
api.option('od.dodval2.stval2').value.set('yes')
raises(ValueError, "api.option('od.dodval2.st2val2').value.set('yes')")
raises(ValueError, "api.option('od.dodval1.st2val1').value.set('yes')")
api.option('od.dodval2.stval2').value.reset()
raises(ValueError, "api.option('od.dodval1.st2val1').value.set('yes')")
api.option('od.dodval2.st2val2').value.set('yes')
raises(ValueError, "api.option('od.dodval2.stval2').value.set('yes')")
#
api.option('od.dodval1.stval1').value.reset()
api.option('od.dodval2.st2val2').value.reset()
api.option('od.dodval1.st2val1').value.set('yes')
raises(ValueError, "api.option('od.dodval1.stval1').value.set('yes')")
def test_consistency_dyndescription_default():
st = StrOption('st', '', 'yes')
st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st, st2], callback=return_list)
od = OptionDescription('od', '', [dod])
st.impl_add_consistency('not_equal', st2)
od2 = OptionDescription('od', '', [od])
api = Config(od2)
raises(ValueError, "api.option('od.dodval1.st2val1').value.set('yes')")
raises(ValueError, "api.option('od.dodval2.st2val2').value.set('yes')")
def test_consistency_dyndescription_default_multi2():
st = StrOption('st', '', ['yes'], multi=True)
st2 = StrOption('st2', '', ['yes'], multi=True)
dod = DynOptionDescription('dod', '', [st, st2], callback=return_list)
dod
raises(ValueError, "st.impl_add_consistency('not_equal', st2)")
def test_consistency_only_one_dyndescription():
st = StrOption('st', '')
st
st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st2], callback=return_list)
raises(ConfigError, "st.impl_add_consistency('not_equal', st2)")
raises(ConfigError, "st2.impl_add_consistency('not_equal', st)")
def test_consistency_became_dyndescription():
st = StrOption('st', '')
st2 = StrOption('st2', '')
st2.impl_add_consistency('not_equal', st)
od = DynOptionDescription('dod', '', [st2], callback=return_list)
od2 = OptionDescription('od', '', [od, st])
od2
raises(ConfigError, "c = Config(od2)")
def test_consistency_became_dyndescription2():
st = StrOption('st', '')
st2 = StrOption('st2', '')
st.impl_add_consistency('not_equal', st2)
od = DynOptionDescription('dod', '', [st2], callback=return_list)
od2 = OptionDescription('od', '', [od, st])
od2
raises(ConfigError, "c = Config(od2)")
def test_consistency_external_dyndescription():
st = StrOption('st', '')
st1 = StrOption('st1', '')
st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list)
od = OptionDescription('od', '', [dod, st])
od
raises(ConfigError, "st.impl_add_consistency('not_equal', st2)")
def test_consistency_notsame_dyndescription():
st1 = StrOption('st1', '')
st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list)
tst1 = StrOption('tst1', '')
tst2 = StrOption('tst2', '')
tdod = DynOptionDescription('tdod', '', [tst1, tst2], callback=return_list)
od = OptionDescription('od', '', [dod, tdod])
od
raises(ConfigError, "st1.impl_add_consistency('not_equal', tst1)")
def test_all_dyndescription():
@pytest.mark.asyncio
async def test_all_dyndescription():
st = StrOption('st', '')
ip = IPOption('ip', '')
network = NetworkOption('network', '')
netmask = NetmaskOption('netmask', '')
ch = ChoiceOption('ch', '', ('val1', 'val2', 'val3'))
ch1 = ChoiceOption('ch1', '', return_list)
ch1 = ChoiceOption('ch1', '', Calculation(return_list))
boo = BoolOption('boo', '')
intr = IntOption('intr', '')
floa = FloatOption('floa', '')
uni = UnicodeOption('uni', '')
uni = StrOption('uni', '')
port = PortOption('port', '')
broad = BroadcastOption('broad', '')
domain = DomainnameOption('domain', '')
@ -829,619 +1001,836 @@ def test_all_dyndescription():
dod = DynOptionDescription('dod', '', [st, ip, network, netmask, ch, ch1,
boo, intr, floa, uni, port, broad,
domain, email, url, username,
filename], callback=return_list)
filename], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod])
api = Config(od)
assert api.option('dodval1.stval1').value.get() is None
assert api.option('dodval1.ipval1').value.get() is None
assert api.option('dodval1.networkval1').value.get() is None
assert api.option('dodval1.netmaskval1').value.get() is None
assert api.option('dodval1.chval1').value.get() is None
assert api.option('dodval1.ch1val1').value.get() is None
assert api.option('dodval1.booval1').value.get() is None
assert api.option('dodval1.intrval1').value.get() is None
assert api.option('dodval1.floaval1').value.get() is None
assert api.option('dodval1.unival1').value.get() is None
assert api.option('dodval1.portval1').value.get() is None
assert api.option('dodval1.broadval1').value.get() is None
assert api.option('dodval1.domainval1').value.get() is None
assert api.option('dodval1.emailval1').value.get() is None
assert api.option('dodval1.urlval1').value.get() is None
assert api.option('dodval1.usernameval1').value.get() is None
assert api.option('dodval1.filenameval1').value.get() is None
#
api.option('dodval1.stval1').value.set("no")
api.option('dodval1.ipval1').value.set("1.1.1.1")
api.option('dodval1.networkval1').value.set("1.1.1.0")
api.option('dodval1.netmaskval1').value.set("255.255.255.0")
api.option('dodval1.chval1').value.set("val1")
api.option('dodval1.ch1val1').value.set("val2")
api.option('dodval1.booval1').value.set(True)
api.option('dodval1.intrval1').value.set(1)
api.option('dodval1.floaval1').value.set(0.1)
api.option('dodval1.unival1').value.set(u"no")
api.option('dodval1.portval1').value.set('80')
api.option('dodval1.broadval1').value.set("1.1.1.255")
api.option('dodval1.domainval1').value.set("test.com")
api.option('dodval1.emailval1').value.set("test@test.com")
api.option('dodval1.urlval1').value.set("http://test.com")
api.option('dodval1.usernameval1').value.set("user1")
api.option('dodval1.filenameval1').value.set("/tmp")
assert api.option('dodval1.stval1').value.get() == "no"
assert api.option('dodval1.ipval1').value.get() == "1.1.1.1"
assert api.option('dodval1.networkval1').value.get() == "1.1.1.0"
assert api.option('dodval1.netmaskval1').value.get() == "255.255.255.0"
assert api.option('dodval1.chval1').value.get() == "val1"
assert api.option('dodval1.ch1val1').value.get() == "val2"
assert api.option('dodval1.booval1').value.get() is True
assert api.option('dodval1.intrval1').value.get() == 1
assert api.option('dodval1.floaval1').value.get() == 0.1
assert api.option('dodval1.unival1').value.get() == u"no"
assert api.option('dodval1.portval1').value.get() == '80'
assert api.option('dodval1.broadval1').value.get() == "1.1.1.255"
assert api.option('dodval1.domainval1').value.get() == "test.com"
assert api.option('dodval1.emailval1').value.get() == "test@test.com"
assert api.option('dodval1.urlval1').value.get() == "http://test.com"
assert api.option('dodval1.usernameval1').value.get() == "user1"
assert api.option('dodval1.filenameval1').value.get() == "/tmp"
assert api.option('dodval2.stval2').value.get() is None
assert api.option('dodval2.ipval2').value.get() is None
assert api.option('dodval2.networkval2').value.get() is None
assert api.option('dodval2.netmaskval2').value.get() is None
assert api.option('dodval2.chval2').value.get() is None
assert api.option('dodval2.ch1val2').value.get() is None
assert api.option('dodval2.booval2').value.get() is None
assert api.option('dodval2.intrval2').value.get() is None
assert api.option('dodval2.floaval2').value.get() is None
assert api.option('dodval2.unival2').value.get() is None
assert api.option('dodval2.portval2').value.get() is None
assert api.option('dodval2.broadval2').value.get() is None
assert api.option('dodval2.domainval2').value.get() is None
assert api.option('dodval2.emailval2').value.get() is None
assert api.option('dodval2.urlval2').value.get() is None
assert api.option('dodval2.usernameval2').value.get() is None
assert api.option('dodval2.filenameval2').value.get() is None
async with await Config(od) as cfg:
assert await cfg.option('dodval1.stval1').value.get() is None
assert await cfg.option('dodval1.ipval1').value.get() is None
assert await cfg.option('dodval1.networkval1').value.get() is None
assert await cfg.option('dodval1.netmaskval1').value.get() is None
assert await cfg.option('dodval1.chval1').value.get() is None
assert await cfg.option('dodval1.ch1val1').value.get() is None
assert await cfg.option('dodval1.booval1').value.get() is None
assert await cfg.option('dodval1.intrval1').value.get() is None
assert await cfg.option('dodval1.floaval1').value.get() is None
assert await cfg.option('dodval1.unival1').value.get() is None
assert await cfg.option('dodval1.portval1').value.get() is None
assert await cfg.option('dodval1.broadval1').value.get() is None
assert await cfg.option('dodval1.domainval1').value.get() is None
assert await cfg.option('dodval1.emailval1').value.get() is None
assert await cfg.option('dodval1.urlval1').value.get() is None
assert await cfg.option('dodval1.usernameval1').value.get() is None
assert await cfg.option('dodval1.filenameval1').value.get() is None
#
await cfg.option('dodval1.stval1').value.set("no")
await cfg.option('dodval1.ipval1').value.set("1.1.1.1")
await cfg.option('dodval1.networkval1').value.set("1.1.1.0")
await cfg.option('dodval1.netmaskval1').value.set("255.255.255.0")
await cfg.option('dodval1.chval1').value.set("val1")
await cfg.option('dodval1.ch1val1').value.set("val2")
await cfg.option('dodval1.booval1').value.set(True)
await cfg.option('dodval1.intrval1').value.set(1)
await cfg.option('dodval1.floaval1').value.set(0.1)
await cfg.option('dodval1.unival1').value.set(u"no")
await cfg.option('dodval1.portval1').value.set('80')
await cfg.option('dodval1.broadval1').value.set("1.1.1.255")
await cfg.option('dodval1.domainval1').value.set("test.com")
await cfg.option('dodval1.emailval1').value.set("test@test.com")
await cfg.option('dodval1.urlval1').value.set("http://test.com")
await cfg.option('dodval1.usernameval1').value.set("user1")
await cfg.option('dodval1.filenameval1').value.set("/tmp")
assert await cfg.option('dodval1.stval1').value.get() == "no"
assert await cfg.option('dodval1.ipval1').value.get() == "1.1.1.1"
assert await cfg.option('dodval1.networkval1').value.get() == "1.1.1.0"
assert await cfg.option('dodval1.netmaskval1').value.get() == "255.255.255.0"
assert await cfg.option('dodval1.chval1').value.get() == "val1"
assert await cfg.option('dodval1.ch1val1').value.get() == "val2"
assert await cfg.option('dodval1.booval1').value.get() is True
assert await cfg.option('dodval1.intrval1').value.get() == 1
assert await cfg.option('dodval1.floaval1').value.get() == 0.1
assert await cfg.option('dodval1.unival1').value.get() == u"no"
assert await cfg.option('dodval1.portval1').value.get() == '80'
assert await cfg.option('dodval1.broadval1').value.get() == "1.1.1.255"
assert await cfg.option('dodval1.domainval1').value.get() == "test.com"
assert await cfg.option('dodval1.emailval1').value.get() == "test@test.com"
assert await cfg.option('dodval1.urlval1').value.get() == "http://test.com"
assert await cfg.option('dodval1.usernameval1').value.get() == "user1"
assert await cfg.option('dodval1.filenameval1').value.get() == "/tmp"
assert await cfg.option('dodval2.stval2').value.get() is None
assert await cfg.option('dodval2.ipval2').value.get() is None
assert await cfg.option('dodval2.networkval2').value.get() is None
assert await cfg.option('dodval2.netmaskval2').value.get() is None
assert await cfg.option('dodval2.chval2').value.get() is None
assert await cfg.option('dodval2.ch1val2').value.get() is None
assert await cfg.option('dodval2.booval2').value.get() is None
assert await cfg.option('dodval2.intrval2').value.get() is None
assert await cfg.option('dodval2.floaval2').value.get() is None
assert await cfg.option('dodval2.unival2').value.get() is None
assert await cfg.option('dodval2.portval2').value.get() is None
assert await cfg.option('dodval2.broadval2').value.get() is None
assert await cfg.option('dodval2.domainval2').value.get() is None
assert await cfg.option('dodval2.emailval2').value.get() is None
assert await cfg.option('dodval2.urlval2').value.get() is None
assert await cfg.option('dodval2.usernameval2').value.get() is None
assert await cfg.option('dodval2.filenameval2').value.get() is None
assert not await list_sessions()
def test_consistency_ip_netmask_dyndescription():
ipa = IPOption('a', '')
netb = NetmaskOption('b', '')
dod = DynOptionDescription('dod', '', [ipa, netb], callback=return_list)
netb.impl_add_consistency('ip_netmask', ipa)
od1 = OptionDescription('od', '', [dod])
cfg = Config(od1)
cfg.option('dodval1.aval1').value.set('192.168.1.1')
cfg.option('dodval1.bval1').value.set('255.255.255.0')
cfg.option('dodval2.aval2').value.set('192.168.1.2')
cfg.option('dodval2.bval2').value.set('255.255.255.128')
cfg.option('dodval2.bval2').value.set('255.255.255.0')
raises(ValueError, "cfg.option('dodval2.bval2').value.set('255.255.255.255')")
def test_consistency_ip_in_network_dyndescription():
neta = NetworkOption('a', '')
netb = NetmaskOption('b', '')
ipc = IPOption('c', '')
dod = DynOptionDescription('dod', '', [neta, netb, ipc], callback=return_list)
ipc.impl_add_consistency('in_network', neta, netb)
od1 = OptionDescription('od', '', [dod])
cfg = Config(od1)
cfg.option('dodval1.aval1').value.set('192.168.1.0')
cfg.option('dodval1.bval1').value.set('255.255.255.0')
cfg.option('dodval1.cval1').value.set('192.168.1.1')
def test_leadership_dyndescription():
@pytest.mark.asyncio
async def test_leadership_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
#
assert api.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st2val1', 0).value.set('no')
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.pop(0)
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
api.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
api.option('od.stval1.st1val1.st2val1', 0).value.reset()
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
api.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
api.option('od.stval1.st1val1.st1val1').value.reset()
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
#
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('no')
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.pop(0)
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
await cfg.option('od.stval1.st1val1.st2val1', 0).value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
await cfg.option('od.stval1.st1val1.st1val1').value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert not await list_sessions()
def test_leadership_default_multi_dyndescription():
@pytest.mark.asyncio
async def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
#
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
#
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert not await list_sessions()
def test_leadership_dyndescription_param():
@pytest.mark.asyncio
async def test_leadership_dyndescription_param():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
odval = OptionDescription('odval1', '', [val1])
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val1)))
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
owner = cfg.owner.get()
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.odval1.val1': ['val1', 'val2']}
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.odval1.val1': ['val1', 'val2']}
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st2val1', 0).value.set('no')
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st1val1').value.pop(0)
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st2val1', 0).value.reset()
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
cfg.option('od.stval1.st1val1.st1val1').value.reset()
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.odval1.val1': ['val1', 'val2']}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.odval1.val1': ['val1', 'val2']}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owners.default
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('no')
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
await cfg.option('od.stval1.st1val1.st1val1').value.pop(0)
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
await cfg.option('od.stval1.st1val1.st2val1', 0).value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owners.default
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
await cfg.option('od.stval1.st1val1.st1val1').value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
assert not await list_sessions()
def test_leadership_default_multi_dyndescription():
@pytest.mark.asyncio
async def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
#
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
#
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert not await list_sessions()
def _test_leadership(cfg):
owner = cfg.owner.get()
cfg.option('od.val1.val1').value.set(['val1', 'val2'])
cfg.option('od.val1.val2', 0).value.set('val1')
cfg.option('od.val1.val2', 1).value.set('val2')
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']}
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
async def _test_leadership(cfg):
owner = await cfg.owner.get()
await cfg.option('od.val1.val1').value.set(['val1', 'val2'])
await cfg.option('od.val1.val2', 0).value.set('val1')
await cfg.option('od.val1.val2', 1).value.set('val2')
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']}
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owners.default
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st2val1', 0).value.set('no')
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('no')
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st1val1').value.pop(0)
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
await cfg.option('od.stval1.st1val1.st1val1').value.pop(0)
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st2val1', 0).value.reset()
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
await cfg.option('od.stval1.st1val1.st2val1', 0).value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owners.default
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
#
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
cfg.option('od.stval1.st1val1.st1val1').value.reset()
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
await cfg.option('od.stval1.st1val1.st1val1').value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
assert await cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
def test_leadership_dyndescription_param_leader():
@pytest.mark.asyncio
async def test_leadership_dyndescription_param_leader():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True)
odval = Leadership('val1', '', [val1, val2])
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val1)))
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
_test_leadership(cfg)
async with await Config(od2) as cfg:
await _test_leadership(cfg)
assert not await list_sessions()
def test_leadership_default_multi_dyndescription():
@pytest.mark.asyncio
async def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
#
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
#
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert not await list_sessions()
def test_leadership_dyndescription_param_follower():
@pytest.mark.asyncio
async def test_leadership_dyndescription_param_follower():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True)
odval = Leadership('val1', '', [val1, val2])
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val2)))
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val2))))
od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
_test_leadership(cfg)
async with await Config(od2) as cfg:
await _test_leadership(cfg)
assert not await list_sessions()
def test_leadership_default_multi_dyndescription():
@pytest.mark.asyncio
async def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
owner = api.owner.get()
#
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
#
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert not await list_sessions()
def test_leadership_submulti_dyndescription():
@pytest.mark.asyncio
async def test_leadership_submulti_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=submulti)
stm = Leadership('st1', '', [st1, st2])
std = DynOptionDescription('st', '', [stm], callback=return_list)
std = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [std])
od2 = OptionDescription('od', '', [od1])
api = Config(od2)
owner = api.owner.get()
#
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st2val1', 0).value.set(['no'])
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == ['no']
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
#
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set(['no'])
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == ['no']
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert not await list_sessions()
def test_leadership_callback_dyndescription():
@pytest.mark.asyncio
async def test_leadership_callback_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(kwargs={'value': ParamOption(st1)}))
st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True)
stm = Leadership('st1', '', [st1, st2])
st1 = DynOptionDescription('st', '', [stm], callback=return_list)
st1 = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [st1])
od2 = OptionDescription('od', '', [od1])
api = Config(od2)
owner = api.owner.get()
assert api.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
assert api.option('od.stval1.st1val1.st1val1').value.get() ==[]
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.value.dict() == {'od.stval1.st1val1.st2val1': ['yes'], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'yes'
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st2val1', 0).value.set('no')
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.pop(0)
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
api.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
api.option('od.stval1.st1val1.st2val1', 0).value.reset()
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
api.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
api.option('od.stval1.st1val1.st1val1').value.reset()
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'yes'
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() ==[]
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': ['yes'], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'yes'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('no')
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.pop(0)
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
await cfg.option('od.stval1.st1val1.st2val1', 0).value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
await cfg.option('od.stval1.st1val1.st1val1').value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'yes'
assert not await list_sessions()
def test_leadership_callback_value_dyndescription():
@pytest.mark.asyncio
async def test_leadership_callback_value_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(kwargs={'value': ParamValue('val')}))
st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True)
stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list)
st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
api = Config(od2)
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
api.option('od.stval1.st1val1.st2val1', 0).value.set('val')
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'val'
async with await Config(od2) as cfg:
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('val')
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'val'
assert not await list_sessions()
def test_leadership_callback_nomulti_dyndescription():
@pytest.mark.asyncio
async def test_leadership_callback_nomulti_dyndescription():
v11 = StrOption('v1', '', "val")
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(ParamOption(v11)))
st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True)
stm = Leadership('st1', '', [st1, st2])
stt = DynOptionDescription('st', '', [stm], callback=return_list)
stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1, v11])
api = Config(od2)
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert api.option('od.stval1.st1val1.st2val1', 0).value.get() == 'val'
async with await Config(od2) as cfg:
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'val'
assert not await list_sessions()
def test_leadership_callback_samegroup_dyndescription():
@pytest.mark.asyncio
async def test_leadership_callback_samegroup_dyndescription():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params=Params(ParamOption(st2)))
st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True)
stm = Leadership('st1', '', [st1, st2, st3])
stt = DynOptionDescription('st', '', [stm], callback=return_list)
stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1])
api = Config(od2)
owner = api.owner.get()
assert api.value.dict() == {'od.stval1.st1val1.st1val1': [],
'od.stval1.st1val1.st2val1': [],
'od.stval1.st1val1.st3val1': [],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert api.option('od.stval1.st1val1.st1val1').value.get() == []
assert api.option('od.stval2.st1val2.st1val2').value.get() == []
assert api.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert api.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': [None],
'od.stval1.st1val1.st3val1': [None],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert api.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
api.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert api.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': ['yes'],
'od.stval1.st1val1.st3val1': ['yes'],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert api.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert api.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert api.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
assert api.option('od.stval2.st1val2.st1val2').owner.isdefault()
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.value.dict() == {'od.stval1.st1val1.st1val1': [],
'od.stval1.st1val1.st2val1': [],
'od.stval1.st1val1.st3val1': [],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': [None],
'od.stval1.st1val1.st3val1': [None],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert await cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': ['yes'],
'od.stval1.st1val1.st3val1': ['yes'],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert not await list_sessions()
def test_invalid_conflict_dyndescription():
@pytest.mark.asyncio
async def test_invalid_conflict_dyndescription():
st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list)
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
dodinvalid = StrOption('dodinvalid', '')
dod, dodinvalid
raises(ConflictError, "OptionDescription('od', '', [dod, dodinvalid])")
with pytest.raises(ConflictError):
OptionDescription('od', '', [dod, dodinvalid])
assert not await list_sessions()
def test_invalid_subod_dyndescription():
@pytest.mark.asyncio
async def test_invalid_subod_dyndescription():
st2 = StrOption('st2', '')
od1 = OptionDescription('od1', '', [st2])
od1
raises(ConfigError, "DynOptionDescription('dod', '', [od1], callback=return_list)")
with pytest.raises(ConfigError):
DynOptionDescription('dod', '', [od1], suffixes=Calculation(return_list))
assert not await list_sessions()
def test_invalid_subdynod_dyndescription():
@pytest.mark.asyncio
async def test_invalid_subdynod_dyndescription():
st2 = StrOption('st2', '')
od1 = DynOptionDescription('od1', '', [st2], callback=return_list)
od1 = DynOptionDescription('od1', '', [st2], suffixes=Calculation(return_list))
od1
raises(ConfigError, "DynOptionDescription('dod', '', [od1], callback=return_list)")
with pytest.raises(ConfigError):
DynOptionDescription('dod', '', [od1], suffixes=Calculation(return_list))
assert not await list_sessions()
def test_invalid_symlink_dyndescription():
@pytest.mark.asyncio
async def test_invalid_symlink_dyndescription():
st = StrOption('st', '')
st2 = SymLinkOption('st2', st)
st2
raises(ConfigError, "DynOptionDescription('dod', '', [st, st2], callback=return_list)")
with pytest.raises(ConfigError):
DynOptionDescription('dod', '', [st, st2], suffixes=Calculation(return_list))
assert not await list_sessions()
def test_nocallback_dyndescription():
@pytest.mark.asyncio
async def test_nocallback_dyndescription():
st = StrOption('st', '')
st2 = StrOption('st2', '')
st, st2
raises(ConfigError, "DynOptionDescription('dod', '', [st, st2])")
with pytest.raises(TypeError):
DynOptionDescription('dod', '', [st, st2])
assert not await list_sessions()
def test_invalid_samevalue_dyndescription():
@pytest.mark.asyncio
async def test_invalid_samevalue_dyndescription():
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_same_list)
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_same_list))
od1 = OptionDescription('od', '', [dod])
cfg = Config(od1)
raises(ValueError, "cfg.value.dict()")
async with await Config(od1) as cfg:
with pytest.raises(ValueError):
await cfg.value.dict()
assert not await list_sessions()
def test_invalid_name_dyndescription():
@pytest.mark.asyncio
async def test_invalid_name_dyndescription():
st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_wrong_list)
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_wrong_list))
od1 = OptionDescription('od', '', [dod])
cfg = Config(od1)
raises(ValueError, "cfg.value.dict()")
async with await Config(od1) as cfg:
with pytest.raises(ValueError):
await cfg.value.dict()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_leadership_dyndescription_convert():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2])
st = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot))
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
#
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('no')
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
assert await cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'no'
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.pop(0)
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
await cfg.option('od.stval1.st1val1.st2val1', 0).value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
await cfg.option('od.stval1.st1val1.st1val1').value.reset()
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_leadership_callback_samegroup_dyndescription_convert():
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True)
st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True)
stm = Leadership('st1', '', [st1, st2, st3])
stt = ConvertDynOptionDescription('st', '', [stm], suffixes=Calculation(return_list_dot))
od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1])
async with await Config(od2) as cfg:
owner = await cfg.owner.get()
assert await cfg.value.dict() == {'od.stval1.st1val1.st1val1': [],
'od.stval1.st1val1.st2val1': [],
'od.stval1.st1val1.st3val1': [],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert await cfg.option('od.stval1.st1val1.st1val1').value.get() == []
assert await cfg.option('od.stval2.st1val2.st1val2').value.get() == []
assert await cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
assert await cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': [None],
'od.stval1.st1val1.st3val1': [None],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
assert await cfg.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
#
await cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
assert await cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
'od.stval1.st1val1.st2val1': ['yes'],
'od.stval1.st1val1.st3val1': ['yes'],
'od.stval2.st1val2.st1val2': [],
'od.stval2.st1val2.st2val2': [],
'od.stval2.st1val2.st3val2': []}
assert await cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
assert await cfg.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
assert await cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_dyn_with_leader_hidden_in_config():
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, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',))
dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list))
od = OptionDescription('root', '', [dyn])
async with await Config(od) as cfg:
await cfg.property.read_write()
await cfg.permissive.add('hidden')
assert await cfg.forcepermissive.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.get() == []
await cfg.forcepermissive.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.set(['192.168.1.1'])
assert await cfg.forcepermissive.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 0).value.get() is None
with pytest.raises(PropertiesOptionError):
await cfg.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 0).value.get()
await cfg.value.dict(leader_to_list=True) == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}],
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': [{'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': '192.168.1.1'}]}
assert not await list_sessions()
@pytest.mark.asyncio
async def test_dyn_leadership_requires():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('notunique',))
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(ip_admin_eth0, notraisepropertyerror=True),
'expected': ParamValue('192.168.1.1'),
'no_condition_is_invalid': ParamValue(True),
'index': ParamIndex()}))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=(disabled_property,))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
dyn = DynOptionDescription('leader', '', [interface1], suffixes=Calculation(return_list))
od = OptionDescription('toto', '', [dyn])
async with await Config(od) as cfg:
await cfg.property.read_write()
assert await cfg.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.get() == []
await cfg.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.set(['192.168.1.2'])
assert await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 0).value.get() is None
assert await cfg.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.get() == ['192.168.1.2']
#
await cfg.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.set(['192.168.1.2', '192.168.1.1'])
assert await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 0).value.get() is None
with pytest.raises(PropertiesOptionError):
await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 1).value.get()
#
await cfg.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.set(['192.168.1.2', '192.168.1.2'])
assert await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 0).value.get() is None
assert await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 1).value.get() is None
await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 1).value.set('255.255.255.255')
assert await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 1).value.get() == '255.255.255.255'
assert await cfg.value.dict() == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': ['192.168.1.2', '192.168.1.2'],
'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': [None, '255.255.255.255'],
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': [],
'leaderval2.ip_admin_eth0val2.netmask_admin_eth0val2': []}
ret = await cfg.value.dict(leader_to_list=True)
assert ret == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.2', 'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': None},
{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.2', 'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': '255.255.255.255'}],
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []}
#
await cfg.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.set(['192.168.1.2', '192.168.1.1'])
assert await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 0).value.get() is None
with pytest.raises(PropertiesOptionError):
await cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 1).value.get()
ret = await cfg.value.dict()
assert set(ret.keys()) == set(['leaderval1.ip_admin_eth0val1.ip_admin_eth0val1', 'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2', 'leaderval2.ip_admin_eth0val2.netmask_admin_eth0val2'])
assert ret['leaderval1.ip_admin_eth0val1.ip_admin_eth0val1'] == ['192.168.1.2', '192.168.1.1']
assert len(ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1']) == 2
assert ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1'][0] is None
assert isinstance(ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1'][1], PropertiesOptionError)
del ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1'][1]
del ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1'][0]
del ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1']
assert await cfg.value.dict(leader_to_list=True) == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.2',
'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': None},
{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}],
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []}
#
assert await cfg.value.dict(leader_to_list=True) == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.2',
'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': None},
{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}],
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []}
assert not await list_sessions()

View File

@ -3,18 +3,15 @@
from .autopath import do_autopath
do_autopath()
from py.test import raises
import pytest
from tiramisu.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, Leadership, Config, \
Params, ParamContext, ParamOption, ParamValue
Calculation, Params, ParamOption, ParamValue, calc_value, delete_session
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
from .config import event_loop
def compare(calculated, expected):
@ -41,14 +38,23 @@ def make_description_freeze():
floatoption = FloatOption('float', 'Test float option', default=2.3)
stroption = StrOption('str', 'Test string option', default="abc")
boolop = BoolOption('boolop', 'Test boolean option op', default=[True], multi=True)
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',),
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(booloption, raisepropertyerror=True),
'expected': ParamValue(True),
'default': ParamValue(None)}))
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value', hidden_property))
wantref2_option = BoolOption('wantref2', 'Test requires', default=False, properties=('force_store_value', 'hidden'))
wantref3_option = BoolOption('wantref3', 'Test requires', default=[False], multi=True, properties=('force_store_value',))
st2 = SymLinkOption('st2', wantref3_option)
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(booloption, raisepropertyerror=True),
'expected': ParamValue(True),
'default': ParamValue(None)}))
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
requires=({'option': booloption, 'expected': True, 'action': 'hidden'},))
properties=(hidden_property,))
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
@ -70,162 +76,151 @@ def return_val3(context, value):
return value
def test_freeze_whole_config():
@pytest.mark.asyncio
async def test_freeze_whole_config():
descr = make_description_freeze()
api = Config(descr)
api.property.read_write()
api.property.add('everything_frozen')
assert api.option('gc.dummy').value.get() is False
prop = []
try:
api.option('gc.dummy').value.set(True)
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
assert api.option('gc.dummy').value.get() is False
#
api.property.pop('everything_frozen')
api.option('gc.dummy').value.set(True)
assert api.option('gc.dummy').value.get() is True
#
api.property.add('everything_frozen')
owners.addowner("everythingfrozen2")
prop = []
try:
api.option('gc.dummy').owner.set('everythingfrozen2')
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.property.add('everything_frozen')
assert await cfg.option('gc.dummy').value.get() is False
prop = []
try:
await cfg.option('gc.dummy').value.set(True)
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
assert await cfg.option('gc.dummy').value.get() is False
#
await cfg.property.pop('everything_frozen')
await cfg.option('gc.dummy').value.set(True)
assert await cfg.option('gc.dummy').value.get() is True
#
await cfg.property.add('everything_frozen')
owners.addowner("everythingfrozen2")
prop = []
try:
await cfg.option('gc.dummy').owner.set('everythingfrozen2')
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
assert not await list_sessions()
def test_freeze_one_option():
@pytest.mark.asyncio
async def test_freeze_one_option():
"freeze an option "
descr = make_description_freeze()
api = Config(descr)
api.property.read_write()
#freeze only one option
api.option('gc.dummy').property.add('frozen')
assert api.option('gc.dummy').value.get() is False
prop = []
try:
api.option('gc.dummy').value.set(True)
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
async with await Config(descr) as cfg:
await cfg.property.read_write()
#freeze only one option
await cfg.option('gc.dummy').property.add('frozen')
assert await cfg.option('gc.dummy').value.get() is False
prop = []
try:
await cfg.option('gc.dummy').value.set(True)
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
assert not await list_sessions()
def test_frozen_value():
@pytest.mark.asyncio
async def test_frozen_value():
"setattr a frozen value at the config level"
s = StrOption("string", "", default="string")
descr = OptionDescription("options", "", [s])
api = Config(descr)
api.property.read_write()
api.property.add('frozen')
api.option('string').property.add('frozen')
prop = []
try:
api.option('string').value.set('egg')
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.property.add('frozen')
await cfg.option('string').property.add('frozen')
prop = []
try:
await cfg.option('string').value.set('egg')
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
assert not await list_sessions()
def test_freeze():
@pytest.mark.asyncio
async def test_freeze():
"freeze a whole configuration object"
descr = make_description_freeze()
api = Config(descr)
api.property.read_write()
api.property.add('frozen')
api.option('gc.name').property.add('frozen')
prop = []
try:
api.option('gc.name').value.set('framework')
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.property.add('frozen')
await cfg.option('gc.name').property.add('frozen')
prop = []
try:
await cfg.option('gc.name').value.set('framework')
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
assert not await list_sessions()
def test_freeze_multi():
@pytest.mark.asyncio
async def test_freeze_multi():
descr = make_description_freeze()
api = Config(descr)
api.property.read_write()
api.property.add('frozen')
api.option('boolop').property.add('frozen')
prop = []
try:
api.option('boolop').value.set([True])
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.property.add('frozen')
await cfg.option('boolop').property.add('frozen')
prop = []
try:
await cfg.option('boolop').value.set([True])
except PropertiesOptionError as err:
prop = err.proptype
assert 'frozen' in prop
assert not await list_sessions()
def test_force_store_value():
@pytest.mark.asyncio
async def test_force_store_value():
descr = make_description_freeze()
conf = Config(descr)
compare(conf.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced')))
conf.option('wantref').value.set(True)
compare(conf.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (True, False, (False,)), ('user', 'forced', 'forced')))
conf.option('wantref').value.reset()
compare(conf.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced')))
async with await Config(descr) as cfg:
compare(await cfg.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced')))
await cfg.option('wantref').value.set(True)
compare(await cfg.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (True, False, (False,)), ('user', 'forced', 'forced')))
await cfg.option('wantref').value.reset()
compare(await cfg.value.exportation(), (('wantref', 'wantref2', 'wantref3'), (None, None, None), (False, False, (False,)), ('forced', 'forced', 'forced')))
assert not await list_sessions()
def test_force_store_value_no_requirement():
booloption = BoolOption('bool', 'Test boolean option', default=True)
try:
BoolOption('wantref', 'Test requires', default=False,
requires=({'option': booloption, 'expected': True, 'action': 'force_store_value'},))
except ValueError:
pass
def test_force_store_value_leadership_follower():
b = IntOption('int', 'Test int option', multi=True)
c = StrOption('str', 'Test string option', multi=True, properties=('force_store_value',))
descr = Leadership("int", "", [b, c])
raises(ConfigError, "conf = Config(descr)")
#def test_force_store_value_leadership():
# b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
# c = StrOption('str', 'Test string option', multi=True)
# descr = Leadership("int", "", [b, c])
# api = Config(descr)
# assert api.value.get() == {'int': ('forced', ())}
def test_force_store_value_leadership_sub():
@pytest.mark.asyncio
async def test_force_store_value_leadership_sub():
b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
c = StrOption('str', 'Test string option', multi=True)
descr = Leadership("int", "", [b, c])
odr = OptionDescription('odr', '', [descr])
api = Config(odr)
compare(api.value.exportation(), (('int.int',), (None,), (tuple(),), ('forced',)))
async with await Config(odr) as cfg:
compare(await cfg.value.exportation(), (('int.int',), (None,), (tuple(),), ('forced',)))
assert not await list_sessions()
def test_force_store_value_callback():
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val)
@pytest.mark.asyncio
async def test_force_store_value_callback():
b = IntOption('int', 'Test int option', Calculation(return_val), properties=('force_store_value',))
descr = OptionDescription("int", "", [b])
api = Config(descr)
compare(api.value.exportation(), (('int',), (None,), (1,), ('forced',)))
async with await Config(descr) as cfg:
compare(await cfg.value.exportation(), (('int',), (None,), (1,), ('forced',)))
assert not await list_sessions()
def test_force_store_value_callback_params():
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params=Params(kwargs={'value': ParamValue(2)}))
@pytest.mark.asyncio
async def test_force_store_value_callback_params():
b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamValue(2)})), properties=('force_store_value',))
descr = OptionDescription("int", "", [b])
api = Config(descr)
compare(api.value.exportation(), (('int',), (None,), (2,), ('forced',)))
async with await Config(descr) as cfg:
compare(await cfg.value.exportation(), (('int',), (None,), (2,), ('forced',)))
assert not await list_sessions()
def test_force_store_value_callback_params_2():
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params=Params(ParamContext(), {'value': ParamValue(2)}))
descr = OptionDescription("int", "", [b])
api = Config(descr)
compare(api.value.exportation(), (('int',), (None,), (2,), ('forced',)))
def test_force_store_value_callback_params_with_opt():
@pytest.mark.asyncio
async def test_force_store_value_callback_params_with_opt():
a = IntOption('val1', "", 2)
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params=Params(kwargs={'value': ParamOption(a)}))
b = IntOption('int', 'Test int option', Calculation(return_val2, Params(kwargs={'value': ParamOption(a)})), properties=('force_store_value',))
descr = OptionDescription("int", "", [a, b])
api = Config(descr)
compare(api.value.exportation(), (('int',), (None,), (2,), ('forced',)))
async with await Config(descr) as cfg:
compare(await cfg.value.exportation(), (('int',), (None,), (2,), ('forced',)))
assert not await list_sessions()

View File

@ -1,18 +1,17 @@
# coding: utf-8
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config, value_list, global_owner
from py.test import raises
from .config import config_type, get_config, value_list, global_owner, event_loop
import pytest
from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, IPOption, NetworkOption, NetmaskOption, \
StrOption, OptionDescription, Leadership, Config
StrOption, OptionDescription, Leadership, Config, delete_session
from tiramisu.error import LeadershipError, PropertiesOptionError, APIError, ConfigError
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
groups.family = groups.GroupType('family')
def compare(calculated, expected):
@ -62,837 +61,1003 @@ def make_description():
return descr
def test_base_config(config_type):
@pytest.mark.asyncio
async def test_base_config(config_type):
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('creole.general.activer_proxy_client').value.get() is False
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,
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
'eoleng', 'general.activer_proxy_client': False}
assert cfg.option('creole').value.dict() == result
result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
False, 'nombre_interfaces': 1}
assert cfg.option('creole').value.dict(flatten=True) == result
if config_type == 'tiramisu-api':
cfg.send()
async with await Config(descr) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('creole.general.activer_proxy_client').value.get() is False
assert await cfg.option('creole.general.nom_machine').value.get() == "eoleng"
if config_type != 'tiramisu-api':
ret = await cfg.option.find('nom_machine', first=True)
assert await ret.value.get() == "eoleng"
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
'eoleng', 'general.activer_proxy_client': False}
assert await cfg.option('creole').value.dict() == result
result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
False, 'nombre_interfaces': 1}
assert await cfg.option('creole').value.dict(flatten=True) == result
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_make_dict_filter():
@pytest.mark.asyncio
async def test_get_group_type():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
subresult = {'numero_etab': None, 'nombre_interfaces': 1,
'serveur_ntp': [], 'mode_conteneur_actif': False,
'time_zone': 'Paris', 'nom_machine': 'eoleng',
'activer_proxy_client': False}
result = {}
for key, value in subresult.items():
result['general.' + key] = value
assert cfg.option('creole').value.dict(withoption='numero_etab') == result
raises(AttributeError, "cfg.option('creole').value.dict(withoption='numero_etab', withvalue='toto')")
assert cfg.option('creole').value.dict(withoption='numero_etab', withvalue=None) == result
assert cfg.option('creole.general').value.dict(withoption='numero_etab') == subresult
async with await Config(descr) as cfg:
await cfg.property.read_write()
grp = cfg.option('creole.general')
assert await grp.group_type() == groups.family
assert await grp.group_type() == 'family'
assert isinstance(await grp.group_type(), groups.GroupType)
assert not await list_sessions()
def test_get_group_type():
@pytest.mark.asyncio
async def test_iter_on_groups():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
grp = cfg.option('creole.general')
assert grp.group_type() == groups.family
assert grp.group_type() == 'family'
assert isinstance(grp.group_type(), groups.GroupType)
async with await Config(descr) as cfg:
await cfg.property.read_write()
result = await cfg.option('creole').list('optiondescription',
group_type=groups.family)
group_names = [await res.option.name() for res in result]
assert group_names == ['general', 'interface1']
for i in await cfg.option('creole').list('optiondescription',
group_type=groups.family):
#test StopIteration
break
result = await cfg.option('creole').list('option',
group_type=groups.family)
assert list(result) == []
result = await cfg.option('creole.general').list('optiondescription',
group_type=groups.family)
assert list(result) == []
assert not await list_sessions()
def test_iter_on_groups():
@pytest.mark.asyncio
async def test_list_recursive():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
result = cfg.option('creole').list('optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
for i in cfg.option('creole').list('optiondescription',
group_type=groups.family):
#test StopIteration
break
result = cfg.option('creole').list('option',
group_type=groups.family)
assert list(result) == []
result = cfg.option('creole.general').list('optiondescription',
group_type=groups.family)
assert list(result) == []
async with await Config(descr) as cfg:
await cfg.property.read_write()
result = await cfg.option('creole').list('all')
group_names = [await res.option.name() for res in result]
assert group_names == ['general', 'interface1']
#
result = await cfg.option.list(recursive=True)
group_names = [await res.option.name() for res in result]
assert group_names == ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif',
'serveur_ntp', 'time_zone', 'ip_admin_eth0',
'netmask_admin_eth0']
result = list(await cfg.option.list(recursive=True, type='optiondescription'))
group_names = [await res.option.name() for res in result]
assert group_names == ['general', 'ip_admin_eth0', 'interface1', 'creole']
assert not await list_sessions()
def test_list_recursive():
@pytest.mark.asyncio
async def test_iter_on_groups_force_permissive():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
result = cfg.option('creole').list('all')
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1']
#
result = cfg.option.list(recursive=True)
group_names = [res.option.name() for res in result]
assert group_names == ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif',
'serveur_ntp', 'time_zone', 'ip_admin_eth0',
'netmask_admin_eth0']
result = list(cfg.option.list(recursive=True, type='optiondescription'))
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'ip_admin_eth0', 'interface1', 'creole']
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.permissive.add('hidden')
result = await cfg.forcepermissive.option('creole.general').list()
group_names = [await res.option.name() for res in result]
ass = ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif',
'mode_conteneur_actif2', 'serveur_ntp', 'time_zone']
assert group_names == ass
# mode_conteneur_actif2 is not visible is not forcepermissive
result = await cfg.option('creole.general').list()
group_names = [await res.option.name() for res in result]
ass.remove('mode_conteneur_actif2')
assert group_names == ass
assert not await list_sessions()
def test_iter_on_groups_force_permissive():
@pytest.mark.asyncio
async def test_iter_group_on_groups_force_permissive():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
result = cfg.forcepermissive.option('creole.general').list()
group_names = [res.option.name() for res in result]
ass = ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif',
'mode_conteneur_actif2', 'serveur_ntp', 'time_zone']
assert group_names == ass
# mode_conteneur_actif2 is not visible is not forcepermissive
result = cfg.option('creole.general').list()
group_names = [res.option.name() for res in result]
ass.remove('mode_conteneur_actif2')
assert group_names == ass
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.permissive.add('hidden')
result = await cfg.forcepermissive.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [await res.option.name() for res in result]
assert group_names == ['general', 'interface1', 'new']
assert not await list_sessions()
def test_iter_group_on_groups_force_permissive():
@pytest.mark.asyncio
async def test_iter_on_groups_props():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
result = cfg.forcepermissive.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general', 'interface1', 'new']
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.option('creole.interface1').property.add('disabled')
result = await cfg.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [await res.option.name() for res in result]
assert group_names == ['general']
assert not await list_sessions()
def test_iter_on_groups_props():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
cfg.option('creole.interface1').property.add('disabled')
result = cfg.option('creole').list(type='optiondescription',
group_type=groups.family)
group_names = [res.option.name() for res in result]
assert group_names == ['general']
@pytest.mark.asyncio
async def test_iter_on_empty_group():
async with await Config(OptionDescription("name", "descr", [])) as cfg:
await cfg.property.read_write()
result = list(await cfg.option.list(type='optiondescription'))
assert result == []
assert not await list_sessions()
def test_iter_on_empty_group():
cfg = Config(OptionDescription("name", "descr", []))
cfg.property.read_write()
result = list(cfg.option.list(type='optiondescription'))
assert result == []
@pytest.mark.asyncio
async def test_iter_not_group():
async with await Config(OptionDescription("name", "descr", [])) as cfg:
await cfg.property.read_write()
try:
list(await cfg.option.list(type='optiondescription', group_type='family'))
except AssertionError:
pass
else:
raise Exception('must raise')
assert not await list_sessions()
def test_iter_not_group():
cfg = Config(OptionDescription("name", "descr", []))
cfg.property.read_write()
try:
list(cfg.option.list(type='optiondescription', group_type='family'))
except AssertionError:
pass
else:
raise Exception('must raise')
def test_groups_with_leader():
@pytest.mark.asyncio
async def test_groups_with_leader():
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert interface1.impl_get_group_type() == groups.leadership
assert not await list_sessions()
def test_groups_is_leader(config_type):
@pytest.mark.asyncio
async def test_groups_is_leader(config_type):
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')
interface1 = Leadership('leadership', '', [ip_admin_eth0, netmask_admin_eth0])
var = StrOption('var', "ip réseau autorisé", multi=True)
od2 = OptionDescription('od2', '', [var])
od1 = OptionDescription('od', '', [interface1, od2])
cfg = Config(od1)
cfg = get_config(cfg, config_type)
assert not cfg.option('od2').option.isleadership()
assert cfg.option('leadership').option.isleadership()
assert not cfg.option('od2.var').option.isleader()
assert not cfg.option('od2.var').option.isfollower()
assert cfg.option('leadership.ip_admin_eth0').option.ismulti()
assert cfg.option('leadership.netmask_admin_eth0').option.ismulti()
assert not cfg.option('leadership.ip_admin_eth0').option.issubmulti()
assert not cfg.option('leadership.netmask_admin_eth0').option.issubmulti()
assert cfg.option('leadership.ip_admin_eth0').option.isleader()
assert not cfg.option('leadership.ip_admin_eth0').option.isfollower()
assert not cfg.option('leadership.netmask_admin_eth0').option.isleader()
assert cfg.option('leadership.netmask_admin_eth0').option.isfollower()
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()
async with await Config(od1) as cfg:
cfg = await get_config(cfg, config_type)
assert not await cfg.option('od2').option.isleadership()
assert await cfg.option('leadership').option.isleadership()
assert not await cfg.option('od2.var').option.isleader()
assert not await cfg.option('od2.var').option.isfollower()
assert await cfg.option('leadership.ip_admin_eth0').option.ismulti()
assert await cfg.option('leadership.netmask_admin_eth0').option.ismulti()
assert not await cfg.option('leadership.ip_admin_eth0').option.issubmulti()
assert not await cfg.option('leadership.netmask_admin_eth0').option.issubmulti()
assert await cfg.option('leadership.ip_admin_eth0').option.isleader()
assert not await cfg.option('leadership.ip_admin_eth0').option.isfollower()
assert not await cfg.option('leadership.netmask_admin_eth0').option.isleader()
assert await cfg.option('leadership.netmask_admin_eth0').option.isfollower()
assert await cfg.option('leadership.netmask_admin_eth0').option.path() == 'leadership.netmask_admin_eth0'
assert await cfg.option('leadership.netmask_admin_eth0').option.defaultmulti() == 'value'
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_groups_with_leader_in_root():
@pytest.mark.asyncio
async def test_groups_with_leader_in_root():
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1
raises(ConfigError, "Config(interface1)")
with pytest.raises(ConfigError):
await Config(interface1, session_id='error')
await delete_session('error')
assert not await list_sessions()
def test_groups_with_leader_in_config():
@pytest.mark.asyncio
async def test_groups_with_leader_in_config():
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
Config(od)
async with await Config(od) as cfg:
pass
assert interface1.impl_get_group_type() == groups.leadership
assert not await list_sessions()
def test_groups_with_leader_make_dict(config_type):
@pytest.mark.asyncio
async def test_groups_with_leader_make_dict(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []}
if config_type != 'tiramisu-api':
# FIXME useful? already in leadership
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 0
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()
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []}
assert await cfg.value.dict(leader_to_list=True) == {'ip_admin_eth0.ip_admin_eth0': []}
if config_type != 'tiramisu-api':
# FIXME useful? already in leadership
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 0
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
if config_type != 'tiramisu-api':
# FIXME
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2
assert await cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]}
assert await cfg.value.dict(leader_to_list=True) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'ip1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'ip2', 'ip_admin_eth0.netmask_admin_eth0': None}]}
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_groups_with_leader_default_value(config_type):
@pytest.mark.asyncio
async def test_groups_with_leader_make_dict2(config_type):
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)
interface1 = Leadership('other', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {'other.ip_admin_eth0': [], 'other.netmask_admin_eth0': []}
assert await cfg.value.dict(leader_to_list=True) == {'other.ip_admin_eth0': []}
if config_type != 'tiramisu-api':
# FIXME useful? already in leadership
assert await cfg.option('other.ip_admin_eth0').value.len() == 0
assert await cfg.option('other.netmask_admin_eth0').value.len() == 0
await cfg.option('other.ip_admin_eth0').value.set(['ip1', 'ip2'])
if config_type != 'tiramisu-api':
# FIXME
assert await cfg.option('other.ip_admin_eth0').value.len() == 2
assert await cfg.option('other.netmask_admin_eth0').value.len() == 2
assert await cfg.value.dict() == {'other.ip_admin_eth0': ['ip1', 'ip2'], 'other.netmask_admin_eth0': [None, None]}
assert await cfg.value.dict(leader_to_list=True) == {'other.ip_admin_eth0': [{'other.ip_admin_eth0': 'ip1', 'other.netmask_admin_eth0': None}, {'other.ip_admin_eth0': 'ip2', 'other.netmask_admin_eth0': None}]}
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_groups_with_leader_default_value(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
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()
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2'])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == []
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_groups_with_leader_default_value_2(config_type):
@pytest.mark.asyncio
async 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)
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])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip3', 'ip4'])
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 cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('netmask2')
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask2'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
if config_type == 'tiramisu-api':
cfg.send()
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip1', 'ip2']
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip3', 'ip4'])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip3', 'ip4']
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.default() == ['ip1', 'ip2']
#
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask1'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('netmask2')
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask2'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_groups_with_leader_hidden_in_config():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
@pytest.mark.asyncio
async def test_groups_with_leader_hidden_in_config():
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, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('hidden',))
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
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()")
async with await Config(od) as cfg:
await cfg.property.read_write()
await cfg.permissive.add('hidden')
assert await cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
await cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
assert await cfg.value.dict() == {}
assert await cfg.value.dict(leader_to_list=True) == {}
assert not await list_sessions()
def test_groups_with_leader_hidden_in_config2():
async def test_groups_with_leader_hidden_in_config2():
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, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#del
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
cfg.property.pop('hidden')
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
cfg.property.add('hidden')
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
cfg.property.pop('hidden')
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
async with await Config(od) as cfg:
await cfg.property.read_write()
await cfg.permissive.add('hidden')
assert await cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
await cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
assert await cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.1']}
assert await cfg.value.dict(leader_to_list=True) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]}
assert not await list_sessions()
def test_groups_with_leader_reset_empty(config_type):
@pytest.mark.asyncio
async def test_groups_with_leader_hidden_in_config2():
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
cfg = Config(od_)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
if config_type != 'tiramisu-api':
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(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
cfg_ori = Config(od_)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
if config_type == 'tiramisu-api':
cfg.send()
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():
#if leader is hidden, follower are hidden too
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
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, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
assert cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
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()")
async with await Config(od) as cfg:
await cfg.property.read_write()
await cfg.permissive.add('hidden')
assert await cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
await cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await cfg.forcepermissive.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#del
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
await cfg.property.pop('hidden')
assert await cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
await cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert await cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
await cfg.property.add('hidden')
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
await cfg.property.pop('hidden')
assert await cfg.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert not await list_sessions()
def test_allowed_groups():
@pytest.mark.asyncio
async def test_groups_with_leader_reset_empty(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
async with await Config(od_) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
if config_type != 'tiramisu-api':
with pytest.raises(LeadershipError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_groups_with_leader_reset_out_of_range(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
async with await Config(od_) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(LeadershipError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.reset()
with pytest.raises(IndexError):
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_allowed_groups():
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)
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1
raises(ValueError, "interface1.impl_set_group_type('toto')")
with pytest.raises(ValueError):
interface1.impl_set_group_type('toto')
assert not await list_sessions()
def test_values_with_leader_disabled_leader(config_type):
@pytest.mark.asyncio
async def test_values_with_leader_disabled_leader(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg_ori = Config(maconfig)
cfg_ori.property.read_write()
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)
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")
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
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()
async with await Config(maconfig) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
with pytest.raises(LeadershipError):
await cfg_ori.option('ip_admin_eth0.ip_admin_eth0').property.add('disabled')
await cfg_ori.option('ip_admin_eth0').property.add('disabled')
cfg = await get_config(cfg_ori, config_type)
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('192.168.230.145')
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_sub_group_in_leader_group():
@pytest.mark.asyncio
async def test_sub_group_in_leader_group():
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)
subgroup = OptionDescription("subgroup", '', [])
raises(ValueError, "Leadership('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])")
with pytest.raises(ValueError):
Leadership('ip_admin_eth0', '', [subgroup, ip_admin_eth0, netmask_admin_eth0])
assert not await list_sessions()
def test_group_always_has_multis():
@pytest.mark.asyncio
async def test_group_always_has_multis():
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")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
with pytest.raises(ValueError):
Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert not await list_sessions()
#____________________________________________________________
def test_values_with_leader_and_followers(config_type):
@pytest.mark.asyncio
async def test_values_with_leader_and_followers1(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
owner = global_owner(cfg, config_type)
cfg = get_config(cfg, config_type)
assert interface1.impl_get_group_type() == groups.leadership
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
if config_type != 'tiramisu-api':
# 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()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
owner = await global_owner(cfg, config_type)
cfg = await get_config(cfg, config_type)
assert interface1.impl_get_group_type() == groups.leadership
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
#
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(APIError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0').value.set([None])
with pytest.raises(APIError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_reset_values_with_leader_and_followers(config_type):
@pytest.mark.asyncio
async def test_reset_values_with_leader_and_followers(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
owner = global_owner(cfg, config_type)
cfg = Config(maconfig)
assert interface1.impl_get_group_type() == groups.leadership
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#reset
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
owner = await global_owner(cfg, config_type)
async with await Config(maconfig) as cfg:
assert interface1.impl_get_group_type() == groups.leadership
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#reset
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert not await list_sessions()
def test_reset_values_with_leader_and_followers_default_value():
@pytest.mark.asyncio
async def test_reset_values_with_leader_and_followers_default_value():
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, default=['255.255.255.0'])
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
with pytest.raises(ValueError):
Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert not await list_sessions()
def test_reset_values_with_leader_and_followers_default(config_type):
@pytest.mark.asyncio
async 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'])
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])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
owner = global_owner(cfg, config_type)
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
owner = await global_owner(cfg, config_type)
cfg = await get_config(cfg, config_type)
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.146'])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
if config_type == 'tiramisu-api':
cfg.send()
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145']
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(None)
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_values_with_leader_and_followers_follower(config_type):
@pytest.mark.asyncio
async def test_values_with_leader_and_followers_follower(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('notunique',))
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])
maconfig = OptionDescription('toto', '', [interface1])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
if config_type != 'tiramisu-api':
with pytest.raises(LeadershipError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
#
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(APIError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)
#reset
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
'192.168.230.145',
'192.168.230.145'])
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_values_with_leader_and_followers_pop(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
if config_type != 'tiramisu-api':
raises(LeadershipError,
"cfg.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'])
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')
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
if config_type != 'tiramisu-api':
# FIXME
raises(APIError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.pop(1)")
#reset
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145',
'192.168.230.145',
'192.168.230.145'])
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()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.146'])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146']
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.146']
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_values_with_leader_and_followers_pop(config_type):
@pytest.mark.asyncio
async def test_values_with_leader_and_followers_leader(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('notunique',))
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])
maconfig = OptionDescription('toto', '', [interface1])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
if config_type != 'tiramisu-api':
with pytest.raises(LeadershipError):
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_values_with_leader_and_followers_leader_pop():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('notunique',))
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])
maconfig = OptionDescription('toto', '', [interface1])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.0.0')
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"]
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
compare(await 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',))))
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
compare(await 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 await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.146"]
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
await 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"])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0')
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0')
compare(await 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'))))
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(5)
compare(await 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'))))
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(await 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'))))
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(await 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'))))
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
compare(await 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',))))
assert not await list_sessions()
@pytest.mark.asyncio
async def test_follower_unique():
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, properties=('unique',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
async with await Config(maconfig) as cfg:
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.146"])
# unique property is removed for a follower
assert not await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).property.get()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_values_with_leader_owner(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
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('255.255.255.0')
cfg.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', 1).value.set('255.255.0.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.230.145', '192.168.230.146']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(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()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
owner = await cfg.owner.get()
cfg = await get_config(cfg, config_type)
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert not await list_sessions()
def test_values_with_leader_and_followers_leader(config_type):
@pytest.mark.asyncio
async def test_values_with_leader_disabled(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, 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.set(["192.168.230.145"])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
if config_type != 'tiramisu-api':
raises(LeadershipError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])")
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
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()
async with await Config(maconfig) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api':
await cfg.send()
#delete with value in disabled var
await cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
##append with value in disabled var
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set("192.168.230.145")
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", '192.168.230.43'])
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_values_with_leader_and_followers_leader_pop():
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg.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', 1).value.set('255.255.0.0')
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145", "192.168.230.146"]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.0.0'
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',))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
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 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'
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"])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 3).value.set('255.255.0.0')
cfg.option('ip_admin_eth0.netmask_admin_eth0', 4).value.set('255.255.0.0')
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'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(5)
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'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
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'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
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'))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(2)
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(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
owner = cfg.owner.get()
cfg = get_config(cfg, config_type)
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
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(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg_ori = Config(maconfig)
cfg_ori.property.read_write()
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)
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")
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
if config_type == 'tiramisu-api':
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
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('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.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.pop(0)
##append with value in disabled var
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.unrestraint.option('ip_admin_eth0.netmask_admin_eth0').property.pop('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.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(config_type):
@pytest.mark.asyncio
async def test_multi_non_valid_value(config_type):
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
maconfig = OptionDescription('toto', '', [ip_admin_eth0])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
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()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('ip_admin_eth0').value.set(['a'])
with pytest.raises(ValueError):
await cfg.option('ip_admin_eth0').value.set([1])
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_multi_leader_default_follower(config_type):
@pytest.mark.asyncio
async def test_multi_leader_default_follower(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
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()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_groups_with_leader_get_modified_value():
@pytest.mark.asyncio
async def test_groups_with_leader_get_modified_value():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('notunique',))
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])
maconfig = OptionDescription('toto', '', [interface1])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
compare(await cfg.value.exportation(), ((), (), (), ()))
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
compare(await cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0',), (None,), (('192.168.1.1',),), ('user',)))
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
compare(await 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',))))
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
compare(await 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'))))
assert not await list_sessions()
@pytest.mark.asyncio
async def test_groups_with_leader_importation(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
compare(cfg.value.exportation(), ((), (), (), ()))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
compare(cfg.value.exportation(), (('ip_admin_eth0.ip_admin_eth0',), (None,), (('192.168.1.1',),), ('user',)))
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
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',))))
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
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'))))
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
await 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']]])
cfg = await get_config(cfg, config_type)
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1', '192.168.1.0']
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.255'
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == 'user'
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'user'
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user'
if config_type == 'tiramisu-api':
await cfg.send()
assert not await list_sessions()
def test_groups_with_leader_importation(config_type):
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
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']]])
cfg = get_config(cfg, config_type)
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1', '192.168.1.0']
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.255'
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.0'
cfg.option('ip_admin_eth0.ip_admin_eth0').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():
@pytest.mark.asyncio
async def test_wrong_index():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
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])
od1 = OptionDescription('od', '', [interface1])
maconfig = OptionDescription('toto', '', [od1])
cfg = Config(maconfig)
cfg.property.read_write()
assert cfg.option('od.ip_admin_eth0.ip_admin_eth0').option.get()
raises(APIError, "cfg.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()")
assert cfg.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get()
assert cfg.option('od.ip_admin_eth0').option.get()
raises(APIError, "cfg.option('od.ip_admin_eth0', 0).option.get()")
assert cfg.option('od').option.get()
raises(APIError, "cfg.option('od', 0).option.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
assert await cfg.option('od.ip_admin_eth0.ip_admin_eth0').option.get()
with pytest.raises(APIError):
await cfg.option('od.ip_admin_eth0.ip_admin_eth0', 0).option.get()
assert await cfg.option('od.ip_admin_eth0.netmask_admin_eth0', 0).option.get()
assert await cfg.option('od.ip_admin_eth0').option.get()
with pytest.raises(APIError):
await cfg.option('od.ip_admin_eth0', 0).option.get()
assert await cfg.option('od').option.get()
with pytest.raises(APIError):
await cfg.option('od', 0).option.get()
assert not await list_sessions()
def test_without_leader_or_follower():
raises(ValueError, "Leadership('ip_admin_eth0', '', [])")
@pytest.mark.asyncio
async def test_without_leader_or_follower():
with pytest.raises(ValueError):
Leadership('ip_admin_eth0', '', [])
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0])")
with pytest.raises(ValueError):
Leadership('ip_admin_eth0', '', [ip_admin_eth0])
#empty optiondescription is allowed
OptionDescription('ip_admin_eth0', '', [])
assert not await list_sessions()
def test_leader_not_multi():
@pytest.mark.asyncio
async def test_leader_not_multi():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé")
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
with pytest.raises(ValueError):
Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert not await list_sessions()
def test_follower_not_multi():
@pytest.mark.asyncio
async def test_follower_not_multi():
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")
raises(ValueError, "Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])")
with pytest.raises(ValueError):
Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
assert not await list_sessions()
def test_follower_not_same():
@pytest.mark.asyncio
async def test_follower_force_store_value():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
ip_admin_eth1 = IPOption('ip_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('ip_netmask', ip_admin_eth0)
interface1 = Leadership('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1])
raises(ConfigError, "Config(maconfig)")
def test_follower_not_same_not_equal():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
ip_admin_eth1 = IPOption('ip_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('not_equal', netmask_admin_eth0)
interface1 = Leadership('interface1', '', [ip_admin_eth1, netmask_admin_eth1])
od1 = OptionDescription('od', '', [interface0, interface1])
maconfig = OptionDescription('toto', '', [od1])
cfg = Config(maconfig)
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():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", multi=True, properties=('force_store_value',))
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',))
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface0])
maconfig = OptionDescription('toto', '', [od1])
raises(ConfigError, "Config(maconfig)")
od2 = OptionDescription('toto', '', [od1])
async with await Config(od2) as cfg:
await cfg.property.read_write()
assert not await cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_follower_force_store_value_read_only():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',))
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface0])
od2 = OptionDescription('toto', '', [od1])
async with await Config(od2) as cfg:
await cfg.property.read_only()
assert not await cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_follower_force_store_value_reset():
ip_admin_eth0 = IPOption('ip_admin_eth0', "ip réseau autorisé", multi=True, default=['1.1.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "masque du sous-réseau", default_multi='255.255.255.0', multi=True, properties=('force_store_value',))
interface0 = Leadership('interface0', '', [ip_admin_eth0, netmask_admin_eth0])
od1 = OptionDescription('od', '', [interface0])
od2 = OptionDescription('toto', '', [od1])
async with await Config(od2) as cfg:
await cfg.property.read_write()
await cfg.option('od.interface0.ip_admin_eth0').value.set(['1.1.1.1', '192.168.0.0'])
assert not await cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault()
assert not await cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault()
#
await cfg.option('od.interface0.netmask_admin_eth0', 1).value.reset()
assert not await cfg.option('od.interface0.netmask_admin_eth0', 1).owner.isdefault()
#
await cfg.option('od.interface0.ip_admin_eth0').value.pop(0)
await cfg.option('od.interface0.ip_admin_eth0').value.pop(0)
assert await cfg.option('od.interface0.ip_admin_eth0').value.get() == []
await cfg.option('od.interface0.ip_admin_eth0').value.reset()
assert not await cfg.option('od.interface0.netmask_admin_eth0', 0).owner.isdefault()
assert not await list_sessions()
@pytest.mark.asyncio
async def test_follower_properties():
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, properties=('aproperty',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
maconfig = OptionDescription('toto', '', [interface1])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['1.1.1.1', '192.168.0.0'])
await cfg.option('ip_admin_eth0.netmask_admin_eth0').property.get() == ('aproperty',)
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).property.get() == ('aproperty',)
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).property.get() == ('aproperty',)
#
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).property.add('newproperty')
await cfg.option('ip_admin_eth0.netmask_admin_eth0').property.get() == ('aproperty',)
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).property.get() == ('aproperty', 'newproperty')
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).property.get() == ('aproperty',)
#
await cfg.option('ip_admin_eth0.netmask_admin_eth0').property.add('newproperty1')
await cfg.option('ip_admin_eth0.netmask_admin_eth0').property.get() == ('aproperty', 'newproperty1')
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).property.get() == ('aproperty', 'newproperty', 'newproperty1')
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).property.get() == ('aproperty', 'newproperty1')
assert not await list_sessions()

View File

@ -3,17 +3,19 @@ from .autopath import do_autopath
do_autopath()
# FIXME from .config import config_type, get_config
from py.test import raises
import pytest
from tiramisu import Config
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
SymLinkOption, Leadership, undefined, Params, ParamOption
from tiramisu import IntOption, StrOption, OptionDescription, \
SymLinkOption, Leadership, undefined, Calculation, Params, \
ParamOption, ParamValue, calc_value
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.setting import groups
from tiramisu.storage import list_sessions
from .config import event_loop
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
#def teardown_function(function):
# assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def make_description():
@ -23,13 +25,11 @@ def make_description():
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
stroption2 = UnicodeOption('unicode2', 'Test string option',
stroption2 = StrOption('unicode2', 'Test string option',
properties=('mandatory', ))
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
stroption4 = StrOption('str4', 'Test string option', multi=True,
properties=('mandatory', ), allow_empty_list=True)
descr = OptionDescription('tiram', '', [subdescr, stroption, stroption1, stroption2, stroption3, stroption4])
descr = OptionDescription('tiram', '', [subdescr, stroption, stroption1, stroption2, stroption3])
return descr
@ -45,7 +45,7 @@ def make_description2():
stroption2 = SymLinkOption('unicode2', stroption1)
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
unicode1 = StrOption('unicode1', 'Test string option', Calculation(return_value, Params(ParamOption(stroption))), properties=('mandatory',))
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1])
return descr
@ -70,558 +70,616 @@ def make_description3():
stroption2 = SymLinkOption('unicode2', stroption1)
stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', ))
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
unicode1 = StrOption('unicode1', 'Test string option', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
int1 = IntOption('int1', '', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1, int1])
return descr
def test_mandatory_ro():
@pytest.mark.asyncio
async def test_mandatory_ro():
descr = make_description()
cfg = Config(descr)
cfg.property.read_only()
prop = []
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str1').value.set('yes')
cfg.property.read_only()
assert cfg.option('str1').value.get() == 'yes'
async with await Config(descr) as cfg:
await cfg.property.read_only()
prop = []
try:
await cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
await cfg.property.read_write()
await cfg.option('str1').value.set('yes')
await cfg.property.read_only()
assert await cfg.option('str1').value.get() == 'yes'
assert not await list_sessions()
def test_mandatory_ro_dict():
@pytest.mark.asyncio
async def test_mandatory_ro_dict():
descr = make_description()
cfg = Config(descr)
cfg.property.read_only()
prop = []
try:
cfg.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str1').value.set('yes')
cfg.option('unicode2').value.set('yes')
cfg.property.read_only()
try:
cfg.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str3').value.set(['yes'])
cfg.property.read_only()
assert cfg.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'str4': [], 'unicode2': 'yes'}
async with await Config(descr) as cfg:
await cfg.property.read_only()
prop = []
try:
await cfg.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
await cfg.property.read_write()
await cfg.option('str1').value.set('yes')
await cfg.option('unicode2').value.set('yes')
await cfg.property.read_only()
try:
await cfg.value.dict()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
await cfg.property.read_write()
await cfg.option('str3').value.set(['yes'])
await cfg.property.read_only()
assert await cfg.value.dict() == {'str': 'abc', 'str1': 'yes', 'str3': ['yes'], 'unicode2': 'yes'}
assert not await list_sessions()
def test_mandatory_rw():
@pytest.mark.asyncio
async def test_mandatory_rw():
descr = make_description()
cfg = Config(descr)
cfg.property.read_write()
# not mandatory in rw
cfg.option('str1').value.get()
cfg.option('str1').value.set('yes')
assert cfg.option('str1').value.get() == 'yes'
async with await Config(descr) as cfg:
await cfg.property.read_write()
# not mandatory in rw
await cfg.option('str1').value.get()
await cfg.option('str1').value.set('yes')
assert await cfg.option('str1').value.get() == 'yes'
assert not await list_sessions()
def test_mandatory_default():
@pytest.mark.asyncio
async def test_mandatory_default():
descr = make_description()
cfg = Config(descr)
cfg.property.read_only()
#not mandatory in rw
cfg.option('str').value.get()
cfg.property.read_write()
cfg.option('str').value.set('yes')
cfg.property.read_only()
cfg.option('str').value.get()
cfg.property.read_write()
cfg.option('str').value.set(None)
cfg.property.read_only()
prop = []
try:
cfg.option('str').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
async with await Config(descr) as cfg:
await cfg.property.read_only()
#not mandatory in rw
await cfg.option('str').value.get()
await cfg.property.read_write()
await cfg.option('str').value.set('yes')
await cfg.property.read_only()
await cfg.option('str').value.get()
await cfg.property.read_write()
await cfg.option('str').value.set(None)
await cfg.property.read_only()
prop = []
try:
await cfg.option('str').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
assert not await list_sessions()
def test_mandatory_delete():
@pytest.mark.asyncio
async def test_mandatory_delete():
descr = make_description()
cfg = Config(descr)
cfg.property.read_only()
cfg.option('str').value.get()
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str1').value.set('yes')
cfg.property.read_only()
assert cfg.option('str1').value.get() == 'yes'
cfg.property.pop('everything_frozen')
prop = []
try:
cfg.option('str1').value.reset()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.option('str').value.reset()
async with await Config(descr) as cfg:
await cfg.property.read_only()
await cfg.option('str').value.get()
try:
await cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
await cfg.property.read_write()
await cfg.option('str1').value.set('yes')
await cfg.property.read_only()
assert await cfg.option('str1').value.get() == 'yes'
await cfg.property.pop('everything_frozen')
prop = []
try:
await cfg.option('str1').value.reset()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
await cfg.option('str').value.reset()
assert cfg.option('str1').value.get() == 'yes'
assert await cfg.option('str1').value.get() == 'yes'
assert not await list_sessions()
#valeur vide : None, '', u'', ...
def test_mandatory_none():
@pytest.mark.asyncio
async def test_mandatory_none():
descr = make_description()
cfg = Config(descr)
cfg.option('str1').value.set(None)
assert cfg.option('str1').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
async with await Config(descr) as cfg:
await cfg.option('str1').value.set(None)
assert await cfg.option('str1').owner.get() == 'user'
await cfg.property.read_only()
prop = []
try:
await cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
assert not await list_sessions()
def test_mandatory_empty():
@pytest.mark.asyncio
async def test_mandatory_empty():
descr = make_description()
cfg = Config(descr)
cfg.option('str1').value.set('')
assert cfg.option('str1').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
async with await Config(descr) as cfg:
await cfg.option('str1').value.set('')
assert await cfg.option('str1').owner.get() == 'user'
await cfg.property.read_only()
prop = []
try:
await cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
assert not await list_sessions()
def test_mandatory_multi_none():
@pytest.mark.asyncio
async def test_mandatory_multi_none():
descr = make_description()
cfg = Config(descr)
cfg.option('str3').value.set([None])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('str3').value.set(['yes', None])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
async with await Config(descr) as cfg:
await cfg.option('str3').value.set([None])
assert await cfg.option('str3').owner.get() == 'user'
await cfg.property.read_only()
prop = []
try:
await cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
await cfg.property.read_write()
await cfg.option('str3').value.set(['yes', None])
assert await cfg.option('str3').owner.get() == 'user'
await cfg.property.read_only()
prop = []
try:
await cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
assert not await list_sessions()
def test_mandatory_multi_empty():
@pytest.mark.asyncio
async def test_mandatory_multi_empty():
descr = make_description()
cfg = Config(descr)
cfg.option('str3').value.set([])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
cfg.property.read_write()
cfg.option('str3').value.set([''])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
cfg.property.read_write()
cfg.option('str3').value.set(['yes', ''])
assert cfg.option('str3').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
async with await Config(descr) as cfg:
await cfg.option('str3').value.set([])
assert await cfg.option('str3').owner.get() == 'user'
await cfg.property.read_only()
prop = []
try:
await cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
await cfg.property.read_write()
await cfg.option('str3').value.set([''])
assert await cfg.option('str3').owner.get() == 'user'
await cfg.property.read_only()
prop = []
try:
await cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
await cfg.property.read_write()
await cfg.option('str3').value.set(['yes', ''])
assert await cfg.option('str3').owner.get() == 'user'
await cfg.property.read_only()
prop = []
try:
await cfg.option('str3').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
assert not await list_sessions()
def test_mandatory_multi_empty_allow_empty_list():
@pytest.mark.asyncio
async def test_mandatory_multi_append():
descr = make_description()
cfg = Config(descr)
cfg.option('str4').value.set([])
assert cfg.option('str4').owner.get() == 'user'
cfg.property.read_only()
prop = []
cfg.option('str4').value.get()
#
cfg.property.read_write()
cfg.option('str4').value.set([''])
assert cfg.option('str4').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str4').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
#
cfg.property.read_write()
cfg.option('str4').value.set(['yes', ''])
assert cfg.option('str4').owner.get() == 'user'
cfg.property.read_only()
prop = []
try:
cfg.option('str4').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
async with await Config(descr) as cfg:
await cfg.option('str3').value.set(['yes'])
await cfg.property.read_write()
ret = await cfg.option('str3').value.get()
ret.append(None)
assert not await list_sessions()
def test_mandatory_multi_append():
@pytest.mark.asyncio
async def test_mandatory_disabled():
descr = make_description()
cfg = Config(descr)
cfg.option('str3').value.set(['yes'])
cfg.property.read_write()
cfg.option('str3').value.get().append(None)
async with await Config(descr) as cfg:
await cfg.option('str1').value.get()
await cfg.option('str1').property.add('disabled')
await cfg.property.read_only()
pop = []
try:
await cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
search_prop = {'disabled'}
assert set(prop) == search_prop
assert not await list_sessions()
def test_mandatory_disabled():
@pytest.mark.asyncio
async def test_mandatory_unicode():
descr = make_description()
cfg = Config(descr)
cfg.option('str1').value.get()
cfg.option('str1').property.add('disabled')
cfg.property.read_only()
pop = []
try:
cfg.option('str1').value.get()
except PropertiesOptionError as err:
prop = err.proptype
search_prop = {'disabled'}
assert set(prop) == search_prop
async with await Config(descr) as cfg:
await cfg.option('unicode2').value.get()
await cfg.property.read_only()
prop = []
try:
await cfg.option('unicode2').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
await cfg.property.read_write()
await cfg.option('unicode2').value.set(u'')
await cfg.property.read_only()
prop = []
try:
await cfg.option('unicode2').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
assert not await list_sessions()
def test_mandatory_unicode():
@pytest.mark.asyncio
async def test_mandatory_warnings_ro():
descr = make_description()
cfg = Config(descr)
cfg.option('unicode2').value.get()
cfg.property.read_only()
prop = []
try:
cfg.option('unicode2').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
cfg.property.read_write()
cfg.option('unicode2').value.set(u'')
cfg.property.read_only()
prop = []
try:
cfg.option('unicode2').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
async with await Config(descr) as cfg:
await cfg.option('str').value.set('')
await cfg.property.read_only()
proc = []
try:
await cfg.option('str').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
await cfg.property.read_write()
await cfg.option('str').value.set('a')
await cfg.property.read_only()
assert list(await cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
assert not await list_sessions()
def test_mandatory_warnings_ro():
@pytest.mark.asyncio
async def test_mandatory_warnings_rw():
descr = make_description()
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_only()
proc = []
try:
cfg.option('str').value.get()
except PropertiesOptionError as err:
prop = err.proptype
assert 'mandatory' in prop
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
cfg.property.read_write()
cfg.option('str').value.set('a')
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
async with await Config(descr) as cfg:
await cfg.option('str').value.set('')
await cfg.property.read_write()
await cfg.option('str').value.get()
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
await cfg.option('str').value.set('a')
assert list(await cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
assert not await list_sessions()
def test_mandatory_warnings_rw():
@pytest.mark.asyncio
async def test_mandatory_warnings_disabled():
descr = make_description()
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
cfg.option('str').value.set('a')
assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
async with await Config(descr) as cfg:
await cfg.option('str').value.set('')
await cfg.property.read_write()
await cfg.option('str').value.get()
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
await cfg.option('str').property.add('disabled')
assert set(await cfg.value.mandatory()) == {'str1', 'unicode2', 'str3'}
assert not await list_sessions()
def test_mandatory_warnings_disabled():
@pytest.mark.asyncio
async def test_mandatory_warnings_hidden():
descr = make_description()
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
cfg.option('str').property.add('disabled')
assert set(cfg.value.mandatory()) == {'str1', 'unicode2', 'str3'}
async with await Config(descr) as cfg:
await cfg.option('str').value.set('')
await cfg.property.read_write()
await cfg.permissive.add('hidden')
await cfg.option('str').value.get()
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
await cfg.option('str').property.add('hidden')
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
assert not await list_sessions()
def test_mandatory_warnings_hidden():
@pytest.mark.asyncio
async def test_mandatory_warnings_frozen():
descr = make_description()
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
cfg.option('str').value.get()
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
cfg.option('str').property.add('hidden')
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
async with await Config(descr) as cfg:
await cfg.option('str').value.set('')
await cfg.property.read_write()
await cfg.option('str').value.get()
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
await cfg.option('str').property.add('frozen')
await cfg.property.read_only()
assert set(await cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
assert not await list_sessions()
def test_mandatory_warnings_frozen():
descr = make_description()
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
cfg.option('str').property.add('frozen')
cfg.property.read_only()
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
def test_mandatory_leader():
@pytest.mark.asyncio
async def test_mandatory_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
properties=('mandatory', ))
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])
descr = OptionDescription('o', '', [interface1])
cfg = Config(descr)
cfg.property.read_only()
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()")
raises(PropertiesOptionError, "cfg.value.dict()")
async with await Config(descr) as cfg:
await cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.value.dict()
assert not await list_sessions()
def test_mandatory_warnings_leader():
@pytest.mark.asyncio
async def test_mandatory_warnings_leader():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True,
properties=('mandatory', ))
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])
descr = OptionDescription('o', '', [interface1])
cfg = Config(descr)
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
async with await Config(descr) as cfg:
assert list(await cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
assert not await list_sessions()
def test_mandatory_leader_empty():
@pytest.mark.asyncio
async def test_mandatory_leader_empty():
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
cfg = Config(descr)
cfg.property.read_write()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.property.read_only()
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()")
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
cfg.property.read_only()
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()")
cfg.property.read_write()
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
cfg.property.read_only()
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()")
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
async with await Config(descr) as cfg:
await cfg.property.read_write()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
await cfg.property.read_write()
#
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
await cfg.property.read_only()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip2'])
await cfg.property.read_only()
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert not await list_sessions()
def test_mandatory_warnings_leader_empty():
@pytest.mark.asyncio
async def test_mandatory_warnings_leader_empty():
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)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
cfg = Config(descr)
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(cfg.value.mandatory()) == []
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(await cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
#
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
assert list(await cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
#
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(await cfg.value.mandatory()) == []
assert not await list_sessions()
def test_mandatory_follower():
@pytest.mark.asyncio
async def test_mandatory_follower():
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, properties=('mandatory', ))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
cfg = Config(descr)
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
raises(PropertiesOptionError, "cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()")
#
cfg.property.read_write()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
async with await Config(descr) as cfg:
await cfg.property.read_only()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [],
'ip_admin_eth0.netmask_admin_eth0': []}
#
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
await cfg.property.read_only()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
#
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('')
await cfg.property.read_only()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
with pytest.raises(PropertiesOptionError):
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
#
await cfg.property.read_write()
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('ip')
await cfg.property.read_only()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
assert await cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip'],
'ip_admin_eth0.netmask_admin_eth0': ['ip']}
assert not await list_sessions()
def test_mandatory_warnings_follower():
@pytest.mark.asyncio
async def test_mandatory_warnings_follower():
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, properties=('mandatory', ))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
descr = OptionDescription('o', '', [interface1])
cfg = Config(descr)
cfg.property.read_only()
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
cfg.property.read_write()
assert list(cfg.value.mandatory()) == []
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0']
async with await Config(descr) as cfg:
await cfg.property.read_only()
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
await cfg.property.read_write()
assert list(await cfg.value.mandatory()) == []
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
assert list(await cfg.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0']
assert not await list_sessions()
def test_mandatory_warnings_symlink():
@pytest.mark.asyncio
async def test_mandatory_warnings_symlink():
descr = make_description_sym()
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
cfg.option('str').property.add('frozen')
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
async with await Config(descr) as cfg:
await cfg.option('str').value.set('')
await cfg.property.read_write()
await cfg.option('str').value.get()
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'str3']
await cfg.option('str').property.add('frozen')
await cfg.property.read_only()
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'str3']
assert not await list_sessions()
#def test_mandatory_warnings_validate():
#@pytest.mark.asyncio
#async def test_mandatory_warnings_validate():
# descr = make_description3()
# cfg = Config(descr)
# cfg.option('str').value.set('')
# raises(ValueError, "list(cfg.value.mandatory())")
# cfg.option('str').value.set('test')
# raises(ValueError, "list(cfg.value.mandatory())")
# cfg = await Config(descr)
# await cfg.option('str').value.set('')
# raises(ValueError, "list(await cfg.value.mandatory())")
# await cfg.option('str').value.set('test')
# raises(ValueError, "list(await cfg.value.mandatory())")
def test_mandatory_warnings_validate_empty():
@pytest.mark.asyncio
async def test_mandatory_warnings_validate_empty():
descr = make_description2()
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
async with await Config(descr) as cfg:
await cfg.option('str').value.set('')
await cfg.property.read_only()
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'str3']
assert not await list_sessions()
def test_mandatory_warnings_requires():
@pytest.mark.asyncio
async def test_mandatory_warnings_requires():
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option',
properties=('mandatory', ))
stroption2 = UnicodeOption('unicode2', 'Test string option',
stroption2 = StrOption('unicode2', 'Test string option',
properties=('mandatory', ))
stroption3 = StrOption('str3', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
mandatory_property = Calculation(calc_value,
Params(ParamValue('mandatory'),
kwargs={'condition': ParamOption(stroption, notraisepropertyerror=True),
'expected': ParamValue('yes'),
'no_condition_is_invalid': ParamValue(True)}))
stroption3 = StrOption('str3', 'Test string option', multi=True, properties=(mandatory_property,))
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3])
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.property.read_write()
cfg.option('str').value.get()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
cfg.property.read_write()
cfg.option('str').value.set('yes')
assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
async with await Config(descr) as cfg:
await cfg.option('str').value.set('')
await cfg.property.read_write()
await cfg.option('str').value.get()
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
await cfg.property.read_only()
assert list(await cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
await cfg.property.read_write()
await cfg.option('str').value.set('yes')
assert list(await cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
assert not await list_sessions()
def test_mandatory_warnings_requires_leadership():
@pytest.mark.asyncio
async def test_mandatory_warnings_requires_leadership():
stroption = StrOption('str', 'Test string option', default="abc",
properties=('mandatory', ))
stroption1 = StrOption('str1', 'Test string option', multi=True)
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
mandatory_property = Calculation(calc_value,
Params(ParamValue(None),
kwargs={'condition': ParamOption(stroption),
'expected': ParamValue('yes'),
'reverse_condition': ParamValue(True),
'default': ParamValue('mandatory')}))
stroption2 = StrOption('str2', 'Test string option', multi=True, properties=(mandatory_property,))
leadership = Leadership('leader', 'leadership', [stroption1, stroption2])
descr = OptionDescription('tiram', '', [stroption, leadership])
cfg = Config(descr)
cfg.option('str').value.set('')
cfg.option('leader.str1').value.set(['str'])
assert list(cfg.value.mandatory()) == ['str']
cfg.option('str').value.set('yes')
assert list(cfg.value.mandatory()) == ['leader.str2']
async with await Config(descr) as cfg:
await cfg.option('str').value.set('')
await cfg.option('leader.str1').value.set(['str'])
assert list(await cfg.value.mandatory()) == ['str']
await cfg.option('str').value.set('yes')
assert list(await cfg.value.mandatory()) == ['leader.str2']
assert not await list_sessions()
def test_mandatory_warnings_requires_leadership_follower():
@pytest.mark.asyncio
async def test_mandatory_warnings_requires_leadership_follower():
stroption = StrOption('str', 'Test string option', multi=True)
stroption1 = StrOption('str1', 'Test string option', multi=True)
stroption2 = StrOption('str2', 'Test string option', multi=True, requires=[{'option': stroption1, 'expected': 'yes', 'action': 'mandatory', 'transitive': False}])
mandatory_property = Calculation(calc_value,
Params(ParamValue(None),
kwargs={'condition': ParamOption(stroption1),
'expected': ParamValue('yes'),
'reverse_condition': ParamValue(True),
'default': ParamValue('mandatory')}))
stroption2 = StrOption('str2', 'Test string option', multi=True, properties=(mandatory_property,))
leadership = Leadership('leader', 'leadership', [stroption, stroption1, stroption2])
descr = OptionDescription('tiram', '', [leadership])
cfg = Config(descr)
cfg.option('leader.str').value.set(['str'])
assert list(cfg.value.mandatory()) == []
cfg.option('leader.str1', 0).value.set('yes')
assert list(cfg.value.mandatory()) == ['leader.str2']
async with await Config(descr) as cfg:
await cfg.option('leader.str').value.set(['str'])
assert list(await cfg.value.mandatory()) == []
await cfg.option('leader.str1', 0).value.set('yes')
assert list(await cfg.value.mandatory()) == ['leader.str2']
assert not await list_sessions()
def test_mandatory_od_disabled():
@pytest.mark.asyncio
async def test_mandatory_od_disabled():
descr = make_description()
descr = OptionDescription('od', '', [descr])
cfg = Config(descr)
cfg.property.read_only()
assert list(cfg.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
cfg.option('tiram').property.add('disabled')
assert list(cfg.value.mandatory()) == []
async with await Config(descr) as cfg:
await cfg.property.read_only()
assert list(await cfg.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
await cfg.option('tiram').property.add('disabled')
assert list(await cfg.value.mandatory()) == []
assert not await list_sessions()

View File

@ -1,17 +1,15 @@
from py.test import raises
import pytest
from .autopath import do_autopath
do_autopath()
from tiramisu.setting import groups, owners
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, BoolOption, ChoiceOption, \
IPOption, OptionDescription, Leadership, Config, GroupConfig, MetaConfig, \
Params, ParamOption, ParamValue
Calculation, Params, ParamOption, ParamValue, calc_value, ParamSelfOption, \
valid_network_netmask, valid_not_equal
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError, APIError
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
from .config import config_type, get_config, delete_sessions, event_loop
owners.addowner('config')
@ -45,372 +43,478 @@ def make_description():
return od2
def make_metaconfig(double=False):
async def make_metaconfig(double=False):
od2 = make_description()
conf1 = Config(od2, session_id='conf1')
conf2 = Config(od2, session_id='conf2')
meta = MetaConfig([conf1, conf2], session_id='meta')
conf1 = await Config(od2, session_id='conf1', delete_old_session=True)
await conf1.property.read_write()
conf2 = await Config(od2, session_id='conf2', delete_old_session=True)
await conf2.property.read_write()
meta = await MetaConfig([conf1, conf2], session_id='meta', delete_old_session=True)
if double:
meta.owner.set(owners.meta2)
meta = MetaConfig([meta], session_id='doublemeta')
meta.property.read_write()
meta.owner.set(owners.meta1)
await meta.owner.set(owners.meta2)
meta = await MetaConfig([meta], session_id='doublemeta', delete_old_session=True)
await meta.property.read_write()
await meta.owner.set(owners.meta1)
return meta
def test_unknown_config():
meta = make_metaconfig()
raises(ConfigError, "meta.config('unknown')")
@pytest.mark.asyncio
async def test_unknown_config():
meta = await make_metaconfig()
with pytest.raises(ConfigError):
await meta.config('unknown')
await delete_sessions(meta)
def test_error_metaconfig():
@pytest.mark.asyncio
async def test_error_metaconfig():
od2 = make_description()
conf1 = Config(od2, session_id='conf1')
raises(TypeError, "MetaConfig([GroupConfig([conf1])], session_id='meta')")
conf1 = await Config(od2, session_id='conf1')
with pytest.raises(TypeError):
await MetaConfig([await GroupConfig([conf1])], session_id='meta')
await delete_sessions(conf1)
def test_path():
meta = make_metaconfig()
assert meta.config.path() == 'meta'
assert meta.config('conf1').config.path() == 'meta.conf1'
assert meta.config('conf2').config.path() == 'meta.conf2'
@pytest.mark.asyncio
async def test_path():
meta = await make_metaconfig()
assert await meta.config.path() == 'meta'
ret = await meta.config('conf1')
assert await ret.config.path() == 'meta.conf1'
ret = await meta.config('conf2')
assert await ret.config.path() == 'meta.conf2'
await delete_sessions(meta)
#FIXME ne pas mettre 2 meta dans une config
#FIXME ne pas mettre 2 OD differents dans un meta
def test_none():
meta = make_metaconfig()
assert meta.option('od1.i3').value.get() is meta.config('conf1').option('od1.i3').value.get() is meta.config('conf2').option('od1.i3').value.get() is None
assert meta.option('od1.i3').owner.get() is meta.config('conf1').option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.default
@pytest.mark.asyncio
async def test_none():
meta = await make_metaconfig()
conf1 = await meta.config('conf1')
conf2 = await meta.config('conf2')
assert await meta.option('od1.i3').value.get() is await conf1.option('od1.i3').value.get() is await conf2.option('od1.i3').value.get() is None
assert await meta.option('od1.i3').owner.get() is await conf1.option('od1.i3').owner.get() is await conf2.option('od1.i3').owner.get() is owners.default
#
meta.option('od1.i3').value.set(3)
assert meta.option('od1.i3').value.get() == meta.config('conf1').option('od1.i3').value.get() == meta.config('conf2').option('od1.i3').value.get() == 3
assert meta.option('od1.i3').owner.get() is meta.config('conf1').option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.meta1
await meta.option('od1.i3').value.set(3)
assert await meta.option('od1.i3').value.get() == await conf1.option('od1.i3').value.get() == await conf2.option('od1.i3').value.get() == 3
assert await meta.option('od1.i3').owner.get() is await conf1.option('od1.i3').owner.get() is await conf2.option('od1.i3').owner.get() is owners.meta1
#
meta.config('conf1').option('od1.i3').value.set(2)
assert meta.option('od1.i3').value.get() == meta.config('conf2').option('od1.i3').value.get() == 3
assert meta.config('conf1').option('od1.i3').value.get() == 2
assert meta.option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.meta1
assert meta.config('conf1').option('od1.i3').owner.get() is owners.user
await conf1.option('od1.i3').value.set(2)
assert await meta.option('od1.i3').value.get() == await conf2.option('od1.i3').value.get() == 3
assert await conf1.option('od1.i3').value.get() == 2
assert await meta.option('od1.i3').owner.get() is await conf2.option('od1.i3').owner.get() is owners.meta1
assert await conf1.option('od1.i3').owner.get() is owners.user
#
meta.option('od1.i3').value.set(4)
assert meta.option('od1.i3').value.get() == meta.config('conf2').option('od1.i3').value.get() == 4
assert meta.config('conf1').option('od1.i3').value.get() == 2
assert meta.option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.meta1
assert meta.config('conf1').option('od1.i3').owner.get() is owners.user
await meta.option('od1.i3').value.set(4)
assert await meta.option('od1.i3').value.get() == await conf2.option('od1.i3').value.get() == 4
assert await conf1.option('od1.i3').value.get() == 2
assert await meta.option('od1.i3').owner.get() is await conf2.option('od1.i3').owner.get() is owners.meta1
assert await conf1.option('od1.i3').owner.get() is owners.user
#
meta.option('od1.i3').value.reset()
assert meta.option('od1.i3').value.get() is meta.config('conf2').option('od1.i3').value.get() is None
assert meta.config('conf1').option('od1.i3').value.get() == 2
assert meta.option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.default
assert meta.config('conf1').option('od1.i3').owner.get() is owners.user
await meta.option('od1.i3').value.reset()
assert await meta.option('od1.i3').value.get() is await conf2.option('od1.i3').value.get() is None
assert await conf1.option('od1.i3').value.get() == 2
assert await meta.option('od1.i3').owner.get() is await conf2.option('od1.i3').owner.get() is owners.default
assert await conf1.option('od1.i3').owner.get() is owners.user
#
meta.config('conf1').option('od1.i3').value.reset()
assert meta.option('od1.i3').value.get() is meta.config('conf1').option('od1.i3').value.get() is meta.config('conf2').option('od1.i3').value.get() is None
assert meta.option('od1.i3').owner.get() is meta.config('conf1').option('od1.i3').owner.get() is meta.config('conf2').option('od1.i3').owner.get() is owners.default
#
assert meta.config(None).config.name() == meta.config.name()
await conf1.option('od1.i3').value.reset()
assert await meta.option('od1.i3').value.get() is await conf1.option('od1.i3').value.get() is await conf2.option('od1.i3').value.get() is None
assert await meta.option('od1.i3').owner.get() is await conf1.option('od1.i3').owner.get() is await conf2.option('od1.i3').owner.get() is owners.default
await delete_sessions(meta)
def test_reset():
meta = make_metaconfig()
assert meta.option('od1.i2').value.get() == 1
meta.option('od1.i2').value.set(2)
meta.config('conf1').option('od1.i2').value.set(3)
assert meta.option('od1.i2').value.get() == 2
assert meta.config('conf1').option('od1.i2').value.get() == 3
assert meta.config('conf2').option('od1.i2').value.get() == 2
meta.config.reset()
assert meta.option('od1.i2').value.get() == 1
assert meta.config('conf1').option('od1.i2').value.get() == 3
assert meta.config('conf2').option('od1.i2').value.get() == 1
@pytest.mark.asyncio
async def test_metaconfig_reset(config_type):
meta = await make_metaconfig()
meta_api = await get_config(meta, config_type)
assert await meta_api.option('od1.i2').value.get() == 1
await meta_api.option('od1.i2').value.set(2)
if config_type == 'tiramisu-api':
meta_api.send()
conf1 = await meta.config('conf1')
conf2 = await meta.config('conf2')
await conf1.option('od1.i2').value.set(3)
assert await meta.option('od1.i2').value.get() == 2
assert await conf1.option('od1.i2').value.get() == 3
assert await conf2.option('od1.i2').value.get() == 2
await meta.config.reset()
assert await meta.option('od1.i2').value.get() == 1
assert await conf1.option('od1.i2').value.get() == 3
assert await conf2.option('od1.i2').value.get() == 1
await delete_sessions(meta)
def test_default():
meta = make_metaconfig()
assert meta.option('od1.i2').value.get() == meta.config('conf1').option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 1
assert meta.option('od1.i2').owner.get() is meta.config('conf1').option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.default
@pytest.mark.asyncio
async def test_default():
meta = await make_metaconfig()
conf1 = await meta.config('conf1')
conf2 = await meta.config('conf2')
assert await meta.option('od1.i2').value.get() == await conf1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 1
assert await meta.option('od1.i2').owner.get() is await conf1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.default
#
meta.option('od1.i2').value.set(3)
assert meta.option('od1.i2').value.get() == meta.config('conf1').option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 3
assert meta.option('od1.i2').owner.get() is meta.config('conf1').option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.meta1
await meta.option('od1.i2').value.set(3)
assert await meta.option('od1.i2').value.get() == await conf1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 3
assert await meta.option('od1.i2').owner.get() is await conf1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.meta1
#
meta.config('conf1').option('od1.i2').value.set(2)
assert meta.option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 3
assert meta.config('conf1').option('od1.i2').value.get() == 2
assert meta.option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.meta1
assert meta.config('conf1').option('od1.i2').owner.get() is owners.user
await conf1.option('od1.i2').value.set(2)
assert await meta.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 3
assert await conf1.option('od1.i2').value.get() == 2
assert await meta.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.meta1
assert await conf1.option('od1.i2').owner.get() is owners.user
#
meta.option('od1.i2').value.set(4)
assert meta.option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 4
assert meta.config('conf1').option('od1.i2').value.get() == 2
assert meta.option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.meta1
assert meta.config('conf1').option('od1.i2').owner.get() is owners.user
await meta.option('od1.i2').value.set(4)
assert await meta.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 4
assert await conf1.option('od1.i2').value.get() == 2
assert await meta.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.meta1
assert await conf1.option('od1.i2').owner.get() is owners.user
#
meta.option('od1.i2').value.reset()
assert meta.option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 1
assert meta.config('conf1').option('od1.i2').value.get() == 2
assert meta.option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.default
assert meta.config('conf1').option('od1.i2').owner.get() is owners.user
await meta.option('od1.i2').value.reset()
assert await meta.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 1
assert await conf1.option('od1.i2').value.get() == 2
assert await meta.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.default
assert await conf1.option('od1.i2').owner.get() is owners.user
#
meta.config('conf1').option('od1.i2').value.reset()
assert meta.option('od1.i2').value.get() == meta.config('conf1').option('od1.i2').value.get() == meta.config('conf2').option('od1.i2').value.get() == 1
assert meta.option('od1.i2').owner.get() is meta.config('conf1').option('od1.i2').owner.get() is meta.config('conf2').option('od1.i2').owner.get() is owners.default
await conf1.option('od1.i2').value.reset()
assert await meta.option('od1.i2').value.get() == await conf1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 1
assert await meta.option('od1.i2').owner.get() is await conf1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.default
await delete_sessions(meta)
def test_contexts():
meta = make_metaconfig()
errors = meta.value.set('od1.i2', 6, only_config=True)
assert meta.option('od1.i2').value.get() == 1
assert meta.option('od1.i2').owner.get() == owners.default
assert meta.config('conf1').option('od1.i2').value.get() == meta.config('conf1').option('od1.i2').value.get() == 6
assert meta.config('conf1').option('od1.i2').owner.get() == meta.config('conf1').option('od1.i2').owner.get() is owners.user
@pytest.mark.asyncio
async def test_contexts():
meta = await make_metaconfig()
errors = await meta.value.set('od1.i2', 6, only_config=True)
assert len(errors) == 0
conf1 = await meta.config('conf1')
assert await meta.option('od1.i2').value.get() == 1
assert await meta.option('od1.i2').owner.get() == owners.default
assert await conf1.option('od1.i2').value.get() == await conf1.option('od1.i2').value.get() == 6
assert await conf1.option('od1.i2').owner.get() == await conf1.option('od1.i2').owner.get() is owners.user
await delete_sessions(meta)
def test_find():
meta = make_metaconfig()
ret = list(meta.option.find('i2'))
@pytest.mark.asyncio
async def test_find():
meta = await make_metaconfig()
ret = list(await meta.option.find('i2'))
assert len(ret) == 1
assert 1 == ret[0].value.get()
assert 1 == meta.option.find('i2', first=True).value.get()
assert meta.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
assert 1 == await ret[0].value.get()
ret = await meta.option.find('i2', first=True)
assert 1 == await ret.value.get()
assert await meta.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
'od1.i2': 1, 'od1.i5': [2]}
await delete_sessions(meta)
def test_meta_meta():
meta = make_metaconfig(double=True)
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf1').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 1
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf1').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.default
@pytest.mark.asyncio
async def test_meta_meta():
meta = await make_metaconfig(double=True)
meta1 = await meta.config('meta')
conf1 = await meta.config('meta.conf1')
conf2 = await meta.config('meta.conf2')
assert await meta.option('od1.i2').value.get() == await meta1.option('od1.i2').value.get() == await conf1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 1
assert await meta.option('od1.i2').owner.get() is await meta1.option('od1.i2').owner.get() is await conf1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.default
#
meta.option('od1.i2').value.set(3)
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf1').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 3
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf1').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.meta1
await meta.option('od1.i2').value.set(3)
assert await meta.option('od1.i2').value.get() == await meta1.option('od1.i2').value.get() == await conf1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 3
assert await meta.option('od1.i2').owner.get() is await meta1.option('od1.i2').owner.get() is await conf1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.meta1
#
meta.config('meta.conf1').option('od1.i2').value.set(2)
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 3
assert meta.config('meta.conf1').option('od1.i2').value.get() == 2
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.meta1
assert meta.config('meta.conf1').option('od1.i2').owner.get() is owners.user
await conf1.option('od1.i2').value.set(2)
assert await meta.option('od1.i2').value.get() == await meta1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 3
assert await conf1.option('od1.i2').value.get() == 2
assert await meta.option('od1.i2').owner.get() is await meta1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.meta1
assert await conf1.option('od1.i2').owner.get() is owners.user
#
meta.config('meta').option('od1.i2').value.set(4)
assert meta.option('od1.i2').value.get() == 3
assert meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 4
assert meta.config('meta.conf1').option('od1.i2').value.get() == 2
assert meta.option('od1.i2').owner.get() is owners.meta1
assert meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.meta2
assert meta.config('meta.conf1').option('od1.i2').owner.get() is owners.user
await meta1.option('od1.i2').value.set(4)
assert await meta.option('od1.i2').value.get() == 3
assert await meta1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 4
assert await conf1.option('od1.i2').value.get() == 2
assert await meta.option('od1.i2').owner.get() is owners.meta1
assert await meta1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.meta2
assert await conf1.option('od1.i2').owner.get() is owners.user
#
meta.config('meta').option('od1.i2').value.reset()
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 3
assert meta.config('meta.conf1').option('od1.i2').value.get() == 2
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.meta1
assert meta.config('meta.conf1').option('od1.i2').owner.get() is owners.user
await meta1.option('od1.i2').value.reset()
assert await meta.option('od1.i2').value.get() == await meta1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 3
assert await conf1.option('od1.i2').value.get() == 2
assert await meta.option('od1.i2').owner.get() is await meta1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.meta1
assert await conf1.option('od1.i2').owner.get() is owners.user
#
meta.option('od1.i2').value.reset()
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 1
assert meta.config('meta.conf1').option('od1.i2').value.get() == 2
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.default
assert meta.config('meta.conf1').option('od1.i2').owner.get() is owners.user
await meta.option('od1.i2').value.reset()
assert await meta.option('od1.i2').value.get() == await meta1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 1
assert await conf1.option('od1.i2').value.get() == 2
assert await meta.option('od1.i2').owner.get() is await meta1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.default
assert await conf1.option('od1.i2').owner.get() is owners.user
#
meta.config('meta.conf1').option('od1.i2').value.reset()
assert meta.option('od1.i2').value.get() == meta.config('meta').option('od1.i2').value.get() == meta.config('meta.conf1').option('od1.i2').value.get() == meta.config('meta.conf2').option('od1.i2').value.get() == 1
assert meta.option('od1.i2').owner.get() is meta.config('meta').option('od1.i2').owner.get() is meta.config('meta.conf1').option('od1.i2').owner.get() is meta.config('meta.conf2').option('od1.i2').owner.get() is owners.default
await conf1.option('od1.i2').value.reset()
assert await meta.option('od1.i2').value.get() == await meta1.option('od1.i2').value.get() == await conf1.option('od1.i2').value.get() == await conf2.option('od1.i2').value.get() == 1
assert await meta.option('od1.i2').owner.get() is await meta1.option('od1.i2').owner.get() is await conf1.option('od1.i2').owner.get() is await conf2.option('od1.i2').owner.get() is owners.default
await delete_sessions(meta)
def test_meta_new_config():
@pytest.mark.asyncio
async def test_meta_new_config():
od = make_description()
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
assert len(list(meta.config.list())) == 2
meta.config.new('newconf1')
assert len(list(meta.config.list())) == 3
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
assert len(list(await meta.config.list())) == 2
await meta.config.new('newconf1')
assert len(list(await meta.config.list())) == 3
await delete_sessions(meta)
def test_meta_new_config_owner():
@pytest.mark.asyncio
async def test_meta_new_config_owner():
od = make_description()
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
meta.owner.set('meta')
meta.config.new('newconf1')
assert meta.owner.get() == 'meta'
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
await meta.owner.set('meta')
await meta.config.new('newconf1')
assert await meta.owner.get() == 'meta'
await delete_sessions(meta)
def test_meta_new_metaconfig():
@pytest.mark.asyncio
async def test_meta_new_metaconfig():
od = make_description()
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
meta.config.new('newconf1', type='metaconfig')
meta.config('newconf1').config.new('newconf2', type='metaconfig')
meta.config('newconf1').config('newconf2').config.new('newconf3')
assert meta.config('newconf1').config('newconf2').config('newconf3').config.name() == 'newconf3'
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
await meta.config.new('newconf1', type='metaconfig')
newconf1 = await meta.config('newconf1')
await newconf1.config.new('newconf2', type='metaconfig')
newconf2 = await newconf1.config('newconf2')
await newconf2.config.new('newconf3')
newconf3 = await newconf2.config('newconf3')
assert await newconf3.session.id() == 'newconf3'
await delete_sessions(meta)
def test_meta_pop_config():
@pytest.mark.asyncio
async def test_meta_pop_config():
od = make_description()
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
meta.option('od1.i1').value.set(2)
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
await meta.option('od1.i1').value.set(2)
#
assert len(list(meta.config.list())) == 2
meta.config.new('newconf1')
assert meta.config('newconf1').value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
assert len(list(await meta.config.list())) == 2
await meta.config.new('newconf1')
newconf1 = await meta.config('newconf1')
assert await newconf1.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
#
assert len(list(meta.config.list())) == 3
newconf1 = meta.config.pop('newconf1')
assert len(list(await meta.config.list())) == 3
newconf1 = await meta.config.pop('newconf1')
try:
assert meta.config('newconf1').value.dict()
await meta.config('newconf1')
except ConfigError:
pass
else:
raise Exception('must raise')
assert newconf1.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
assert await newconf1.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
#
assert len(list(meta.config.list())) == 2
raises(ConfigError, "meta.config.pop('newconf1')")
assert len(list(await meta.config.list())) == 2
with pytest.raises(ConfigError):
await meta.config.pop('newconf1')
await delete_sessions([meta, newconf1])
def test_meta_add_config():
@pytest.mark.asyncio
async def test_meta_add_config():
od = make_description()
od2 = make_description()
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
meta.option('od1.i1').value.set(2)
meta = await MetaConfig(['name1', 'name2'], optiondescription=od, delete_old_session=True)
await meta.option('od1.i1').value.set(2)
#
assert len(list(meta.config.list())) == 2
config = Config(od, session_id='new')
assert config.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
meta.config.add(config)
assert len(list(await meta.config.list())) == 2
config = await Config(od, session_id='new', delete_old_session=True)
assert await config.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
await meta.config.add(config)
#
assert len(list(meta.config.list())) == 3
assert config.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
assert len(list(await meta.config.list())) == 3
assert await config.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
#
raises(ConflictError, "meta.config.add(config)")
raises(ValueError, "meta.config.add(Config(od2))")
with pytest.raises(ConflictError):
await meta.config.add(config)
newconfig = await Config(od2)
with pytest.raises(ValueError):
await meta.config.add(newconfig)
await delete_sessions([meta, newconfig])
def test_meta_add_config_readd():
@pytest.mark.asyncio
async def test_meta_add_config_readd():
od = make_description()
meta = MetaConfig([], optiondescription=od)
meta2 = MetaConfig([], optiondescription=od)
config = Config(od, session_id='new')
meta = await MetaConfig([], optiondescription=od)
meta2 = await MetaConfig([], optiondescription=od)
config = await Config(od, session_id='new')
#
meta.config.add(config)
#
raises(ConflictError, "meta2.config.add(config)")
await meta.config.add(config)
await meta2.config.add(config)
assert len(list(await config.config.parents())) == 2
await delete_sessions([meta, meta2])
def test_meta_new_config_wrong_name():
@pytest.mark.asyncio
async def test_meta_new_config_wrong_name():
od = make_description()
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
assert len(list(meta.config.list())) == 2
raises(ConflictError, "meta.config.new('name1')")
assert len(list(meta.config.list())) == 2
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
assert len(list(await meta.config.list())) == 2
with pytest.raises(ConflictError):
await meta.config.new('name1')
assert len(list(await meta.config.list())) == 2
await delete_sessions(meta)
def test_meta_meta_set():
meta = make_metaconfig(double=True)
errors1 = meta.value.set('od1.i1', 7, only_config=True)
errors2 = meta.value.set('od1.i6', 7, only_config=True)
@pytest.mark.asyncio
async def test_meta_load_config():
od = make_description()
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
assert len(list(await meta.config.list())) == 2
await meta.config.load('name1')
assert len(list(await meta.config.list())) == 3
await delete_sessions(meta)
@pytest.mark.asyncio
async def test_meta_load_config_wrong_name():
od = make_description()
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
assert len(list(await meta.config.list())) == 2
with pytest.raises(ConfigError):
await meta.config.load('name3')
assert len(list(await meta.config.list())) == 2
await delete_sessions(meta)
@pytest.mark.asyncio
async def test_meta_meta_set():
meta = await make_metaconfig(double=True)
errors1 = await meta.value.set('od1.i1', 7, only_config=True)
errors2 = await meta.value.set('od1.i6', 7, only_config=True)
assert len(errors1) == 0
assert len(errors2) == 2
conf1 = meta.config('meta.conf1')._config_bag.context
conf2 = meta.config('meta.conf2')._config_bag.context
assert meta.config('meta.conf1').option('od1.i1').value.get() == meta.config('meta.conf2').option('od1.i1').value.get() == 7
conf1 = await meta.config('meta.conf1')
conf2 = await meta.config('meta.conf2')
assert await conf1.option('od1.i1').value.get() == await conf2.option('od1.i1').value.get() == 7
#
dconfigs = []
for conf in meta.config.find('i1', value=7).config.list():
ret = await meta.config.find('i1', value=7)
for conf in await ret.config.list():
dconfigs.append(conf._config_bag.context)
assert [conf1, conf2] == dconfigs
meta.config('meta.conf1').option('od1.i1').value.set(8)
assert [conf1._config_bag.context, conf2._config_bag.context] == dconfigs
await conf1.option('od1.i1').value.set(8)
#
dconfigs = []
for conf in meta.config.find('i1').config.list():
ret = await meta.config.find('i1')
for conf in await ret.config.list():
dconfigs.append(conf._config_bag.context)
assert [conf1, conf2] == dconfigs
assert conf2 == list(meta.config.find('i1', value=7).config.list())[0]._config_bag.context
assert conf1 == list(meta.config.find('i1', value=8).config.list())[0]._config_bag.context
assert [conf1._config_bag.context, conf2._config_bag.context] == dconfigs
ret = await meta.config.find('i1', value=7)
assert len(await ret.config.list()) == 1
assert conf2._config_bag.context == list(await ret.config.list())[0]._config_bag.context
ret = await meta.config.find('i1', value=8)
assert len(await ret.config.list()) == 1
assert conf1._config_bag.context == list(await ret.config.list())[0]._config_bag.context
#
dconfigs = []
for conf in meta.config.find('i5', value=2).config.list():
ret = await meta.config.find('i5', value=2)
for conf in await ret.config.list():
dconfigs.append(conf._config_bag.context)
assert [conf1, conf2] == dconfigs
assert [conf1._config_bag.context, conf2._config_bag.context] == dconfigs
#
raises(AttributeError, "meta.config.find('i1', value=10)")
raises(AttributeError, "meta.config.find('not', value=10)")
raises(AttributeError, "meta.config.find('i6')")
raises(ValueError, "meta.value.set('od1.i6', 7, only_config=True, force_default=True)")
raises(ValueError, "meta.value.set('od1.i6', 7, only_config=True, force_default_if_same=True)")
raises(ValueError, "meta.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True)")
with pytest.raises(AttributeError):
await meta.config.find('i1', value=10)
with pytest.raises(AttributeError):
await meta.config.find('not', value=10)
with pytest.raises(AttributeError):
await meta.config.find('i6')
with pytest.raises(ValueError):
await meta.value.set('od1.i6', 7, only_config=True, force_default=True)
with pytest.raises(ValueError):
await meta.value.set('od1.i6', 7, only_config=True, force_default_if_same=True)
with pytest.raises(ValueError):
await meta.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True)
await delete_sessions(meta)
def test_not_meta():
@pytest.mark.asyncio
async def test_not_meta():
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, session_id='conf1')
conf2 = Config(od2, session_id='conf2')
conf3 = Config(od2)
conf4 = Config(od2, session_id='conf4')
raises(TypeError, "GroupConfig(conf1)")
conf1 = await Config(od2, session_id='conf1')
conf2 = await Config(od2, session_id='conf2')
conf3 = await Config(od2)
conf4 = await Config(od2, session_id='conf4')
with pytest.raises(TypeError):
await GroupConfig(conf1)
#same name
#raises(ConflictError, "GroupConfig([conf2, conf4], session_id='conf2')")
raises(ConflictError, "GroupConfig([conf2, conf2], session_id='conf8')")
grp = GroupConfig([conf1, conf2])
raises(APIError, "grp.option('od1.i1').value.get()")
conf1, conf2 = grp.config.list()
errors = grp.value.set('od1.i1', 7)
#with pytest.raises(ConflictError):
# GroupConfig([conf2, conf4], session_id='conf2')")
with pytest.raises(ConflictError):
await GroupConfig([conf2, conf2], session_id='conf8')
grp = await GroupConfig([conf1, conf2])
with pytest.raises(APIError):
await grp.option('od1.i1').value.get()
conf1, conf2 = await grp.config.list()
errors = await grp.value.set('od1.i1', 7)
assert len(errors) == 0
assert grp.config('conf1').option('od1.i1').value.get() == grp.config('conf2').option('od1.i1').value.get() == 7
assert grp.config('conf1').option('od1.i1').owner.get() is grp.config('conf2').option('od1.i1').owner.get() is owners.user
grp.option('od1.i1').value.reset()
assert grp.config('conf1').option('od1.i1').owner.get() is grp.config('conf2').option('od1.i1').owner.get() is owners.default
conf1 = await grp.config('conf1')
conf2 = await grp.config('conf2')
assert await conf1.option('od1.i1').value.get() == await conf2.option('od1.i1').value.get() == 7
assert await conf1.option('od1.i1').owner.get() is await conf2.option('od1.i1').owner.get() is owners.user
await grp.option('od1.i1').value.reset()
assert await conf1.option('od1.i1').owner.get() is await conf2.option('od1.i1').owner.get() is owners.default
await delete_sessions([conf1, conf2, conf3, conf4])
def test_group_find_firsts():
@pytest.mark.asyncio
async def test_group_find_firsts():
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, session_id='conf1')
conf2 = Config(od2, session_id='conf2')
grp = GroupConfig([conf1, conf2])
itr = grp.config.find('i1').config.list()
conf1._config_bag.context == next(itr)._config_bag.context
conf2._config_bag.context == next(itr)._config_bag.context
try:
next(itr)
except StopIteration:
pass
except:
raise Exception('no')
else:
raise Exception('no')
conf1 = await Config(od2, session_id='conf1')
conf2 = await Config(od2, session_id='conf2')
grp = await GroupConfig([conf1, conf2])
ret = await grp.config.find('i1')
newconf1, newconf2 = await grp.config.list()
conf1._config_bag.context == newconf1._config_bag.context
conf2._config_bag.context == newconf2._config_bag.context
await delete_sessions([conf1, conf2])
def test_group_group():
@pytest.mark.asyncio
async def test_group_group():
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, session_id='conf9')
conf2 = Config(od2, session_id='conf10')
grp = GroupConfig([conf1, conf2], 'grp')
grp2 = GroupConfig([grp])
errors = grp2.value.set('od1.i1', 2)
conf1 = await Config(od2, session_id='conf9')
conf2 = await Config(od2, session_id='conf10')
grp = await GroupConfig([conf1, conf2], 'grp')
grp2 = await GroupConfig([grp])
errors = await grp2.value.set('od1.i1', 2)
assert len(errors) == 0
assert grp2.config('grp.conf9').option('od1.i1').value.get() == 2
assert grp2.config('grp.conf9').option('od1.i1').owner.get() is owners.user
conf9 = await grp2.config('grp.conf9')
assert await conf9.option('od1.i1').value.get() == 2
assert await conf9.option('od1.i1').owner.get() is owners.user
await delete_sessions([conf1, conf2, conf9])
def test_group_group_path():
@pytest.mark.asyncio
async def test_group_group_path():
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, session_id='conf9')
conf2 = Config(od2, session_id='conf10')
grp = GroupConfig([conf1, conf2], 'grp')
grp2 = GroupConfig([grp], 'grp2')
assert grp2.config.path() == 'grp2'
assert grp2.config('grp').config.path() == 'grp'
assert grp2.config('grp.conf9').config.path() == 'conf9'
assert grp2.config('grp.conf10').config.path() == 'conf10'
conf1 = await Config(od2, session_id='conf9')
conf2 = await Config(od2, session_id='conf10')
grp = await GroupConfig([conf1, conf2], 'grp')
grp2 = await GroupConfig([grp], 'grp2')
assert await grp2.config.path() == 'grp2'
newgrp = await grp2.config('grp')
assert await newgrp.config.path() == 'grp'
newgrp = await grp2.config('grp.conf9')
assert await newgrp.config.path() == 'conf9'
newgrp = await grp2.config('grp.conf10')
assert await newgrp.config.path() == 'conf10'
await delete_sessions([conf1, conf2])
def test_meta_unconsistent():
@pytest.mark.asyncio
async def test_meta_unconsistent():
i1 = IntOption('i1', '')
i2 = IntOption('i2', '', default=1)
i3 = IntOption('i3', '')
@ -419,588 +523,753 @@ def test_meta_unconsistent():
od2 = OptionDescription('od2', '', [od1])
i5 = IntOption('i5', '')
od3 = OptionDescription('od3', '', [i5])
conf1 = Config(od2, session_id='conf1')
conf2 = Config(od2, session_id='conf2')
conf3 = Config(od2, session_id='conf3')
conf4 = Config(od3, session_id='conf4')
meta = MetaConfig([conf1, conf2])
meta.owner.set(owners.meta1)
raises(TypeError, 'MetaConfig("string")')
conf1 = await Config(od2, session_id='conf1')
conf2 = await Config(od2, session_id='conf2')
conf3 = await Config(od2, session_id='conf3')
conf4 = await Config(od3, session_id='conf4')
meta = await MetaConfig([conf1, conf2])
await meta.owner.set(owners.meta1)
with pytest.raises(TypeError):
await MetaConfig("string")
#same descr but conf1 already in meta
raises(ValueError, "MetaConfig([conf1, conf3])")
assert len(list(await conf1.config.parents())) == 1
assert len(list(await conf3.config.parents())) == 0
new_meta = await MetaConfig([conf1, conf3])
assert len(list(await conf1.config.parents())) == 2
assert len(list(await conf3.config.parents())) == 1
#not same descr
raises(ValueError, "MetaConfig([conf3, conf4])")
with pytest.raises(ValueError):
await MetaConfig([conf3, conf4])
await delete_sessions([meta, new_meta, conf4])
def test_meta_leadership():
@pytest.mark.asyncio
async def test_meta_leadership():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
meta.property.read_only()
itr = meta.config.find('ip_admin_eth0').config.list()
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
itr = meta.config.find('netmask_admin_eth0').config.list()
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
meta.property.read_write()
raises(AttributeError, "meta.config.find('netmask_admin_eth0')")
itr = meta.unrestraint.config.find('netmask_admin_eth0').config.list()
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
meta.property.read_only()
itr = meta.config.find('netmask_admin_eth0').config.list()
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2])
await meta.property.read_only()
ret = await meta.config.find('ip_admin_eth0')
configs = await ret.config.list()
assert len(configs) == 2
assert conf1._config_bag.context == configs[0]._config_bag.context
assert conf2._config_bag.context == configs[1]._config_bag.context
ret = await meta.config.find('netmask_admin_eth0')
configs = await ret.config.list()
assert len(configs) == 2
assert conf1._config_bag.context == configs[0]._config_bag.context
assert conf2._config_bag.context == configs[1]._config_bag.context
await meta.property.read_write()
with pytest.raises(AttributeError):
await meta.config.find('netmask_admin_eth0')
ret = await meta.unrestraint.config.find('netmask_admin_eth0')
configs = await ret.config.list()
assert conf1._config_bag.context == configs[0]._config_bag.context
assert conf2._config_bag.context == configs[1]._config_bag.context
await meta.property.read_only()
ret = await meta.config.find('netmask_admin_eth0')
configs = await ret.config.list()
assert conf1._config_bag.context == configs[0]._config_bag.context
assert conf2._config_bag.context == configs[1]._config_bag.context
await delete_sessions(meta)
def test_meta_leadership_value2():
@pytest.mark.asyncio
async def test_meta_leadership_value():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2], session_id="meta")
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8'])
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#FIXME devrait raise ! assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0', 0).value.get() == None
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2], session_id="meta")
await conf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8'])
assert await conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
with pytest.raises(APIError):
await conf1.option('ip_admin_eth0.ip_admin_eth0', 0).value.get()
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset()
await conf1.option('ip_admin_eth0.ip_admin_eth0').value.reset()
#
meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
await meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert await conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
await meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert await conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await conf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
#
await meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.2.1', '192.168.3.1'])
await meta.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.0')
#
assert await conf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await conf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
await delete_sessions(meta)
def test_meta_leadership_value_default():
@pytest.mark.asyncio
async def test_meta_leadership_value_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2])
newconf1 = await meta.config('conf1')
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#
meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
await meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
#
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
await meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
await delete_sessions(meta)
def test_meta_leadership_owners():
@pytest.mark.asyncio
async def test_meta_leadership_owners():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
meta.owner.set(owners.meta1)
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
raises(LeadershipError, "meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()")
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2])
await meta.owner.set(owners.meta1)
newconf1 = await meta.config('conf1')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
with pytest.raises(LeadershipError):
await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
#
meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
await meta.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
#
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1
await meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1
#
meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1
await meta.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.meta1
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
assert meta.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.meta1
await delete_sessions(meta)
def test_meta_force_default():
@pytest.mark.asyncio
async def test_meta_force_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
meta.property.read_write()
meta.owner.set('meta1')
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2])
await meta.property.read_write()
await meta.owner.set('meta1')
newconf1 = await meta.config('conf1')
newconf2 = await meta.config('conf2')
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
errors = await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
#
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3'])
errors = await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3'])
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
#
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True)
errors = await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True)
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
await delete_sessions(meta)
def test_meta_force_dont_change_value():
@pytest.mark.asyncio
async def test_meta_force_dont_change_value():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
meta.property.read_write()
meta.owner.set('meta1')
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True)
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2])
await meta.property.read_write()
await meta.owner.set('meta1')
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
newconf1 = await meta.config('conf1')
newconf2 = await meta.config('conf2')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True)
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
await delete_sessions(meta)
def test_meta_force_default_if_same():
@pytest.mark.asyncio
async def test_meta_force_default_if_same():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
meta.property.read_write()
meta.owner.set('meta1')
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2])
await meta.property.read_write()
await meta.owner.set('meta1')
#
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
newconf1 = await meta.config('conf1')
newconf2 = await meta.config('conf2')
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True)
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True)
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True)
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
errors = await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True)
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
await delete_sessions(meta)
def test_meta_force_default_if_same_and_dont_change():
@pytest.mark.asyncio
async def test_meta_force_default_if_same_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
meta.property.read_write()
meta.owner.set('meta1')
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2])
await meta.property.read_write()
await meta.owner.set('meta1')
#
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
newconf1 = await meta.config('conf1')
newconf2 = await meta.config('conf2')
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True)
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True)
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.meta1
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
#
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True)
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
errors = await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True)
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
await delete_sessions(meta)
def test_meta_force_default_and_dont_change():
@pytest.mark.asyncio
async def test_meta_force_default_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='rconf1')
conf2 = Config(od, session_id='rconf2')
meta = MetaConfig([conf1, conf2])
meta.property.read_write()
meta.owner.set('meta1')
raises(ValueError, "meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True)")
conf1 = await Config(od, session_id='rconf1')
conf2 = await Config(od, session_id='rconf2')
meta = await MetaConfig([conf1, conf2])
await meta.property.read_write()
await meta.owner.set('meta1')
with pytest.raises(ValueError):
await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True)
await delete_sessions(meta)
def test_meta_properties_meta():
@pytest.mark.asyncio
async def test_meta_properties_meta():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',))
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
conf1.property.read_write()
conf2.property.read_write()
meta = MetaConfig([conf1, conf2])
meta.property.read_write()
assert meta.config('conf1').value.dict() == {}
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
await conf1.property.read_write()
await conf2.property.read_write()
meta = await MetaConfig([conf1, conf2])
await meta.property.read_write()
ret = await meta.config('conf1')
assert await ret.value.dict() == {}
await delete_sessions(meta)
def test_meta_exception_meta():
@pytest.mark.asyncio
async def test_meta_exception_meta():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, callback=raise_exception)
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", Calculation(raise_exception), multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
meta.property.read_write()
raises(Exception, "conf1.make_dict()")
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2])
await meta.property.read_write()
with pytest.raises(Exception):
await conf1.make_dict()
await delete_sessions(meta)
def test_meta_properties_requires_mandatory():
@pytest.mark.asyncio
async def test_meta_properties_requires1():
opt1 = BoolOption('opt1', 'opt1', False)
opt2 = BoolOption('opt2', "")
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(opt1, todict=True),
'expected': ParamValue(False)}))
od2 = OptionDescription('od2', "", [opt2], properties=(disabled_property,))
opt3 = BoolOption('opt3', '', validators=[Calculation(valid_not_equal, Params((ParamOption(opt2), ParamSelfOption())))])
od = OptionDescription('root', '', [opt1, od2, opt3])
conf1 = await Config(od, session_id='conf1')
await conf1.property.read_write()
meta = await MetaConfig([conf1], 'meta')
await meta.property.read_write()
await meta.option('opt1').value.set(True)
#
await conf1.option('od2.opt2').value.set(False)
await delete_sessions(meta)
@pytest.mark.asyncio
async def test_meta_properties_requires_mandatory():
probes = BoolOption('probes', 'probes available', False)
eth0_method = ChoiceOption('eth0_method', '', ('static', 'dhcp'), 'static')
ip_address = IPOption('ip_address', '')
ip_eth0 = IPOption('ip_eth0', "ip", requires=({'option': probes, 'expected': True, 'action': 'mandatory'},), callback=return_condition, callback_params=Params(kwargs={'val': ParamOption(ip_address), 'condition': ParamOption(eth0_method), 'expected': ParamValue('dhcp')}))
ip_gw = IPOption('ip_gw', 'gw')
ip_gw.impl_add_consistency('not_equal', ip_eth0)
mandatory_property = Calculation(calc_value,
Params(ParamValue('mandatory'),
kwargs={'condition': ParamOption(probes),
'expected': ParamValue('yes'),
'default': ParamValue(None)}))
ip_eth0 = IPOption('ip_eth0', "ip", Calculation(return_condition, Params(kwargs={'val': ParamOption(ip_address), 'condition': ParamOption(eth0_method), 'expected': ParamValue('dhcp')})), properties=(mandatory_property,))
ip_gw = IPOption('ip_gw', 'gw', validators=[Calculation(valid_not_equal, Params((ParamOption(ip_eth0), ParamSelfOption())))])
od = OptionDescription('root', '', [ip_gw, probes, eth0_method, ip_address, ip_eth0])
conf1 = Config(od, session_id='conf1')
conf1.property.read_write()
meta = MetaConfig([conf1], 'meta')
conf1 = await Config(od, session_id='conf1')
await conf1.property.read_write()
meta = await MetaConfig([conf1], 'meta')
#
meta.option('probes').value.set(True)
meta.option('ip_address').value.set('1.1.1.1')
meta.option('ip_gw').value.set('1.1.1.2')
conf1.option('eth0_method').value.set('dhcp')
conf1.property.read_only()
assert conf1.value.dict(fullpath=True) == {'probes': True, 'eth0_method': 'dhcp', 'ip_address': '1.1.1.1', 'ip_eth0': '1.1.1.1', 'ip_gw': '1.1.1.2'}
await meta.option('probes').value.set(True)
await meta.option('ip_address').value.set('1.1.1.1')
await meta.option('ip_gw').value.set('1.1.1.2')
await conf1.option('eth0_method').value.set('dhcp')
await conf1.property.read_only()
assert await conf1.value.dict(fullpath=True) == {'probes': True, 'eth0_method': 'dhcp', 'ip_address': '1.1.1.1', 'ip_eth0': '1.1.1.1', 'ip_gw': '1.1.1.2'}
await delete_sessions(meta)
def test_meta_callback():
@pytest.mark.asyncio
async def test_meta_callback():
val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamValue('yes')))
val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val5 = StrOption('val5', "", callback=return_value, callback_params=Params(kwargs={'value': ParamValue('yes')}))
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))))
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes'))))
val4 = StrOption('val4', "", Calculation(return_value, Params(kwargs={'value': ParamOption(val1)})))
val5 = StrOption('val5', "", Calculation(return_value, Params(kwargs={'value': ParamValue('yes')})))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
cfg = Config(maconfig, session_id='cfg')
meta = MetaConfig([cfg])
meta.property.read_write()
assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
meta.config('cfg').option('val1').value.set('new')
assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
meta.config('cfg').option('val1').value.reset()
meta.option('val1').value.set('new')
assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
meta.config('cfg').option('val4').value.set('new1')
assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
meta.config('cfg').option('val4').value.reset()
meta.option('val4').value.set('new1')
assert meta.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
meta.option('val4').value.reset()
cfg = await Config(maconfig, session_id='cfg')
meta = await MetaConfig([cfg])
await meta.property.read_write()
newcfg = await meta.config('cfg')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
await newcfg.option('val1').value.set('new')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
await newcfg.option('val1').value.reset()
await meta.option('val1').value.set('new')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
await newcfg.option('val4').value.set('new1')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
await newcfg.option('val4').value.reset()
await meta.option('val4').value.set('new1')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
await meta.option('val4').value.reset()
await delete_sessions(meta)
def test_meta_callback_follower():
@pytest.mark.asyncio
async def test_meta_callback_follower():
val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val)))
val3 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
val4 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
val1 = StrOption('val1', "", [Calculation(return_value, Params(ParamOption(val)))], multi=True)
val3 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))), multi=True)
val4 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val1))), multi=True)
interface1 = Leadership('val1', '', [val1, val3, val4])
od = OptionDescription('root', '', [interface1])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
cfg = Config(maconfig, session_id='cfg1')
meta = MetaConfig([cfg])
meta.property.read_write()
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.config('cfg1').option('val').value.set('val1')
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
meta.config('cfg1').option('val').value.reset()
meta.option('val').value.set('val1')
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
meta.option('val').value.reset()
meta.config('cfg1').option('val1.val2', 0).value.set('val2')
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.config('cfg1').option('val1.val2', 0).value.reset()
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.option('val1.val2', 0).value.set('val2')
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.config('cfg1').option('val1.val3', 0).value.set('val6')
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
meta.option('val1.val2', 0).value.reset()
meta.config('cfg1').option('val1.val3', 0).value.reset()
meta.config('cfg1').option('val1.val1').value.set(['val3'])
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.config('cfg1').option('val1.val1').value.reset()
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
meta.option('val1.val1').value.set(['val3'])
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.config('cfg1').option('val1.val2', 0).value.set('val2')
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
meta.option('val1.val1').value.set(['val3', 'rah'])
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
meta.option('val1.val1').value.pop(1)
meta.option('val1.val1').value.set(['val4'])
assert meta.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'}
conf1 = await Config(maconfig, session_id='conf1')
meta = await MetaConfig([conf1])
await meta.property.read_write()
assert await conf1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await conf1.option('val').value.set('val1')
assert await conf1.value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
#
await conf1.option('val').value.reset()
await meta.option('val').value.set('val1')
assert await conf1.value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
#
await meta.option('val').value.reset()
await conf1.option('val1.val2', 0).value.set('val2')
assert await conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await conf1.option('val1.val2', 0).value.reset()
assert await conf1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await meta.option('val1.val2', 0).value.set('val2')
assert await conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await meta.option('val1.val1').value.set(['val'])
assert await conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await conf1.option('val1.val3', 0).value.set('val6')
assert await conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
#
await meta.option('val1.val2', 0).value.reset()
await conf1.option('val1.val3', 0).value.reset()
await conf1.option('val1.val1').value.set(['val3'])
assert await conf1.value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
#
await conf1.option('val1.val1').value.reset()
assert await conf1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await meta.option('val1.val1').value.set(['val3'])
assert await conf1.value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
#
await conf1.option('val1.val2', 0).value.set('val2')
assert await conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
#
await meta.option('val1.val1').value.set(['val3', 'rah'])
assert await conf1.value.dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
#
await meta.option('val1.val1').value.pop(1)
await meta.option('val1.val1').value.set(['val4'])
assert await conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'}
await delete_sessions(meta)
def test_meta_reset():
@pytest.mark.asyncio
async def test_meta_reset():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
meta = MetaConfig([conf1, conf2])
meta.property.read_write()
meta.owner.set('meta1')
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
meta = await MetaConfig([conf1, conf2])
await meta.property.read_write()
await meta.owner.set('meta1')
newconf1 = await meta.config('conf1')
newconf2 = await meta.config('conf2')
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
errors = await meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
meta.value.reset('ip_admin_eth0.ip_admin_eth0')
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
await meta.value.reset('ip_admin_eth0.ip_admin_eth0')
assert await meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
await delete_sessions(meta)
def test_meta_properties_meta_copy():
@pytest.mark.asyncio
async def test_meta_properties_meta_copy():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface1, session_id='conf1')
conf2 = Config(interface1, session_id='conf2')
conf1.property.read_write()
conf2.property.read_write()
meta = MetaConfig([conf1, conf2], session_id='meta1')
meta.property.read_write()
conf1 = await Config(interface1, session_id='conf1')
conf2 = await Config(interface1, session_id='conf2')
await conf1.property.read_write()
await conf2.property.read_write()
meta = await MetaConfig([conf1, conf2], session_id='meta1')
await meta.property.read_write()
conf3 = meta.config('conf1').config.copy(session_id='conf3')
meta2 = conf3.config.metaconfig()
assert meta.config.name() == meta2.config.name()
newconf1 = await meta.config('conf1')
newconf2 = await meta.config('conf2')
conf3 = await newconf1.config.copy(session_id='conf3')
# old fashion
meta2 = await conf3.config.metaconfig()
assert await meta.session.id() == await meta2.session.id()
# new method
meta2 = list(await conf3.config.parents())
assert len(meta2) == 1
assert await meta.session.id() == await meta2[0].session.id()
assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert meta.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
meta.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert meta.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
ret = meta.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert meta.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
newconf3 = await meta.config('conf3')
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await meta.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
ret = await meta.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
await delete_sessions(meta)
def test_meta_properties_meta_deepcopy():
@pytest.mark.asyncio
async def test_meta_properties_meta_deepcopy():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
properties=('disabled',))
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface1, session_id='conf1')
conf2 = Config(interface1, session_id='conf2')
conf1.property.read_write()
conf2.property.read_write()
meta = MetaConfig([conf1, conf2])
meta.permissive.set(frozenset({'hidden'}))
meta.property.read_write()
conf1 = await Config(interface1, session_id='conf1')
conf2 = await Config(interface1, session_id='conf2')
await conf1.property.read_write()
await conf2.property.read_write()
meta = await MetaConfig([conf1, conf2])
await meta.permissive.add('hidden')
await meta.property.read_write()
meta2 = meta.config('conf1').config.deepcopy(session_id='conf3')
newconf1 = await meta.config('conf1')
newconf2 = await meta.config('conf2')
meta2 = await newconf1.config.deepcopy(session_id='conf3')
newconf3 = await meta2.config('conf3')
assert meta != meta2
assert meta.permissive.get() == meta2.permissive.get()
assert await meta.permissive.get() == await meta2.permissive.get()
assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert meta2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
meta.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert meta2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
meta.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert meta2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await meta.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await meta.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await delete_sessions([meta, meta2])
def test_meta_properties_submeta_deepcopy():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
properties=('disabled',))
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface1, session_id='conf1')
conf1.property.read_write()
meta1 = MetaConfig([conf1], session_id='meta1')
meta2 = MetaConfig([meta1], session_id='meta2')
meta_copy = conf1.config.deepcopy(session_id='conf2',
metaconfig_prefix='copy_')
assert meta_copy.config.name() == 'copy_meta2'
assert meta_copy.config('copy_meta1').config.name() == 'copy_meta1'
assert meta_copy.config('copy_meta1').config('conf2').config.name() == 'conf2'
def test_meta_properties_deepcopy_meta():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
properties=('disabled',))
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface1, session_id='conf1')
conf1.property.read_write()
meta1 = MetaConfig([conf1], session_id='meta1')
meta2 = MetaConfig([meta1], session_id='meta2')
meta_copy = meta1.config.deepcopy(session_id='meta3',
metaconfig_prefix='copy_')
assert meta_copy.config.name() == 'copy_meta2'
assert meta_copy.config('meta3').config.name() == 'meta3'
assert list(meta_copy.config('meta3').config.list()) == []
def test_meta_properties_submeta_deepcopy_owner():
@pytest.mark.asyncio
async def test_meta_properties_meta_deepcopy_multi_parent():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip")
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask")
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface1, session_id='conf1')
conf1.owner.set('conf1_user')
conf1.property.read_write()
meta1 = MetaConfig([conf1], session_id='meta1')
meta1.owner.set('meta1_user')
meta2 = MetaConfig([meta1], session_id='meta2')
meta2.owner.set('meta2_user')
conf1 = await Config(interface1, session_id='conf1')
conf2 = await Config(interface1, session_id='conf2')
await conf1.property.read_write()
await conf2.property.read_write()
meta1 = await MetaConfig([conf1, conf2], session_id='meta1')
await meta1.permissive.add('hidden')
await meta1.property.read_write()
meta2 = await MetaConfig(['name1', 'name2'], optiondescription=interface1, session_id='meta2')
await meta2.config.add(conf1)
await meta1.option('ip_admin_eth0').value.set('192.168.1.1')
await meta2.option('netmask_admin_eth0').value.set('255.255.255.0')
assert await meta1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': None}
assert await meta2.value.dict() == {'ip_admin_eth0': None, 'netmask_admin_eth0': '255.255.255.0'}
assert await conf1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': '255.255.255.0'}
assert await conf2.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': None}
copy_meta2 = await conf1.config.deepcopy(session_id='copy_conf1', metaconfig_prefix='copy_')
assert await copy_meta2.config.path() == 'copy_meta2'
copy_meta1 = await copy_meta2.config('copy_meta1')
copy_conf1 = await copy_meta1.config('copy_conf1')
assert await copy_meta2.value.dict() == {'ip_admin_eth0': None, 'netmask_admin_eth0': '255.255.255.0'}
assert await copy_conf1.value.dict() == {'ip_admin_eth0': '192.168.1.1', 'netmask_admin_eth0': '255.255.255.0'}
await delete_sessions([conf1, conf2, meta1, meta2, copy_conf1, copy_meta1, copy_meta2])
@pytest.mark.asyncio
async def test_meta_properties_submeta_deepcopy():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
properties=('disabled',))
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = await Config(interface1, session_id='conf1')
await conf1.property.read_write()
meta1 = await MetaConfig([conf1], session_id='meta1')
meta2 = await MetaConfig([meta1], session_id='meta2')
meta_copy = await conf1.config.deepcopy(session_id='conf2',
metaconfig_prefix='copy_')
assert await meta_copy.session.id() == 'copy_meta2'
newcopy = await meta_copy.config('copy_meta1')
assert await newcopy.session.id() == 'copy_meta1'
newcopy = await newcopy.config('conf2')
assert await newcopy.session.id() == 'conf2'
await delete_sessions([meta2, meta_copy])
@pytest.mark.asyncio
async def test_meta_properties_deepcopy_meta():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
properties=('disabled',))
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = await Config(interface1, session_id='conf1')
await conf1.property.read_write()
meta1 = await MetaConfig([conf1], session_id='meta1')
meta2 = await MetaConfig([meta1], session_id='meta2')
meta_copy = await meta1.config.deepcopy(session_id='meta3',
metaconfig_prefix='copy_')
assert await meta_copy.session.id() == 'copy_meta2'
newcopy = await meta_copy.config('meta3')
assert await newcopy.session.id() == 'meta3'
assert list(await newcopy.config.list()) == []
await delete_sessions([meta2, meta_copy])
@pytest.mark.asyncio
async def test_meta_properties_submeta_deepcopy_owner():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip")
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask")
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = await Config(interface1, session_id='conf1')
await conf1.owner.set('conf1_user')
await conf1.property.read_write()
meta1 = await MetaConfig([conf1], session_id='meta1')
await meta1.owner.set('meta1_user')
meta2 = await MetaConfig([meta1], session_id='meta2')
await meta2.owner.set('meta2_user')
#
conf1.option('ip_admin_eth0').value.set('192.168.0.1')
assert conf1.option('ip_admin_eth0').owner.get() == 'conf1_user'
meta1.option('ip_admin_eth0').value.set('192.168.0.2')
assert meta1.option('ip_admin_eth0').owner.get() == 'meta1_user'
meta2.option('ip_admin_eth0').value.set('192.168.0.3')
assert meta2.option('ip_admin_eth0').owner.get() == 'meta2_user'
await conf1.option('ip_admin_eth0').value.set('192.168.0.1')
assert await conf1.option('ip_admin_eth0').owner.get() == 'conf1_user'
await meta1.option('ip_admin_eth0').value.set('192.168.0.2')
assert await meta1.option('ip_admin_eth0').owner.get() == 'meta1_user'
await meta2.option('ip_admin_eth0').value.set('192.168.0.3')
assert await meta2.option('ip_admin_eth0').owner.get() == 'meta2_user'
#
meta2_copy = conf1.config.deepcopy(session_id='conf2',
meta2_copy = await conf1.config.deepcopy(session_id='conf2',
metaconfig_prefix='copy_')
meta2_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
assert meta2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3'
assert meta2_copy.option('ip_admin_eth0').owner.get() == 'meta2_user'
assert meta2_copy.option('netmask_admin_eth0').owner.get() == 'meta2_user'
await meta2_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
assert await meta2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3'
assert await meta2_copy.option('ip_admin_eth0').owner.get() == 'meta2_user'
assert await meta2_copy.option('netmask_admin_eth0').owner.get() == 'meta2_user'
#
meta1_copy = meta2_copy.config('copy_meta1')
meta1_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
assert meta1_copy.option('ip_admin_eth0').value.get() == '192.168.0.2'
assert meta1_copy.option('ip_admin_eth0').owner.get() == 'meta1_user'
assert meta1_copy.option('netmask_admin_eth0').owner.get() == 'meta1_user'
meta1_copy = await meta2_copy.config('copy_meta1')
await meta1_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
assert await meta1_copy.option('ip_admin_eth0').value.get() == '192.168.0.2'
assert await meta1_copy.option('ip_admin_eth0').owner.get() == 'meta1_user'
assert await meta1_copy.option('netmask_admin_eth0').owner.get() == 'meta1_user'
#
conf2 = meta1_copy.config('conf2')
conf2.owner.set('conf2_user')
conf2.option('netmask_admin_eth0').value.set('255.255.255.255')
assert conf2.option('netmask_admin_eth0').owner.get() == 'conf2_user'
assert conf2.option('ip_admin_eth0').value.get() == '192.168.0.1'
assert conf2.option('ip_admin_eth0').owner.get() == 'conf1_user'
conf2 = await meta1_copy.config('conf2')
await conf2.owner.set('conf2_user')
await conf2.option('netmask_admin_eth0').value.set('255.255.255.255')
assert await conf2.option('netmask_admin_eth0').owner.get() == 'conf2_user'
assert await conf2.option('ip_admin_eth0').value.get() == '192.168.0.1'
assert await conf2.option('ip_admin_eth0').owner.get() == 'conf1_user'
await delete_sessions([meta1, meta2, conf2, meta2_copy])
def test_meta_properties_meta_set_value():
@pytest.mark.asyncio
async def test_meta_properties_meta_set_value():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface1, session_id='conf1')
conf2 = Config(interface1, session_id='conf2')
conf1.property.read_write()
conf2.property.read_write()
meta = MetaConfig([conf1, conf2])
meta.property.read_write()
assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True)
conf1 = await Config(interface1, session_id='conf1')
conf2 = await Config(interface1, session_id='conf2')
await conf1.property.read_write()
await conf2.property.read_write()
meta = await MetaConfig([conf1, conf2])
await meta.property.read_write()
ret = await meta.config('conf1')
assert await ret.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
ret = await meta.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True)
assert len(ret) == 2
assert isinstance(ret[0], PropertiesOptionError)
assert isinstance(ret[1], PropertiesOptionError)
del ret[1]
del ret[0]
del ret
ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True)
ret = await meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True)
assert len(ret) == 1
assert isinstance(ret[0], PropertiesOptionError)
del ret[0]
del ret
ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True)
ret = await meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True)
assert len(ret) == 3
assert isinstance(ret[0], PropertiesOptionError)
assert isinstance(ret[1], PropertiesOptionError)
@ -1009,143 +1278,151 @@ def test_meta_properties_meta_set_value():
del ret[1]
del ret[0]
del ret
ret = meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True)
ret = await meta.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True)
assert len(ret) == 1
assert isinstance(ret[0], PropertiesOptionError)
del ret[0]
del ret
ret = meta.value.set('ip_admin_eth0', '255.255.255.255', only_config=True)
ret = await meta.value.set('ip_admin_eth0', '255.255.255.255', only_config=True)
assert len(ret) == 2
assert isinstance(ret[0], ValueError)
assert isinstance(ret[1], ValueError)
del ret[1]
del ret[0]
del ret
ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_default=True)
ret = await meta.value.set('ip_admin_eth0', '255.255.255.255', force_default=True)
assert len(ret) == 1
assert isinstance(ret[0], ValueError)
del ret[0]
del ret
ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True)
ret = await meta.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True)
assert len(ret) == 1
assert isinstance(ret[0], ValueError)
del ret[0]
del ret
ret = meta.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True)
ret = await meta.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True)
assert len(ret) == 1
assert isinstance(ret[0], ValueError)
del ret[0]
del ret
await delete_sessions(meta)
def test_metaconfig_force_metaconfig_on_freeze():
@pytest.mark.asyncio
async def test_metaconfig_force_metaconfig_on_freeze():
dummy1 = StrOption('dummy1', 'doc dummy', default='default', properties=('force_metaconfig_on_freeze',))
group = OptionDescription('group', '', [dummy1])
config = Config(group, session_id='config')
config.owner.set(owners.config)
meta1 = MetaConfig([config], session_id='meta1')
meta1.owner.set(owners.meta1)
meta2 = MetaConfig([meta1], session_id='meta2')
meta2.owner.set(owners.meta2)
config.property.read_write()
cfg = await Config(group, session_id='cfg')
await cfg.owner.set(owners.config)
meta1 = await MetaConfig([cfg], session_id='meta1')
await meta1.owner.set(owners.meta1)
meta2 = await MetaConfig([meta1], session_id='meta2')
await meta2.owner.set(owners.meta2)
await cfg.property.read_write()
config.option('dummy1').property.add('frozen')
await cfg.option('dummy1').property.add('frozen')
#
assert config.option('dummy1').value.get() == 'default'
assert config.option('dummy1').owner.get() == 'default'
assert await cfg.option('dummy1').value.get() == 'default'
assert await cfg.option('dummy1').owner.get() == 'default'
#
meta2.option('dummy1').value.set('meta2')
await meta2.option('dummy1').value.set('meta2')
#
assert config.option('dummy1').value.get() == 'meta2'
assert config.option('dummy1').owner.get() == 'meta2'
assert await cfg.option('dummy1').value.get() == 'meta2'
assert await cfg.option('dummy1').owner.get() == 'meta2'
#
config.option('dummy1').property.pop('frozen')
config.option('dummy1').value.set('config')
config.option('dummy1').property.add('frozen')
await cfg.option('dummy1').property.pop('frozen')
await cfg.option('dummy1').value.set('cfg')
await cfg.option('dummy1').property.add('frozen')
#
assert config.option('dummy1').value.get() == 'meta2'
assert config.option('dummy1').owner.get() == 'meta2'
assert await cfg.option('dummy1').value.get() == 'meta2'
assert await cfg.option('dummy1').owner.get() == 'meta2'
#
meta1.option('dummy1').value.set('meta1')
await meta1.option('dummy1').value.set('meta1')
#
assert config.option('dummy1').value.get() == 'meta1'
assert config.option('dummy1').owner.get() == 'meta1'
assert await cfg.option('dummy1').value.get() == 'meta1'
assert await cfg.option('dummy1').owner.get() == 'meta1'
#
config.option('dummy1').property.pop('frozen')
assert config.option('dummy1').value.get() == 'config'
assert config.option('dummy1').owner.get() == 'config'
await cfg.option('dummy1').property.pop('frozen')
assert await cfg.option('dummy1').value.get() == 'cfg'
assert await cfg.option('dummy1').owner.get() == 'config'
await delete_sessions([meta1, meta2])
def test_metaconfig_force_metaconfig_on_freeze_option():
@pytest.mark.asyncio
async def test_metaconfig_force_metaconfig_on_freeze_option():
dummy1 = StrOption('dummy1', 'doc dummy', default='default')
dummy2 = StrOption('dummy2', 'doc dummy', default='default', properties=('force_default_on_freeze',))
group = OptionDescription('group', '', [dummy1, dummy2])
config = Config(group, session_id='config')
config.owner.set(owners.config)
meta1 = MetaConfig([config], session_id='meta1')
meta1.owner.set(owners.meta1)
meta2 = MetaConfig([meta1], session_id='meta2')
meta2.owner.set(owners.meta2)
config.property.read_write()
cfg = await Config(group, session_id='cfg')
await cfg.owner.set(owners.config)
meta1 = await MetaConfig([cfg], session_id='meta1')
await meta1.owner.set(owners.meta1)
meta2 = await MetaConfig([meta1], session_id='meta2')
await meta2.owner.set(owners.meta2)
await cfg.property.read_write()
config.option('dummy1').property.add('frozen')
config.option('dummy1').property.add('force_metaconfig_on_freeze')
config.option('dummy2').property.add('frozen')
await cfg.option('dummy1').property.add('frozen')
await cfg.option('dummy1').property.add('force_metaconfig_on_freeze')
await cfg.option('dummy2').property.add('frozen')
#
assert config.option('dummy1').value.get() == 'default'
assert config.option('dummy1').owner.get() == 'default'
assert config.option('dummy2').value.get() == 'default'
assert config.option('dummy2').owner.get() == 'default'
assert await cfg.option('dummy1').value.get() == 'default'
assert await cfg.option('dummy1').owner.get() == 'default'
assert await cfg.option('dummy2').value.get() == 'default'
assert await cfg.option('dummy2').owner.get() == 'default'
#
meta2.option('dummy1').value.set('meta2')
meta2.option('dummy2').value.set('meta2')
await meta2.option('dummy1').value.set('meta2')
await meta2.option('dummy2').value.set('meta2')
#
assert config.option('dummy1').value.get() == 'meta2'
assert config.option('dummy1').owner.get() == 'meta2'
assert config.option('dummy2').value.get() == 'default'
assert config.option('dummy2').owner.get() == 'default'
assert await cfg.option('dummy1').value.get() == 'meta2'
assert await cfg.option('dummy1').owner.get() == 'meta2'
assert await cfg.option('dummy2').value.get() == 'default'
assert await cfg.option('dummy2').owner.get() == 'default'
#
config.option('dummy1').property.pop('frozen')
config.option('dummy2').property.pop('frozen')
config.option('dummy1').value.set('config')
config.option('dummy2').value.set('config')
config.option('dummy1').property.add('frozen')
config.option('dummy2').property.add('frozen')
await cfg.option('dummy1').property.pop('frozen')
await cfg.option('dummy2').property.pop('frozen')
await cfg.option('dummy1').value.set('cfg')
await cfg.option('dummy2').value.set('cfg')
await cfg.option('dummy1').property.add('frozen')
await cfg.option('dummy2').property.add('frozen')
#
assert config.option('dummy1').value.get() == 'meta2'
assert config.option('dummy1').owner.get() == 'meta2'
assert config.option('dummy2').value.get() == 'default'
assert config.option('dummy2').owner.get() == 'default'
assert await cfg.option('dummy1').value.get() == 'meta2'
assert await cfg.option('dummy1').owner.get() == 'meta2'
assert await cfg.option('dummy2').value.get() == 'default'
assert await cfg.option('dummy2').owner.get() == 'default'
#
meta1.option('dummy1').value.set('meta1')
meta1.option('dummy2').value.set('meta1')
await meta1.option('dummy1').value.set('meta1')
await meta1.option('dummy2').value.set('meta1')
#
assert config.option('dummy1').value.get() == 'meta1'
assert config.option('dummy1').owner.get() == 'meta1'
assert config.option('dummy2').value.get() == 'default'
assert config.option('dummy2').owner.get() == 'default'
assert await cfg.option('dummy1').value.get() == 'meta1'
assert await cfg.option('dummy1').owner.get() == 'meta1'
assert await cfg.option('dummy2').value.get() == 'default'
assert await cfg.option('dummy2').owner.get() == 'default'
#
meta1.option('dummy1').property.add('force_metaconfig_on_freeze')
assert config.option('dummy1').value.get() == 'meta2'
assert config.option('dummy1').owner.get() == 'meta2'
await meta1.option('dummy1').property.add('force_metaconfig_on_freeze')
assert await cfg.option('dummy1').value.get() == 'meta2'
assert await cfg.option('dummy1').owner.get() == 'meta2'
#
meta2.option('dummy1').property.add('force_metaconfig_on_freeze')
assert config.option('dummy1').value.get() == 'default'
assert config.option('dummy1').owner.get() == 'default'
await meta2.option('dummy1').property.add('force_metaconfig_on_freeze')
assert await cfg.option('dummy1').value.get() == 'default'
assert await cfg.option('dummy1').owner.get() == 'default'
#
meta1.option('dummy1').property.pop('force_metaconfig_on_freeze')
assert config.option('dummy1').value.get() == 'meta1'
assert config.option('dummy1').owner.get() == 'meta1'
await meta1.option('dummy1').property.pop('force_metaconfig_on_freeze')
assert await cfg.option('dummy1').value.get() == 'meta1'
assert await cfg.option('dummy1').owner.get() == 'meta1'
#
config.option('dummy1').property.pop('frozen')
assert config.option('dummy1').value.get() == 'config'
assert config.option('dummy1').owner.get() == 'config'
await cfg.option('dummy1').property.pop('frozen')
assert await cfg.option('dummy1').value.get() == 'cfg'
assert await cfg.option('dummy1').owner.get() == 'config'
await delete_sessions([meta1, meta2])
def test_meta_get_config():
@pytest.mark.asyncio
async def test_meta_get_config():
od = make_description()
meta = MetaConfig(['name1', 'name2'], optiondescription=od)
meta.config.new('meta1', type='metaconfig')
assert isinstance(meta.config.get('meta1'), MetaConfig)
assert isinstance(meta.config.get('name1'), Config)
raises(ConfigError, "meta.config.get('unknown')")
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
await meta.config.new('meta1', type='metaconfig')
assert isinstance(await meta.config.get('meta1'), MetaConfig)
assert isinstance(await meta.config.get('name1'), Config)
with pytest.raises(ConfigError):
await meta.config.get('unknown')
await delete_sessions(meta)

View File

@ -1,23 +1,21 @@
from .autopath import do_autopath
do_autopath()
from py.test import raises
import pytest
from tiramisu.setting import groups, owners
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \
OptionDescription, Leadership, Config, GroupConfig, MixConfig, \
MetaConfig, Params, ParamOption, ParamValue
MetaConfig, Params, ParamOption, ParamValue, ParamSelfOption, Calculation, \
valid_network_netmask, delete_session
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError, APIError
from tiramisu.storage import list_sessions
from .config import delete_sessions, event_loop
owners.addowner('mix1')
owners.addowner('mix2')
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def return_value(value=None):
return value
@ -74,221 +72,277 @@ def make_description3():
return od2
def make_mixconfig(double=False):
async def make_mixconfig(double=False):
od1 = make_description()
od2 = make_description1()
od3 = make_description2()
conf1 = Config(od1, session_id='conf1')
conf2 = Config(od2, session_id='conf2')
mix = MixConfig(od3, [conf1, conf2], session_id='mix')
conf1 = await Config(od1, session_id='conf1', delete_old_session=True)
await conf1.property.read_write()
conf2 = await Config(od2, session_id='conf2', delete_old_session=True)
await conf2.property.read_write()
mix = await MixConfig(od3, [conf1, conf2], session_id='mix', delete_old_session=True)
if double:
od4 = make_description3()
mix.owner.set(owners.mix2)
mix = MixConfig(od4, [mix], session_id='doublemix')
mix.property.read_write()
mix.owner.set(owners.mix1)
await mix.owner.set(owners.mix2)
mix = await MixConfig(od4, [mix], session_id='doublemix')
await mix.property.read_write()
await mix.owner.set(owners.mix1)
return mix
def test_mix_name():
mix = make_mixconfig(True)
assert mix.config.path() == 'doublemix'
assert mix.config('mix').config.path() == 'doublemix.mix'
assert mix.config('mix.conf1').config.path() == 'doublemix.mix.conf1'
assert mix.config('mix.conf2').config.path() == 'doublemix.mix.conf2'
@pytest.mark.asyncio
async def test_mix_name():
mix = await make_mixconfig(True)
assert await mix.config.path() == 'doublemix'
ret = await mix.config('mix')
assert await ret.config.path() == 'doublemix.mix'
ret = await mix.config('mix.conf1')
assert await ret.config.path() == 'doublemix.mix.conf1'
ret = await mix.config('mix.conf2')
assert await ret.config.path() == 'doublemix.mix.conf2'
await delete_sessions(mix)
def test_mix_not_group():
@pytest.mark.asyncio
async def test_mix_not_group():
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, session_id='conf1')
grp = GroupConfig([conf1])
raises(TypeError, "MixConfig(od2, [grp])")
async with await Config(od2, session_id='conf1') as conf1:
grp = await GroupConfig([conf1])
with pytest.raises(TypeError):
await MixConfig(od2, [grp], session_id='error')
await delete_session('error')
assert not await list_sessions()
def test_unknown_config():
mix = make_mixconfig()
raises(ConfigError, "mix.config('unknown')")
@pytest.mark.asyncio
async def test_unknown_config():
mix = await make_mixconfig()
with pytest.raises(ConfigError):
await mix.config('unknown')
await delete_sessions(mix)
def test_none():
mix = make_mixconfig()
assert mix.option('od1.i3').value.get() is mix.config('conf1').option('od1.i3').value.get() is mix.config('conf2').option('od1.i3').value.get() is None
assert mix.option('od1.i3').owner.get() is mix.config('conf1').option('od1.i3').owner.get() is mix.config('conf2').option('od1.i3').owner.get() is owners.default
@pytest.mark.asyncio
async def test_none():
mix = await make_mixconfig()
newconf1 = await mix.config('conf1')
newconf2 = await mix.config('conf2')
assert await mix.option('od1.i3').value.get() is await newconf1.option('od1.i3').value.get() is await newconf2.option('od1.i3').value.get() is None
assert await mix.option('od1.i3').owner.get() is await newconf1.option('od1.i3').owner.get() is await newconf2.option('od1.i3').owner.get() is owners.default
#
mix.option('od1.i3').value.set(3)
assert mix.option('od1.i3').value.get() == mix.config('conf1').option('od1.i3').value.get() == mix.config('conf2').option('od1.i3').value.get() == 3
assert mix.option('od1.i3').owner.get() is mix.config('conf1').option('od1.i3').owner.get() is mix.config('conf2').option('od1.i3').owner.get() is owners.mix1
await mix.option('od1.i3').value.set(3)
assert await mix.option('od1.i3').value.get() == await newconf1.option('od1.i3').value.get() == await newconf2.option('od1.i3').value.get() == 3
assert await mix.option('od1.i3').owner.get() is await newconf1.option('od1.i3').owner.get() is await newconf2.option('od1.i3').owner.get() is owners.mix1
#
mix.config('conf1').option('od1.i3').value.set(2)
assert mix.option('od1.i3').value.get() == mix.config('conf2').option('od1.i3').value.get() == 3
assert mix.config('conf1').option('od1.i3').value.get() == 2
assert mix.option('od1.i3').owner.get() is mix.config('conf2').option('od1.i3').owner.get() is owners.mix1
assert mix.config('conf1').option('od1.i3').owner.get() is owners.user
await newconf1.option('od1.i3').value.set(2)
assert await mix.option('od1.i3').value.get() == await newconf2.option('od1.i3').value.get() == 3
assert await newconf1.option('od1.i3').value.get() == 2
assert await mix.option('od1.i3').owner.get() is await newconf2.option('od1.i3').owner.get() is owners.mix1
assert await newconf1.option('od1.i3').owner.get() is owners.user
#
mix.option('od1.i3').value.set(4)
assert mix.option('od1.i3').value.get() == mix.config('conf2').option('od1.i3').value.get() == 4
assert mix.config('conf1').option('od1.i3').value.get() == 2
assert mix.option('od1.i3').owner.get() is mix.config('conf2').option('od1.i3').owner.get() is owners.mix1
assert mix.config('conf1').option('od1.i3').owner.get() is owners.user
await mix.option('od1.i3').value.set(4)
assert await mix.option('od1.i3').value.get() == await newconf2.option('od1.i3').value.get() == 4
assert await newconf1.option('od1.i3').value.get() == 2
assert await mix.option('od1.i3').owner.get() is await newconf2.option('od1.i3').owner.get() is owners.mix1
assert await newconf1.option('od1.i3').owner.get() is owners.user
#
mix.option('od1.i3').value.reset()
assert mix.option('od1.i3').value.get() is mix.config('conf2').option('od1.i3').value.get() is None
assert mix.config('conf1').option('od1.i3').value.get() == 2
assert mix.option('od1.i3').owner.get() is mix.config('conf2').option('od1.i3').owner.get() is owners.default
assert mix.config('conf1').option('od1.i3').owner.get() is owners.user
await mix.option('od1.i3').value.reset()
assert await mix.option('od1.i3').value.get() is await newconf2.option('od1.i3').value.get() is None
assert await newconf1.option('od1.i3').value.get() == 2
assert await mix.option('od1.i3').owner.get() is await newconf2.option('od1.i3').owner.get() is owners.default
assert await newconf1.option('od1.i3').owner.get() is owners.user
#
mix.config('conf1').option('od1.i3').value.reset()
assert mix.option('od1.i3').value.get() is mix.config('conf1').option('od1.i3').value.get() is mix.config('conf2').option('od1.i3').value.get() is None
assert mix.option('od1.i3').owner.get() is mix.config('conf1').option('od1.i3').owner.get() is mix.config('conf2').option('od1.i3').owner.get() is owners.default
await newconf1.option('od1.i3').value.reset()
assert await mix.option('od1.i3').value.get() is await newconf1.option('od1.i3').value.get() is await newconf2.option('od1.i3').value.get() is None
assert await mix.option('od1.i3').owner.get() is await newconf1.option('od1.i3').owner.get() is await newconf2.option('od1.i3').owner.get() is owners.default
#
assert mix.config(None).config.name() == mix.config.name()
assert await mix.session.id() == await mix.session.id()
await delete_sessions(mix)
def test_reset():
mix = make_mixconfig()
assert mix.option('od1.i2').value.get() == 1
mix.option('od1.i2').value.set(2)
mix.config('conf1').option('od1.i2').value.set(3)
assert mix.option('od1.i2').value.get() == 2
assert mix.config('conf1').option('od1.i2').value.get() == 3
assert mix.config('conf2').option('od1.i2').value.get() == 2
mix.config.reset()
assert mix.option('od1.i2').value.get() == 1
assert mix.config('conf1').option('od1.i2').value.get() == 3
assert mix.config('conf2').option('od1.i2').value.get() == 1
@pytest.mark.asyncio
async def test_reset():
mix = await make_mixconfig()
assert await mix.option('od1.i2').value.get() == 1
await mix.option('od1.i2').value.set(2)
newconf1 = await mix.config('conf1')
newconf2 = await mix.config('conf2')
await newconf1.option('od1.i2').value.set(3)
assert await mix.option('od1.i2').value.get() == 2
assert await newconf1.option('od1.i2').value.get() == 3
assert await newconf2.option('od1.i2').value.get() == 2
await mix.config.reset()
assert await mix.option('od1.i2').value.get() == 1
assert await newconf1.option('od1.i2').value.get() == 3
assert await newconf2.option('od1.i2').value.get() == 1
await delete_sessions(mix)
def test_default():
mix = make_mixconfig()
assert mix.option('od1.i2').value.get() == mix.config('conf1').option('od1.i2').value.get() == mix.config('conf2').option('od1.i2').value.get() == 1
assert mix.option('od1.i2').owner.get() is mix.config('conf1').option('od1.i2').owner.get() is mix.config('conf2').option('od1.i2').owner.get() is owners.default
@pytest.mark.asyncio
async def test_default():
mix = await make_mixconfig()
newconf1 = await mix.config('conf1')
newconf2 = await mix.config('conf2')
assert await mix.option('od1.i2').value.get() == await newconf1.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 1
assert await mix.option('od1.i2').owner.get() is await newconf1.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.default
#
mix.option('od1.i2').value.set(3)
assert mix.option('od1.i2').value.get() == mix.config('conf1').option('od1.i2').value.get() == mix.config('conf2').option('od1.i2').value.get() == 3
assert mix.option('od1.i2').owner.get() is mix.config('conf1').option('od1.i2').owner.get() is mix.config('conf2').option('od1.i2').owner.get() is owners.mix1
await mix.option('od1.i2').value.set(3)
assert await mix.option('od1.i2').value.get() == await newconf1.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 3
assert await mix.option('od1.i2').owner.get() is await newconf1.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.mix1
#
mix.config('conf1').option('od1.i2').value.set(2)
assert mix.option('od1.i2').value.get() == mix.config('conf2').option('od1.i2').value.get() == 3
assert mix.config('conf1').option('od1.i2').value.get() == 2
assert mix.option('od1.i2').owner.get() is mix.config('conf2').option('od1.i2').owner.get() is owners.mix1
assert mix.config('conf1').option('od1.i2').owner.get() is owners.user
await newconf1.option('od1.i2').value.set(2)
assert await mix.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 3
assert await newconf1.option('od1.i2').value.get() == 2
assert await mix.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.mix1
assert await newconf1.option('od1.i2').owner.get() is owners.user
#
mix.option('od1.i2').value.set(4)
assert mix.option('od1.i2').value.get() == mix.config('conf2').option('od1.i2').value.get() == 4
assert mix.config('conf1').option('od1.i2').value.get() == 2
assert mix.option('od1.i2').owner.get() is mix.config('conf2').option('od1.i2').owner.get() is owners.mix1
assert mix.config('conf1').option('od1.i2').owner.get() is owners.user
await mix.option('od1.i2').value.set(4)
assert await mix.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 4
assert await newconf1.option('od1.i2').value.get() == 2
assert await mix.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.mix1
assert await newconf1.option('od1.i2').owner.get() is owners.user
#
mix.option('od1.i2').value.reset()
assert mix.option('od1.i2').value.get() == mix.config('conf2').option('od1.i2').value.get() == 1
assert mix.config('conf1').option('od1.i2').value.get() == 2
assert mix.option('od1.i2').owner.get() is mix.config('conf2').option('od1.i2').owner.get() is owners.default
assert mix.config('conf1').option('od1.i2').owner.get() is owners.user
await mix.option('od1.i2').value.reset()
assert await mix.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 1
assert await newconf1.option('od1.i2').value.get() == 2
assert await mix.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.default
assert await newconf1.option('od1.i2').owner.get() is owners.user
#
mix.config('conf1').option('od1.i2').value.reset()
assert mix.option('od1.i2').value.get() == mix.config('conf1').option('od1.i2').value.get() == mix.config('conf2').option('od1.i2').value.get() == 1
assert mix.option('od1.i2').owner.get() is mix.config('conf1').option('od1.i2').owner.get() is mix.config('conf2').option('od1.i2').owner.get() is owners.default
await newconf1.option('od1.i2').value.reset()
assert await mix.option('od1.i2').value.get() == await newconf1.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 1
assert await mix.option('od1.i2').owner.get() is await newconf1.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.default
await delete_sessions(mix)
def test_contexts():
mix = make_mixconfig()
errors = mix.value.set('od1.i2', 6, only_config=True)
assert mix.option('od1.i2').value.get() == 1
assert mix.option('od1.i2').owner.get() == owners.default
assert mix.config('conf1').option('od1.i2').value.get() == mix.config('conf1').option('od1.i2').value.get() == 6
assert mix.config('conf1').option('od1.i2').owner.get() == mix.config('conf1').option('od1.i2').owner.get() is owners.user
@pytest.mark.asyncio
async def test_contexts():
mix = await make_mixconfig()
errors = await mix.value.set('od1.i2', 6, only_config=True)
newconf1 = await mix.config('conf1')
assert await mix.option('od1.i2').value.get() == 1
assert await mix.option('od1.i2').owner.get() == owners.default
assert await newconf1.option('od1.i2').value.get() == await newconf1.option('od1.i2').value.get() == 6
assert await newconf1.option('od1.i2').owner.get() == await newconf1.option('od1.i2').owner.get() is owners.user
assert len(errors) == 0
await delete_sessions(mix)
def test_find():
mix = make_mixconfig()
ret = list(mix.option.find('i2'))
@pytest.mark.asyncio
async def test_find():
mix = await make_mixconfig()
ret = list(await mix.option.find('i2'))
assert len(ret) == 1
assert 1 == ret[0].value.get()
assert 1 == mix.option.find('i2', first=True).value.get()
assert mix.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
assert 1 == await ret[0].value.get()
ret = await mix.option.find('i2', first=True)
assert 1 == await ret.value.get()
assert await mix.value.dict() == {'od1.i4': 2, 'od1.i1': None, 'od1.i3': None,
'od1.i2': 1, 'od1.i5': [2]}
await delete_sessions(mix)
def test_mix_mix():
mix = make_mixconfig(double=True)
assert mix.option('od1.i2').value.get() == mix.config('mix').option('od1.i2').value.get() == mix.config('mix.conf1').option('od1.i2').value.get() == mix.config('mix.conf2').option('od1.i2').value.get() == 1
assert mix.option('od1.i2').owner.get() is mix.config('mix').option('od1.i2').owner.get() is mix.config('mix.conf1').option('od1.i2').owner.get() is mix.config('mix.conf2').option('od1.i2').owner.get() is owners.default
@pytest.mark.asyncio
async def test_mix_mix():
mix = await make_mixconfig(double=True)
newmix = await mix.config('mix')
newconf1 = await mix.config('mix.conf1')
newconf2 = await mix.config('mix.conf2')
assert await mix.option('od1.i2').value.get() == await newmix.option('od1.i2').value.get() == await newconf1.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 1
assert await mix.option('od1.i2').owner.get() is await newmix.option('od1.i2').owner.get() is await newconf1.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.default
#
mix.option('od1.i2').value.set(3)
assert mix.option('od1.i2').value.get() == mix.config('mix').option('od1.i2').value.get() == mix.config('mix.conf1').option('od1.i2').value.get() == mix.config('mix.conf2').option('od1.i2').value.get() == 3
assert mix.option('od1.i2').owner.get() is mix.config('mix').option('od1.i2').owner.get() is mix.config('mix.conf1').option('od1.i2').owner.get() is mix.config('mix.conf2').option('od1.i2').owner.get() is owners.mix1
await mix.option('od1.i2').value.set(3)
assert await mix.option('od1.i2').value.get() == await newmix.option('od1.i2').value.get() == await newconf1.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 3
assert await mix.option('od1.i2').owner.get() is await newmix.option('od1.i2').owner.get() is await newconf1.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.mix1
#
mix.config('mix.conf1').option('od1.i2').value.set(2)
assert mix.option('od1.i2').value.get() == mix.config('mix').option('od1.i2').value.get() == mix.config('mix.conf2').option('od1.i2').value.get() == 3
assert mix.config('mix.conf1').option('od1.i2').value.get() == 2
assert mix.option('od1.i2').owner.get() is mix.config('mix').option('od1.i2').owner.get() is mix.config('mix.conf2').option('od1.i2').owner.get() is owners.mix1
assert mix.config('mix.conf1').option('od1.i2').owner.get() is owners.user
await newconf1.option('od1.i2').value.set(2)
assert await mix.option('od1.i2').value.get() == await newmix.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 3
assert await newconf1.option('od1.i2').value.get() == 2
assert await mix.option('od1.i2').owner.get() is await newmix.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.mix1
assert await newconf1.option('od1.i2').owner.get() is owners.user
#
mix.config('mix').option('od1.i2').value.set(4)
assert mix.option('od1.i2').value.get() == 3
assert mix.config('mix').option('od1.i2').value.get() == mix.config('mix.conf2').option('od1.i2').value.get() == 4
assert mix.config('mix.conf1').option('od1.i2').value.get() == 2
assert mix.option('od1.i2').owner.get() is owners.mix1
assert mix.config('mix').option('od1.i2').owner.get() is mix.config('mix.conf2').option('od1.i2').owner.get() is owners.mix2
assert mix.config('mix.conf1').option('od1.i2').owner.get() is owners.user
await newmix.option('od1.i2').value.set(4)
assert await mix.option('od1.i2').value.get() == 3
assert await newmix.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 4
assert await newconf1.option('od1.i2').value.get() == 2
assert await mix.option('od1.i2').owner.get() is owners.mix1
assert await newmix.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.mix2
assert await newconf1.option('od1.i2').owner.get() is owners.user
#
mix.config('mix').option('od1.i2').value.reset()
assert mix.option('od1.i2').value.get() == mix.config('mix').option('od1.i2').value.get() == mix.config('mix.conf2').option('od1.i2').value.get() == 3
assert mix.config('mix.conf1').option('od1.i2').value.get() == 2
assert mix.option('od1.i2').owner.get() is mix.config('mix').option('od1.i2').owner.get() is mix.config('mix.conf2').option('od1.i2').owner.get() is owners.mix1
assert mix.config('mix.conf1').option('od1.i2').owner.get() is owners.user
await newmix.option('od1.i2').value.reset()
assert await mix.option('od1.i2').value.get() == await newmix.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 3
assert await newconf1.option('od1.i2').value.get() == 2
assert await mix.option('od1.i2').owner.get() is await newmix.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.mix1
assert await newconf1.option('od1.i2').owner.get() is owners.user
#
mix.option('od1.i2').value.reset()
assert mix.option('od1.i2').value.get() == mix.config('mix').option('od1.i2').value.get() == mix.config('mix.conf2').option('od1.i2').value.get() == 1
assert mix.config('mix.conf1').option('od1.i2').value.get() == 2
assert mix.option('od1.i2').owner.get() is mix.config('mix').option('od1.i2').owner.get() is mix.config('mix.conf2').option('od1.i2').owner.get() is owners.default
assert mix.config('mix.conf1').option('od1.i2').owner.get() is owners.user
await mix.option('od1.i2').value.reset()
assert await mix.option('od1.i2').value.get() == await newmix.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 1
assert await newconf1.option('od1.i2').value.get() == 2
assert await mix.option('od1.i2').owner.get() is await newmix.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.default
assert await newconf1.option('od1.i2').owner.get() is owners.user
#
mix.config('mix.conf1').option('od1.i2').value.reset()
assert mix.option('od1.i2').value.get() == mix.config('mix').option('od1.i2').value.get() == mix.config('mix.conf1').option('od1.i2').value.get() == mix.config('mix.conf2').option('od1.i2').value.get() == 1
assert mix.option('od1.i2').owner.get() is mix.config('mix').option('od1.i2').owner.get() is mix.config('mix.conf1').option('od1.i2').owner.get() is mix.config('mix.conf2').option('od1.i2').owner.get() is owners.default
await newconf1.option('od1.i2').value.reset()
assert await mix.option('od1.i2').value.get() == await newmix.option('od1.i2').value.get() == await newconf1.option('od1.i2').value.get() == await newconf2.option('od1.i2').value.get() == 1
assert await mix.option('od1.i2').owner.get() is await newmix.option('od1.i2').owner.get() is await newconf1.option('od1.i2').owner.get() is await newconf2.option('od1.i2').owner.get() is owners.default
await delete_sessions(mix)
def test_mix_mix_set():
mix = make_mixconfig(double=True)
errors1 = mix.value.set('od1.i1', 7, only_config=True)
errors2 = mix.value.set('od1.i6', 7, only_config=True)
@pytest.mark.asyncio
async def test_mix_mix_set():
mix = await make_mixconfig(double=True)
errors1 = await mix.value.set('od1.i1', 7, only_config=True)
errors2 = await mix.value.set('od1.i6', 7, only_config=True)
assert len(errors1) == 0
assert len(errors2) == 2
conf1 = mix.config('mix.conf1')._config_bag.context
conf2 = mix.config('mix.conf2')._config_bag.context
assert mix.config('mix.conf1').option('od1.i1').value.get() == mix.config('mix.conf2').option('od1.i1').value.get() == 7
ret = await mix.config('mix.conf1')
conf1 = ret._config_bag.context
ret = await mix.config('mix.conf2')
conf2 = ret._config_bag.context
newconf1 = await mix.config('mix.conf1')
newconf2 = await mix.config('mix.conf2')
assert await newconf1.option('od1.i1').value.get() == await newconf2.option('od1.i1').value.get() == 7
#
dconfigs = []
for conf in mix.config.find('i1', value=7).config.list():
ret = await mix.config.find('i1', value=7)
for conf in await ret.config.list():
dconfigs.append(conf._config_bag.context)
assert [conf1, conf2] == dconfigs
mix.config('mix.conf1').option('od1.i1').value.set(8)
await newconf1.option('od1.i1').value.set(8)
#
dconfigs = []
for conf in mix.config.find('i1').config.list():
ret = await mix.config.find('i1')
for conf in await ret.config.list():
dconfigs.append(conf._config_bag.context)
assert [conf1, conf2] == dconfigs
assert conf2 == list(mix.config.find('i1', value=7).config.list())[0]._config_bag.context
assert conf1 == list(mix.config.find('i1', value=8).config.list())[0]._config_bag.context
ret = await mix.config.find('i1', value=7)
assert conf2 == list(await ret.config.list())[0]._config_bag.context
ret = await mix.config.find('i1', value=8)
assert conf1 == list(await ret.config.list())[0]._config_bag.context
#
dconfigs = []
for conf in mix.config.find('i5', value=2).config.list():
ret = await mix.config.find('i5', value=2)
for conf in await ret.config.list():
dconfigs.append(conf._config_bag.context)
assert [conf1, conf2] == dconfigs
#
raises(AttributeError, "mix.config.find('i1', value=10)")
raises(AttributeError, "mix.config.find('not', value=10)")
raises(AttributeError, "mix.config.find('i6')")
raises(ValueError, "mix.value.set('od1.i6', 7, only_config=True, force_default=True)")
raises(ValueError, "mix.value.set('od1.i6', 7, only_config=True, force_default_if_same=True)")
raises(ValueError, "mix.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True)")
with pytest.raises(AttributeError):
await mix.config.find('i1', value=10)
with pytest.raises(AttributeError):
await mix.config.find('not', value=10)
with pytest.raises(AttributeError):
await mix.config.find('i6')
with pytest.raises(ValueError):
await mix.value.set('od1.i6', 7, only_config=True, force_default=True)
with pytest.raises(ValueError):
await mix.value.set('od1.i6', 7, only_config=True, force_default_if_same=True)
with pytest.raises(ValueError):
await mix.value.set('od1.i6', 7, only_config=True, force_dont_change_value=True)
await delete_sessions(mix)
def test_mix_unconsistent():
@pytest.mark.asyncio
async def test_mix_unconsistent():
i1 = IntOption('i1', '')
i2 = IntOption('i2', '', default=1)
i3 = IntOption('i3', '')
@ -296,389 +350,464 @@ def test_mix_unconsistent():
od1 = OptionDescription('od1', '', [i1, i2, i3, i4])
od2 = OptionDescription('od2', '', [od1])
od3 = OptionDescription('od3', '', [od1])
conf1 = Config(od2, session_id='conf1')
conf2 = Config(od2, session_id='conf2')
conf3 = Config(od2, session_id='conf3')
conf1 = await Config(od2, session_id='conf1')
conf2 = await Config(od2, session_id='conf2')
conf3 = await Config(od2, session_id='conf3')
i5 = IntOption('i5', '')
od4 = OptionDescription('od4', '', [i5])
conf4 = Config(od4, session_id='conf4')
mix = MixConfig(od2, [conf1, conf2])
mix.owner.set(owners.mix1)
raises(TypeError, 'MixConfig(od2, "string")')
conf4 = await Config(od4, session_id='conf4')
mix = await MixConfig(od2, [conf1, conf2])
await mix.owner.set(owners.mix1)
with pytest.raises(TypeError):
await MixConfig(od2, "string", session_id='error')
await delete_session('error')
# same descr but conf1 already in mix
raises(ValueError, "MixConfig(od2, [conf1, conf3])")
assert len(list(await conf1.config.parents())) == 1
assert len(list(await conf3.config.parents())) == 0
new_mix = await MixConfig(od2, [conf1, conf3])
assert len(list(await conf1.config.parents())) == 2
assert len(list(await conf3.config.parents())) == 1
# not same descr
MixConfig(od2, [conf3, conf4])
tmix = await MixConfig(od2, [conf3, conf4])
await delete_sessions([mix, conf3, conf4, tmix, new_mix])
def test_mix_leadership():
@pytest.mark.asyncio
async def test_mix_leadership():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2])
mix.property.read_only()
itr = mix.config.find('ip_admin_eth0').config.list()
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
itr = mix.config.find('netmask_admin_eth0').config.list()
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
mix.property.read_write()
raises(AttributeError, "mix.config.find('netmask_admin_eth0')")
itr = mix.unrestraint.config.find('netmask_admin_eth0').config.list()
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
mix.property.read_only()
itr = mix.config.find('netmask_admin_eth0').config.list()
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
mix = await MixConfig(od, [conf1, conf2])
await mix.property.read_only()
ret = await mix.config.find('ip_admin_eth0')
configs = await ret.config.list()
assert len(configs) == 2
assert conf1._config_bag.context == configs[0]._config_bag.context
assert conf2._config_bag.context == configs[1]._config_bag.context
ret = await mix.config.find('netmask_admin_eth0')
configs = await ret.config.list()
assert len(configs) == 2
assert conf1._config_bag.context == configs[0]._config_bag.context
assert conf2._config_bag.context == configs[1]._config_bag.context
await mix.property.read_write()
with pytest.raises(AttributeError):
await mix.config.find('netmask_admin_eth0')
ret = await mix.unrestraint.config.find('netmask_admin_eth0')
configs = await ret.config.list()
assert len(configs) == 2
assert conf1._config_bag.context == configs[0]._config_bag.context
assert conf2._config_bag.context == configs[1]._config_bag.context
await mix.property.read_only()
ret = await mix.config.find('netmask_admin_eth0')
configs = await ret.config.list()
assert len(configs) == 2
assert conf1._config_bag.context == configs[0]._config_bag.context
assert conf2._config_bag.context == configs[1]._config_bag.context
await delete_sessions(mix)
def test_mix_leadership_value2():
@pytest.mark.asyncio
async def test_mix_leadership_value2():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2], session_id="mix")
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8'])
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#FIXME devrait raise ! assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0', 0).value.get() == None
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
mix = await MixConfig(od, [conf1, conf2], session_id="mix")
newconf1 = await mix.config('conf1')
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.8'])
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#FIXME devrait raise ! assert await newconf1.option('ip_admin_eth0.ip_admin_eth0', 0).value.get() == None
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset()
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.reset()
#
mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
await mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
await mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
await delete_sessions(mix)
def test_mix_leadership_value_default():
@pytest.mark.asyncio
async def test_mix_leadership_value_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2])
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
mix = await MixConfig(od, [conf1, conf2])
newconf1 = await mix.config('conf1')
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#
mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
#
mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
await mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.255.0'
#
mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
await mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == '255.255.0.0'
await delete_sessions(mix)
def test_mix_leadership_owners():
@pytest.mark.asyncio
async def test_mix_leadership_owners():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2])
mix.owner.set(owners.mix1)
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
raises(LeadershipError, "mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()")
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
mix = await MixConfig(od, [conf1, conf2])
await mix.owner.set(owners.mix1)
newconf1 = await mix.config('conf1')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
with pytest.raises(LeadershipError):
await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.reset()
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
#
mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
await mix.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
#
mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1
await mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1
#
mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1
await mix.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.0.0')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.mix1
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
assert mix.config('conf1').option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.user
assert await newconf1.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.mix1
await delete_sessions(mix)
def test_mix_force_default():
@pytest.mark.asyncio
async def test_mix_force_default():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2])
mix.property.read_write()
mix.owner.set('mix1')
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
mix = await MixConfig(od, [conf1, conf2])
await mix.property.read_write()
await mix.owner.set('mix1')
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
newconf1 = await mix.config('conf1')
newconf2 = await mix.config('conf2')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
errors = await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
assert len(errors) == 0
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
#
errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3'])
errors = await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.3'])
assert len(errors) == 0
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
#
errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True)
errors = await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True)
assert len(errors) == 0
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
await delete_sessions(mix)
def test_mix_force_dont_change_value():
@pytest.mark.asyncio
async def test_mix_force_dont_change_value():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2])
mix.property.read_write()
mix.owner.set('mix1')
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True)
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
mix = await MixConfig(od, [conf1, conf2])
await mix.property.read_write()
await mix.owner.set('mix1')
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
newconf1 = await mix.config('conf1')
newconf2 = await mix.config('conf2')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_dont_change_value=True)
assert len(errors) == 0
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
await delete_sessions(mix)
def test_mix_force_default_if_same():
@pytest.mark.asyncio
async def test_mix_force_default_if_same():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2])
mix.property.read_write()
mix.owner.set('mix1')
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
mix = await MixConfig(od, [conf1, conf2])
await mix.property.read_write()
await mix.owner.set('mix1')
#
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
newconf1 = await mix.config('conf1')
newconf2 = await mix.config('conf2')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True)
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True)
assert len(errors) == 0
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True)
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
errors = await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True)
assert len(errors) == 0
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
await delete_sessions(mix)
def test_mix_force_default_if_same_and_dont_change():
@pytest.mark.asyncio
async def test_mix_force_default_if_same_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2])
mix.property.read_write()
mix.owner.set('mix1')
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
mix = await MixConfig(od, [conf1, conf2])
await mix.property.read_write()
await mix.owner.set('mix1')
#
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
newconf1 = await mix.config('conf1')
newconf2 = await mix.config('conf2')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True)
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.4'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
errors = await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default_if_same=True, force_dont_change_value=True)
assert len(errors) == 0
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.4']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.mix1
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
#
mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
errors = mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True)
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.3'])
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
errors = await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.5'], force_default_if_same=True, force_dont_change_value=True)
assert len(errors) == 0
assert mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert mix.config('conf1').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert mix.config('conf2').option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.5']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.3']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').owner.get() is owners.user
await delete_sessions(mix)
def test_mix_force_default_and_dont_change():
@pytest.mark.asyncio
async def test_mix_force_default_and_dont_change():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='rconf1')
conf2 = Config(od, session_id='rconf2')
mix = MixConfig(od, [conf1, conf2])
mix.property.read_write()
mix.owner.set('mix1')
raises(ValueError, "mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True)")
conf1 = await Config(od, session_id='rconf1')
conf2 = await Config(od, session_id='rconf2')
mix = await MixConfig(od, [conf1, conf2])
await mix.property.read_write()
await mix.owner.set('mix1')
with pytest.raises(ValueError):
await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.4'], force_default=True, force_dont_change_value=True)
await delete_sessions(mix)
def test_mix_properties_mix():
@pytest.mark.asyncio
async def test_mix_properties_mix():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0], properties=('disabled',))
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
conf1.property.read_write()
conf2.property.read_write()
mix = MixConfig(od, [conf1, conf2])
mix.property.read_write()
assert mix.config('conf1').value.dict() == {}
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
await conf1.property.read_write()
await conf2.property.read_write()
mix = await MixConfig(od, [conf1, conf2])
await mix.property.read_write()
newconf1 = await mix.config('conf1')
assert await newconf1.value.dict() == {}
await delete_sessions(mix)
def test_mix_exception_mix():
@pytest.mark.asyncio
async def test_mix_exception_mix():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, callback=raise_exception)
netmask_admin_eth0.impl_add_consistency('network_netmask', ip_admin_eth0)
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", Calculation(raise_exception), multi=True, validators=[Calculation(valid_network_netmask, Params((ParamOption(ip_admin_eth0), ParamSelfOption())))])
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od = OptionDescription('root', '', [interface1])
conf1 = Config(od, session_id='conf1')
conf2 = Config(od, session_id='conf2')
mix = MixConfig(od, [conf1, conf2])
mix.property.read_write()
raises(Exception, "conf1.make_dict()")
conf1 = await Config(od, session_id='conf1')
conf2 = await Config(od, session_id='conf2')
mix = await MixConfig(od, [conf1, conf2])
await mix.property.read_write()
with pytest.raises(ConfigError):
await conf1.value.dict()
await delete_sessions(mix)
def test_mix_callback():
@pytest.mark.asyncio
async def test_mix_callback():
val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamValue('yes')))
val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val5 = StrOption('val5', "", callback=return_value, callback_params=Params(kwargs={'value': ParamValue('yes')}))
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))))
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes'))))
val4 = StrOption('val4', "", Calculation(return_value, Params(kwargs={'value': ParamOption(val1)})))
val5 = StrOption('val5', "", Calculation(return_value, Params(kwargs={'value': ParamValue('yes')})))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
cfg = Config(maconfig, session_id='cfg')
mix = MixConfig(maconfig, [cfg])
mix.property.read_write()
assert mix.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
mix.config('cfg').option('val1').value.set('new')
assert mix.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
mix.config('cfg').option('val1').value.reset()
mix.option('val1').value.set('new')
assert mix.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
mix.config('cfg').option('val4').value.set('new1')
assert mix.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
mix.config('cfg').option('val4').value.reset()
mix.option('val4').value.set('new1')
assert mix.config('cfg').value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
mix.option('val4').value.reset()
cfg = await Config(maconfig, session_id='cfg')
mix = await MixConfig(maconfig, [cfg])
await mix.property.read_write()
newcfg = await mix.config('cfg')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
await newcfg.option('val1').value.set('new')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
await newcfg.option('val1').value.reset()
await mix.option('val1').value.set('new')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
await newcfg.option('val4').value.set('new1')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
await newcfg.option('val4').value.reset()
await mix.option('val4').value.set('new1')
assert await newcfg.value.dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
await mix.option('val4').value.reset()
await delete_sessions(mix)
def test_mix_callback_follower():
@pytest.mark.asyncio
async def test_mix_callback_follower():
val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val)))
val3 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
val4 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
val1 = StrOption('val1', "", [Calculation(return_value, Params(ParamOption(val)))], multi=True)
val3 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))), multi=True)
val4 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val1))), multi=True)
interface1 = Leadership('val1', '', [val1, val3, val4])
od = OptionDescription('root', '', [interface1])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
cfg = Config(maconfig, session_id='cfg1')
mix = MixConfig(maconfig, [cfg])
mix.property.read_write()
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
mix.config('cfg1').option('val').value.set('val1')
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
mix.config('cfg1').option('val').value.reset()
mix.option('val').value.set('val1')
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
mix.option('val').value.reset()
mix.config('cfg1').option('val1.val2', 0).value.set('val2')
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
mix.config('cfg1').option('val1.val2', 0).value.reset()
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
mix.option('val1.val2', 0).value.set('val2')
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
mix.config('cfg1').option('val1.val3', 0).value.set('val6')
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
mix.option('val1.val2', 0).value.reset()
mix.config('cfg1').option('val1.val3', 0).value.reset()
mix.config('cfg1').option('val1.val1').value.set(['val3'])
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
mix.config('cfg1').option('val1.val1').value.reset()
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
mix.option('val1.val1').value.set(['val3'])
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
mix.config('cfg1').option('val1.val2', 0).value.set('val2')
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
mix.option('val1.val1').value.set(['val3', 'rah'])
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
mix.option('val1.val1').value.pop(1)
mix.option('val1.val1').value.set(['val4'])
assert mix.config('cfg1').value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'}
cfg = await Config(maconfig, session_id='cfg1')
mix = await MixConfig(maconfig, [cfg])
await mix.property.read_write()
newcfg1 = await mix.config('cfg1')
assert await newcfg1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await newcfg1.option('val').value.set('val1')
assert await newcfg1.value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
#
await newcfg1.option('val').value.reset()
await mix.option('val').value.set('val1')
assert await newcfg1.value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
#
await mix.option('val').value.reset()
await newcfg1.option('val1.val2', 0).value.set('val2')
assert await newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await newcfg1.option('val1.val2', 0).value.reset()
assert await newcfg1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await mix.option('val1.val2', 0).value.set('val2')
assert await newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await mix.option('val1.val1').value.set(['val'])
assert await newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await newcfg1.option('val1.val3', 0).value.set('val6')
assert await newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
#
await mix.option('val1.val2', 0).value.reset()
await newcfg1.option('val1.val3', 0).value.reset()
await newcfg1.option('val1.val1').value.set(['val3'])
assert await newcfg1.value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
#
await newcfg1.option('val1.val1').value.reset()
assert await newcfg1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
#
await mix.option('val1.val1').value.set(['val3'])
assert await newcfg1.value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
#
await newcfg1.option('val1.val2', 0).value.set('val2')
assert await newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
#
await mix.option('val1.val1').value.set(['val3', 'rah'])
assert await newcfg1.value.dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
#
await mix.option('val1.val1').value.pop(1)
await mix.option('val1.val1').value.set(['val4'])
assert await newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'}
await delete_sessions(mix)
def test_meta_reset():
@pytest.mark.asyncio
async def test_meta_reset():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
@ -691,30 +820,34 @@ def test_meta_reset():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "mask", multi=True, properties=('hidden',))
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od2 = OptionDescription('root', '', [interface1])
conf1 = Config(od0, session_id='conf1')
conf2 = Config(od1, session_id='conf2')
meta = MixConfig(od2, [conf1, conf2])
meta.property.read_write()
meta.owner.set('mix1')
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
errors = meta.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
conf1 = await Config(od0, session_id='conf1')
conf2 = await Config(od1, session_id='conf2')
mix = await MixConfig(od2, [conf1, conf2])
await mix.property.read_write()
await mix.owner.set('mix1')
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
newconf1 = await mix.config('conf1')
newconf2 = await mix.config('conf2')
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
errors = await mix.value.set('ip_admin_eth0.ip_admin_eth0', ['192.168.1.1'])
assert len(errors) == 0
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
meta.value.reset('ip_admin_eth0.ip_admin_eth0')
assert meta.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf1').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert meta.config('conf2').option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.2']
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['192.168.1.1']
await mix.value.reset('ip_admin_eth0.ip_admin_eth0')
assert await mix.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf1.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
assert await newconf2.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
await delete_sessions(mix)
def test_mix_properties_mix_copy():
@pytest.mark.asyncio
async def test_mix_properties_mix_copy():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
@ -724,31 +857,41 @@ def test_mix_properties_mix_copy():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface0, session_id='conf1')
conf2 = Config(interface1, session_id='conf2')
conf1.property.read_write()
conf2.property.read_write()
mix = MixConfig(interface2, [conf1, conf2], session_id='mix1')
mix.property.read_write()
conf1 = await Config(interface0, session_id='conf1')
conf2 = await Config(interface1, session_id='conf2')
await conf1.property.read_write()
await conf2.property.read_write()
mix = await MixConfig(interface2, [conf1, conf2], session_id='mix1')
await mix.property.read_write()
conf3 = mix.config('conf1').config.copy(session_id='conf3')
mix2 = conf3.config.metaconfig()
assert mix.config.name() == mix2.config.name()
newconf1 = await mix.config('conf1')
conf3 = await newconf1.config.copy(session_id='conf3')
newconf3 = await mix.config('conf3')
# old fashion
mix2 = await conf3.config.metaconfig()
assert await mix.session.id() == await mix2.session.id()
# new method
mix2 = list(await conf3.config.parents())
assert len(mix2) == 1
assert await mix.session.id() == await mix2[0].session.id()
assert mix.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert mix.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert mix.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
mix.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert mix.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert mix.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert mix.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
ret = mix.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert mix.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert mix.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert mix.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
newconf2 = await mix.config('conf2')
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await conf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await mix.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert await conf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
ret = await mix.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert await conf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
await delete_sessions(mix)
def test_mix_properties_mix_deepcopy():
@pytest.mark.asyncio
async def test_mix_properties_mix_deepcopy():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
properties=('disabled',))
@ -761,32 +904,37 @@ def test_mix_properties_mix_deepcopy():
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
properties=('disabled',))
interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface0, session_id='conf1')
conf2 = Config(interface1, session_id='conf2')
conf1.property.read_write()
conf2.property.read_write()
mix = MixConfig(interface2, [conf1, conf2])
mix.permissive.set(frozenset({'hidden'}))
mix.property.read_write()
conf1 = await Config(interface0, session_id='conf1')
conf2 = await Config(interface1, session_id='conf2')
await conf1.property.read_write()
await conf2.property.read_write()
mix = await MixConfig(interface2, [conf1, conf2])
await mix.permissive.add('hidden')
await mix.property.read_write()
mix2 = mix.config('conf1').config.deepcopy(session_id='conf3')
newconf1 = await mix.config('conf1')
newconf2 = await mix.config('conf2')
mix2 = await newconf1.config.deepcopy(session_id='conf3')
newconf3 = await mix2.config('conf3')
assert mix != mix2
assert mix.permissive.get() == mix2.permissive.get()
assert await mix.permissive.get() == await mix2.permissive.get()
assert mix.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert mix.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert mix2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
mix.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert mix.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert mix.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert mix2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
mix.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert mix.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert mix.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert mix2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await mix.option('ip_admin_eth0').value.set(['192.168.1.2'])
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.2']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await mix.value.set('ip_admin_eth0', ['192.168.1.3'], force_default_if_same=True)
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.3']}
assert await newconf3.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await delete_sessions([mix, mix2])
def test_mix_properties_submix_deepcopy():
@pytest.mark.asyncio
async def test_mix_properties_submix_deepcopy():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
properties=('disabled',))
@ -799,18 +947,22 @@ def test_mix_properties_submix_deepcopy():
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
properties=('disabled',))
interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface0, session_id='conf1')
conf1.property.read_write()
mix1 = MixConfig(interface1, [conf1], session_id='mix1')
mix2 = MixConfig(interface2, [mix1], session_id='mix2')
mix_copy = conf1.config.deepcopy(session_id='conf2',
metaconfig_prefix='copy_')
assert mix_copy.config.name() == 'copy_mix2'
assert mix_copy.config('copy_mix1').config.name() == 'copy_mix1'
assert mix_copy.config('copy_mix1').config('conf2').config.name() == 'conf2'
conf1 = await Config(interface0, session_id='conf1')
await conf1.property.read_write()
mix1 = await MixConfig(interface1, [conf1], session_id='mix1')
mix2 = await MixConfig(interface2, [mix1], session_id='mix2')
mix_copy = await conf1.config.deepcopy(session_id='conf2',
metaconfig_prefix='copy_')
assert await mix_copy.session.id() == 'copy_mix2'
ret1 = await mix_copy.config('copy_mix1')
assert await ret1.session.id() == 'copy_mix1'
ret2 = await mix_copy.config('copy_mix1.conf2')
assert await ret2.session.id() == 'conf2'
await delete_sessions([mix1, mix2, mix_copy, ret1, ret2])
def test_mix_properties_submix_deepcopy_owner():
@pytest.mark.asyncio
async def test_mix_properties_submix_deepcopy_owner():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip")
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth1', "mask")
interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
@ -820,38 +972,40 @@ def test_mix_properties_submix_deepcopy_owner():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip")
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask")
interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface0, session_id='conf1')
conf1.owner.set('conf1_user')
conf1.property.read_write()
mix1 = MixConfig(interface1, [conf1], session_id='mix1')
mix1.owner.set('mix1_user')
mix2 = MixConfig(interface2, [mix1], session_id='mix2')
mix2.owner.set('mix2_user')
conf1 = await Config(interface0, session_id='conf1')
await conf1.owner.set('conf1_user')
await conf1.property.read_write()
mix1 = await MixConfig(interface1, [conf1], session_id='mix1')
await mix1.owner.set('mix1_user')
mix2 = await MixConfig(interface2, [mix1], session_id='mix2')
await mix2.owner.set('mix2_user')
#
conf1.option('ip_admin_eth0').value.set('192.168.0.1')
assert conf1.option('ip_admin_eth0').owner.get() == 'conf1_user'
mix2.option('ip_admin_eth0').value.set('192.168.0.3')
assert mix2.option('ip_admin_eth0').owner.get() == 'mix2_user'
await conf1.option('ip_admin_eth0').value.set('192.168.0.1')
assert await conf1.option('ip_admin_eth0').owner.get() == 'conf1_user'
await mix2.option('ip_admin_eth0').value.set('192.168.0.3')
assert await mix2.option('ip_admin_eth0').owner.get() == 'mix2_user'
#
mix2_copy = conf1.config.deepcopy(session_id='conf2',
metaconfig_prefix='copy_')
mix2_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
assert mix2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3'
assert mix2_copy.option('ip_admin_eth0').owner.get() == 'mix2_user'
assert mix2_copy.option('netmask_admin_eth0').owner.get() == 'mix2_user'
mix2_copy = await conf1.config.deepcopy(session_id='conf2',
metaconfig_prefix='copy_')
await mix2_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
assert await mix2_copy.option('ip_admin_eth0').value.get() == '192.168.0.3'
assert await mix2_copy.option('ip_admin_eth0').owner.get() == 'mix2_user'
assert await mix2_copy.option('netmask_admin_eth0').owner.get() == 'mix2_user'
#
mix1_copy = mix2_copy.config('copy_mix1')
mix1_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
mix1_copy = await mix2_copy.config('copy_mix1')
await mix1_copy.option('netmask_admin_eth0').value.set('255.255.255.255')
#
conf2 = mix1_copy.config('conf2')
conf2.owner.set('conf2_user')
conf2.option('netmask_admin_eth1').value.set('255.255.255.255')
assert conf2.option('netmask_admin_eth1').owner.get() == 'conf2_user'
assert conf2.option('ip_admin_eth0').value.get() == '192.168.0.1'
assert conf2.option('ip_admin_eth0').owner.get() == 'conf1_user'
conf2 = await mix1_copy.config('conf2')
await conf2.owner.set('conf2_user')
await conf2.option('netmask_admin_eth1').value.set('255.255.255.255')
assert await conf2.option('netmask_admin_eth1').owner.get() == 'conf2_user'
assert await conf2.option('ip_admin_eth0').value.get() == '192.168.0.1'
assert await conf2.option('ip_admin_eth0').owner.get() == 'conf1_user'
await delete_sessions([mix1, mix2, mix1_copy, mix2_copy])
def test_mix_properties_mix_set_value():
@pytest.mark.asyncio
async def test_mix_properties_mix_set_value():
ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
@ -861,28 +1015,29 @@ def test_mix_properties_mix_set_value():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
interface2 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
conf1 = Config(interface0, session_id='conf1')
conf2 = Config(interface1, session_id='conf2')
conf1.property.read_write()
conf2.property.read_write()
mix = MixConfig(interface2, [conf1, conf2])
mix.property.read_write()
assert mix.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True)
conf1 = await Config(interface0, session_id='conf1')
conf2 = await Config(interface1, session_id='conf2')
await conf1.property.read_write()
await conf2.property.read_write()
mix = await MixConfig(interface2, [conf1, conf2])
await mix.property.read_write()
newconf2 = await mix.config('conf2')
assert await newconf2.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
ret = await mix.value.set('netmask_admin_eth0', ['255.255.255.255'], only_config=True)
assert len(ret) == 2
assert isinstance(ret[0], PropertiesOptionError)
assert isinstance(ret[1], AttributeError)
del ret[1]
del ret[0]
del ret
ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True)
ret = await mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default=True)
assert len(ret) == 2
assert isinstance(ret[0], AttributeError)
assert isinstance(ret[1], PropertiesOptionError)
del ret[1]
del ret[0]
del ret
ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True)
ret = await mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_dont_change_value=True)
assert len(ret) == 3
assert isinstance(ret[0], PropertiesOptionError)
assert isinstance(ret[1], AttributeError)
@ -891,44 +1046,46 @@ def test_mix_properties_mix_set_value():
del ret[1]
del ret[0]
del ret
ret = mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True)
ret = await mix.value.set('netmask_admin_eth0', ['255.255.255.255'], force_default_if_same=True)
assert len(ret) == 2
assert isinstance(ret[0], AttributeError)
assert isinstance(ret[1], PropertiesOptionError)
del ret[1]
del ret[0]
del ret
ret = mix.value.set('ip_admin_eth0', '255.255.255.255', only_config=True)
ret = await mix.value.set('ip_admin_eth0', '255.255.255.255', only_config=True)
assert len(ret) == 2
assert isinstance(ret[0], AttributeError)
assert isinstance(ret[1], ValueError)
del ret[1]
del ret[0]
del ret
ret = mix.value.set('ip_admin_eth0', '255.255.255.255', force_default=True)
ret = await mix.value.set('ip_admin_eth0', '255.255.255.255', force_default=True)
assert len(ret) == 2
assert isinstance(ret[0], AttributeError)
assert isinstance(ret[1], ValueError)
del ret[1]
del ret[0]
del ret
ret = mix.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True)
ret = await mix.value.set('ip_admin_eth0', '255.255.255.255', force_dont_change_value=True)
assert len(ret) == 2
assert isinstance(ret[0], AttributeError)
assert isinstance(ret[1], ValueError)
del ret[1]
del ret[0]
del ret
ret = mix.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True)
ret = await mix.value.set('ip_admin_eth0', '255.255.255.255', force_default_if_same=True)
assert len(ret) == 2
assert isinstance(ret[0], AttributeError)
assert isinstance(ret[1], ValueError)
del ret[1]
del ret[0]
del ret
await delete_sessions(mix)
def test_mix_different_default():
@pytest.mark.asyncio
async def test_mix_different_default():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0])
ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.2'])
@ -940,93 +1097,103 @@ def test_mix_different_default():
interface3 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, ip_admin_eth1])
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.6'])
interface4 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0])
conf1 = Config(interface0, session_id='conf1')
conf1.property.read_write()
conf2 = Config(interface1, session_id='conf2')
conf2.property.read_write()
mix = MixConfig(interface2, [conf1, conf2], session_id='submix1')
mix = MixConfig(interface3, [mix], session_id='submix2')
mix = MixConfig(interface4, [mix])
mix.property.read_write()
conf1 = await Config(interface0, session_id='conf1')
await conf1.property.read_write()
conf2 = await Config(interface1, session_id='conf2')
await conf2.property.read_write()
mix = await MixConfig(interface2, [conf1, conf2], session_id='submix1')
mix = await MixConfig(interface3, [mix], session_id='submix2')
mix = await MixConfig(interface4, [mix])
await mix.property.read_write()
#
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']}
newsubmix2 = await mix.config('submix2')
newsubmix1 = await mix.config('submix2.submix1')
newconf1 = await mix.config('submix2.submix1.conf1')
newconf2 = await mix.config('submix2.submix1.conf2')
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
#
mix.option('ip_admin_eth0').value.set(['192.168.1.7'])
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.7'], 'ip_admin_eth1': ['192.168.1.5']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
await mix.option('ip_admin_eth0').value.set(['192.168.1.7'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.7'], 'ip_admin_eth1': ['192.168.1.5']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
#
mix.config('submix2').option('ip_admin_eth0').value.set(['192.168.1.8'])
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.8']}
await newsubmix2.option('ip_admin_eth0').value.set(['192.168.1.8'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.8']}
#
raises(AttributeError, "mix.config('submix2.submix1').option('ip_admin_eth0').value.set(['192.168.1.9'])")
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.8']}
with pytest.raises(AttributeError):
await newsubmix1.option('ip_admin_eth0').value.set(['192.168.1.9'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.8']}
#
raises(AttributeError, "mix.config('submix2.submix1.conf2').option('ip_admin_eth0').value.set(['192.168.1.9'])")
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.8']}
with pytest.raises(AttributeError):
await newconf2.option('ip_admin_eth0').value.set(['192.168.1.9'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.8']}
#
mix.config('submix2.submix1.conf1').option('ip_admin_eth0').value.set(['192.168.1.9'])
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
await newconf1.option('ip_admin_eth0').value.set(['192.168.1.9'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
#
raises(AttributeError, "mix.option('ip_admin_eth1').value.set(['192.168.1.10'])")
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
with pytest.raises(AttributeError):
await mix.option('ip_admin_eth1').value.set(['192.168.1.10'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.5']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
#
mix.config('submix2').option('ip_admin_eth1').value.set(['192.168.1.10'])
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.10']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.10']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
await newsubmix2.option('ip_admin_eth1').value.set(['192.168.1.10'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.10']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.10']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
#
mix.config('submix2.submix1').option('ip_admin_eth1').value.set(['192.168.1.11'])
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
await newsubmix1.option('ip_admin_eth1').value.set(['192.168.1.11'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
#
mix.config('submix2.submix1.conf2').option('ip_admin_eth1').value.set(['192.168.1.12'])
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
await newconf2.option('ip_admin_eth1').value.set(['192.168.1.12'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
#
raises(AttributeError, "mix.config('submix2.submix1.conf1').option('ip_admin_eth1').value.set(['192.168.1.13'])")
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
with pytest.raises(AttributeError):
await newconf1.option('ip_admin_eth1').value.set(['192.168.1.13'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await newsubmix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert await newsubmix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert await newconf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
assert await newconf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
await delete_sessions(mix)
def test_mix_different_default_reset():
@pytest.mark.asyncio
async def test_mix_different_default_reset():
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
interface0 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0])
ip_admin_eth0 = NetworkOption('ip_admin_eth1', "ip", multi=True, default=['192.168.1.2'])
@ -1038,105 +1205,137 @@ def test_mix_different_default_reset():
interface3 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, ip_admin_eth1])
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.6'])
interface4 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0])
conf1 = Config(interface0, session_id='conf1')
conf1.property.read_write()
conf2 = Config(interface1, session_id='conf2')
conf2.property.read_write()
mix = MixConfig(interface2, [conf1, conf2], session_id='submix1')
mix = MixConfig(interface3, [mix], session_id='submix2')
mix = MixConfig(interface4, [mix])
mix.property.read_write()
conf1 = await Config(interface0, session_id='conf1')
await conf1.property.read_write()
conf2 = await Config(interface1, session_id='conf2')
await conf2.property.read_write()
mix = await MixConfig(interface2, [conf1, conf2], session_id='submix1')
mix = await MixConfig(interface3, [mix], session_id='submix2')
mix = await MixConfig(interface4, [mix])
await mix.property.read_write()
#
mix.option('ip_admin_eth0').value.set(['192.168.1.7'])
mix.config('submix2').option('ip_admin_eth0').value.set(['192.168.1.8'])
mix.config('submix2').option('ip_admin_eth1').value.set(['192.168.1.10'])
mix.config('submix2.submix1').option('ip_admin_eth1').value.set(['192.168.1.11'])
mix.config('submix2.submix1.conf2').option('ip_admin_eth1').value.set(['192.168.1.12'])
mix.config('submix2.submix1.conf1').option('ip_admin_eth0').value.set(['192.168.1.9'])
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
await mix.option('ip_admin_eth0').value.set(['192.168.1.7'])
submix2 = await mix.config('submix2')
submix1 = await mix.config('submix2.submix1')
conf1 = await mix.config('submix2.submix1.conf1')
conf2 = await mix.config('submix2.submix1.conf2')
await submix2.option('ip_admin_eth0').value.set(['192.168.1.8'])
await submix2.option('ip_admin_eth1').value.set(['192.168.1.10'])
await submix1.option('ip_admin_eth1').value.set(['192.168.1.11'])
await conf2.option('ip_admin_eth1').value.set(['192.168.1.12'])
await conf1.option('ip_admin_eth0').value.set(['192.168.1.9'])
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.7']}
assert await submix2.value.dict() == {'ip_admin_eth0': ['192.168.1.8'], 'ip_admin_eth1': ['192.168.1.10']}
assert await submix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert await conf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
assert await conf1.value.dict() == {'ip_admin_eth0': ['192.168.1.9']}
#
mix.value.reset('ip_admin_eth0')
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.10']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await mix.value.reset('ip_admin_eth0')
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']}
assert await submix2.value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.10']}
assert await submix1.value.dict() == {'ip_admin_eth1': ['192.168.1.11']}
assert await conf2.value.dict() == {'ip_admin_eth1': ['192.168.1.12']}
assert await conf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
#
mix.value.reset('ip_admin_eth1')
assert mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']}
assert mix.config('submix2').value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']}
assert mix.config('submix2.submix1').value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert mix.config('submix2.submix1.conf2').value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert mix.config('submix2.submix1.conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await mix.value.reset('ip_admin_eth1')
assert await mix.value.dict() == {'ip_admin_eth0': ['192.168.1.6']}
assert await submix2.value.dict() == {'ip_admin_eth0': ['192.168.1.4'], 'ip_admin_eth1': ['192.168.1.5']}
assert await submix1.value.dict() == {'ip_admin_eth1': ['192.168.1.3']}
assert await conf2.value.dict() == {'ip_admin_eth1': ['192.168.1.2']}
assert await conf1.value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
await delete_sessions(mix)
def test_mix_pop_config():
@pytest.mark.asyncio
async def test_mix_pop_config():
od = make_description()
config1 = Config(od, session_id='config1')
config2 = Config(od, session_id='config2')
mix = MixConfig(od, [config1, config2])
mix.option('od1.i1').value.set(2)
config1 = await Config(od, session_id='config1')
config2 = await Config(od, session_id='config2')
mix = await MixConfig(od, [config1, config2])
await mix.option('od1.i1').value.set(2)
#
assert len(list(mix.config.list())) == 2
assert mix.config('config1').value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
newconf1 = mix.config.pop('config1')
assert len(list(await mix.config.list())) == 2
newconfig1 = await mix.config('config1')
assert await newconfig1.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
newconf1 = await mix.config.pop('config1')
try:
assert mix.config('config1').value.dict()
await mix.config('config1')
except ConfigError:
pass
else:
raise Exception('must raise')
assert newconf1.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
assert await newconf1.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
#
assert len(list(mix.config.list())) == 1
raises(ConfigError, "mix.config.pop('newconf1')")
assert len(list(await mix.config.list())) == 1
with pytest.raises(ConfigError):
await mix.config.pop('newconf1')
await delete_sessions([mix, newconf1])
def test_mix_add_config():
@pytest.mark.asyncio
async def test_mix_add_config():
od = make_description()
config1 = Config(od, session_id='config1')
config2 = Config(od, session_id='config2')
mix = MixConfig(od, [config1, config2])
mix.option('od1.i1').value.set(2)
config1 = await Config(od, session_id='config1')
config2 = await Config(od, session_id='config2')
mix = await MixConfig(od, [config1, config2])
await mix.option('od1.i1').value.set(2)
#
assert len(list(mix.config.list())) == 2
config = Config(od, session_id='new')
assert config.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
mix.config.add(config)
assert len(list(await mix.config.list())) == 2
config = await Config(od, session_id='new')
assert await config.value.dict() == {'od1.i1': None, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
await mix.config.add(config)
#
assert len(list(mix.config.list())) == 3
assert config.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
assert len(list(await mix.config.list())) == 3
assert await config.value.dict() == {'od1.i1': 2, 'od1.i2': 1, 'od1.i3': None, 'od1.i4': 2, 'od1.i5': [2], 'od1.i6': None}
#
raises(ConflictError, "mix.config.add(config)")
with pytest.raises(ConflictError):
await mix.config.add(config)
await delete_sessions(mix)
def test_mix_add_config_readd():
@pytest.mark.asyncio
async def test_mix_add_config_readd():
od = make_description()
mix = MixConfig(od, [])
mix2 = MixConfig(od, [])
mix = await MixConfig(od, [])
mix2 = await MixConfig(od, [])
#
config = Config(od, session_id='new')
mix.config.add(config)
raises(ConflictError, "mix2.config.add(config)")
config = await Config(od, session_id='new')
await mix.config.add(config)
await mix2.config.add(config)
assert len(list(await config.config.parents())) == 2
await delete_sessions([mix, mix2])
def test_meta_new_mixconfig():
@pytest.mark.asyncio
async def test_mix_new_config_readd():
od = make_description()
conf = Config(od, session_id='conf1')
meta = MetaConfig([conf])
assert isinstance(meta.config.new('mixconfig', type="mixconfig"), MixConfig)
mix = await MixConfig(od, [])
assert len(list(await mix.config.list())) == 0
mix2 = await mix.config.new('mix2')
assert len(list(await mix.config.list())) == 1
await delete_sessions([mix, mix2])
def test_meta_get_mixconfig():
@pytest.mark.asyncio
async def test_meta_new_mixconfig():
od = make_description()
conf = Config(od, session_id='conf1')
meta = MetaConfig([conf])
meta.config.new('mixconfig', type="mixconfig")
assert isinstance(meta.config.get('mixconfig'), MixConfig)
raises(ConfigError, "meta.config.get('unknown')")
meta.config.get('mixconfig').config.add(MixConfig(od, [], session_id='mixconfig2'))
assert isinstance(meta.config.get('mixconfig').config.get('mixconfig2'), MixConfig)
cfg = await Config(od, session_id='cfg1')
meta = await MetaConfig([cfg])
mix = await meta.config.new('mixconfig', type="mixconfig")
assert isinstance(mix, MixConfig)
await delete_sessions(meta)
@pytest.mark.asyncio
async def test_meta_get_mixconfig():
od = make_description()
cfg = await Config(od, session_id='conf1')
meta = await MetaConfig([cfg])
await meta.config.new('mixconfig', type="mixconfig")
assert isinstance(await meta.config.get('mixconfig'), MixConfig)
with pytest.raises(ConfigError):
await meta.config.get('unknown')
newmix = await meta.config.get('mixconfig')
await newmix.config.add(await MixConfig(od, [], session_id='mixconfig2'))
assert isinstance(await newmix.config.get('mixconfig2'), MixConfig)
await delete_sessions(meta)

View File

@ -0,0 +1,97 @@
from tiramisu import IntOption, OptionDescription, MetaConfig, list_sessions
from tiramisu.error import ConfigError
import pytest
from .config import delete_sessions, event_loop
async def make_metaconfig():
i1 = IntOption('i1', '')
i2 = IntOption('i2', '', default=1)
i3 = IntOption('i3', '')
i4 = IntOption('i4', '', default=2)
i5 = IntOption('i5', '', default=[2], multi=True)
i6 = IntOption('i6', '', properties=('disabled',))
od1 = OptionDescription('od1', '', [i1, i2, i3, i4, i5, i6])
od2 = OptionDescription('od2', '', [od1])
return await MetaConfig([], optiondescription=od2, session_id='metacfg1', delete_old_session=True)
@pytest.mark.asyncio
async def test_multi_parents_path():
"""
metacfg1 (1) ---
| -- cfg1
metacfg2 (2) ---
"""
metacfg1 = await make_metaconfig()
cfg1 = await metacfg1.config.new(type='config', session_id="cfg1")
metacfg2 = await MetaConfig([cfg1], session_id='metacfg2', delete_old_session=True)
#
assert await metacfg1.config.path() == 'metacfg1'
assert await metacfg2.config.path() == 'metacfg2'
assert await cfg1.config.path() == 'metacfg2.metacfg1.cfg1'
await delete_sessions([metacfg1, metacfg2])
@pytest.mark.asyncio
async def test_multi_parents_path_same():
"""
--- metacfg2 (1) ---
metacfg1 --| | -- cfg1
--- metacfg3 (2) ---
"""
metacfg1 = await make_metaconfig()
metacfg2 = await metacfg1.config.new(type='metaconfig', session_id="metacfg2")
metacfg3 = await metacfg1.config.new(type='metaconfig', session_id="metacfg3")
cfg1 = await metacfg2.config.new(type='config', session_id="cfg1")
await metacfg3.config.add(cfg1)
#
assert await metacfg2.config.path() == 'metacfg1.metacfg2'
assert await metacfg3.config.path() == 'metacfg1.metacfg3'
assert await cfg1.config.path() == 'metacfg1.metacfg3.metacfg1.metacfg2.cfg1'
await metacfg1.option('od1.i1').value.set(1)
await metacfg3.option('od1.i1').value.set(2)
assert await cfg1.option('od1.i1').value.get() == 1
orideep = await cfg1.config.deepcopy(metaconfig_prefix="test_", session_id='test_cfg1')
deep = orideep
while True:
try:
children = list(await deep.config.list())
except:
break
assert len(children) < 2
deep = children[0]
assert await deep.config.path() == 'test_metacfg3.test_metacfg1.test_metacfg2.test_cfg1'
assert await cfg1.option('od1.i1').value.get() == 1
await delete_sessions([metacfg1, orideep])
@pytest.mark.asyncio
async def test_multi_parents_value():
metacfg1 = await make_metaconfig()
cfg1 = await metacfg1.config.new(type='config', session_id="cfg1")
metacfg2 = await MetaConfig([cfg1], session_id='metacfg2', delete_old_session=True)
#
assert await cfg1.option('od1.i1').value.get() == None
assert await cfg1.option('od1.i2').value.get() == 1
assert await cfg1.option('od1.i3').value.get() == None
#
assert await metacfg1.option('od1.i1').value.get() == None
assert await metacfg1.option('od1.i2').value.get() == 1
assert await metacfg1.option('od1.i3').value.get() == None
#
assert await metacfg2.option('od1.i1').value.get() == None
assert await metacfg2.option('od1.i2').value.get() == 1
assert await metacfg2.option('od1.i3').value.get() == None
#
await metacfg1.option('od1.i3').value.set(3)
assert await metacfg1.option('od1.i3').value.get() == 3
assert await cfg1.option('od1.i3').value.get() == 3
assert await metacfg2.option('od1.i2').value.get() == 1
#
await metacfg2.option('od1.i2').value.set(4)
assert await metacfg2.option('od1.i2').value.get() == 4
assert await metacfg1.option('od1.i2').value.get() == 1
assert await cfg1.option('od1.i2').value.get() == 4
await delete_sessions([metacfg1, metacfg2])

View File

@ -4,139 +4,199 @@ and to compare them
from .autopath import do_autopath
do_autopath()
from py.test import raises
import pytest
import warnings
from tiramisu.error import APIError, ConfigError
from tiramisu import IntOption, SymLinkOption, OptionDescription, Config
from tiramisu.setting import groups
from tiramisu.storage import list_sessions
from tiramisu import IntOption, SymLinkOption, OptionDescription, Config, Calculation, groups, list_sessions
from tiramisu.i18n import _
from .config import event_loop
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
try:
groups.family
except:
groups.family = groups.GroupType('family')
def a_func():
return None
def test_option_valid_name():
@pytest.mark.asyncio
async def test_option_valid_name():
IntOption('test', '')
raises(ValueError, 'IntOption(1, "")')
# raises(ValueError, 'IntOption("1test", "")')
with pytest.raises(ValueError):
IntOption(1, "")
i = IntOption("test1", "")
# raises(ValueError, 'IntOption("_test", "")')
# raises(ValueError, 'IntOption(" ", "")')
raises(ValueError, 'SymLinkOption(1, i)')
with pytest.raises(ValueError):
SymLinkOption(1, i)
i = SymLinkOption("test1", i)
#
#
#@pytest.mark.asyncio
#async def test_option_unvalid_name():
# with pytest.raises(ValueError):
# IntOption('test.', '')
# with pytest.raises(ValueError):
# IntOption('test.val', '')
# with pytest.raises(ValueError):
# IntOption('.test', '')
# with pytest.raises(ValueError):
# OptionDescription('.test', '', [])
def test_option_with_callback():
# no default value with callback
raises(ValueError, "IntOption('test', '', default=1, callback=a_func)")
def test_option_get_information():
@pytest.mark.asyncio
async def test_option_get_information():
description = "it's ok"
string = 'some informations'
i = IntOption('test', description)
raises(ValueError, "i.impl_get_information('noinfo')")
with pytest.raises(ValueError):
i.impl_get_information('noinfo')
i.impl_set_information('info', string)
assert i.impl_get_information('info') == string
raises(ValueError, "i.impl_get_information('noinfo')")
with pytest.raises(ValueError):
i.impl_get_information('noinfo')
assert i.impl_get_information('noinfo', 'default') == 'default'
assert i.impl_get_information('doc') == description
def test_option_get_information_config():
@pytest.mark.asyncio
async def test_option_get_information_config():
description = "it's ok"
string = 'some informations'
string
i = IntOption('test', description)
od = OptionDescription('od', '', [i])
Config(od)
raises(ValueError, "i.impl_get_information('noinfo')")
raises(AttributeError, "i.impl_set_information('info', string)")
# assert i.impl_get_information('info') == string
raises(ValueError, "i.impl_get_information('noinfo')")
async with await Config(od) as cfg:
pass
with pytest.raises(ValueError):
i.impl_get_information('noinfo')
with pytest.raises(AttributeError):
i.impl_set_information('info', string)
with pytest.raises(ValueError):
i.impl_get_information('noinfo')
assert i.impl_get_information('noinfo', 'default') == 'default'
assert i.impl_get_information('doc') == description
assert not await list_sessions()
def test_option_get_information_config2():
@pytest.mark.asyncio
async def test_option_get_information_default():
description = "it's ok"
string = 'some informations'
i = IntOption('test', description)
i.impl_set_information('noinfo', 'optdefault')
od = OptionDescription('od', '', [i])
async with await Config(od) as cfg:
#
assert await cfg.option('test').information.get('noinfo', 'falsedefault') == 'optdefault'
#
await cfg.option('test').information.set('noinfo', 'notdefault')
assert await cfg.option('test').information.get('noinfo', 'falsedefault') == 'notdefault'
assert not await list_sessions()
@pytest.mark.asyncio
async def test_option_get_information_config2():
description = "it's ok"
string = 'some informations'
i = IntOption('test', description)
i.impl_set_information('info', string)
od = OptionDescription('od', '', [i])
Config(od)
raises(ValueError, "i.impl_get_information('noinfo')")
raises(AttributeError, "i.impl_set_information('info', 'hello')")
async with await Config(od) as cfg:
pass
with pytest.raises(ValueError):
i.impl_get_information('noinfo')
with pytest.raises(AttributeError):
i.impl_set_information('info', 'hello')
assert i.impl_get_information('info') == string
raises(ValueError, "i.impl_get_information('noinfo')")
with pytest.raises(ValueError):
i.impl_get_information('noinfo')
assert i.impl_get_information('noinfo', 'default') == 'default'
assert i.impl_get_information('doc') == description
assert not await list_sessions()
def test_optiondescription_get_information():
@pytest.mark.asyncio
async def test_optiondescription_get_information():
description = "it's ok"
string = 'some informations'
o = OptionDescription('test', description, [])
o.impl_set_information('info', string)
assert o.impl_get_information('info') == string
raises(ValueError, "o.impl_get_information('noinfo')")
with pytest.raises(ValueError):
o.impl_get_information('noinfo')
assert o.impl_get_information('noinfo', 'default') == 'default'
assert o.impl_get_information('doc') == description
assert not await list_sessions()
def test_option_isoptiondescription():
@pytest.mark.asyncio
async def test_option_isoptiondescription():
i = IntOption('test', '')
od = OptionDescription('od', '', [i])
od = OptionDescription('od', '', [od])
cfg = Config(od)
assert cfg.option('od').option.isoptiondescription()
assert not cfg.option('od.test').option.isoptiondescription()
async with await Config(od) as cfg:
assert await cfg.option('od').option.isoptiondescription()
assert not await cfg.option('od.test').option.isoptiondescription()
assert not await list_sessions()
def test_option_double():
@pytest.mark.asyncio
async def test_option_double():
i = IntOption('test', '')
od = OptionDescription('od1', '', [i])
od = OptionDescription('od2', '', [od])
od = OptionDescription('od3', '', [od])
cfg = Config(od)
assert cfg.option('od2.od1.test').value.get() is None
assert cfg.option('od2').option('od1').option('test').value.get() is None
async with await Config(od) as cfg:
assert await cfg.option('od2.od1.test').value.get() is None
assert await cfg.option('od2').option('od1').option('test').value.get() is None
assert not await list_sessions()
def test_option_multi():
@pytest.mark.asyncio
async def test_option_multi():
IntOption('test', '', multi=True)
IntOption('test', '', multi=True, default_multi=1)
IntOption('test', '', default=[1], multi=True, default_multi=1)
#add default_multi to not multi's option
raises(ValueError, "IntOption('test', '', default_multi=1)")
with pytest.raises(ValueError):
IntOption('test', '', default_multi=1)
#unvalid default_multi
raises(ValueError, "IntOption('test', '', multi=True, default_multi='yes')")
#not default_multi with callback
raises(ValueError, "IntOption('test', '', multi=True, default_multi=1, callback=a_func)")
with pytest.raises(ValueError):
IntOption('test', '', multi=True, default_multi='yes')
assert not await list_sessions()
def test_unknown_option():
#@pytest.mark.asyncio
#async def test_option_multi_legacy():
# #not default_multi with callback
# #with pytest.raises(ValueError):
# IntOption('test', '', multi=True, default_multi=1, callback=a_func)")
@pytest.mark.asyncio
async def test_unknown_option():
i = IntOption('test', '')
od1 = OptionDescription('od', '', [i])
od2 = OptionDescription('od', '', [od1])
api = Config(od2)
# test is an option, not an optiondescription
raises(TypeError, "api.option('od.test.unknown').value.get()")
# unknown is an unknown option
raises(AttributeError, "api.option('unknown').value.get()")
# unknown is an unknown option
raises(AttributeError, "api.option('od.unknown').value.get()")
# unknown is an unknown optiondescription
raises(AttributeError, "api.option('od.unknown.suboption').value.get()")
async with await Config(od2) as cfg:
# test is an option, not an optiondescription
with pytest.raises(TypeError):
await cfg.option('od.test.unknown').value.get()
# unknown is an unknown option
with pytest.raises(AttributeError):
await cfg.option('unknown').value.get()
# unknown is an unknown option
with pytest.raises(AttributeError):
await cfg.option('od.unknown').value.get()
# unknown is an unknown optiondescription
with pytest.raises(AttributeError):
await cfg.option('od.unknown.suboption').value.get()
assert not await list_sessions()
def test_optiondescription_list():
@pytest.mark.asyncio
async def test_optiondescription_list():
groups.notfamily1 = groups.GroupType('notfamily1')
i = IntOption('test', '')
i2 = IntOption('test', '')
@ -146,28 +206,30 @@ def test_optiondescription_list():
od3.impl_set_group_type(groups.notfamily1)
od2 = OptionDescription('od', '', [od1, od3])
od4 = OptionDescription('od', '', [od2])
api = Config(od4)
assert len(list(api.option('od').list('option'))) == 0
assert len(list(api.option('od').list('optiondescription'))) == 2
assert len(list(api.option('od').list('optiondescription', group_type=groups.family))) == 1
assert len(list(api.option('od').list('optiondescription', group_type=groups.notfamily1))) == 1
assert len(list(api.option('od.od').list('option'))) == 1
assert len(list(api.option('od.od2').list('option'))) == 1
try:
list(api.option('od').list('unknown'))
except AssertionError:
pass
else:
raise Exception('must raise')
try:
list(api.option('od').list('option', group_type='toto'))
except AssertionError:
pass
else:
raise Exception('must raise')
async with await Config(od4) as cfg:
assert len(list(await cfg.option('od').list('option'))) == 0
assert len(list(await cfg.option('od').list('optiondescription'))) == 2
assert len(list(await cfg.option('od').list('optiondescription', group_type=groups.family))) == 1
assert len(list(await cfg.option('od').list('optiondescription', group_type=groups.notfamily1))) == 1
assert len(list(await cfg.option('od.od').list('option'))) == 1
assert len(list(await cfg.option('od.od2').list('option'))) == 1
try:
list(await cfg.option('od').list('unknown'))
except AssertionError:
pass
else:
raise Exception('must raise')
try:
list(await cfg.option('od').list('option', group_type='toto'))
except AssertionError:
pass
else:
raise Exception('must raise')
assert not await list_sessions()
def test_optiondescription_group():
@pytest.mark.asyncio
async def test_optiondescription_group():
groups.notfamily = groups.GroupType('notfamily')
i = IntOption('test', '')
i2 = IntOption('test', '')
@ -176,26 +238,28 @@ def test_optiondescription_group():
od3 = OptionDescription('od2', '', [i2])
od3.impl_set_group_type(groups.notfamily)
od2 = OptionDescription('od', '', [od1, od3])
api = Config(od2)
assert len(list(api.option.list('option'))) == 0
assert len(list(api.option.list('optiondescription'))) == 2
assert len(list(api.option.list('optiondescription', group_type=groups.family))) == 1
assert len(list(api.option.list('optiondescription', group_type=groups.notfamily))) == 1
try:
list(api.option.list('unknown'))
except AssertionError:
pass
else:
raise Exception('must raise')
try:
list(api.option.list('option', group_type='toto'))
except AssertionError:
pass
else:
raise Exception('must raise')
async with await Config(od2) as cfg:
assert len(list(await cfg.option.list('option'))) == 0
assert len(list(await cfg.option.list('optiondescription'))) == 2
assert len(list(await cfg.option.list('optiondescription', group_type=groups.family))) == 1
assert len(list(await cfg.option.list('optiondescription', group_type=groups.notfamily))) == 1
try:
list(await cfg.option.list('unknown'))
except AssertionError:
pass
else:
raise Exception('must raise')
try:
list(await cfg.option.list('option', group_type='toto'))
except AssertionError:
pass
else:
raise Exception('must raise')
assert not await list_sessions()
def test_optiondescription_group_redefined():
@pytest.mark.asyncio
async def test_optiondescription_group_redefined():
try:
groups.notfamily = groups.GroupType('notfamily')
except:
@ -203,43 +267,61 @@ def test_optiondescription_group_redefined():
i = IntOption('test', '')
od1 = OptionDescription('od', '', [i])
od1.impl_set_group_type(groups.family)
raises(ValueError, "od1.impl_set_group_type(groups.notfamily)")
with pytest.raises(ValueError):
od1.impl_set_group_type(groups.notfamily)
assert not await list_sessions()
def test_optiondescription_group_leadership():
@pytest.mark.asyncio
async def test_optiondescription_group_leadership():
i = IntOption('test', '')
od1 = OptionDescription('od', '', [i])
raises(ConfigError, "od1.impl_set_group_type(groups.leadership)")
with pytest.raises(ConfigError):
od1.impl_set_group_type(groups.leadership)
assert not await list_sessions()
def test_asign_optiondescription():
@pytest.mark.asyncio
async def test_asign_optiondescription():
i = IntOption('test', '')
od1 = OptionDescription('od', '', [i])
od2 = OptionDescription('od', '', [od1])
api = Config(od2)
raises(APIError, "api.option('od').value.set('test')")
raises(APIError, "api.option('od').value.reset()")
async with await Config(od2) as cfg:
with pytest.raises(APIError):
await cfg.option('od').value.set('test')
with pytest.raises(APIError):
await cfg.option('od').value.reset()
assert not await list_sessions()
def test_intoption():
@pytest.mark.asyncio
async def test_intoption():
i1 = IntOption('test1', 'description', min_number=3)
i2 = IntOption('test2', 'description', max_number=3)
od = OptionDescription('od', '', [i1, i2])
cfg = Config(od)
raises(ValueError, "cfg.option('test1').value.set(2)")
cfg.option('test1').value.set(3)
cfg.option('test1').value.set(4)
cfg.option('test2').value.set(2)
cfg.option('test2').value.set(3)
raises(ValueError, "cfg.option('test2').value.set(4)")
async with await Config(od) as cfg:
with pytest.raises(ValueError):
await cfg.option('test1').value.set(2)
await cfg.option('test1').value.set(3)
await cfg.option('test1').value.set(4)
await cfg.option('test2').value.set(2)
await cfg.option('test2').value.set(3)
with pytest.raises(ValueError):
await cfg.option('test2').value.set(4)
assert not await list_sessions()
def test_get_display_type():
@pytest.mark.asyncio
async def test_get_display_type():
i1 = IntOption('test1', 'description', min_number=3)
assert i1.get_display_type() == _('integer')
assert not await list_sessions()
def test_option_not_in_config():
@pytest.mark.asyncio
async def test_option_not_in_config():
i1 = IntOption('test1', 'description', min_number=3)
raises(AttributeError, "i1.impl_getpath()")
with pytest.raises(AttributeError):
i1.impl_getpath()
assert not await list_sessions()

View File

@ -1,22 +1,20 @@
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config
from py.test import raises
import pytest
import warnings
from tiramisu import Config
from tiramisu.config import KernelConfig
from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \
undefined, Params, ParamOption, ParamValue, ParamContext, calc_value
undefined, Calculation, Params, ParamOption, ParamValue, ParamIndex, calc_value, \
valid_ip_netmask, ParamSelfOption, ParamInformation, ParamSelfInformation
from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError
from tiramisu.i18n import _
from tiramisu.storage import list_sessions
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
from .config import config_type, get_config, event_loop
def return_val():
@ -45,6 +43,10 @@ def return_value(value=None):
return value
async def return_async_value(value=None):
return value
def return_value2(*args, **kwargs):
value = list(args)
value.extend(kwargs.values())
@ -74,13 +76,7 @@ def return_calc(i, j, k):
def is_config(config, **kwargs):
if isinstance(config, KernelConfig):
return 'yes'
else:
return 'no'
def ret_from_config(config):
cfg = Config(config)
return cfg.option('val1').value.get()
return 'no'
def return_raise(*arg):
@ -102,11 +98,9 @@ def make_description_duplicates():
floatoption = FloatOption('float', 'Test float option', default=2.3)
stroption = StrOption('str', 'Test string option', default="abc")
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
wantref_option = BoolOption('wantref', 'Test requires', default=False)
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
default=False)
# dummy2 (same path)
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
# dummy3 (same name)
@ -119,31 +113,43 @@ def make_description_duplicates():
return descr
def test_identical_paths():
@pytest.mark.asyncio
async def test_identical_paths():
"""If in the schema (the option description) there is something that
have the same name, an exection is raised
"""
raises(ConflictError, "make_description_duplicates()")
with warnings.catch_warnings(record=True) as w:
with pytest.raises(ConflictError):
make_description_duplicates()
def test_hidden_if_in2(config_type):
@pytest.mark.asyncio
async def test_hidden_if_in2(config_type):
intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc",
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(intoption),
'expected': ParamValue(1),
'default': ParamValue(None)}))
stroption = StrOption('str', 'Test string option', default="abc", properties=(hidden_property,))
descr = OptionDescription('constraints', '', [stroption, intoption])
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
assert not 'hidden' in cfg.option('str').property.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('str').value.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()
async with await Config(descr) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
assert not 'hidden' in await cfg.option('str').property.get()
await cfg.option('int').value.set(1)
with pytest.raises(PropertiesOptionError):
await cfg.option('str').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('str').value.set('uvw')
if config_type == 'tiramisu-api':
await cfg.send()
assert 'hidden' in await cfg_ori.unrestraint.option('str').property.get()
assert not await list_sessions()
def test_hidden_if_in_with_group(config_type):
@pytest.mark.asyncio
async def test_hidden_if_in_with_group(config_type):
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
@ -154,21 +160,28 @@ def test_hidden_if_in_with_group(config_type):
booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc")
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(intoption),
'expected': ParamValue(1),
'default': ParamValue(None)}))
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption], properties=(hidden_property,))
descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption])
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
assert not 'hidden' in cfg_ori.option('str').property.get()
cfg.option('int').value.set(1)
if config_type == 'tiramisu-api':
cfg.send()
raises(PropertiesOptionError, "cfg_ori.option('gc.name').value.get()")
async with await Config(descr) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
assert not 'hidden' in await cfg_ori.option('str').property.get()
await cfg.option('int').value.set(1)
if config_type == 'tiramisu-api':
await cfg.send()
with pytest.raises(PropertiesOptionError):
await cfg_ori.option('gc.name').value.get()
assert not await list_sessions()
def test_disabled_with_group():
@pytest.mark.asyncio
async def test_disabled_with_group():
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
@ -179,15 +192,21 @@ def test_disabled_with_group():
booloption = BoolOption('bool', 'Test boolean option', default=True)
intoption = IntOption('int', 'Test int option', default=0)
stroption = StrOption('str', 'Test string option', default="abc")
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
requires=({'option': intoption, 'expected': 1, 'action': 'disabled'},))
disabled_property = Calculation(calc_value,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(intoption),
'expected': ParamValue(1),
'default': ParamValue(None)}))
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption], properties=(disabled_property,))
descr = OptionDescription('constraints', '', [gcgroup, booloption,
objspaceoption, stroption, intoption])
cfg = Config(descr)
cfg.property.read_write()
assert cfg.option('gc.name').value.get()
cfg.option('int').value.set(1)
raises(PropertiesOptionError, "cfg.option('gc.name').value.get()")
async with await Config(descr) as cfg:
await cfg.property.read_write()
assert await cfg.option('gc.name').value.get()
await cfg.option('int').value.set(1)
with pytest.raises(PropertiesOptionError):
await cfg.option('gc.name').value.get()
assert not await list_sessions()
#____________________________________________________________
@ -201,11 +220,15 @@ def make_description_callback():
floatoption = FloatOption('float', 'Test float option', default=2.3)
stroption = StrOption('str', 'Test string option', default="abc")
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
wantref_option = BoolOption('wantref', 'Test requires', default=False,
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
hidden_property = Calculation(calc_value,
Params(ParamValue('hidden'),
kwargs={'condition': ParamOption(boolop),
'expected': ParamValue(True),
'default': ParamValue(None)}))
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=(hidden_property,))
wantframework_option = BoolOption('wantframework', 'Test requires',
default=False,
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
properties=(hidden_property,))
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
wantref_option, stroption,
@ -214,1141 +237,1320 @@ def make_description_callback():
return descr
def test_has_callback():
@pytest.mark.asyncio
async def test_has_callback():
descr = make_description_callback()
# here the owner is 'default'
cfg = Config(descr)
cfg.property.read_write()
cfg.option('bool').value.set(False)
# because dummy has a callback
cfg.property.add('freeze')
cfg.option('gc.dummy').property.add('frozen')
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.set(True)")
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.option('bool').value.set(False)
# because dummy has a callback
await cfg.property.add('freeze')
await cfg.option('gc.dummy').property.add('frozen')
with pytest.raises(PropertiesOptionError):
await cfg.option('gc.dummy').value.set(True)
assert not await list_sessions()
def test_freeze_and_has_callback():
@pytest.mark.asyncio
async def test_freeze_and_has_callback():
descr = make_description_callback()
cfg = Config(descr)
cfg.property.read_write()
cfg.option('bool').value.set(False)
cfg.property.add('freeze')
cfg.option('gc.dummy').property.add('frozen')
raises(PropertiesOptionError, "cfg.option('gc.dummy').value.set(True)")
async with await Config(descr) as cfg:
await cfg.property.read_write()
await cfg.option('bool').value.set(False)
await cfg.property.add('freeze')
await cfg.option('gc.dummy').property.add('frozen')
with pytest.raises(PropertiesOptionError):
await cfg.option('gc.dummy').value.set(True)
assert not await list_sessions()
def test_callback(config_type):
val1 = StrOption('val1', "", callback=return_val)
@pytest.mark.asyncio
async def test_callback(config_type):
val1 = StrOption('val1', "", Calculation(return_val))
val2 = StrOption('val2', "")
maconfig = OptionDescription('rootconfig', '', [val1, val2])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
if config_type != 'tiramisu-api':
assert cfg.option('val1').option.callbacks() != (None, None)
assert cfg.option('val2').option.callbacks() == (None, None)
assert cfg.option('val1').value.get() == 'val'
cfg.option('val1').value.set('new-val')
assert cfg.option('val1').value.get() == 'new-val'
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == 'val'
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == 'val'
await cfg.option('val1').value.set('new-val')
assert await cfg.option('val1').value.get() == 'new-val'
await cfg.option('val1').value.reset()
assert await cfg.option('val1').value.get() == 'val'
assert not await list_sessions()
def test_callback_params_without_callback():
raises(ValueError, "StrOption('val2', '', callback_params=Params(ParamValue('yes')))")
@pytest.mark.asyncio
async def test_params():
with pytest.raises(ValueError):
Params('str')
with pytest.raises(ValueError):
Params(('str',))
with pytest.raises(ValueError):
Params(kwargs={'a': 'str'})
def test_params():
raises(ValueError, "Params([ParamContext()])")
raises(ValueError, "Params('str')")
raises(ValueError, "Params(('str',))")
raises(ValueError, "Params(kwargs=[ParamContext()])")
raises(ValueError, "Params(kwargs={'a': 'str'})")
def test_param_option():
@pytest.mark.asyncio
async def test_param_option():
val1 = StrOption('val1', "")
raises(ValueError, "ParamOption('str')")
raises(ValueError, "ParamOption(val1, 'str')")
with pytest.raises(ValueError):
ParamOption('str')
with pytest.raises(AssertionError):
ParamOption(val1, 'str')
def test_callback_invalid():
raises(AssertionError, 'val1 = StrOption("val1", "", callback="string")')
raises(AssertionError, 'val1 = StrOption("val1", "", callback=return_val, callback_params="string")')
@pytest.mark.asyncio
async def test_callback_with_error(config_type):
val1 = StrOption("val1", "", Calculation(is_config, Params(ParamValue('string'), kwargs={'value': ParamValue('string')})))
maconfig = OptionDescription('rootconfig', '', [val1])
async with await Config(maconfig) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == 'no'
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_value(config_type):
val1 = StrOption('val1', "", 'val')
val1
raises(AssertionError, "StrOption('val2', '', callback=return_value, callback_params={'': 'string'})")
raises(AssertionError, "StrOption('val4', '', callback=return_value, callback_params={'value': (('string', False),)})")
raises(AssertionError, "StrOption('val4', '', callback=return_value, callback_params={'value': ((val1, 'string'),)})")
raises(AssertionError, "StrOption('val4', '', callback=return_value, callback_params={'value': ((val1, False, 'unknown'),)})")
raises(AssertionError, "StrOption('val4', '', callback=return_value, callback_params={'value': ((val1,),)})")
def test_callback_with_context():
context = ParamContext()
value = ParamValue('string')
params = Params((context,), {'value': value})
val1 = StrOption("val1", "", callback=is_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1])
cfg = Config(maconfig)
assert cfg.option('val1').value.get() == 'yes'
def test_callback_with_context_named():
context = ParamContext()
params = Params(kwargs={'config': context})
val1 = StrOption("val1", "", callback=is_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1])
cfg = Config(maconfig)
assert cfg.option('val1').value.get() == 'yes'
def test_callback_with_error(config_type):
val1 = StrOption("val1", "", callback=is_config, callback_params=Params(ParamValue('string'), kwargs={'value': ParamValue('string')}))
maconfig = OptionDescription('rootconfig', '', [val1])
cfg = Config(maconfig)
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == 'no'
def test_callback_with_context_value():
context = ParamContext()
params = Params((context,))
val1 = StrOption("val1", "")
val2 = StrOption("val2", "", callback=ret_from_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1, val2])
cfg = Config(maconfig)
cfg.option('val1').value.set('yes')
assert cfg.option('val1').value.get() == 'yes'
assert cfg.option('val2').value.get() == 'yes'
cfg.option('val1').value.set('no')
assert cfg.option('val1').value.get() == 'no'
assert cfg.option('val2').value.get() == 'no'
def test_callback_value(config_type):
val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamValue('yes')))
val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val5 = StrOption('val5', "", callback=return_value, callback_params=Params(ParamValue('yes')))
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))))
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes'))))
val4 = StrOption('val4', "", Calculation(return_value, Params(kwargs={'value': ParamOption(val1)})))
val5 = StrOption('val5', "", Calculation(return_value, Params(ParamValue('yes'))))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == 'val'
assert cfg.option('val2').value.get() == 'val'
assert cfg.option('val4').value.get() == 'val'
cfg.option('val1').value.set('new-val')
assert cfg.option('val1').value.get() == 'new-val'
assert cfg.option('val2').value.get() == 'new-val'
assert cfg.option('val4').value.get() == 'new-val'
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == 'val'
assert cfg.option('val2').value.get() == 'val'
assert cfg.option('val3').value.get() == 'yes'
assert cfg.option('val4').value.get() == 'val'
assert cfg.option('val5').value.get() == 'yes'
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == 'val'
assert await cfg.option('val2').value.get() == 'val'
assert await cfg.option('val4').value.get() == 'val'
await cfg.option('val1').value.set('new-val')
assert await cfg.option('val1').value.get() == 'new-val'
assert await cfg.option('val2').value.get() == 'new-val'
assert await cfg.option('val4').value.get() == 'new-val'
await cfg.option('val1').value.reset()
assert await cfg.option('val1').value.get() == 'val'
assert await cfg.option('val2').value.get() == 'val'
assert await cfg.option('val3').value.get() == 'yes'
assert await cfg.option('val4').value.get() == 'val'
assert await cfg.option('val5').value.get() == 'yes'
assert not await list_sessions()
def test_callback_value_tuple(config_type):
@pytest.mark.asyncio
async def test_callback_async_value(config_type):
val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", Calculation(return_async_value, Params(ParamOption(val1))))
val3 = StrOption('val3', "", Calculation(return_async_value, Params(ParamValue('yes'))))
val4 = StrOption('val4', "", Calculation(return_async_value, Params(kwargs={'value': ParamOption(val1)})))
val5 = StrOption('val5', "", Calculation(return_async_value, Params(ParamValue('yes'))))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == 'val'
assert await cfg.option('val2').value.get() == 'val'
assert await cfg.option('val4').value.get() == 'val'
await cfg.option('val1').value.set('new-val')
assert await cfg.option('val1').value.get() == 'new-val'
assert await cfg.option('val2').value.get() == 'new-val'
assert await cfg.option('val4').value.get() == 'new-val'
await cfg.option('val1').value.reset()
assert await cfg.option('val1').value.get() == 'val'
assert await cfg.option('val2').value.get() == 'val'
assert await cfg.option('val3').value.get() == 'yes'
assert await cfg.option('val4').value.get() == 'val'
assert await cfg.option('val5').value.get() == 'yes'
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_information(config_type):
val1 = StrOption('val1', "", Calculation(return_value, Params(ParamInformation('information', 'no_value'))))
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamInformation('information'))))
maconfig = OptionDescription('rootconfig', '', [val1, val2])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == 'no_value'
with pytest.raises(ConfigError):
await cfg.option('val2').value.get()
await cfg.information.set('information', 'new_value')
assert await cfg.option('val1').value.get() == 'new_value'
assert await cfg.option('val2').value.get() == 'new_value'
await cfg.information.set('information', 'new_value2')
assert await cfg.option('val1').value.get() == 'new_value2'
assert await cfg.option('val2').value.get() == 'new_value2'
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_information2(config_type):
val1 = StrOption('val1', "", Calculation(return_value, Params(ParamSelfInformation('information', 'no_value'))))
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamSelfInformation('information'))))
val2.impl_set_information('information', 'new_value')
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamSelfInformation('information'))))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == 'no_value'
assert await cfg.option('val2').value.get() == 'new_value'
with pytest.raises(ConfigError):
await cfg.option('val3').value.get()
await cfg.option('val2').information.set('information', 'new_value2')
assert await cfg.option('val2').value.get() == 'new_value2'
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_value_tuple(config_type):
val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", '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'))))
val3 = StrOption('val3', "", Calculation(return_concat, Params((ParamOption(val1), ParamOption(val2)))))
val4 = StrOption('val4', "", Calculation(return_concat, Params((ParamValue('yes'), ParamValue('no')))))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == 'val1'
assert cfg.option('val2').value.get() == 'val2'
assert cfg.option('val3').value.get() == 'val1.val2'
assert cfg.option('val4').value.get() == 'yes.no'
cfg.option('val1').value.set('new-val')
assert cfg.option('val3').value.get() == 'new-val.val2'
cfg.option('val1').value.reset()
assert cfg.option('val3').value.get() == 'val1.val2'
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == 'val1'
assert await cfg.option('val2').value.get() == 'val2'
assert await cfg.option('val3').value.get() == 'val1.val2'
assert await cfg.option('val4').value.get() == 'yes.no'
await cfg.option('val1').value.set('new-val')
assert await cfg.option('val3').value.get() == 'new-val.val2'
await cfg.option('val1').value.reset()
assert await cfg.option('val3').value.get() == 'val1.val2'
assert not await list_sessions()
def test_callback_value_force_permissive2(config_type):
@pytest.mark.asyncio
async def test_callback_value_force_permissive2(config_type):
val1 = StrOption('val1', "", 'val', properties=('disabled',))
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True)))
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))))
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val1, True))))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
cfg = Config(maconfig)
cfg.property.read_only()
if config_type != 'tiramisu-api':
raises(ConfigError, "cfg.option('val2').value.get()")
cfg.option('val3').value.get() is None
else:
raises(ConfigError, "get_config(cfg, config_type)")
async with await Config(maconfig) as cfg:
await cfg.property.read_only()
if config_type != 'tiramisu-api':
with pytest.raises(ConfigError):
await cfg.option('val2').value.get()
await cfg.option('val3').value.get() is None
else:
with pytest.raises(ConfigError):
await get_config(cfg, config_type)
assert not await list_sessions()
def test_callback_value_force_permissive_kwargs():
@pytest.mark.asyncio
async def test_callback_value_force_permissive_kwargs():
val1 = StrOption('val1', "", 'val', properties=('disabled',))
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)))
val2 = StrOption('val2', "", Calculation(return_value, Params(value=ParamOption(val1))))
val3 = StrOption('val3', "", Calculation(return_value, Params(value=ParamOption(val1, True))))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
cfg = Config(maconfig)
cfg.property.read_only()
raises(ConfigError, "cfg.option('val2').value.get()")
cfg.option('val3').value.get() is None
async with await Config(maconfig) as cfg:
await cfg.property.read_only()
with pytest.raises(ConfigError):
await cfg.option('val2').value.get()
await cfg.option('val3').value.get() is None
assert not await list_sessions()
def test_callback_symlink(config_type):
@pytest.mark.asyncio
async def test_callback_symlink(config_type):
val1 = StrOption('val1', "", 'val')
val2 = SymLinkOption('val2', val1)
val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val2)))
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamOption(val2))))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == 'val'
assert cfg.option('val2').value.get() == 'val'
assert cfg.option('val3').value.get() == 'val'
cfg.option('val1').value.set('new-val')
assert cfg.option('val1').value.get() == 'new-val'
assert cfg.option('val3').value.get() == 'new-val'
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == 'val'
assert cfg.option('val3').value.get() == 'val'
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == 'val'
assert await cfg.option('val2').value.get() == 'val'
assert await cfg.option('val3').value.get() == 'val'
await cfg.option('val1').value.set('new-val')
assert await cfg.option('val1').value.get() == 'new-val'
assert await cfg.option('val3').value.get() == 'new-val'
await cfg.option('val1').value.reset()
assert await cfg.option('val1').value.get() == 'val'
assert await cfg.option('val3').value.get() == 'val'
assert not await list_sessions()
def test_callback_list():
val1 = StrOption('val1', "", callback=return_list)
@pytest.mark.asyncio
async def test_callback_list():
val1 = StrOption('val1', "", Calculation(return_list))
maconfig = OptionDescription('rootconfig', '', [val1])
cfg = Config(maconfig)
cfg.property.read_write()
raises(ValueError, "cfg.option('val1').value.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(ValueError):
await cfg.option('val1').value.get()
assert not await list_sessions()
def test_callback_list2():
val1 = StrOption('val1', "", callback=return_list)
#val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) # , 'forcepermissive': False}]})
@pytest.mark.asyncio
async def test_callback_list2():
val1 = StrOption('val1', "", Calculation(return_list))
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))))
maconfig = OptionDescription('rootconfig', '', [val1, val2])
cfg = Config(maconfig)
cfg.property.read_write()
raises(ValueError, "cfg.option('val1').value.get()")
#cfg.val2
raises(ValueError, "cfg.option('val2').value.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(ValueError):
await cfg.option('val1').value.get()
#await cfg.val2
with pytest.raises(ValueError):
await cfg.option('val2').value.get()
assert not await list_sessions()
def test_callback_multi(config_type):
val1 = StrOption('val1', "", callback=return_val, multi=True)
@pytest.mark.asyncio
async def test_callback_multi(config_type):
val1 = StrOption('val1', "", [Calculation(return_val)], multi=True)
maconfig = OptionDescription('rootconfig', '', [val1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == ['val']
cfg.option('val1').value.set(['new-val'])
assert cfg.option('val1').value.get() == ['new-val']
cfg.option('val1').value.set(['new-val', 'new-val2'])
assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == ['val']
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == ['val']
await cfg.option('val1').value.set(['new-val'])
assert await cfg.option('val1').value.get() == ['new-val']
await cfg.option('val1').value.set(['new-val', 'new-val2'])
assert await cfg.option('val1').value.get() == ['new-val', 'new-val2']
await cfg.option('val1').value.reset()
assert await cfg.option('val1').value.get() == ['val']
assert not await list_sessions()
def test_callback_multi_value(config_type):
@pytest.mark.asyncio
async def test_callback_multi_value(config_type):
val1 = StrOption('val1', "", ['val'], multi=True)
#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')))
#val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params={'': ((val1, False), 'yes')})
option = ParamOption(val1)
params1 = Params((option,))
value = ParamValue('yes')
params2 = Params((value,))
params3 = Params((option, value))
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=params1)
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=params2)
val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params=params3)
val2 = StrOption('val2', "", Calculation(return_value, params1), multi=True)
val3 = StrOption('val3', "", [Calculation(return_value, params2)], multi=True)
val4 = StrOption('val4', "", Calculation(return_list2, params3), multi=True)
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == ['val']
assert cfg.option('val2').value.get() == ['val']
assert cfg.option('val4').value.get() == ['val', 'yes']
cfg.option('val1').value.set(['new-val'])
assert cfg.option('val1').value.get() == ['new-val']
assert cfg.option('val2').value.get() == ['new-val']
assert cfg.option('val4').value.get() == ['new-val', 'yes']
cfg.option('val1').value.set(['new-val', 'new-val2'])
assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
assert cfg.option('val2').value.get() == ['new-val', 'new-val2']
assert cfg.option('val4').value.get() == ['new-val', 'new-val2', 'yes']
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == ['val']
assert cfg.option('val2').value.get() == ['val']
assert cfg.option('val3').value.get() == ['yes']
assert cfg.option('val4').value.get() == ['val', 'yes']
cfg.option('val2').value.set(['val', 'new'])
assert cfg.option('val1').value.get() == ['val']
assert cfg.option('val2').value.get() == ['val', 'new']
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == ['val']
assert await cfg.option('val2').value.get() == ['val']
assert await cfg.option('val4').value.get() == ['val', 'yes']
await cfg.option('val1').value.set(['new-val'])
assert await cfg.option('val1').value.get() == ['new-val']
assert await cfg.option('val2').value.get() == ['new-val']
assert await cfg.option('val4').value.get() == ['new-val', 'yes']
await cfg.option('val1').value.set(['new-val', 'new-val2'])
assert await cfg.option('val1').value.get() == ['new-val', 'new-val2']
assert await cfg.option('val2').value.get() == ['new-val', 'new-val2']
assert await cfg.option('val4').value.get() == ['new-val', 'new-val2', 'yes']
await cfg.option('val1').value.reset()
assert await cfg.option('val1').value.get() == ['val']
assert await cfg.option('val2').value.get() == ['val']
assert await cfg.option('val3').value.get() == ['yes']
assert await cfg.option('val4').value.get() == ['val', 'yes']
await cfg.option('val2').value.set(['val', 'new'])
assert await cfg.option('val1').value.get() == ['val']
assert await cfg.option('val2').value.get() == ['val', 'new']
assert not await list_sessions()
def test_callback_multi_list(config_type):
val1 = StrOption('val1', "", callback=return_list, multi=True)
@pytest.mark.asyncio
async def test_callback_multi_list(config_type):
val1 = StrOption('val1', "", Calculation(return_list), multi=True, properties=('notunique',))
maconfig = OptionDescription('rootconfig', '', [val1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == ['val', 'val']
cfg.option('val1').value.set(['new-val'])
assert cfg.option('val1').value.get() == ['new-val']
cfg.option('val1').value.set(['new-val', 'new-val2'])
assert cfg.option('val1').value.get() == ['new-val', 'new-val2']
cfg.option('val1').value.reset()
assert cfg.option('val1').value.get() == ['val', 'val']
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == ['val', 'val']
await cfg.option('val1').value.set(['new-val'])
assert await cfg.option('val1').value.get() == ['new-val']
await cfg.option('val1').value.set(['new-val', 'new-val2'])
assert await cfg.option('val1').value.get() == ['new-val', 'new-val2']
await cfg.option('val1').value.reset()
assert await cfg.option('val1').value.get() == ['val', 'val']
assert not await list_sessions()
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)
@pytest.mark.asyncio
async def test_callback_multi_list_extend(config_type):
val1 = StrOption('val1', "", Calculation(return_list2, Params((ParamValue(['1', '2', '3']), ParamValue(['4', '5'])))), multi=True)
maconfig = OptionDescription('rootconfig', '', [val1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1').value.get() == ['1', '2', '3', '4', '5']
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1').value.get() == ['1', '2', '3', '4', '5']
assert not await list_sessions()
def test_callback_multi_callback(config_type):
val1 = StrOption('val1', "", multi=True, callback=return_val)
@pytest.mark.asyncio
async def test_callback_multi_callback(config_type):
val1 = StrOption('val1', "", [Calculation(return_val)], multi=True)
interface1 = OptionDescription('val1', '', [val1])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == ['val']
cfg.option('val1.val1').value.set(['val1', undefined])
assert cfg.option('val1.val1').value.get() == ['val1', 'val']
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1.val1').value.get() == ['val']
await cfg.option('val1.val1').value.set(['val1', undefined])
assert await cfg.option('val1.val1').value.get() == ['val1', None]
assert not await list_sessions()
def test_callback_leader_and_followers_leader(config_type):
val1 = StrOption('val1', "", multi=True, callback=return_val)
@pytest.mark.asyncio
async def test_callback_multi_callback_default(config_type):
val1 = StrOption('val1', "", default_multi=Calculation(return_val), multi=True)
interface1 = OptionDescription('val1', '', [val1])
maconfig = OptionDescription('rootconfig', '', [interface1])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1.val1').value.get() == []
await cfg.option('val1.val1').value.set(['val1', undefined])
assert await cfg.option('val1.val1').value.get() == ['val1', 'val']
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader(config_type):
val1 = StrOption('val1', "", default=[Calculation(return_val)], default_multi=Calculation(return_val), multi=True, properties=('notunique',))
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == ['val']
cfg.option('val1.val1').value.set([undefined, undefined])
assert cfg.option('val1.val1').value.get() == ['val', 'val']
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == None
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1.val1').value.get() == ['val']
await cfg.option('val1.val1').value.set([undefined, undefined])
assert await cfg.option('val1.val1').value.get() == ['val', 'val']
assert await cfg.option('val1.val2', 0).value.get() == None
assert await cfg.option('val1.val2', 1).value.get() == None
assert not await list_sessions()
def test_callback_follower(config_type):
@pytest.mark.asyncio
async def test_callback_follower(config_type):
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params=Params(ParamValue(['string', 'new'])))
val2 = StrOption('val2', "", Calculation(return_value3, Params(ParamValue(['string', 'new']), {'index': ParamIndex()})), multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('val1.val1').value.set(['val'])
assert cfg.option('val1.val2', 0).value.get() == 'string'
cfg.option('val1.val1').value.set(['val', 'val1'])
assert cfg.option('val1.val2', 0).value.get() == 'string'
assert cfg.option('val1.val2', 1).value.get() == 'new'
cfg.option('val1.val1').value.set(['val', 'val1', 'val2'])
assert cfg.option('val1.val2', 0).value.get() == 'string'
assert cfg.option('val1.val2', 1).value.get() == 'new'
assert cfg.option('val1.val2', 2).value.get() == None
cfg.option('val1.val1').value.set(['val', 'val1', 'val2', 'val3'])
assert cfg.option('val1.val2', 0).value.get() == 'string'
assert cfg.option('val1.val2', 1).value.get() == 'new'
assert cfg.option('val1.val2', 2).value.get() == None
assert cfg.option('val1.val2', 3).value.get() == None
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('val1.val1').value.set(['val'])
assert await cfg.option('val1.val2', 0).value.get() == 'string'
await cfg.option('val1.val1').value.set(['val', 'val1'])
assert await cfg.option('val1.val2', 0).value.get() == 'string'
assert await cfg.option('val1.val2', 1).value.get() == 'new'
await cfg.option('val1.val1').value.set(['val', 'val1', 'val2'])
assert await cfg.option('val1.val2', 0).value.get() == 'string'
assert await cfg.option('val1.val2', 1).value.get() == 'new'
assert await cfg.option('val1.val2', 2).value.get() == None
await cfg.option('val1.val1').value.set(['val', 'val1', 'val2', 'val3'])
assert await cfg.option('val1.val2', 0).value.get() == 'string'
assert await cfg.option('val1.val2', 1).value.get() == 'new'
assert await cfg.option('val1.val2', 2).value.get() == None
assert await cfg.option('val1.val2', 3).value.get() == None
assert not await list_sessions()
def test_callback_leader_and_followers_leader2(config_type):
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader2(config_type):
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, default_multi='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)))
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val2), {'index': ParamIndex()})), multi=True)
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val3), {'index': ParamIndex()})), multi=True)
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('val1.val1').value.set(['val'])
assert cfg.option('val1.val4', 0).value.get() == 'val2'
assert cfg.option('val1.val3', 0).value.get() == 'val2'
assert cfg.option('val1.val2', 0).value.get() == 'val2'
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
await cfg.option('val1.val1').value.set(['val'])
assert await cfg.option('val1.val4', 0).value.get() == 'val2'
assert await cfg.option('val1.val3', 0).value.get() == 'val2'
assert await cfg.option('val1.val2', 0).value.get() == 'val2'
assert not await list_sessions()
def test_callback_leader_and_followers_leader_mandatory1(config_type):
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader_mandatory1(config_type):
val = StrOption('val', "", default='val')
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',))
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
val1 = StrOption('val1', "", Calculation(return_value2, Params(ParamOption(val))), properties=('mandatory',), multi=True)
val3 = StrOption('val3', "", Calculation(return_index, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
val4 = StrOption('val4', "", Calculation(return_index, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
cfg_ori = Config(maconfig)
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val1').value.get() == ['val']
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('val1.val1').value.set([undefined, 'val3'])
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()")
async with await Config(maconfig) as cfg_ori:
await cfg_ori.property.read_only()
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('val1.val3', 0).value.get() == 'val'
assert await cfg.option('val1.val4', 0).value.get() == 'val'
assert await cfg.option('val1.val1').value.get() == ['val']
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
await cfg.option('val1.val1').value.set([undefined, 'val3'])
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.property.read_only()
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('val1.val1').value.get() == ['val', 'val3']
assert await cfg.option('val1.val3', 0).value.get() == 'val'
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(PropertiesOptionError):
await cfg.option('val1.val3', 1).value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('val1.val4', 1).value.get()
assert not await list_sessions()
def test_callback_leader_and_followers_leader_mandatory2(config_type):
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader_mandatory2(config_type):
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',))
val3 = StrOption('val3', "", 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',))
val1 = StrOption('val1', "", Calculation(return_index, Params(ParamOption(val), {'val2': ParamOption(val_)})), properties=('mandatory',), multi=True)
val3 = StrOption('val3', "", Calculation(return_index, Params(ParamOption(val1), {'val2': ParamOption(val_), 'index': ParamIndex()})), properties=('mandatory',), multi=True)
val4 = StrOption('val4', "", Calculation(return_index, Params(ParamOption(val1), {'val2': ParamOption(val_), 'index': ParamIndex()})), properties=('mandatory',), multi=True)
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
cfg_ori = Config(maconfig)
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val4', 1).value.get() == 'val_'
assert cfg.option('val1.val1').value.get() == ['val', 'val_']
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
assert cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert cfg.option('val1.val4', 0).value.get() == 'val'
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']
async with await Config(maconfig) as cfg_ori:
await cfg_ori.property.read_only()
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('val1.val3', 0).value.get() == 'val'
assert await cfg.option('val1.val3', 1).value.get() == 'val_'
assert await cfg.option('val1.val4', 0).value.get() == 'val'
assert await cfg.option('val1.val4', 1).value.get() == 'val_'
assert await cfg.option('val1.val1').value.get() == ['val', 'val_']
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
await cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
assert await cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
await cfg_ori.property.read_only()
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('val1.val3', 0).value.get() == 'val'
assert await cfg.option('val1.val3', 1).value.get() == 'val_'
assert await cfg.option('val1.val4', 0).value.get() == 'val'
assert await cfg.option('val1.val4', 1).value.get() == 'val_'
if config_type != 'tiramisu-api':
# FIXME
with pytest.raises(PropertiesOptionError):
await cfg.option('val1.val3', 2).value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('val1.val4', 2).value.get()
assert await cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
assert not await list_sessions()
def test_callback_leader_and_followers_leader_mandatory3(config_type):
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader_mandatory3(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), {'val': ParamOption(val_)}), 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',))
val1 = StrOption('val1', "", Calculation(return_value2, Params(ParamOption(val), {'val': ParamOption(val_)})), properties=('mandatory',), multi=True)
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
cfg_ori = Config(maconfig)
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val4', 1).value.get() == 'val_'
assert cfg.option('val1.val1').value.get() == ['val', 'val_']
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val3', 1).value.get() == 'val_'
assert cfg.option('val1.val3', 2).value.get() == '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']
async with await Config(maconfig) as cfg_ori:
await cfg_ori.property.read_only()
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('val1.val3', 0).value.get() == 'val'
assert await cfg.option('val1.val3', 1).value.get() == 'val_'
assert await cfg.option('val1.val4', 0).value.get() == 'val'
assert await cfg.option('val1.val4', 1).value.get() == 'val_'
assert await cfg.option('val1.val1').value.get() == ['val', 'val_']
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
await cfg.option('val1.val1').value.set(['val', 'val_', 'val3'])
await cfg_ori.property.read_only()
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('val1.val3', 0).value.get() == 'val'
assert await cfg.option('val1.val3', 1).value.get() == 'val_'
assert await cfg.option('val1.val3', 2).value.get() == 'val3'
assert await cfg.option('val1.val4', 0).value.get() == 'val'
assert await cfg.option('val1.val4', 1).value.get() == 'val_'
assert await cfg.option('val1.val4', 2).value.get() == 'val3'
assert await cfg.option('val1.val1').value.get() == ['val', 'val_', 'val3']
assert not await list_sessions()
def test_callback_leader_and_followers_leader_mandatory4(config_type):
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader_mandatory4(config_type):
val = StrOption('val', "", default='val')
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',))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
val1 = StrOption('val1', "", Calculation(return_value2, Params(ParamOption(val))), properties=('mandatory',), multi=True)
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val1), {'index': ParamIndex()})), properties=('mandatory',), multi=True)
interface1 = Leadership('val1', '', [val1, val3, val4])
maconfig = OptionDescription('rootconfig', '', [val, interface1])
cfg_ori = Config(maconfig)
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
#raises(IndexError, "cfg.option('val1.val3').value.get()")
assert cfg.option('val1.val3', 0).value.get() == 'val'
assert cfg.option('val1.val4', 0).value.get() == 'val'
assert cfg.option('val1.val1').value.get() == ['val']
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('val1.val1').value.set(['val', 'val3'])
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'
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'
async with await Config(maconfig) as cfg_ori:
await cfg_ori.property.read_only()
cfg = await get_config(cfg_ori, config_type)
#raises(IndexError, "await cfg.option('val1.val3').value.get()")
assert await cfg.option('val1.val3', 0).value.get() == 'val'
assert await cfg.option('val1.val4', 0).value.get() == 'val'
assert await cfg.option('val1.val1').value.get() == ['val']
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
await cfg.option('val1.val1').value.set(['val', 'val3'])
await cfg_ori.property.read_only()
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('val1.val1').value.get() == ['val', 'val3']
assert await cfg.option('val1.val3', 0).value.get() == 'val'
assert await cfg.option('val1.val3', 1).value.get() == 'val3'
assert await cfg.option('val1.val4', 0).value.get() == 'val'
assert await cfg.option('val1.val4', 1).value.get() == 'val3'
assert not await list_sessions()
def test_callback_leader_and_followers_leader3():
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader3():
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
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)))
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val2), {'index': ParamIndex()})), multi=True)
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val3), {'index': ParamIndex()})), multi=True)
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
assert list(cfg.value.mandatory()) == ['val1.val1']
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
# FIXME cfg = await get_config(cfg, config_type)
assert list(await cfg.value.mandatory()) == ['val1.val1']
assert not await list_sessions()
def test_callback_leader_and_followers_leader4():
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader4():
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('mandatory',))
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert', 'mandatory'))
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)))
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val2), {'index': ParamIndex()})), multi=True)
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val3), {'index': ParamIndex()})), multi=True)
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
cfg.property.add('expert')
cfg.permissive.set(frozenset(['expert']))
assert list(cfg.value.mandatory()) == []
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
# FIXME cfg = await get_config(cfg, config_type)
await cfg.property.add('expert')
await cfg.permissive.add('expert')
assert list(await cfg.value.mandatory()) == []
assert not await list_sessions()
def test_consistency_leader_and_followers_leader_mandatory_transitive():
@pytest.mark.asyncio
async def test_consistency_leader_and_followers_leader_mandatory_transitive():
#default value
val1 = IPOption('val1', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
val2.impl_add_consistency('ip_netmask', val1)
#no value
val3 = IPOption('val3', "", multi=True, properties=('mandatory',))
val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
val4.impl_add_consistency('ip_netmask', val3)
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'), validators=[Calculation(valid_ip_netmask, Params((ParamOption(val1), ParamSelfOption())))])
interface1 = Leadership('val1', '', [val1, val2])
interface2 = Leadership('val3', '', [val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
cfg = Config(maconfig)
cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
try:
cfg.option('val1.val1').value.get()
except PropertiesOptionError as error:
assert str(error) == str(_('cannot access to {0} "{1}" because "{2}" has {3} {4}').format('option', 'val1', 'val2', _('property'), '"disabled"'))
else:
raise Exception('must raises')
raises(PropertiesOptionError, "cfg.option('val3.val3').value.get()")
assert list(cfg.value.mandatory()) == []
maconfig = OptionDescription('rootconfig', '', [interface1])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
# FIXME cfg = await get_config(cfg, config_type)
try:
await cfg.option('val1.val2', 0).value.get()
except PropertiesOptionError as error:
assert str(error) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'val2', _('property'), '"disabled"'))
else:
raise Exception('must raises')
assert list(await cfg.value.mandatory()) == []
assert not await list_sessions()
def test_consistency_leader_and_followers_leader_mandatory_non_transitive():
#no value
val1 = IPOption('val1', "", multi=True, properties=('mandatory',))
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
val2.impl_add_consistency('ip_netmask', val1, transitive=False)
#default value
val3 = IPOption('val3', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
val4.impl_add_consistency('ip_netmask', val3, transitive=False)
interface1 = Leadership('val1', '', [val1, val2])
interface2 = Leadership('val3', '', [val3, val4])
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
cfg = Config(maconfig)
cfg.property.read_write()
# FIXME cfg = get_config(cfg, config_type)
assert list(cfg.value.mandatory()) == ["val1.val1"]
def test_callback_leader_and_followers_leader_list(config_type):
val1 = StrOption('val1', "", multi=True, callback=return_list)
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader_list(config_type):
val1 = StrOption('val1', "", Calculation(return_list), multi=True, properties=('notunique',))
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == ['val', 'val']
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == None
cfg.option('val1.val1').value.set(['val', 'val', undefined])
assert cfg.option('val1.val1').value.get() == ['val', 'val', None]
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == None
assert cfg.option('val1.val2', 2).value.get() == None
cfg.option('val1.val1').value.reset()
assert cfg.option('val1.val1').value.get() == ['val', 'val']
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == None
cfg.option('val1.val1').value.pop(1)
assert cfg.option('val1.val1').value.get() == ['val']
assert cfg.option('val1.val2', 0).value.get() == None
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1.val1').value.get() == ['val', 'val']
assert await cfg.option('val1.val2', 0).value.get() == None
assert await cfg.option('val1.val2', 1).value.get() == None
await cfg.option('val1.val1').value.set(['val', 'val', undefined])
assert await cfg.option('val1.val1').value.get() == ['val', 'val', None]
assert await cfg.option('val1.val2', 0).value.get() == None
assert await cfg.option('val1.val2', 1).value.get() == None
assert await cfg.option('val1.val2', 2).value.get() == None
await cfg.option('val1.val1').value.reset()
assert await cfg.option('val1.val1').value.get() == ['val', 'val']
assert await cfg.option('val1.val2', 0).value.get() == None
assert await cfg.option('val1.val2', 1).value.get() == None
await cfg.option('val1.val1').value.pop(1)
assert await cfg.option('val1.val1').value.get() == ['val']
assert await cfg.option('val1.val2', 0).value.get() == None
assert not await list_sessions()
def test_callback_leader_and_followers_leader_follower_list(config_type):
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader_follower_list(config_type):
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_list)
val2 = StrOption('val2', "", Calculation(return_list), multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').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()")
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1.val1').value.get() == []
if config_type == 'tiramisu-api':
# when "tiramisu-api", raise when set and not in get function
with pytest.raises(ConfigError):
await cfg.option('val1.val1').value.set(['val1'])
else:
await cfg.option('val1.val1').value.set(['val1'])
with pytest.raises(LeadershipError):
await cfg.option('val1.val2', 0).value.get()
assert not await list_sessions()
def test_callback_leader_and_followers_follower(config_type):
@pytest.mark.asyncio
async def test_callback_leader_and_followers_follower(config_type):
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_val)
val2 = StrOption('val2', "", Calculation(return_val), multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == []
#
cfg.option('val1.val1').value.set(['val1'])
assert cfg.option('val1.val1').value.get() == ['val1']
assert cfg.option('val1.val2', 0).value.get() == 'val'
#
cfg.option('val1.val1').value.set(['val1', 'val2'])
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert cfg.option('val1.val2', 0).value.get() == 'val'
assert cfg.option('val1.val2', 1).value.get() == 'val'
#
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert cfg.option('val1.val2', 0).value.get() == 'val'
assert cfg.option('val1.val2', 1).value.get() == 'val'
assert cfg.option('val1.val2', 2).value.get() == 'val'
#
cfg.option('val1.val1').value.pop(2)
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert cfg.option('val1.val2', 0).value.get() == 'val'
assert cfg.option('val1.val2', 1).value.get() == 'val'
#
cfg.option('val1.val2', 0).value.set('val2')
cfg.option('val1.val2', 1).value.set('val2')
assert cfg.option('val1.val2', 0).value.get() == 'val2'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
#
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val2', 0).value.get() == 'val2'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val2', 2).value.get() == 'val'
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1.val1').value.get() == []
#
await cfg.option('val1.val1').value.set(['val1'])
assert await cfg.option('val1.val1').value.get() == ['val1']
assert await cfg.option('val1.val2', 0).value.get() == 'val'
#
await cfg.option('val1.val1').value.set(['val1', 'val2'])
assert await cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert await cfg.option('val1.val2', 0).value.get() == 'val'
assert await cfg.option('val1.val2', 1).value.get() == 'val'
#
await cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert await cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert await cfg.option('val1.val2', 0).value.get() == 'val'
assert await cfg.option('val1.val2', 1).value.get() == 'val'
assert await cfg.option('val1.val2', 2).value.get() == 'val'
#
await cfg.option('val1.val1').value.pop(2)
assert await cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert await cfg.option('val1.val2', 0).value.get() == 'val'
assert await cfg.option('val1.val2', 1).value.get() == 'val'
#
await cfg.option('val1.val2', 0).value.set('val2')
await cfg.option('val1.val2', 1).value.set('val2')
assert await cfg.option('val1.val2', 0).value.get() == 'val2'
assert await cfg.option('val1.val2', 1).value.get() == 'val2'
#
await cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert await cfg.option('val1.val2', 0).value.get() == 'val2'
assert await cfg.option('val1.val2', 1).value.get() == 'val2'
assert await cfg.option('val1.val2', 2).value.get() == 'val'
assert not await list_sessions()
def test_callback_leader_and_followers():
@pytest.mark.asyncio
async def test_callback_leader_and_followers():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_val)
val2 = StrOption('val2', "", Calculation(return_val), multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
assert not await list_sessions()
def test_callback_leader_and_followers_follower_cal(config_type):
@pytest.mark.asyncio
async def test_callback_leader_and_followers_follower_cal(config_type):
val3 = StrOption('val3', "", multi=True)
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
val2 = StrOption('val2', "", multi=True, callback=return_val)
val1 = StrOption('val1', "", Calculation(return_value, Params(ParamOption(val3))), multi=True)
val2 = StrOption('val2', "", Calculation(return_val), multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val3])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
#
assert cfg.option('val3').value.get() == []
assert cfg.option('val1.val1').value.get() == []
#
cfg.option('val1.val1').value.set(['val1'])
cfg.option('val3').value.set(['val1'])
assert cfg.option('val1.val1').value.get() == ['val1']
assert cfg.option('val1.val2', 0).value.get() == 'val'
#
cfg.option('val1.val1').value.reset()
cfg.option('val1.val2', 0).value.set('val')
#
cfg.option('val3').value.set(['val1', 'val2'])
assert cfg.option('val1.val2', 0).value.get() == 'val'
assert cfg.option('val1.val2', 1).value.get() == 'val'
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
# len of follower is higher than leader's one
cfg.option('val1.val2', 0).value.set('val1')
cfg.option('val1.val2', 1).value.set('val2')
if config_type == 'tiramisu-api':
# when "tiramisu-api", raise when set and not in get function
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()")
#
cfg.option('val3').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val2', 2).value.get() == 'val'
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
#
assert await cfg.option('val3').value.get() == []
assert await cfg.option('val1.val1').value.get() == []
#
await cfg.option('val1.val1').value.set(['val1'])
await cfg.option('val3').value.set(['val1'])
assert await cfg.option('val1.val1').value.get() == ['val1']
assert await cfg.option('val1.val2', 0).value.get() == 'val'
#
await cfg.option('val1.val1').value.reset()
await cfg.option('val1.val2', 0).value.set('val')
#
await cfg.option('val3').value.set(['val1', 'val2'])
assert await cfg.option('val1.val2', 0).value.get() == 'val'
assert await cfg.option('val1.val2', 1).value.get() == 'val'
assert await cfg.option('val1.val1').value.get() == ['val1', 'val2']
# len of follower is higher than leader's one
await cfg.option('val1.val2', 0).value.set('val1')
await cfg.option('val1.val2', 1).value.set('val2')
if config_type == 'tiramisu-api':
# when "tiramisu-api", raise when set and not in get function
with pytest.raises(ConfigError):
await cfg.option('val3').value.set(['val1'])
else:
await cfg.option('val3').value.set(['val1'])
assert await cfg.option('val1.val1').value.get() == ['val1']
with pytest.raises(LeadershipError):
await cfg.option('val1.val2', 0).value.get()
#
await cfg.option('val3').value.set(['val1', 'val2', 'val3'])
assert await cfg.option('val1.val2', 0).value.get() == 'val1'
assert await cfg.option('val1.val2', 1).value.get() == 'val2'
assert await cfg.option('val1.val2', 2).value.get() == 'val'
assert not await list_sessions()
def test_callback_leader_and_followers_leader_disabled():
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader_disabled():
#properties must be transitive
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('disabled',))
val1 = StrOption('val1', "", ['val1'], multi=True)
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
interface1 = Leadership('val1', '', [val1, val2], properties=('disabled',))
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('val1.val1').value.get()")
raises(PropertiesOptionError, "cfg.option('val1.val1').value.set(['yes'])")
raises(PropertiesOptionError, "cfg.option('val1.val2', 0).value.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(PropertiesOptionError):
await cfg.option('val1.val1').value.get()
with pytest.raises(PropertiesOptionError):
await cfg.option('val1.val1').value.set(['yes'])
with pytest.raises(PropertiesOptionError):
await cfg.option('val1.val2', 0).value.get()
assert not await list_sessions()
def test_callback_leader_and_followers_leader_callback_disabled():
@pytest.mark.asyncio
async def test_callback_leader_and_followers_leader_callback_disabled():
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
val1 = StrOption('val1', "", Calculation(return_value, Params(ParamOption(val0))), multi=True)
val2 = StrOption('val2', "", multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
cfg = Config(maconfig)
cfg.property.read_write()
raises(ConfigError, "cfg.option('val1.val1').value.get()")
raises(ConfigError, "cfg.option('val1.val2').value.get()")
cfg.property.pop('disabled')
cfg.option('val1.val1').value.set([])
cfg.property.add('disabled')
assert cfg.option('val1.val1').value.get() == []
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(ConfigError):
await cfg.option('val1.val1').value.get()
with pytest.raises(ConfigError):
await cfg.option('val1.val2').value.get()
await cfg.property.pop('disabled')
await cfg.option('val1.val1').value.set([])
await cfg.property.add('disabled')
assert await cfg.option('val1.val1').value.get() == []
assert not await list_sessions()
def test_callback_leader_and_followers_follower_disabled():
@pytest.mark.asyncio
async def test_callback_leader_and_followers_follower_disabled():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, properties=('disabled',))
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
assert cfg.option('val1.val1').value.get() == []
cfg.option('val1.val1').value.set(['yes'])
assert cfg.option('val1.val1').value.get() == ['yes']
cfg.property.pop('disabled')
assert cfg.option('val1.val2', 0).value.get() == None
cfg.option('val1.val2', 0).value.set('no')
cfg.option('val1.val1').value.set(['yes', 'yes2', 'yes3'])
cfg.option('val1.val2', 2).value.set('no1')
assert cfg.option('val1.val2', 0).value.get() == 'no'
assert cfg.option('val1.val2', 1).value.get() == None
assert cfg.option('val1.val2', 2).value.get() == 'no1'
cfg.property.add('disabled')
cfg.option('val1.val1').value.pop(0)
assert cfg.option('val1.val1').value.get() == ['yes2', 'yes3']
cfg.property.pop('disabled')
assert cfg.option('val1.val2', 0).value.get() == None
assert cfg.option('val1.val2', 1).value.get() == 'no1'
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
assert await cfg.option('val1.val1').value.get() == []
await cfg.option('val1.val1').value.set(['yes'])
assert await cfg.option('val1.val1').value.get() == ['yes']
await cfg.property.pop('disabled')
assert await cfg.option('val1.val2', 0).value.get() == None
await cfg.option('val1.val2', 0).value.set('no')
await cfg.option('val1.val1').value.set(['yes', 'yes2', 'yes3'])
await cfg.option('val1.val2', 2).value.set('no1')
assert await cfg.option('val1.val2', 0).value.get() == 'no'
assert await cfg.option('val1.val2', 1).value.get() == None
assert await cfg.option('val1.val2', 2).value.get() == 'no1'
await cfg.property.add('disabled')
await cfg.option('val1.val1').value.pop(0)
assert await cfg.option('val1.val1').value.get() == ['yes2', 'yes3']
await cfg.property.pop('disabled')
assert await cfg.option('val1.val2', 0).value.get() == None
assert await cfg.option('val1.val2', 1).value.get() == 'no1'
assert not await list_sessions()
def test_callback_leader_and_followers_follower_callback_disabled():
@pytest.mark.asyncio
async def test_callback_leader_and_followers_follower_callback_disabled():
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val0))), multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
cfg = Config(maconfig)
cfg.property.read_write()
assert cfg.option('val1.val1').value.get() == []
cfg.option('val1.val1').value.set(['yes'])
assert cfg.option('val1.val1').value.get() == ['yes']
cfg.property.pop('disabled')
cfg.option('val1.val2', 0).value.set('no')
cfg.option('val1.val1').value.set(['yes', 'yes1'])
assert cfg.option('val1.val2', 0).value.get() == 'no'
cfg.property.add('disabled')
cfg.option('val1.val1').value.pop(1)
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
assert await cfg.option('val1.val1').value.get() == []
await cfg.option('val1.val1').value.set(['yes'])
assert await cfg.option('val1.val1').value.get() == ['yes']
await cfg.property.pop('disabled')
await cfg.option('val1.val2', 0).value.set('no')
await cfg.option('val1.val1').value.set(['yes', 'yes1'])
assert await cfg.option('val1.val2', 0).value.get() == 'no'
await cfg.property.add('disabled')
await cfg.option('val1.val1').value.pop(1)
assert not await list_sessions()
def test_callback_leader_and_followers_value():
@pytest.mark.asyncio
async def test_callback_leader_and_followers_value():
val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
val1 = StrOption('val1', "", multi=True)
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')))
val5 = StrOption('val5', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val4)))
val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val5)))
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamOption(val1))), multi=True)
val3 = StrOption('val3', "", Calculation(return_value, Params(ParamValue('yes'))), multi=True)
val5 = StrOption('val5', "", Calculation(return_value, Params(ParamOption(val4))), multi=True)
val6 = StrOption('val6', "", Calculation(return_value, Params(ParamOption(val5))), multi=True)
interface1 = Leadership('val1', '', [val1, val2, val3, val5, val6])
maconfig = OptionDescription('rootconfig', '', [interface1, val4])
cfg = Config(maconfig)
cfg.property.read_write()
cfg.option('val4').value.get() == ['val10', 'val11']
assert cfg.option('val1.val1').value.get() == []
#raises(LeadershipError, "cfg.val1.val1")
#raises(LeadershipError, "cfg.val1.val2")
#raises(LeadershipError, "cfg.val1.val3")
#raises(LeadershipError, "cfg.val1.val5")
#raises(LeadershipError, "cfg.val1.val6")
#
#default calculation has greater length
#raises(LeadershipError, "cfg.option('val1.val1').value.set(['val1']")
#
cfg.option('val1.val1').value.set(['val1', 'val2'])
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val3', 0).value.get() == 'yes'
assert cfg.option('val1.val3', 1).value.get() == 'yes'
raises(LeadershipError, "cfg.option('val1.val5', 0).value.get()")
raises(LeadershipError, "cfg.option('val1.val5', 1).value.get()")
raises(LeadershipError, "cfg.option('val1.val6', 0).value.get()")
raises(LeadershipError, "cfg.option('val1.val6', 1).value.get()")
#
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val2', 2).value.get() == 'val3'
assert cfg.option('val1.val3', 0).value.get() == 'yes'
assert cfg.option('val1.val3', 1).value.get() == 'yes'
assert cfg.option('val1.val3', 2).value.get() == 'yes'
raises(LeadershipError, "cfg.option('val1.val5', 2).value.get()")
raises(LeadershipError, "cfg.option('val1.val6', 2).value.get()")
#
cfg.option('val1.val1').value.pop(2)
assert cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert cfg.option('val1.val2', 0).value.get() == 'val1'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val3', 0).value.get() == 'yes'
assert cfg.option('val1.val3', 1).value.get() == 'yes'
#
cfg.option('val1.val2', 0).value.set('val2')
cfg.option('val1.val2', 1).value.set('val2')
cfg.option('val1.val3', 0).value.set('val2')
cfg.option('val1.val3', 1).value.set('val2')
cfg.option('val1.val5', 0).value.set('val2')
cfg.option('val1.val5', 1).value.set('val2')
assert cfg.option('val1.val2', 0).value.get() == 'val2'
assert cfg.option('val1.val2', 1).value.get() == 'val2'
assert cfg.option('val1.val3', 0).value.get() == 'val2'
assert cfg.option('val1.val3', 1).value.get() == 'val2'
assert cfg.option('val1.val5', 0).value.get() == 'val2'
assert cfg.option('val1.val5', 1).value.get() == 'val2'
assert cfg.option('val1.val6', 0).value.get() == 'val2'
assert cfg.option('val1.val6', 1).value.get() == 'val2'
#
cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert cfg.option('val1.val2', 2).value.get() == 'val3'
assert cfg.option('val1.val3', 2).value.get() == 'yes'
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
await cfg.option('val4').value.get() == ['val10', 'val11']
assert await cfg.option('val1.val1').value.get() == []
#with pytest.raises(LeadershipError):
# await cfg.val1.val1")
#with pytest.raises(LeadershipError):
# await cfg.val1.val2")
#with pytest.raises(LeadershipError):
# await cfg.val1.val3")
#with pytest.raises(LeadershipError):
# await cfg.val1.val5")
#with pytest.raises(LeadershipError):
# await cfg.val1.val6")
#
#default calculation has greater length
#with pytest.raises(LeadershipError):
# await cfg.option('val1.val1').value.set(['val1']")
#
await cfg.option('val1.val1').value.set(['val1', 'val2'])
assert await cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert await cfg.option('val1.val2', 0).value.get() == 'val1'
assert await cfg.option('val1.val2', 1).value.get() == 'val2'
assert await cfg.option('val1.val3', 0).value.get() == 'yes'
assert await cfg.option('val1.val3', 1).value.get() == 'yes'
with pytest.raises(LeadershipError):
await cfg.option('val1.val5', 0).value.get()
with pytest.raises(LeadershipError):
await cfg.option('val1.val5', 1).value.get()
with pytest.raises(LeadershipError):
await cfg.option('val1.val6', 0).value.get()
with pytest.raises(LeadershipError):
await cfg.option('val1.val6', 1).value.get()
#
await cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert await cfg.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
assert await cfg.option('val1.val2', 0).value.get() == 'val1'
assert await cfg.option('val1.val2', 1).value.get() == 'val2'
assert await cfg.option('val1.val2', 2).value.get() == 'val3'
assert await cfg.option('val1.val3', 0).value.get() == 'yes'
assert await cfg.option('val1.val3', 1).value.get() == 'yes'
assert await cfg.option('val1.val3', 2).value.get() == 'yes'
with pytest.raises(LeadershipError):
await cfg.option('val1.val5', 2).value.get()
with pytest.raises(LeadershipError):
await cfg.option('val1.val6', 2).value.get()
#
await cfg.option('val1.val1').value.pop(2)
assert await cfg.option('val1.val1').value.get() == ['val1', 'val2']
assert await cfg.option('val1.val2', 0).value.get() == 'val1'
assert await cfg.option('val1.val2', 1).value.get() == 'val2'
assert await cfg.option('val1.val3', 0).value.get() == 'yes'
assert await cfg.option('val1.val3', 1).value.get() == 'yes'
#
await cfg.option('val1.val2', 0).value.set('val2')
await cfg.option('val1.val2', 1).value.set('val2')
await cfg.option('val1.val3', 0).value.set('val2')
await cfg.option('val1.val3', 1).value.set('val2')
await cfg.option('val1.val5', 0).value.set('val2')
await cfg.option('val1.val5', 1).value.set('val2')
assert await cfg.option('val1.val2', 0).value.get() == 'val2'
assert await cfg.option('val1.val2', 1).value.get() == 'val2'
assert await cfg.option('val1.val3', 0).value.get() == 'val2'
assert await cfg.option('val1.val3', 1).value.get() == 'val2'
assert await cfg.option('val1.val5', 0).value.get() == 'val2'
assert await cfg.option('val1.val5', 1).value.get() == 'val2'
assert await cfg.option('val1.val6', 0).value.get() == 'val2'
assert await cfg.option('val1.val6', 1).value.get() == 'val2'
#
await cfg.option('val1.val1').value.set(['val1', 'val2', 'val3'])
assert await cfg.option('val1.val2', 2).value.get() == 'val3'
assert await cfg.option('val1.val3', 2).value.get() == 'yes'
assert not await list_sessions()
def test_callback_leader():
val2 = StrOption('val2', "", multi=True, callback=return_value)
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
raises(ValueError, "Leadership('val1', '', [val1, val2])")
def test_callback_different_type(config_type):
@pytest.mark.asyncio
async def test_callback_different_type(config_type):
val = IntOption('val', "", default=2)
val_ = IntOption('val_', "", default=3)
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', "", Calculation(return_calc, Params((ParamOption(val), ParamOption(val1)), {'k': ParamOption(val_)})), multi=True)
interface1 = Leadership('val1', '', [val1, val2])
maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val1.val1').value.get() == []
cfg.option('val1.val1').value.set([1])
assert cfg.option('val1.val1').value.get() == [1]
assert cfg.option('val1.val2', 0).value.get() == 6
cfg.option('val1.val1').value.set([1, 3])
assert cfg.option('val1.val1').value.get() == [1, 3]
assert cfg.option('val1.val2', 0).value.get() == 6
assert cfg.option('val1.val2', 1).value.get() == 8
cfg.option('val1.val1').value.set([1, 3, 5])
assert cfg.option('val1.val1').value.get() == [1, 3, 5]
assert cfg.option('val1.val2', 0).value.get() == 6
assert cfg.option('val1.val2', 1).value.get() == 8
assert cfg.option('val1.val2', 2).value.get() == 10
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val1.val1').value.get() == []
await cfg.option('val1.val1').value.set([1])
assert await cfg.option('val1.val1').value.get() == [1]
assert await cfg.option('val1.val2', 0).value.get() == 6
await cfg.option('val1.val1').value.set([1, 3])
assert await cfg.option('val1.val1').value.get() == [1, 3]
assert await cfg.option('val1.val2', 0).value.get() == 6
assert await cfg.option('val1.val2', 1).value.get() == 8
await cfg.option('val1.val1').value.set([1, 3, 5])
assert await cfg.option('val1.val1').value.get() == [1, 3, 5]
assert await cfg.option('val1.val2', 0).value.get() == 6
assert await cfg.option('val1.val2', 1).value.get() == 8
assert await cfg.option('val1.val2', 2).value.get() == 10
assert not await list_sessions()
def test_callback_hidden():
@pytest.mark.asyncio
async def test_callback_hidden():
opt1 = BoolOption('opt1', '')
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
# do not raise, forcepermissive
cfg.option('od2.opt2').value.get()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(PropertiesOptionError):
await cfg.option('od1.opt1').value.get()
# do not raise, forcepermissive
await cfg.option('od2.opt2').value.get()
assert not await list_sessions()
def test_callback_hidden_permissive():
@pytest.mark.asyncio
async def test_callback_hidden_permissive():
opt1 = BoolOption('opt1', '')
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.permissive.set(frozenset(['hidden']))
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
cfg.option('od2.opt2').value.get()
async with await Config(maconfig) as cfg:
await cfg.permissive.add('hidden')
await cfg.property.read_write()
with pytest.raises(PropertiesOptionError):
await cfg.option('od1.opt1').value.get()
await cfg.option('od2.opt2').value.get()
assert not await list_sessions()
def test_callback_hidden_permissive_callback():
@pytest.mark.asyncio
async def test_callback_hidden_permissive_callback():
opt1 = BoolOption('opt1', '')
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1, True)))
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1, True))))
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od1.opt1').value.get()")
cfg.option('od2.opt2').value.get()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(PropertiesOptionError):
await cfg.option('od1.opt1').value.get()
await cfg.option('od2.opt2').value.get()
assert not await list_sessions()
def test_callback_two_disabled():
@pytest.mark.asyncio
async def test_callback_two_disabled():
opt1 = BoolOption('opt1', '', properties=('disabled',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('disabled',))
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('disabled',))
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(PropertiesOptionError):
await cfg.option('od2.opt2').value.get()
assert not await list_sessions()
def test_callback_two_disabled2():
@pytest.mark.asyncio
async def test_callback_two_disabled2():
opt1 = BoolOption('opt1', '', properties=('hidden',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('hidden',))
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('hidden',))
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
assert cfg.forcepermissive.option('od2.opt2').owner.isdefault()
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
await cfg.permissive.add('hidden')
with pytest.raises(PropertiesOptionError):
await cfg.option('od2.opt2').value.get()
assert await cfg.forcepermissive.option('od2.opt2').owner.isdefault()
assert not await list_sessions()
def test_callback_calculating_invalid():
@pytest.mark.asyncio
async def test_callback_calculating_invalid():
opt1 = IntOption('opt1', '', 1)
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_write()
raises(ValueError, "cfg.option('od2.opt2').value.get()")
cfg.unrestraint.option('od2.opt2').property.add('disabled')
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(ValueError):
await cfg.option('od2.opt2').value.get()
await cfg.unrestraint.option('od2.opt2').property.add('disabled')
with pytest.raises(PropertiesOptionError):
await cfg.option('od2.opt2').value.get()
assert not await list_sessions()
def test_callback_calculating_disabled():
@pytest.mark.asyncio
async def test_callback_unrestraint():
opt1 = IntOption('opt1', '', 1)
opt2 = IntOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
od1 = OptionDescription('od1', '', [opt1], properties=('disabled',))
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(ConfigError):
await cfg.option('od2.opt2').value.get()
assert await cfg.unrestraint.option('od2.opt2').value.get() == 1
assert not await list_sessions()
@pytest.mark.asyncio
async def test_callback_calculating_disabled():
opt1 = BoolOption('opt1', '', properties=('disabled',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_write()
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(ConfigError):
await cfg.option('od2.opt2').value.get()
assert not await list_sessions()
def test_callback_calculating_mandatory():
@pytest.mark.asyncio
async def test_callback_calculating_mandatory():
opt1 = BoolOption('opt1', '', properties=('disabled',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('mandatory',))
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('mandatory',))
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_only()
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_only()
with pytest.raises(ConfigError):
await cfg.option('od2.opt2').value.get()
assert not await list_sessions()
def test_callback_calculating_mandatory_multi():
@pytest.mark.asyncio
async def test_callback_calculating_mandatory_multi():
opt1 = BoolOption('opt1', '', multi=True, properties=('disabled',))
opt2 = BoolOption('opt2', '', multi=True, callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('mandatory',))
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('mandatory',), multi=True)
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_only()
raises(ConfigError, "cfg.option('od2.opt2').value.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_only()
with pytest.raises(ConfigError):
await cfg.option('od2.opt2').value.get()
assert not await list_sessions()
def test_callback_two_disabled_multi():
@pytest.mark.asyncio
async def test_callback_two_disabled_multi():
opt1 = BoolOption('opt1', '', properties=('disabled',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('disabled',), multi=True)
opt2 = BoolOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))), properties=('disabled',), multi=True)
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_write()
raises(PropertiesOptionError, "cfg.option('od2.opt2').value.get()")
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
with pytest.raises(PropertiesOptionError):
await cfg.option('od2.opt2').value.get()
assert not await list_sessions()
def test_callback_multi_list_params(config_type):
@pytest.mark.asyncio
async def test_callback_multi_list_params(config_type):
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(ParamOption(val1)))
val2 = StrOption('val2', "", Calculation(return_list, Params(ParamOption(val1))), multi=True, properties=('notunique',))
oval2 = OptionDescription('val2', '', [val2])
maconfig = OptionDescription('rootconfig', '', [val1, oval2])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val2.val2').value.get() == ['val', 'val']
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val2.val2').value.get() == ['val', 'val']
assert not await list_sessions()
def test_callback_multi_list_params_key(config_type):
@pytest.mark.asyncio
async def test_callback_multi_list_params_key(config_type):
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', "", Calculation(return_list, Params(kwargs={'value': ParamOption(val1)})), multi=True, properties=('notunique',))
oval2 = OptionDescription('val2', '', [val2])
maconfig = OptionDescription('rootconfig', '', [val1, oval2])
cfg = Config(maconfig)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.option('val2.val2').value.get() == ['val', 'val']
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.option('val2.val2').value.get() == ['val', 'val']
assert not await list_sessions()
def test_leadership_callback_description(config_type):
@pytest.mark.asyncio
async def test_leadership_callback_description(config_type):
st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(st1)))
st2 = StrOption('st2', "", Calculation(return_value, Params(ParamOption(st1))), multi=True)
stm = Leadership('st1', '', [st1, st2])
st = OptionDescription('st', '', [stm])
od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
cfg = get_config(cfg, config_type)
owner = cfg.owner.get()
assert cfg.option('od.st.st1.st1').value.get() == []
assert cfg.option('od.st.st1.st1').owner.isdefault()
##
cfg.option('od.st.st1.st1').value.set(['yes'])
cfg.option('od.st.st1.st2', 0).value.set('yes')
assert cfg.option('od.st.st1.st1').owner.get() == owner
assert cfg.option('od.st.st1.st2', 0).owner.get() == owner
async with await Config(od2) as cfg:
cfg = await get_config(cfg, config_type)
owner = await cfg.owner.get()
assert await cfg.option('od.st.st1.st1').value.get() == []
assert await cfg.option('od.st.st1.st1').owner.isdefault()
##
await cfg.option('od.st.st1.st1').value.set(['yes'])
await cfg.option('od.st.st1.st2', 0).value.set('yes')
assert await cfg.option('od.st.st1.st1').owner.get() == owner
assert await cfg.option('od.st.st1.st2', 0).owner.get() == owner
assert not await list_sessions()
def test_callback_raise():
opt1 = BoolOption('opt1', 'Option 1', callback=return_raise)
opt2 = BoolOption('opt2', 'Option 2', callback=return_valueerror)
@pytest.mark.asyncio
async def test_callback_raise():
opt1 = BoolOption('opt1', 'Option 1', Calculation(return_raise))
opt2 = BoolOption('opt2', 'Option 2', Calculation(return_valueerror))
od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2])
cfg = Config(maconfig)
cfg.property.read_write()
try:
cfg.option('od1.opt1').value.get()
except ConfigError as err:
assert '"Option 1"' in str(err)
try:
cfg.option('od2.opt2').value.get()
except ConfigError as err:
assert '"Option 2"' in str(err)
async with await Config(maconfig) as cfg:
await cfg.property.read_write()
try:
await cfg.option('od1.opt1').value.get()
except ConfigError as err:
assert '"Option 1"' in str(err)
try:
await cfg.option('od2.opt2').value.get()
except ConfigError as err:
assert '"Option 2"' in str(err)
assert not await list_sessions()
def test_calc_value_simple(config_type):
@pytest.mark.asyncio
async def test_calc_value_simple(config_type):
val1 = StrOption('val1', '', 'val1')
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1)))
val2 = StrOption('val2', '', Calculation(calc_value, Params(ParamOption(val1))))
od = OptionDescription('root', '', [val1, val2])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
assert not await list_sessions()
def test_calc_value_multi(config_type):
@pytest.mark.asyncio
async def test_calc_value_multi(config_type):
val1 = StrOption('val1', "", 'val1')
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', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True))), multi=True)
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']}
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': ['val1', 'val2']}
assert not await list_sessions()
def test_calc_value_disabled():
@pytest.mark.asyncio
async def test_calc_value_disabled():
val1 = StrOption('val1', '', 'val1')
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1, True), default=ParamValue('default_value')))
val2 = StrOption('val2', '', Calculation(calc_value, Params(ParamOption(val1, True), default=ParamValue('default_value'))))
od = OptionDescription('root', '', [val1, val2])
cfg = Config(od)
cfg.property.read_write()
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
cfg.option('val1').property.add('disabled')
assert cfg.value.dict() == {'val2': 'default_value'}
async with await Config(od) as cfg:
await cfg.property.read_write()
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val1'}
await cfg.option('val1').property.add('disabled')
assert await cfg.value.dict() == {'val2': 'default_value'}
assert not await list_sessions()
def test_calc_value_condition(config_type):
@pytest.mark.asyncio
async def test_calc_value_condition(config_type):
boolean = BoolOption('boolean', '', True)
val1 = StrOption('val1', '', 'val1')
val2 = StrOption('val2', '', callback=calc_value, callback_params=Params(ParamOption(val1, True),
default=ParamValue('default_value'),
condition=ParamOption(boolean),
expected=ParamValue(True)))
val2 = StrOption('val2', '', Calculation(calc_value, Params(ParamOption(val1, True),
default=ParamValue('default_value'),
condition=ParamOption(boolean),
expected=ParamValue(True))))
od = OptionDescription('root', '', [boolean, val1, val2])
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'boolean': True, 'val1': 'val1', 'val2': 'val1'}
cfg.option('boolean').value.set(False)
assert cfg.value.dict() == {'boolean': False, 'val1': 'val1', 'val2': 'default_value'}
async with await Config(od) as cfg:
await cfg.property.read_write()
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {'boolean': True, 'val1': 'val1', 'val2': 'val1'}
await cfg.option('boolean').value.set(False)
assert await cfg.value.dict() == {'boolean': False, 'val1': 'val1', 'val2': 'default_value'}
assert not await list_sessions()
def test_calc_value_allow_none(config_type):
@pytest.mark.asyncio
async def test_calc_value_allow_none(config_type):
val1 = StrOption('val1', "", 'val1')
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', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), allow_none=ParamValue(True))), multi=True)
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]}
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {'val1': 'val1', 'val2': None, 'val3': ['val1', None]}
assert not await list_sessions()
def test_calc_value_remove_duplicate(config_type):
@pytest.mark.asyncio
async def test_calc_value_remove_duplicate(config_type):
val1 = StrOption('val1', "", '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', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), multi=ParamValue(True), remove_duplicate_value=ParamValue(True))), multi=True)
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']}
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val1', 'val3': ['val1']}
assert not await list_sessions()
def test_calc_value_join(config_type):
@pytest.mark.asyncio
async def test_calc_value_join(config_type):
val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val2')
val3 = StrOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), join=ParamValue('.')))
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val1.val2'}
val3 = StrOption('val3', "")
val4 = StrOption('val4', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2), ParamOption(val3)), join=ParamValue('.'))))
od = OptionDescription('root', '', [val1, val2, val3, val4])
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': None, 'val4': None}
await cfg.option('val3').value.set('val3')
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'}
assert not await list_sessions()
def test_calc_value_min():
@pytest.mark.asyncio
async def test_calc_value_min():
val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val2')
val3 = StrOption('val3', "", 'val3')
val4 = StrOption('val4', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2), ParamOption(val3, True)), join=ParamValue('.'), min_args_len=ParamValue(3)))
val4 = StrOption('val4', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2), ParamOption(val3, True)), join=ParamValue('.'), min_args_len=ParamValue(3))))
od = OptionDescription('root', '', [val1, val2, val3, val4])
cfg = Config(od)
cfg.property.read_write()
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'}
cfg.option('val3').property.add('disabled')
assert cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val4': ''}
async with await Config(od) as cfg:
await cfg.property.read_write()
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'}
await cfg.option('val3').property.add('disabled')
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val4': ''}
assert not await list_sessions()
def test_calc_value_add(config_type):
@pytest.mark.asyncio
async def test_calc_value_add(config_type):
val1 = IntOption('val1', "", 1)
val2 = IntOption('val2', "", 2)
val3 = IntOption('val3', "", callback=calc_value, callback_params=Params((ParamOption(val1), ParamOption(val2)), operator=ParamValue('add')))
val3 = IntOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), operator=ParamValue('add'))))
od = OptionDescription('root', '', [val1, val2, val3])
cfg = Config(od)
cfg = get_config(cfg, config_type)
assert cfg.value.dict() == {'val1': 1, 'val2': 2, 'val3': 3}
async with await Config(od) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.value.dict() == {'val1': 1, 'val2': 2, 'val3': 3}
assert not await list_sessions()

View File

@ -1,1177 +0,0 @@
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config
from py.test import raises
from tiramisu.setting import owners, groups
from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\
BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, Leadership,\
Config, undefined, Params, ParamOption
from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError
from tiramisu.api import TIRAMISU_VERSION
import warnings
from tiramisu.storage import list_sessions
from tiramisu.i18n import _
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def test_consistency():
a = IntOption('a', '')
b = IntOption('b', '')
a.impl_add_consistency('not_equal', b)
#consistency to itself
raises(ConfigError, "a.impl_add_consistency('not_equal', a)")
def test_consistency_not_exists():
a = IntOption('a', '')
b = IntOption('b', '')
a, b
raises(ConfigError, "a.impl_add_consistency('not_exists', b)")
def test_consistency_unknown_params():
a = IntOption('a', '')
b = IntOption('b', '')
a, b
raises(ValueError, "a.impl_add_consistency('not_equal', b, unknown=False)")
def test_consistency_warnings_only_default():
a = IntOption('a', '', 1)
b = IntOption('b', '', 1)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
a.impl_add_consistency('not_equal', b, warnings_only=True)
assert w != []
def test_consistency_warnings_only(config_type):
a = IntOption('a', '')
b = IntOption('b', '')
c = IntOption('c', '')
od = OptionDescription('od', '', [a, b, c])
a.impl_add_consistency('not_equal', b, warnings_only=True)
cfg = Config(od)
assert cfg.option('a').option.consistencies()
assert not cfg.option('b').option.consistencies()
assert not cfg.option('c').option.consistencies()
cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
cfg.option('b').value.set(1)
assert w != []
def test_consistency_warnings_only_more_option(config_type):
a = IntOption('a', '')
b = IntOption('b', '')
d = IntOption('d', '')
od = OptionDescription('od', '', [a, b, d])
a.impl_add_consistency('not_equal', b, d, warnings_only=True)
cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
cfg.option('b').value.set(1)
assert w != []
assert len(w) == 1
with warnings.catch_warnings(record=True) as w:
cfg.option('d').value.get()
assert w != []
assert len(w) == 1
with warnings.catch_warnings(record=True) as w:
cfg.option('d').value.set(1)
assert w != []
assert len(w) == 1
def test_consistency_error_prefix():
a = IntOption('a', '')
b = IntOption('b', '')
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
cfg = Config(od)
cfg.option('a').value.set(1)
try:
cfg.option('b').value.set(1)
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"')
try:
cfg.option('b').value.set(1)
except Exception as err:
err.prefix = ''
assert str(err) == _('must be different from the value of {}').format('"a"')
def test_consistency_warnings_only_option(config_type):
a = IntOption('a', '')
b = IntOption('b', '', warnings_only=True)
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set(1)
warnings.simplefilter("always", ValueWarning)
with warnings.catch_warnings(record=True) as w:
cfg.option('b').value.set(1)
assert w != []
cfg.option('a').value.reset()
cfg.option('b').value.set(1)
raises(ValueError, "cfg.option('a').value.set(1)")
#
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)
with warnings.catch_warnings(record=True) as w:
cfg.option('a').value.set(1)
assert len(w) == 1
def test_consistency_not_equal(config_type):
a = IntOption('a', '')
b = IntOption('b', '')
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() is None
assert cfg.option('b').value.get() is None
cfg.option('a').value.set(1)
cfg.option('a').value.reset()
cfg.option('a').value.set(1)
raises(ValueError, "cfg.option('b').value.set(1)")
cfg.option('b').value.set(2)
#
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)
with warnings.catch_warnings(record=True) as w:
cfg.option('b').value.set(1)
assert len(w) == 1
def test_consistency_not_equal_many_opts(config_type):
a = IntOption('a', '')
b = IntOption('b', '')
c = IntOption('c', '')
d = IntOption('d', '')
e = IntOption('e', '')
f = IntOption('f', '')
od = OptionDescription('od', '', [a, b, c, d, e, f])
a.impl_add_consistency('not_equal', b, c, d, e, f)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() is None
assert cfg.option('b').value.get() is None
#
cfg.option('a').value.set(1)
cfg.option('a').value.reset()
#
cfg.option('a').value.set(1)
raises(ValueError, "cfg.option('b').value.set(1)")
assert cfg.option('b').value.get() == None
#
cfg.option('b').value.set(2)
raises(ValueError, "cfg.option('f').value.set(2)")
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
#
cfg.option('d').value.set(3)
raises(ValueError, "cfg.option('f').value.set(3)")
raises(ValueError, "cfg.option('a').value.set(3)")
cfg.option('d').value.set(3)
raises(ValueError, "cfg.option('c').value.set(3)")
raises(ValueError, "cfg.option('e').value.set(3)")
#
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)
with warnings.catch_warnings(record=True) as w:
cfg.option('c').value.set(3)
assert len(w) == 1
with warnings.catch_warnings(record=True) as w:
cfg.option('e').value.set(3)
assert len(w) == 1
def test_consistency_not_equal_many_opts_one_disabled(config_type):
a = IntOption('a', '')
b = IntOption('b', '')
c = IntOption('c', '')
d = IntOption('d', '')
e = IntOption('e', '')
f = IntOption('f', '')
g = IntOption('g', '', properties=('disabled',))
od = OptionDescription('od', '', [a, b, c, d, e, f, g])
a.impl_add_consistency('not_equal', b, c, d, e, f, g, transitive=False)
cfg_ori = Config(od)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() is None
assert cfg.option('b').value.get() is None
#
cfg.option('a').value.set(1)
cfg.option('a').value.reset()
#
cfg.option('a').value.set(1)
raises(ValueError, "cfg.option('b').value.set(1)")
#
cfg.option('b').value.set(2)
raises(ValueError, "cfg.option('f').value.set(2)")
raises(ValueError, "cfg.option('f').value.set(1)")
#
cfg.option('d').value.set(3)
raises(ValueError, "cfg.option('f').value.set(3)")
raises(ValueError, "cfg.option('a').value.set(3)")
raises(ValueError, "cfg.option('c').value.set(3)")
raises(ValueError, "cfg.option('e').value.set(3)")
#
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:
cfg.option('c').value.set(3)
assert len(w) == 1
def test_consistency_not_in_config_1():
a = IntOption('a', '')
b = IntOption('b', '')
a.impl_add_consistency('not_equal', b)
od1 = OptionDescription('od1', '', [a])
od = OptionDescription('root', '', [od1])
od
raises(ConfigError, "Config(od)")
def test_consistency_not_in_config_2():
a = IntOption('a', '')
b = IntOption('b', '')
a.impl_add_consistency('not_equal', b)
od1 = OptionDescription('od1', '', [a])
od2 = OptionDescription('od2', '', [b])
od = OptionDescription('root', '', [od1, od2])
Config(od)
def test_consistency_not_in_config_3():
a = IntOption('a', '')
b = IntOption('b', '')
a.impl_add_consistency('not_equal', b)
od1 = OptionDescription('od1', '', [a])
od2 = OptionDescription('od2', '', [b])
od = OptionDescription('root', '', [od1, od2])
od
#with subconfig
raises(ConfigError, "Config(od1)")
def test_consistency_after_config():
a = IntOption('a', '')
b = IntOption('b', '')
od1 = OptionDescription('od1', '', [a])
od2 = OptionDescription('od2', '', [b])
od = OptionDescription('root', '', [od1, od2])
Config(od)
raises(AttributeError, "a.impl_add_consistency('not_equal', b)")
def test_consistency_not_equal_symlink():
a = IntOption('a', '')
b = IntOption('b', '')
c = SymLinkOption('c', a)
od = OptionDescription('od', '', [a, b, c])
a.impl_add_consistency('not_equal', b)
cfg = Config(od)
assert set(od._cache_consistencies.keys()) == set([a, b])
def test_consistency_mix(config_type):
b = IntOption('b', '', multi=True)
c = IntOption('c', '', multi=True)
d = IntOption('d', '', multi=True)
od = Leadership('c', '', [c, d])
od2 = OptionDescription('a', '', [b, od])
c.impl_add_consistency('not_equal', b, d)
cfg_ori = Config(od2)
cfg = get_config(cfg_ori, config_type)
cfg.option('b').value.set([1, 2, 3])
cfg.option('c.c').value.set([4, 5])
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', 1).value.set(4)")
#
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:
cfg.option('c.d', 1).value.set(4)
assert len(w) == 1
def test_consistency_not_equal_submulti():
a = IntOption('a', '', multi=submulti)
b = IntOption('b', '', multi=submulti)
od = OptionDescription('a', '', [a, b])
raises(ConfigError, 'a.impl_add_consistency("not_equal", b)')
def test_consistency_not_equal_default_submulti():
a = IntOption('a', '', [[1, 2]], multi=submulti)
b = IntOption('b', '', [[1]], multi=submulti)
od = OptionDescription('od', '', [a, b])
od
raises(ConfigError, "a.impl_add_consistency('not_equal', b)")
def test_consistency_not_equal_leadership(config_type):
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od])
a.impl_add_consistency('not_equal', b)
cfg = Config(od2)
cfg = get_config(cfg, config_type)
assert cfg.option('a.a').value.get() == []
cfg.option('a.a').value.set([1])
cfg.option('a.a').value.reset()
cfg.option('a.a').value.set([1])
raises(ValueError, "cfg.option('a.b', 0).value.set(1)")
cfg.option('a.b', 0).value.set(2)
cfg.option('a.a').value.reset()
cfg.option('a.a').value.set([1])
cfg.value.dict()
def test_consistency_not_equal_leadership_error_multi1():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = NetmaskOption('c', '', multi=True)
od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od, c])
c.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od2)")
def test_consistency_not_equal_leadership_error_multi2():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = IPOption('c', '', multi=True)
od = Leadership('a', '', [a, b])
od2 = OptionDescription('b', '', [od, c])
b.impl_add_consistency('ip_netmask', c)
raises(ConfigError, "Config(od2)")
def test_consistency_ip_netmask_leadership_error_not_leader():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = OptionDescription('a', '', [a, b])
od2 = OptionDescription('b', '', [od])
b.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od2)")
def test_consistency_ip_netmask_leadership_error_leader_and_not():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = IPOption('c', '', multi=True)
d = NetmaskOption('d', '', multi=True)
od = Leadership('a', '', [a, b])
od2 = OptionDescription('c', '', [c, d])
od3 = OptionDescription('b', '', [od, od2])
d.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od3)")
def test_consistency_ip_netmask_leadership_error_otherleader():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = IPOption('c', '', multi=True)
d = NetmaskOption('d', '', multi=True)
od = Leadership('a', '', [a, b])
od2 = Leadership('c', '', [c, d])
od3 = OptionDescription('b', '', [od, od2])
d.impl_add_consistency('ip_netmask', a)
raises(ConfigError, "Config(od2)")
def test_consistency_not_equal_leadership_default():
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True, default_multi=1)
od = Leadership('a', '', [a, b])
od2 = OptionDescription('a', '', [od])
a.impl_add_consistency('not_equal', b)
cfg = Config(od2)
# FIXME cfg = get_config(cfg, config_type)
assert cfg.option('a.a').value.get() == []
raises(ValueError, "cfg.option('a.a').value.set([1])")
cfg.option('a.a').value.set([2])
cfg.option('a.a').value.reset()
#
cfg.property.add('demoting_error_warning')
with warnings.catch_warnings(record=True) as w:
cfg.option('a.a').value.set([1])
assert len(w) == 1
def test_consistency_not_equal_multi(config_type):
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True)
od = OptionDescription('a', '', [a, b])
a.impl_add_consistency('not_equal', b)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() == []
assert cfg.option('b').value.get() == []
cfg.option('a').value.set([1])
cfg.option('a').value.reset()
cfg.option('a').value.set([1])
raises(ValueError, "cfg.option('b').value.set([1])")
cfg.option('a').value.set([2])
raises(ValueError, "cfg.option('b').value.set([2, 1])")
cfg.option('a').value.set([2, 3])
raises(ValueError, "cfg.option('a').value.set([2, 3, 3])")
raises(ValueError, "cfg.option('b').value.set([2, 3])")
#
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:
cfg.option('b').value.set([2, 3])
assert len(w) == 1
def test_consistency_not_equal_multi_default1():
a = IntOption('a', '', multi=True, default=[1])
b = IntOption('b', '', multi=True, default=[3, 1])
od = OptionDescription('a', '', [a, b])
raises(ValueError, "b.impl_add_consistency('not_equal', a)")
def test_consistency_not_equal_multi_default2():
a = IntOption('a', '', multi=True, default=[1])
b = IntOption('b', '', multi=True, default_multi=1)
od = OptionDescription('a', '', [a, b])
#default_multi not tested now
a.impl_add_consistency('not_equal', b)
def test_consistency_not_equal_leader_default(config_type):
a = IntOption('a', '', multi=True, default=[2, 1])
b = IntOption('b', '', multi=True, default_multi=1)
od = Leadership('a', '', [a, b])
a.impl_add_consistency('not_equal', b)
od2 = OptionDescription('a', '', [od])
cfg = Config(od2)
cfg = get_config(cfg, config_type)
# default_multi not tested
raises(ValueError, "cfg.option('a.b', 0).value.get()")
cfg.option('a.b', 0).value.set(3)
cfg.option('a.b', 1).value.set(3)
assert cfg.option('a.b', 1).value.get() == 3
def test_consistency_not_equal_multi_default_modif(config_type):
a = IntOption('a', '', multi=True)
b = IntOption('b', '', multi=True, default=[1, 2])
od = OptionDescription('a', '', [a, b])
a.impl_add_consistency('not_equal', b)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a').value.get() == []
assert cfg.option('b').value.get() == [1, 2]
raises(ValueError, "cfg.option('a').value.set([1])")
raises(ValueError, "cfg.option('b').value.set([1, 2, 1])")
#
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:
cfg.option('b').value.set([1, 2, 1])
assert len(w) == 1
def test_consistency_default():
a = IntOption('a', '', 1)
b = IntOption('b', '', 1)
a, b
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
def test_consistency_default_multi():
a = IntOption('a', '', [2, 1], multi=True)
b = IntOption('b', '', [1, 1], multi=True)
c = IntOption('c', '', [1, 2], multi=True)
b
raises(ValueError, "a.impl_add_consistency('not_equal', b)")
if TIRAMISU_VERSION != 2:
raises(ValueError, "a.impl_add_consistency('not_equal', c)")
def test_consistency_default_diff():
a = IntOption('a', '', 3)
b = IntOption('b', '', 1)
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
cfg = Config(od)
# FIXME cfg = get_config(cfg, config_type)
raises(ValueError, "cfg.option('a').value.set(1)")
cfg.option('a').value.set(2)
cfg.option('b').value.set(3)
owner = cfg.owner.get()
assert cfg.option('a').owner.get() == owner
raises(ValueError, "cfg.option('a').value.reset()")
assert cfg.option('a').owner.get() == owner
#
cfg.property.add('demoting_error_warning')
with warnings.catch_warnings(record=True) as w:
cfg.option('a').value.reset()
assert len(w) == 1
def test_consistency_ip_netmask(config_type):
a = IPOption('a', '')
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
cfg_ori = Config(od)
cfg = cfg_ori
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set('192.168.1.1')
cfg.option('b').value.set('255.255.255.0')
cfg.option('a').value.set('192.168.1.2')
cfg.option('b').value.set('255.255.255.128')
cfg.option('b').value.set('255.255.255.0')
raises(ValueError, "cfg.option('a').value.set('192.168.1.0')")
raises(ValueError, "cfg.option('a').value.set('192.168.1.255')")
cfg.option('a').value.reset()
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')")
#
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:
cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1
def test_consistency_ip_netmask_invalid():
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [b])
raises(ConfigError, "b.impl_add_consistency('ip_netmask')")
def test_consistency_network_netmask(config_type):
a = NetworkOption('a', '')
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('network_netmask', a)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set('192.168.1.1')
cfg.option('b').value.set('255.255.255.255')
cfg.option('b').value.reset()
cfg.option('a').value.set('192.168.1.0')
cfg.option('b').value.set('255.255.255.0')
raises(ValueError, "cfg.option('a').value.set('192.168.1.1')")
#
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:
cfg.option('a').value.set('192.168.1.1')
assert len(w) == 1
def test_consistency_network_netmask_invalid():
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [b])
raises(ConfigError, "b.impl_add_consistency('network_netmask')")
def test_consistency_ip_in_network(config_type):
a = NetworkOption('a', '')
b = NetmaskOption('b', '')
c = IPOption('c', '')
d = IPOption('d', '')
od = OptionDescription('od', '', [a, b, c, d])
c.impl_add_consistency('in_network', a, b)
d.impl_add_consistency('in_network', a, b, warnings_only=True)
warnings.simplefilter("always", ValueWarning)
cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('a').value.set('192.168.1.0')
cfg.option('b').value.set('255.255.255.0')
cfg.option('c').value.set('192.168.1.1')
raises(ValueError, "cfg.option('c').value.set('192.168.2.1')")
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:
cfg.option('d').value.set('192.168.2.1')
assert len(w) == 1
def test_consistency_ip_in_network_cidr(config_type):
a = NetworkOption('a', '', cidr=True)
c = IPOption('c', '')
d = IPOption('d', '')
od = OptionDescription('od', '', [a, c, d])
c.impl_add_consistency('in_network', a)
d.impl_add_consistency('in_network', a, warnings_only=True)
warnings.simplefilter("always", ValueWarning)
cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('a').value.set('192.168.1.0/24')
cfg.option('c').value.set('192.168.1.1')
raises(ValueError, "cfg.option('c').value.set('192.168.2.1')")
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:
cfg.option('d').value.set('192.168.2.1')
assert len(w) == 1
def test_consistency_ip_in_network_invalid():
a = NetworkOption('a', '')
b = NetmaskOption('b', '')
c = IPOption('c', '')
d = IPOption('d', '')
od = OptionDescription('od', '', [a, b, c, d])
raises(ConfigError, "c.impl_add_consistency('in_network', a)")
def test_consistency_ip_netmask_error_multi():
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '')
OptionDescription('od', '', [a, b])
raises(ConfigError, "b.impl_add_consistency('ip_netmask', a)")
def test_consistency_ip_netmask_multi(config_type):
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od])
cfg_ori = Config(od2)
cfg = get_config(cfg_ori, config_type)
cfg.option('a.a').value.set(['192.168.1.1'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.a').value.set(['192.168.1.2'])
cfg.option('a.b', 0).value.set('255.255.255.128')
cfg.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.0'])")
#
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:
cfg.option('a.a').value.set(['192.168.1.0'])
assert len(w) == 1
def test_consistency_network_netmask_multi(config_type):
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od', '', [od])
cfg = Config(od2)
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set(['192.168.1.1'])
cfg.option('a.b', 0).value.set('255.255.255.255')
cfg.option('a.b', 0).value.reset()
cfg.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.1'])")
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',))
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b])
od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a)
cfg = Config(od2)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set([undefined])
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(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', default_multi=u'255.255.255.0', multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
cfg_ori = Config(od2)
cfg_ori.property.read_write()
cfg_ori.property.pop('cache')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a.a').value.get() == []
cfg.option('a.a').value.set(['192.168.1.0'])
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a.a').value.get() == [u'192.168.1.0']
assert cfg.option('a.b', 0).value.get() == u'255.255.255.0'
if config_type == 'tiramisu-api':
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):
return u'255.255.255.0'
def return_netmask2(leader):
if leader is not None:
if leader.endswith('2.1'):
return u'255.255.255.0'
if not leader.endswith('.0'):
return u'255.255.255.255'
return u'255.255.255.0'
def test_consistency_network_netmask_multi_follower_callback(config_type):
a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask, multi=True, properties=('mandatory',))
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
cfg_ori = Config(od2)
cfg_ori.property.read_write()
cfg_ori.property.pop('cache')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a.a').value.get() == []
cfg.option('a.a').value.set(['192.168.1.0'])
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.property.read_only()
cfg = get_config(cfg_ori, config_type)
assert cfg.option('a.a').value.get() == [u'192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
if config_type == 'tiramisu-api':
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(config_type):
a = NetworkOption('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])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
cfg = Config(od2)
cfg.property.read_write()
cfg.property.pop('cache')
cfg = get_config(cfg, config_type)
assert cfg.option('a.a').value.get() == []
cfg.option('a.a').value.set(['192.168.1.0'])
assert cfg.option('a.a').value.get() == ['192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.0', '192.168.2.1'])")
assert cfg.option('a.a').value.get() == [u'192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
raises(ValueError, "cfg.option('a.a').value.set(['192.168.2.1'])")
assert cfg.option('a.a').value.get() == [u'192.168.1.0']
assert cfg.option('a.b', 0).value.get() == '255.255.255.0'
cfg.option('a.a').value.set(['192.168.1.0', '192.168.1.1'])
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(config_type):
a = IPOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
od2 = OptionDescription('od2', '', [od])
cfg = Config(od2)
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set(['192.168.1.1'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.a').value.set(['192.168.1.2'])
cfg.option('a.b', 0).value.set('255.255.255.128')
cfg.option('a.b', 0).value.set('255.255.255.0')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.0'])")
cfg.option('a.a').value.set(['192.168.1.128'])
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(config_type):
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
cfg = Config(od2)
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set(['192.168.1.1'])
cfg.option('a.b', 0).value.set('255.255.255.255')
cfg.option('a.b', 0).value.reset()
cfg.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.1'])")
def test_consistency_broadcast(config_type):
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True)
od = Leadership('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a, b)
od2 = OptionDescription('od2', '', [od])
cfg = Config(od2)
cfg = get_config(cfg, config_type)
#first, test network_netmask
cfg.option('a.a').value.set(['192.168.1.128'])
raises(ValueError, "cfg.option('a.a').value.set(['255.255.255.0'])")
#
cfg.option('a.a').value.set(['192.168.1.0'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.c', 0).value.set('192.168.1.255')
raises(ValueError, "cfg.option('a.a').value.set(['192.168.1.1'])")
#
cfg.option('a.a').value.set(['192.168.1.0', '192.168.2.128'])
cfg.option('a.b', 0).value.set('255.255.255.0')
cfg.option('a.b', 1).value.set('255.255.255.128')
cfg.option('a.c', 0).value.set('192.168.1.255')
cfg.option('a.c', 1).value.set('192.168.2.255')
raises(ValueError, "cfg.option('a.c', 1).value.set('192.168.2.128')")
cfg.option('a.c', 1).value.set('192.168.2.255')
def test_consistency_broadcast_error(config_type):
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True)
od = Leadership('a', '', [a, b, c])
od2 = OptionDescription('od2', '', [od])
b.impl_add_consistency('network_netmask', a)
c.impl_add_consistency('broadcast', a)
cfg = Config(od2)
cfg = get_config(cfg, config_type)
raises(ConfigError, "cfg.option('a.a').value.set(['192.168.1.0'])")
def test_consistency_broadcast_warnings(config_type):
warnings.simplefilter("always", ValueWarning)
a = NetworkOption('a', '', properties=('mandatory', 'disabled'))
b = NetmaskOption('b', '', properties=('mandatory', 'disabled'))
c = NetmaskOption('c', '', properties=('mandatory', 'disabled'))
od = OptionDescription('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a, warnings_only=True)
cfg_ori = Config(od)
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
cfg.option('a').value.set('192.168.1.4')
cfg.option('b').value.set('255.255.255.0')
assert len(w) == 1
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:
list(cfg.value.mandatory())
assert len(w) == 0
def test_consistency_broadcast_default_1():
a = NetworkOption('a', '', '192.168.1.0')
b = NetmaskOption('b', '', '255.255.255.128')
c = BroadcastOption('c', '', '192.168.2.127')
od = OptionDescription('a', '', [a, b, c])
od
raises(ValueError, "c.impl_add_consistency('broadcast', a, b)")
def test_consistency_broadcast_default_2():
a = NetworkOption('a', '', '192.168.1.0')
b = NetmaskOption('b', '', '255.255.255.128')
d = BroadcastOption('d', '', '192.168.1.127')
od2 = OptionDescription('a', '', [a, b, d])
od2
d.impl_add_consistency('broadcast', a, b)
def test_consistency_not_all(config_type):
#_cache_consistencies is not None by not options has consistencies
a = NetworkOption('a', '', multi=True)
b = NetmaskOption('b', '', multi=True)
c = BroadcastOption('c', '', multi=True)
od = Leadership('a', '', [a, b, c])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
cfg = Config(od2)
cfg = get_config(cfg, config_type)
cfg.option('a.a').value.set(['192.168.1.0'])
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(config_type):
a = IntOption('a', '', 1)
b = IntOption('b', '', 2, properties=('hidden',))
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
cfg = Config(od)
cfg.property.read_write()
cfg.permissive.set(frozenset(['hidden']))
cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
def test_consistency_disabled(config_type):
a = IntOption('a', '')
b = IntOption('b', '', properties=('disabled',))
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
raises(PropertiesOptionError, "cfg.option('a').value.set(1)")
def test_consistency_disabled_transitive(config_type):
a = IntOption('a', '')
b = IntOption('b', '', properties=('disabled',))
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b, transitive=False)
cfg = Config(od)
cfg.property.read_write()
cfg = get_config(cfg, config_type)
cfg.option('a').value.set(1)
def test_consistency_disabled_transitive_2(config_type):
a = IPOption('a', '')
b = IPOption('b', '')
c = NetworkOption('c', '', default='192.168.1.0')
d = NetmaskOption('d', '', default='255.255.255.0', properties=('disabled',))
od = OptionDescription('od', '', [a, b, c, d])
a.impl_add_consistency('not_equal', b)
a.impl_add_consistency('in_network', c, d, transitive=False)
cfg_ori = Config(od)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set('192.168.1.1')
raises(ValueError, "cfg.option('b').value.set('192.168.1.1')")
cfg.option('a').value.set('192.168.2.1')
#
cfg.option('a').value.set('192.168.1.1')
if config_type == 'tiramisu-api':
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')")
#
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:
cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1
def return_val(*args, **kwargs):
return '192.168.1.1'
def test_consistency_with_callback(config_type):
a = NetworkOption('a', '', default='192.168.1.0')
b = NetmaskOption('b', '', default='255.255.255.0')
c = IPOption('c', '', callback=return_val, callback_params=Params(ParamOption(a)))
od = OptionDescription('od', '', [a, b, c])
c.impl_add_consistency('in_network', a, b)
cfg = Config(od)
cfg = get_config(cfg, config_type)
cfg.option('c').value.get()
def test_consistency_warnings_only_options(config_type):
a = IPOption('a', '', warnings_only=True)
b = IPOption('b', '')
c = NetworkOption('c', '', default='192.168.1.0')
d = NetmaskOption('d', '', default='255.255.255.0', properties=('disabled',))
od = OptionDescription('od', '', [a, b, c, d])
a.impl_add_consistency('not_equal', b)
a.impl_add_consistency('in_network', c, d, transitive=False)
cfg_ori = Config(od)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('a').value.set('192.168.1.1')
raises(ValueError, "cfg.option('b').value.set('192.168.1.1')")
cfg.option('a').value.set('192.168.2.1')
#
cfg.option('a').value.set('192.168.1.1')
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:
cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1
def test_consistency_warnings_only_options_callback(config_type):
a = IPOption('a', '', warnings_only=True)
b = IPOption('b', '')
c = NetworkOption('c', '', default='192.168.1.0')
d = NetmaskOption('d', '', callback=return_netmask2, callback_params=Params(ParamOption(c)))
od = OptionDescription('od', '', [a, b, c, d])
a.impl_add_consistency('not_equal', b)
a.impl_add_consistency('in_network', c, d, transitive=False)
cfg_ori = Config(od)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
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:
cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1
#
cfg.option('a').value.set('192.168.1.1')
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:
cfg.option('a').value.set('192.168.2.1')
assert len(w) == 1
def test_consistency_double_warnings(config_type):
a = IntOption('a', '')
b = IntOption('b', '', 1)
c = IntOption('c', '', 1)
od = OptionDescription('od', '', [a, b, c])
warnings.simplefilter("always", ValueWarning)
a.impl_add_consistency('not_equal', b, warnings_only=True)
a.impl_add_consistency('not_equal', c, warnings_only=True)
od2 = OptionDescription('od2', '', [od])
cfg_ori = Config(od2)
cfg = get_config(cfg_ori, config_type)
with warnings.catch_warnings(record=True) as w:
cfg.option('od.a').value.set(1)
assert w != []
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:
cfg.option('od.c').value.set(2)
assert len(w) == 0
with warnings.catch_warnings(record=True) as w:
cfg.option('od.a').value.set(2)
assert len(w) == 1
#
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:
cfg.option('od.a').value.set(1)
assert w == []
def test_consistency_warnings_error(config_type):
a = IntOption('a', '')
b = IntOption('b', '', 1)
c = IntOption('c', '', 1)
od = OptionDescription('od', '', [a, b, c])
warnings.simplefilter("always", ValueWarning)
a.impl_add_consistency('not_equal', b, warnings_only=True)
a.impl_add_consistency('not_equal', c)
cfg = Config(od)
cfg = get_config(cfg, config_type)
with warnings.catch_warnings(record=True) as w:
raises(ValueError, "cfg.option('a').value.set(1)")
assert w == []
def test_consistency_network_netmask_mandatory(config_type):
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')
od = Leadership('a', '', [a, b])
b.impl_add_consistency('network_netmask', a)
od2 = OptionDescription('od2', '', [od])
cfg = Config(od2)
cfg.property.read_only()
cfg.property.pop('mandatory')
cfg = get_config(cfg, config_type)
cfg.value.dict()
def test_consistency_has_dependency():
a = IPOption('a', '')
b = NetmaskOption('b', '')
od = OptionDescription('od', '', [a, b])
b.impl_add_consistency('ip_netmask', a)
cfg = Config(od)
assert cfg.option('a').option.has_dependency() is True
assert cfg.option('b').option.has_dependency() is True
assert cfg.option('a').option.has_dependency(False) is True
assert cfg.option('b').option.has_dependency(False) is True
def test_consistency_not_equal_has_dependency():
a = IntOption('a', '')
b = IntOption('b', '')
od = OptionDescription('od', '', [a, b])
a.impl_add_consistency('not_equal', b)
cfg = Config(od)
assert cfg.option('a').option.has_dependency() is False
assert cfg.option('b').option.has_dependency() is False
assert cfg.option('a').option.has_dependency(False) is True
assert cfg.option('b').option.has_dependency(False) is True

View File

@ -1,24 +1,19 @@
"test all types of option default values for options, add new option in a descr"
from .autopath import do_autopath
do_autopath()
from .config import config_type, get_config
from py.test import raises
import pytest
from tiramisu.setting import owners
from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.error import PropertiesOptionError, ConfigError, LeadershipError
from tiramisu import IntOption, FloatOption, StrOption, ChoiceOption, \
BoolOption, OptionDescription, Leadership, Config, undefined
BoolOption, OptionDescription, Leadership, Config, undefined, delete_session
from tiramisu.storage import list_sessions
from .config import config_type, get_config, event_loop
owners.addowner("frozenmultifollower")
def teardown_function(function):
assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
def make_description():
gcoption = ChoiceOption('name', 'GC name', ['ref', 'framework'], 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
@ -45,7 +40,8 @@ def make_description():
#____________________________________________________________
# default values
def test_default_is_none(config_type):
@pytest.mark.asyncio
async def test_default_is_none(config_type):
"""
Most constructors take a ``default`` argument that specifies the default
value of the option. If this argument is not supplied the default value is
@ -54,210 +50,245 @@ def test_default_is_none(config_type):
dummy1 = BoolOption('dummy1', 'doc dummy')
dummy2 = BoolOption('dummy2', 'doc dummy')
group = OptionDescription('group', '', [dummy1, dummy2])
cfg = Config(group)
cfg = get_config(cfg, config_type)
# so when the default value is not set, there is actually a default value
assert cfg.option('dummy1').value.get() is None
assert cfg.option('dummy2').value.get() is None
async with await Config(group) as cfg:
cfg = await get_config(cfg, config_type)
# so when the default value is not set, there is actually a default value
assert await cfg.option('dummy1').value.get() is None
assert await cfg.option('dummy2').value.get() is None
assert not await list_sessions()
def test_set_defaut_value_from_option_object():
@pytest.mark.asyncio
async def test_set_defaut_value_from_option_object():
"""Options have an available default setting and can give it back"""
b = BoolOption("boolean", "", default=False)
assert b.impl_getdefault() is False
assert not await list_sessions()
def test_force_default_on_freeze():
@pytest.mark.asyncio
async def test_force_default_on_freeze():
"a frozen option wich is forced returns his default"
dummy1 = BoolOption('dummy1', 'doc dummy', default=False, properties=('force_default_on_freeze',))
dummy2 = BoolOption('dummy2', 'doc dummy', default=True)
group = OptionDescription('group', '', [dummy1, dummy2])
cfg_ori = Config(group)
cfg_ori.property.read_write()
cfg = cfg_ori
# FIXME cfg = get_config(cfg_ori, config_type)
owner = cfg.owner.get()
cfg.option('dummy1').value.set(True)
cfg.option('dummy2').value.set(False)
assert cfg.option('dummy1').owner.get() == owner
assert cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# cfg.send()
cfg_ori.option('dummy1').property.add('frozen')
cfg_ori.option('dummy2').property.add('frozen')
# cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1').value.get() is False
assert cfg.option('dummy2').value.get() is False
assert cfg.option('dummy1').owner.isdefault()
assert cfg.option('dummy2').owner.get() == owner
# 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')")
async with await Config(group) as cfg_ori:
await cfg_ori.property.read_write()
cfg = cfg_ori
# FIXME cfg = await get_config(cfg_ori, config_type)
owner = await cfg.owner.get()
await cfg.option('dummy1').value.set(True)
await cfg.option('dummy2').value.set(False)
assert await cfg.option('dummy1').owner.get() == owner
assert await cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# await cfg.send()
await cfg_ori.option('dummy1').property.add('frozen')
await cfg_ori.option('dummy2').property.add('frozen')
# cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy1').value.get() is False
assert await cfg.option('dummy2').value.get() is False
assert await cfg.option('dummy1').owner.isdefault()
assert await cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# await cfg.send()
with pytest.raises(PropertiesOptionError):
await cfg_ori.option('dummy2').owner.set('frozen')
# cfg = await get_config(cfg_ori, config_type)
with pytest.raises(PropertiesOptionError):
await cfg.option('dummy1').value.reset()
# if config_type == 'tiramisu-api':
# await cfg.send()
await cfg_ori.option('dummy1').property.pop('frozen')
# cfg = await get_config(cfg_ori, config_type)
await cfg.option('dummy1').value.reset()
# if config_type == 'tiramisu-api':
# await cfg.send()
await cfg.option('dummy1').property.add('frozen')
# cfg = await get_config(cfg_ori, config_type)
with pytest.raises(PropertiesOptionError):
await cfg.option('dummy2').owner.set('frozen')
assert not await list_sessions()
def test_force_default_on_freeze_multi():
@pytest.mark.asyncio
async def test_force_default_on_freeze_multi():
dummy1 = BoolOption('dummy1', 'doc dummy', default=[False], properties=('force_default_on_freeze',), multi=True)
dummy2 = BoolOption('dummy2', 'doc dummy', default=[True], multi=True)
group = OptionDescription('group', '', [dummy1, dummy2])
cfg_ori = Config(group)
cfg_ori.property.read_write()
cfg = cfg_ori
# FIXME cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1').value.set([undefined, True])
cfg.option('dummy2').value.set([undefined, False])
owner = cfg.owner.get()
assert cfg.option('dummy1').owner.get() == owner
assert cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# cfg.send()
cfg_ori.option('dummy1').property.add('frozen')
cfg_ori.option('dummy2').property.add('frozen')
# cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1').value.get() == [False]
assert cfg.option('dummy2').value.get() == [True, False]
assert cfg.option('dummy1').owner.isdefault()
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()
async with await Config(group) as cfg_ori:
await cfg_ori.property.read_write()
cfg = cfg_ori
# FIXME cfg = await get_config(cfg_ori, config_type)
await cfg.option('dummy1').value.set([undefined, True])
await cfg.option('dummy2').value.set([undefined, False])
owner = await cfg.owner.get()
assert await cfg.option('dummy1').owner.get() == owner
assert await cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# await cfg.send()
await cfg_ori.option('dummy1').property.add('frozen')
await cfg_ori.option('dummy2').property.add('frozen')
# cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy1').value.get() == [False]
assert await cfg.option('dummy2').value.get() == [True, False]
assert await cfg.option('dummy1').owner.isdefault()
assert await cfg.option('dummy2').owner.get() == owner
# if config_type == 'tiramisu-api':
# await cfg.send()
with pytest.raises(PropertiesOptionError):
await cfg_ori.option('dummy2').owner.set('owner')
# cfg = await get_config(cfg_ori, config_type)
with pytest.raises(PropertiesOptionError):
await cfg.option('dummy2').value.reset()
# if config_type == 'tiramisu-api':
# await cfg.send()
await cfg_ori.option('dummy1').property.pop('frozen')
# cfg = await get_config(cfg_ori, config_type)
await cfg.option('dummy1').value.reset()
assert not await list_sessions()
def test_force_default_on_freeze_leader():
@pytest.mark.asyncio
async def test_force_default_on_freeze_leader():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze',))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
raises(ConfigError, "Config(descr)")
with pytest.raises(ConfigError):
await Config(descr, session_id='error')
await delete_session('error')
assert not await list_sessions()
def test_force_metaconfig_on_freeze_leader():
@pytest.mark.asyncio
async def test_force_metaconfig_on_freeze_leader():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_metaconfig_on_freeze',))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
raises(ConfigError, "Config(descr)")
with pytest.raises(ConfigError):
await Config(descr, session_id='error')
await delete_session('error')
assert not await list_sessions()
def test_force_default_on_freeze_leader_frozen():
@pytest.mark.asyncio
async def test_force_default_on_freeze_leader_frozen():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_default_on_freeze', 'frozen'))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
cfg = Config(descr)
raises(ConfigError, "cfg.option('dummy1.dummy1').property.pop('frozen')")
async with await Config(descr) as cfg:
with pytest.raises(LeadershipError):
await cfg.option('dummy1.dummy1').property.pop('frozen')
assert not await list_sessions()
def test_force_metaconfig_on_freeze_leader_frozen():
@pytest.mark.asyncio
async def test_force_metaconfig_on_freeze_leader_frozen():
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('force_metaconfig_on_freeze', 'frozen'))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True)
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
cfg = Config(descr)
raises(ConfigError, "cfg.option('dummy1.dummy1').property.pop('frozen')")
async with await Config(descr) as cfg:
with pytest.raises(LeadershipError):
await cfg.option('dummy1.dummy1').property.pop('frozen')
assert not await list_sessions()
def test_force_default_on_freeze_follower(config_type):
dummy1 = BoolOption('dummy1', 'Test int option', multi=True)
@pytest.mark.asyncio
async def test_force_default_on_freeze_follower(config_type):
dummy1 = BoolOption('dummy1', 'Test int option', multi=True, properties=('notunique',))
dummy2 = BoolOption('dummy2', 'Test string option', multi=True, properties=('force_default_on_freeze',))
descr = Leadership("dummy1", "", [dummy1, dummy2])
descr = OptionDescription("root", "", [descr])
cfg_ori = Config(descr)
cfg_ori.property.read_write()
cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1.dummy1').value.set([True])
cfg.option('dummy1.dummy2', 0).value.set(False)
assert cfg.option('dummy1.dummy1').value.get() == [True]
assert cfg.option('dummy1.dummy2', 0).value.get() == False
assert cfg.option('dummy1.dummy1').owner.get() == 'user'
assert cfg.option('dummy1.dummy2', 0).owner.get() == 'user'
#
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('dummy1.dummy2').property.add('frozen')
cfg = get_config(cfg_ori, config_type)
assert cfg.option('dummy1.dummy1').value.get() == [True]
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)
#
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('dummy1.dummy2').property.pop('frozen')
cfg = get_config(cfg_ori, config_type)
cfg.option('dummy1.dummy1').value.set([True, True])
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
#
if config_type == 'tiramisu-api':
cfg.send()
cfg_ori.option('dummy1.dummy2').property.add('frozen')
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
#
cfg.option('dummy1.dummy1').value.pop(1)
assert cfg.option('dummy1.dummy1').value.get() == [True]
assert cfg.option('dummy1.dummy2', 0).value.get() == None
#
if config_type == 'tiramisu-api':
cfg.send()
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
#
cfg.option('dummy1.dummy1').value.set([True, True])
assert cfg.option('dummy1.dummy2', 0).value.get() == False
assert cfg.option('dummy1.dummy2', 1).value.get() == None
async with await Config(descr) as cfg_ori:
await cfg_ori.property.read_write()
cfg = await get_config(cfg_ori, config_type)
await cfg.option('dummy1.dummy1').value.set([True])
await cfg.option('dummy1.dummy2', 0).value.set(False)
assert await cfg.option('dummy1.dummy1').value.get() == [True]
assert await cfg.option('dummy1.dummy2', 0).value.get() == False
assert await cfg.option('dummy1.dummy1').owner.get() == 'user'
assert await cfg.option('dummy1.dummy2', 0).owner.get() == 'user'
#
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.option('dummy1.dummy2').property.add('frozen')
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy1.dummy1').value.get() == [True]
assert await cfg.option('dummy1.dummy2', 0).value.get() == None
assert await cfg.option('dummy1.dummy1').owner.get() == 'user'
assert await cfg.option('dummy1.dummy2', 0).owner.isdefault()
if config_type == 'tiramisu-api':
await cfg.send()
with pytest.raises(PropertiesOptionError):
await cfg_ori.option('dummy1.dummy2', 0).owner.set('frozenmultifollower')
cfg = await get_config(cfg_ori, config_type)
#
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.option('dummy1.dummy2').property.pop('frozen')
cfg = await get_config(cfg_ori, config_type)
await cfg.option('dummy1.dummy1').value.set([True, True])
await cfg.option('dummy1.dummy2', 1).value.set(False)
assert await cfg.option('dummy1.dummy1').value.get() == [True, True]
assert await cfg.option('dummy1.dummy2', 0).value.get() == False
assert await cfg.option('dummy1.dummy2', 1).value.get() == False
#
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.option('dummy1.dummy2').property.add('frozen')
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy1.dummy1').value.get() == [True, True]
assert await cfg.option('dummy1.dummy2', 0).value.get() == None
assert await cfg.option('dummy1.dummy2', 1).value.get() == None
#
await cfg.option('dummy1.dummy1').value.pop(1)
assert await cfg.option('dummy1.dummy1').value.get() == [True]
assert await cfg.option('dummy1.dummy2', 0).value.get() == None
#
if config_type == 'tiramisu-api':
await cfg.send()
await cfg_ori.option('dummy1.dummy2').property.pop('frozen')
cfg = await get_config(cfg_ori, config_type)
assert await cfg.option('dummy1.dummy1').value.get() == [True]
assert await cfg.option('dummy1.dummy2', 0).value.get() == False
#
await cfg.option('dummy1.dummy1').value.set([True, True])
assert await cfg.option('dummy1.dummy2', 0).value.get() == False
assert await cfg.option('dummy1.dummy2', 1).value.get() == None
assert not await list_sessions()
def test_overrides_changes_option_value(config_type):
@pytest.mark.asyncio
async def test_overrides_changes_option_value(config_type):
"with config.override(), the default is changed and the value is changed"
descr = OptionDescription("test", "", [
BoolOption("b", "", default=False)])
cfg = Config(descr)
cfg = get_config(cfg, config_type)
cfg.option('b').value.set(True)
async with await Config(descr) as cfg:
cfg = await get_config(cfg, config_type)
await cfg.option('b').value.set(True)
assert not await list_sessions()
def test_choice_with_no_default(config_type):
@pytest.mark.asyncio
async def test_choice_with_no_default(config_type):
descr = OptionDescription("test", "", [
ChoiceOption("backend", "", ("c", "cli"))])
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('backend').value.get() is None
cfg.option('backend').value.set('c')
async with await Config(descr) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('backend').value.get() is None
await cfg.option('backend').value.set('c')
assert not await list_sessions()
def test_choice_with_default(config_type):
@pytest.mark.asyncio
async def test_choice_with_default(config_type):
descr = OptionDescription("test", "", [
ChoiceOption("backend", "", ("c", "cli"), default="cli")])
cfg = Config(descr)
cfg = get_config(cfg, config_type)
assert cfg.option('backend').value.get() == 'cli'
async with await Config(descr) as cfg:
cfg = await get_config(cfg, config_type)
assert await cfg.option('backend').value.get() == 'cli'
assert not await list_sessions()

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