Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default template to add custom attributes #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@ suites:
multipath:
storage_type: "purestorage"
aliases: [ "mysql:3624a937017bcaa64842651bf00015fea" ]
- name: customized
run_list:
- recipe[multipath::default]
attributes:
multipath:
storage_type: "customized"
defaults:
queue_without_daemon: "no"
max_fds: "max"
devices:
OPEN-d*:
vendor: "\"HP\""
path_grouping_policy: "multibus"
rr_min_io: 1000
HSV200:
vendor: "\"HP\""
path_grouping_policy: "group_by_prio"
rr_min_io: 100
Invista:
vendor: "\"EMC\""
path_grouping_policy: "multibus"
product_blacklist: "\"LUNZ\""
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This cookbook provides provides the ability to configure Device Mapper
Multipath MPIO for Fibre-Channel and iSCSI storage attached systems.

A generic template, as well as four vendor-specific templates are included
A generic template, a customizable template, as well as four vendor-specific templates are included
within this cookbook. Included vendor-specific templates are for
Equallogic iSCSI, EMC Clariion, Dell Powervault MDxxxx and PureStorage
storage arrays.
Expand All @@ -25,7 +25,42 @@ storage arrays.
- ["blacklist_regex"]: An array of regular expressions to blacklist. Default '^sd[a]$'
- ["blacklist_wwid"]: An array of World-Wide Identifiers (WWID) to blacklist. Default empty.
- ["aliases"]: A colon separated mapping of WWID to assign a friendly name. Default empty.
- ["storage_type"]: Select a vendor-specific multipath template (equallogic, powervault, clariion, default)
- ["storage_type"]: Select a vendor-specific multipath template (equallogic, powervault, clariion, default, customized)

#### Using the "customized" storage_type

When setting ["storage_type"] = "customized", the following attributes come into play for the multipath.conf template:

Default Attributes

* multipath (namespace)
- ["defaults"]["user_friendly_names"] = "yes"
- use the bindings file to assign a persistent and unique alias to the multipath)
- ["defaults"]["find_multipaths"] = "yes"
- multipath will only create a device if conditions are met. See multipath man page for more detail)

Additional custom attributes can be added to the default and devices sections with the following format:

* multipath (namespace)
- ["defaults"]["parameter"]: Adds multipath parameter to defaults section of multipath.conf
- ["devices"]["product name"]["parameter"]: Adds multipath parameter to devices section of multipath.conf

Note: A valid device entry requires a product value, a vendor value, and one multipath parameter. (The product value in the below example is "HSV200")

Example:

```json
"normal": {
"multipath": {
"default": {
"queue_without_daemon": "no" },
"devices": {
"HSV200": {
"vendor": "\"HP\"",
"path_grouping_policy": "multibus"
} } }
}
```

## Usage

Expand Down
4 changes: 4 additions & 0 deletions attributes/customized-multipath.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if node['multipath']['storage_type'] == "customized"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to put this inside of a hash rather than using the if matching here.

ex:

default['multipath']['customized']['defaults']

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic was left-over from a previous iteration I had and I forgot to remove it. I think it would suffice to just remove the logic, don't you?

default['multipath']['defaults']['user_friendly_names'] = "yes"
default['multipath']['defaults']['find_multipaths'] = "yes"
end
43 changes: 43 additions & 0 deletions templates/default/customized-multipath.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Template dropped by Chef for <%= node["fqdn"] %>
# Local modifications will be overwritten

defaults {
<% node["multipath"]["defaults"].each do |param,param_value| -%>
<%= param %> <%= param_value %>
<% end -%>
}

blacklist {
<% node["multipath"]["blacklist_wwid"].each do |bl_wwid| -%>
wwid <%= bl_wwid %>
<% end -%>
<% node["multipath"]["blacklist_regex"].each do |bl_device| -%>
devnode "<%= bl_device %>"
<% end -%>
devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
devnode "^hd[a-z][[0-9]*]"
devnode "^cciss!c[0-9]d[0-9]*[p[0-9]*]"
}

