Exemplo n.º 1
0
 def test_remove_description(self):
     assert_xml_equal(
         """
             <recipient id="alert-recipient-1" value="value1"/>
         """,
         etree.tostring(
             alert.update_recipient(self.mock_reporter,
                                    self.tree,
                                    "alert-recipient-1",
                                    description="")).decode())
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient id="alert-recipient-1" value="value1"/>
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode())
     self.assertEqual([], self.mock_reporter.report_item_list)
Exemplo n.º 2
0
 def test_update_same_value_duplicity_allowed(self):
     assert_xml_equal(
         '<recipient id="alert-recipient" value="test_val"/>',
         etree.tostring(alert.update_recipient(
             self.mock_reporter, self.tree, "alert-recipient",
             recipient_value="test_val", allow_same_value=True
         )).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient
                             id="alert-recipient-1"
                             value="value1"
                             description="desc"
                         />
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode()
     )
     self.assertEqual([], self.mock_reporter.report_item_list)
Exemplo n.º 3
0
 def test_update_same_value_duplicity_allowed(self):
     assert_xml_equal(
         '<recipient id="alert-recipient" value="test_val"/>',
         etree.tostring(
             alert.update_recipient(self.mock_reporter,
                                    self.tree,
                                    "alert-recipient",
                                    recipient_value="test_val",
                                    allow_same_value=True)).decode())
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient
                             id="alert-recipient-1"
                             value="value1"
                             description="desc"
                         />
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode())
     self.assertEqual([], self.mock_reporter.report_item_list)
Exemplo n.º 4
0
 def test_remove_description(self):
     assert_xml_equal(
         """
             <recipient id="alert-recipient-1" value="value1"/>
         """,
         etree.tostring(
            alert.update_recipient(
                self.mock_reporter, self.tree, "alert-recipient-1",
                description=""
            )
         ).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="test_val"/>
                         <recipient id="alert-recipient-1" value="value1"/>
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode()
     )
     self.assertEqual([], self.mock_reporter.report_item_list)
Exemplo n.º 5
0
def update_recipient(lib_env,
                     recipient_id,
                     instance_attribute_dict,
                     meta_attribute_dict,
                     recipient_value=None,
                     description=None,
                     allow_same_value=False):
    """
    Update existing recipient.

    lib_env -- LibraryEnvironment
    recipient_id -- id of recipient to be updated
    instance_attribute_dict -- dictionary of instance attributes to update
    meta_attribute_dict -- dictionary of meta attributes to update
    recipient_value -- new recipient value, if None old value will stay
        unchanged
    description -- new description, if empty string, old description will be
        deleted, if None old value will stay unchanged
    allow_same_value -- if True unique recipient value is not required
    """
    if not recipient_value and recipient_value is not None:
        raise LibraryError(
            reports.cib_alert_recipient_invalid_value(recipient_value))
    cib = lib_env.get_cib(REQUIRED_CIB_VERSION)
    recipient = alert.update_recipient(lib_env.report_processor,
                                       cib,
                                       recipient_id,
                                       recipient_value=recipient_value,
                                       description=description,
                                       allow_same_value=allow_same_value)
    alert.update_instance_attributes(recipient, instance_attribute_dict)
    alert.update_meta_attributes(recipient, meta_attribute_dict)

    lib_env.push_cib(cib)
Exemplo n.º 6
0
 def test_recipient_not_exists(self):
     assert_raise_library_error(
         lambda: alert.update_recipient(self.mock_reporter, self.tree,
                                        "recipient"),
         (severities.ERROR, report_codes.ID_NOT_FOUND, {
             "id": "recipient",
             "id_description": "Recipient"
         }))
Exemplo n.º 7
0
 def test_recipient_not_exists(self):
     assert_raise_library_error(
         lambda: alert.update_recipient(self.mock_reporter, self.tree,
                                        "missing-recipient"),
         (severities.ERROR, report_codes.ID_NOT_FOUND, {
             "id": "missing-recipient",
             "expected_types": ["recipient"],
             "context_type": "alerts",
             "context_id": "",
         }, None))
Exemplo n.º 8
0
 def test_duplicity_of_value_not_allowed(self):
     report_item = (severities.ERROR,
                    report_codes.CIB_ALERT_RECIPIENT_ALREADY_EXISTS, {
                        "alert": "alert",
                        "recipient": "value1"
                    }, report_codes.FORCE_ALERT_RECIPIENT_VALUE_NOT_UNIQUE)
     assert_raise_library_error(lambda: alert.update_recipient(
         self.mock_reporter, self.tree, "alert-recipient", "value1"))
     assert_report_item_list_equal(self.mock_reporter.report_item_list,
                                   [report_item])
Exemplo n.º 9
0
 def test_recipient_not_exists(self):
     assert_raise_library_error(
         lambda: alert.update_recipient(
             self.mock_reporter, self.tree, "recipient"),
         (
             severities.ERROR,
             report_codes.ID_NOT_FOUND,
             {
                 "id": "recipient",
                 "id_description": "Recipient"
             }
         )
     )
Exemplo n.º 10
0
 def test_recipient_not_exists(self):
     assert_raise_library_error(
         lambda: alert.update_recipient(
             self.mock_reporter, self.tree, "missing-recipient"),
         (
             severities.ERROR,
             report_codes.ID_NOT_FOUND,
             {
                 "id": "missing-recipient",
                 "expected_types": ["recipient"],
                 "context_type": "alerts",
                 "context_id": "",
             },
             None
         )
     )
