示例#1
0
 def test_create_upgrade(self):
     (self.config
         .runner.cib.load(
             filename="cib-empty-2.0.xml",
             name="load_cib_old_version"
         )
         .runner.cib.upgrade()
         .runner.cib.load()
         .env.push_cib(optional_in_conf=self.fixture_final_alerts)
     )
     cmd_alert.create_alert(
         self.env_assist.get_env(),
         "my-alert",
         "/my/path",
         {
             "instance": "value",
             "another": "val"
         },
         {"meta1": "val1"},
         "my description"
     )
     self.env_assist.assert_reports([
         (
             Severities.INFO,
             report_codes.CIB_UPGRADE_SUCCESSFUL,
             {},
             None
         ),
     ])
示例#2
0
 def test_create_upgrade(self):
     (self.config
         .runner.cib.load(
             filename="cib-empty-2.0.xml",
             name="load_cib_old_version"
         )
         .runner.cib.upgrade()
         .runner.cib.load()
         .env.push_cib(optional_in_conf=self.fixture_final_alerts)
     )
     cmd_alert.create_alert(
         self.env_assist.get_env(),
         "my-alert",
         "/my/path",
         {
             "instance": "value",
             "another": "val"
         },
         {"meta1": "val1"},
         "my description"
     )
     self.env_assist.assert_reports([
         (
             Severities.INFO,
             report_codes.CIB_UPGRADE_SUCCESSFUL,
             {},
             None
         ),
     ])
示例#3
0
    def test_upgrade_needed(self, mock_ensure_cib_version):
        original_cib_xml = """
            <cib validate-with="pacemaker-2.4.1">
                <configuration>
                </configuration>
            </cib>
        """
        self.mock_env._push_cib_xml(original_cib_xml)
        mock_ensure_cib_version.return_value = etree.XML(
            """
            <cib validate-with="pacemaker-2.5.0">
                <configuration>
                </configuration>
            </cib>
            """
        )
        cmd_alert.create_alert(
            self.mock_env,
            "my-alert",
            "/my/path",
            {
                "instance": "value",
                "another": "val"
            },
            {"meta1": "val1"},
            "my description"
        )
        assert_xml_equal(
            """
<cib validate-with="pacemaker-2.5.0">
    <configuration>
        <alerts>
            <alert id="my-alert" path="/my/path" description="my description">
                <meta_attributes id="my-alert-meta_attributes">
                    <nvpair
                        id="my-alert-meta_attributes-meta1"
                        name="meta1"
                        value="val1"
                    />
                </meta_attributes>
                <instance_attributes id="my-alert-instance_attributes">
                    <nvpair
                        id="my-alert-instance_attributes-another"
                        name="another"
                        value="val"
                    />
                    <nvpair
                        id="my-alert-instance_attributes-instance"
                        name="instance"
                        value="value"
                    />
                </instance_attributes>
            </alert>
        </alerts>
    </configuration>
</cib>
            """,
            self.mock_env._get_cib_xml()
        )
        self.assertEqual(1, mock_ensure_cib_version.call_count)
示例#4
0
 def test_create_no_upgrade(self):
     (self.config.runner.cib.load().env.push_cib(
         optional_in_conf=self.fixture_final_alerts))
     cmd_alert.create_alert(self.env_assist.get_env(), "my-alert",
                            "/my/path", {
                                "instance": "value",
                                "another": "val"
                            }, {"meta1": "val1"}, "my description")
