Skip to content

Commit

Permalink
fix support for new role names
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjelinek committed Aug 18, 2021
1 parent 2b943c5 commit 90c0922
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 40 deletions.
22 changes: 13 additions & 9 deletions pcs/common/pacemaker/role.py
Expand Up @@ -5,13 +5,17 @@ def get_value_for_cib(
role: const.PcmkRoleType, is_latest_supported: bool
) -> const.PcmkRoleType:
if is_latest_supported:
if role in const.PCMK_ROLES_PROMOTED:
return const.PCMK_ROLE_PROMOTED_PRIMARY
if role in const.PCMK_ROLES_UNPROMOTED:
return const.PCMK_ROLE_UNPROMOTED_PRIMARY
else:
if role in const.PCMK_ROLES_PROMOTED:
return const.PCMK_ROLE_PROMOTED_LEGACY
if role in const.PCMK_ROLES_UNPROMOTED:
return const.PCMK_ROLE_UNPROMOTED_LEGACY
return get_value_primary(role)
if role in const.PCMK_ROLES_PROMOTED:
return const.PCMK_ROLE_PROMOTED_LEGACY
if role in const.PCMK_ROLES_UNPROMOTED:
return const.PCMK_ROLE_UNPROMOTED_LEGACY
return role


def get_value_primary(role: const.PcmkRoleType) -> const.PcmkRoleType:
if role in const.PCMK_ROLES_PROMOTED:
return const.PCMK_ROLE_PROMOTED_PRIMARY
if role in const.PCMK_ROLES_UNPROMOTED:
return const.PCMK_ROLE_UNPROMOTED_PRIMARY
return role
8 changes: 6 additions & 2 deletions pcs/lib/resource_agent.py
Expand Up @@ -17,8 +17,8 @@
from lxml.etree import _Element

from pcs import settings
from pcs.common import const, pacemaker, reports
from pcs.common.interface.dto import DataTransferObject, meta
from pcs.common import reports
from pcs.common.reports.types import SeverityLevel
from pcs.common.str_tools import format_list
from pcs.common.tools import xml_fromstring
Expand Down Expand Up @@ -535,7 +535,11 @@ def _get_raw_actions(self) -> List[AgentActionDto]:
str(action.attrib["name"]),
action.get("timeout"),
action.get("interval"),
action.get("role"),
pacemaker.role.get_value_primary(
const.PcmkRoleType(str(action.attrib["role"]))
)
if action.get("role", None) is not None
else action.get("role"),
action.get("start-delay"),
action.get("depth"),
action.get("automatic"),
Expand Down
4 changes: 2 additions & 2 deletions pcs/utils.py
Expand Up @@ -1565,8 +1565,8 @@ def resource_running_on(resource, passed_state=None, stopped=False):
message_parts = []
for alist, label in (
(nodes_started, "running"),
(nodes_promoted, "master"),
(nodes_unpromoted, "slave"),
(nodes_promoted, str(const.PCMK_ROLE_PROMOTED_PRIMARY).lower()),
(nodes_unpromoted, str(const.PCMK_ROLE_UNPROMOTED_PRIMARY).lower()),
):
if alist:
alist.sort()
Expand Down
2 changes: 1 addition & 1 deletion pcs_test/resources/cib-empty-3.7.xml
@@ -1,4 +1,4 @@
<cib epoch="557" num_updates="122" admin_epoch="0" validate-with="pacemaker-3.7" crm_feature_set="3.7.0" update-origin="rh7-3" update-client="crmd" cib-last-written="Thu Aug 23 16:49:17 2012" have-quorum="0" dc-uuid="2">
<cib epoch="557" num_updates="122" admin_epoch="0" validate-with="pacemaker-3.7" crm_feature_set="3.10.0" update-origin="rh7-3" update-client="crmd" cib-last-written="Thu Aug 23 16:49:17 2012" have-quorum="0" dc-uuid="2">
<configuration>
<crm_config/>
<nodes>
Expand Down
46 changes: 23 additions & 23 deletions pcs_test/tier0/lib/commands/resource/test_resource_create.py
Expand Up @@ -370,13 +370,13 @@ def fixture_state_resources_xml(
)


