Module: MasterManipulator::Site

Included in:
Beaker::TestCase
Defined in:
lib/master_manipulator/site.rb

Instance Method Summary collapse

Instance Method Details

#create_site_pp(master_host, opts = {}) ⇒ String

Create a site.pp file with file bucket enabled. Also, allow the creation of a custom node definition or use the default node definition.

Examples:

Create a site.pp on master using the default node definition and an otherwise empty manifest

site_pp = create_site_pp(master)

Create a site.pp on master for a node named ‘mailgrunt’ with an otherwise empty manifest

site_pp = create_site_pp(master, {:node_def_name => 'mailgrunt'})

Create a site.pp on master for a node named ‘mailgrunt’ with a custom node definition in the manifest

site_pp = create_site_pp(master, {:manifest => manifest_for_mailgrunt, :node_def_name => 'mailgrunt'})

Parameters:

  • master_host (Beaker::Host)

    the target master for site.pp injection.

  • opts (Hash) (defaults to: {})

    Optional options hash containing options.

Options Hash (opts):

  • :manifest (String)

    The node definition to lay down

  • :node_def_name (String)

    The node definition name

Returns:

  • (String)

    manifest A manifest containing the input node definition to lay down in site.pp



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/master_manipulator/site.rb', line 49

def create_site_pp(master_host, opts = {})
  opts[:manifest] ||= ''
  opts[:node_def_name] ||= 'default'
  master_certname = on(master_host, puppet('config print certname')).stdout.rstrip

  default_def = <<-MANIFEST
node default {
}
MANIFEST

  node_def = <<-MANIFEST
node #{opts[:node_def_name]} {
  #{opts[:manifest]}
}
MANIFEST

  if opts[:node_def_name] != 'default'
    node_def = "#{default_def}\n#{node_def}"
  end

  site_pp = <<-MANIFEST
filebucket { 'main':
  server => '#{master_certname}',
  path   => false,
}

File { backup => 'main' }

#{node_def}
MANIFEST

  return site_pp
end

#get_manifests_path(master_host, opts = {}) ⇒ String

Get the location of an environment’s manifests path; defaults to production environment.

Examples:

Get the manifests path for the production environment on master

prod_env_manifests_path = get_manifests_path(master)

Get the manifests path for the testing environment on master

test_env_manifests_path = get_manifests_path(master, {:env => 'test'})

Parameters:

  • master_host (Beaker::Host)

    The master host that contains environments.

  • opts (Hash) (defaults to: {})

    Optional options hash containing options.

Options Hash (opts):

  • :env (String)

    The environment to query on the specified master

Returns:

  • (String)

    The absolute path to the manifests for the given environment on the given master



13
14
15
16
17
18
# File 'lib/master_manipulator/site.rb', line 13

def get_manifests_path(master_host, opts = {})
  opts[:env] ||= 'production'
  environment_base_path = on(master_host, puppet('config print environmentpath')).stdout.rstrip

  return File.join(environment_base_path, opts[:env], 'manifests')
end

#get_site_pp_path(master_host, opts = {}) ⇒ String

Get the path to a given environment’s site.pp; defaults to production environment.

Examples:

Return the path to the site.pp file for the production environment on master

prod_env_site_pp_path = get_site_pp_path(master)

Return the path to the site.pp file for the testing environment on master

prod_env_site_pp_path = get_site_pp_path(master, {:env => 'testing'})

Parameters:

  • master_host (Beaker::Host)

    The master to query.

  • opts (Hash) (defaults to: {})

    Optional options hash containing options.

Options Hash (opts):

  • :env (String)

    opts The environment to query on the specified master

Returns:

  • (String)

    The absolute path to the site.pp for the given environment on the given master



29
30
31
32
33
# File 'lib/master_manipulator/site.rb', line 29

def get_site_pp_path(master_host, opts = {})
  opts[:env] ||= 'production'

  return File.join(get_manifests_path(master_host, opts), 'site.pp')
end

#inject_site_pp(master_host, site_pp_path, manifest) ⇒ Object

Inject a site.pp manifest onto a master.

Examples:

Place this_is_junk.pp, with the contents defined in manifest, in /tmp on the master named compile_master

site_pp = inject_site_pp(compile_master, '/tmp/this_is_junk.pp', manifest)

Parameters:

  • master_host (Beaker::Host)

    the target master for injection.

  • site_pp_path (String)

    a path on the remote host into which the site.pp will be injected.

  • manifest (String)

    the manifest content to inject into site.pp to the host target path.

Returns:

  • nil



114
115
116
117
118
119
# File 'lib/master_manipulator/site.rb', line 114

def inject_site_pp(master_host, site_pp_path, manifest)
  site_pp_dir = File.dirname(site_pp_path)
  create_remote_file(master_host, site_pp_path, manifest)

  set_perms_on_remote(master_host, site_pp_dir, '0744')
end

#set_perms_on_remote(master_host, path, mode, opts = {}) ⇒ Object

Set mode, owner and group on a remote path.

Examples:

Set perms on a file on master with the default user and group

set_perms_on_remote(master, '/tmp/this_is_junk.pp', '0644')

Set perms on a file on master with the default user and a custom group

set_perms_on_remote(master, '/tmp/this_is_junk.pp', '0644', {:group => 'tutones')

Set perms on a file on master with a custom user and the default group

set_perms_on_remote(master, '/tmp/this_is_junk.pp', '0644', {:user => 'tommy')

Set perms on a file on master with a custom user and a custom group

set_perms_on_remote(master, '/tmp/this_is_junk.pp', '0644', {:user => 'tommy', :group => 'tutones')

Parameters:

  • master_host (Beaker::Host)

    The remote host containing the target path.

  • path (String)

    The pathname on which to set mode, user and group.

  • mode (String)

    The desired file mode in 4-digit octal string (e.g. ‘0644’).

  • opts (Hash) (defaults to: {})

    Optional options hash containing options.

Options Hash (opts):

  • :owner (String)

    The user owner to assign

  • :group (String)

    The group owner to assign

Returns:

  • nil



99
100
101
102
103
104
105
# File 'lib/master_manipulator/site.rb', line 99

def set_perms_on_remote(master_host, path, mode, opts = {})
  opts[:owner] ||= on(master_host, puppet('config print user')).stdout.rstrip
  opts[:group] ||= on(master_host, puppet('config print group')).stdout.rstrip

  on(master_host, "chmod -Rv #{mode} #{path}")
  on(master_host, "chown -Rv #{opts[:owner]}:#{opts[:group]} #{path}")
end