|
|
be1b1f |
From b52c3ed9ec342b021357b915eaf6581f9f6a57d2 Mon Sep 17 00:00:00 2001
|
|
|
8d6168 |
From: Ondrej Mular <omular@redhat.com>
|
|
|
8d6168 |
Date: Fri, 31 Aug 2018 10:12:18 +0200
|
|
|
8d6168 |
Subject: [PATCH] fix allowed instance attrs for some fence agents
|
|
|
8d6168 |
|
|
|
8d6168 |
Fix is effective only for agents `fence_compute` and `fence_evacuate`
|
|
|
8d6168 |
---
|
|
|
8d6168 |
pcs/lib/resource_agent.py | 22 ++++++++++++-
|
|
|
8d6168 |
pcs/lib/test/test_resource_agent.py | 50 +++++++++++++++++++++++++++++
|
|
|
8d6168 |
pcs/test/test_stonith.py | 63 +++++++++++++++++++++++++++++++++++++
|
|
|
8d6168 |
3 files changed, 134 insertions(+), 1 deletion(-)
|
|
|
8d6168 |
|
|
|
8d6168 |
diff --git a/pcs/lib/resource_agent.py b/pcs/lib/resource_agent.py
|
|
|
be1b1f |
index 34b18b9b..447cf1fe 100644
|
|
|
8d6168 |
--- a/pcs/lib/resource_agent.py
|
|
|
8d6168 |
+++ b/pcs/lib/resource_agent.py
|
|
|
8d6168 |
@@ -469,6 +469,14 @@ class Agent(object):
|
|
|
8d6168 |
"obsoletes": parameter_element.get("obsoletes", None),
|
|
|
8d6168 |
})
|
|
|
8d6168 |
|
|
|
8d6168 |
+ def _get_always_allowed_parameters(self):
|
|
|
8d6168 |
+ """
|
|
|
8d6168 |
+ This method should be overriden in descendants.
|
|
|
8d6168 |
+
|
|
|
8d6168 |
+ Returns set of always allowed parameters of a agent.
|
|
|
8d6168 |
+ """
|
|
|
8d6168 |
+ return set()
|
|
|
8d6168 |
+
|
|
|
8d6168 |
def validate_parameters(
|
|
|
8d6168 |
self, parameters,
|
|
|
8d6168 |
parameters_type="resource",
|
|
|
8d6168 |
@@ -518,13 +526,17 @@ class Agent(object):
|
|
|
8d6168 |
agent_params = self.get_parameters()
|
|
|
8d6168 |
|
|
|
8d6168 |
required_missing = []
|
|
|
8d6168 |
+ always_allowed = self._get_always_allowed_parameters()
|
|
|
8d6168 |
for attr in agent_params:
|
|
|
8d6168 |
if attr["required"] and attr["name"] not in parameters_values:
|
|
|
8d6168 |
required_missing.append(attr["name"])
|
|
|
8d6168 |
|
|
|
8d6168 |
valid_attrs = [attr["name"] for attr in agent_params]
|
|
|
8d6168 |
return (
|
|
|
8d6168 |
- [attr for attr in parameters_values if attr not in valid_attrs],
|
|
|
8d6168 |
+ [
|
|
|
8d6168 |
+ attr for attr in parameters_values
|
|
|
8d6168 |
+ if attr not in valid_attrs and attr not in always_allowed
|
|
|
8d6168 |
+ ],
|
|
|
8d6168 |
required_missing
|
|
|
8d6168 |
)
|
|
|
8d6168 |
|
|
|
8d6168 |
@@ -858,6 +870,14 @@ class StonithAgent(CrmAgent):
|
|
|
8d6168 |
self._get_stonithd_metadata().get_parameters()
|
|
|
8d6168 |
)
|
|
|
8d6168 |
|
|
|
8d6168 |
+ def _get_always_allowed_parameters(self):
|
|
|
8d6168 |
+ if self.get_name() in ("fence_compute", "fence_evacuate"):
|
|
|
8d6168 |
+ return set([
|
|
|
8d6168 |
+ "project-domain", "project_domain", "user-domain",
|
|
|
8d6168 |
+ "user_domain", "compute-domain", "compute_domain",
|
|
|
8d6168 |
+ ])
|
|
|
8d6168 |
+ return set()
|
|
|
8d6168 |
+
|
|
|
8d6168 |
def validate_parameters(
|
|
|
8d6168 |
self, parameters,
|
|
|
8d6168 |
parameters_type="stonith",
|
|
|
8d6168 |
diff --git a/pcs/lib/test/test_resource_agent.py b/pcs/lib/test/test_resource_agent.py
|
|
|
be1b1f |
index 4ec94e26..2396bf30 100644
|
|
|
8d6168 |
--- a/pcs/lib/test/test_resource_agent.py
|
|
|
8d6168 |
+++ b/pcs/lib/test/test_resource_agent.py
|
|
|
8d6168 |
@@ -1275,6 +1275,23 @@ class AgentMetadataValidateParametersValuesTest(TestCase):
|
|
|
8d6168 |
(["obsoletes"], ["deprecated"])
|
|
|
8d6168 |
)
|
|
|
8d6168 |
|
|
|
8d6168 |
+ @patch_agent_object(
|
|
|
8d6168 |
+ "_get_always_allowed_parameters",
|
|
|
8d6168 |
+ lambda self: set(["always_allowed", "another-one", "last_one"])
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ def test_always_allowed(self, mock_metadata):
|
|
|
8d6168 |
+ mock_metadata.return_value = self.metadata
|
|
|
8d6168 |
+ self.assertEqual(
|
|
|
8d6168 |
+ self.agent.validate_parameters_values({
|
|
|
8d6168 |
+ "another_required_param": "value1",
|
|
|
8d6168 |
+ "required_param": "value2",
|
|
|
8d6168 |
+ "test_param": "value3",
|
|
|
8d6168 |
+ "always_allowed": "value4",
|
|
|
8d6168 |
+ "another-one": "value5",
|
|
|
8d6168 |
+ }),
|
|
|
8d6168 |
+ ([], [])
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+
|
|
|
8d6168 |
|
|
|
8d6168 |
class AgentMetadataValidateParameters(TestCase):
|
|
|
8d6168 |
def setUp(self):
|
|
|
8d6168 |
@@ -2175,3 +2192,36 @@ class AbsentResourceAgentTest(TestCase):
|
|
|
8d6168 |
self.assertEqual(([], []), absent.validate_parameters_values({
|
|
|
8d6168 |
"whatever": "anything"
|
|
|
8d6168 |
}))
|
|
|
8d6168 |
+
|
|
|
8d6168 |
+
|
|
|
8d6168 |
+class StonithAgentAlwaysAllowedParametersTest(TestCase):
|
|
|
8d6168 |
+ def setUp(self):
|
|
|
8d6168 |
+ self.runner = mock.MagicMock(spec_set=CommandRunner)
|
|
|
8d6168 |
+ self.always_allowed = set([
|
|
|
8d6168 |
+ "project-domain", "project_domain", "user-domain", "user_domain",
|
|
|
8d6168 |
+ "compute-domain", "compute_domain",
|
|
|
8d6168 |
+ ])
|
|
|
8d6168 |
+
|
|
|
8d6168 |
+ def test_fence_compute(self):
|
|
|
8d6168 |
+ self.assertEquals(
|
|
|
8d6168 |
+ self.always_allowed,
|
|
|
8d6168 |
+ lib_ra.StonithAgent(
|
|
|
8d6168 |
+ self.runner, "fence_compute"
|
|
|
8d6168 |
+ )._get_always_allowed_parameters()
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+
|
|
|
8d6168 |
+ def test_fence_evacuate(self):
|
|
|
8d6168 |
+ self.assertEquals(
|
|
|
8d6168 |
+ self.always_allowed,
|
|
|
8d6168 |
+ lib_ra.StonithAgent(
|
|
|
8d6168 |
+ self.runner, "fence_evacuate"
|
|
|
8d6168 |
+ )._get_always_allowed_parameters()
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+
|
|
|
8d6168 |
+ def test_some_other_agent(self):
|
|
|
8d6168 |
+ self.assertEquals(
|
|
|
8d6168 |
+ set(),
|
|
|
8d6168 |
+ lib_ra.StonithAgent(
|
|
|
8d6168 |
+ self.runner, "fence_dummy"
|
|
|
8d6168 |
+ )._get_always_allowed_parameters()
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
diff --git a/pcs/test/test_stonith.py b/pcs/test/test_stonith.py
|
|
|
be1b1f |
index cdb2ecee..ff981acc 100644
|
|
|
8d6168 |
--- a/pcs/test/test_stonith.py
|
|
|
8d6168 |
+++ b/pcs/test/test_stonith.py
|
|
|
8d6168 |
@@ -469,6 +469,69 @@ class StonithTest(TestCase, AssertPcsMixin):
|
|
|
8d6168 |
)
|
|
|
8d6168 |
)
|
|
|
8d6168 |
|
|
|
8d6168 |
+ def test_stonith_compute_evacuate_always_allowed_parameters(self):
|
|
|
8d6168 |
+ self.assert_pcs_success(
|
|
|
8d6168 |
+ "stonith create test1 fence_compute auth_url=test1 project_domain=val1 project-domain=val2 user_domain=val3 user-domain=val4 compute_domain=val5 compute-domain=val6",
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ self.assert_pcs_success(
|
|
|
8d6168 |
+ "stonith show --full",
|
|
|
8d6168 |
+ outdent(
|
|
|
8d6168 |
+ """\
|
|
|
8d6168 |
+ Resource: test1 (class=stonith type=fence_compute)
|
|
|
8d6168 |
+ Attributes: auth_url=test1 compute-domain=val6 compute_domain=val5 project-domain=val2 project_domain=val1 user-domain=val4 user_domain=val3
|
|
|
8d6168 |
+ Operations: monitor interval=60s (test1-monitor-interval-60s)
|
|
|
8d6168 |
+ """
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ self.assert_pcs_success(
|
|
|
8d6168 |
+ "stonith create test2 fence_evacuate auth_url=test2 project_domain=val0 project-domain=val1 user_domain=val2 user-domain=val3 compute_domain=val4 compute-domain=val5",
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ self.assert_pcs_success(
|
|
|
8d6168 |
+ "stonith show --full",
|
|
|
8d6168 |
+ outdent(
|
|
|
8d6168 |
+ """\
|
|
|
8d6168 |
+ Resource: test1 (class=stonith type=fence_compute)
|
|
|
8d6168 |
+ Attributes: auth_url=test1 compute-domain=val6 compute_domain=val5 project-domain=val2 project_domain=val1 user-domain=val4 user_domain=val3
|
|
|
8d6168 |
+ Operations: monitor interval=60s (test1-monitor-interval-60s)
|
|
|
8d6168 |
+ Resource: test2 (class=stonith type=fence_evacuate)
|
|
|
8d6168 |
+ Attributes: auth_url=test2 compute-domain=val5 compute_domain=val4 project-domain=val1 project_domain=val0 user-domain=val3 user_domain=val2
|
|
|
8d6168 |
+ Operations: monitor interval=60s (test2-monitor-interval-60s)
|
|
|
8d6168 |
+ """
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ self.assert_pcs_success(
|
|
|
8d6168 |
+ "stonith update test1 auth_url=new0 project_domain=new1 project-domain=new2 user_domain=new3 user-domain=new4 compute_domain=new5 compute-domain=new6",
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ self.assert_pcs_success(
|
|
|
8d6168 |
+ "stonith show --full",
|
|
|
8d6168 |
+ outdent(
|
|
|
8d6168 |
+ """\
|
|
|
8d6168 |
+ Resource: test1 (class=stonith type=fence_compute)
|
|
|
8d6168 |
+ Attributes: auth_url=new0 compute-domain=new6 compute_domain=new5 project-domain=new2 project_domain=new1 user-domain=new4 user_domain=new3
|
|
|
8d6168 |
+ Operations: monitor interval=60s (test1-monitor-interval-60s)
|
|
|
8d6168 |
+ Resource: test2 (class=stonith type=fence_evacuate)
|
|
|
8d6168 |
+ Attributes: auth_url=test2 compute-domain=val5 compute_domain=val4 project-domain=val1 project_domain=val0 user-domain=val3 user_domain=val2
|
|
|
8d6168 |
+ Operations: monitor interval=60s (test2-monitor-interval-60s)
|
|
|
8d6168 |
+ """
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ self.assert_pcs_success(
|
|
|
8d6168 |
+ "stonith update test2 auth_url=new1 project_domain=new2 project-domain=new3 user_domain=new4 user-domain=new5 compute_domain=new6 compute-domain=new7",
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ self.assert_pcs_success(
|
|
|
8d6168 |
+ "stonith show --full",
|
|
|
8d6168 |
+ outdent(
|
|
|
8d6168 |
+ """\
|
|
|
8d6168 |
+ Resource: test1 (class=stonith type=fence_compute)
|
|
|
8d6168 |
+ Attributes: auth_url=new0 compute-domain=new6 compute_domain=new5 project-domain=new2 project_domain=new1 user-domain=new4 user_domain=new3
|
|
|
8d6168 |
+ Operations: monitor interval=60s (test1-monitor-interval-60s)
|
|
|
8d6168 |
+ Resource: test2 (class=stonith type=fence_evacuate)
|
|
|
8d6168 |
+ Attributes: auth_url=new1 compute-domain=new7 compute_domain=new6 project-domain=new3 project_domain=new2 user-domain=new5 user_domain=new4
|
|
|
8d6168 |
+ Operations: monitor interval=60s (test2-monitor-interval-60s)
|
|
|
8d6168 |
+ """
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+ )
|
|
|
8d6168 |
+
|
|
|
8d6168 |
def testStonithFenceConfirm(self):
|
|
|
8d6168 |
output, returnVal = pcs(temp_cib, "stonith fence blah blah")
|
|
|
8d6168 |
assert returnVal == 1
|
|
|
8d6168 |
--
|
|
|
8d6168 |
2.13.6
|
|
|
8d6168 |
|