Ejemplo n.º 1
0
def get_failcounts(env,
                   resource=None,
                   node=None,
                   operation=None,
                   interval=None):
    # pylint: disable=redefined-outer-name
    """
    List resources failcounts, optionally filtered by a resource, node or op

    LibraryEnvironment env
    string resource -- show failcounts for the specified resource only
    string node -- show failcounts for the specified node only
    string operation -- show failcounts for the specified operation only
    string interval -- show failcounts for the specified operation interval only
    """
    report_items = []
    if interval is not None and operation is None:
        report_items.append(
            reports.prerequisite_option_is_missing("interval", "operation"))
    if interval is not None:
        report_items.extend(
            ValueTimeInterval("interval").validate({"interval": interval}))
    if report_items:
        raise LibraryError(*report_items)

    interval_ms = (None if interval is None else timeout_to_seconds(interval) *
                   1000)

    all_failcounts = cib_status.get_resources_failcounts(
        get_status(env.get_cib()))
    return cib_status.filter_resources_failcounts(all_failcounts,
                                                  resource=resource,
                                                  node=node,
                                                  operation=operation,
                                                  interval=interval_ms)
Ejemplo n.º 2
0
 def test_no_failures(self):
     status_xml = etree.fromstring("""
         <status>
             <node_state uname="node1">
                 <transient_attributes>
                     <instance_attributes>
                     </instance_attributes>
                 </transient_attributes>
             </node_state>
             <node_state uname="node2">
                 <transient_attributes>
                 </transient_attributes>
             </node_state>
             <node_state uname="node3">
             </node_state>
         </status>
     """)
     self.assertEqual(status.get_resources_failcounts(status_xml), [])
Ejemplo n.º 3
0
 def test_no_failures(self):
     status_xml = etree.fromstring("""
         <status>
             <node_state uname="node1">
                 <transient_attributes>
                     <instance_attributes>
                     </instance_attributes>
                 </transient_attributes>
             </node_state>
             <node_state uname="node2">
                 <transient_attributes>
                 </transient_attributes>
             </node_state>
             <node_state uname="node3">
             </node_state>
         </status>
     """)
     self.assertEqual(
         status.get_resources_failcounts(status_xml),
         []
     )
Ejemplo n.º 4
0
def get_failcounts(
    env, resource=None, node=None, operation=None, interval=None
):
    # pylint: disable=redefined-outer-name
    """
    List resources failcounts, optionally filtered by a resource, node or op

    LibraryEnvironment env
    string resource -- show failcounts for the specified resource only
    string node -- show failcounts for the specified node only
    string operation -- show failcounts for the specified operation only
    string interval -- show failcounts for the specified operation interval only
    """
    report_items = []
    if interval is not None and operation is None:
        report_items.append(
            reports.prerequisite_option_is_missing("interval", "operation")
        )
    if interval is not None:
        report_items.extend(
            value_time_interval("interval")({"interval": interval})
        )
    if report_items:
        raise LibraryError(*report_items)

    interval_ms = (
        None if interval is None
        else timeout_to_seconds(interval) * 1000
    )

    all_failcounts = cib_status.get_resources_failcounts(
        get_status(env.get_cib())
    )
    return cib_status.filter_resources_failcounts(
        all_failcounts,
        resource=resource,
        node=node,
        operation=operation,
        interval=interval_ms
    )