<% unless node["multipath"]["aliases"].empty? -%>
multipaths {
<% node["multipath"]["aliases"].each do |alias_def| -%>
<% alias_arr = alias_def.split(/:/) -%>
multipath {
wwid <%= alias_arr[1] %>
alias <%= alias_arr[0] %>
}
<% end -%>
}
<% end -%>

devices {
<% node["multipath"]["devices"].each do |product,parameters| %>
device {
product "<%= product %>"
<% parameters.each do |param,param_value| %>
<%= param %> <%= param_value %>
<% end -%>
}
<% end -%>
}
65 changes: 65 additions & 0 deletions test/integration/customized/bats/default.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bats

@test 'multipath configuration sets default user_friendly_names to yes' {
grep -A 1 "defaults {" /etc/multipath.conf |grep "user_friendly_names yes"
}

@test 'multipath configuration sets default find_multipaths to yes' {
grep -A 2 "defaults {" /etc/multipath.conf |grep "find_multipaths yes"
}

@test 'multipath configuration sets default queue_without_daemon to no' {
grep -A 3 "defaults {" /etc/multipath.conf |grep "queue_without_daemon no"
}

@test 'multipath configuration sets default max_fds to max' {
grep -A 4 "defaults {" /etc/multipath.conf |grep "max_fds max"
}

@test 'multipath configuration sets device product to OPEN-d*' {
grep -A 4 "device {" /etc/multipath.conf |grep "product[[:space:]][[:punct:]]OPEN-d"
}

@test 'multipath configuration sets OPEN-d* device vendor to HP' {
grep -A 4 "device {" /etc/multipath.conf |grep -A 1 "product[[:space:]][[:punct:]]OPEN-d" |grep "vendor[[:space:]][[:punct:]]HP"
}

@test 'multipath configuration sets OPEN-d* device path_grouping_policy to multibus' {
grep -A 4 "device {" /etc/multipath.conf |grep -A 2 "product[[:space:]][[:punct:]]OPEN-d" |grep "path_grouping_policy[[:space:]]multibus"
}

@test 'multipath configuration sets OPEN-d* device rr_min_io to 1000' {
grep -A 4 "device {" /etc/multipath.conf |grep -A 3 "product[[:space:]][[:punct:]]OPEN-d" |grep "rr_min_io[[:space:]]1000\>"
}

@test 'multipath configuration sets device product to HSV200' {
grep -A 4 "device {" /etc/multipath.conf |grep "product[[:space:]][[:punct:]]HSV200"
}

@test 'multipath configuration sets HSV200 device vendor to HP' {
grep -A 4 "device {" /etc/multipath.conf |grep -A 1 "product[[:space:]][[:punct:]]HSV200" |grep "vendor[[:space:]][[:punct:]]HP"
}

@test 'multipath configuration sets HSV200 device path_grouping_policy to group_by_prio' {
grep -A 4 "device {" /etc/multipath.conf |grep -A 2 "product[[:space:]][[:punct:]]HSV200" |grep "path_grouping_policy[[:space:]]group_by_prio"
}

@test 'multipath configuration sets HSV200 device rr_min_io to 1000' {
grep -A 4 "device {" /etc/multipath.conf |grep -A 3 "product[[:space:]][[:punct:]]HSV200" |grep "rr_min_io[[:space:]]100\>"
}

@test 'multipath configuration sets device product to Invista' {
grep -A 4 "device {" /etc/multipath.conf |grep "product[[:space:]][[:punct:]]Invista"
}

@test 'multipath configuration sets Invista device vendor to EMC' {
grep -A 4 "device {" /etc/multipath.conf |grep -A 1 "product[[:space:]][[:punct:]]Invista" |grep "vendor[[:space:]][[:punct:]]EMC"
}

@test 'multipath configuration sets Invista device path_grouping_policy to multibus' {
grep -A 4 "device {" /etc/multipath.conf |grep -A 2 "product[[:space:]][[:punct:]]Invista" |grep "path_grouping_policy[[:space:]]multibus"
}

@test 'multipath configuration sets Invista device product_blacklist to LUNZ' {
grep -A 4 "device {" /etc/multipath.conf |grep -A 3 "product[[:space:]][[:punct:]]Invista" |grep "product_blacklist[[:space:]][[:punct:]]LUNZ\>"
}