Beispiel #1
0
 def setUp(self):
     self.corosync_conf_file = get_tmp_file(
         "tier1_cluster_config_uuid_generate.conf")
     self.pcs_runner = PcsRunner(
         cib_file=None,
         corosync_conf_opt=self.corosync_conf_file.name,
     )
Beispiel #2
0
 def setUp(self):
     self.new_cib_file = get_tmp_file(self._get_tmp_file_name())
     self.pcs_runner_orig = PcsRunner(
         cib_file=get_test_resource("cib-resources.xml")
     )
     self.pcs_runner_new = PcsRunner(cib_file=self.new_cib_file.name)
     write_file_to_tmpfile(
         get_test_resource("cib-empty.xml"), self.new_cib_file
     )
     self.maxDiff = None
Beispiel #3
0
class ResourceConfigJson(TestCase):
    def setUp(self):
        self.pcs_runner = PcsRunner(
            cib_file=get_test_resource("cib-resources.xml"),
        )

    def test_all(self):
        stdout, retval = self.pcs_runner.run(
            ["resource", "config", "--output-format=json"]
        )
        self.assertEqual(retval, 0)
        expected = ListCibResourcesDto(
            primitives=[
                resources_dto.PRIMITIVE_R1,
                resources_dto.PRIMITIVE_R7,
                resources_dto.PRIMITIVE_R5,
                resources_dto.STONITH_S1,
                resources_dto.PRIMITIVE_R2,
                resources_dto.PRIMITIVE_R3,
                resources_dto.PRIMITIVE_R4,
                resources_dto.PRIMITIVE_R6,
            ],
            clones=[
                resources_dto.CLONE_G1,
                resources_dto.CLONE_R6,
            ],
            groups=[
                resources_dto.GROUP_G2,
                resources_dto.GROUP_G1,
            ],
            bundles=[
                resources_dto.BUNDLE_B1,
                resources_dto.BUNDLE_B2,
            ],
        )
        self.assertEqual(json.loads(stdout), to_dict(expected))

    def test_get_multiple(self):
        stdout, retval = self.pcs_runner.run(
            ["resource", "config", "--output-format=json", "G1-clone", "R1"]
        )
        self.assertEqual(retval, 0)
        expected = ListCibResourcesDto(
            primitives=[
                resources_dto.PRIMITIVE_R1,
                resources_dto.PRIMITIVE_R2,
                resources_dto.PRIMITIVE_R3,
                resources_dto.PRIMITIVE_R4,
            ],
            clones=[resources_dto.CLONE_G1],
            groups=[resources_dto.GROUP_G1],
            bundles=[],
        )
        self.assertEqual(json.loads(stdout), to_dict(expected))
Beispiel #4
0
class ClusterUuidGenerateLocal(AssertPcsMixin, TestCase):
    def setUp(self):
        self.corosync_conf_file = get_tmp_file(
            "tier1_cluster_config_uuid_generate.conf")
        self.pcs_runner = PcsRunner(
            cib_file=None,
            corosync_conf_opt=self.corosync_conf_file.name,
        )

    def tearDown(self):
        self.corosync_conf_file.close()

    def test_uuid_not_present(self):
        write_data_to_tmpfile(
            fixture_corosync_conf_minimal(no_cluster_uuid=True),
            self.corosync_conf_file,
        )
        self.assert_pcs_success(["cluster", "config", "uuid", "generate"])
        corosync_json_after, _ = self.pcs_runner.run(
            ["cluster", "config", "show", "--output-format=json"])
        self.assertIn("cluster_uuid", json.loads(corosync_json_after))

    def test_uuid_present(self):
        write_data_to_tmpfile(
            fixture_corosync_conf_minimal(),
            self.corosync_conf_file,
        )
        self.assert_pcs_fail(
            ["cluster", "config", "uuid", "generate"],
            stdout_full="Error: Cluster UUID has already been set, use --force "
            "to override\n"
            "Error: Errors have occurred, therefore pcs is unable "
            "to continue\n",
        )

    def test_uuid_present_with_force(self):
        write_data_to_tmpfile(
            fixture_corosync_conf_minimal(),
            self.corosync_conf_file,
        )
        corosync_json_before, _ = self.pcs_runner.run(
            ["cluster", "config", "show", "--output-format=json"])
        self.assert_pcs_success(
            ["cluster", "config", "uuid", "generate", "--force"],
            stdout_full="Warning: Cluster UUID has already been set\n",
        )
        corosync_json_after, _ = self.pcs_runner.run(
            ["cluster", "config", "show", "--output-format=json"])
        self.assertNotEqual(
            json.loads(corosync_json_before)["cluster_uuid"],
            json.loads(corosync_json_after)["cluster_uuid"],
        )
