Skip to content

Commit

Permalink
Merge pull request #189 from rwaffen/beaker_fixes
Browse files Browse the repository at this point in the history
Beaker fixes
  • Loading branch information
rwaffen committed Sep 4, 2015
2 parents 3040d1f + 0f3e7f0 commit 577dd09
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 104 deletions.
5 changes: 2 additions & 3 deletions lib/puppet/provider/onecluster/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ def self.instances
def self.prefetch(resources)
clusters = instances
resources.keys.each do |name|
if provider = clusters.find{ |cluster| cluster.name == name }
resources[name].provider = provider
end
provider = clusters.find{ |cluster| cluster.name == name }
resources[name].provider = provider unless provider.nil?
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/puppet/provider/onedatastore/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ def self.instances
def self.prefetch(resources)
datastores = instances
resources.keys.each do |name|
if provider = datastores.find{ |datastore| datastore.name == name }
resources[name].provider = provider
end
provider = datastores.find{ |datastore| datastore.name == name }
resources[name].provider = provider unless provider.nil?
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/puppet/provider/onehost/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ def self.instances
def self.prefetch(resources)
hosts = instances
resources.keys.each do |name|
if provider = hosts.find{ |host| host.name == name }
resources[name].provider = provider
end
provider = hosts.find{ |host| host.name == name }
resources[name].provider = provider unless provider.nil?
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/puppet/provider/oneimage/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ def self.instances
def self.prefetch(resources)
images = instances
resources.keys.each do |name|
if provider = images.find{ |image| image.name == name }
resources[name].provider = provider
end
provider = images.find{ |image| image.name == name }
resources[name].provider = provider unless provider.nil?
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/puppet/provider/onesecgroup/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ def self.instances
def self.prefetch(resources)
secgroups = instances
resources.keys.each do |name|
if provider = secgroups.find{ |secgroup| secgroup.name == name }
resources[name].provider = provider
end
provider = secgroups.find{ |secgroup| secgroup.name == name }
resources[name].provider = provider unless provider.nil?
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/provider/onetemplate/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def create
end if resource[:context]
end
end
tempfile = builder.to_xml
file.write(tempfile)
file.close
self.debug "Creating template using #{tempfile}"
Expand Down Expand Up @@ -114,9 +115,8 @@ def self.instances
def self.prefetch(resources)
templates = instances
resources.keys.each do |name|
if provider = templates.find{ |template| template.name == name }
resources[name].provider = provider
end
provider = templates.find { |template| template.name == name }
resources[name].provider = provider unless provider.nil?
end
end

Expand Down
7 changes: 3 additions & 4 deletions lib/puppet/provider/onevm/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ def self.instances
def self.prefetch(resources)
vms = instances
resources.keys.each do |name|
if provider = vms.find{ |vm| vm.name == name }
resources[name].provider = provider
end
provider = vms.find{ |vm| vm.name == name }
resources[name].provider = provider unless provider.nil?
end
end

# setters
def template=(value)
raise "Can not modify a VM template"
raise 'Can not modify a VM template'
end
end
116 changes: 42 additions & 74 deletions lib/puppet/provider/onevnet/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
# Deutsche Post E-POST Development GmbH - 2014, 2015
#

#require 'pry'

require 'rubygems'
require 'nokogiri'

Puppet::Type.type(:onevnet).provide(:cli) do
desc "onevnet provider"
desc 'onevnet provider'

has_command(:onevnet, "onevnet") do
has_command(:onevnet, 'onevnet') do
environment :HOME => '/root', :ONE_AUTH => '/var/lib/one/.one/one_auth'
end

Expand All @@ -29,44 +27,18 @@
def create
file = Tempfile.new("onevnet-#{resource[:name]}")
builder = Nokogiri::XML::Builder.new do |xml|
xml.VNET do
xml.NAME resource[:name]
xml.BRIDGE resource[:bridge]
xml.PHYDEV do
resource[:phydev]
end if resource[:phydev]
xml.VLAN_ID do
resource[:vlanid]
end if resource[:vlanid]
xml.TEMPLATE do
xml.DNS do
resource[:dnsservers]
end
end if resource[:dnsservers]
xml.TEMPLATE do
xml.GATEWAY do
resource[:gateway]
end
end if resource[:gateway]
xml.TEMPLATE do
xml.NETWORK_MASK do
resource[:netmask]
end
end if resource[:netmask]
xml.TEMPLATE do
xml.NETWORK_ADDRESS do
resource[:network_address]
end
end if resource[:network_address]
xml.CONTEXT do
resource[:context].each do |k,v|
xml.send(k.upcase, v)
end if resource[:context]
end
end
# end xml vnet do
xml.VNET do
xml.NAME resource[:name]
xml.BRIDGE resource[:bridge]
xml.PHYDEV resource[:phydev] if resource[:phydev]
xml.VLAN_ID resource[:vlanid] if resource[:vlanid]
xml.DNS resource[:dnsservers].join(' ') if resource[:dnsservers]
xml.GATEWAY resource[:gateway] if resource[:gateway]
xml.NETWORK_MASK resource[:netmask] if resource[:netmask]
xml.NETWORK_ADDRESS resource[:network_address] if resource[:network_address]
xml.CONTEXT resource[:context].each { |k, v| xml.send(k.upcase, v) } if resource[:context]
end
end
# end builder
tempfile = builder.to_xml
file.write(tempfile)
file.close
Expand All @@ -89,31 +61,29 @@ def exists?

