def update_alert( lib_env, alert_id, path, instance_attribute_dict, meta_attribute_dict, description=None ): """ Update existing alert with specified id. lib_env -- LibraryEnvironment alert_id -- id of alert to be updated path -- new path, if None old value will stay unchanged instance_attribute_dict -- dictionary of instance attributes to update meta_attribute_dict -- dictionary of meta attributes to update description -- new description, if empty string, old description will be deleted, if None old value will stay unchanged """ alert_el = alert.update_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()
def update_alert( lib_env, alert_id, path, instance_attribute_dict, meta_attribute_dict, description=None ): """ Update existing alert with specified id. lib_env -- LibraryEnvironment alert_id -- id of alert to be updated path -- new path, if None old value will stay unchanged instance_attribute_dict -- dictionary of instance attributes to update meta_attribute_dict -- dictionary of meta attributes to update description -- new description, if empty string, old description will be deleted, if None old value will stay unchanged """ cib = lib_env.get_cib(REQUIRED_CIB_VERSION) alert_el = alert.update_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)
def update_alert( lib_env: LibraryEnvironment, alert_id, path, instance_attribute_dict, meta_attribute_dict, description=None, ): """ Update existing alert with specified id. lib_env -- LibraryEnvironment alert_id -- id of alert to be updated path -- new path, if None old value will stay unchanged instance_attribute_dict -- dictionary of instance attributes to update meta_attribute_dict -- dictionary of meta attributes to update description -- new description, if empty string, old description will be deleted, if None old value will stay unchanged """ cib = lib_env.get_cib() id_provider = IdProvider(cib) alert_el = alert.update_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()
def test_id_not_exists(self): assert_raise_library_error( lambda: alert.update_alert(self.tree, "alert0", "/test"), (severities.ERROR, report_codes.ID_NOT_FOUND, { "id": "alert0", "context_type": "alerts", "context_id": "", "id_description": "alert" }))
def test_id_not_exists(self): assert_raise_library_error( lambda: alert.update_alert(self.tree, "alert0", "/test"), (severities.ERROR, report_codes.ID_NOT_FOUND, { "id": "alert0", "expected_types": ["alert"], "context_type": "alerts", "context_id": "", }, None))
def test_id_not_exists(self): assert_raise_library_error( lambda: alert.update_alert(self.tree, "alert0", "/test"), ( severities.ERROR, report_codes.CIB_ALERT_NOT_FOUND, {"alert": "alert0"} ) )
def test_id_not_exists(self): assert_raise_library_error( lambda: alert.update_alert(self.tree, "alert0", "/test"), ( severities.ERROR, report_codes.ID_NOT_FOUND, { "id": "alert0", "context_type": "alerts", "context_id": "", "id_description": "alert" } ) )
def test_id_not_exists(self): assert_raise_library_error( lambda: alert.update_alert(self.tree, "alert0", "/test"), ( severities.ERROR, report_codes.ID_NOT_FOUND, { "id": "alert0", "expected_types": ["alert"], "context_type": "alerts", "context_id": "", }, None ) )
def test_remove_description(self): assert_xml_equal( '<alert id="alert1" path="/path1"/>', etree.tostring(alert.update_alert(self.tree, "alert1", None, "")).decode()) assert_xml_equal( """ <cib> <configuration> <alerts> <alert id="alert" path="/path"/> <alert id="alert1" path="/path1"/> </alerts> </configuration> </cib> """, etree.tostring(self.tree).decode())
def test_update_path(self): assert_xml_equal( '<alert id="alert" path="/test/path"/>', etree.tostring(alert.update_alert(self.tree, "alert", "/test/path")).decode()) assert_xml_equal( """ <cib> <configuration> <alerts> <alert id="alert" path="/test/path"/> <alert id="alert1" path="/path1" description="nothing"/> </alerts> </configuration> </cib> """, etree.tostring(self.tree).decode())
def test_remove_path(self): assert_xml_equal( '<alert id="alert" path="/path"/>', etree.tostring(alert.update_alert(self.tree, "alert", "")).decode() ) assert_xml_equal( """ <cib> <configuration> <alerts> <alert id="alert" path="/path"/> <alert id="alert1" path="/path1" description="nothing"/> </alerts> </configuration> </cib> """, etree.tostring(self.tree).decode() )
def test_id_not_exists(self): assert_raise_library_error( lambda: alert.update_alert(self.tree, "alert0", "/test"), (severities.ERROR, report_codes.CIB_ALERT_NOT_FOUND, { "alert": "alert0" }))