Browse Source

Fix config for ovs ethernet ports

L23module generates incorrect configuration file for
ethernet ports and corresponding bridges are missing it
after the reboot.

Change-Id: I0666a623352e42e999c181c29279a8c3566466d8
Closes-bug: #1514421
tags/7.0-eol
Stanislav Makar 3 years ago
parent
commit
7d7b076fe5

+ 9
- 3
deployment/puppet/l23network/lib/puppet/provider/l23_stored_config/ovs_ubuntu.rb View File

@@ -87,6 +87,10 @@ Puppet::Type.type(:l23_stored_config).provide(:ovs_ubuntu, :parent => Puppet::Pr
87 87
       header << "allow-#{bridge} #{provider.name}"
88 88
       props[:bridge]   = bridge
89 89
       provider.jacks   = nil
90
+    elsif provider.if_type.to_s == 'ethernet'
91
+      header << "allow-#{bridge} #{provider.name}"
92
+      props[:bridge]   = bridge
93
+      provider.jacks   = nil
90 94
     else
91 95
       header << "auto #{provider.name}" if provider.onboot
92 96
     end
@@ -98,14 +102,16 @@ Puppet::Type.type(:l23_stored_config).provide(:ovs_ubuntu, :parent => Puppet::Pr
98 102
 
99 103
   def self.unmangle__if_type(provider, val)
100 104
     val = "OVS#{val.to_s.capitalize}".to_sym
101
-    val = 'OVSPort' if val.to_s == 'OVSPatch'
105
+    val = 'OVSPort' if val.to_s == 'OVSEthernet'
106
+    val = 'OVSPort' if val.to_s == 'OVSPatch' # this is hack due to ovs 2.3 scripts do not support OVSPatchPort
102 107
     val = 'OVSIntPort' if val.to_s == 'OVSVport'
103 108
     val
104 109
   end
105 110
 
106 111
   def self.mangle__if_type(val)
107 112
     val = val.gsub('OVS', '').downcase.to_sym
108
-    val = :patch if val.to_s == 'port'
113
+    val = :ethernet if val.to_s == 'port'
114
+    val = :patch if val.to_s == 'port' # this is hack due to ovs 2.3 scripts do not support OVSPatchPort
109 115
     val = :vport if val.to_s == 'intport'
110 116
     val
111 117
   end
@@ -118,7 +124,7 @@ Puppet::Type.type(:l23_stored_config).provide(:ovs_ubuntu, :parent => Puppet::Pr
118 124
           :detect_shift => 3,
119 125
       },
120 126
       :vlan_id  => {
121
-          :detect_re    => /(ovs_)?extra\s+--\s+set\s+Port\s+(p_.*-[0 1])\s+tag=(\d+)/,
127
+          :detect_re    => /(ovs_)?extra\s+--\s+set\s+Port\s+(.*[\d+])\s+tag=(\d+)/,
122 128
           :detect_shift => 3,
123 129
       },
124 130
     })

+ 5
- 2
deployment/puppet/l23network/lib/puppet/provider/l2_port/ovs.rb View File

@@ -24,7 +24,7 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
24 24
     @old_property_hash = {}
25 25
     @property_flush = {}.merge! @resource
26 26
     #
27
-    cmd = ["add-port", @resource[:bridge], @resource[:interface]]
27
+    cmd = ['--may-exist', 'add-port', @resource[:bridge], @resource[:interface]]
28 28
     # # tag and trunks for port
29 29
     # port_properties = @resource[:port_properties]
30 30
     # if ![nil, :absent].include? @resource[:vlan_id] and @resource[:vlan_id] > 0
@@ -45,6 +45,9 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
45 45
       tt = "type=" + @resource[:type].to_s
46 46
     elsif File.exist? "/sys/class/net/#{@resource[:interface]}"
47 47
       tt = nil
48
+      # Flush ipaddr and routes for interface, then adding to the bridge
49
+      iproute('route', 'flush', 'dev', @resource[:interface])
50
+      iproute('addr', 'flush', 'dev', @resource[:interface])
48 51
     else
49 52
       tt = "type=internal"
50 53
     end
@@ -99,4 +102,4 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
99 102
   end
100 103
 
101 104
 end
102
-# vim: set ts=2 sw=2 et :
105
+# vim: set ts=2 sw=2 et :

+ 9
- 3
deployment/puppet/l23network/manifests/l2/port.pp View File

@@ -96,7 +96,7 @@ define l23network::l2::port (
96 96
   }
97 97
 
98 98
   if $delay_while_up and ! is_numeric($delay_while_up) {
99
-    fail("Delay for waiting after UP interface ${port} should be numeric, not an '$delay_while_up'.")
99
+    fail("Delay for waiting after UP interface ${port} should be numeric, not an '${delay_while_up}'.")
100 100
   }
101 101
 
102 102
   # # implicitly create bridge, if it given and not exists