class CreateRolesNormilization(TestCase):
class CreateRolesNormalization(TestCase):
def setUp(self):
self.env_assist, self.config = get_env_tools(test_case=self)

def prepare(self, ocf_1_1=True, cib_support=True):
def prepare(self, ocf_1_0=True, cib_support=True):
agent_file_name = None
if ocf_1_1:
if ocf_1_0:
agent_file_name = (
"resource_agent_ocf_pacemaker_stateful_ocf_1.0.xml"
)
Expand All @@ -400,10 +400,12 @@ def create(self, operation_list=None):
)

def test_roles_normalization_user_defined(self):
self.prepare(False, False)
self.prepare(True, False)
self.config.env.push_cib(
resources=fixture_cib_resources_xml(
fixture_cib_primitive_stateful(use_legacy_roles=True)
fixture_cib_primitive_stateful(
use_legacy_roles=True, include_reload=False
)
)
)
self.create(
Expand All @@ -414,10 +416,12 @@ def test_roles_normalization_user_defined(self):
)

def test_roles_normalization_user_defined_new_roles(self):
self.prepare(False, False)
self.prepare(True, False)
self.config.env.push_cib(
resources=fixture_cib_resources_xml(
fixture_cib_primitive_stateful(use_legacy_roles=True)
fixture_cib_primitive_stateful(
use_legacy_roles=True, include_reload=False
)
)
)
self.create(
Expand All @@ -428,10 +432,10 @@ def test_roles_normalization_user_defined_new_roles(self):
)

def test_roles_normalization_user_defined_with_cib_support(self):
self.prepare(False, True)
self.prepare(True, True)
self.config.env.push_cib(
resources=fixture_cib_resources_xml(
fixture_cib_primitive_stateful()
fixture_cib_primitive_stateful(include_reload=False)
)
)
self.create(
Expand All @@ -442,10 +446,10 @@ def test_roles_normalization_user_defined_with_cib_support(self):
)

def test_roles_normalization_user_defined_new_roles_with_cib_support(self):
self.prepare(False, True)
self.prepare(True, True)
self.config.env.push_cib(
resources=fixture_cib_resources_xml(
fixture_cib_primitive_stateful()
fixture_cib_primitive_stateful(include_reload=False)
)
)
self.create(
Expand All @@ -456,12 +460,10 @@ def test_roles_normalization_user_defined_new_roles_with_cib_support(self):
)

def test_roles_normalization_agent(self):
self.prepare(True, False)
self.prepare(False, False)
self.config.env.push_cib(
resources=fixture_cib_resources_xml(
fixture_cib_primitive_stateful(
use_legacy_roles=True, include_reload=False
)
fixture_cib_primitive_stateful(use_legacy_roles=True)
)
)
self.create(
Expand All @@ -472,12 +474,10 @@ def test_roles_normalization_agent(self):
)

def test_roles_normalization_agent_new_roles(self):
self.prepare(True, False)
self.prepare(False, False)
self.config.env.push_cib(
resources=fixture_cib_resources_xml(
fixture_cib_primitive_stateful(
use_legacy_roles=True, include_reload=False
)
fixture_cib_primitive_stateful(use_legacy_roles=True)
)
)
self.create(
Expand All @@ -488,10 +488,10 @@ def test_roles_normalization_agent_new_roles(self):
)

def test_roles_normalization_agent_with_cib_support(self):
self.prepare(True, True)
self.prepare(False, True)
self.config.env.push_cib(
resources=fixture_cib_resources_xml(
fixture_cib_primitive_stateful(include_reload=False)
fixture_cib_primitive_stateful()
)
)
self.create(
Expand All @@ -502,10 +502,10 @@ def test_roles_normalization_agent_with_cib_support(self):
)

def test_roles_normalization_agent_new_roles_with_cib_support(self):
self.prepare(True, True)
self.prepare(False, True)
self.config.env.push_cib(
resources=fixture_cib_resources_xml(
fixture_cib_primitive_stateful(include_reload=False)
fixture_cib_primitive_stateful()
)
)
self.create(
Expand Down

0 comments on commit 90c0922

Please sign in to comment.