File: mount_utils.rb

package info (click to toggle)
puppet-agent 8.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,392 kB
  • sloc: ruby: 286,820; sh: 492; xml: 116; makefile: 88; cs: 68
file content (75 lines) | stat: -rw-r--r-- 3,011 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
module MountUtils
  module_function

  # Return the absolute path to the filesystem table file.
  # @param host [String] hostname
  # @return [String] path to the filesystem table file.
  def filesystem_file(host)
    case host['platform']
    when %r{aix}
      '/etc/filesystems'
    when %r{el-|centos|fedora|sles|debian|ubuntu|amazon}
      '/etc/fstab'
    else
      # TODO: Add Solaris and OSX support, as per PUP-5201 and PUP-4823
      fail_test("Unable to determine filesystem table file location for #{host['platform']}")
    end
  end

  # Return a standard filesystem type to use when creating filesysytems.
  # @param host [String] hostname
  # @return [String] filesystem type.
  def filesystem_type(host)
    case host['platform']
    when %r{aix}
      'jfs2'
    when %r{el-|centos|fedora|sles|debian|ubuntu|amazon}
      'ext3'
    else
      # TODO: Add Solaris and OSX support, as per PUP-5201 and PUP-4823
      fail_test("Unable to determine a standard filesystem table type for #{host['platform']}")
    end
  end

  # Appends a new filesystem entry to the filesystem table.
  # @param host [String] hostname.
  # @param mount_name [String] the name of the mount point. We use /tmp/name as the
  # new filesystem, and /name as the actual mount point.
  def add_entry_to_filesystem_table(host, mount_name)
    fs_file = filesystem_file(host)
    fs_type = filesystem_type(host)

    case host['platform']
    when %r{aix}
      # NOTE: /dev/hd8 is the default jfs logging device on AIX.
      on(host, "echo '/#{mount_name}:\n  dev = /dev/#{mount_name}\n  vfs = #{fs_type}\n  log = /dev/hd8' >> #{fs_file}")
    when %r{el-|centos|fedora|sles|debian|ubuntu|amazon}
      # Correctly munge whitespaces in mountpoints
      munged_mount_name = mount_name.gsub(' ', '\\\040')
      on(host, "echo '/tmp/#{munged_mount_name}  /#{munged_mount_name}  #{fs_type}  loop  0  0' >> #{fs_file}")
    else
      # TODO: Add Solaris and OSX support, as per PUP-5201 and PUP-4823
      fail_test("Adding entries to the filesystem table on #{host['platform']} is not currently supported.")
    end
  end

  # Creates a new filesystem on the host.
  # @param host [String] hostname
  # @param mount_name [String] the name of the mount point.
  def create_filesystem(host, mount_name)
    fs_type = filesystem_type(host)

    case host['platform']
    when %r{aix}
      volume_group = on(host, 'lsvg').stdout.split("\n")[0]
      on(host, "mklv -y #{mount_name} #{volume_group} 1M")
      on(host, "mkfs -V #{fs_type} -l #{mount_name} /dev/#{mount_name}")
    when %r{el-|centos|fedora|sles|debian|ubuntu|amazon}
      on(host, "dd if=/dev/zero of='/tmp/#{mount_name}' count=16384", acceptable_exit_codes: [0, 1])
      on(host, "yes | mkfs -t #{fs_type} -q '/tmp/#{mount_name}'", acceptable_exit_codes: (0..254))
    else
      # TODO: Add Solaris and OSX support, as per PUP-5201 and PUP-4823
      fail_test("Creating filesystems on #{host['platform']} is not currently supported.")
    end
  end
end