# Return the full hash of all existing onevnet resources
def self.instances
vnets = Nokogiri::XML(onevnet('list','-x')).root.xpath('/VNET_POOL/VNET')
#pry.binding
vnets.collect do |vnet|
new(
:name => vnet.xpath('./NAME').text,
:ensure => :present,
:bridge => vnet.xpath('./BRIDGE').text,
:context => nil,
:dnsservers => (vnet.xpath('./TEMPLATE/DNS').text.split(" ") unless vnet.xpath('./TEMPLATE/DNS').nil?),
:gateway => (vnet.xpath('./TEMPLATE/GATEWAY').text unless vnet.xpath('./TEMPLATE/GATEWAY').nil?),
:netmask => (vnet.xpath('./TEMPLATE/NETWORK_MASK').text unless vnet.xpath('./TEMPLATE/NETWORK_MASK').nil?),
:network_address => (vnet.xpath('./TEMPLATE/NETWORK_ADDRESS').text unless vnet.xpath('./TEMPLATE/NETWORK_ADDRESS').nil?),
:model => (vnet.xpath('./TEMPLATE/MODEL').text unless vnet.xpath('./TEMPLATE/MODEL').nil?),
:phydev => vnet.xpath('./PHYDEV').text,
:vlanid => vnet.xpath('./VLAN_ID').text
)
end
vnets = Nokogiri::XML(onevnet('list', '-x')).root.xpath('/VNET_POOL/VNET')
vnets.collect do |vnet|
new(
:ensure => :present,
:name => vnet.xpath('./NAME').text,
:bridge => vnet.xpath('./BRIDGE').text,
:phydev => vnet.xpath('./PHYDEV').text,
:vlanid => vnet.xpath('./VLAN_ID').text,
:context => nil,
:dnsservers => (vnet.xpath('./TEMPLATE/DNS').text.split(' ') unless vnet.xpath('./TEMPLATE/DNS').nil?),
:gateway => (vnet.xpath('./TEMPLATE/GATEWAY').text unless vnet.xpath('./TEMPLATE/GATEWAY').nil?),
:netmask => (vnet.xpath('./TEMPLATE/NETWORK_MASK').text unless vnet.xpath('./TEMPLATE/NETWORK_MASK').nil?),
:network_address => (vnet.xpath('./TEMPLATE/NETWORK_ADDRESS').text unless vnet.xpath('./TEMPLATE/NETWORK_ADDRESS').nil?),
:model => (vnet.xpath('./TEMPLATE/MODEL').text unless vnet.xpath('./TEMPLATE/MODEL').nil?)
)
end
end

def self.prefetch(resources)
vnets = instances
resources.keys.each do |name|
if provider = vnets.find{ |vnet| vnet.name == name }
resources[name].provider = provider
end
provider = vnets.find { |vnet| vnet.name == name }
resources[name].provider = provider unless provider.nil?
end
end

Expand All @@ -122,24 +92,22 @@ def flush
file << @property_hash.map { |k, v|
unless resource[k].nil? or resource[k].to_s.empty? or [:name, :provider, :ensure].include?(k)
case k
when :vlanid
[ 'VLAN_ID', v ]
when :addressrange
k.each_pair do |key, value|
end
when :dnsservers
[ 'DNS', "\"#{v.join(" ")}\"" ]
when :netmask
[ 'NETWORK_MASK', v ]
else
[ k.to_s.upcase, v ]
when :vlanid
['VLAN_ID', v]
when :addressrange
k.each_pair { |key, value|}
when :dnsservers
['DNS', "\"#{v.join(' ')}\""]
when :netmask
['NETWORK_MASK', v]
else
[k.to_s.upcase, v]
end
end
}.map{|a| "#{a[0]} = #{a[1]}" unless a.nil? }.join("\n")
}.map { |a| "#{a[0]} = #{a[1]}" unless a.nil? }.join("\n")
file.close
self.debug(IO.read file.path)
onevnet('update', resource[:name], file.path, '--append') unless @property_hash.empty?
file.delete
end

end
11 changes: 6 additions & 5 deletions lib/puppet/provider/onevnet_addressrange/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ def self.instances
def self.prefetch(resources)
vnets = instances
resources.keys.each do |name|
if provider = vnets.find{ |vnet| vnet.name == name }
resources[name].provider = provider
end
provider = vnets.find{ |vnet| vnet.name == name }
resources[name].provider = provider unless provider.nil?
end
end

Expand All @@ -109,12 +108,14 @@ def flush
end
end
}.map{|a| "#{a[0]} = #{a[1]}," unless a.nil? }.join("\n")
file << "AR_ID = #{ar_id}" unless ar_id.nil?
file << "AR_ID = #{resource[:ar_id]}" unless resource[:ar_id].nil?
file << ']'
file.close
self.debug(IO.read file.path)
self.debug(@property_hash)
onevnet('updatear', resource[:onevnet_name], ar_id, file.path ) unless ( @property_hash.empty? or ar_id.nil? or !defined? ar_id )
unless @property_hash.empty? or resource[:ar_id].nil? or not defined? resource[:ar_id]
onevnet('updatear', resource[:onevnet_name], resource[:ar_id], file.path)
end
file.delete
end

Expand Down
3 changes: 1 addition & 2 deletions spec/acceptance/onesecgroup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
before :all do
pp =<<-EOS
class { 'one':
oned => true,
one_version => '4.12',
oned => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/onevnet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class { 'one':
onevnet_addressrange { 'ar3':
ensure => present,
onevnet_name => 'vnet2',
onevnet_name => 'vnet3',
protocol => ip6,
ip_size => '10',
mac => '02:00:0a:00:00:96',
Expand Down

0 comments on commit 577dd09

Please sign in to comment.