Exemple #1
0
 def test_put_new_constraint_to_constraint_section(self):
     constraint_section = etree.Element("constraints")
     constraint.create_with_set(
         constraint_section,
         "ticket",
         {"a": "b"},
         [{
             "ids": ["A", "B"],
             "options": {
                 "c": "d"
             }
         }],
     )
     assert_xml_equal(
         etree.tostring(constraint_section).decode(),
         """
         <constraints>
             <ticket a="b">
                 <resource_set c="d" id="constraint_set_set">
                     <resource_ref id="A"/>
                     <resource_ref id="B"/>
                 </resource_set>
             </ticket>
         </constraints>
     """,
     )
Exemple #2
0
 def test_refuse_empty_resource_set_list(self):
     constraint_section = etree.Element("constraints")
     assert_raise_library_error(
         lambda: constraint.create_with_set(constraint_section, "ticket",
                                            {"a": "b"}, []),
         (severities.ERROR, report_codes.EMPTY_RESOURCE_SET_LIST, {}),
     )
Exemple #3
0
def create_with_set(
    tag_name,
    prepare_options,
    env,
    resource_set_list,
    constraint_options,
    resource_in_clone_alowed=False,
    duplication_alowed=False,
    duplicate_check=None,
):
    """
    string tag_name is constraint tag name
    callable prepare_options takes
        cib(Element), options(dict), resource_set_list and return corrected
        options or if options not usable raises error
    env is library environment
    list resource_set_list is description of resource set, for example:
        {"ids": ["A", "B"], "options": {"sequential": "true"}},
    dict constraint_options is base for building attributes of constraint tag
    bool resource_in_clone_alowed flag for allowing to reference id which is
        in tag clone or master
    bool duplication_alowed flag for allowing create duplicate element
    callable duplicate_check takes two elements and decide if they are
        duplicates
    """
    cib = env.get_cib()

    find_valid_resource_id = partial(
        constraint.find_valid_resource_id,
        env.report_processor,
        cib,
        resource_in_clone_alowed,
    )

    constraint_section = get_constraints(cib)
    constraint_element = constraint.create_with_set(
        constraint_section,
        tag_name,
        options=prepare_options(cib, constraint_options, resource_set_list),
        resource_set_list=[
            resource_set.prepare_set(
                find_valid_resource_id, resource_set_item, env.report_processor
            )
            for resource_set_item in resource_set_list
        ],
    )

    if not duplicate_check:
        duplicate_check = constraint.have_duplicate_resource_sets

    constraint.check_is_without_duplication(
        env.report_processor,
        constraint_section,
        constraint_element,
        are_duplicate=duplicate_check,
        export_element=constraint.export_with_set,
        duplication_alowed=duplication_alowed,
    )

    env.push_cib()
Exemple #4
0
 def test_put_new_constraint_to_constraint_section(self):
     constraint_section = etree.Element("constraints")
     constraint.create_with_set(
         constraint_section,
         "ticket",
         {"a": "b"},
         [{"ids": ["A", "B"], "options": {"c": "d"}}]
     )
     assert_xml_equal(etree.tostring(constraint_section).decode(), """
         <constraints>
             <ticket a="b">
                 <resource_set c="d" id="pcs_rsc_set_A_B">
                     <resource_ref id="A"/>
                     <resource_ref id="B"/>
                 </resource_set>
             </ticket>
         </constraints>
     """)
Exemple #5
0
 def test_refuse_empty_resource_set_list(self):
     constraint_section = etree.Element("constraints")
     assert_raise_library_error(
         lambda: constraint.create_with_set(
             constraint_section,
             "ticket",
             {"a": "b"},
             []
         ),
         (severities.ERROR, report_codes.EMPTY_RESOURCE_SET_LIST, {})
     )
Exemple #6
0
def create_with_set(
    tag_name, prepare_options, env, resource_set_list, constraint_options,
    can_repair_to_clone=False,
    resource_in_clone_alowed=False,
    duplication_alowed=False,
    duplicate_check=None,
):
    """
    string tag_name is constraint tag name
    callable prepare_options takes
        cib(Element), options(dict), resource_set_list and return corrected
        options or if options not usable raises error
    env is library environment
    list resource_set_list is description of resource set, for example:
        {"ids": ["A", "B"], "options": {"sequential": "true"}},
    dict constraint_options is base for building attributes of constraint tag
    bool resource_in_clone_alowed flag for allowing to reference id which is
        in tag clone or master
    bool duplication_alowed flag for allowing create duplicate element
    callable duplicate_check takes two elements and decide if they are
        duplicates
    """
    cib = env.get_cib()

    find_valid_resource_id = partial(
        constraint.find_valid_resource_id,
        env.report_processor, cib, can_repair_to_clone, resource_in_clone_alowed
    )

    constraint_section = get_constraints(cib)
    constraint_element = constraint.create_with_set(
        constraint_section,
        tag_name,
        options=prepare_options(cib, constraint_options, resource_set_list),
        resource_set_list=[
             resource_set.prepare_set(find_valid_resource_id, resource_set_item)
             for resource_set_item in resource_set_list
        ]
    )

    if not duplicate_check:
        duplicate_check = constraint.have_duplicate_resource_sets

    constraint.check_is_without_duplication(
        env.report_processor,
        constraint_section,
        constraint_element,
        are_duplicate=duplicate_check,
        export_element=constraint.export_with_set,
        duplication_alowed=duplication_alowed,
    )

    env.push_cib(cib)