Blame SOURCES/bz1176018-02-pcs-pcsd-should-be-able-to-config.patch

f778fe
From b8b59f772b2bbdb9728b32c674e69df851f82397 Mon Sep 17 00:00:00 2001
f778fe
From: Ivan Devat <idevat@redhat.com>
f778fe
Date: Tue, 30 May 2017 16:56:50 +0200
f778fe
Subject: [PATCH] squash bz1176018 pcs/pcsd should be able to config
f778fe
f778fe
43aeca1 fix --skip-offline without effect problem
f778fe
f778fe
38de786 clean remote/guest node before pushing cib
f778fe
---
f778fe
 pcs/cli/cluster/command.py           | 15 +++++----
f778fe
 pcs/lib/commands/cluster.py          | 65 ++++++++++++++++++++----------------
f778fe
 pcs/lib/nodes_task.py                | 13 ++++++--
f778fe
 pcs/lib/test/test_nodes_task.py      |  4 ---
f778fe
 pcs/test/test_cluster_pcmk_remote.py | 16 +++++----
f778fe
 5 files changed, 66 insertions(+), 47 deletions(-)
f778fe
f778fe
diff --git a/pcs/cli/cluster/command.py b/pcs/cli/cluster/command.py
f778fe
index f725326..963bd8c 100644
f778fe
--- a/pcs/cli/cluster/command.py
f778fe
+++ b/pcs/cli/cluster/command.py
f778fe
@@ -35,6 +35,7 @@ def node_add_remote(lib, arg_list, modifiers):
f778fe
 
f778fe
     parts = parse_resource_create_args(rest_args)
f778fe
     force = modifiers["force"]
f778fe
+    skip_offline = modifiers["skip_offline_nodes"]
f778fe
 
f778fe
     lib.cluster.node_add_remote(
f778fe
         node_host,
f778fe
@@ -42,8 +43,8 @@ def node_add_remote(lib, arg_list, modifiers):
f778fe
         parts["op"],
f778fe
         parts["meta"],
f778fe
         parts["options"],
f778fe
-        allow_incomplete_distribution=force,
f778fe
-        allow_pacemaker_remote_service_fail=force,
f778fe
+        allow_incomplete_distribution=skip_offline,
f778fe
+        allow_pacemaker_remote_service_fail=skip_offline,
f778fe
         allow_invalid_operation=force,
f778fe
         allow_invalid_instance_attributes=force,
f778fe
         use_default_operations=not modifiers["no-default-ops"],
f778fe
@@ -58,7 +59,7 @@ def create_node_remove_remote(remove_resource):
f778fe
             arg_list[0],
f778fe
             remove_resource,
f778fe
             allow_remove_multiple_nodes=modifiers["force"],
f778fe
-            allow_pacemaker_remote_service_fail=modifiers["force"],
f778fe
+            allow_pacemaker_remote_service_fail=modifiers["skip_offline_nodes"],
f778fe
         )
f778fe
     return node_remove_remote
f778fe
 
f778fe
@@ -71,14 +72,14 @@ def node_add_guest(lib, arg_list, modifiers):
f778fe
     resource_id = arg_list[1]
f778fe
     meta_options = prepare_options(arg_list[2:])
f778fe
 
f778fe
-    force = modifiers["force"]
f778fe
+    skip_offline = modifiers["skip_offline_nodes"]
f778fe
 
f778fe
     lib.cluster.node_add_guest(
f778fe
         node_name,
f778fe
         resource_id,
f778fe
         meta_options,
f778fe
-        allow_incomplete_distribution=force,
f778fe
-        allow_pacemaker_remote_service_fail=force,
f778fe
+        allow_incomplete_distribution=skip_offline,
f778fe
+        allow_pacemaker_remote_service_fail=skip_offline,
f778fe
         wait=modifiers["wait"],
f778fe
     )
f778fe
 
