Skip to content

Instantly share code, notes, and snippets.

@AMeng
Created June 4, 2014 20:09
Show Gist options
  • Save AMeng/7fa54b7afaceb1e1db15 to your computer and use it in GitHub Desktop.
Save AMeng/7fa54b7afaceb1e1db15 to your computer and use it in GitHub Desktop.

Recipe:

include_recipe "apache2::mod_python"

version = node[:graphite][:version]
pyver = node[:graphite][:python_version]

package "python-cairo-dev"
package "python-django"
package "python-django-tagging"
package "python-memcache"
package "python-rrdtool"

remote_file "/usr/src/graphite-web-#{version}.tar.gz" do
  source node[:graphite][:graphite_web][:uri]
  checksum node[:graphite][:graphite_web][:checksum]
end

execute "untar graphite-web" do
  command "tar xzf graphite-web-#{version}.tar.gz"
  creates "/usr/src/graphite-web-#{version}"
  cwd "/usr/src"
end

execute "install graphite-web" do
  command "python setup.py install"
  creates "/opt/graphite/webapp/graphite_web-#{version}-py#{pyver}.egg-info"
  cwd "/usr/src/graphite-web-#{version}"
end

if node[:graphite][:graphite_web][:use_mod_wsgi]
  link "/opt/graphite/conf/graphite.wsgi" do
    to "/opt/graphite/conf/graphite.wsgi.example"
  end

  template "/etc/apache2/sites-available/graphite" do
    source "graphite-vhost-mod-wsgi.conf.erb"
    mode 0644
    owner "root"
    group "root"
  end
else
  template "/etc/apache2/sites-available/graphite" do
    source "graphite-vhost.conf.erb"
    mode 0644
    owner "root"
    group "root"
  end
end

apache_site "000-default" do
  enable false
end

apache_site "graphite"

directory "/opt/graphite/storage/log" do
  owner "www-data"
  group "www-data"
end

directory "/opt/graphite/storage/log/webapp" do
  owner "www-data"
  group "www-data"
end

directory "/opt/graphite/storage" do
  owner "www-data"
  group "www-data"
end

directory "/opt/graphite/storage/whisper" do
  owner "www-data"
  group "www-data"
end

cookbook_file "/opt/graphite/bin/set_admin_passwd.py" do
  mode "755"
end

cookbook_file "/opt/graphite/storage/graphite.db" do
  action :create_if_missing
  notifies :run, "execute[set admin password]"
end

execute "set admin password" do
  command "/opt/graphite/bin/set_admin_passwd.py root #{node[:graphite][:password]}"
  action :nothing
end

file "/opt/graphite/storage/graphite.db" do
  owner "www-data"
  group "www-data"
  mode "644"
end

Generated spec

require 'chefspec'

