Class: Cisco::Host

Inherits:
Unix::Host show all
Defined in:
lib/beaker/host/cisco.rb

Constant Summary

Constants inherited from Beaker::Host

Beaker::Host::SELECT_TIMEOUT

Instance Attribute Summary

Attributes included from Beaker::CommandFactory

#assertions

Attributes inherited from Beaker::Host

#host_hash, #logger, #name, #options

Instance Method Summary collapse

Methods inherited from Unix::Host

#determine_ssh_server, #external_copy_base, #initialize

Methods included from Unix::Pkg

#check_for_command, #check_for_package, #determine_if_x86_64, #extract_rpm_proxy_options, #install_local_package, #install_package, #install_package_with_rpm, #pkg_initialize, #solaris_install_local_package, #uncompress_local_tarball, #uninstall_package, #update_apt_if_needed, #update_pacman_if_needed, #upgrade_package

Methods included from Beaker::CommandFactory

#execute, #fail_test

Methods included from Unix::Exec

#add_env_var, #clear_env_var, #delete_env_var, #echo, #enable_remote_rsyslog, #environment_variable_string_pair_array, #get_env_var, #get_ip, #mirror_env_to_profile_d, #mkdir_p, #modified_at, #mv, #path, #ping, #reboot, #rm_rf, #selinux_enabled?, #ssh_permit_user_environment, #ssh_service_restart, #ssh_set_user_environment, #touch, #which

Methods included from Unix::File

#cat, #chgrp, #chmod, #chown, #file_exist?, #ls_ld, #noask_file_text, #path_split, #repo_filename, #system_temp_path, #tmpdir, #tmpfile

Methods included from Unix::Group

#group_absent, #group_get, #group_gid, #group_list, #group_present

Methods included from Unix::User

#user_absent, #user_get, #user_list, #user_present

Methods inherited from Beaker::Host

#+, #[], #[]=, #add_env_var, #close, #connection, create, #delete, #do_rsync_to, #do_scp_from, #do_scp_to, #exec, #fips_mode?, #get_ip, #get_public_ip, #has_key?, #hostname, #initialize, #install_package, #ip, #is_cygwin?, #is_pe?, #is_powershell?, #is_x86_64?, #log_prefix, #node_name, #path_split, #pkg_initialize, #platform, #port_open?, #puppet_configprint, #reachable_name, #rm_rf, #tmpdir, #tmpfile, #to_s, #to_str, #up?, #wait_for_port

Methods included from Beaker::DSL::Patterns

#block_on

Methods included from Beaker::DSL::Helpers::HoconHelpers

#hocon_file_edit_in_place_on, #hocon_file_edit_on, #hocon_file_read_on

Methods included from Beaker::DSL::Helpers::WebHelpers

#link_exists?, #port_open_within?

Methods included from Beaker::DSL::Helpers::TestHelpers

#current_step_name, #current_test_filename, #current_test_name, #set_current_step_name, #set_current_test_filename, #set_current_test_name

Methods included from Beaker::DSL::Helpers::HostHelpers

#add_system32_hosts_entry, #archive_file_from, #backup_the_file, #check_for_package, #create_remote_file, #curl_on, #curl_with_retries, #directory_exists_on, #echo_on, #execute_powershell_script_on, #file_contents_on, #file_exists_on, #install_package, #link_exists_on, #on, #retry_on, #rsync_to, #run_script, #run_script_on, #scp_from, #scp_to, #shell, #uninstall_package, #upgrade_package, #win_ads_path

Constructor Details

This class inherits a constructor from Unix::Host

Instance Method Details

#append_commands(command = '', _user_ac = '', _opts = {}) ⇒ String

Gets the specific append commands as needed for this host

Parameters:

  • command (String) (defaults to: '')

    Command to be executed

  • user_ac (String)

    List of user-specified commands to append

  • opts (Hash)

    optional parameters

Returns:

  • (String)

    Command string as needed for this host



102
103
104
105
106
# File 'lib/beaker/host/cisco.rb', line 102

def append_commands(command = '', _user_ac = '', _opts = {})
  command.gsub('"') { '\\"' }
  # vsh commands, ntpdate or when user is root commands do not require an appended `"`
  return '"' unless /ntpdate|\/isan\/bin\/vsh/.match?(command) || self[:user] == 'root'
end

#environment_string(env) ⇒ String

Construct the environment string for this command

Parameters:

  • env (Hash{String=>String})

    An optional Hash containing key-value pairs to be treated as environment variables that should be set for the duration of the puppet command.

