Openvswitch packages should be installed only if use_ovs=>true

This patch change following:
* don't install ovs packages if it is not required
* don't check ovs service if use_ovs == false
* no more usage of ovs-vsctl in commands for lnx provider
  if ovs-vsctl is in commands - puppet invalidates provider
  due to external tools can't be executed

Closes-bug: #1442672
Change-Id: I7ca7bfaa5fddc704c824df81b6e5a5a32ca726ca
This commit is contained in:
Sergey Vasilenko 2015-04-10 17:56:44 +03:00
parent c7d6bd13dd
commit fb392fddc2
10 changed files with 140 additions and 64 deletions

View File

@ -4,6 +4,16 @@ require 'yaml'
class Puppet::Provider::L2_base < Puppet::Provider
def self.ovs_vsctl(*cmd)
begin
ff = IO.popen(['ovs-vsctl'] + Array(*cmd))
rv = ff.readlines().map{|l| l.chomp()}
rescue
rv = nil
end
return rv
end
def self.prefetch(resources)
interfaces = instances
resources.keys.each do |name|
@ -130,13 +140,13 @@ class Puppet::Provider::L2_base < Puppet::Provider
def self.get_ovs_bridges
# return OVS interfaces hash if it possible
begin
vsctl_list_bridges = vsctl('list', 'Bridge').split("\n")
vsctl_list_bridges << :EOF # last section of output should be processsed anyway.
rescue
vsctl_list_bridges = ovs_vsctl(['list', 'Bridge'])
if vsctl_list_bridges.nil?
debug("Can't find OVS ports, because error while 'ovs-vsctl list Bridge' execution")
return {}
end
vsctl_list_bridges << :EOF # last section of output should be processsed anyway.
#
buff = {}
rv = {}
@ -167,13 +177,12 @@ class Puppet::Provider::L2_base < Puppet::Provider
def self.get_ovs_ports
# return OVS interfaces hash if it possible
begin
vsctl_list_ports = vsctl('list', 'Port').split("\n")
vsctl_list_ports << :EOF # last section of output should be processsed anyway.
rescue
vsctl_list_ports = ovs_vsctl(['list', 'Port'])
if vsctl_list_ports.nil?
debug("Can't find OVS ports, because error while 'ovs-vsctl list Port' execution")
return {}
end
vsctl_list_ports << :EOF # last section of output should be processsed anyway.
#
buff = {}
rv = {}
@ -203,13 +212,12 @@ class Puppet::Provider::L2_base < Puppet::Provider
def self.get_ovs_interfaces
# return OVS interfaces hash if it possible
begin
vsctl_list_interfaces = vsctl('list', 'Interface').split("\n")
vsctl_list_interfaces << :EOF # last section of output should be processsed anyway.
rescue
vsctl_list_interfaces = ovs_vsctl(['list', 'Interface'])
if vsctl_list_interfaces.nil?
debug("Can't find OVS interfaces, because error while 'ovs-vsctl list Interface' execution")
return {}
end
vsctl_list_interfaces << :EOF # last section of output should be processsed anyway.
#
buff = {}
rv = {}
@ -243,10 +251,8 @@ class Puppet::Provider::L2_base < Puppet::Provider
end
def self.ovs_vsctl_show
begin
#content = vsctl('show')
content = `ovs-vsctl show`
rescue
content = ovs_vsctl('show')
if content.nil?
debug("Can't get OVS configuration, because error while 'ovs-vsctl show' execution")
return {}
end
@ -264,7 +270,7 @@ class Puppet::Provider::L2_base < Puppet::Provider
_po = nil
_if = nil
#_ift = nil
content.split("\n").each do |line|
content.each do |line|
line.rstrip!
case line
when /^\s+Bridge\s+"?([\w\-\.]+)\"?$/
@ -357,15 +363,16 @@ class Puppet::Provider::L2_base < Puppet::Provider
bridges = {}
# obtain OVS bridges list
re_c = /^\s*([\w\-]+)/
begin
vsctl('list-br').split(/\n+/).select{|l| l.match(re_c)}.collect{|a| $1 if a.match(re_c)}.each do |br_name|
listbr = ovs_vsctl('list-br')
if listbr.nil?
debug("No OVS bridges found, because error while 'ovs-vsctl list-br' execution")
else
listbr.select{|l| l.match(re_c)}.collect{|a| $1 if a.match(re_c)}.each do |br_name|
br_name.strip!
bridges[br_name] = {
:br_type => :ovs
}
end
rescue
debug("No OVS bridges found, because error while 'ovs-vsctl list-br' execution")
end
# obtain LNX bridges list
re_c = /([\w\-]+)\s+\d+/
@ -393,15 +400,14 @@ class Puppet::Provider::L2_base < Puppet::Provider
# }
#
port_mappings = {}
begin
ovs_bridges = vsctl('list-br').split(/\n+/).select{|l| l.match(/^\s*[\w\-]+/)}
rescue
ovs_bridges = ovs_vsctl('list-br')
if ovs_bridges.nil?
debug("No OVS bridges found, because error while 'ovs-vsctl list-br' execution")
return {}
end
ovs_bridges.each do |br_name|
ovs_bridges.select{|l| l.match(/^\s*[\w\-]+/)}.each do |br_name|
br_name.strip!
ovs_portlist = vsctl('list-ports', br_name).split(/\n+/).select{|l| l.match(/^\s*[\w\-]+\s*/)}
ovs_portlist = ovs_vsctl(['list-ports', br_name]).select{|l| l.match(/^\s*[\w\-]+\s*/)}
#todo: handle error
ovs_portlist.each do |port_name|
port_name.strip!

