Skip to content

Commit

Permalink
updating and locking lvm to 3.0 (#55)
Browse files Browse the repository at this point in the history
* Update default.rb

* Update metadata.rb

* Update metadata.rb

* Added attribute for wipe_attributes to pass along to the lvm_volump_group resource

* Allow gem deps to vary within major version

This fixes this error, which was solved in newer versions of Ridley:
    An error occurred while reading the Berksfile:
      uninitialized constant Ridley::Mixin::ParamsValidate::ValidationFailed

https://travis-ci.org/rightscale-cookbooks/ephemeral_lvm/builds/125138768

* according to chai gce changed metadata
ephemeral drives have type "LOCAL-SSD" now

"gce": {
    "attached_disks": {
      "disks": [
        {
          "deviceName": "persistent-disk-0",
          "index": 0,
          "mode": "READ_WRITE",
          "type": "PERSISTENT"
        },
        {
          "deviceName": "local-ssd-0",
          "index": 1,
          "mode": "READ_WRITE",
          "type": "LOCAL-SSD"
        }
      ]
    },

* updated metadata and changeling

* updating to lvm-3.0

* additional try for wipefs as new version supports -f flag

* fix deprecation warning, using allow instead of should_receive

* chef 12 migration

* updating travis

* updating net-persistent-http

* fixing versions

* updating from skeleton for tests

* adding gitignore

* updating for cookstyle

* removing berksfile.lock

* adding .travis_install.sh

* removing centos7.0

* removing apt

* updating ruby-version

* updating rakefile and travis

* pinning Berksfile.lock

* updating readme to chef12

* using pipmychangelog

* fixes #57

* updating lvm to 4.0.5

* updating changelog

* reverting to 3.1.0, since 4.0.x has breaking changes
  • Loading branch information
rshade committed Jan 25, 2017
1 parent 959b9a1 commit cad6e3f
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 37 deletions.
12 changes: 3 additions & 9 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ AllCops:
Exclude:
- 'berks-cookbooks/**/*'
- 'knife.rb'
Style/AccessorMethodName:
Exclude:
- 'Rakefile'
Metrics/BlockNesting:
Exclude:
- 'libraries/helper.rb'
Style/GuardClause:
Exclude:
- 'test/cookbooks/fake/recipes/gce.rb'
#Metrics/BlockNesting:
# Exclude:
# - 'libraries/helper.rb'
1 change: 1 addition & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
source 'https://supermarket.chef.io'

metadata
Expand Down
6 changes: 4 additions & 2 deletions Berksfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ DEPENDENCIES
path: test/cookbooks/fake

GRAPH
ephemeral_lvm (2.0.0)
lvm (~> 3.1)
ephemeral_lvm (2.1.0)
lvm (~> 3.1.0)
now (>= 0.0.0)
fake (0.1.0)
lvm (3.1.0)
now (1.0.0)
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ ephemeral_lvm Cookbook CHANGELOG

This file is used to list changes made in each version of the ephemeral_lvm cookbook.

v2.1.0
------
- [lvm-3.1.0](https://github.com/chef-cookbooks/lvm/releases/tag/v3.1.0)
- Pull Request [#50][]: fixed detection for gce ephemeral device type "LOCAL-SSD" ([@areznikov-kabam][])
- Pull Request [#48][]: Wipe Signatures ([@kingpong][])
- Pull Request [#46][]: Added attribute for wipe_attributes to pass along to the lvm_volump_group ([@freimer][])
- Pull Request [#33][]: Using include_recipe_now technic to allow compile time lvm2 package run ([@felka][])

v2.0.1
-------
- addressed GCE "LOCAL-SSD" type for ephemeral drives

v2.0.0
-------

Expand Down Expand Up @@ -113,7 +125,15 @@ v1.0.0
[#11]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/11
[#13]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/13
[#19]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/19
[#33]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/33
[#46]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/46
[#48]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/48
[#50]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/50
[#54]: https://github.com/rightscale-cookbooks/ephemeral_lvm/issues/54
[@areznikov-kabam]: https://github.com/areznikov-kabam
[@autrejacoupa]: https://github.com/autrejacoupa
[@drywheat]: https://github.com/drywheat
[@felka]: https://github.com/felka
[@freimer]: https://github.com/freimer
[@juliandunn]: https://github.com/juliandunn
[@kingpong]: https://github.com/kingpong
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
source 'https://rubygems.org'

gem 'rake'
Expand Down
1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# -*- mode: ruby -*-
# vi: set ft=ruby :

Expand Down
4 changes: 4 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: ephemeral_lvm
# Attributes:: default
Expand Down Expand Up @@ -42,3 +43,6 @@

# The stripe size in kilobytes to be used if more than one ephemeral disk is found
default['ephemeral_lvm']['stripe_size'] = 512

# Whether to wipe signatures on any existing drives
default['ephemeral_lvm']['wipe_signatures'] = false
46 changes: 28 additions & 18 deletions libraries/helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: ephemeral_lvm
# Library:: helper
Expand All @@ -24,7 +25,33 @@ module Helper
#
# @param cloud [String] the name of cloud
# @param node [Chef::Node] the Chef node
def self.gce_ephemeral_devices?(cloud, node)
# According to the GCE documentation, the instances have links for ephemeral disks as
# /dev/disk/by-id/google-ephemeral-disk-*. Refer to
# https://developers.google.com/compute/docs/disks#scratchdisks for more information.
#
ephemeral_devices = node[cloud]['attached_disks']['disks'].map do |disk|
if ((disk['type'] == 'EPHEMERAL') || (disk['type'] == 'LOCAL-SSD')) && disk['deviceName'].match(/^local-ssd-\d+$/)
"/dev/disk/by-id/google-#{disk['deviceName']}"
end
end unless node[cloud]['attached_disks'].nil?

ephemeral_devices = node[cloud]['instance']['disks'].map do |disk|
if disk['type'] == 'LOCAL-SSD' && disk['deviceName'].match(/^local-ssd-\d+$/)
"/dev/disk/by-id/google-#{disk['deviceName']}"
end
end unless node[cloud]['instance'].nil?

# Removes nil elements from the ephemeral_devices array if any.
ephemeral_devices.compact!
ephemeral_devices
end

# Identifies the ephemeral devices available on a cloud server based on cloud-specific Ohai data and returns
# them as an array. This method also does the mapping required for Xen hypervisors (/dev/sdX -> /dev/xvdX).
#
# @param cloud [String] the name of cloud
# @param node [Chef::Node] the Chef node
# @return [Array<String>] list of ephemeral available ephemeral devices.
#
def self.get_ephemeral_devices(cloud, node)
Expand Down Expand Up @@ -58,24 +85,7 @@ def self.get_ephemeral_devices(cloud, node)
#
case cloud
when 'gce'
# According to the GCE documentation, the instances have links for ephemeral disks as
# /dev/disk/by-id/google-ephemeral-disk-*. Refer to
# https://developers.google.com/compute/docs/disks#scratchdisks for more information.
#
ephemeral_devices = node[cloud]['attached_disks']['disks'].map do |disk|
if disk['type'] == 'EPHEMERAL' && disk['deviceName'].match(/^local-ssd-\d+$/)
"/dev/disk/by-id/google-#{disk['deviceName']}"
end
end unless node[cloud]['attached_disks'].nil?

ephemeral_devices = node[cloud]['instance']['disks'].map do |disk|
if disk['type'] == 'LOCAL-SSD' && disk['deviceName'].match(/^local-ssd-\d+$/)
"/dev/disk/by-id/google-#{disk['deviceName']}"
end
end unless node[cloud]['instance'].nil?

# Removes nil elements from the ephemeral_devices array if any.
ephemeral_devices.compact!
ephemeral_devices = gce_ephemeral_devices?(cloud, node)
else
Chef::Log.info 'No ephemeral disks found.'
end
Expand Down
13 changes: 11 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true
name 'ephemeral_lvm'
maintainer 'RightScale, Inc.'
maintainer_email '[email protected]'
license 'Apache 2.0'
description 'Configures available ephemeral devices on a cloud server'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '2.0.0'
version '2.1.0'
issues_url 'https://github.com/rightscale-cookbooks/ephemeral_lvm/issues' if respond_to?(:issues_url)
source_url 'https://github.com/rightscale-cookbooks/ephemeral_lvm' if respond_to?(:source_url)
chef_version '>= 12.0' if respond_to?(:chef_version)
Expand All @@ -13,7 +14,8 @@
supports 'centos'
supports 'debian'

depends 'lvm', '~> 3.1'
depends 'now'
depends 'lvm', '~> 3.1.0'

recipe 'ephemeral_lvm::default', 'Sets up ephemeral devices on a cloud server'

Expand Down Expand Up @@ -66,3 +68,10 @@
default: '512',
recipes: ['ephemeral_lvm::default'],
required: 'optional'

attribute 'ephemeral_lvm/wipe_signatures',
display_name: 'Ephemeral LVM Wire Signatures',
description: 'Whether to wipe any existing filesystem signatures',
default: false,
recipes: ['ephemeral_lvm::default'],
required: 'optional'
6 changes: 5 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: ephemeral_lvm
# Recipe:: default
Expand All @@ -19,7 +20,7 @@

# Include the lvm::default recipe which sets up the resources/providers for lvm
#
include_recipe 'lvm'
include_recipe_now 'lvm'

if !node.attribute?('cloud') || !node['cloud'].attribute?('provider') || !node.attribute?(node['cloud']['provider'])
log 'Not running on a known cloud, not setting up ephemeral LVM'
Expand All @@ -46,6 +47,7 @@
ephemeral_devices.each do |ephemeral_device|
Chef::Log.info "Preparing #{ephemeral_device}"
Mixlib::ShellOut.new("wipefs --all #{ephemeral_device}").run_command
Mixlib::ShellOut.new("wipefs --all -f #{ephemeral_device}").run_command
end
else
Chef::Log.info 'No need to remove ephemeral disk filesystem signatures.'
Expand All @@ -57,6 +59,8 @@
# they are created with LVM stripes with the stripe size set in the attributes.
#
lvm_volume_group node['ephemeral_lvm']['volume_group_name'] do
wipe_signatures node['ephemeral_lvm']['wipe_signatures']

physical_volumes ephemeral_devices

logical_volume node['ephemeral_lvm']['logical_volume_name'] do
Expand Down
1 change: 1 addition & 0 deletions spec/ephemeral_lvm_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative 'spec_helper'
require_relative '../libraries/helper'
require 'logger'
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: ephemeral_lvm
# Spec:: spec_helper
Expand Down
1 change: 1 addition & 0 deletions test/cookbooks/fake/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: fake
# Attributes:: default
Expand Down
1 change: 1 addition & 0 deletions test/cookbooks/fake/libraries/helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: fake
# Library:: helper
Expand Down
1 change: 1 addition & 0 deletions test/cookbooks/fake/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
name 'fake'
maintainer 'RightScale, Inc.'
maintainer_email '[email protected]'
Expand Down
1 change: 1 addition & 0 deletions test/cookbooks/fake/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: fake
# Recipe:: default
Expand Down
8 changes: 3 additions & 5 deletions test/cookbooks/fake/recipes/gce.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: fake
# Recipe:: gce
Expand Down Expand Up @@ -26,11 +27,8 @@
#
node['fake']['devices'].each do |device|
match = device.match(%{\/dev\/loop(\d+)})
if match.nil?
next
else
device_index = match[1]
end
next if match.nil?
device_index = match[1]
link "/dev/disk/by-id/google-ephemeral-disk-#{device_index}" do
to device
end
Expand Down

0 comments on commit cad6e3f

Please sign in to comment.