예제 #1
0
 def test_with_description(self):
     assert_xml_equal(
         """
         <recipient
             id="alert-recipient-1"
             value="value1"
             description="desc"
         />
         """,
         etree.tostring(
             alert.add_recipient(self.mock_reporter,
                                 self.tree,
                                 "alert",
                                 "value1",
                                 description="desc")).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)
예제 #2
0
 def test_duplicity_of_value_allowed(self):
     assert_xml_equal(
         '<recipient id="alert-recipient-1" value="test_val"/>',
         etree.tostring(
             alert.add_recipient(self.mock_reporter,
                                 self.tree,
                                 "alert",
                                 "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="test_val"/>
                     </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": "test_val"
           })])
예제 #3
0
 def test_alert_not_exist(self):
     assert_raise_library_error(
         lambda: alert.add_recipient(self.mock_reporter, self.tree,
                                     "alert1", "test_val"),
         (severities.ERROR, report_codes.CIB_ALERT_NOT_FOUND, {
             "alert": "alert1"
         }))
예제 #4
0
 def test_with_description(self):
     assert_xml_equal(
         """
         <recipient
             id="alert-recipient-1"
             value="value1"
             description="desc"
         />
         """,
         etree.tostring(alert.add_recipient(
             self.mock_reporter, self.tree, "alert", "value1",
             description="desc"
         )).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)
예제 #5
0
파일: alert.py 프로젝트: rriifftt/pcs
def add_recipient(lib_env,
                  alert_id,
                  recipient_value,
                  instance_attribute_dict,
                  meta_attribute_dict,
                  recipient_id=None,
                  description=None,
                  allow_same_value=False):
    """
    Add new recipient to alert witch id alert_id.

    lib_env -- LibraryEnvironment
    alert_id -- id of alert to which new recipient should be added
    recipient_value -- value of new recipient
    instance_attribute_dict -- dictionary of instance attributes to update
    meta_attribute_dict -- dictionary of meta attributes to update
    recipient_id -- id of new recipient, if None it will be generated
    description -- recipient description
    allow_same_value -- if True unique recipient value is not required
    """
    if not recipient_value:
        raise LibraryError(reports.required_option_is_missing(["value"]))

    cib = lib_env.get_cib(REQUIRED_CIB_VERSION)
    recipient = alert.add_recipient(lib_env.report_processor,
                                    cib,
                                    alert_id,
                                    recipient_value,
                                    recipient_id=recipient_id,
                                    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)
예제 #6
0
 def test_id_exists(self):
     assert_raise_library_error(
         lambda: alert.add_recipient(self.mock_reporter, self.tree, "alert",
                                     "value1", "alert-recipient"),
         (severities.ERROR, report_codes.ID_ALREADY_EXISTS, {
             "id": "alert-recipient"
         }))
     self.assertEqual([], self.mock_reporter.report_item_list)
예제 #7
0
파일: test_alert.py 프로젝트: cwjenkins/pcs
 def test_alert_not_exist(self):
     assert_raise_library_error(
         lambda: alert.add_recipient(self.mock_reporter, self.tree,
                                     "alert1", "test_val"),
         (severities.ERROR, report_codes.ID_NOT_FOUND, {
             "id": "alert1",
             "context_type": "alerts",
             "context_id": "",
             "id_description": "alert"
         }))
예제 #8
0
 def test_duplicity_of_value_not_allowed(self):
     report_item = (severities.ERROR,
                    report_codes.CIB_ALERT_RECIPIENT_ALREADY_EXISTS, {
                        "alert": "alert",
                        "recipient": "test_val"
                    }, report_codes.FORCE_ALERT_RECIPIENT_VALUE_NOT_UNIQUE)
     assert_raise_library_error(lambda: alert.add_recipient(
         self.mock_reporter, self.tree, "alert", "test_val"))
     assert_report_item_list_equal(self.mock_reporter.report_item_list,
                                   [report_item])
예제 #9
0
파일: test_alert.py 프로젝트: dchirikov/pcs
 def test_alert_not_exist(self):
     assert_raise_library_error(
         lambda: alert.add_recipient(
             self.mock_reporter, self.tree, "alert1", "test_val"
         ),
         (
             severities.ERROR,
             report_codes.CIB_ALERT_NOT_FOUND,
             {"alert": "alert1"}
         )
     )