Beispiel #5
0
 def setUp(self):
     # pylint: disable=invalid-name
     self.temp_cib = get_tmp_file("tier1_cib_resource_group_ungroup")
     self.pcs_runner = PcsRunner(self.temp_cib.name)
     xml_manip = XmlManipulation.from_file(self.empty_cib)
     xml_manip.append_to_first_tag_name(
         "resources",
         FIXTURE_CLONE,
         FIXTURE_DUMMY,
     )
     xml_manip.append_to_first_tag_name(
         "configuration",
         FIXTURE_TAGS_CONFIG_XML,
     )
     xml_manip.append_to_first_tag_name(
         "constraints",
         """
         <rsc_location id="location-C-clone-rh7-1-INFINITY" node="rh7-1"
             rsc="C-clone" score="INFINITY"/>
         """,
         """
         <rsc_location id="location-TagCloneOnly-rh7-1-INFINITY"
             node="rh7-1" rsc="TagCloneOnly" score="INFINITY"/>
         """,
     )
     write_data_to_tmpfile(str(xml_manip), self.temp_cib)
Beispiel #6
0
 def setUp(self):
     shutil.copy(coro_conf, temp_conf)
     # The tested commands work differently when non-live corosync.conf
     # (--corosync_conf) is used. In these tests it is not possible to cover
     # all the live config behavior, so we stick to using a non-live config.
     # Live behavior is tested in pcs_test.tier0.lib.commands.test_quorum.
     self.pcs_runner = PcsRunner(cib_file=None, corosync_conf_opt=temp_conf)
Beispiel #7
0
 def setUp(self):
     shutil.copy(EMPTY_CIB, TEMP_CIB)
     self.pcs_runner = PcsRunner(None)
     ensure_booth_config_not_exists()
     self.assert_pcs_success(
         fake_file("booth setup sites 1.1.1.1 2.2.2.2 arbitrators 3.3.3.3"))
     self.pcs_runner.cib_file = TEMP_CIB
Beispiel #8
0
 def setUp(self):
     # pylint: disable=invalid-name
     self.temp_cib = get_tmp_file("tier1_cib_resource_group_ungroup")
     self.pcs_runner = PcsRunner(self.temp_cib.name)
     xml_manip = XmlManipulation.from_file(self.empty_cib)
     xml_manip.append_to_first_tag_name("resources", FIXTURE_AGROUP_XML)
     xml_manip.append_to_first_tag_name(
         "configuration",
         """
         <tags>
             <tag id="T1">
                 <obj_ref id="AGroup"/>
             </tag>
             <tag id="T2">
                 <obj_ref id="AGroup"/>
             </tag>
         </tags>
         """,
     )
     xml_manip.append_to_first_tag_name(
         "constraints",
         """
         <rsc_location id="location-AGroup-rh7-1-INFINITY" node="rh7-1"
             rsc="AGroup" score="INFINITY"/>
         """,
         """
         <rsc_location id="location-T1-rh7-1-INFINITY" node="rh7-1" rsc="T1"
             score="INFINITY"/>
         """,
     )
     write_data_to_tmpfile(str(xml_manip), self.temp_cib)
Beispiel #9
0
 def setUp(self):
     self.temp_cib = get_tmp_file("tier1_cib_resource_clone_unclone_clone")
     self.pcs_runner = PcsRunner(self.temp_cib.name)
     self.set_cib_file(FIXTURE_PRIMITIVE_FOR_CLONE)
     self.stonith_deprecation_warning = (
         "Deprecation Warning: Ability of this command to accept stonith "
         "resources is deprecated and will be removed in a future release.\n"
     )
Beispiel #10
0
 def setUp(self):
     shutil.copy(EMPTY_CIB, TEMP_CIB)
     self.pcs_runner = PcsRunner(None)
     ensure_booth_config_not_exists()
     self.assert_pcs_success(
         fake_file("booth setup sites 1.1.1.1 2.2.2.2 arbitrators 3.3.3.3"))
     self.pcs_runner.cib_file = TEMP_CIB
     self.lib = mock.Mock(spec_set=["booth"])
     self.lib.booth = mock.Mock(spec_set=["create_in_cluster"])
Beispiel #11
0
 def setUp(self):
     self.corosync_conf_file = get_tmp_file(
         "tier1_cluster_config_show_corosync.conf")
     self.pcs_runner = PcsRunner(
         cib_file=None,
         corosync_conf_opt=self.corosync_conf_file.name,
     )
     write_data_to_tmpfile(fixture_corosync_conf_minimal(),
                           self.corosync_conf_file)