Ejemplo n.º 5
0
 def test_failures(self):
     status_xml = etree.fromstring("""
         <status>
             <node_state uname="node1">
                 <transient_attributes>
                     <instance_attributes>
                         <nvpair name="fail-count-clone:0#start_0"
                             value="INFINITY"/>
                         <nvpair name="last-failure-clone:0#start_0"
                             value="1528871936"/>
                         <nvpair name="fail-count-clone:1#start_0"
                             value="999"/>
                         <nvpair name="last-failure-clone:1#start_0"
                             value="1528871937"/>
                     </instance_attributes>
                 </transient_attributes>
             </node_state>
             <node_state uname="node2">
                 <transient_attributes>
                     <instance_attributes>
                         <nvpair name="fail-count-resource#monitor_500"
                             value="10"/>
                         <nvpair name="last-failure-resource#monitor_500"
                             value="1528871946"/>
                         <nvpair name="fail-count-no-last#stop_0"
                             value="3"/>
                         <nvpair name="last-failure-no-count#monitor_1000"
                             value="1528871956"/>
                         <nvpair name="ignored-resource#monitor_1000"
                             value="ignored"/>
                         <nvpair name="fail-count-no-int#start_0"
                             value="a few"/>
                         <nvpair name="last-failure-no-int#start_0"
                             value="an hour ago"/>
                     </instance_attributes>
                 </transient_attributes>
             </node_state>
         </status>
     """)
     self.assertEqual(
         sorted(
             status.get_resources_failcounts(status_xml),
             key=lambda x: [str(x[key]) for key in sorted(x.keys())]
         ),
         sorted([
             {
                 "node": "node1",
                 "resource": "clone",
                 "clone_id": "0",
                 "operation": "start",
                 "interval": "0",
                 "fail_count": "INFINITY",
                 "last_failure": 1528871936,
             },
             {
                 "node": "node1",
                 "resource": "clone",
                 "clone_id": "1",
                 "operation": "start",
                 "interval": "0",
                 "fail_count": 999,
                 "last_failure": 1528871937,
             },
             {
                 "node": "node2",
                 "resource": "resource",
                 "clone_id": None,
                 "operation": "monitor",
                 "interval": "500",
                 "fail_count": 10,
                 "last_failure": 1528871946,
             },
             {
                 "node": "node2",
                 "resource": "no-last",
                 "clone_id": None,
                 "operation": "stop",
                 "interval": "0",
                 "fail_count": 3,
                 "last_failure": 0,
             },
             {
                 "node": "node2",
                 "resource": "no-count",
                 "clone_id": None,
                 "operation": "monitor",
                 "interval": "1000",
                 "fail_count": 0,
                 "last_failure": 1528871956,
             },
             {
                 "node": "node2",
                 "resource": "no-int",
                 "clone_id": None,
                 "operation": "start",
                 "interval": "0",
                 "fail_count": 1,
                 "last_failure": 0,
             },
         ],
             key=lambda x: [str(x[key]) for key in sorted(x.keys())]
         )
     )
Ejemplo n.º 6
0
 def test_failures(self):
     status_xml = etree.fromstring("""
         <status>
             <node_state uname="node1">
                 <transient_attributes>
                     <instance_attributes>
                         <nvpair name="fail-count-clone:0#start_0"
                             value="INFINITY"/>
                         <nvpair name="last-failure-clone:0#start_0"
                             value="1528871936"/>
                         <nvpair name="fail-count-clone:1#start_0"
                             value="999"/>
                         <nvpair name="last-failure-clone:1#start_0"
                             value="1528871937"/>
                     </instance_attributes>
                 </transient_attributes>
             </node_state>
             <node_state uname="node2">
                 <transient_attributes>
                     <instance_attributes>
                         <nvpair name="fail-count-resource#monitor_500"
                             value="10"/>
                         <nvpair name="last-failure-resource#monitor_500"
                             value="1528871946"/>
                         <nvpair name="fail-count-no-last#stop_0"
                             value="3"/>
                         <nvpair name="last-failure-no-count#monitor_1000"
                             value="1528871956"/>
                         <nvpair name="ignored-resource#monitor_1000"
                             value="ignored"/>
                         <nvpair name="fail-count-no-int#start_0"
                             value="a few"/>
                         <nvpair name="last-failure-no-int#start_0"
                             value="an hour ago"/>
                     </instance_attributes>
                 </transient_attributes>
             </node_state>
         </status>
     """)
     self.assertEqual(
         sorted(status.get_resources_failcounts(status_xml),
                key=lambda x: [str(x[key]) for key in sorted(x.keys())]),
         sorted([
             {
                 "node": "node1",
                 "resource": "clone",
                 "clone_id": "0",
                 "operation": "start",
                 "interval": "0",
                 "fail_count": "INFINITY",
                 "last_failure": 1528871936,
             },
             {
                 "node": "node1",
                 "resource": "clone",
                 "clone_id": "1",
                 "operation": "start",
                 "interval": "0",
                 "fail_count": 999,
                 "last_failure": 1528871937,
             },
             {
                 "node": "node2",
                 "resource": "resource",
                 "clone_id": None,
                 "operation": "monitor",
                 "interval": "500",
                 "fail_count": 10,
                 "last_failure": 1528871946,
             },
             {
                 "node": "node2",
                 "resource": "no-last",
                 "clone_id": None,
                 "operation": "stop",
                 "interval": "0",
                 "fail_count": 3,
                 "last_failure": 0,
             },
             {
                 "node": "node2",
                 "resource": "no-count",
                 "clone_id": None,
                 "operation": "monitor",
                 "interval": "1000",
                 "fail_count": 0,
                 "last_failure": 1528871956,
             },
             {
                 "node": "node2",
                 "resource": "no-int",
                 "clone_id": None,
                 "operation": "start",
                 "interval": "0",
                 "fail_count": 1,
                 "last_failure": 0,
             },
         ],
                key=lambda x: [str(x[key]) for key in sorted(x.keys())]))