Returns:

  • (String)

    Returns a string containing command line arguments that will ensure the environment is correctly set for the given host.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/beaker/host/cisco.rb', line 119

def environment_string env
  prestring = ''
  return prestring if env.empty?

  env_array = self.environment_variable_string_pair_array(env)
  environment_string = env_array.join(' ')

  prestring << if self[:platform].include?('cisco_nexus')
                 " export"
               else
                 " env"
               end
  environment_string = "#{prestring} #{environment_string}"
  environment_string << ';' if prestring.include?('export')
  environment_string
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



70
71
72
# File 'lib/beaker/host/cisco.rb', line 70

def package_config_dir
  '/etc/yum/repos.d/'
end

#platform_defaultsObject

as the cisco hosts tend to have custom ssh configuration, the presets do not apply where verification of the host keys is disabled



11
12
13
14
15
16
17
18
# File 'lib/beaker/host/cisco.rb', line 11

def platform_defaults
  h = Beaker::Options::OptionsHash.new
  h.merge({
            'ssh' => {
              :verify_host_key => false,
            },
          })
end

#prepend_commands(command = '', user_pc = '', _opts = {}) ⇒ String

Gets the specific prepend commands as needed for this host

Parameters:

  • command (String) (defaults to: '')

    Command to be executed

  • user_pc (String) (defaults to: '')

    List of user-specified commands to prepend

  • opts (Hash)

    optional parameters

Returns:

  • (String)

    Command string as needed for this host



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/beaker/host/cisco.rb', line 81

def prepend_commands(command = '', user_pc = '', _opts = {})
  return user_pc unless command.index('vsh').nil?

  if self[:platform].include?('cisco_nexus')
    return user_pc unless command.index('ntpdate').nil?
  end

  prepend_cmds = 'source /etc/profile;'
  prepend_cmds << " sudo -E sh -c \"" if self[:user] != 'root'
  prepend_cmds << "ip netns exec #{self[:vrf]} " if self[:vrf]
  prepend_cmds << "#{user_pc} " if user_pc && !user_pc.empty?
  prepend_cmds.strip
end

#repo_typeString

Gets the repo type for the given platform

Returns:

  • (String)

    Type of repo (rpm|deb)

Raises:

  • (ArgumentError)

    For an unknown platform



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

def repo_type
  'rpm'
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



46
47
48
49
50
51
52
53
54
# File 'lib/beaker/host/cisco.rb', line 46

def scp_path(path)
  if self[:platform].include?('cisco_nexus')
    @home_dir ||= execute('pwd')
    answer = "#{@home_dir}/#{File.basename(path)}"
    answer << '/' if /\/$/.match?(path)
    return answer
  end
  path
end

#scp_post_operations(scp_file_actual, scp_file_target) ⇒ Object

Handles host operations needed after an SCP takes place

Parameters:

  • scp_file_actual (String)

    File path to actual SCP’d file on host

  • scp_file_target (String)

    File path to target SCP location on host

Returns:

  • nil



35
36
37
38
# File 'lib/beaker/host/cisco.rb', line 35

def scp_post_operations(scp_file_actual, scp_file_target)
  execute("mv #{scp_file_actual} #{scp_file_target}") if self[:platform].include?('cisco_nexus')
  nil
end

#skip_set_env?String?

Tells you whether a host platform supports beaker’s

{Beaker::HostPrebuiltSteps#set_env} method

Returns:

  • (String, nil)

    Reason message if set_env should be skipped, nil if it should run.



25
26
27
# File 'lib/beaker/host/cisco.rb', line 25

def skip_set_env?
  'Cisco does not allow SSH control through the BASH shell'
end

#validate_setupObject

Validates that the host was setup correctly

Returns:

  • nil

Raises:

  • (ArgumentError)

    If the host is setup incorrectly, this will be raised with the appropriate message



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/beaker/host/cisco.rb', line 141

def validate_setup
  msg = nil
  if self[:platform].include?('cisco_nexus')
    msg = 'Cisco Nexus hosts must be provided with a :vrf value.' if !self[:vrf]
    msg = 'Cisco hosts must be provided with a :user value' if !self[:user]
  end
  if self[:platform].include?('cisco_ios_xr')
    msg = 'Cisco hosts must be provided with a :user value' if !self[:user]
  end

  return unless msg

  msg << <<-EOF
      Check https://github.com/puppetlabs/beaker/blob/master/docs/hosts/cisco.md for more info.'
  EOF
  raise ArgumentError, msg
end