View File

@ -8,8 +8,7 @@ Puppet::Type.type(:l2_bond).provide(:lnx, :parent => Puppet::Provider::Lnx_base)
defaultfor :osfamily => :linux
commands :iproute => 'ip',
:ethtool_cmd => 'ethtool',
:brctl => 'brctl',
:vsctl => 'ovs-vsctl'
:brctl => 'brctl'
def self.prefetch(resources)
@ -142,7 +141,7 @@ Puppet::Type.type(:l2_bond).provide(:lnx, :parent => Puppet::Provider::Lnx_base)
# do not remove bridge-based interface from his bridge
case port_bridges_hash[@resource[:bond]][:br_type]
when :ovs
vsctl('del-port', br_name, @resource[:bond])
ovs_vsctl(['del-port', br_name, @resource[:bond]])
# todo catch exception
when :lnx
brctl('delif', br_name, @resource[:bond])
@ -156,7 +155,7 @@ Puppet::Type.type(:l2_bond).provide(:lnx, :parent => Puppet::Provider::Lnx_base)
if !@property_flush[:bridge].nil? and @property_flush[:bridge].to_sym != :absent
case @bridges[@property_flush[:bridge]][:br_type]
when :ovs
vsctl('add-port', @property_flush[:bridge], @resource[:bond])
ovs_vsctl(['add-port', @property_flush[:bridge], @resource[:bond]])
when :lnx
brctl('addif', @property_flush[:bridge], @resource[:bond])
else

View File

