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, #pe_puppet_agent_promoted_package_info, #pe_puppet_agent_promoted_package_install, #pkg_initialize, #puppet_agent_dev_package_info, #solaris_install_local_package, #solaris_puppet_agent_dev_package_info, #uncompress_local_tarball, #uninstall_package, #update_apt_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

#+, #[], #[]=, #close, #connection, create, #delete, #do_rsync_to, #do_scp_from, #do_scp_to, #exec, #fips_mode?, #get_ip, #get_public_ip, #graceful_restarts?, #has_key?, #hostname, #initialize, #ip, #is_cygwin?, #is_pe?, #is_powershell?, #is_using_passenger?, #is_x86_64?, #log_prefix, #node_name, #pkg_initialize, #platform, #port_open?, #puppet_configprint, #reachable_name, #to_s, #to_str, #up?, #use_service_scripts?, #uses_passenger!, #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, #exit_code, #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, #stderr, #stdout, #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



108
109
110
111
112
# File 'lib/beaker/host/cisco.rb', line 108

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 command =~ /ntpdate|\/isan\/bin\/vsh/ || self[:user] == 'root'
end

#environment_string(env) ⇒ String

Construct the environment string for this command



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/beaker/host/cisco.rb', line 125

def environment_string env
  prestring = ''
  return prestring if env.empty?
  env_array = self.environment_variable_string_pair_array( env )
  environment_string = env_array.join(' ')

  if self[:platform] =~ /cisco_nexus/
    prestring << " export"
  else
    prestring << " env"
  end
  environment_string = "#{prestring} #{environment_string}"
  environment_string << ';' if prestring =~ /export/
  environment_string
end

#package_config_dirString

Gets the config dir location for package information

Raises:

  • (ArgumentError)

    For an unknown platform



73
74
75
# File 'lib/beaker/host/cisco.rb', line 73

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



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

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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/beaker/host/cisco.rb', line 84

def prepend_commands(command = '', user_pc = '', opts = {})
  return user_pc unless command.index('vsh').nil?
  if self[:platform] =~ /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'
  if self[:vrf]
    prepend_cmds << "ip netns exec #{self[:vrf]} "
  end
  if user_pc && !user_pc.empty?
    prepend_cmds << "#{user_pc} "
  end
  prepend_cmds.strip
end

#repo_typeString

Gets the repo type for the given platform

Raises:

  • (ArgumentError)

    For an unknown platform



64
65
66
# File 'lib/beaker/host/cisco.rb', line 64

def repo_type
  'rpm'
end

#scp_path(path) ⇒ String

Handles any changes needed in a path for SCP



49
50
51
52
53
54
55
56
57
# File 'lib/beaker/host/cisco.rb', line 49

def scp_path(path)
  if self[:platform] =~ /cisco_nexus/
    @home_dir ||= execute( 'pwd' )
    answer = "#{@home_dir}/#{File.basename( path )}"
    answer << '/' if 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



36
37
38
39
40
41
# File 'lib/beaker/host/cisco.rb', line 36

def scp_post_operations(scp_file_actual, scp_file_target)
  if self[:platform] =~ /cisco_nexus/
    execute( "mv #{scp_file_actual} #{scp_file_target}" )
  end
  nil
end

#skip_set_env?String?

Tells you whether a host platform supports beaker’s

{Beaker::HostPrebuiltSteps#set_env} method


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

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

#validate_setupObject

Validates that the host was setup correctly

Raises:

  • (ArgumentError)

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



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/beaker/host/cisco.rb', line 146

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

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