Sha256: 56ed23059f852f4907bf7f5a37a8aacbda6c734ffeb30bf7b84f7a16617d986b

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'rspec/core'
require 'rspec/mocks'
require 'rbovirt'
require 'yaml'

module OVIRT::RSpec

  # get ovirt ca certificate public key
  # * url - ovirt server url
  def ca_cert(url)
    ca_url = URI.parse(url)
    ca_url.path = "/ca.crt"
    http = Net::HTTP.new(ca_url.host, ca_url.port)
    http.use_ssl = (ca_url.scheme == 'https')
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    request = Net::HTTP::Get.new(ca_url.path)
    http.request(request).body
  end

  def setup_client(options = {})
    user, password, url, datacenter = endpoint
    cert = ca_cert(url)
    store = OpenSSL::X509::Store.new().add_cert(OpenSSL::X509::Certificate.new(cert))
    opts = { :ca_cert_store => store }
    @client = ::OVIRT::Client.new(user, password, url, opts)
    datacenter_id = @client.datacenters.find{|x| x.name == datacenter}.id rescue raise("Cannot find datacenter #{datacenter}")
    opts.merge!(:datacenter_id => datacenter_id)
    opts.merge! options
    @client = ::OVIRT::Client.new(user, password, url, opts)
  end

  def endpoint
    return config['user'], config['password'], config['url'], config['datacenter']
  end

  def cluster_name
    config['cluster'] || 'Default'
  end

  def network_name
    config['network'] || 'ovirtmgmt'
  end

  def support_user_level_api
    config['version'] && config['version'] > 3.1
  end

  def config
    @config ||= YAML.load(File.read(File.expand_path("endpoint.yml", File.dirname(__FILE__))))
  end

end

RSpec.configure do |config|
  config.include OVIRT::RSpec
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rbovirt-0.0.30 spec/spec_helper.rb