@@ -123,9 +123,15 @@ define l23network::l2::port (
123 123
     # the device is treated as an Ethernet device
124 124
     # https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-networkscripts-interfaces_network-bridge.html
125 125
 
126
+    if $provider =~ /ovs/ {
127
+      $real_if_type = 'ethernet'
128
+    } else {
129
+      $real_if_type = $if_type
130
+    }
131
+
126 132
     L23_stored_config <| title == $port_name |> {
127 133
       ensure          => $ensure,
128
-      if_type         => $if_type,
134
+      if_type         => $real_if_type,
129 135
       bridge          => $bridge,
130 136
       vlan_id         => $port_vlan_id,
131 137
       vlan_dev        => $port_vlan_dev,
@@ -168,7 +174,7 @@ define l23network::l2::port (
168 174
         ensure  => present,
169 175
         owner   => 'root',
170 176
         mode    => '0755',
171
-        content => template("l23network/centos_post_up.erb"),
177
+        content => template('l23network/centos_post_up.erb'),
172 178
       } -> L23_stored_config <| title == $port_name |>
173 179
     } else {
174 180
       file {"${::l23network::params::interfaces_dir}/interface-up-script-${port_name}":

+ 5
- 0
deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/ubuntu_ports/ifcfg-p2p1 View File

@@ -0,0 +1,5 @@
1
+allow-br-ovs1 p2p1
2
+iface p2p1 inet manual
3
+ovs_type OVSPort
4
+ovs_bridge br-ovs1
5
+ovs_extra -- set Port p2p1 tag=100

+ 2
- 0
deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/ubuntu_ports/ifcfg-p2p2 View File

@@ -0,0 +1,2 @@
1
+auto p2p2
2
+iface p2p2 inet manual

+ 8
- 0
deployment/puppet/l23network/spec/spec_helper.rb View File

@@ -22,4 +22,12 @@ RSpec.configure do |c|
22 22
   c.mock_with(:mocha)
23 23
 end
24 24
 
25
+
26
+def puppet_debug_override
27
+  if ENV['SPEC_PUPPET_DEBUG']
28
+    Puppet::Util::Log.level = :debug
29
+    Puppet::Util::Log.newdestination(:console)
30
+  end
31
+end
32
+
25 33
 ###

+ 2
- 8
deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/lnx_ubuntu__ifconfig__spec.rb View File

@@ -41,10 +41,7 @@ describe Puppet::Type.type(:l23_stored_config).provider(:lnx_ubuntu) do
41 41
   end
42 42
 
43 43
   before(:each) do
44
-    if ENV['SPEC_PUPPET_DEBUG']
45
-      Puppet::Util::Log.level = :debug
46
-      Puppet::Util::Log.newdestination(:console)
47
-    end
44
+    puppet_debug_override()
48 45
   end
49 46
 
50 47
   def fixture_path
@@ -119,10 +116,7 @@ describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
119 116
   end
120 117
 
121 118
   before(:each) do
122
-    if ENV['SPEC_PUPPET_DEBUG']
123
-      Puppet::Util::Log.level = :debug
124
-      Puppet::Util::Log.newdestination(:console)
125
-    end
119
+    puppet_debug_override()
126 120
   end
127 121
 
128 122
   context "just eth interface with OVS provider" do

+ 80
- 0
deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/lnx_ubuntu__port__spec.rb View File

@@ -0,0 +1,80 @@
1
+require 'spec_helper'
2
+
3
+resources_map =     {
4
+      :'p2p2' => {
5
+                 :name     => 'p2p2',
6
+                 :if_type  => 'ethernet',
7
+                 :provider => 'lnx_ubuntu',
8
+               },
9
+}
10
+
11
+describe Puppet::Type.type(:l23_stored_config).provider(:lnx_ubuntu) do
12
+
13
+  let(:input_data) { resources_map}
14
+
15
+  let(:resources) do
16
+    resources = {}
17
+    input_data.each do |name, res|
18
+      resources.store name, Puppet::Type.type(:l23_stored_config).new(res)
19
+    end
20
+    return resources
21
+  end
22
+
23
+  let(:providers) do
24
+    providers = {}
25
+    resources.each do |name, resource|
26
+      provider = resource.provider
27
+      if ENV['SPEC_PUPPET_DEBUG']
28
+        class << provider
29
+          def debug(msg)
30
+            puts msg
31
+          end
32
+        end
33
+      end
34
+      provider.create
35
+      providers.store name, provider
36
+    end
37
+    return providers
38
+  end
39
+
40
+  before(:each) do
41
+    puppet_debug_override()
42
+  end
43
+
44
+  def fixture_path
45
+    File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'ubuntu_ports')
46
+  end
47
+
48
+  def fixture_file(file)
49
+    File.join(fixture_path, file)
50
+  end
51
+
52
+  def fixture_data(file)
53
+     File.read(fixture_file(file))
54
+  end
55
+
56
+  context "formating config files" do
57
+
58
+    context 'OVS port p2p2 ' do
59
+      subject { providers[:'p2p2'] }
60
+      let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
61
+      it { expect(cfg_file).to match(/auto\s+p2p2/) }
62
+      it { expect(cfg_file).to match(/iface\s+p2p2\s+inet\s+manual/) }
63
+      it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(2) }
64
+    end
65
+
66
+  end
67
+
68
+  context "parsing config files" do
69
+
70
+    context 'OVS port p2p2' do
71
+      let(:res) { subject.class.parse_file('p2p2', fixture_data('ifcfg-p2p2'))[0] }
72
+      it { expect(res[:method]).to eq :manual }
73
+      it { expect(res[:onboot]).to eq true }
74
+      it { expect(res[:name]).to eq 'p2p2' }
75
+      it { expect(res[:if_provider].to_s).to eq 'lnx' }
76
+    end
77
+
78
+  end
79
+
80
+end

+ 30
- 39
deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/ovs_ubuntu__port__spec.rb View File

@@ -1,22 +1,18 @@
1 1
 require 'spec_helper'
2
-require 'yaml'
2
+
3
+resources_map =     {
4
+      :'p2p1' => {
5
+                 :name     => 'p2p1',
6
+                 :if_type  => 'ethernet',
7
+                 :bridge   => 'br-ovs1',
8
+                 :vlan_id  => '100',
9
+                 :provider => 'ovs_ubuntu',
10
+               },
11
+}
3 12
 
4 13
 describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
5 14
 
6
-  let(:input_data) do
7
-    {
8
-      :ttt0 => {
9
-        :name           => 'ttt0',
10
-        :ensure         => 'present',
11
-        :bridge         => 'br9',
12
-        :if_type        => 'vport',
13
-        :mtu            => '6000',
14
-        :onboot         => true,
15
-        :method         => 'manual',
16
-        :provider       => 'ovs_ubuntu',
17
-      },
18
-    }
19
-  end
15
+  let(:input_data) { resources_map}
20 16
 
21 17
   let(:resources) do
22 18
     resources = {}
@@ -40,7 +36,7 @@ describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
40 36
       provider.create
41 37
       providers.store name, provider
42 38
     end
43
-    providers
39
+    return providers
44 40
   end
45 41
 
46 42
   before(:each) do
@@ -51,7 +47,7 @@ describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
51 47
   end
52 48
 
53 49
   def fixture_path
54
-    File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'ovs_ubuntu__spec')
50
+    File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'ubuntu_ports')
55 51
   end