@ -10,7 +10,6 @@ Puppet::Type.type(:l2_bridge).provide(:lnx, :parent => Puppet::Provider::Lnx_bas
defaultfor :osfamily => :linux
commands :brctl => 'brctl',
:ethtool_cmd => 'ethtool',
:vsctl => 'ovs-vsctl',
:iproute => 'ip'
def self.instances

View File

@ -5,7 +5,6 @@ Puppet::Type.type(:l2_port).provide(:lnx, :parent => Puppet::Provider::Lnx_base)
commands :iproute => 'ip',
:ethtool_cmd => 'ethtool',
:brctl => 'brctl',
:vsctl => 'ovs-vsctl',
:pkill => 'pkill'
@ -112,7 +111,7 @@ Puppet::Type.type(:l2_port).provide(:lnx, :parent => Puppet::Provider::Lnx_base)
# do not remove bridge-based interface from his bridge
case br_type
when :ovs
vsctl('del-port', br_name, @resource[:interface])
ovs_vsctl(['del-port', br_name, @resource[:interface]])
when :lnx
brctl('delif', br_name, @resource[:interface])
else
@ -124,7 +123,7 @@ Puppet::Type.type(:l2_port).provide(:lnx, :parent => Puppet::Provider::Lnx_base)
if !@property_flush[:bridge].nil? and @property_flush[:bridge].to_sym != :absent
case @bridges[@property_flush[:bridge]][:br_type]
when :ovs
vsctl('add-port', @property_flush[:bridge], @resource[:interface])
ovs_vsctl(['add-port', @property_flush[:bridge], @resource[:interface]])
when :lnx
begin
brctl('addif', @property_flush[:bridge], @resource[:interface])

View File

@ -4,13 +4,16 @@
# Requirements, packages and services.
#
class l23network (
$use_ovs = true,
$use_lnx = true,
$use_ovs = false,
$install_ovs = $use_ovs,
$install_brtool = $use_lnx,
$install_ethtool = $use_lnx,
$install_bondtool = $use_lnx,
$install_vlantool = $use_lnx,
$ovs_modname = undef,
$ovs_datapath_package_name = undef,
$ovs_common_package_name = undef,
){
include stdlib
@ -24,6 +27,9 @@ class l23network (
install_ethtool => $install_ethtool,
install_bondtool => $install_bondtool,
install_vlantool => $install_vlantool,
ovs_modname => $ovs_modname,
ovs_datapath_package_name => $ovs_datapath_package_name,
ovs_common_package_name => $ovs_common_package_name,
}
if $::l23network::params::interfaces_file {

View File

@ -4,14 +4,16 @@
# Requirements, packages and services.
#
class l23network::l2 (
$use_ovs = true,
$use_lnx = true,
$use_ovs = false,
$install_ovs = $use_ovs,
$install_brtool = $use_lnx,
$install_ethtool = $use_lnx,
$install_bondtool = $use_lnx,
$install_vlantool = $use_lnx,
$ovs_modname = 'openvswitch'
$ovs_modname = $::l23network::params::ovs_kern_module_name,
$ovs_datapath_package_name = $::l23network::params::ovs_datapath_package_name,
$ovs_common_package_name = $::l23network::params::ovs_common_package_name,
){
include stdlib
include ::l23network::params
@ -19,30 +21,33 @@ class l23network::l2 (
if $use_ovs {
$ovs_mod_ensure = present
if $install_ovs {
if $::l23network::params::ovs_datapath_package_name {
if $ovs_datapath_package_name {
package { 'openvswitch-datapath':
name => $::l23network::params::ovs_datapath_package_name
name => $ovs_datapath_package_name
}
Package['openvswitch-datapath'] -> Service['openvswitch-service']
}
package { 'openvswitch-common':
name => $::l23network::params::ovs_common_package_name
if $ovs_common_package_name {
package { 'openvswitch-common':
name => $ovs_common_package_name
}
Package['openvswitch-common'] ~> Service['openvswitch-service']
}
Package<| title=='openvswitch-datapath' |> -> Package['openvswitch-common']
Package['openvswitch-common'] ~> Service['openvswitch-service']
Package<| title=='openvswitch-datapath' |> -> Package<| title=='openvswitch-common' |>
}
$ovs_service_ensure = 'running'
service {'openvswitch-service':
ensure => 'running',
name => $::l23network::params::ovs_service_name,
enable => true,
hasstatus => true,
}
Service['openvswitch-service'] -> Anchor['l23network::l2::init']
} else {
$ovs_mod_ensure = absent
$ovs_service_ensure = 'stopped'
}
service {'openvswitch-service':
ensure => $ovs_service_ensure,
name => $::l23network::params::ovs_service_name,
enable => $ovs_service_ensure == 'running',
hasstatus => true,
}
Service['openvswitch-service'] -> Anchor['l23network::l2::init']
@k_mod{$ovs_modname:
ensure => $ovs_mod_ensure

View File

@ -15,6 +15,7 @@ class l23network::params {
$lnx_bridge_tools = 'bridge-utils'
$ovs_datapath_package_name = 'openvswitch-datapath-dkms'
$ovs_common_package_name = 'openvswitch-switch'
$ovs_kern_module_name = 'openvswitch'
}
/(?i)redhat/: {
$interfaces_dir = '/etc/sysconfig/network-scripts'
@ -27,6 +28,7 @@ class l23network::params {
$lnx_bridge_tools = 'bridge-utils'
$ovs_datapath_package_name = 'kmod-openvswitch'
$ovs_common_package_name = 'openvswitch'
$ovs_kern_module_name = 'openvswitch'
}
/(?i)darwin/: {
$interfaces_dir = '/tmp/1'

View File

@ -0,0 +1,67 @@
require 'spec_helper'
describe 'l23network', :type => :class do
context 'default init of l23network module' do
# let(:title) { 'empty network scheme' }
let(:facts) { {
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
} }
it do
should compile.with_all_deps
end
it do
should contain_package('bridge-utils').with_ensure('present')
should contain_package('ethtool').with_ensure('present')
should contain_package('ifenslave').with_ensure('present')
should contain_package('vlan').with_ensure('present')
end
end
context 'init l23network module with enabled OVS' do
#let(:title) { 'empty network scheme' }
let(:facts) { {
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:kernel => 'Linux',
:l23_os => 'ubuntu',
:l3_fqdn_hostname => 'stupid_hostname',
} }
let(:params) { {
:use_ovs => true
} }
it do
should compile.with_all_deps
end
it do
should contain_package('openvswitch-common').with({
'name' => 'openvswitch-switch'
})
should contain_package('bridge-utils').with_ensure('present')
should contain_package('ethtool').with_ensure('present')
should contain_package('ifenslave').with_ensure('present')
should contain_package('vlan').with_ensure('present')
end
it do
should contain_service('openvswitch-service').with({
'ensure' => 'running',
'name' => 'openvswitch-switch',
'enable' => true
})
end
end
end
###

View File

@ -0,0 +1 @@

View File

@ -2,20 +2,12 @@ notice('MODULAR: netconfig.pp')
$network_scheme = hiera('network_scheme')
class { 'l23network' :}
class { 'l23network' :
use_ovs => hiera('use_neutron', false)
}
prepare_network_config($network_scheme)
$sdn = generate_network_config()
notify {"SDN: ${sdn}": }
#todo(sv): temporary commented. Will be enabled later as part of
# 'disable-offloading' re-implementation
#if hiera('disable_offload') {
# L23network::L3::Ifconfig<||> {
# ethtool => {
# 'K' => ['gso off', 'gro off'],
# }
# }
#}
notify {"SDN": message=>"${sdn}" }
# setting kernel reserved ports