describe 'graphite::web' do
  let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }

  it 'runs successfully' do
    expect{chef_run}.not_to raise_error
  end

  it "deletes the /etc/apache2/conf.d/python.conf file" do
    expect(chef_run).to delete_file("/etc/apache2/conf.d/python.conf")
  end

  it "installs the apache2 package" do
    expect(chef_run).to install_package("apache2")
  end

  it "enables the apache2 service" do
    expect(chef_run).to enable_service("apache2")
  end

  it "creates the /etc/apache2/ssl directory" do
    expect(chef_run).to create_directory("/etc/apache2/ssl")
  end

  it "creates the /etc/apache2/conf.d directory" do
    expect(chef_run).to create_directory("/etc/apache2/conf.d")
  end

  it "creates the /var/cache/apache2 directory" do
    expect(chef_run).to create_directory("/var/cache/apache2")
  end

  it "creates the /etc/sysconfig/httpd template" do
    expect(chef_run).to create_template("/etc/sysconfig/httpd")
  end

  it "creates the apache2.conf template" do
    expect(chef_run).to create_template("apache2.conf")
  end

  it "creates the apache2-conf-security template" do
    expect(chef_run).to create_template("apache2-conf-security")
  end

  it "creates the apache2-conf-charset template" do
    expect(chef_run).to create_template("apache2-conf-charset")
  end

  it "creates the /etc/apache2/ports.conf template" do
    expect(chef_run).to create_template("/etc/apache2/ports.conf")
  end

  it "creates the /etc/apache2/sites-available/default template" do
    expect(chef_run).to create_template("/etc/apache2/sites-available/default")
  end

  it "creates the /etc/apache2/mods-available/status.conf template" do
    expect(chef_run).to create_template("/etc/apache2/mods-available/status.conf")
  end

  it "runs the a2enmod status execute" do
    expect(chef_run).to run_execute("a2enmod status")
  end

  it "creates the /etc/apache2/mods-available/alias.conf template" do
    expect(chef_run).to create_template("/etc/apache2/mods-available/alias.conf")
  end

  it "runs the a2enmod alias execute" do
    expect(chef_run).to run_execute("a2enmod alias")
  end

  it "runs the a2enmod auth_basic execute" do
    expect(chef_run).to run_execute("a2enmod auth_basic")
  end

  it "runs the a2enmod authn_file execute" do
    expect(chef_run).to run_execute("a2enmod authn_file")
  end

  it "runs the a2enmod authz_default execute" do
    expect(chef_run).to run_execute("a2enmod authz_default")
  end

  it "runs the a2enmod authz_groupfile execute" do
    expect(chef_run).to run_execute("a2enmod authz_groupfile")
  end

  it "runs the a2enmod authz_host execute" do
    expect(chef_run).to run_execute("a2enmod authz_host")
  end

  it "runs the a2enmod authz_user execute" do
    expect(chef_run).to run_execute("a2enmod authz_user")
  end

  it "creates the /etc/apache2/mods-available/autoindex.conf template" do
    expect(chef_run).to create_template("/etc/apache2/mods-available/autoindex.conf")
  end

  it "runs the a2enmod autoindex execute" do
    expect(chef_run).to run_execute("a2enmod autoindex")
  end

  it "creates the /etc/apache2/mods-available/dir.conf template" do
    expect(chef_run).to create_template("/etc/apache2/mods-available/dir.conf")
  end

  it "runs the a2enmod dir execute" do
    expect(chef_run).to run_execute("a2enmod dir")
  end

  it "runs the a2enmod env execute" do
    expect(chef_run).to run_execute("a2enmod env")
  end

  it "creates the /etc/apache2/mods-available/mime.conf template" do
    expect(chef_run).to create_template("/etc/apache2/mods-available/mime.conf")
  end

  it "runs the a2enmod mime execute" do
    expect(chef_run).to run_execute("a2enmod mime")
  end

  it "creates the /etc/apache2/mods-available/negotiation.conf template" do
    expect(chef_run).to create_template("/etc/apache2/mods-available/negotiation.conf")
  end

  it "runs the a2enmod negotiation execute" do
    expect(chef_run).to run_execute("a2enmod negotiation")
  end

  it "creates the /etc/apache2/mods-available/setenvif.conf template" do
    expect(chef_run).to create_template("/etc/apache2/mods-available/setenvif.conf")
  end

  it "runs the a2enmod setenvif execute" do
    expect(chef_run).to run_execute("a2enmod setenvif")
  end

  it "runs the a2dissite default execute" do
    expect(chef_run).to run_execute("a2dissite default")
  end

  it "starts the apache2 service" do
    expect(chef_run).to start_service("apache2")
  end

  it "runs the a2enmod python execute" do
    expect(chef_run).to run_execute("a2enmod python")
  end

  it "installs the python-cairo-dev package" do
    expect(chef_run).to install_package("python-cairo-dev")
  end

  it "installs the python-django package" do
    expect(chef_run).to install_package("python-django")
  end

  it "installs the python-django-tagging package" do
    expect(chef_run).to install_package("python-django-tagging")
  end

  it "installs the python-memcache package" do
    expect(chef_run).to install_package("python-memcache")
  end

  it "installs the python-rrdtool package" do
    expect(chef_run).to install_package("python-rrdtool")
  end

  it "creates the /usr/src/graphite-web-0.9.12.tar.gz remote_file" do
    expect(chef_run).to create_remote_file("/usr/src/graphite-web-0.9.12.tar.gz")
  end

  it "runs the untar graphite-web execute" do
    expect(chef_run).to run_execute("untar graphite-web")
  end

  it "runs the install graphite-web execute" do
    expect(chef_run).to run_execute("install graphite-web")
  end

  it "creates the /etc/apache2/sites-available/graphite template" do
    expect(chef_run).to create_template("/etc/apache2/sites-available/graphite")
  end

  it "runs the a2dissite 000-default execute" do
    expect(chef_run).to run_execute("a2dissite 000-default")
  end

  it "runs the a2ensite graphite execute" do
    expect(chef_run).to run_execute("a2ensite graphite")
  end

  it "creates the /opt/graphite/storage/log directory" do
    expect(chef_run).to create_directory("/opt/graphite/storage/log")
  end

  it "creates the /opt/graphite/storage/log/webapp directory" do
    expect(chef_run).to create_directory("/opt/graphite/storage/log/webapp")
  end

  it "creates the /opt/graphite/storage directory" do
    expect(chef_run).to create_directory("/opt/graphite/storage")
  end

  it "creates the /opt/graphite/storage/whisper directory" do
    expect(chef_run).to create_directory("/opt/graphite/storage/whisper")
  end

  it "creates the /opt/graphite/bin/set_admin_passwd.py cookbook_file" do
    expect(chef_run).to create_cookbook_file("/opt/graphite/bin/set_admin_passwd.py")
  end

  it "create_if_missings the /opt/graphite/storage/graphite.db cookbook_file" do
    expect(chef_run).to create_if_missing_cookbook_file("/opt/graphite/storage/graphite.db")
  end

  it "nothings the set admin password execute" do
    expect(chef_run).to nothing_execute("set admin password")
  end

  it "creates the /opt/graphite/storage/graphite.db file" do
    expect(chef_run).to create_file("/opt/graphite/storage/graphite.db")
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment