def test_show_only_caption_when_no_constraint_loaded(self): self.assertEqual(["caption"], command.show( "caption", load_constraints=lambda: {"plain": [], "with_resource_sets": []}, format_options=lambda: None, modifiers=InputModifiers({}) ))
def show(lib, argv, modificators): """ show all ticket constraints object lib exposes library list argv see usage for "constraint colocation show" dict like object modificators can contain "full" """ print("\n".join(command.show( "Ticket Constraints:", lib.constraint_ticket.show, console_report.constraint_plain, modificators, )))
def show(lib, argv, modifiers): """ show all colocation constraints object lib exposes library list argv see usage for "constraint colocation show" dict like object modifiers can contain "full" Options: * --full - print more details * -f - CIB file """ modifiers.ensure_only_supported("-f", "--full") if argv: raise CmdLineInputError() print("\n".join(command.show( "Colocation Constraints:", lib.constraint_colocation.show, console_report.constraint_plain, modifiers, )))
def test_show_constraints_full(self): load_constraints = mock.Mock() load_constraints.return_value = { "plain": [{"options": {"id": "plain_id"}}], "with_resource_sets": [fixture_constraint()] } format_options = mock.Mock() format_options.return_value = "plain constraint listing" self.assertEqual( [ "caption", " plain constraint listing", " Resource Sets:", " "+fixture_constraint_console(), ], command.show( "caption", load_constraints, format_options, InputModifiers({"--full": ""}) ) )
def _config_show_cib_lines(lib): """ Commandline options: * -f - CIB file """ # update of pcs_options will change output of constraint show and # displaying resources and operations defaults utils.pcs_options["--full"] = 1 # get latest modifiers object after updating pcs_options modifiers = utils.get_input_modifiers() cib_xml = utils.get_cib() cib_etree = utils.get_cib_etree(cib_xml=cib_xml) cib_dom = utils.get_cib_dom(cib_xml=cib_xml) resource_lines = [] stonith_lines = [] for resource_el in cib_etree.find(".//resources"): is_stonith = ("class" in resource_el.attrib and resource_el.attrib["class"] == "stonith") resource_el_lines = resource.resource_node_lines(resource_el) if is_stonith: stonith_lines += resource_el_lines else: resource_lines += resource_el_lines all_lines = [] all_lines.append("Resources:") all_lines.extend(indent(resource_lines, indent_step=1)) all_lines.append("") all_lines.append("Stonith Devices:") all_lines.extend(indent(stonith_lines, indent_step=1)) all_lines.append("Fencing Levels:") levels_lines = stonith.stonith_level_config_to_str( lib.fencing_topology.get_config()) if levels_lines: all_lines.extend(indent(levels_lines, indent_step=2)) all_lines.append("") constraints_element = cib_dom.getElementsByTagName("constraints")[0] all_lines.extend( constraint.location_lines( constraints_element, showDetail=True, show_expired=True, verify_expiration=False, )) all_lines.extend( constraint_command.show( "Ordering Constraints:", lib.constraint_order.show, constraints_reports.order_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend( constraint_command.show( "Colocation Constraints:", lib.constraint_colocation.show, constraints_reports.colocation_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend( constraint_command.show( "Ticket Constraints:", lib.constraint_ticket.show, constraints_reports.ticket_plain, modifiers.get_subset("-f", "--full"), )) all_lines.append("") all_lines.extend(alert.alert_config_lines(lib)) all_lines.append("") all_lines.append("Resources Defaults:") all_lines.extend( indent( nvset_dto_list_to_lines( lib.cib_options.resource_defaults_config(), with_ids=modifiers.get("--full"), text_if_empty="No defaults set", ))) all_lines.append("Operations Defaults:") all_lines.extend( indent( nvset_dto_list_to_lines( lib.cib_options.operation_defaults_config(), with_ids=modifiers.get("--full"), text_if_empty="No defaults set", ))) all_lines.append("") all_lines.append("Cluster Properties:") properties = utils.get_set_properties() all_lines.extend( indent( [ "{0}: {1}".format(prop, val) for prop, val in sorted(properties.items()) ], indent_step=1, )) all_lines.append("") all_lines.append("Tags:") tags = lib.tag.config([]) if not tags: all_lines.append(" No tags defined") tag_lines = [] for tag in tags: tag_lines.append(tag["tag_id"]) tag_lines.extend(indent(tag["idref_list"])) all_lines.extend(indent(tag_lines, indent_step=1)) return all_lines
def _config_show_cib_lines(lib): """ Commandline options: * -f - CIB file """ # update of pcs_options will change output of constraint show utils.pcs_options["--full"] = 1 # get latest modifiers object after updating pcs_options modifiers = utils.get_input_modifiers() cib_xml = utils.get_cib() cib_etree = utils.get_cib_etree(cib_xml=cib_xml) cib_dom = utils.get_cib_dom(cib_xml=cib_xml) resource_lines = [] stonith_lines = [] for resource_el in cib_etree.find(".//resources"): is_stonith = ( "class" in resource_el.attrib and resource_el.attrib["class"] == "stonith" ) resource_el_lines = resource.resource_node_lines(resource_el) if is_stonith: stonith_lines += resource_el_lines else: resource_lines += resource_el_lines all_lines = [] all_lines.append("Resources:") all_lines.extend(indent(resource_lines, indent_step=1)) all_lines.append("") all_lines.append("Stonith Devices:") all_lines.extend(indent(stonith_lines, indent_step=1)) all_lines.append("Fencing Levels:") levels_lines = stonith.stonith_level_config_to_str( lib.fencing_topology.get_config() ) if levels_lines: all_lines.extend(indent(levels_lines, indent_step=2)) all_lines.append("") constraints_element = cib_dom.getElementsByTagName('constraints')[0] all_lines.extend( constraint.location_lines(constraints_element, showDetail=True) ) all_lines.extend(constraint_command.show( "Ordering Constraints:", lib.constraint_order.show, order_console_report.constraint_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend(constraint_command.show( "Colocation Constraints:", lib.constraint_colocation.show, colocation_console_report.constraint_plain, modifiers.get_subset("-f", "--full"), )) all_lines.extend(constraint_command.show( "Ticket Constraints:", lib.constraint_ticket.show, ticket_console_report.constraint_plain, modifiers.get_subset("-f", "--full"), )) all_lines.append("") all_lines.extend(alert.alert_config_lines(lib)) all_lines.append("") all_lines.append("Resources Defaults:") all_lines.extend(indent( resource.show_defaults(cib_dom, "rsc_defaults"), indent_step=1 )) all_lines.append("Operations Defaults:") all_lines.extend(indent( resource.show_defaults(cib_dom, "op_defaults"), indent_step=1 )) all_lines.append("") all_lines.append("Cluster Properties:") properties = utils.get_set_properties() all_lines.extend(indent( [ "{0}: {1}".format(prop, val) for prop, val in sorted(properties.items()) ], indent_step=1 )) return all_lines