예제 #1
0
 def test_no_such_level_ignore_missing(self):
     lib.remove_levels_by_params(self.reporter, self.tree, 9,
                                 TARGET_TYPE_NODE, "nodeB", ["d3"], True)
     self.assertEqual(self.get_remaining_ids(), [
         "fl1", "fl2", "fl3", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9",
         "fl10"
     ])
예제 #2
0
def remove_levels_by_params(
    lib_env, level=None, target_type=None, target_value=None, devices=None,
    ignore_if_missing=False
):
    """
    Remove specified fencing level(s)

    LibraryEnvironment lib_env -- environment
    int|string level -- level (index) of the fencing level to remove
    constant target_type -- the removed fencing level target value type
    mixed target_value -- the removed fencing level target value
    Iterable devices -- list of stonith devices of the removed fencing level
    bool ignore_if_missing -- when True, do not report if level not found
    """
    cib_fencing_topology.remove_levels_by_params(
        lib_env.report_processor,
        get_fencing_topology(lib_env.get_cib()),
        level,
        target_type,
        target_value,
        devices,
        ignore_if_missing
    )
    lib_env.report_processor.send()
    lib_env.push_cib()
예제 #3
0
 def test_combination(self):
     lib.remove_levels_by_params(self.reporter, self.tree, 2,
                                 TARGET_TYPE_NODE, "nodeB", ["d3"])
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl2", "fl3", "fl5", "fl6", "fl7", "fl8", "fl9", "fl10"])
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #4
0
def remove_levels_by_params(
    lib_env, level=None, target_type=None, target_value=None, devices=None,
    ignore_if_missing=False
):
    """
    Remove specified fencing level(s)

    LibraryEnvironment lib_env -- environment
    int|string level -- level (index) of the fencing level to remove
    constant target_type -- the removed fencing level target value type
    mixed target_value -- the removed fencing level target value
    Iterable devices -- list of stonith devices of the removed fencing level
    bool ignore_if_missing -- when True, do not report if level not found
    """
    cib_fencing_topology.remove_levels_by_params(
        lib_env.report_processor,
        get_fencing_topology(lib_env.get_cib()),
        level,
        target_type,
        target_value,
        devices,
        ignore_if_missing
    )
    lib_env.report_processor.send()
    lib_env.push_cib()
예제 #5
0
 def test_more_devices(self):
     lib.remove_levels_by_params(self.reporter,
                                 self.tree,
                                 devices=["d2", "d1"])
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl2", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9", "fl10"])
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #6
0
 def test_target_node(self):
     lib.remove_levels_by_params(self.reporter,
                                 self.tree,
                                 target_type=TARGET_TYPE_NODE,
                                 target_value="nodeA")
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl3", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9", "fl10"])
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #7
0
 def test_target_attrib(self):
     lib.remove_levels_by_params(self.reporter,
                                 self.tree,
                                 target_type=TARGET_TYPE_ATTRIBUTE,
                                 target_value=("fencing", "improved"))
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl2", "fl3", "fl4", "fl5", "fl6", "fl9", "fl10"])
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #8
0
 def test_more_devices(self):
     lib.remove_levels_by_params(
         self.reporter, self.tree, devices=["d2", "d1"]
     )
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl2", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9", "fl10"]
     )
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #9
0
 def test_level(self):
     lib.remove_levels_by_params(
         self.reporter, self.tree, level=2
     )
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl3", "fl5", "fl7", "fl8", "fl9", "fl10"]
     )
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #10
0
 def test_level(self):
     lib.remove_levels_by_params(
         self.reporter, self.tree, level=2
     )
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl3", "fl5", "fl7", "fl8", "fl9", "fl10"]
     )
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #11
0
 def test_target_pattern(self):
     lib.remove_levels_by_params(self.reporter,
                                 self.tree,
                                 target_type=TARGET_TYPE_REGEXP,
                                 target_value="node\d+")
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl2", "fl3", "fl4", "fl7", "fl8", "fl9", "fl10"])
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #12
0
 def test_combination(self):
     lib.remove_levels_by_params(
         self.reporter, self.tree, 2, TARGET_TYPE_NODE, "nodeB", ["d3"]
     )
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl2", "fl3", "fl5", "fl6", "fl7", "fl8", "fl9", "fl10"]
     )
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #13
0
 def test_target_attrib(self):
     lib.remove_levels_by_params(
         self.reporter, self.tree, target_type=TARGET_TYPE_ATTRIBUTE,
         target_value=("fencing", "improved")
     )
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl2", "fl3", "fl4", "fl5", "fl6", "fl9", "fl10"]
     )
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #14
0
 def test_target_pattern(self):
     lib.remove_levels_by_params(
         self.reporter, self.tree, target_type=TARGET_TYPE_REGEXP,
         target_value="node\d+"
     )
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl2", "fl3", "fl4", "fl7", "fl8", "fl9", "fl10"]
     )
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #15
0
 def test_target_node(self):
     lib.remove_levels_by_params(
         self.reporter, self.tree, target_type=TARGET_TYPE_NODE,
         target_value="nodeA"
     )
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl3", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9", "fl10"]
     )
     assert_report_item_list_equal(self.reporter.report_item_list, [])