示例#5
0
    def test_upgrade_needed(self, mock_ensure_cib_version):
        original_cib_xml = """
            <cib validate-with="pacemaker-2.4.1">
                <configuration>
                </configuration>
            </cib>
        """
        self.mock_env._push_cib_xml(original_cib_xml)
        mock_ensure_cib_version.return_value = etree.XML("""
            <cib validate-with="pacemaker-2.5.0">
                <configuration>
                </configuration>
            </cib>
            """)
        cmd_alert.create_alert(self.mock_env, "my-alert", "/my/path", {
            "instance": "value",
            "another": "val"
        }, {"meta1": "val1"}, "my description")
        assert_xml_equal(
            """
<cib validate-with="pacemaker-2.5.0">
    <configuration>
        <alerts>
            <alert id="my-alert" path="/my/path" description="my description">
                <meta_attributes id="my-alert-meta_attributes">
                    <nvpair
                        id="my-alert-meta_attributes-meta1"
                        name="meta1"
                        value="val1"
                    />
                </meta_attributes>
                <instance_attributes id="my-alert-instance_attributes">
                    <nvpair
                        id="my-alert-instance_attributes-another"
                        name="another"
                        value="val"
                    />
                    <nvpair
                        id="my-alert-instance_attributes-instance"
                        name="instance"
                        value="value"
                    />
                </instance_attributes>
            </alert>
        </alerts>
    </configuration>
</cib>
            """, self.mock_env._get_cib_xml())
        self.assertEqual(1, mock_ensure_cib_version.call_count)
示例#6
0
 def test_create_no_upgrade(self):
     (self.config
         .runner.cib.load()
         .env.push_cib(optional_in_conf=self.fixture_final_alerts)
     )
     cmd_alert.create_alert(
         self.env_assist.get_env(),
         "my-alert",
         "/my/path",
         {
             "instance": "value",
             "another": "val"
         },
         {"meta1": "val1"},
         "my description"
     )
示例#7
0
 def test_no_path(self, mock_upgrade_cib):
     assert_raise_library_error(
         lambda: cmd_alert.create_alert(self.mock_env, None, None, None,
                                        None),
         (Severities.ERROR, report_codes.REQUIRED_OPTION_IS_MISSING, {
             "option_name": "path"
         }))
     self.assertEqual(0, mock_upgrade_cib.call_count)
示例#8
0
 def test_no_path(self, mock_ensure_cib_version):
     assert_raise_library_error(
         lambda: cmd_alert.create_alert(self.mock_env, None, None, None,
                                        None),
         (Severities.ERROR, report_codes.REQUIRED_OPTION_IS_MISSING, {
             "option_names": ["path"]
         }))
     mock_ensure_cib_version.assert_not_called()
示例#9
0
 def test_no_path(self):
     self.env_assist.assert_raise_library_error(
         lambda: cmd_alert.create_alert(self.env_assist.get_env(), None,
                                        None, None, None),
         [
             (Severities.ERROR, report_codes.REQUIRED_OPTIONS_ARE_MISSING, {
                 "option_names": ["path"]
             }, None),
         ],
     )
示例#10
0
 def test_no_path(self, mock_upgrade_cib):
     assert_raise_library_error(
         lambda: cmd_alert.create_alert(
             self.mock_env, None, None, None, None
         ),
         (
             Severities.ERROR,
             report_codes.REQUIRED_OPTION_IS_MISSING,
             {"option_name": "path"}
         )
     )
     self.assertEqual(0, mock_upgrade_cib.call_count)
示例#11
0
 def test_no_path(self, mock_ensure_cib_version):
     assert_raise_library_error(
         lambda: cmd_alert.create_alert(
             self.mock_env, None, None, None, None
         ),
         (
             Severities.ERROR,
             report_codes.REQUIRED_OPTION_IS_MISSING,
             {"option_names": ["path"]}
         )
     )
     mock_ensure_cib_version.assert_not_called()
示例#12
0
 def test_no_path(self):
     self.env_assist.assert_raise_library_error(
         lambda: cmd_alert.create_alert(
             self.env_assist.get_env(), None, None, None, None
         ),
         [
             (
                 Severities.ERROR,
                 report_codes.REQUIRED_OPTION_IS_MISSING,
                 {"option_names": ["path"]},
                 None
             ),
         ],
     )