示例#1
0
 def test_no_alerts(self):
     # pylint: disable=no-self-use
     tree = etree.XML(
         """
         <cib>
             <configuration/>
         </cib>
         """
     )
     assert_xml_equal(
         '<alert id="my-alert" path="/test/path"/>',
         etree.tostring(
             alert.create_alert(tree, "my-alert", "/test/path")
         ).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="my-alert" path="/test/path"/>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(tree).decode()
     )
示例#2
0
文件: alert.py 项目: junaruga/pcs
def create_alert(
    lib_env,
    alert_id,
    path,
    instance_attribute_dict,
    meta_attribute_dict,
    description=None
):
    """
    Create new alert.
    Raises LibraryError if path is not specified, or any other failure.

    lib_env -- LibraryEnvironment
    alert_id -- id of alert to be created, if None it will be generated
    path -- path to script for alert
    instance_attribute_dict -- dictionary of instance attributes
    meta_attribute_dict -- dictionary of meta attributes
    description -- alert description description
    """
    if not path:
        raise LibraryError(reports.required_option_is_missing(["path"]))


    alert_el = alert.create_alert(
        lib_env.get_cib(REQUIRED_CIB_VERSION),
        alert_id,
        path,
        description
    )
    alert.update_instance_attributes(alert_el, instance_attribute_dict)
    alert.update_meta_attributes(alert_el, meta_attribute_dict)

    lib_env.push_cib()
示例#3
0
def create_alert(
    lib_env,
    alert_id,
    path,
    instance_attribute_dict,
    meta_attribute_dict,
    description=None
):
    """
    Create new alert.
    Raises LibraryError if path is not specified, or any other failure.

    lib_env -- LibraryEnvironment
    alert_id -- id of alert to be created, if None it will be generated
    path -- path to script for alert
    instance_attribute_dict -- dictionary of instance attributes
    meta_attribute_dict -- dictionary of meta attributes
    description -- alert description description
    """
    if not path:
        raise LibraryError(reports.required_option_is_missing(["path"]))

    cib = lib_env.get_cib(REQUIRED_CIB_VERSION)

    alert_el = alert.create_alert(cib, alert_id, path, description)
    alert.update_instance_attributes(alert_el, instance_attribute_dict)
    alert.update_meta_attributes(alert_el, meta_attribute_dict)

    lib_env.push_cib(cib)
示例#4
0
def create_alert(
    lib_env: LibraryEnvironment,
    alert_id,
    path,
    instance_attribute_dict,
    meta_attribute_dict,
    description=None,
):
    """
    Create new alert.
    Raises LibraryError if path is not specified, or any other failure.

    lib_env -- LibraryEnvironment
    alert_id -- id of alert to be created, if None it will be generated
    path -- path to script for alert
    instance_attribute_dict -- dictionary of instance attributes
    meta_attribute_dict -- dictionary of meta attributes
    description -- alert description description
    """
    if not path:
        raise LibraryError(
            ReportItem.error(
                reports.messages.RequiredOptionsAreMissing(["path"])))

    cib = lib_env.get_cib(REQUIRED_CIB_VERSION)
    id_provider = IdProvider(cib)
    alert_el = alert.create_alert(cib, alert_id, path, description)
    arrange_first_instance_attributes(alert_el, instance_attribute_dict,
                                      id_provider)
    arrange_first_meta_attributes(alert_el, meta_attribute_dict, id_provider)

    lib_env.push_cib()
示例#5
0
 def test_alerts_exists_with_description(self):
     assert_xml_equal(
         '<alert id="my-alert" path="/test/path" description="nothing"/>',
         etree.tostring(
             alert.create_alert(
                 self.tree, "my-alert", "/test/path", "nothing"
             )
         ).decode(),
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert"/>
                     <alert
                         id="my-alert"
                         path="/test/path"
                         description="nothing"
                     />
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode(),
     )
示例#6
0
 def test_no_alerts(self):
     # pylint: disable=no-self-use
     tree = etree.XML(
         """
         <cib>
             <configuration/>
         </cib>
         """
     )
     assert_xml_equal(
         '<alert id="my-alert" path="/test/path"/>',
         etree.tostring(
             alert.create_alert(tree, "my-alert", "/test/path")
         ).decode(),
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="my-alert" path="/test/path"/>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(tree).decode(),
     )
示例#7
0
 def test_id_exists(self):
     assert_raise_library_error(
         lambda: alert.create_alert(self.tree, "alert", "/path"),
         (severities.ERROR, report_codes.ID_ALREADY_EXISTS, {
             "id": "alert"
         }),
     )
示例#8
0
 def test_invalid_id(self):
     assert_raise_library_error(
         lambda: alert.create_alert(self.tree, "1alert", "/path"),
         (severities.ERROR, report_codes.INVALID_ID, {
             "id": "1alert",
             "id_description": "alert-id",
             "invalid_character": "1",
             "is_first_char": True,
         }))
示例#9
0
 def test_id_exists(self):
     assert_raise_library_error(
         lambda: alert.create_alert(self.tree, "alert", "/path"),
         (
             severities.ERROR,
             report_codes.ID_ALREADY_EXISTS,
             {"id": "alert"}
         )
     )
示例#10
0
 def test_invalid_id(self):
     assert_raise_library_error(
         lambda: alert.create_alert(self.tree, "1alert", "/path"),
         (
             severities.ERROR,
             report_codes.INVALID_ID,
             {
                 "id": "1alert",
                 "id_description": "alert-id",
                 "invalid_character": "1",
                 "is_first_char": True,
             }
         )
     )
示例#11
0
 def test_no_id(self):
     assert_xml_equal(
         '<alert id="alert-1" path="/test/path"/>',
         etree.tostring(alert.create_alert(self.tree, None,
                                           "/test/path")).decode())
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert"/>
                     <alert id="alert-1" path="/test/path"/>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode())
示例#12
0
 def test_no_id(self):
     assert_xml_equal(
         '<alert id="alert-1" path="/test/path"/>',
         etree.tostring(
             alert.create_alert(self.tree, None, "/test/path")
         ).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert"/>
                     <alert id="alert-1" path="/test/path"/>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode()
     )
示例#13
0
 def test_alerts_exists_with_description(self):
     assert_xml_equal(
         '<alert id="my-alert" path="/test/path" description="nothing"/>',
         etree.tostring(alert.create_alert(
             self.tree, "my-alert", "/test/path", "nothing"
         )).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert"/>
                     <alert
                         id="my-alert"
                         path="/test/path"
                         description="nothing"
                     />
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode()
     )