f778fe
@@ -89,7 +90,7 @@ def node_remove_guest(lib, arg_list, modifiers):
f778fe
     lib.cluster.node_remove_guest(
f778fe
         arg_list[0],
f778fe
         allow_remove_multiple_nodes=modifiers["force"],
f778fe
-        allow_pacemaker_remote_service_fail=modifiers["force"],
f778fe
+        allow_pacemaker_remote_service_fail=modifiers["skip_offline_nodes"],
f778fe
         wait=modifiers["wait"],
f778fe
     )
f778fe
 
f778fe
diff --git a/pcs/lib/commands/cluster.py b/pcs/lib/commands/cluster.py
f778fe
index 0bafef5..fe883f3 100644
f778fe
--- a/pcs/lib/commands/cluster.py
f778fe
+++ b/pcs/lib/commands/cluster.py
f778fe
@@ -21,13 +21,16 @@ from pcs.lib.errors import LibraryError
f778fe
 from pcs.lib.pacemaker import state
f778fe
 from pcs.lib.pacemaker.live import remove_node
f778fe
 
f778fe
-def _ensure_can_add_node_to_remote_cluster(env, node_addresses):
f778fe
+def _ensure_can_add_node_to_remote_cluster(
f778fe
+    env, node_addresses, warn_on_communication_exception=False
f778fe
+):
f778fe
     report_items = []
f778fe
     nodes_task.check_can_add_node_to_cluster(
f778fe
         env.node_communicator(),
f778fe
         node_addresses,
f778fe
         report_items,
f778fe
-        check_response=nodes_task.availability_checker_remote_node
f778fe
+        check_response=nodes_task.availability_checker_remote_node,
f778fe
+        warn_on_communication_exception=warn_on_communication_exception,
f778fe
     )
f778fe
     env.report_processor.process_list(report_items)
f778fe
 