예제 #10
0
 def test_id_exists(self):
     assert_raise_library_error(
         lambda: alert.add_recipient(
             self.mock_reporter, self.tree, "alert", "value1",
             "alert-recipient"
         ),
         (
             severities.ERROR,
             report_codes.ID_ALREADY_EXISTS,
             {"id": "alert-recipient"}
         )
     )
     self.assertEqual([], self.mock_reporter.report_item_list)
예제 #11
0
 def test_alert_not_exist(self):
     assert_raise_library_error(
         lambda: alert.add_recipient(self.mock_reporter, self.tree,
                                     "alert1", "test_val"),
         (
             severities.ERROR,
             report_codes.ID_NOT_FOUND,
             {
                 "id": "alert1",
                 "expected_types": ["alert"],
                 "context_type": "alerts",
                 "context_id": "",
             },
             None,
         ),
     )
예제 #12
0
 def test_alert_not_exist(self):
     assert_raise_library_error(
         lambda: alert.add_recipient(
             self.mock_reporter, self.tree, "alert1", "test_val"
         ),
         (
             severities.ERROR,
             report_codes.ID_NOT_FOUND,
             {
                 "id": "alert1",
                 "context_type": "alerts",
                 "context_id": "",
                 "id_description": "alert"
             }
         )
     )
예제 #13
0
파일: alert.py 프로젝트: tomjelinek/pcs
def add_recipient(
    lib_env,
    alert_id,
    recipient_value,
    instance_attribute_dict,
    meta_attribute_dict,
    recipient_id=None,
    description=None,
    allow_same_value=False
):
    """
    Add new recipient to alert witch id alert_id.

    lib_env -- LibraryEnvironment
    alert_id -- id of alert to which new recipient should be added
    recipient_value -- value of new recipient
    instance_attribute_dict -- dictionary of instance attributes to update
    meta_attribute_dict -- dictionary of meta attributes to update
    recipient_id -- id of new recipient, if None it will be generated
    description -- recipient description
    allow_same_value -- if True unique recipient value is not required
    """
    if not recipient_value:
        raise LibraryError(
            reports.required_option_is_missing(["value"])
        )

    cib = lib_env.get_cib(REQUIRED_CIB_VERSION)
    id_provider = IdProvider(cib)
    recipient = alert.add_recipient(
        lib_env.report_processor,
        cib,
        alert_id,
        recipient_value,
        recipient_id=recipient_id,
        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()
예제 #14
0
def add_recipient(
    lib_env: LibraryEnvironment,
    alert_id,
    recipient_value,
    instance_attribute_dict,
    meta_attribute_dict,
    recipient_id=None,
    description=None,
    allow_same_value=False,
):
    """
    Add new recipient to alert witch id alert_id.

    lib_env -- LibraryEnvironment
    alert_id -- id of alert to which new recipient should be added
    recipient_value -- value of new recipient
    instance_attribute_dict -- dictionary of instance attributes to update
    meta_attribute_dict -- dictionary of meta attributes to update
    recipient_id -- id of new recipient, if None it will be generated
    description -- recipient description
    allow_same_value -- if True unique recipient value is not required
    """
    if not recipient_value:
        raise LibraryError(
            ReportItem.error(
                reports.messages.RequiredOptionsAreMissing(["value"])))

    cib = lib_env.get_cib(REQUIRED_CIB_VERSION)
    id_provider = IdProvider(cib)
    recipient = alert.add_recipient(
        lib_env.report_processor,
        cib,
        alert_id,
        recipient_value,
        recipient_id=recipient_id,
        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()
예제 #15
0
 def test_duplicity_of_value_not_allowed(self):
     report_item = (
         severities.ERROR,
         report_codes.CIB_ALERT_RECIPIENT_ALREADY_EXISTS,
         {
             "alert": "alert",
             "recipient": "test_val"
         },
         report_codes.FORCE_ALERT_RECIPIENT_VALUE_NOT_UNIQUE
     )
     assert_raise_library_error(
         lambda: alert.add_recipient(
             self.mock_reporter, self.tree, "alert", "test_val"
         ),
         report_item
     )
     assert_report_item_list_equal(
         self.mock_reporter.report_item_list,
         [report_item]
     )
예제 #16
0
 def test_duplicity_of_value_allowed(self):
     assert_xml_equal(
         '<recipient id="alert-recipient-1" value="test_val"/>',
         etree.tostring(
             alert.add_recipient(
                 self.mock_reporter, self.tree, "alert", "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="test_val"/>
                     </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": "test_val"
             }
         )]
     )