From 54b85b0695a39283f57f34aa43bc606f03a2b153 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Sun, 4 Oct 2015 09:21:48 +0200 Subject: [PATCH] crowbar-pacemaker: Support String for ordering of order_only_existing It can be useful to have non-sequential sets of dependencies in crowbar_pacemaker_order_only_existing, so on top of supporting definition of ordering as Array, we also need support as String which lets us use the full syntax of crm. This requires some pseudo-parsing of the crm syntax to make sure we don't drop bits that shouldn't be dropped, but also to drop empty sets after non-existing resources have been removed. Backport of https://github.com/crowbar/crowbar-ha/pull/29 --- .../providers/order_only_existing.rb | 25 ++++++++++++++++++- .../resources/order_only_existing.rb | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/chef/cookbooks/crowbar-pacemaker/providers/order_only_existing.rb b/chef/cookbooks/crowbar-pacemaker/providers/order_only_existing.rb index 065d5d8f..f7adf3a7 100644 --- a/chef/cookbooks/crowbar-pacemaker/providers/order_only_existing.rb +++ b/chef/cookbooks/crowbar-pacemaker/providers/order_only_existing.rb @@ -24,10 +24,33 @@ def delete_order(name) end action :create do + ordering = new_resource.ordering # evil command line; there must be a better way to fetch the list of resources # unfortunately, "crm_resource --list-raw" doesn't list groups/clones/etc. all_resources = %x{crm --display=plain configure show | awk '/^(primitive|group|clone|ms)/ {print $2}'}.split("\n") - ordering_for_existing_resources = new_resource.ordering.select { |r| all_resources.include?(r) } + case ordering + when Array + ordering_for_existing_resources = ordering.select { |r| all_resources.include?(r) } + when String + # Try to ensure the syntax makes sense + raise "Sets in ordering cannot be nested." if ordering =~ /\([^\)]*[\(\[\]]/ || ordering =~ /\[[^\]]*[\[\(\)]/ + # Only keep valid items, including what's valid in the crm syntax, which + # is: + # - foo ( bar foobar ) xyz + # - foo [ bar foobar ] xyz + # - foo [ bar foobar sequantial=true ] xyz + # - foo [ bar foobar require-all=true ] xyz + ordering_array = ordering.split(" ") + existing_ordering_array = ordering_array.select do |r| + all_resources.include?(r) || %w{( ) [ ]}.include?(r) || r =~ /sequential=/ || r =~ /require-all=/ + end + # Drop empty sets; we don't want something like: + # order Mandatory: foo ( ) bar + # It should become: + # order Mandatory: foo bar + existing_ordering = existing_ordering_array.join(" ").gsub(/[\(\[](( sequential=[^ ]*)|( require-all=[^ ]*))* [\)\]]/, "") + ordering_for_existing_resources = existing_ordering.split(" ") + end if ordering_for_existing_resources.length <= 1 delete_order(new_resource.name) diff --git a/chef/cookbooks/crowbar-pacemaker/resources/order_only_existing.rb b/chef/cookbooks/crowbar-pacemaker/resources/order_only_existing.rb index fddd8ed0..809d7a49 100644 --- a/chef/cookbooks/crowbar-pacemaker/resources/order_only_existing.rb +++ b/chef/cookbooks/crowbar-pacemaker/resources/order_only_existing.rb @@ -48,3 +48,4 @@ attribute :name, :kind_of => String, :name_attribute => true attribute :score, :kind_of => String attribute :ordering, :kind_of => Array +attribute :ordering, :kind_of => [Array, String]