Class: Beaker::Abs

Inherits:
Hypervisor
  • Object
show all
Defined in:
lib/beaker/hypervisor/abs.rb

Instance Method Summary collapse

Constructor Details

#initialize(hosts, options) ⇒ Abs

Returns a new instance of Abs.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/beaker/hypervisor/abs.rb', line 21

def initialize(hosts, options)
  @options = options
  @logger = options[:logger]
  @hosts = hosts

  resource_hosts = ENV['ABS_RESOURCE_HOSTS'] || @options[:abs_resource_hosts]

  @abs_service_name = ENV['ABS_SERVICE_NAME'] || @options[:abs_service_name] || "abs"
  @abs_service_priority = ENV['ABS_SERVICE_PRIORITY'] || @options[:abs_service_priority] || "1"

  raise ArgumentError.new("ABS_RESOURCE_HOSTS must be specified when using the Beaker::Abs hypervisor when provisioning") if resource_hosts.nil? && !options[:provision]
  resource_hosts = provision_vms(hosts).to_json if resource_hosts.nil?
  @resource_hosts = JSON.parse(resource_hosts)
end

Instance Method Details

#cleanupObject



95
96
97
# File 'lib/beaker/hypervisor/abs.rb', line 95

def cleanup
  # nothing to do
end

#connection_preference(host) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/beaker/hypervisor/abs.rb', line 36

def connection_preference(host)
  vmhostname = host[:vmhostname]
  if vmhostname && host[:hypervisor] == 'abs'
    @resource_hosts.each do |resource_host|
      if resource_host['hostname'] == vmhostname
        engine = resource_host['engine']
        case engine
        when /^(vmpooler|nspooler)$/
          # ABS does not set ip, do not include
          # vmpooler hostname is the platform name, nspooler hostname == vmhostname
          return [:vmhostname]
        else
          super
        end
      end
    end
  end
  super
end

#generate_floaty_request_strings(hosts, supported_vm_list) ⇒ Object

Based upon the host file, this method counts the number of each template needed and generates the host=Xnum eg redhat-7-x86_64=2 expected by floaty



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/beaker/hypervisor/abs.rb', line 143

def generate_floaty_request_strings(hosts, supported_vm_list)
  vm_list = {}

  hosts.each do |host|
    if supported_vm_list.include?(host[:template])
      if vm_list.include?(host[:template])
        vm_list[host[:template]] = vm_list[host[:template]] + 1
      else
        vm_list[host[:template]] = 1
      end
    else
      raise ArgumentError.new("#{host.name} has a template #{host[:template]} that is not found in vmpooler or nspooler")
    end
  end

  vm_request = ""
  vm_list.each do |key, value|
    vm_request.concat("#{key}=#{value} ")
  end

  vm_request
end

#provisionObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/beaker/hypervisor/abs.rb', line 56

def provision
  type2hosts = {}

  # Each resource_host is of the form:
  # {
  #   "hostname" => "mkbx0m6dnnntgz1.delivery.puppetlabs.net",
  #   "type"     => "centos-7-i386",
  #   "engine"   => "vmpooler",
  # }
  # {
  #   "hostname" => "sol10-1.delivery.puppetlabs.net",
  #   "type"     => "solaris-10-sparc",
  #   "engine"   => "nspooler",
  # }
  @resource_hosts.each do |resource_host|
    type = resource_host['type']
    type2hosts[type] ||= []
    type2hosts[type] << resource_host['hostname']
    type2hosts[type] << resource_host['ip']
  end

  # for each host, get a vm for that template type
  @hosts.each do |host|
    template = host['template']

    raise ArgumentError.new("Failed to provision host '#{host.hostname}' because its 'template' is missing.") if template.nil?

    if provisioned_hosts = type2hosts[template]
      host['vmhostname'] = provisioned_hosts.shift
      host['ip'] = provisioned_hosts.shift
    else
      raise ArgumentError.new("Failed to provision host '#{host.hostname}', no template of type '#{host['template']}' was provided.")
    end
  end
  if Beaker::Hypervisor.respond_to?(:set_ssh_connection_preference)
    Beaker::Hypervisor.set_ssh_connection_preference(@hosts, self)
  end
end

#provision_vms(hosts) ⇒ Object

Raises:

  • (ArgumentError)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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/hypervisor/abs.rb', line 99

def provision_vms(hosts)

  verbose = false
  config = Conf.read_config # get the vmfloaty config file in home dir

  # TODO: the options object provided by the floaty cli is required in get_service_config()
  cli = Clifloaty.new(@abs_service_name, @abs_service_priority)

  #the service object is the interfacte to all methods
  abs_service = Service.new(cli, config)
  supported_vm_list = abs_service.list(verbose)
  supported_vm_list = supported_vm_list.reject { |e| e.empty? }
  supported_vm_list = supported_vm_list.reject { |e| e.start_with?("*") }

  vm_request = generate_floaty_request_strings(hosts, supported_vm_list)


  vm_beaker_abs = []
  # Will return a JSON Object like this:
  # {"redhat-7-x86_64"=>["rich-apparition.delivery.puppetlabs.net", "despondent-side.delivery.puppetlabs.net"], "centos-7-x86_64"=>["firmer-vamp.delivery.puppetlabs.net"]}
  os_types = Utils.generate_os_hash(vm_request.split)
  vm_floaty_output = abs_service.retrieve(verbose, os_types)


  raise ArgumentError.new("Timed out getting the ABS resources") if vm_floaty_output.nil?
  vm_floaty_output_cleaned = Utils.standardize_hostnames(vm_floaty_output)
  vm_floaty_output_cleaned.each do |os_platform, value|
    # filter any extra key that does not have an Array value
    if !value.is_a?(Array)
      next
    end
    value.each do | hostname |
      # I don't think the engine is being used by the beaker-abs process
      vm_beaker_abs.push({"hostname": hostname, "type": os_platform, "engine":"beaker-abs"})
    end
  end

  # to do need to figure out what the NSPooler requests are, and combine the output for that with vm_beaker_abs and return that object
  # for now just returning vmpooler abs object
  vm_beaker_abs
end