Module: Unix::File

Includes:
Beaker::CommandFactory
Included in:
Host
Defined in:
lib/beaker/host/unix/file.rb

Instance Attribute Summary

Attributes included from Beaker::CommandFactory

#assertions

Instance Method Summary collapse

Methods included from Beaker::CommandFactory

#execute, #fail_test

Instance Method Details

#cat(path) ⇒ Object



61
62
63
# File 'lib/beaker/host/unix/file.rb', line 61

def cat(path)
  execute("cat #{path}")
end

#chgrp(group, path, recursive = false) ⇒ Beaker::Result

Change group ownership of a path

Parameters:

  • group (String)

    Group to chgrp to

  • path (String)

    Path to chgrp

  • recursive (Boolean) (defaults to: false)

    Whether to pass the recursive flag

Returns:

See Also:



46
47
48
# File 'lib/beaker/host/unix/file.rb', line 46

def chgrp(group, path, recursive = false)
  execute("chgrp #{recursive ? '-R ' : ''}#{group} #{path}")
end

#chmod(mod, path, recursive = false) ⇒ Object



33
34
35
# File 'lib/beaker/host/unix/file.rb', line 33

def chmod(mod, path, recursive = false)
  execute("chmod #{recursive ? '-R ' : ''}#{mod} #{path}")
end

#chown(user, path, recursive = false) ⇒ Beaker::Result

Note:

To maintain argument order consistency with the underlying syscall, avoid having to specify nil arguments, and not do anything hacky with the arguments list, this method does not allow you to modify group ownership. Use Host::chgrp instead.

Change user ownership of a path

Parameters:

  • user (String)

    User to chown to

  • path (String)

    Path to chown

  • recursive (Boolean) (defaults to: false)

    Whether to pass the recursive flag

Returns:

See Also:



29
30
31
# File 'lib/beaker/host/unix/file.rb', line 29

def chown(user, path, recursive = false)
  execute("chown #{recursive ? '-R ' : ''}#{user} #{path}")
end

#file_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
# File 'lib/beaker/host/unix/file.rb', line 79

def file_exist?(path)
  result = exec(Beaker::Command.new("test -e #{path}"), :acceptable_exit_codes => [0, 1])
  result.exit_code == 0
end

#ls_ld(path) ⇒ Beaker::Result

List long output of a path

Parameters:

  • path (String)

    Path to list properties of

Returns:

See Also:



57
58
59
# File 'lib/beaker/host/unix/file.rb', line 57

def ls_ld(path)
  execute("ls -ld #{path}")
end

#noask_file_textString

Returns the noask file text for Solaris hosts

Returns:

  • (String)

    the text of the noask file

Raises:

  • (ArgumentError)

    If called on a host with a platform that’s not Solaris



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/beaker/host/unix/file.rb', line 158

def noask_file_text
  if self['platform'].variant == 'solaris' && self['platform'].version == '10'
    noask = <<~NOASK
      # Write the noask file to a temporary directory
      # please see man -s 4 admin for details about this file:
      # http://www.opensolarisforum.org/man/man4/admin.html
      #
      # The key thing we don't want to prompt for are conflicting files.
      # The other nocheck settings are mostly defensive to prevent prompts
      # We _do_ want to check for available free space and abort if there is
      # not enough
      mail=
      # Overwrite already installed instances
      instance=overwrite
      # Do not bother checking for partially installed packages
      partial=nocheck
      # Do not bother checking the runlevel
      runlevel=nocheck
      # Do not bother checking package dependencies (We take care of this)
      idepend=nocheck
      rdepend=nocheck
      # DO check for available free space and abort if there isn't enough
      space=quit
      # Do not check for setuid files.
      setuid=nocheck
      # Do not check if files conflict with other packages
      conflict=nocheck
      # We have no action scripts.  Do not check for them.
      action=nocheck
      # Install to the default base directory.
      basedir=default
    NOASK
  else
    msg = "noask file text unknown for platform '#{self['platform']}'"
    raise ArgumentError, msg
  end
  noask
end

#package_config_dirString

Gets the config dir location for package information

Returns:

  • (String)

    Path to package config dir

Raises:

  • (ArgumentError)

    For an unknown platform



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/beaker/host/unix/file.rb', line 89

def package_config_dir
  case self['platform']
  when /amazon|fedora|el-|redhat|centos/
    '/etc/yum.repos.d/'
  when /opensuse|sles/
    '/etc/zypp/repos.d/'
  when /debian|ubuntu/
    '/etc/apt/sources.list.d'
  else
    msg = "package config dir unknown for platform '#{self['platform']}'"
    raise ArgumentError, msg
  end
end

#path_split(paths) ⇒ Object



75
76
77
# File 'lib/beaker/host/unix/file.rb', line 75

def path_split(paths)
  paths.split(':')
end

#repo_filename(package_name, build_version) ⇒ String

Returns the repo filename for a given package & version for a platform

Parameters:

  • package_name (String)

    Name of the package

  • build_version (String)

    Version string of the package

Returns:

  • (String)

    Filename of the repo

Raises:

  • (ArgumentError)

    For an unknown platform



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/beaker/host/unix/file.rb', line 111

def repo_filename(package_name, build_version)
  variant, version, arch, codename = self['platform'].to_array
  repo_filename = format("pl-%s-%s-", package_name, build_version)

  case variant
  when /amazon|fedora|el|redhat|centos|opensuse|sles/
    variant = 'el' if %w[centos redhat].include?(variant)

    variant = 'redhatfips' if self['packaging_platform']&.include?('redhatfips')

    fedora_prefix = (variant == 'fedora' ? 'f' : '')

    pattern = "%s-%s%s-%s.repo"

    repo_filename << (format(pattern, variant, fedora_prefix, version, arch))
  when /debian|ubuntu/
    repo_filename << (format("%s.list", codename))
  else
    msg = "#repo_filename: repo filename pattern not known for platform '#{self['platform']}'"
    raise ArgumentError, msg
  end

  repo_filename
end

#repo_typeString

Gets the repo type for the given platform

Returns:

  • (String)

    Type of repo (rpm|deb)

Raises:

  • (ArgumentError)

    For an unknown platform



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/beaker/host/unix/file.rb', line 141

def repo_type
  case self['platform']
  when /amazon|fedora|el-|redhat|centos|opensuse|sles/
    'rpm'
  when /debian|ubuntu/
    'deb'
  else
    msg = "#repo_type: repo type not known for platform '#{self['platform']}'"
    raise ArgumentError, msg
  end
end

#scp_path(path) ⇒ String

Handles any changes needed in a path for SCP

Parameters:

  • path (String)

    File path to SCP to

Returns:

  • (String)

    path, changed if needed due to host constraints



71
72
73
# File 'lib/beaker/host/unix/file.rb', line 71

def scp_path(path)
  path
end

#system_temp_pathObject



12
13
14
# File 'lib/beaker/host/unix/file.rb', line 12

def system_temp_path
  '/tmp'
end

#tmpdir(name = '') ⇒ Object



8
9
10
# File 'lib/beaker/host/unix/file.rb', line 8

def tmpdir(name = '')
  execute("mktemp -dt #{name}.XXXXXX")
end

#tmpfile(name = '', extension = nil) ⇒ Object



4
5
6
# File 'lib/beaker/host/unix/file.rb', line 4

def tmpfile(name = '', extension = nil)
  execute("mktemp -t #{name}.XXXXXX#{extension}")
end