|
|
b75106 |
From 4effb249590c6da5eeb13d9106f36e210e6fe5c2 Mon Sep 17 00:00:00 2001
|
|
|
b75106 |
From: Ondrej Mular <omular@redhat.com>
|
|
|
b75106 |
Date: Mon, 10 Jan 2022 16:04:54 +0100
|
|
|
b75106 |
Subject: [PATCH 3/4] Multiple fixes in `pcs resource move` command
|
|
|
b75106 |
|
|
|
b75106 |
---
|
|
|
b75106 |
pcs/common/reports/codes.py | 1 +
|
|
|
b75106 |
pcs/common/reports/messages.py | 21 ++
|
|
|
b75106 |
pcs/lib/cib/node.py | 14 +-
|
|
|
b75106 |
pcs/lib/commands/resource.py | 105 ++++++-
|
|
|
b75106 |
pcs/lib/node.py | 7 +-
|
|
|
b75106 |
pcs/resource.py | 7 +
|
|
|
b75106 |
.../tier0/common/reports/test_messages.py | 12 +
|
|
|
b75106 |
.../resource/test_resource_move_autoclean.py | 280 +++++++++++++++++-
|
|
|
b75106 |
.../resource/test_resource_move_ban.py | 45 ++-
|
|
|
b75106 |
.../tools/command_env/config_runner_pcmk.py | 2 +
|
|
|
b75106 |
pcs_test/tools/command_env/mock_runner.py | 2 +-
|
|
|
b75106 |
pcs_test/tools/fixture_cib.py | 1 +
|
|
|
b75106 |
12 files changed, 463 insertions(+), 34 deletions(-)
|
|
|
b75106 |
|
|
|
b75106 |
diff --git a/pcs/common/reports/codes.py b/pcs/common/reports/codes.py
|
|
|
b75106 |
index 8ed83d84..8887fd6d 100644
|
|
|
b75106 |
--- a/pcs/common/reports/codes.py
|
|
|
b75106 |
+++ b/pcs/common/reports/codes.py
|
|
|
b75106 |
@@ -421,6 +421,7 @@ RESOURCE_UNMOVE_UNBAN_PCMK_EXPIRED_NOT_SUPPORTED = M(
|
|
|
b75106 |
)
|
|
|
b75106 |
RESOURCE_MOVE_CONSTRAINT_CREATED = M("RESOURCE_MOVE_CONSTRAINT_CREATED")
|
|
|
b75106 |
RESOURCE_MOVE_CONSTRAINT_REMOVED = M("RESOURCE_MOVE_CONSTRAINT_REMOVED")
|
|
|
b75106 |
+RESOURCE_MOVE_NOT_AFFECTING_RESOURCE = M("RESOURCE_MOVE_NOT_AFFECTING_RESOURCE")
|
|
|
b75106 |
RESOURCE_MOVE_AFFECTS_OTRHER_RESOURCES = M(
|
|
|
b75106 |
"RESOURCE_MOVE_AFFECTS_OTRHER_RESOURCES"
|
|
|
b75106 |
)
|
|
|
b75106 |
diff --git a/pcs/common/reports/messages.py b/pcs/common/reports/messages.py
|
|
|
b75106 |
index 16171fd0..37c79ba1 100644
|
|
|
b75106 |
--- a/pcs/common/reports/messages.py
|
|
|
b75106 |
+++ b/pcs/common/reports/messages.py
|
|
|
b75106 |
@@ -6140,6 +6140,27 @@ class ResourceMoveConstraintRemoved(ReportItemMessage):
|
|
|
b75106 |
)
|
|
|
b75106 |
|
|
|
b75106 |
|
|
|
b75106 |
+@dataclass(frozen=True)
|
|
|
b75106 |
+class ResourceMoveNotAffectingResource(ReportItemMessage):
|
|
|
b75106 |
+ """
|
|
|
b75106 |
+ Creating a location constraint to move a resource has no effect on the
|
|
|
b75106 |
+ resource.
|
|
|
b75106 |
+
|
|
|
b75106 |
+ resource_id -- id of the resource to be moved
|
|
|
b75106 |
+ """
|
|
|
b75106 |
+
|
|
|
b75106 |
+ resource_id: str
|
|
|
b75106 |
+ _code = codes.RESOURCE_MOVE_NOT_AFFECTING_RESOURCE
|
|
|
b75106 |
+
|
|
|
b75106 |
+ @property
|
|
|
b75106 |
+ def message(self) -> str:
|
|
|
b75106 |
+ return (
|
|
|
b75106 |
+ f"Unable to move resource '{self.resource_id}' using a location "
|
|
|
b75106 |
+ "constraint. Current location of the resource may be affected by "
|
|
|
b75106 |
+ "some other constraint."
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
@dataclass(frozen=True)
|
|
|
b75106 |
class ResourceMoveAffectsOtherResources(ReportItemMessage):
|
|
|
b75106 |
"""
|
|
|
b75106 |
diff --git a/pcs/lib/cib/node.py b/pcs/lib/cib/node.py
|
|
|
b75106 |
index 20a41ca0..df2ffbaa 100644
|
|
|
b75106 |
--- a/pcs/lib/cib/node.py
|
|
|
b75106 |
+++ b/pcs/lib/cib/node.py
|
|
|
b75106 |
@@ -1,12 +1,17 @@
|
|
|
b75106 |
from collections import namedtuple
|
|
|
b75106 |
+from typing import Set
|
|
|
b75106 |
from lxml import etree
|
|
|
b75106 |
+from lxml.etree import _Element
|
|
|
b75106 |
|
|
|
b75106 |
from pcs.common import reports
|
|
|
b75106 |
from pcs.common.reports.item import ReportItem
|
|
|
b75106 |
from pcs.lib.cib.nvpair import update_nvset
|
|
|
b75106 |
from pcs.lib.cib.tools import get_nodes
|
|
|
b75106 |
from pcs.lib.errors import LibraryError
|
|
|
b75106 |
-from pcs.lib.xml_tools import append_when_useful
|
|
|
b75106 |
+from pcs.lib.xml_tools import (
|
|
|
b75106 |
+ append_when_useful,
|
|
|
b75106 |
+ get_root,
|
|
|
b75106 |
+)
|
|
|
b75106 |
|
|
|
b75106 |
|
|
|
b75106 |
class PacemakerNode(namedtuple("PacemakerNode", "name addr")):
|
|
|
b75106 |
@@ -58,6 +63,13 @@ def update_node_instance_attrs(
|
|
|
b75106 |
append_when_useful(cib_nodes, node_el)
|
|
|
b75106 |
|
|
|
b75106 |
|
|
|
b75106 |
+def get_node_names(cib: _Element) -> Set[str]:
|
|
|
b75106 |
+ return {
|
|
|
b75106 |
+ str(node.attrib["uname"])
|
|
|
b75106 |
+ for node in get_nodes(get_root(cib)).iterfind("./node")
|
|
|
b75106 |
+ }
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
def _ensure_node_exists(tree, node_name, state_nodes=None):
|
|
|
b75106 |
"""
|
|
|
b75106 |
Make sure node with specified name exists
|
|
|
b75106 |
diff --git a/pcs/lib/commands/resource.py b/pcs/lib/commands/resource.py
|
|
|
b75106 |
index d0e8f4db..82ce73e0 100644
|
|
|
b75106 |
--- a/pcs/lib/commands/resource.py
|
|
|
b75106 |
+++ b/pcs/lib/commands/resource.py
|
|
|
b75106 |
@@ -50,12 +50,16 @@ from pcs.lib.cib.tools import (
|
|
|
b75106 |
from pcs.lib.env import LibraryEnvironment, WaitType
|
|
|
b75106 |
from pcs.lib.errors import LibraryError
|
|
|
b75106 |
from pcs.lib.external import CommandRunner
|
|
|
b75106 |
-from pcs.lib.node import get_existing_nodes_names_addrs
|
|
|
b75106 |
+from pcs.lib.node import (
|
|
|
b75106 |
+ get_existing_nodes_names_addrs,
|
|
|
b75106 |
+ get_pacemaker_node_names,
|
|
|
b75106 |
+)
|
|
|
b75106 |
from pcs.lib.pacemaker import simulate as simulate_tools
|
|
|
b75106 |
from pcs.lib.pacemaker.live import (
|
|
|
b75106 |
diff_cibs_xml,
|
|
|
b75106 |
get_cib,
|
|
|
b75106 |
get_cib_xml,
|
|
|
b75106 |
+ get_cluster_status_dom,
|
|
|
b75106 |
has_resource_unmove_unban_expired_support,
|
|
|
b75106 |
push_cib_diff_xml,
|
|
|
b75106 |
resource_ban,
|
|
|
b75106 |
@@ -1589,6 +1593,16 @@ def move(
|
|
|
b75106 |
)
|
|
|
b75106 |
|
|
|
b75106 |
|
|
|
b75106 |
+def _nodes_exist_reports(
|
|
|
b75106 |
+ cib: _Element, node_names: Iterable[str]
|
|
|
b75106 |
+) -> ReportItemList:
|
|
|
b75106 |
+ existing_node_names = get_pacemaker_node_names(cib)
|
|
|
b75106 |
+ return [
|
|
|
b75106 |
+ reports.ReportItem.error(reports.messages.NodeNotFound(node_name))
|
|
|
b75106 |
+ for node_name in (set(node_names) - existing_node_names)
|
|
|
b75106 |
+ ]
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
def move_autoclean(
|
|
|
b75106 |
env: LibraryEnvironment,
|
|
|
b75106 |
resource_id: str,
|
|
|
b75106 |
@@ -1626,6 +1640,9 @@ def move_autoclean(
|
|
|
b75106 |
if resource_el is not None:
|
|
|
b75106 |
report_list.extend(resource.common.validate_move(resource_el, master))
|
|
|
b75106 |
|
|
|
b75106 |
+ if node:
|
|
|
b75106 |
+ report_list.extend(_nodes_exist_reports(cib, [node]))
|
|
|
b75106 |
+
|
|
|
b75106 |
if env.report_processor.report_list(report_list).has_errors:
|
|
|
b75106 |
raise LibraryError()
|
|
|
b75106 |
|
|
|
b75106 |
@@ -1659,8 +1676,32 @@ def move_autoclean(
|
|
|
b75106 |
add_constraint_cib_diff = diff_cibs_xml(
|
|
|
b75106 |
env.cmd_runner(), env.report_processor, cib_xml, rsc_moved_cib_xml
|
|
|
b75106 |
)
|
|
|
b75106 |
+ with get_tmp_cib(
|
|
|
b75106 |
+ env.report_processor, rsc_moved_cib_xml
|
|
|
b75106 |
+ ) as rsc_moved_constraint_cleared_cib_file:
|
|
|
b75106 |
+ stdout, stderr, retval = resource_unmove_unban(
|
|
|
b75106 |
+ env.cmd_runner(
|
|
|
b75106 |
+ dict(CIB_file=rsc_moved_constraint_cleared_cib_file.name)
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ resource_id,
|
|
|
b75106 |
+ node,
|
|
|
b75106 |
+ master,
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ if retval != 0:
|
|
|
b75106 |
+ raise LibraryError(
|
|
|
b75106 |
+ ReportItem.error(
|
|
|
b75106 |
+ reports.messages.ResourceUnmoveUnbanPcmkError(
|
|
|
b75106 |
+ resource_id, stdout, stderr
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ rsc_moved_constraint_cleared_cib_file.seek(0)
|
|
|
b75106 |
+ constraint_removed_cib = rsc_moved_constraint_cleared_cib_file.read()
|
|
|
b75106 |
remove_constraint_cib_diff = diff_cibs_xml(
|
|
|
b75106 |
- env.cmd_runner(), env.report_processor, rsc_moved_cib_xml, cib_xml
|
|
|
b75106 |
+ env.cmd_runner(),
|
|
|
b75106 |
+ env.report_processor,
|
|
|
b75106 |
+ rsc_moved_cib_xml,
|
|
|
b75106 |
+ constraint_removed_cib,
|
|
|
b75106 |
)
|
|
|
b75106 |
|
|
|
b75106 |
if not (add_constraint_cib_diff and remove_constraint_cib_diff):
|
|
|
b75106 |
@@ -1689,13 +1730,15 @@ def move_autoclean(
|
|
|
b75106 |
)
|
|
|
b75106 |
)
|
|
|
b75106 |
)
|
|
|
b75106 |
- _ensure_resource_is_not_moved(
|
|
|
b75106 |
+ _ensure_resource_moved_and_not_moved_back(
|
|
|
b75106 |
env.cmd_runner,
|
|
|
b75106 |
env.report_processor,
|
|
|
b75106 |
etree_to_str(after_move_simulated_cib),
|
|
|
b75106 |
remove_constraint_cib_diff,
|
|
|
b75106 |
resource_id,
|
|
|
b75106 |
strict,
|
|
|
b75106 |
+ resource_state_before,
|
|
|
b75106 |
+ node,
|
|
|
b75106 |
)
|
|
|
b75106 |
push_cib_diff_xml(env.cmd_runner(), add_constraint_cib_diff)
|
|
|
b75106 |
env.report_processor.report(
|
|
|
b75106 |
@@ -1704,13 +1747,15 @@ def move_autoclean(
|
|
|
b75106 |
)
|
|
|
b75106 |
)
|
|
|
b75106 |
env.wait_for_idle(wait_timeout)
|
|
|
b75106 |
- _ensure_resource_is_not_moved(
|
|
|
b75106 |
+ _ensure_resource_moved_and_not_moved_back(
|
|
|
b75106 |
env.cmd_runner,
|
|
|
b75106 |
env.report_processor,
|
|
|
b75106 |
get_cib_xml(env.cmd_runner()),
|
|
|
b75106 |
remove_constraint_cib_diff,
|
|
|
b75106 |
resource_id,
|
|
|
b75106 |
strict,
|
|
|
b75106 |
+ resource_state_before,
|
|
|
b75106 |
+ node,
|
|
|
b75106 |
)
|
|
|
b75106 |
push_cib_diff_xml(env.cmd_runner(), remove_constraint_cib_diff)
|
|
|
b75106 |
env.report_processor.report(
|
|
|
b75106 |
@@ -1730,16 +1775,35 @@ def move_autoclean(
|
|
|
b75106 |
raise LibraryError()
|
|
|
b75106 |
|
|
|
b75106 |
|
|
|
b75106 |
-def _ensure_resource_is_not_moved(
|
|
|
b75106 |
+def _ensure_resource_moved_and_not_moved_back(
|
|
|
b75106 |
runner_factory: Callable[[Optional[Mapping[str, str]]], CommandRunner],
|
|
|
b75106 |
report_processor: reports.ReportProcessor,
|
|
|
b75106 |
cib_xml: str,
|
|
|
b75106 |
remove_constraint_cib_diff: str,
|
|
|
b75106 |
resource_id: str,
|
|
|
b75106 |
strict: bool,
|
|
|
b75106 |
+ resource_state_before: Dict[str, List[str]],
|
|
|
b75106 |
+ node: Optional[str],
|
|
|
b75106 |
) -> None:
|
|
|
b75106 |
# pylint: disable=too-many-locals
|
|
|
b75106 |
with get_tmp_cib(report_processor, cib_xml) as rsc_unmove_cib_file:
|
|
|
b75106 |
+ if not _was_resource_moved(
|
|
|
b75106 |
+ node,
|
|
|
b75106 |
+ resource_state_before,
|
|
|
b75106 |
+ get_resource_state(
|
|
|
b75106 |
+ get_cluster_status_dom(
|
|
|
b75106 |
+ runner_factory(dict(CIB_file=rsc_unmove_cib_file.name))
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ resource_id,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ ):
|
|
|
b75106 |
+ raise LibraryError(
|
|
|
b75106 |
+ reports.ReportItem.error(
|
|
|
b75106 |
+ reports.messages.ResourceMoveNotAffectingResource(
|
|
|
b75106 |
+ resource_id
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ )
|
|
|
b75106 |
push_cib_diff_xml(
|
|
|
b75106 |
runner_factory(dict(CIB_file=rsc_unmove_cib_file.name)),
|
|
|
b75106 |
remove_constraint_cib_diff,
|
|
|
b75106 |
@@ -1809,20 +1873,31 @@ def _resource_running_on_nodes(
|
|
|
b75106 |
return frozenset()
|
|
|
b75106 |
|
|
|
b75106 |
|
|
|
b75106 |
+def _was_resource_moved(
|
|
|
b75106 |
+ node: Optional[str],
|
|
|
b75106 |
+ resource_state_before: Dict[str, List[str]],
|
|
|
b75106 |
+ resource_state_after: Dict[str, List[str]],
|
|
|
b75106 |
+) -> bool:
|
|
|
b75106 |
+ running_on_nodes = _resource_running_on_nodes(resource_state_after)
|
|
|
b75106 |
+ return not bool(
|
|
|
b75106 |
+ resource_state_before
|
|
|
b75106 |
+ and ( # running resource moved
|
|
|
b75106 |
+ not running_on_nodes
|
|
|
b75106 |
+ or (node and node not in running_on_nodes)
|
|
|
b75106 |
+ or (resource_state_before == resource_state_after)
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
def _move_wait_report(
|
|
|
b75106 |
resource_id: str,
|
|
|
b75106 |
node: Optional[str],
|
|
|
b75106 |
resource_state_before: Dict[str, List[str]],
|
|
|
b75106 |
resource_state_after: Dict[str, List[str]],
|
|
|
b75106 |
) -> ReportItem:
|
|
|
b75106 |
- allowed_nodes = frozenset([node] if node else [])
|
|
|
b75106 |
- running_on_nodes = _resource_running_on_nodes(resource_state_after)
|
|
|
b75106 |
-
|
|
|
b75106 |
severity = reports.item.ReportItemSeverity.info()
|
|
|
b75106 |
- if resource_state_before and ( # running resource moved
|
|
|
b75106 |
- not running_on_nodes
|
|
|
b75106 |
- or (allowed_nodes and allowed_nodes.isdisjoint(running_on_nodes))
|
|
|
b75106 |
- or (resource_state_before == resource_state_after)
|
|
|
b75106 |
+ if not _was_resource_moved(
|
|
|
b75106 |
+ node, resource_state_before, resource_state_after
|
|
|
b75106 |
):
|
|
|
b75106 |
severity = reports.item.ReportItemSeverity.error()
|
|
|
b75106 |
if not resource_state_after:
|
|
|
b75106 |
@@ -1873,14 +1948,18 @@ class _MoveBanTemplate:
|
|
|
b75106 |
lifetime=None,
|
|
|
b75106 |
wait: WaitType = False,
|
|
|
b75106 |
):
|
|
|
b75106 |
+ # pylint: disable=too-many-locals
|
|
|
b75106 |
# validate
|
|
|
b75106 |
wait_timeout = env.ensure_wait_satisfiable(wait) # raises on error
|
|
|
b75106 |
|
|
|
b75106 |
+ cib = env.get_cib()
|
|
|
b75106 |
resource_el, report_list = resource.common.find_one_resource(
|
|
|
b75106 |
- get_resources(env.get_cib()), resource_id
|
|
|
b75106 |
+ get_resources(cib), resource_id
|
|
|
b75106 |
)
|
|
|
b75106 |
if resource_el is not None:
|
|
|
b75106 |
report_list.extend(self._validate(resource_el, master))
|
|
|
b75106 |
+ if node:
|
|
|
b75106 |
+ report_list.extend(_nodes_exist_reports(cib, [node]))
|
|
|
b75106 |
if env.report_processor.report_list(report_list).has_errors:
|
|
|
b75106 |
raise LibraryError()
|
|
|
b75106 |
|
|
|
b75106 |
diff --git a/pcs/lib/node.py b/pcs/lib/node.py
|
|
|
b75106 |
index ff08f747..3a7f236e 100644
|
|
|
b75106 |
--- a/pcs/lib/node.py
|
|
|
b75106 |
+++ b/pcs/lib/node.py
|
|
|
b75106 |
@@ -3,6 +3,7 @@ from typing import (
|
|
|
b75106 |
List,
|
|
|
b75106 |
Optional,
|
|
|
b75106 |
Tuple,
|
|
|
b75106 |
+ Set,
|
|
|
b75106 |
)
|
|
|
b75106 |
|
|
|
b75106 |
from lxml.etree import _Element
|
|
|
b75106 |
@@ -11,7 +12,7 @@ from pcs.common import reports
|
|
|
b75106 |
from pcs.common.reports import ReportItemList
|
|
|
b75106 |
from pcs.common.reports import ReportItemSeverity
|
|
|
b75106 |
from pcs.common.reports.item import ReportItem
|
|
|
b75106 |
-from pcs.lib.cib.node import PacemakerNode
|
|
|
b75106 |
+from pcs.lib.cib.node import PacemakerNode, get_node_names
|
|
|
b75106 |
from pcs.lib.cib.resource import remote_node, guest_node
|
|
|
b75106 |
from pcs.lib.corosync.config_facade import ConfigFacade as CorosyncConfigFacade
|
|
|
b75106 |
from pcs.lib.corosync.node import CorosyncNode
|
|
|
b75106 |
@@ -28,6 +29,10 @@ def get_existing_nodes_names(
|
|
|
b75106 |
)
|
|
|
b75106 |
|
|
|
b75106 |
|
|
|
b75106 |
+def get_pacemaker_node_names(cib: _Element) -> Set[str]:
|
|
|
b75106 |
+ return get_node_names(cib) | set(get_existing_nodes_names(None, cib)[0])
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
def get_existing_nodes_names_addrs(
|
|
|
b75106 |
corosync_conf=None, cib=None, error_on_missing_name=False
|
|
|
b75106 |
):
|
|
|
b75106 |
diff --git a/pcs/resource.py b/pcs/resource.py
|
|
|
b75106 |
index c7cf4c7e..f4f2c093 100644
|
|
|
b75106 |
--- a/pcs/resource.py
|
|
|
b75106 |
+++ b/pcs/resource.py
|
|
|
b75106 |
@@ -24,6 +24,7 @@ from pcs.settings import (
|
|
|
b75106 |
pacemaker_wait_timeout_status as PACEMAKER_WAIT_TIMEOUT_STATUS,
|
|
|
b75106 |
)
|
|
|
b75106 |
from pcs.cli.common.errors import (
|
|
|
b75106 |
+ SEE_MAN_CHANGES,
|
|
|
b75106 |
raise_command_replaced,
|
|
|
b75106 |
CmdLineInputError,
|
|
|
b75106 |
)
|
|
|
b75106 |
@@ -868,6 +869,12 @@ def resource_move(lib: Any, argv: List[str], modifiers: InputModifiers):
|
|
|
b75106 |
node = None
|
|
|
b75106 |
if argv:
|
|
|
b75106 |
node = argv.pop(0)
|
|
|
b75106 |
+ if node.startswith("lifetime="):
|
|
|
b75106 |
+ deprecation_warning(
|
|
|
b75106 |
+ "Option 'lifetime' has been removed. {}".format(
|
|
|
b75106 |
+ SEE_MAN_CHANGES.format("0.11")
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ )
|
|
|
b75106 |
if argv:
|
|
|
b75106 |
raise CmdLineInputError()
|
|
|
b75106 |
|
|
|
b75106 |
diff --git a/pcs_test/tier0/common/reports/test_messages.py b/pcs_test/tier0/common/reports/test_messages.py
|
|
|
b75106 |
index a6f92395..a56ef382 100644
|
|
|
b75106 |
--- a/pcs_test/tier0/common/reports/test_messages.py
|
|
|
b75106 |
+++ b/pcs_test/tier0/common/reports/test_messages.py
|
|
|
b75106 |
@@ -4515,6 +4515,18 @@ class ResourceMoveConstraintRemoved(NameBuildTest):
|
|
|
b75106 |
)
|
|
|
b75106 |
|
|
|
b75106 |
|
|
|
b75106 |
+class ResourceMoveNotAffectingResource(NameBuildTest):
|
|
|
b75106 |
+ def test_success(self):
|
|
|
b75106 |
+ self.assert_message_from_report(
|
|
|
b75106 |
+ (
|
|
|
b75106 |
+ "Unable to move resource 'R1' using a location constraint. "
|
|
|
b75106 |
+ "Current location of the resource may be affected by some "
|
|
|
b75106 |
+ "other constraint."
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ reports.ResourceMoveNotAffectingResource("R1"),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
class ResourceMoveAffectsOtherResources(NameBuildTest):
|
|
|
b75106 |
def test_multiple(self):
|
|
|
b75106 |
self.assert_message_from_report(
|
|
|
b75106 |
diff --git a/pcs_test/tier0/lib/commands/resource/test_resource_move_autoclean.py b/pcs_test/tier0/lib/commands/resource/test_resource_move_autoclean.py
|
|
|
b75106 |
index 32d758de..1bd4ee82 100644
|
|
|
b75106 |
--- a/pcs_test/tier0/lib/commands/resource/test_resource_move_autoclean.py
|
|
|
b75106 |
+++ b/pcs_test/tier0/lib/commands/resource/test_resource_move_autoclean.py
|
|
|
b75106 |
@@ -20,6 +20,25 @@ from pcs_test.tools.command_env import get_env_tools
|
|
|
b75106 |
from pcs_test.tools.misc import get_test_resource as rc
|
|
|
b75106 |
|
|
|
b75106 |
|
|
|
b75106 |
+def _node_fixture(name, node_id):
|
|
|
b75106 |
+ return f'<node id="{node_id}" uname="{name}"/>'
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
+def _node_list_fixture(nodes):
|
|
|
b75106 |
+ return "\n".join(
|
|
|
b75106 |
+ _node_fixture(node_name, node_id)
|
|
|
b75106 |
+ for node_id, node_name in enumerate(nodes)
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
+def _nodes_section_fixture(content):
|
|
|
b75106 |
+ return f"""
|
|
|
b75106 |
+ <nodes>
|
|
|
b75106 |
+ {content}
|
|
|
b75106 |
+ </nodes>
|
|
|
b75106 |
+ """
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
def _rsc_primitive_fixture(res_id):
|
|
|
b75106 |
return f'<primitive id="{res_id}"/>'
|
|
|
b75106 |
|
|
|
b75106 |
@@ -145,11 +164,17 @@ class MoveAutocleanSuccess(MoveAutocleanCommonSetup):
|
|
|
b75106 |
resources=_resources_tag(
|
|
|
b75106 |
_resource_primitive + _resource_promotable_clone
|
|
|
b75106 |
),
|
|
|
b75106 |
+ nodes=_nodes_section_fixture(
|
|
|
b75106 |
+ _node_list_fixture([self.orig_node, self.new_node])
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
)
|
|
|
b75106 |
self.orig_cib = etree_to_str(
|
|
|
b75106 |
xml_fromstring(self.config.calls.get(config_load_cib_name).stdout)
|
|
|
b75106 |
)
|
|
|
b75106 |
self.cib_with_constraint = '<updated_cib with_constraint="True"/>'
|
|
|
b75106 |
+ self.cib_without_constraint = (
|
|
|
b75106 |
+ '<cib with_constraint="False" updated="True"/>'
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.cib_simulate_constraint = (
|
|
|
b75106 |
'<cib simulate="True" with_constraint="True"/>'
|
|
|
b75106 |
)
|
|
|
b75106 |
@@ -160,6 +185,9 @@ class MoveAutocleanSuccess(MoveAutocleanCommonSetup):
|
|
|
b75106 |
self.cib_diff_add_constraint_updated_tmp_file_name = (
|
|
|
b75106 |
"cib_diff_add_constraint_updated"
|
|
|
b75106 |
)
|
|
|
b75106 |
+ self.cib_constraint_removed_by_unmove_file_name = (
|
|
|
b75106 |
+ "cib_constraint_removed_by_unmove"
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.cib_diff_remove_constraint_orig_tmp_file_name = (
|
|
|
b75106 |
"cib_diff_remove_constraint_orig"
|
|
|
b75106 |
)
|
|
|
b75106 |
@@ -220,13 +248,18 @@ class MoveAutocleanSuccess(MoveAutocleanCommonSetup):
|
|
|
b75106 |
self.cib_diff_add_constraint_updated_tmp_file_name,
|
|
|
b75106 |
orig_content=self.cib_with_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
+ TmpFileCall(
|
|
|
b75106 |
+ self.cib_constraint_removed_by_unmove_file_name,
|
|
|
b75106 |
+ orig_content=self.cib_with_constraint,
|
|
|
b75106 |
+ new_content=self.cib_without_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
TmpFileCall(
|
|
|
b75106 |
self.cib_diff_remove_constraint_orig_tmp_file_name,
|
|
|
b75106 |
orig_content=self.cib_with_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
TmpFileCall(
|
|
|
b75106 |
self.cib_diff_remove_constraint_updated_tmp_file_name,
|
|
|
b75106 |
- orig_content=self.orig_cib,
|
|
|
b75106 |
+ orig_content=self.cib_without_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
TmpFileCall(
|
|
|
b75106 |
self.simulated_cib_add_constraint_tmp_file_name,
|
|
|
b75106 |
@@ -296,6 +329,12 @@ class MoveAutocleanSuccess(MoveAutocleanCommonSetup):
|
|
|
b75106 |
stdout=self.cib_diff_add_constraint,
|
|
|
b75106 |
name="runner.cib.diff.add_constraint",
|
|
|
b75106 |
)
|
|
|
b75106 |
+ self.config.runner.pcmk.resource_clear(
|
|
|
b75106 |
+ resource=resource_id,
|
|
|
b75106 |
+ master=is_promotable,
|
|
|
b75106 |
+ node=self.new_node if with_node else None,
|
|
|
b75106 |
+ env=dict(CIB_file=self.cib_constraint_removed_by_unmove_file_name),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.config.runner.cib.diff(
|
|
|
b75106 |
self.cib_diff_remove_constraint_orig_tmp_file_name,
|
|
|
b75106 |
self.cib_diff_remove_constraint_updated_tmp_file_name,
|
|
|
b75106 |
@@ -308,6 +347,13 @@ class MoveAutocleanSuccess(MoveAutocleanCommonSetup):
|
|
|
b75106 |
cib_xml=self.cib_with_constraint,
|
|
|
b75106 |
name="pcmk.simulate.rsc.move",
|
|
|
b75106 |
)
|
|
|
b75106 |
+ self.config.runner.pcmk.load_state(
|
|
|
b75106 |
+ resources=status_after,
|
|
|
b75106 |
+ name="runner.pcmk.load_state.mid_simulation",
|
|
|
b75106 |
+ env=dict(
|
|
|
b75106 |
+ CIB_file=self.cib_apply_diff_remove_constraint_from_simulated_cib_tmp_file_name
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.config.runner.cib.push_diff(
|
|
|
b75106 |
cib_diff=self.cib_diff_remove_constraint,
|
|
|
b75106 |
name="pcmk.push_cib_diff.simulation.remove_constraint",
|
|
|
b75106 |
@@ -335,6 +381,13 @@ class MoveAutocleanSuccess(MoveAutocleanCommonSetup):
|
|
|
b75106 |
self.cib_with_constraint,
|
|
|
b75106 |
name="load_cib_after_move",
|
|
|
b75106 |
)
|
|
|
b75106 |
+ self.config.runner.pcmk.load_state(
|
|
|
b75106 |
+ resources=status_after,
|
|
|
b75106 |
+ name="runner.pcmk.load_state.after_push",
|
|
|
b75106 |
+ env=dict(
|
|
|
b75106 |
+ CIB_file=self.cib_apply_diff_remove_constraint_after_push_tmp_file_name
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.config.runner.cib.push_diff(
|
|
|
b75106 |
cib_diff=self.cib_diff_remove_constraint,
|
|
|
b75106 |
name="pcmk.push_cib_diff.simulation.remove_constraint_after_move",
|
|
|
b75106 |
@@ -380,6 +433,11 @@ class MoveAutocleanSuccess(MoveAutocleanCommonSetup):
|
|
|
b75106 |
file_path=self.cib_diff_add_constraint_updated_tmp_file_name,
|
|
|
b75106 |
content=self.cib_with_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
+ fixture.debug(
|
|
|
b75106 |
+ reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
+ file_path=self.cib_constraint_removed_by_unmove_file_name,
|
|
|
b75106 |
+ content=self.cib_with_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
fixture.debug(
|
|
|
b75106 |
reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
file_path=self.cib_diff_remove_constraint_orig_tmp_file_name,
|
|
|
b75106 |
@@ -388,7 +446,7 @@ class MoveAutocleanSuccess(MoveAutocleanCommonSetup):
|
|
|
b75106 |
fixture.debug(
|
|
|
b75106 |
reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
file_path=self.cib_diff_remove_constraint_updated_tmp_file_name,
|
|
|
b75106 |
- content=self.orig_cib,
|
|
|
b75106 |
+ content=self.cib_without_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
fixture.debug(
|
|
|
b75106 |
reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
@@ -758,9 +816,7 @@ class MoveAutocleanValidations(MoveAutocleanCommonSetup):
|
|
|
b75106 |
resources=_state_resource_fixture(resource_id, "Stopped"),
|
|
|
b75106 |
)
|
|
|
b75106 |
self.env_assist.assert_raise_library_error(
|
|
|
b75106 |
- lambda: move_autoclean(
|
|
|
b75106 |
- self.env_assist.get_env(), resource_id, node="node"
|
|
|
b75106 |
- ),
|
|
|
b75106 |
+ lambda: move_autoclean(self.env_assist.get_env(), resource_id),
|
|
|
b75106 |
[
|
|
|
b75106 |
fixture.error(
|
|
|
b75106 |
reports.codes.CANNOT_MOVE_RESOURCE_NOT_RUNNING,
|
|
|
b75106 |
@@ -770,11 +826,33 @@ class MoveAutocleanValidations(MoveAutocleanCommonSetup):
|
|
|
b75106 |
expected_in_processor=False,
|
|
|
b75106 |
)
|
|
|
b75106 |
|
|
|
b75106 |
+ def test_node_not_found(self):
|
|
|
b75106 |
+ resource_id = "A"
|
|
|
b75106 |
+ node = "non_existing_node"
|
|
|
b75106 |
+ self.config.runner.cib.load(
|
|
|
b75106 |
+ resources=_resources_tag(_rsc_primitive_fixture(resource_id)),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ self.env_assist.assert_raise_library_error(
|
|
|
b75106 |
+ lambda: move_autoclean(
|
|
|
b75106 |
+ self.env_assist.get_env(), resource_id, node
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ self.env_assist.assert_reports(
|
|
|
b75106 |
+ [
|
|
|
b75106 |
+ fixture.error(
|
|
|
b75106 |
+ reports.codes.NODE_NOT_FOUND,
|
|
|
b75106 |
+ node=node,
|
|
|
b75106 |
+ searched_types=[],
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ ],
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+
|
|
|
b75106 |
def test_constraint_already_exist(self):
|
|
|
b75106 |
resource_id = "A"
|
|
|
b75106 |
config_load_cib_name = "load_cib"
|
|
|
b75106 |
node = "node1"
|
|
|
b75106 |
cib_with_constraint = '<cib with_constraint="True"/>'
|
|
|
b75106 |
+ cib_without_constraint = '<cib with_constraint="False" updated="True"/>'
|
|
|
b75106 |
cib_rsc_move_tmp_file_name = "cib_rsc_move_tmp_file"
|
|
|
b75106 |
cib_diff_add_constraint_orig_tmp_file_name = (
|
|
|
b75106 |
"cib_diff_add_constraint_orig"
|
|
|
b75106 |
@@ -788,6 +866,9 @@ class MoveAutocleanValidations(MoveAutocleanCommonSetup):
|
|
|
b75106 |
cib_diff_remove_constraint_updated_tmp_file_name = (
|
|
|
b75106 |
"cib_diff_remove_constraint_updated"
|
|
|
b75106 |
)
|
|
|
b75106 |
+ cib_constraint_removed_by_unmove_file_name = (
|
|
|
b75106 |
+ "cib_constraint_removed_by_unmove"
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.config.runner.cib.load(
|
|
|
b75106 |
resources=_resources_tag(_rsc_primitive_fixture(resource_id)),
|
|
|
b75106 |
constraints=f"""
|
|
|
b75106 |
@@ -795,6 +876,7 @@ class MoveAutocleanValidations(MoveAutocleanCommonSetup):
|
|
|
b75106 |
<rsc_location id="prefer-{resource_id}" rsc="{resource_id}" role="Started" node="{node}" score="INFINITY"/>
|
|
|
b75106 |
</constraints>
|
|
|
b75106 |
""",
|
|
|
b75106 |
+ nodes=_nodes_section_fixture(_node_list_fixture([node])),
|
|
|
b75106 |
name=config_load_cib_name,
|
|
|
b75106 |
)
|
|
|
b75106 |
orig_cib = etree_to_str(
|
|
|
b75106 |
@@ -815,13 +897,18 @@ class MoveAutocleanValidations(MoveAutocleanCommonSetup):
|
|
|
b75106 |
cib_diff_add_constraint_updated_tmp_file_name,
|
|
|
b75106 |
orig_content=cib_with_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
+ TmpFileCall(
|
|
|
b75106 |
+ cib_constraint_removed_by_unmove_file_name,
|
|
|
b75106 |
+ orig_content=cib_with_constraint,
|
|
|
b75106 |
+ new_content=cib_without_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
TmpFileCall(
|
|
|
b75106 |
cib_diff_remove_constraint_orig_tmp_file_name,
|
|
|
b75106 |
orig_content=cib_with_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
TmpFileCall(
|
|
|
b75106 |
cib_diff_remove_constraint_updated_tmp_file_name,
|
|
|
b75106 |
- orig_content=orig_cib,
|
|
|
b75106 |
+ orig_content=cib_without_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
]
|
|
|
b75106 |
)
|
|
|
b75106 |
@@ -839,6 +926,11 @@ class MoveAutocleanValidations(MoveAutocleanCommonSetup):
|
|
|
b75106 |
stdout="",
|
|
|
b75106 |
name="runner.cib.diff.add_constraint",
|
|
|
b75106 |
)
|
|
|
b75106 |
+ self.config.runner.pcmk.resource_clear(
|
|
|
b75106 |
+ resource=resource_id,
|
|
|
b75106 |
+ node=node,
|
|
|
b75106 |
+ env=dict(CIB_file=cib_constraint_removed_by_unmove_file_name),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.config.runner.cib.diff(
|
|
|
b75106 |
cib_diff_remove_constraint_orig_tmp_file_name,
|
|
|
b75106 |
cib_diff_remove_constraint_updated_tmp_file_name,
|
|
|
b75106 |
@@ -863,6 +955,11 @@ class MoveAutocleanValidations(MoveAutocleanCommonSetup):
|
|
|
b75106 |
file_path=cib_diff_add_constraint_updated_tmp_file_name,
|
|
|
b75106 |
content=cib_with_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
+ fixture.debug(
|
|
|
b75106 |
+ reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
+ file_path=cib_constraint_removed_by_unmove_file_name,
|
|
|
b75106 |
+ content=cib_with_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
fixture.debug(
|
|
|
b75106 |
reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
file_path=cib_diff_remove_constraint_orig_tmp_file_name,
|
|
|
b75106 |
@@ -871,7 +968,7 @@ class MoveAutocleanValidations(MoveAutocleanCommonSetup):
|
|
|
b75106 |
fixture.debug(
|
|
|
b75106 |
reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
file_path=cib_diff_remove_constraint_updated_tmp_file_name,
|
|
|
b75106 |
- content=orig_cib,
|
|
|
b75106 |
+ content=cib_without_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
fixture.info(
|
|
|
b75106 |
reports.codes.NO_ACTION_NECESSARY,
|
|
|
b75106 |
@@ -896,6 +993,9 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
self.cib_diff_add_constraint = "diff_add_constraint"
|
|
|
b75106 |
self.cib_diff_remove_constraint = "diff_remove_constraint"
|
|
|
b75106 |
self.cib_with_constraint = '<cib with_constraint="True"/>'
|
|
|
b75106 |
+ self.cib_without_constraint = (
|
|
|
b75106 |
+ '<cib with_constraint="False" updated="True"/>'
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.cib_rsc_move_tmp_file_name = "cib_rsc_move_tmp_file"
|
|
|
b75106 |
self.cib_diff_add_constraint_orig_tmp_file_name = (
|
|
|
b75106 |
"cib_diff_add_constraint_orig"
|
|
|
b75106 |
@@ -903,6 +1003,9 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
self.cib_diff_add_constraint_updated_tmp_file_name = (
|
|
|
b75106 |
"cib_diff_add_constraint_updated"
|
|
|
b75106 |
)
|
|
|
b75106 |
+ self.cib_constraint_removed_by_unmove_file_name = (
|
|
|
b75106 |
+ "cib_constraint_removed_by_unmove"
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.cib_diff_remove_constraint_orig_tmp_file_name = (
|
|
|
b75106 |
"cib_diff_remove_constraint_orig"
|
|
|
b75106 |
)
|
|
|
b75106 |
@@ -951,6 +1054,9 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
|
|
|
b75106 |
self.config.runner.cib.load(
|
|
|
b75106 |
resources=_resources_tag(_rsc_primitive_fixture(self.resource_id)),
|
|
|
b75106 |
+ nodes=_nodes_section_fixture(
|
|
|
b75106 |
+ _node_list_fixture(["node1", "node2"])
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
name=self.config_load_cib_name,
|
|
|
b75106 |
)
|
|
|
b75106 |
self.orig_cib = etree_to_str(
|
|
|
b75106 |
@@ -979,13 +1085,18 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
self.cib_diff_add_constraint_updated_tmp_file_name,
|
|
|
b75106 |
orig_content=self.cib_with_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
+ TmpFileCall(
|
|
|
b75106 |
+ self.cib_constraint_removed_by_unmove_file_name,
|
|
|
b75106 |
+ orig_content=self.cib_with_constraint,
|
|
|
b75106 |
+ new_content=self.cib_without_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
TmpFileCall(
|
|
|
b75106 |
self.cib_diff_remove_constraint_orig_tmp_file_name,
|
|
|
b75106 |
orig_content=self.cib_with_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
TmpFileCall(
|
|
|
b75106 |
self.cib_diff_remove_constraint_updated_tmp_file_name,
|
|
|
b75106 |
- orig_content=self.orig_cib,
|
|
|
b75106 |
+ orig_content=self.cib_without_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
TmpFileCall(
|
|
|
b75106 |
self.simulated_cib_add_constraint_tmp_file_name,
|
|
|
b75106 |
@@ -1067,6 +1178,11 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
stdout=self.cib_diff_add_constraint,
|
|
|
b75106 |
name="runner.cib.diff.add_constraint",
|
|
|
b75106 |
)
|
|
|
b75106 |
+ self.config.runner.pcmk.resource_clear(
|
|
|
b75106 |
+ resource=self.resource_id,
|
|
|
b75106 |
+ node=node,
|
|
|
b75106 |
+ env=dict(CIB_file=self.cib_constraint_removed_by_unmove_file_name),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.config.runner.cib.diff(
|
|
|
b75106 |
self.cib_diff_remove_constraint_orig_tmp_file_name,
|
|
|
b75106 |
self.cib_diff_remove_constraint_updated_tmp_file_name,
|
|
|
b75106 |
@@ -1081,6 +1197,15 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
)
|
|
|
b75106 |
if stage <= 1:
|
|
|
b75106 |
return
|
|
|
b75106 |
+ self.config.runner.pcmk.load_state(
|
|
|
b75106 |
+ resources=_state_resource_fixture(
|
|
|
b75106 |
+ self.resource_id, "Started", node if node else "node2"
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ name="runner.pcmk.load_state.mid_simulation",
|
|
|
b75106 |
+ env=dict(
|
|
|
b75106 |
+ CIB_file=self.cib_apply_diff_remove_constraint_from_simulated_cib_tmp_file_name
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.config.runner.cib.push_diff(
|
|
|
b75106 |
cib_diff=self.cib_diff_remove_constraint,
|
|
|
b75106 |
name="pcmk.push_cib_diff.simulation.remove_constraint",
|
|
|
b75106 |
@@ -1110,6 +1235,17 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
self.cib_with_constraint,
|
|
|
b75106 |
name="load_cib_after_move",
|
|
|
b75106 |
)
|
|
|
b75106 |
+ if stage <= 3:
|
|
|
b75106 |
+ return
|
|
|
b75106 |
+ self.config.runner.pcmk.load_state(
|
|
|
b75106 |
+ resources=_state_resource_fixture(
|
|
|
b75106 |
+ self.resource_id, "Started", node if node else "node2"
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ name="runner.pcmk.load_state.after_push",
|
|
|
b75106 |
+ env=dict(
|
|
|
b75106 |
+ CIB_file=self.cib_apply_diff_remove_constraint_after_push_tmp_file_name
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.config.runner.cib.push_diff(
|
|
|
b75106 |
cib_diff=self.cib_diff_remove_constraint,
|
|
|
b75106 |
name="pcmk.push_cib_diff.simulation.remove_constraint_after_move",
|
|
|
b75106 |
@@ -1126,7 +1262,7 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
),
|
|
|
b75106 |
name="pcmk.simulate.rsc.unmove.after_push",
|
|
|
b75106 |
)
|
|
|
b75106 |
- if stage <= 3:
|
|
|
b75106 |
+ if stage <= 4:
|
|
|
b75106 |
return
|
|
|
b75106 |
self.config.runner.cib.push_diff(
|
|
|
b75106 |
cib_diff=self.cib_diff_remove_constraint,
|
|
|
b75106 |
@@ -1153,6 +1289,11 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
file_path=self.cib_diff_add_constraint_updated_tmp_file_name,
|
|
|
b75106 |
content=self.cib_with_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
+ fixture.debug(
|
|
|
b75106 |
+ reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
+ file_path=self.cib_constraint_removed_by_unmove_file_name,
|
|
|
b75106 |
+ content=self.cib_with_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
fixture.debug(
|
|
|
b75106 |
reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
file_path=self.cib_diff_remove_constraint_orig_tmp_file_name,
|
|
|
b75106 |
@@ -1161,7 +1302,7 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
fixture.debug(
|
|
|
b75106 |
reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
file_path=self.cib_diff_remove_constraint_updated_tmp_file_name,
|
|
|
b75106 |
- content=self.orig_cib,
|
|
|
b75106 |
+ content=self.cib_without_constraint,
|
|
|
b75106 |
),
|
|
|
b75106 |
fixture.debug(
|
|
|
b75106 |
reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
@@ -1199,7 +1340,7 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
reports.codes.WAIT_FOR_IDLE_STARTED,
|
|
|
b75106 |
timeout=0,
|
|
|
b75106 |
),
|
|
|
b75106 |
- ][: {None: None, 3: -2, 2: 7, 1: 5}[stage]]
|
|
|
b75106 |
+ ][: {None: None, 4: -2, 3: 10, 2: 8, 1: 6}[stage]]
|
|
|
b75106 |
|
|
|
b75106 |
def test_move_affects_other_resources_strict(self):
|
|
|
b75106 |
self.tmp_file_mock_obj.set_calls(
|
|
|
b75106 |
@@ -1304,7 +1445,8 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
),
|
|
|
b75106 |
)
|
|
|
b75106 |
)
|
|
|
b75106 |
- self.set_up_testing_env(stage=3)
|
|
|
b75106 |
+ setup_stage = 4
|
|
|
b75106 |
+ self.set_up_testing_env(stage=setup_stage)
|
|
|
b75106 |
self.env_assist.assert_raise_library_error(
|
|
|
b75106 |
lambda: move_autoclean(self.env_assist.get_env(), self.resource_id),
|
|
|
b75106 |
[
|
|
|
b75106 |
@@ -1316,7 +1458,7 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
],
|
|
|
b75106 |
expected_in_processor=False,
|
|
|
b75106 |
)
|
|
|
b75106 |
- self.env_assist.assert_reports(self.get_reports(stage=3))
|
|
|
b75106 |
+ self.env_assist.assert_reports(self.get_reports(stage=setup_stage))
|
|
|
b75106 |
|
|
|
b75106 |
def test_unmove_after_push_affects_other_resources_strict(self):
|
|
|
b75106 |
self.tmp_file_mock_obj.set_calls(
|
|
|
b75106 |
@@ -1330,7 +1472,8 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
),
|
|
|
b75106 |
)
|
|
|
b75106 |
)
|
|
|
b75106 |
- self.set_up_testing_env(stage=3)
|
|
|
b75106 |
+ setup_stage = 4
|
|
|
b75106 |
+ self.set_up_testing_env(stage=setup_stage)
|
|
|
b75106 |
self.env_assist.assert_raise_library_error(
|
|
|
b75106 |
lambda: move_autoclean(
|
|
|
b75106 |
self.env_assist.get_env(),
|
|
|
b75106 |
@@ -1346,7 +1489,7 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
],
|
|
|
b75106 |
expected_in_processor=False,
|
|
|
b75106 |
)
|
|
|
b75106 |
- self.env_assist.assert_reports(self.get_reports(stage=3))
|
|
|
b75106 |
+ self.env_assist.assert_reports(self.get_reports(stage=setup_stage))
|
|
|
b75106 |
|
|
|
b75106 |
def test_resource_not_runnig_after_move(self):
|
|
|
b75106 |
self.tmp_file_mock_obj.set_calls(
|
|
|
b75106 |
@@ -1381,8 +1524,113 @@ class MoveAutocleanFailures(MoveAutocleanCommonSetup):
|
|
|
b75106 |
]
|
|
|
b75106 |
)
|
|
|
b75106 |
|
|
|
b75106 |
+ def test_simulation_resource_not_moved(self):
|
|
|
b75106 |
+ node = "node2"
|
|
|
b75106 |
+ different_node = f"different-{node}"
|
|
|
b75106 |
+ setup_stage = 1
|
|
|
b75106 |
+ self.tmp_file_mock_obj.set_calls(
|
|
|
b75106 |
+ self.get_tmp_files_mocks(
|
|
|
b75106 |
+ _simulation_transition_fixture(
|
|
|
b75106 |
+ _simulation_synapses_fixture(self.resource_id)
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ + [
|
|
|
b75106 |
+ TmpFileCall(
|
|
|
b75106 |
+ self.cib_apply_diff_remove_constraint_from_simulated_cib_tmp_file_name,
|
|
|
b75106 |
+ orig_content=self.cib_simulate_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ ]
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ self.set_up_testing_env(node=node, stage=setup_stage)
|
|
|
b75106 |
+ self.config.runner.pcmk.load_state(
|
|
|
b75106 |
+ resources=_state_resource_fixture(
|
|
|
b75106 |
+ self.resource_id, "Started", different_node
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ name="runner.pcmk.load_state.final",
|
|
|
b75106 |
+ env=dict(
|
|
|
b75106 |
+ CIB_file=self.cib_apply_diff_remove_constraint_from_simulated_cib_tmp_file_name
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ self.env_assist.assert_raise_library_error(
|
|
|
b75106 |
+ lambda: move_autoclean(
|
|
|
b75106 |
+ self.env_assist.get_env(),
|
|
|
b75106 |
+ self.resource_id,
|
|
|
b75106 |
+ node=node,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ [
|
|
|
b75106 |
+ fixture.error(
|
|
|
b75106 |
+ reports.codes.RESOURCE_MOVE_NOT_AFFECTING_RESOURCE,
|
|
|
b75106 |
+ resource_id=self.resource_id,
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ ],
|
|
|
b75106 |
+ expected_in_processor=False,
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ self.env_assist.assert_reports(
|
|
|
b75106 |
+ self.get_reports(stage=setup_stage)
|
|
|
b75106 |
+ + [
|
|
|
b75106 |
+ fixture.debug(
|
|
|
b75106 |
+ reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
+ file_path=self.cib_apply_diff_remove_constraint_from_simulated_cib_tmp_file_name,
|
|
|
b75106 |
+ content=self.cib_simulate_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ ]
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+
|
|
|
b75106 |
+ def test_after_push_resource_not_moved(self):
|
|
|
b75106 |
+ node = "node2"
|
|
|
b75106 |
+ different_node = f"different-{node}"
|
|
|
b75106 |
+ setup_stage = 3
|
|
|
b75106 |
+ self.tmp_file_mock_obj.set_calls(
|
|
|
b75106 |
+ self.get_tmp_files_mocks(
|
|
|
b75106 |
+ _simulation_transition_fixture(
|
|
|
b75106 |
+ _simulation_synapses_fixture(self.resource_id)
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ _simulation_transition_fixture(),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ + [
|
|
|
b75106 |
+ TmpFileCall(
|
|
|
b75106 |
+ self.cib_apply_diff_remove_constraint_after_push_tmp_file_name,
|
|
|
b75106 |
+ orig_content=self.cib_with_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ ]
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ self.set_up_testing_env(node=node, stage=setup_stage)
|
|
|
b75106 |
+ self.config.runner.pcmk.load_state(
|
|
|
b75106 |
+ resources=_state_resource_fixture(
|
|
|
b75106 |
+ self.resource_id, "Started", different_node
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ name="runner.pcmk.load_state.final",
|
|
|
b75106 |
+ env=dict(
|
|
|
b75106 |
+ CIB_file=self.cib_apply_diff_remove_constraint_after_push_tmp_file_name,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ self.env_assist.assert_raise_library_error(
|
|
|
b75106 |
+ lambda: move_autoclean(
|
|
|
b75106 |
+ self.env_assist.get_env(),
|
|
|
b75106 |
+ self.resource_id,
|
|
|
b75106 |
+ node=node,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ [
|
|
|
b75106 |
+ fixture.error(
|
|
|
b75106 |
+ reports.codes.RESOURCE_MOVE_NOT_AFFECTING_RESOURCE,
|
|
|
b75106 |
+ resource_id=self.resource_id,
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ ],
|
|
|
b75106 |
+ expected_in_processor=False,
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ self.env_assist.assert_reports(
|
|
|
b75106 |
+ self.get_reports(stage=setup_stage)
|
|
|
b75106 |
+ + [
|
|
|
b75106 |
+ fixture.debug(
|
|
|
b75106 |
+ reports.codes.TMP_FILE_WRITE,
|
|
|
b75106 |
+ file_path=self.cib_apply_diff_remove_constraint_after_push_tmp_file_name,
|
|
|
b75106 |
+ content=self.cib_with_constraint,
|
|
|
b75106 |
+ ),
|
|
|
b75106 |
+ ]
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+
|
|
|
b75106 |
def test_resource_running_on_a_different_node(self):
|
|
|
b75106 |
- node = "node1"
|
|
|
b75106 |
+ node = "node2"
|
|
|
b75106 |
different_node = f"different-{node}"
|
|
|
b75106 |
self.tmp_file_mock_obj.set_calls(
|
|
|
b75106 |
self.get_tmp_files_mocks(
|
|
|
b75106 |
diff --git a/pcs_test/tier0/lib/commands/resource/test_resource_move_ban.py b/pcs_test/tier0/lib/commands/resource/test_resource_move_ban.py
|
|
|
b75106 |
index 5d57fa06..28dd1cd1 100644
|
|
|
b75106 |
--- a/pcs_test/tier0/lib/commands/resource/test_resource_move_ban.py
|
|
|
b75106 |
+++ b/pcs_test/tier0/lib/commands/resource/test_resource_move_ban.py
|
|
|
b75106 |
@@ -10,6 +10,29 @@ from pcs.common.reports import ReportItemSeverity as severities
|
|
|
b75106 |
from pcs.common.reports import codes as report_codes
|
|
|
b75106 |
from pcs.lib.commands import resource
|
|
|
b75106 |
|
|
|
b75106 |
+
|
|
|
b75106 |
+def _node_fixture(name, node_id):
|
|
|
b75106 |
+ return f'<node id="{node_id}" uname="{name}"/>'
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
+def _node_list_fixture(nodes):
|
|
|
b75106 |
+ return "\n".join(
|
|
|
b75106 |
+ _node_fixture(node_name, node_id)
|
|
|
b75106 |
+ for node_id, node_name in enumerate(nodes)
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
+def _nodes_section_fixture(content):
|
|
|
b75106 |
+ return f"""
|
|
|
b75106 |
+ <nodes>
|
|
|
b75106 |
+ {content}
|
|
|
b75106 |
+ </nodes>
|
|
|
b75106 |
+ """
|
|
|
b75106 |
+
|
|
|
b75106 |
+
|
|
|
b75106 |
+nodes_section = _nodes_section_fixture(
|
|
|
b75106 |
+ _node_list_fixture(["node", "node1", "node2"])
|
|
|
b75106 |
+)
|
|
|
b75106 |
resources_primitive = """
|
|
|
b75106 |
<resources>
|
|
|
b75106 |
<primitive id="A" />
|
|
|
b75106 |
@@ -128,8 +151,24 @@ class MoveBanBaseMixin(MoveBanClearBaseMixin):
|
|
|
b75106 |
expected_in_processor=False,
|
|
|
b75106 |
)
|
|
|
b75106 |
|
|
|
b75106 |
+ def test_node_not_found(self):
|
|
|
b75106 |
+ self.config.runner.cib.load(resources=resources_primitive)
|
|
|
b75106 |
+ node = "node"
|
|
|
b75106 |
+ self.env_assist.assert_raise_library_error(
|
|
|
b75106 |
+ lambda: self.lib_action(self.env_assist.get_env(), "A", node)
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ self.env_assist.assert_reports(
|
|
|
b75106 |
+ [
|
|
|
b75106 |
+ fixture.error(
|
|
|
b75106 |
+ report_codes.NODE_NOT_FOUND, node=node, searched_types=[]
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+ ]
|
|
|
b75106 |
+ )
|
|
|
b75106 |
+
|
|
|
b75106 |
def test_all_options(self):
|
|
|
b75106 |
- self.config.runner.cib.load(resources=resources_promotable)
|
|
|
b75106 |
+ self.config.runner.cib.load(
|
|
|
b75106 |
+ resources=resources_promotable, nodes=nodes_section
|
|
|
b75106 |
+ )
|
|
|
b75106 |
self.config_pcmk_action(
|
|
|
b75106 |
resource="A-clone",
|
|
|
b75106 |
master=True,
|
|
|
b75106 |
@@ -274,7 +313,9 @@ class MoveBanWaitMixin:
|
|
|
b75106 |
def setUp(self):
|
|
|
b75106 |
self.timeout = 10
|
|
|
b75106 |
self.env_assist, self.config = get_env_tools(self)
|
|
|
b75106 |
- self.config.runner.cib.load(resources=resources_primitive)
|
|
|
b75106 |
+ self.config.runner.cib.load(
|
|
|
b75106 |
+ resources=resources_primitive, nodes=nodes_section
|
|
|
b75106 |
+ )
|
|
|
b75106 |
|
|
|
b75106 |
@mock.patch.object(
|
|
|
b75106 |
settings,
|
|
|
b75106 |
diff --git a/pcs_test/tools/command_env/config_runner_pcmk.py b/pcs_test/tools/command_env/config_runner_pcmk.py
|
|
|
b75106 |
index 6df3dff3..7a88cf96 100644
|
|
|
b75106 |
--- a/pcs_test/tools/command_env/config_runner_pcmk.py
|
|
|
b75106 |
+++ b/pcs_test/tools/command_env/config_runner_pcmk.py
|
|
|
b75106 |
@@ -695,6 +695,7 @@ class PcmkShortcuts:
|
|
|
b75106 |
stdout="",
|
|
|
b75106 |
stderr="",
|
|
|
b75106 |
returncode=0,
|
|
|
b75106 |
+ env=None,
|
|
|
b75106 |
):
|
|
|
b75106 |
"""
|
|
|
b75106 |
Create a call for crm_resource --clear
|
|
|
b75106 |
@@ -711,6 +712,7 @@ class PcmkShortcuts:
|
|
|
b75106 |
string stdout -- crm_resource's stdout
|
|
|
b75106 |
string stderr -- crm_resource's stderr
|
|
|
b75106 |
int returncode -- crm_resource's returncode
|
|
|
b75106 |
+ dict env -- CommandRunner environment variables
|
|
|
b75106 |
"""
|
|
|
b75106 |
# arguments are used via locals()
|
|
|
b75106 |
# pylint: disable=unused-argument
|
|
|
b75106 |
diff --git a/pcs_test/tools/command_env/mock_runner.py b/pcs_test/tools/command_env/mock_runner.py
|
|
|
b75106 |
index f7871fc2..8520ce02 100644
|
|
|
b75106 |
--- a/pcs_test/tools/command_env/mock_runner.py
|
|
|
b75106 |
+++ b/pcs_test/tools/command_env/mock_runner.py
|
|
|
b75106 |
@@ -143,6 +143,6 @@ class Runner:
|
|
|
b75106 |
env.update(env_extend)
|
|
|
b75106 |
if env != call.env:
|
|
|
b75106 |
raise self.__call_queue.error_with_context(
|
|
|
b75106 |
- f"ENV doesn't match. Expected: {call.env}; Real: {env}"
|
|
|
b75106 |
+ f"Command #{i}: ENV doesn't match. Expected: {call.env}; Real: {env}"
|
|
|
b75106 |
)
|
|
|
b75106 |
return call.stdout, call.stderr, call.returncode
|
|
|
b75106 |
diff --git a/pcs_test/tools/fixture_cib.py b/pcs_test/tools/fixture_cib.py
|
|
|
b75106 |
index 602491c8..bf02bacc 100644
|
|
|
b75106 |
--- a/pcs_test/tools/fixture_cib.py
|
|
|
b75106 |
+++ b/pcs_test/tools/fixture_cib.py
|
|
|
b75106 |
@@ -310,6 +310,7 @@ MODIFIER_GENERATORS = {
|
|
|
b75106 |
"replace": replace_all,
|
|
|
b75106 |
"append": append_all,
|
|
|
b75106 |
"resources": lambda xml: replace_all({"./configuration/resources": xml}),
|
|
|
b75106 |
+ "nodes": lambda xml: replace_all({"./configuration/nodes": xml}),
|
|
|
b75106 |
"constraints": lambda xml: replace_all(
|
|
|
b75106 |
{"./configuration/constraints": xml}
|
|
|
b75106 |
),
|
|
|
b75106 |
--
|
|
|
b75106 |
2.31.1
|
|
|
b75106 |
|