Exemplo n.º 1
0
 def test_get_all_resources_2(self):
     """Dedicated test for temporarily purposes."""
     status = ClusterStatusPcs(executor=run_cmd_groups)
     self.assertNotEqual(status, None)
     resources = status.get_all_resources()
     self.assertEqual(type(resources), list)
     print(resources)
Exemplo n.º 2
0
 def test_get_resource_from_cloned_group_by_name(self):
     status = ClusterStatusPcs(executor=run_cmd_groups)
     self.assertNotEqual(status, None)
     res = status.get_resource_from_cloned_group_by_name("test-1")
     self.assertNotEqual(res, None)
     self.assertEqual(res.name, "test-1")
     self.assertEqual(res.group, "io_group")
     self.assertTrue(res.clone)
Exemplo n.º 3
0
    def test_get_clone_resource_by_name(self):
        status = ClusterStatusPcs(executor=run_cmd)
        self.assertNotEqual(status, None)
        res = status.get_clone_resource_by_name("test-cl")
        self.assertTrue(isinstance(res, ClusterCloneResource))
        self.assertEqual(res.name, "test-cl")
        self.assertEqual(len(res.copies), 2)

        res = status.get_clone_resource_by_name("does-not-exist")
        self.assertEqual(res, None)
Exemplo n.º 4
0
 def test_get_summary(self):
     status = ClusterStatusPcs(executor=run_cmd)
     self.assertNotEqual(status, None)
     summary = status.get_summary()
     self.assertTrue(summary.quorum)
     self.assertFalse(summary.stonith_enabled)
     self.assertFalse(summary.maintenance_mode)
     self.assertEqual(summary.num_nodes, 2)
     self.assertEqual(summary.num_resources_configured, 4)
     self.assertEqual(summary.num_resources_disabled, 0)
Exemplo n.º 5
0
 def test_check_nodes_online(self):
     status = ClusterStatusPcs(executor=run_cmd)
     validator = ClusterTestAdapter(status, None)
     nodes = [
         "ssc-vm-1550.colo.seagate.com", "ssc-vm-1551.colo.seagate.com"
     ]
     self.assertTrue(validator.check_nodes_online(nodelist=nodes))
Exemplo n.º 6
0
 def test_check_resource_layout(self):
     status = ClusterStatusPcs(executor=run_cmd_groups)
     node_list = ["localhrost", "localfrost"]
     file_list = [f"{DIR_PATH}/all-combinations.json"]
     layout = ClusterLayoutJson.from_json_file(file_list, node_list)
     validator = ClusterTestAdapter(status, layout)
     self.assertTrue(validator.check_resource_layout())
Exemplo n.º 7
0
    def test_get_nodes(self):
        status = ClusterStatusPcs(executor=run_cmd)
        self.assertNotEqual(status, None)

        nodes = status.get_nodes()
        self.assertEqual(len(nodes), 2)

        expected = [
            "ssc-vm-1550.colo.seagate.com",
            "ssc-vm-1551.colo.seagate.com",
        ]
        names = set()
        for node in nodes:
            self.assertTrue(node.online)
            self.assertFalse(node.standby)
            self.assertFalse(node.unclean)
            self.assertEqual(node.resources_running, 2)
            names.add(node.name)

        self.assertEqual(names, set(expected))
Exemplo n.º 8
0
    def test_get_unique_resource_by_name(self):
        status = ClusterStatusPcs(executor=run_cmd_groups)
        self.assertNotEqual(status, None)
        res = status.get_unique_resource_by_name("test-4")
        self.assertTrue(isinstance(res, ClusterResource))
        self.assertEqual(res.name, "test-4")
        self.assertEqual(res.group, "")

        res = status.get_unique_resource_by_name("does-not-exist")
        self.assertEqual(res, None)

        status = ClusterStatusPcs(executor=run_cmd_groups)
        self.assertNotEqual(status, None)
        res = status.get_unique_resource_by_name("test-5")
        self.assertTrue(isinstance(res, ClusterResource))
        self.assertEqual(res.name, "test-5")
        self.assertEqual(res.group, "alone")

        res = status.get_unique_resource_by_name("test-3")
        self.assertEqual(res, None)