f778fe
@@ -88,7 +91,11 @@ def _prepare_pacemaker_remote_environment(
f778fe
         return
f778fe
 
f778fe
     candidate_node = NodeAddresses(node_host)
f778fe
-    _ensure_can_add_node_to_remote_cluster(env, candidate_node)
f778fe
+    _ensure_can_add_node_to_remote_cluster(
f778fe
+        env,
f778fe
+        candidate_node,
f778fe
+        allow_incomplete_distribution
f778fe
+    )
f778fe
     _share_authkey(
f778fe
         env,
f778fe
         current_nodes,
f778fe
@@ -296,17 +303,13 @@ def _find_resources_to_remove(
f778fe
 
f778fe
     return resource_element_list
f778fe
 
f778fe
-def _remove_pcmk_remote_from_cib(
f778fe
-    nodes, resource_element_list, get_host, remove_resource
f778fe
-):
f778fe
+def _get_node_addresses_from_resources(nodes, resource_element_list, get_host):
f778fe
     node_addresses_set = set()
f778fe
     for resource_element in resource_element_list:
f778fe
         for node in nodes:
f778fe
             #remote nodes uses ring0 only
f778fe
             if get_host(resource_element) == node.ring0:
f778fe
                 node_addresses_set.add(node)
f778fe
-        remove_resource(resource_element)
f778fe
-
f778fe
     return sorted(node_addresses_set, key=lambda node: node.ring0)
f778fe
 
f778fe
 def _destroy_pcmk_remote_env(env, node_addresses_list, allow_fails):
f778fe
@@ -382,28 +385,31 @@ def node_remove_remote(
f778fe
         allow_remove_multiple_nodes,
f778fe
         remote_node.find_node_resources,
f778fe
     )
f778fe
-    node_addresses_list = _remove_pcmk_remote_from_cib(
f778fe
+
f778fe
+    node_addresses_list = _get_node_addresses_from_resources(
f778fe
         get_nodes_remote(cib),
f778fe
         resource_element_list,
f778fe
         remote_node.get_host,
f778fe
-        lambda resource_element: remove_resource(
f778fe
-            resource_element.attrib["id"],
f778fe
-            is_remove_remote_context=True,
f778fe
-        )
f778fe
     )
f778fe
+
f778fe
     if not env.is_corosync_conf_live:
f778fe
         env.report_processor.process_list(
f778fe
             _report_skip_live_parts_in_remove(node_addresses_list)
f778fe
         )
f778fe
-        return
f778fe
+    else:
f778fe
+        _destroy_pcmk_remote_env(
f778fe
+            env,
f778fe
+            node_addresses_list,
f778fe
+            allow_pacemaker_remote_service_fail
f778fe
+        )
f778fe
 
f778fe
     #remove node from pcmk caches is currently integrated in remove_resource
f778fe
     #function
f778fe
-    _destroy_pcmk_remote_env(
f778fe
-        env,
f778fe
-        node_addresses_list,
f778fe
-        allow_pacemaker_remote_service_fail
f778fe
-    )
f778fe
+    for resource_element in resource_element_list:
f778fe
+        remove_resource(
f778fe
+            resource_element.attrib["id"],
f778fe
+            is_remove_remote_context=True,
f778fe
+        )
f778fe
 
f778fe
 def node_remove_guest(
f778fe
     env, node_identifier,
f778fe
@@ -435,29 +441,32 @@ def node_remove_guest(
f778fe
         guest_node.find_node_resources,
f778fe
     )
f778fe
 
f778fe
-    node_addresses_list =  _remove_pcmk_remote_from_cib(
f778fe
+    node_addresses_list = _get_node_addresses_from_resources(
f778fe
         get_nodes_guest(cib),
f778fe
         resource_element_list,
f778fe
         guest_node.get_host,
f778fe
-        guest_node.unset_guest,
f778fe
     )
f778fe
-    env.push_cib(cib, wait)
f778fe
 
f778fe
     if not env.is_corosync_conf_live:
f778fe
         env.report_processor.process_list(
f778fe
             _report_skip_live_parts_in_remove(node_addresses_list)
f778fe
         )
f778fe
-        return
f778fe
+    else:
f778fe
+        _destroy_pcmk_remote_env(
f778fe
+            env,
f778fe
+            node_addresses_list,
f778fe
+            allow_pacemaker_remote_service_fail
f778fe
+        )
f778fe
+
f778fe
+    for resource_element in resource_element_list:
f778fe
+        guest_node.unset_guest(resource_element)
f778fe
+
f778fe
+    env.push_cib(cib, wait)
f778fe
 
f778fe
     #remove node from pcmk caches
f778fe
     for node_addresses in node_addresses_list:
f778fe
         remove_node(env.cmd_runner(), node_addresses.name)
f778fe
 
f778fe
-    _destroy_pcmk_remote_env(
f778fe
-        env,
f778fe
-        node_addresses_list,
f778fe
-        allow_pacemaker_remote_service_fail
f778fe
-    )
f778fe
 
f778fe
 def node_clear(env, node_name, allow_clear_cluster_node=False):
f778fe
     """
f778fe
diff --git a/pcs/lib/nodes_task.py b/pcs/lib/nodes_task.py
f778fe
index 703609b..6086c4b 100644
f778fe
--- a/pcs/lib/nodes_task.py
f778fe
+++ b/pcs/lib/nodes_task.py
f778fe
@@ -277,7 +277,8 @@ def availability_checker_remote_node(
f778fe
 
f778fe
 def check_can_add_node_to_cluster(
f778fe
     node_communicator, node, report_items,
f778fe
-    check_response=availability_checker_node
f778fe
+    check_response=availability_checker_node,
f778fe
+    warn_on_communication_exception=False,
f778fe
 ):
f778fe
     """
f778fe
     Analyze result of node_available check if it is possible use the node as
f778fe
@@ -294,13 +295,21 @@ def check_can_add_node_to_cluster(
f778fe
         node_communicator,
f778fe
         node,
f778fe
         "remote/node_available",
f778fe
-        safe_report_items
f778fe
+        safe_report_items,
f778fe
+        warn_on_communication_exception=warn_on_communication_exception
f778fe
     )
f778fe
     report_items.extend(safe_report_items)
f778fe
 
f778fe
     if ReportListAnalyzer(safe_report_items).error_list:
f778fe
         return
f778fe
 
f778fe
+    #If there was a communication error and --skip-offline is in effect, no
f778fe
+    #exception was raised. If there is no result cannot process it.
f778fe
+    #Note: the error may be caused by older pcsd daemon not supporting commands
f778fe
+    #sent by newer client.
f778fe
+    if not availability_info:
f778fe
+        return
f778fe
+
f778fe
     is_in_expected_format = (
f778fe
         isinstance(availability_info, dict)
f778fe
         and
f778fe
diff --git a/pcs/lib/test/test_nodes_task.py b/pcs/lib/test/test_nodes_task.py
f778fe
index 61ba132..5459337 100644
f778fe
--- a/pcs/lib/test/test_nodes_task.py
f778fe
+++ b/pcs/lib/test/test_nodes_task.py
f778fe
@@ -790,10 +790,6 @@ class CheckCanAddNodeToCluster(TestCase):
f778fe
     def test_report_no_dict_in_json_response(self):
f778fe
         self.assert_result_causes_invalid_format("bad answer")
f778fe
 
f778fe
-    def test_report_dict_without_mandatory_key(self):
f778fe
-        self.assert_result_causes_invalid_format({})
f778fe
-
f778fe
-
f778fe
 class OnNodeTest(TestCase):
f778fe
     def setUp(self):
f778fe
         self.reporter = MockLibraryReportProcessor()
f778fe
diff --git a/pcs/test/test_cluster_pcmk_remote.py b/pcs/test/test_cluster_pcmk_remote.py
f778fe
index 5dc1633..0db4a5c 100644
f778fe
--- a/pcs/test/test_cluster_pcmk_remote.py
f778fe
+++ b/pcs/test/test_cluster_pcmk_remote.py
f778fe
@@ -399,11 +399,11 @@ class NodeRemoveRemote(ResourceTest):
f778fe
         self.assert_effect(
f778fe
             "cluster node remove-remote NODE-HOST",
f778fe
             "<resources/>",
f778fe
-            outdent(
f778fe
+            fixture_nolive_remove_report(["NODE-HOST"]) + outdent(
f778fe
                 """\
f778fe
                 Deleting Resource - NODE-NAME
f778fe
                 """
f778fe
-            ) + fixture_nolive_remove_report(["NODE-HOST"])
f778fe
+            )
f778fe
         )
f778fe
 
f778fe
     def test_success_remove_by_node_name(self):
f778fe
@@ -411,11 +411,11 @@ class NodeRemoveRemote(ResourceTest):
f778fe
         self.assert_effect(
f778fe
             "cluster node remove-remote NODE-NAME",
f778fe
             "<resources/>",
f778fe
-            outdent(
f778fe
+            fixture_nolive_remove_report(["NODE-HOST"]) + outdent(
f778fe
                 """\
f778fe
                 Deleting Resource - NODE-NAME
f778fe
                 """
f778fe
-            ) + fixture_nolive_remove_report(["NODE-HOST"])
f778fe
+            )
f778fe
         )
f778fe
 
f778fe
     def test_refuse_on_duplicit(self):
f778fe
@@ -431,13 +431,17 @@ class NodeRemoveRemote(ResourceTest):
f778fe
         self.assert_effect(
f778fe
             "cluster node remove-remote HOST-A --force",
f778fe
             "<resources/>",
f778fe
+
f778fe
+            "Warning: multiple resource for 'HOST-A' found: 'HOST-A', 'NODE-NAME'\n"
f778fe
+            +
f778fe
+            fixture_nolive_remove_report(["HOST-A", "HOST-B"])
f778fe
+            +
f778fe
             outdent(
f778fe
                 """\
f778fe
-                Warning: multiple resource for 'HOST-A' found: 'HOST-A', 'NODE-NAME'
f778fe
                 Deleting Resource - NODE-NAME
f778fe
                 Deleting Resource - HOST-A
f778fe
                 """
f778fe
-            ) + fixture_nolive_remove_report(["HOST-A", "HOST-B"])
f778fe
+            )
f778fe
         )
f778fe
 
f778fe
 class NodeRemoveGuest(ResourceTest):
f778fe
-- 
f778fe
1.8.3.1
f778fe