Base code for remove OVS usage ability
Change-Id: I8ba876fad0a942b65b06b101abc3f41abaad6650 Blueprint: graph-concept-extension
This commit is contained in:
parent
8318d70565
commit
85ea4c7522
|
@ -0,0 +1,65 @@
|
|||
require 'yaml'
|
||||
|
||||
Puppet::Parser::Functions::newfunction( :remove_ovs_usage,
|
||||
:type => :rvalue, :doc => <<-EOS
|
||||
This function get network_scheme and returns mangled
|
||||
network scheme without ovs-based elements.
|
||||
EOS
|
||||
) do |argv|
|
||||
|
||||
def bridge_name_max_len
|
||||
15
|
||||
end
|
||||
|
||||
if argv.size != 1
|
||||
raise(
|
||||
Puppet::ParseError,
|
||||
"remove_ovs_usage(): Wrong number of arguments. Should be two."
|
||||
)
|
||||
end
|
||||
if !argv[0].is_a?(Hash)
|
||||
raise(
|
||||
Puppet::ParseError,
|
||||
"remove_ovs_usage(): Wrong network_scheme. Should be non-empty Hash."
|
||||
)
|
||||
end
|
||||
if argv[0]['version'].to_s.to_f < 1.1
|
||||
raise(
|
||||
Puppet::ParseError,
|
||||
"remove_ovs_usage(): You network_scheme hash has wrong format.\nThis parser can work with v1.1 format, please convert you config."
|
||||
)
|
||||
end
|
||||
|
||||
network_scheme = argv[0]
|
||||
rv = {
|
||||
'use_ovs' => false
|
||||
}
|
||||
overrides = []
|
||||
|
||||
network_scheme['transformations'].each do |tr|
|
||||
if tr['provider'] == 'ovs'
|
||||
if tr['action'] == 'add-patch'
|
||||
overrides << {
|
||||
'action' => 'override',
|
||||
'override' => "patch-#{tr['bridges'][0]}:#{tr['bridges'][1]}",
|
||||
'provider' => 'lnx'
|
||||
}
|
||||
else
|
||||
overrides << {
|
||||
'action' => 'override',
|
||||
'override' => tr['name'],
|
||||
'provider' => 'lnx'
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ! overrides.empty?
|
||||
rv['network_scheme'] = {
|
||||
'transformations' => overrides
|
||||
}
|
||||
end
|
||||
|
||||
return rv.to_yaml() + "\n"
|
||||
end
|
||||
# vim: set ts=2 sw=2 et :
|
|
@ -17,6 +17,7 @@ class osnailyfacter::hiera::hiera {
|
|||
'override/configuration/role%{disable_globals_yaml}',
|
||||
'override/configuration/cluster%{disable_globals_yaml}',
|
||||
'override/configuration/default_route%{disable_globals_yaml}',
|
||||
'override/configuration/remove_ovs_usage%{disable_globals_yaml}',
|
||||
'class/%{calling_class}%{disable_globals_yaml}',
|
||||
'module/%{calling_module}%{disable_globals_yaml}',
|
||||
'deleted_nodes%{disable_globals_yaml}',
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class osnailyfacter::netconfig::remove_ovs_usage {
|
||||
notice('MODULAR: netconfig/remove_ovs_usage.pp')
|
||||
|
||||
$network_scheme = hiera_hash('network_scheme', {})
|
||||
$overrides = remove_ovs_usage($network_scheme)
|
||||
|
||||
file {"/etc/hiera/override/configuration/remove_ovs_usage.yaml":
|
||||
ensure => file,
|
||||
content => inline_template("<%= @overrides %>")
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
class { '::osnailyfacter::netconfig::remove_ovs_usage' :}
|
|
@ -0,0 +1,102 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'remove_ovs_usage' do
|
||||
|
||||
let(:input_without_transformations) {
|
||||
{
|
||||
'version' => 1.2,
|
||||
'transformations' => {},
|
||||
}
|
||||
}
|
||||
|
||||
let(:output_without_transformations) {
|
||||
{
|
||||
'use_ovs' => false,
|
||||
}
|
||||
}
|
||||
|
||||
let(:i_w_nonpatch) {
|
||||
{
|
||||
'version' => 1.2,
|
||||
'transformations' => [
|
||||
{
|
||||
'provider' => 'ovs',
|
||||
'action' => 'foo',
|
||||
'name' => 'bar',
|
||||
}
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
let(:o_w_nonpatch) {
|
||||
{
|
||||
'use_ovs' => false,
|
||||
'network_scheme' => {
|
||||
'transformations' => [
|
||||
{
|
||||
'action' => 'override',
|
||||
'override' => 'bar',
|
||||
'provider' => 'lnx',
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let(:i_w_patch) {
|
||||
{
|
||||
'version' => 1.2,
|
||||
'transformations' => [
|
||||
{
|
||||
'provider' => 'ovs',
|
||||
'action' => 'add-patch',
|
||||
'name' => 'bar',
|
||||
'bridges' => [
|
||||
'bridge-0',
|
||||
'bridge-1',
|
||||
]
|
||||
}
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
let(:o_w_patch) {
|
||||
{
|
||||
'use_ovs' => false,
|
||||
'network_scheme' => {
|
||||
'transformations' => [
|
||||
{
|
||||
'action' => 'override',
|
||||
'override' => 'patch-bridge-0:bridge-1',
|
||||
'provider' => 'lnx',
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it 'should exist' do
|
||||
is_expected.not_to be_nil
|
||||
end
|
||||
|
||||
it 'should expect 1 argument' do
|
||||
is_expected.to run.with_params().and_raise_error(Puppet::ParseError)
|
||||
is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError)
|
||||
end
|
||||
|
||||
it 'should expect a hash as given argument' do
|
||||
is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError)
|
||||
end
|
||||
|
||||
it 'should return a hash with disabled ovs in any case' do
|
||||
is_expected.to run.with_params(input_without_transformations).and_return(output_without_transformations.to_yaml() + "\n")
|
||||
end
|
||||
|
||||
it 'should return a proper hash when override action is not add-patch' do
|
||||
is_expected.to run.with_params(i_w_nonpatch).and_return(o_w_nonpatch.to_yaml() + "\n")
|
||||
end
|
||||
|
||||
it 'should return a proper hash when override action is an add-patch' do
|
||||
is_expected.to run.with_params(i_w_patch).and_return(o_w_patch.to_yaml() + "\n")
|
||||
end
|
||||
end
|
|
@ -0,0 +1,22 @@
|
|||
# ROLE: virt
|
||||
# ROLE: primary-controller
|
||||
# ROLE: controller
|
||||
require 'spec_helper'
|
||||
require 'shared-examples'
|
||||
manifest = 'netconfig/remove_ovs_usage.pp'
|
||||
describe manifest do
|
||||
before(:each) do
|
||||
Noop.puppet_function_load :remove_ovs_usage
|
||||
MockFunction.new(:remove_ovs_usage) do |function|
|
||||
allow(function).to receive(:call).and_return(true)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'catalog' do
|
||||
let(:network_scheme) {
|
||||
{}
|
||||
}
|
||||
it { should contain_file('/etc/hiera/override/configuration/remove_ovs_usage.yaml') }
|
||||
end
|
||||
test_ubuntu_and_centos manifest
|
||||
end
|
Loading…
Reference in New Issue