Exemplo n.º 9
0
 def test_get_all_resources(self):
     status = ClusterStatusPcs(executor=run_cmd)
     self.assertNotEqual(status, None)
     resources = status.get_all_resources()
     self.assertEqual(type(resources), list)
     self.assertEqual(len(resources), 3)
Exemplo n.º 10
0
 def test_check_nodes_standby(self):
     status = ClusterStatusPcs(executor=run_cmd_groups)
     validator = ClusterTestAdapter(status, None)
     self.assertTrue(validator.check_nodes_standby())
Exemplo n.º 11
0
 def test_check_resources_managed(self):
     status = ClusterStatusPcs(executor=run_cmd)
     validator = ClusterTestAdapter(status, None)
     self.assertTrue(validator.check_resources_managed())
Exemplo n.º 12
0
 def test_check_nodes_configured(self):
     status = ClusterStatusPcs(executor=run_cmd_groups)
     node_list = ["localhrost", "localfrost"]
     layout = ClusterLayoutJson.from_json_file([], node_list)
     validator = ClusterTestAdapter(status, layout)
     self.assertTrue(validator.check_nodes_configured())
Exemplo n.º 13
0
    def validate_cluster(node_list: list,
                         comp_files_dir: str = COMPONENTS_CONFIG_DIR,
                         executor: Callable[[str], tuple] = None) -> bool:
        """
        Perform cluster sanity-checks.

        A wrapper for many check functions to be called at once.

        Params:
            node_list: expected list of nodes in the cluster.
            comp_files_dir: directory where component json files are located.
            executor: Callable to invoke "pcs status xml". Used for tests.

        Returns:
            bool: result of sanity checks.

        Raises:
            FileNotFoundError: no component files found.
            ValidationStatusError: issues with ClusterStatus class.
            ValidationConfigError: issues with ClusterLayout init.
        """
        res = True

        status = ClusterStatusPcs(executor=executor)
        file_list = TestExecutor._get_component_json_files(comp_files_dir)
        if not file_list:
            raise FileNotFoundError(
                f"Component files were not found in {comp_files_dir}")
        layout = ClusterLayoutJson.from_json_file(file_list, node_list)
        validator = ClusterTestAdapter(status, layout)

        sub_res = validator.check_resource_layout()
        res &= sub_res
        if not sub_res:
            Log.info(
                "Cluster resource layout does't correspond to component files config."
            )

        sub_res = validator.check_quorum_state()
        res &= sub_res
        if not sub_res:
            Log.info("Cluster doesn't have quorum. This is a showstopper!")

        # NOTE: Change if this assumption is incorrect or even remove this!
        sub_res = validator.check_stonith_state(expected_state=False)
        res &= sub_res
        if not sub_res:
            Log.info(
                "Stonith is not disabled for some reason. Check expected configuration."
            )

        sub_res = validator.check_maintenance_mode(expected_state=False)
        res &= sub_res
        if not sub_res:
            Log.info(
                "Cluster maintenance mode is on. Cluster check expected configuration."
            )

        sub_res = validator.check_nodes_online(nodelist=node_list)
        res &= sub_res
        if not sub_res:
            Log.info("Some nodes are offline. Check HA logs for details.")

        sub_res = validator.check_nodes_standby()
        res &= sub_res
        if not sub_res:
            Log.info("Some nodes are in standby. Check HA logs for details.")

        sub_res = validator.check_nodes_maintenance()
        res &= sub_res
        if not sub_res:
            Log.info(
                "Some nodes are in maintenance mode. Cluster doesn't function normally."
            )

        sub_res = validator.check_nodes_unclean()
        res &= sub_res
        if not sub_res:
            Log.info(
                "Some nodes are in unclean state. Cluster doesn't function normally."
            )

        sub_res = validator.check_resources_failed()
        res &= sub_res
        if not sub_res:
            Log.info(
                "Some resources are failed. Cluster doesn't function normally."
            )

        sub_res = validator.check_resources_role(expected_role="Started")
        res &= sub_res
        if not sub_res:
            Log.info(
                "Some resources are not started. Cluster doesn't function normally."
            )

        return res