Example #1
0
 def test_return_corrected_resurce_set(self):
     find_valid_id = mock.Mock()
     find_valid_id.side_effect = lambda id: {"A": "AA", "B": "BB"}[id]
     self.assertEqual(
         {"ids": ["AA", "BB"], "options": {"sequential": "true"}},
         resource_set.prepare_set(find_valid_id, {"ids": ["A", "B"], "options": {"sequential": "true"}}),
     )
Example #2
0
File: common.py Project: vvidic/pcs
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()
Example #3
0
 def test_return_corrected_resurce_set(self):
     find_valid_id = mock.Mock()
     find_valid_id.side_effect = lambda id: {"A": "AA", "B": "BB"}[id]
     self.assertEqual(
         {"ids": ["AA", "BB"], "options": {"sequential": "true"}},
         resource_set.prepare_set(find_valid_id, {
             "ids": ["A", "B"],
             "options": {"sequential": "true"}
         })
     )
Example #4
0
 def test_refuse_invalid_attribute_value(self):
     assert_raise_library_error(
         lambda: resource_set.prepare_set(mock.Mock(), {
             "ids": ["A", "B"],
             "options": {"role": "invalid"}
         }),
         (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
             'option_name': 'role',
             'allowed_values': ('Stopped', 'Started', 'Master', 'Slave'),
             'option_value': 'invalid',
         }),
     )
Example #5
0
 def test_refuse_invalid_attribute_value(self):
     assert_raise_library_error(
         lambda: resource_set.prepare_set(mock.Mock(), {
             "ids": ["A", "B"],
             "options": {"role": "invalid"}
         }),
         (severities.ERROR, report_codes.INVALID_OPTION_VALUE, {
             'option_name': 'role',
             'allowed_values': ('Stopped', 'Started', 'Master', 'Slave'),
             'option_value': 'invalid',
         }),
     )
Example #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)
Example #7
0
 def test_refuse_invalid_attribute_value(self):
     assert_raise_library_error(
         lambda: resource_set.prepare_set(mock.Mock(), {"ids": ["A", "B"], "options": {"role": "invalid"}}),
         (
             severities.ERROR,
             report_codes.INVALID_OPTION_VALUE,
             {
                 "option_name": "role",
                 "allowed_values": ("Stopped", "Started", "Master", "Slave"),
                 "option_value": "invalid",
             },
         ),
     )
Example #8
0
 def test_refuse_invalid_attribute_name(self):
     assert_raise_library_error(
         lambda: resource_set.prepare_set(mock.Mock(), {"ids": ["A", "B"], "options": {"invalid_name": "true"}}),
         (
             severities.ERROR,
             report_codes.INVALID_OPTION,
             {
                 "option_name": "invalid_name",
                 "option_type": None,
                 "allowed": ["action", "require-all", "role", "sequential"],
             },
         ),
     )
Example #9
0
 def test_refuse_invalid_attribute_name(self):
     assert_raise_library_error(
         lambda: resource_set.prepare_set(mock.Mock(), {
             "ids": ["A", "B"],
             "options": {
                 "invalid_name": "true"
             }
         }),
         (severities.ERROR, report_codes.INVALID_OPTION, {
             "option_names": ["invalid_name"],
             "option_type": None,
             "allowed": ["action", "require-all", "role", "sequential"],
         }),
     )
Example #10
0
 def test_refuse_invalid_attribute_value(self):
     assert_raise_library_error(
         lambda: resource_set.prepare_set(mock.Mock(), {
             "ids": ["A", "B"],
             "options": {
                 "role": "invalid"
             }
         }),
         (
             severities.ERROR,
             report_codes.INVALID_OPTION_VALUE,
             {
                 "option_name": "role",
                 "allowed_values":
                 ("Master", "Slave", "Started", "Stopped"),
                 "option_value": "invalid",
                 "cannot_be_empty": False,
                 "forbidden_characters": None,
             },
         ),
     )
Example #11
0
 def test_refuse_invalid_attribute_name(self):
     assert_raise_library_error(
         lambda: resource_set.prepare_set(
             mock.Mock(),
             {
                 "ids": ["A", "B"],
                 "options": {
                     "invalid_name": "true"
                 }
             },
             self.report_processor,
         ), )
     self.report_processor.assert_reports([
         fixture.error(
             reports.codes.INVALID_OPTIONS,
             option_names=["invalid_name"],
             option_type="set",
             allowed=["action", "require-all", "role", "sequential"],
             allowed_patterns=[],
         ),
     ])
Example #12
0
 def test_refuse_invalid_attribute_value(self):
     assert_raise_library_error(
         lambda: resource_set.prepare_set(
             mock.Mock(),
             {
                 "ids": ["A", "B"],
                 "options": {
                     "role": "invalid"
                 }
             },
             self.report_processor,
         ), )
     self.report_processor.assert_reports([
         fixture.error(
             reports.codes.INVALID_OPTION_VALUE,
             option_name="role",
             allowed_values=const.PCMK_ROLES,
             option_value="invalid",
             cannot_be_empty=False,
             forbidden_characters=None,
         ),
     ])