예제 #16
0
 def test_no_such_level_ignore_missing(self):
     lib.remove_levels_by_params(
         self.reporter, self.tree, 9, TARGET_TYPE_NODE, "nodeB", ["d3"], True
     )
     self.assertEqual(
         self.get_remaining_ids(),
         [
             "fl1", "fl2", "fl3", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9",
             "fl10"
         ]
     )
예제 #17
0
 def test_no_such_level(self):
     report_list = lib.remove_levels_by_params(
         self.tree, 9, TARGET_TYPE_NODE, "nodeB", ["d3"]
     )
     assert_report_item_list_equal(
         report_list,
         [
             (
                 severity.ERROR,
                 report_codes.CIB_FENCING_LEVEL_DOES_NOT_EXIST,
                 {
                     "devices": ["d3",],
                     "target_type": TARGET_TYPE_NODE,
                     "target_value": "nodeB",
                     "level": 9,
                 },
                 None,
             ),
         ],
     )
     self.assertEqual(
         self.get_remaining_ids(),
         [
             "fl1",
             "fl2",
             "fl3",
             "fl4",
             "fl5",
             "fl6",
             "fl7",
             "fl8",
             "fl9",
             "fl10",
         ],
     )
예제 #18
0
 def test_invalid_target(self):
     assert_raise_library_error(
         lambda: lib.remove_levels_by_params(
             self.reporter, self.tree, target_type="bad_target",
             target_value="nodeA"
         ),
         (
             severity.ERROR,
             report_codes.INVALID_OPTION_TYPE,
             {
                 "option_name": "target",
                 "allowed_types": [
                     "node",
                     "regular expression",
                     "attribute_name=value"
                 ]
             },
             None
         ),
     )
     self.assertEqual(
         self.get_remaining_ids(),
         [
             "fl1", "fl2", "fl3", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9",
             "fl10"
         ]
     )
예제 #19
0
 def test_invalid_target(self):
     assert_raise_library_error(
         lambda: lib.remove_levels_by_params(
             self.reporter, self.tree, target_type="bad_target",
             target_value="nodeA"
         ),
         (
             severity.ERROR,
             report_codes.INVALID_OPTION_TYPE,
             {
                 "option_name": "target",
                 "allowed_types": [
                     "node",
                     "regular expression",
                     "attribute_name=value"
                 ]
             },
             None
         ),
     )
     self.assertEqual(
         self.get_remaining_ids(),
         [
             "fl1", "fl2", "fl3", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9",
             "fl10"
         ]
     )
예제 #20
0
 def test_one_device(self):
     report_list = lib.remove_levels_by_params(self.tree, devices=["d3"])
     self.assertEqual(
         self.get_remaining_ids(),
         ["fl1", "fl3", "fl5", "fl6", "fl7", "fl8", "fl9", "fl10"],
     )
     assert_report_item_list_equal(report_list, [])
예제 #21
0
 def test_no_such_level(self):
     assert_raise_library_error(
         lambda: lib.remove_levels_by_params(
             self.reporter, self.tree, 9, TARGET_TYPE_NODE, "nodeB", ["d3"
                                                                      ]),
         (severity.ERROR, report_codes.CIB_FENCING_LEVEL_DOES_NOT_EXIST, {
             "devices": [
                 "d3",
             ],
             "target_type": TARGET_TYPE_NODE,
             "target_value": "nodeB",
             "level": 9,
         }, None),
     )
     self.assertEqual(self.get_remaining_ids(), [
         "fl1", "fl2", "fl3", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9",
         "fl10"
     ])
