Blame SOURCES/bz1386114-02-deal-with-f-corosync_conf-if-create-remote-res.patch

f778fe
From 698f63f743aa970b4af977e4a410e64ee7013fa4 Mon Sep 17 00:00:00 2001
f778fe
From: Ivan Devat <idevat@redhat.com>
f778fe
Date: Tue, 30 May 2017 17:00:41 +0200
f778fe
Subject: [PATCH] deal with -f/--corosync_conf if create remote res.
f778fe
f778fe
Do not request corosync.conf when `pcs resource create` with -f is used
f778fe
for create remote (ocf:pacemaker:remote) or guest (meta remote-node).
f778fe
---
f778fe
 pcs/cli/common/lib_wrapper.py |  6 ++-
f778fe
 pcs/lib/commands/resource.py  | 90 ++++++++++++++++++++++++++++---------------
f778fe
 pcs/resource.py               | 13 +++++--
f778fe
 3 files changed, 74 insertions(+), 35 deletions(-)
f778fe
f778fe
diff --git a/pcs/cli/common/lib_wrapper.py b/pcs/cli/common/lib_wrapper.py
f778fe
index 683ba4d..4d6ed9a 100644
f778fe
--- a/pcs/cli/common/lib_wrapper.py
f778fe
+++ b/pcs/cli/common/lib_wrapper.py
f778fe
@@ -318,7 +318,8 @@ def load_module(env, middleware_factory, name):
f778fe
         return bind_all(
f778fe
             env,
f778fe
             middleware.build(
f778fe
-                middleware_factory.cib
f778fe
+                middleware_factory.cib,
f778fe
+                middleware_factory.corosync_conf_existing,
f778fe
             ),
f778fe
             {
f778fe
                 "bundle_create": resource.bundle_create,
f778fe
@@ -338,7 +339,8 @@ def load_module(env, middleware_factory, name):
f778fe
         return bind_all(
f778fe
             env,
f778fe
             middleware.build(
f778fe
-                middleware_factory.cib
f778fe
+                middleware_factory.cib,
f778fe
+                middleware_factory.corosync_conf_existing,
f778fe
             ),
f778fe
             {
f778fe
                 "create": stonith.create,
f778fe
diff --git a/pcs/lib/commands/resource.py b/pcs/lib/commands/resource.py
f778fe
index a9f8271..3a060b8 100644
f778fe
--- a/pcs/lib/commands/resource.py
f778fe
+++ b/pcs/lib/commands/resource.py
f778fe
@@ -46,8 +46,12 @@ def resource_environment(
f778fe
         ])
f778fe
 
f778fe
 def _validate_remote_connection(
f778fe
-    nodes, resource_id, instance_attributes,  allow_not_suitable_command
f778fe
+    resource_agent, nodes_to_validate_against, resource_id, instance_attributes,
f778fe
+    allow_not_suitable_command
f778fe
 ):
f778fe
+    if resource_agent.get_name() != remote_node.AGENT_NAME.full_name:
f778fe
+        return []
f778fe
+
f778fe
     report_list = []
f778fe
     report_list.append(
f778fe
         reports.get_problem_creator(
f778fe
@@ -58,7 +62,7 @@ def _validate_remote_connection(
f778fe
 
f778fe
     report_list.extend(
f778fe
         remote_node.validate_host_not_conflicts(
f778fe
-            nodes,
f778fe
+            nodes_to_validate_against,
f778fe
             resource_id,
f778fe
             instance_attributes
f778fe
         )
f778fe
@@ -66,8 +70,8 @@ def _validate_remote_connection(
f778fe
     return report_list
f778fe
 
f778fe
 def _validate_guest_change(
f778fe
-    tree, nodes, meta_attributes, allow_not_suitable_command,
f778fe
-    detect_remove=False
f778fe
+    tree, nodes_to_validate_against, meta_attributes,
f778fe
+    allow_not_suitable_command, detect_remove=False
f778fe
 ):
f778fe
     if not guest_node.is_node_name_in_options(meta_attributes):
f778fe
         return []
f778fe
@@ -89,7 +93,7 @@ def _validate_guest_change(
f778fe
     report_list.extend(
f778fe
         guest_node.validate_conflicts(
f778fe
             tree,
f778fe
-            nodes,
f778fe
+            nodes_to_validate_against,
f778fe
             node_name,
f778fe
             meta_attributes
f778fe
         )
f778fe
@@ -97,28 +101,54 @@ def _validate_guest_change(
f778fe
 
f778fe
     return report_list
f778fe
 
f778fe
-def _validate_special_cases(
f778fe
-    nodes, resource_agent, resources_section, resource_id, meta_attributes,
f778fe
+def _get_nodes_to_validate_against(env, tree):
f778fe
+    if not env.is_corosync_conf_live and env.is_cib_live:
f778fe
+        raise LibraryError(
f778fe
+            reports.live_environment_required(["COROSYNC_CONF"])
f778fe
+        )
f778fe
+
f778fe
+    if not env.is_cib_live and env.is_corosync_conf_live:
f778fe
+        #we do not try to get corosync.conf from live cluster when cib is not
f778fe
+        #taken from live cluster
f778fe
+        return get_nodes(tree=tree)
f778fe
+
f778fe
+    return get_nodes(env.get_corosync_conf(), tree)
f778fe
+
f778fe
+
f778fe
+def _check_special_cases(
f778fe
+    env, resource_agent, resources_section, resource_id, meta_attributes,
f778fe
     instance_attributes, allow_not_suitable_command
f778fe
 ):
f778fe
-    report_list = []
f778fe
-
f778fe
-    if resource_agent.get_name() == remote_node.AGENT_NAME.full_name:
f778fe
-        report_list.extend(_validate_remote_connection(
f778fe
-            nodes,
f778fe
-            resource_id,
f778fe
-            instance_attributes,
f778fe
-            allow_not_suitable_command,
f778fe
-        ))
f778fe
+    if(
f778fe
+        resource_agent.get_name() != remote_node.AGENT_NAME.full_name
f778fe
+        and
f778fe
+        not guest_node.is_node_name_in_options(meta_attributes)
f778fe
+    ):
f778fe
+        #if no special case happens we won't take care about corosync.conf that
f778fe
+        #is needed for getting nodes to validate against
f778fe
+        return
f778fe
+
f778fe
+    nodes_to_validate_against = _get_nodes_to_validate_against(
f778fe
+        env,
f778fe
+        resources_section
f778fe
+    )
f778fe
 
f778fe
+    report_list = []
f778fe
+    report_list.extend(_validate_remote_connection(
f778fe
+        resource_agent,
f778fe
+        nodes_to_validate_against,
f778fe
+        resource_id,
f778fe
+        instance_attributes,
f778fe
+        allow_not_suitable_command,
f778fe
+    ))
f778fe
     report_list.extend(_validate_guest_change(
f778fe
         resources_section,
f778fe
-        nodes,
f778fe
+        nodes_to_validate_against,
f778fe
         meta_attributes,
f778fe
         allow_not_suitable_command,
f778fe
     ))
f778fe
 
f778fe
-    return report_list
f778fe
+    env.report_processor.process_list(report_list)
f778fe
 
f778fe
 def create(
f778fe
     env, resource_id, resource_agent_name,
f778fe
@@ -167,15 +197,15 @@ def create(
f778fe
         [resource_id],
f778fe
         ensure_disabled or resource.common.are_meta_disabled(meta_attributes),
f778fe
     ) as resources_section:
f778fe
-        env.report_processor.process_list(_validate_special_cases(
f778fe
-            get_nodes(env.get_corosync_conf(), resources_section),
f778fe
+        _check_special_cases(
f778fe
+            env,
f778fe
             resource_agent,
f778fe
             resources_section,
f778fe
             resource_id,
f778fe
             meta_attributes,
f778fe
             instance_attributes,
f778fe
             allow_not_suitable_command
f778fe
-        ))
f778fe
+        )
f778fe
 
f778fe
         primitive_element = resource.primitive.create(
f778fe
             env.report_processor, resources_section,
f778fe
@@ -247,15 +277,15 @@ def _create_as_clone_common(
f778fe
             resource.common.is_clone_deactivated_by_meta(clone_meta_options)
f778fe
         )
f778fe
     ) as resources_section:
f778fe
-        env.report_processor.process_list(_validate_special_cases(
f778fe
-            get_nodes(env.get_corosync_conf(), resources_section),
f778fe
+        _check_special_cases(
f778fe
+            env,
f778fe
             resource_agent,
f778fe
             resources_section,
f778fe
             resource_id,
f778fe
             meta_attributes,
f778fe
             instance_attributes,
f778fe
             allow_not_suitable_command
f778fe
-        ))
f778fe
+        )
f778fe
 
f778fe
         primitive_element = resource.primitive.create(
f778fe
             env.report_processor, resources_section,
f778fe
@@ -325,15 +355,15 @@ def create_in_group(
f778fe
         [resource_id],
f778fe
         ensure_disabled or resource.common.are_meta_disabled(meta_attributes),
f778fe
     ) as resources_section:
f778fe
-        env.report_processor.process_list(_validate_special_cases(
f778fe
-            get_nodes(env.get_corosync_conf(), resources_section),
f778fe
+        _check_special_cases(
f778fe
+            env,
f778fe
             resource_agent,
f778fe
             resources_section,
f778fe
             resource_id,
f778fe
             meta_attributes,
f778fe
             instance_attributes,
f778fe
             allow_not_suitable_command
f778fe
-        ))
f778fe
+        )
f778fe
 
f778fe
         primitive_element = resource.primitive.create(
f778fe
             env.report_processor, resources_section,
f778fe
@@ -406,15 +436,15 @@ def create_into_bundle(
f778fe
         disabled_after_wait=ensure_disabled,
f778fe
         required_cib_version=(2, 8, 0)
f778fe
     ) as resources_section:
f778fe
-        env.report_processor.process_list(_validate_special_cases(
f778fe
-            get_nodes(env.get_corosync_conf(), resources_section),
f778fe
+        _check_special_cases(
f778fe
+            env,
f778fe
             resource_agent,
f778fe
             resources_section,
f778fe
             resource_id,
f778fe
             meta_attributes,
f778fe
             instance_attributes,
f778fe
             allow_not_suitable_command
f778fe
-        ))
f778fe
+        )
f778fe
 
f778fe
         primitive_element = resource.primitive.create(
f778fe
             env.report_processor, resources_section,
f778fe
diff --git a/pcs/resource.py b/pcs/resource.py
f778fe
index 4d5f43a..dc6da13 100644
f778fe
--- a/pcs/resource.py
f778fe
+++ b/pcs/resource.py
f778fe
@@ -28,24 +28,31 @@ from pcs.cli.resource.parse_args import (
f778fe
     parse_bundle_update_options,
f778fe
     parse_create as parse_create_args,
f778fe
 )
f778fe
-from pcs.lib.env_tools import get_nodes
f778fe
 from pcs.lib.errors import LibraryError
f778fe
+from pcs.lib.cib.resource import guest_node
f778fe
 import pcs.lib.pacemaker.live as lib_pacemaker
f778fe
 from pcs.lib.pacemaker.values import timeout_to_seconds
f778fe
 import pcs.lib.resource_agent as lib_ra
f778fe
 from pcs.cli.common.console_report import error, warn
f778fe
-from pcs.lib.commands.resource import _validate_guest_change
f778fe
+from pcs.lib.commands.resource import(
f778fe
+    _validate_guest_change,
f778fe
+    _get_nodes_to_validate_against,
f778fe
+)
f778fe
 
f778fe
 
f778fe
 RESOURCE_RELOCATE_CONSTRAINT_PREFIX = "pcs-relocate-"
f778fe
 
f778fe
 def _detect_guest_change(meta_attributes, allow_not_suitable_command):
f778fe
+    if not guest_node.is_node_name_in_options(meta_attributes):
f778fe
+        return
f778fe
+
f778fe
     env = utils.get_lib_env()
f778fe
     cib = env.get_cib()
f778fe
+    nodes_to_validate_against = _get_nodes_to_validate_against(env, cib)
f778fe
     env.report_processor.process_list(
f778fe
         _validate_guest_change(
f778fe
             cib,
f778fe
-            get_nodes(env.get_corosync_conf(), cib),
f778fe
+            nodes_to_validate_against,
f778fe
             meta_attributes,
f778fe
             allow_not_suitable_command,
f778fe
             detect_remove=True,
f778fe
-- 
f778fe
1.8.3.1
f778fe