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, #platform_defaults

Methods included from Unix::Pkg

#check_for_command, #check_for_package, #deploy_apt_repo, #deploy_package_repo, #deploy_yum_repo, #deploy_zyp_repo, #determine_if_x86_64, #extract_rpm_proxy_options, #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, #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, #environment_variable_string_pair_array, #get_env_var, #get_ip, #mirror_env_to_profile_d, #mkdir_p, #mv, #path, #ping, #reboot, #rm_rf, #ssh_permit_user_environment, #ssh_service_restart, #ssh_set_user_environment, #touch

Methods included from Unix::File

#file_exist?, #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, #get_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!

Methods included from Beaker::DSL::Patterns

#block_on

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

#link_exists?, #port_open_within?

Methods included from Beaker::DSL::Helpers::TKHelpers

#modify_tk_config

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::PuppetHelpers

#apply_manifest, #apply_manifest_on, #create_tmpdir_for_user, #puppet_group, #puppet_user, #run_agent_on, #sign_certificate, #sign_certificate_for, #sleep_until_nc_started, #sleep_until_puppetdb_started, #sleep_until_puppetserver_started, #stop_agent, #stop_agent_on, #stub_forge, #stub_forge_on, #stub_hosts, #stub_hosts_on, #wait_for_host_in_dashboard, #with_forge_stubbed, #with_forge_stubbed_on, #with_host_stubbed_on, #with_puppet_running, #with_puppet_running_on

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

#add_system32_hosts_entry, #backup_the_file, #check_for_package, #create_remote_file, #create_tmpdir_on, #curl_on, #curl_with_retries, #deploy_package_repo, #echo_on, #execute_powershell_script_on, #exit_code, #install_package, #on, #retry_on, #rsync_to, #run_script, #run_script_on, #scp_from, #scp_to, #shell, #stderr, #stdout, #upgrade_package

Methods included from Beaker::DSL::Helpers::FacterHelpers

#fact, #fact_on

Constructor Details

This class inherits a constructor from Unix::Host

Instance Method Details

#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.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/beaker/host/cisco.rb', line 95

def environment_string env
  prestring = 'source /etc/profile;'
  prestring << " sudo sh -c \"" if self[:user] != 'root'
  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

Returns:

  • (String)

    Path to package config dir

Raises:

  • (ArgumentError)

    For an unknown platform



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

def package_config_dir
  '/etc/yum/repos.d/'
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) (defaults to: {})

    optional parameters

Returns:

  • (String)

    Command string as needed for this host



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/beaker/host/cisco.rb', line 71

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

  prepend_cmds = ''
  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

Returns:

  • (String)

    Type of repo (rpm|deb)

Raises:

  • (ArgumentError)

    For an unknown platform



51
52
53
# File 'lib/beaker/host/cisco.rb', line 51

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



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

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

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



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

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

Returns:

  • (String, nil)

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



13
14
15
# File 'lib/beaker/host/cisco.rb', line 13

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



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

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