Beispiel #12
0
 def setUp(self):
     # pylint cannot possibly know this is being mixed into TestCase classes
     # pylint: disable=invalid-name
     self.booth_dir = get_tmp_dir("tier1_booth")
     self.booth_cfg_path = os.path.join(self.booth_dir.name, "booth.cfg")
     self.booth_key_path = os.path.join(self.booth_dir.name, "booth.key")
     self.temp_cib = get_tmp_file("tier1_booth")
     write_file_to_tmpfile(EMPTY_CIB, self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
Beispiel #13
0
class ResourceConfigCmdMixin:
    # pylint: disable=invalid-name
    def setUp(self):
        self.new_cib_file = get_tmp_file(self._get_tmp_file_name())
        self.pcs_runner_orig = PcsRunner(
            cib_file=get_test_resource("cib-resources.xml")
        )
        self.pcs_runner_new = PcsRunner(cib_file=self.new_cib_file.name)
        write_file_to_tmpfile(
            get_test_resource("cib-empty.xml"), self.new_cib_file
        )
        self.maxDiff = None

    def tearDown(self):
        self.new_cib_file.close()

    def _get_as_json(self, runner):
        stdout, retval = runner.run(
            ["resource", "config", "--output-format=json"]
        )
        self.assertEqual(retval, 0)
        return json.loads(stdout)

    def test_all(self):
        stdout, retval = self.pcs_runner_orig.run(
            ["resource", "config", "--output-format=cmd"]
        )
        self.assertEqual(retval, 0)
        cmds = [
            split(cmd)[1:]
            for cmd in stdout.replace("\\\n", "").strip().split(";\n")
        ]
        for cmd in cmds:
            stdout, retval = self.pcs_runner_new.run(cmd)
            self.assertEqual(
                retval,
                0,
                f"Command {cmd} exited with {retval}\nstdout:\n{stdout}\n",
            )
        self.assertEqual(
            self._get_as_json(self.pcs_runner_new),
            self._get_as_json(self.pcs_runner_orig),
        )
Beispiel #14
0
    def set_up(self):
        fixture_dir = get_test_resource("temp_fixtures")
        os.makedirs(fixture_dir, exist_ok=True)
        self._cache_path = os.path.join(fixture_dir, self._cache_name)
        self._pcs_runner = PcsRunner(self._cache_path)

        with open(self._empty_cib_path, "r") as template_file, open(
            self.cache_path, "w"
        ) as cache_file:
            cache_file.write(template_file.read())
        self._setup_cib()
Beispiel #15
0
    def setUp(self):
        self.temp_cib = get_tmp_file("tier1_cluster_cib_push")
        self.pcs_runner = PcsRunner(self.temp_cib.name)
        write_data_to_tmpfile(CIB_EPOCH, self.temp_cib)

        self.updated_cib = get_tmp_file("tier1_cluster_cib_push_updated")
        write_data_to_tmpfile("<cib/>", self.updated_cib)
        self.cib_push_cmd = f"cluster cib-push {self.updated_cib.name}".split()
        self.cib_push_diff_cmd = self.cib_push_cmd + [
            f"diff-against={self.temp_cib.name}"
        ]
Beispiel #16
0
 def setUp(self):
     # pylint cannot know this will be mixed into a TetsCase class
     # pylint: disable=invalid-name
     shutil.copy(EMPTY_CIB, TEMP_CIB)
     self.pcs_runner = PcsRunner(None)
     ensure_booth_config_not_exists()
     self.assert_pcs_success(
         fake_file("booth setup sites 1.1.1.1 2.2.2.2 arbitrators 3.3.3.3"))
     self.pcs_runner.cib_file = TEMP_CIB
     self.lib = mock.Mock(spec_set=["booth"])
     self.lib.booth = mock.Mock(spec_set=["remove_from_cluster"])
Beispiel #17
0
 def setUp(self):
     self.corosync_conf_file = get_tmp_file(
         "tier1_cluster_setup_local_corosync.conf")
     self.known_hosts_file = get_tmp_file(
         "tier1_cluster_setup_local_known-hosts")
     self.pcs_runner = PcsRunner(
         cib_file=None,
         corosync_conf_opt=self.corosync_conf_file.name,
         mock_settings={
             "pcsd_known_hosts_location": self.known_hosts_file.name,
         },
     )
Beispiel #18
0
class StonithConfigJson(TestCase):
    def setUp(self):
        self.pcs_runner = PcsRunner(
            cib_file=get_test_resource("cib-resources.xml"),
        )
        self.maxDiff = None

    def test_all(self):
        stdout, retval = self.pcs_runner.run(
            ["stonith", "config", "--output-format=json"],
            ignore_stderr=True,
        )
        self.assertEqual(retval, 0)
        expected = ListCibResourcesDto(
            primitives=[
                resources_dto.STONITH_S2,
                resources_dto.STONITH_S1,
            ],
            clones=[],
            groups=[],
            bundles=[],
        )
        self.assertEqual(json.loads(stdout), to_dict(expected))

    def test_get_specified(self):
        stdout, retval = self.pcs_runner.run(
            ["stonith", "config", "--output-format=json", "S1"],
            ignore_stderr=True,
        )
        self.assertEqual(retval, 0)
        expected = ListCibResourcesDto(
            primitives=[
                resources_dto.STONITH_S1,
            ],
            clones=[],
            groups=[],
            bundles=[],
        )
        self.assertEqual(json.loads(stdout), to_dict(expected))
Beispiel #19
0
 def setUp(self):
     # pylint: disable=invalid-name
     self.temp_cib = get_tmp_file("tier1_cib_resource_move")
     self.pcs_runner = PcsRunner(self.temp_cib.name)
     xml_manip = XmlManipulation.from_file(self.empty_cib)
     xml_manip.append_to_first_tag_name("resources", fixture_primitive)
     xml_manip.append_to_first_tag_name(
         "constraints",
         *fixture_constraints,
     )
     xml_manip.append_to_first_tag_name(
         "nodes",
         *fixture_nodes,
     )
     write_data_to_tmpfile(str(xml_manip), self.temp_cib)
Beispiel #20
0
    def fixture_cib(self):
        shutil.copy(self.empty_cib, self.temp_cib)
        self.pcs_runner = PcsRunner(self.temp_cib)
        self.assert_pcs_success(
            "resource create --no-default-ops R ocf:heartbeat:Dummy")
        #add to cib:
        # <primitive class="ocf" id="R" provider="heartbeat" type="Dummy">
        #   <operations>
        #     <op id="R-monitor-interval-60s" interval="60s"
        #       name="monitor"
        #     />
        #   </operations>
        # </primitive>
        with open(self.temp_cib) as cib_file:
            cib_content = cib_file.read()

        #clean
        self.pcs_runner = None
        shutil.copy(self.empty_cib, self.temp_cib)

        return cib_content
Beispiel #21
0
 def setUp(self):
     self.temp_cib = get_tmp_file("tier1_status_xml_status")
     write_file_to_tmpfile(rc("cib-empty.xml"), self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
Beispiel #22
0
 def setUp(self):
     self.temp_cib = get_tmp_file("tier0_statust_stonith_warning")
     write_file_to_tmpfile(self.empty_cib, self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
Beispiel #23
0
 def setUp(self):
     # pylint: disable=invalid-name
     self.temp_cib = get_tmp_file("tier1_status_resource_stonith_status")
     write_file_to_tmpfile(self.cib_file, self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
Beispiel #24
0
 def setUp(self):
     # pylint: disable=invalid-name
     self.temp_cib = get_tmp_file("tier1_cib_options")
     self.pcs_runner = PcsRunner(self.temp_cib.name)
Beispiel #25
0
 def setUp(self):
     # pylint: disable=invalid-name
     self.temp_cib = get_tmp_file("tier1_tag")
     write_file_to_tmpfile(tags_cib, self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
Beispiel #26
0
 def setUp(self):
     # pylint cannot know this will be mixed into a TetsCase class
     # pylint: disable=invalid-name
     self.temp_cib = get_tmp_file("tier1_booth_delete_remove")
     write_file_to_tmpfile(EMPTY_CIB, self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
Beispiel #27
0
 def setUp(self):
     self.temp_cib = get_tmp_file("tier1_misc")
     write_file_to_tmpfile(rc("cib-empty-1.2.xml"), self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
     self.pcs_runner.mock_settings = get_mock_settings(
         "crm_resource_binary")
Beispiel #28
0
 def setUp(self):
     self.temp_cib = get_tmp_file("tier1_cib_resource_manage_unmanage")
     write_file_to_tmpfile(self.empty_cib, self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
Beispiel #29
0
 def setUp(self):
     self.temp_cib = get_tmp_file("tier1_alert")
     write_file_to_tmpfile(empty_cib, self.temp_cib)
     self.pcs_runner = PcsRunner(self.temp_cib.name)
Beispiel #30
0
 def setUp(self):
     # pylint cannot possibly know this is being mixed into TestCase classes
     # pylint: disable=invalid-name
     self.pcs_runner = PcsRunner(None)