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))
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"], )
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), )
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))