예제 #22
0
 def test_invalid_target(self):
     report_list = lib.remove_levels_by_params(self.tree,
                                               target_type="bad_target",
                                               target_value="nodeA")
     assert_report_item_list_equal(
         report_list,
         [
             (
                 severity.ERROR,
                 report_codes.INVALID_OPTION_TYPE,
                 {
                     "option_name":
                     "target",
                     "allowed_types": [
                         "node",
                         "regular expression",
                         "attribute_name=value",
                     ],
                 },
                 None,
             ),
         ],
     )
     self.assertEqual(
         self.get_remaining_ids(),
         [
             "fl1",
             "fl2",
             "fl3",
             "fl4",
             "fl5",
             "fl6",
             "fl7",
             "fl8",
             "fl9",
             "fl10",
         ],
     )
예제 #23
0
 def test_no_such_level(self):
     assert_raise_library_error(
         lambda: lib.remove_levels_by_params(
             self.reporter, self.tree, 9, TARGET_TYPE_NODE, "nodeB", ["d3"]
         ),
         (
             severity.ERROR,
             report_codes.CIB_FENCING_LEVEL_DOES_NOT_EXIST,
             {
                 "devices": ["d3", ],
                 "target_type": TARGET_TYPE_NODE,
                 "target_value": "nodeB",
                 "level": 9,
             },
             None
         ),
     )
     self.assertEqual(
         self.get_remaining_ids(),
         [
             "fl1", "fl2", "fl3", "fl4", "fl5", "fl6", "fl7", "fl8", "fl9",
             "fl10"
         ]
     )
예제 #24
0
def remove_levels_by_params(
    lib_env: LibraryEnvironment,
    level=None,
    # TODO create a special type, so that it cannot accept any string
    target_type: Optional[str] = None,
    target_value=None,
    devices: Optional[Iterable[str]] = None,
    # TODO remove, deprecated backward compatibility layer
    ignore_if_missing: bool = False,
    # TODO remove, deprecated backward compatibility layer
    target_may_be_a_device: bool = False,
):
    """
    Remove specified fencing level(s).

    LibraryEnvironment lib_env -- environment
    int|string level -- level (index) of the fencing level to remove
    target_type -- the removed fencing level target value type
    mixed target_value -- the removed fencing level target value
    devices -- list of stonith devices of the removed fencing level
    ignore_if_missing -- when True, do not report if level not found
    target_may_be_a_device -- enables backward compatibility mode for old CLI
    """
    topology_el = get_fencing_topology(lib_env.get_cib())
    report_list = cib_fencing_topology.remove_levels_by_params(
        topology_el,
        level,
        target_type,
        target_value,
        devices,
        ignore_if_missing,
        validate_device_ids=(not target_may_be_a_device),
    )

    if not target_may_be_a_device or target_type != TARGET_TYPE_NODE:
        if lib_env.report_processor.report_list(report_list).has_errors:
            raise LibraryError()
        lib_env.push_cib()
        return

    # TODO remove, deprecated backward compatibility mode
    # CLI command parameters are: level, node, stonith, stonith... Both the
    # node and the stonith list are optional. If the node is ommited and the
    # stonith list is present, there is no way to figure it out, since there is
    # no specification of what the parameter is. Hence the pre-lib code tried
    # both. First it assumed the first parameter is a node. If that fence level
    # didn't exist, it assumed the first parameter is a device. Since it was
    # only possible to specify node as a target back then, this is enabled only
    # in that case.
    # CLI has no way to figure out what the first parameter is. Therefore, the
    # lib must try both cases if asked to do so.
    if not report.has_errors(report_list):
        lib_env.report_processor.report_list(report_list)
        lib_env.push_cib()
        return

    level_not_found = False
    for report_item in report_list:
        if (report_item.message.code ==
                report.codes.CIB_FENCING_LEVEL_DOES_NOT_EXIST):
            level_not_found = True
            break
    if not level_not_found:
        lib_env.report_processor.report_list(report_list)
        raise LibraryError()

    target_and_devices = [target_value]
    if devices:
        target_and_devices.extend(devices)
    report_list_second = cib_fencing_topology.remove_levels_by_params(
        topology_el,
        level,
        None,
        None,
        target_and_devices,
        ignore_if_missing,
        validate_device_ids=(not target_may_be_a_device),
    )
    if not report.has_errors(report_list_second):
        lib_env.report_processor.report_list(report_list_second)
        lib_env.push_cib()
        return

    lib_env.report_processor.report_list(report_list)
    lib_env.report_processor.report_list(report_list_second)
    raise LibraryError()