Exemplo n.º 11
0
 def test_duplicity_of_value_allowed(self):
     assert_xml_equal(
         """
         <recipient id="alert-recipient" value="value1"/>
         """,
         etree.tostring(
             alert.update_recipient(
                 self.mock_reporter,
                 self.tree,
                 "alert-recipient",
                 recipient_value="value1",
                 allow_same_value=True,
             )
         ).decode(),
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="value1"/>
                         <recipient
                             id="alert-recipient-1"
                             value="value1"
                             description="desc"
                         />
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode(),
     )
     assert_report_item_list_equal(
         self.mock_reporter.report_item_list,
         [
             (
                 severities.WARNING,
                 report_codes.CIB_ALERT_RECIPIENT_ALREADY_EXISTS,
                 {"alert": "alert", "recipient": "value1"},
             )
         ],
     )
Exemplo n.º 12
0
def update_recipient(
    lib_env,
    recipient_id,
    instance_attribute_dict,
    meta_attribute_dict,
    recipient_value=None,
    description=None,
    allow_same_value=False
):
    """
    Update existing recipient.

    lib_env -- LibraryEnvironment
    recipient_id -- id of recipient to be updated
    instance_attribute_dict -- dictionary of instance attributes to update
    meta_attribute_dict -- dictionary of meta attributes to update
    recipient_value -- new recipient value, if None old value will stay
        unchanged
    description -- new description, if empty string, old description will be
        deleted, if None old value will stay unchanged
    allow_same_value -- if True unique recipient value is not required
    """
    if not recipient_value and recipient_value is not None:
        raise LibraryError(
            reports.cib_alert_recipient_invalid_value(recipient_value)
        )
    cib = lib_env.get_cib(REQUIRED_CIB_VERSION)
    id_provider = IdProvider(cib)
    recipient = alert.update_recipient(
        lib_env.report_processor,
        cib,
        recipient_id,
        recipient_value=recipient_value,
        description=description,
        allow_same_value=allow_same_value
    )
    arrange_first_instance_attributes(
        recipient, instance_attribute_dict, id_provider
    )
    arrange_first_meta_attributes(
        recipient, meta_attribute_dict, id_provider
    )

    lib_env.push_cib()
Exemplo n.º 13
0
Arquivo: alert.py Projeto: vvidic/pcs
def update_recipient(
    lib_env: LibraryEnvironment,
    recipient_id,
    instance_attribute_dict,
    meta_attribute_dict,
    recipient_value=None,
    description=None,
    allow_same_value=False,
):
    """
    Update existing recipient.

    lib_env -- LibraryEnvironment
    recipient_id -- id of recipient to be updated
    instance_attribute_dict -- dictionary of instance attributes to update
    meta_attribute_dict -- dictionary of meta attributes to update
    recipient_value -- new recipient value, if None old value will stay
        unchanged
    description -- new description, if empty string, old description will be
        deleted, if None old value will stay unchanged
    allow_same_value -- if True unique recipient value is not required
    """
    if not recipient_value and recipient_value is not None:
        raise LibraryError(
            ReportItem.error(
                reports.messages.CibAlertRecipientValueInvalid(
                    recipient_value)))
    cib = lib_env.get_cib()
    id_provider = IdProvider(cib)
    recipient = alert.update_recipient(
        lib_env.report_processor,
        cib,
        recipient_id,
        recipient_value=recipient_value,
        description=description,
        allow_same_value=allow_same_value,
    )
    arrange_first_instance_attributes(recipient, instance_attribute_dict,
                                      id_provider)
    arrange_first_meta_attributes(recipient, meta_attribute_dict, id_provider)

    lib_env.push_cib()
Exemplo n.º 14
0
 def test_duplicity_of_value_not_allowed(self):
     report_item = (
         severities.ERROR,
         report_codes.CIB_ALERT_RECIPIENT_ALREADY_EXISTS,
         {
             "alert": "alert",
             "recipient": "value1"
         },
         report_codes.FORCE_ALERT_RECIPIENT_VALUE_NOT_UNIQUE
     )
     assert_raise_library_error(
         lambda: alert.update_recipient(
             self.mock_reporter, self.tree, "alert-recipient", "value1"
         ),
         report_item
     )
     assert_report_item_list_equal(
         self.mock_reporter.report_item_list,
         [report_item]
     )
Exemplo n.º 15
0
 def test_duplicity_of_value_allowed(self):
     assert_xml_equal(
         """
         <recipient id="alert-recipient" value="value1"/>
         """,
         etree.tostring(alert.update_recipient(
             self.mock_reporter, self.tree, "alert-recipient",
             recipient_value="value1", allow_same_value=True
         )).decode()
     )
     assert_xml_equal(
         """
         <cib>
             <configuration>
                 <alerts>
                     <alert id="alert" path="/path">
                         <recipient id="alert-recipient" value="value1"/>
                         <recipient
                             id="alert-recipient-1"
                             value="value1"
                             description="desc"
                         />
                     </alert>
                 </alerts>
             </configuration>
         </cib>
         """,
         etree.tostring(self.tree).decode()
     )
     assert_report_item_list_equal(
         self.mock_reporter.report_item_list,
         [(
             severities.WARNING,
             report_codes.CIB_ALERT_RECIPIENT_ALREADY_EXISTS,
             {
                 "alert": "alert",
                 "recipient": "value1"
             }
         )]
     )