56 52
 
57 53
   def fixture_file(file)
@@ -62,34 +58,29 @@ describe Puppet::Type.type(:l23_stored_config).provider(:ovs_ubuntu) do
62 58
      File.read(fixture_file(file))
63 59
   end
64 60
 
65
-  # context "the method property" do
66
-  #   context 'when dhcp' do
67
-  #     let(:data) { subject.class.parse_file('eth0', fixture_data('ifcfg-eth0'))[0] }
68
-  #     it { expect(data[:method]).to eq :dhcp }
69
-  #   end
70
-  # end
71
-
72
-  context "one OVS port, included to the OVS bridge" do
61
+  context "formating config files" do
73 62
 
74
-    context 'format file' do
75
-      subject { providers[:ttt0] }
63
+    context 'OVS port p2p1 ' do
64
+      subject { providers[:'p2p1'] }
76 65
       let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
77
-      it { expect(cfg_file).to match(/auto\s+ttt0/) }
78
-      it { expect(cfg_file).to match(/allow-br9\s+ttt0/) }
79
-      it { expect(cfg_file).to match(/iface\s+ttt0\s+inet\s+manual/) }
80
-      it { expect(cfg_file).to match(/mtu\s+6000/) }
81
-      it { expect(cfg_file).to match(/ovs_type\s+OVSIntPort/) }
82
-      it { expect(cfg_file).to match(/ovs_bridge\s+br9/) }
83
-      it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(6) }  #  no more lines in the interface file
66
+      it { expect(cfg_file).to match(/allow-br-ovs1\s+p2p1/) }
67
+      it { expect(cfg_file).to match(/iface\s+p2p1\s+inet\s+manual/) }
68
+      it { expect(cfg_file).to match(/ovs_type\s+OVSPort/) }
69
+      it { expect(cfg_file).to match(/ovs_bridge\s+br-ovs1/) }
70
+      it { expect(cfg_file).to match(/ovs_extra\s+--\s+set\s+Port\s+p2p1\st+ag=100/) }
71
+      it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(5) }
84 72
     end
85 73
 
86
-    context "parse data from fixture" do
87
-      let(:res) { subject.class.parse_file('bond_lacp', fixture_data('ifcfg-port'))[0] }
74
+  end
75
+
76
+  context "parsing config files" do
88 77
 
78
+    context 'OVS port p2p1' do
79
+      let(:res) { subject.class.parse_file('p2p1', fixture_data('ifcfg-p2p1'))[0] }
89 80
       it { expect(res[:method]).to eq :manual }
90
-      it { expect(res[:mtu]).to eq '6000' }
91
-      it { expect(res[:bridge]).to eq 'br9' }
92
-      it { expect(res[:if_type].to_s).to eq 'vport' }
81
+      it { expect(res[:name]).to eq 'p2p1' }
82
+      it { expect(res[:bridge]).to eq "br-ovs1" }
83
+      it { expect(res[:vlan_id]).to eq '100' }
93 84
       it { expect(res[:if_provider].to_s).to eq 'ovs' }
94 85
     end
95 86
 

Loading…
Cancel
Save