Browse Source

Implement Ovs2Ovs patch support CentOS7/RHEL7

*Implement tags for ovs2ovs patch for Centos7/RHEL7
*Implement ovs port for Ubuntu and Centos7/RHEL7
*Test coverage

Change-Id: I553a9d152f83b6a24ab5a5a3e4bb6bf41edbb303
Closes-bug: #1514421
tags/8.0
Stanislav Makar 3 years ago
parent
commit
14a5becf1d
17 changed files with 589 additions and 47 deletions
  1. 9
    3
      deployment/puppet/l23network/lib/puppet/provider/l23_stored_config/ovs_ubuntu.rb
  2. 27
    0
      deployment/puppet/l23network/lib/puppet/provider/l23_stored_config_ovs_centos.rb
  3. 2
    2
      deployment/puppet/l23network/lib/puppet/provider/l2_port/ovs.rb
  4. 9
    3
      deployment/puppet/l23network/manifests/l2/port.pp
  5. 7
    0
      deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_patches/ifcfg-ovs2ovs-patch1
  6. 7
    0
      deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_patches/ifcfg-ovs2ovs-patch2
  7. 8
    0
      deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_patches/ifcfg-ovs2ovs-tag
  8. 5
    0
      deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_ports/ifcfg-lnx-port
  9. 4
    0
      deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_ports/ifcfg-lnx-port2
  10. 6
    0
      deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_ports/ifcfg-ovs-port
  11. 5
    0
      deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/ubuntu_ports/ifcfg-p2p1
  12. 2
    0
      deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/ubuntu_ports/ifcfg-p2p2
  13. 123
    0
      deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/lnx_centos7__port__spec.rb
  14. 80
    0
      deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/lnx_ubuntu__port__spec.rb
  15. 169
    0
      deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/ovs_centos7__ovs2ovs_patch__spec.rb
  16. 96
    0
      deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/ovs_centos7__port__spec.rb
  17. 30
    39
      deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/ovs_ubuntu__port__spec.rb

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

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

+ 27
- 0
deployment/puppet/l23network/lib/puppet/provider/l23_stored_config_ovs_centos.rb View File

@@ -6,6 +6,8 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
6 6
     rv = super
7 7
     rv.merge!({
8 8
       :devicetype     => 'DEVICETYPE',
9
+      :vlan_id        => 'OVS_OPTIONS',
10
+      :jacks          => 'OVS_PATCH_PEER',
9 11
       :bridge         => 'OVS_BRIDGE',
10 12
       :lnx_bridge     => 'BRIDGE',
11 13
       :bond_slaves    => 'BOND_IFACES',
@@ -22,6 +24,12 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
22 24
     return rv
23 25
   end
24 26
 
27
+  def self.boolean_properties
28
+    rv = super
29
+    rv.delete(:vlan_id)
30
+    return rv
31
+  end
32
+
25 33
   def self.properties_fake
26 34
     rv = super
27 35
     rv.push(:devicetype)
@@ -119,15 +127,27 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
119 127
   def self.unmangle__if_type(provider, val)
120 128
     val = "OVS#{val.to_s.capitalize}".to_sym
121 129
     val = 'OVSIntPort' if val.to_s == 'OVSVport'
130
+    val = 'OVSPort' if val.to_s == 'OVSEthernet'
131
+    val = 'OVSPatchPort' if val.to_s == 'OVSPatch'
122 132
     val
123 133
   end
124 134
 
125 135
   def self.mangle__if_type(val)
126 136
     val = val.gsub('OVS', '').downcase.to_sym
127 137
     val = :vport if val.to_s == 'intport'
138
+    val = :ethernet if val.to_s == 'port'
139
+    val = :patch if val.to_s == 'patchport'
128 140
     val
129 141
   end
130 142
 
143
+  def self.unmangle__jacks(provider, val)
144
+    val.join()
145
+  end
146
+
147
+  def self.mangle__jacks(val)
148
+    val.split(' ')
149
+  end
150
+
131 151
   def self.unmangle__bond_slaves(provider, val)
132 152
     "\"#{val.join(' ')}\""
133 153
   end
@@ -148,7 +168,14 @@ class Puppet::Provider::L23_stored_config_ovs_centos < Puppet::Provider::L23_sto
148 168
     val.split(' ')
149 169
   end
150 170
 
171
+  def self.unmangle__vlan_id(provider, val)
172
+    "\"tag=#{val}\""
173
+  end
151 174
 
175
+  def self.mangle__vlan_id(val)
176
+    val =  val.gsub('"', '').split('=')[1]
177
+    val
178
+  end
152 179
 
153 180
 end
154 181
 

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

@@ -22,7 +22,7 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
22 22
     @old_property_hash = {}
23 23
     @property_flush = {}.merge! @resource
24 24
     #
25
-    cmd = ["add-port", @resource[:bridge], @resource[:interface]]
25
+    cmd = ['--may-exist', 'add-port', @resource[:bridge], @resource[:interface]]
26 26
     # # tag and trunks for port
27 27
     # port_properties = @resource[:port_properties]
28 28
     # if ![nil, :absent].include? @resource[:vlan_id] and @resource[:vlan_id] > 0
@@ -97,4 +97,4 @@ Puppet::Type.type(:l2_port).provide(:ovs, :parent => Puppet::Provider::Ovs_base)
97 97
   end
98 98
 
99 99
 end
100
-# vim: set ts=2 sw=2 et :
100
+# 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}":

+ 7
- 0
deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_patches/ifcfg-ovs2ovs-patch1 View File

@@ -0,0 +1,7 @@
1
+BOOTPROTO=none
2
+DEVICE=ovs2ovs-patch1
3
+ONBOOT=yes
4
+TYPE=OVSPatchPort
5
+OVS_BRIDGE=ovs-br1
6
+OVS_PATCH_PEER=ovs2ovs-patch2
7
+DEVICETYPE=ovs

+ 7
- 0
deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_patches/ifcfg-ovs2ovs-patch2 View File

@@ -0,0 +1,7 @@
1
+BOOTPROTO=none
2
+DEVICE=ovs2ovs-patch2
3
+ONBOOT=yes
4
+TYPE=OVSPatchPort
5
+OVS_BRIDGE=ovs-br2
6
+OVS_PATCH_PEER=ovs2ovs-patch1
7
+DEVICETYPE=ovs

+ 8
- 0
deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_patches/ifcfg-ovs2ovs-tag View File

@@ -0,0 +1,8 @@
1
+BOOTPROTO=none
2
+DEVICE=ovs2ovs-tag
3
+ONBOOT=yes
4
+OVS_OPTIONS="tag=3"
5
+TYPE=OVSPatchPort
6
+OVS_BRIDGE=ovs-brt2
7
+OVS_PATCH_PEER=ovs2ovs-patcht1
8
+DEVICETYPE=ovs

+ 5
- 0
deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_ports/ifcfg-lnx-port View File

@@ -0,0 +1,5 @@
1
+BOOTPROTO=none
2
+DEVICE=lnx-port
3
+ONBOOT=yes
4
+MTU=9000
5
+TYPE=Ethernet

+ 4
- 0
deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_ports/ifcfg-lnx-port2 View File

@@ -0,0 +1,4 @@
1
+BOOTPROTO=none
2
+DEVICE=lnx-port2
3
+ONBOOT=yes
4
+MTU=9000

+ 6
- 0
deployment/puppet/l23network/spec/fixtures/provider/l23_stored_config/centos7_ports/ifcfg-ovs-port View File

@@ -0,0 +1,6 @@
1
+BOOTPROTO=none
2
+DEVICE=ovs-port
3
+ONBOOT=yes
4
+MTU=9000
5
+TYPE=OVSPort
6
+DEVICETYPE=ovs

+ 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

+ 123
- 0
deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/lnx_centos7__port__spec.rb View File

@@ -0,0 +1,123 @@
1
+require 'spec_helper'
2
+require 'yaml'
3
+
4
+describe Puppet::Type.type(:l23_stored_config).provider(:lnx_centos7) do
5
+
6
+  let(:facts) do
7
+    {
8
+      :osfamily => 'Redhat',
9
+      :operatingsystem => 'CentOS',
10
+      :l23_os => 'centos7',
11
+    }
12
+  end
13
+
14
+  let(:input_data) do
15
+    {
16
+      :lnx_port => {
17
+        :name           => 'lnx-port',
18
+        :ensure         => 'present',
19
+        :if_type        => 'ethernet',
20
+        :mtu            => '9000',
21
+        :onboot         => true,
22
+        :method         => 'manual',
23
+        :provider       => 'lnx_centos7',
24
+      },
25
+      :lnx_port_without_type => {
26
+        :name           => 'lnx-port2',
27
+        :ensure         => 'present',
28
+        :mtu            => '9000',
29
+        :onboot         => true,
30
+        :method         => 'manual',
31
+        :provider       => 'lnx_centos7',
32
+      },
33
+
34
+    }
35
+  end
36
+
37
+  let(:resources) do
38
+    resources = {}
39
+    input_data.each do |name, res|
40
+      resources.store name, Puppet::Type.type(:l23_stored_config).new(res)
41
+    end
42
+    resources
43
+  end
44
+
45
+  let(:providers) do
46
+    providers = {}
47
+    resources.each do |name, resource|
48
+      provider = resource.provider
49
+      if ENV['SPEC_PUPPET_DEBUG']
50
+        class << provider
51
+          def debug(msg)
52
+            puts msg
53
+          end
54
+        end
55
+      end
56
+      provider.create
57
+      providers.store name, provider
58
+    end
59
+    providers
60
+  end
61
+
62
+  before(:each) do
63
+    puppet_debug_override()
64
+  end
65
+
66
+  def fixture_path
67
+    File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'centos7_ports')
68
+  end
69
+
70
+  def fixture_file(file)
71
+    File.join(fixture_path, file)
72
+  end
73
+
74
+  def fixture_data(file)
75
+     File.read(fixture_file(file))
76
+  end
77
+
78
+  context "lnx port" do
79
+
80
+    context 'format file for lnx-port' do
81
+      subject { providers[:lnx_port] }
82
+      let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
83
+      it { expect(cfg_file).to match(%r{DEVICE=lnx-port}) }
84
+      it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
85
+      it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
86
+      it { expect(cfg_file).to match(%r{TYPE=Ethernet}) }
87
+      it { expect(cfg_file).to match(%r{MTU=9000}) }
88
+      it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(5) }  #  no more lines in the interface file
89
+    end
90
+
91
+    context 'format file for lnx-port2 without type' do
92
+      subject { providers[:lnx_port_without_type] }
93
+      let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
94
+      it { expect(cfg_file).to match(%r{DEVICE=lnx-port2}) }
95
+      it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
96
+      it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
97
+      it { expect(cfg_file).to match(%r{MTU=9000}) }
98
+      it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(4) }  #  no more lines in the interface file
99
+    end
100
+
101
+
102
+    context "parse port lnx-port data from fixture" do
103
+      let(:res) { subject.class.parse_file('lnx-port', fixture_data('ifcfg-lnx-port'))[0] }
104
+      it { expect(res[:name]).to eq 'lnx-port' }
105
+      it { expect(res[:if_type].to_s).to eq 'ethernet' }
106
+      it { expect(res[:method].to_s).to eq 'manual' }
107
+      it { expect(res[:mtu]).to eq '9000' }
108
+      it { expect(res[:onboot]).to eq true }
109
+      it { expect(res[:provider]).to eq :lnx_centos7 }
110
+    end
111
+
112
+    context "parse port lnx-port2 data from fixture" do
113
+      let(:res) { subject.class.parse_file('lnx-port2', fixture_data('ifcfg-lnx-port2'))[0] }
114
+      it { expect(res[:name]).to eq 'lnx-port2' }
115
+      it { expect(res[:method].to_s).to eq 'manual' }
116
+      it { expect(res[:mtu]).to eq '9000' }
117
+      it { expect(res[:onboot]).to eq true }
118
+      it { expect(res[:provider]).to eq :lnx_centos7 }
119
+    end
120
+
121
+  end
122
+
123
+end

+ 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

+ 169
- 0
deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/ovs_centos7__ovs2ovs_patch__spec.rb View File

@@ -0,0 +1,169 @@
1
+require 'spec_helper'
2
+require 'yaml'
3
+
4
+describe Puppet::Type.type(:l23_stored_config).provider(:ovs_centos7) do
5
+
6
+  let(:facts) do
7
+    {
8
+      :osfamily => 'Redhat',
9
+      :operatingsystem => 'CentOS',
10
+      :l23_os => 'centos7',
11
+    }
12
+  end
13
+
14
+  let(:input_data) do
15
+    {
16
+      :ovs2ovs_patch1 => {
17
+        :name           => 'ovs2ovs-patch1',
18
+        :ensure         => 'present',
19
+        :if_type        => 'patch',
20
+        :bridge         => ['ovs-br1'],
21
+        :jacks          => ['ovs2ovs-patch2'],
22
+        :onboot         => true,
23
+        :method         => 'manual',
24
+        :provider       => 'ovs_centos7',
25
+      },
26
+      :ovs2ovs_patch2 => {
27
+        :name           => 'ovs2ovs-patch2',
28
+        :ensure         => 'present',
29
+        :if_type        => 'patch',
30
+        :bridge         => ['ovs-br2'],
31
+        :jacks          => ['ovs2ovs-patch1'],
32
+        :onboot         => true,
33
+        :method         => 'manual',
34
+        :provider       => 'ovs_centos7',
35
+      },
36
+      :ovs2ovs_patch_with_tag => {
37
+        :name           => 'ovs2ovs-tag',
38
+        :ensure         => 'present',
39
+        :if_type        => 'patch',
40
+        :bridge         => ['ovs-brt2'],
41
+        :jacks          => ['ovs2ovs-patcht1'],
42
+        :vlan_id        => 3,
43
+        :onboot         => true,
44
+        :method         => 'manual',
45
+        :provider       => 'ovs_centos7',
46
+      },
47
+    }
48
+  end
49
+
50
+  let(:resources) do
51
+    resources = {}
52
+    input_data.each do |name, res|
53
+      resources.store name, Puppet::Type.type(:l23_stored_config).new(res)
54
+    end
55
+    return resources
56
+  end
57
+
58
+  let(:providers) do
59
+    providers = {}
60
+    resources.each do |name, resource|
61
+      provider = resource.provider
62
+      if ENV['SPEC_PUPPET_DEBUG']
63
+        class << provider
64
+          def debug(msg)
65
+            puts msg
66
+          end
67
+        end
68
+      end
69
+      provider.create
70
+      providers.store name, provider
71
+    end
72
+    providers
73
+  end
74
+
75
+  before(:each) do
76
+    puppet_debug_override()
77
+  end
78
+
79
+  def fixture_path
80
+    File.join(PROJECT_ROOT, 'spec', 'fixtures', 'provider', 'l23_stored_config', 'centos7_patches')
81
+  end
82
+
83
+  def fixture_file(file)
84
+    File.join(fixture_path, file)
85
+  end
86
+
87
+  def fixture_data(file)
88
+     File.read(fixture_file(file))
89
+  end
90
+
91
+  context "ovs2ovs patch" do
92
+
93
+    context 'format ovs2ovs-patch2 file' do
94
+      subject { providers[:ovs2ovs_patch1] }
95
+      let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
96
+      it { expect(cfg_file).to match(%r{DEVICE=ovs2ovs-patch1}) }
97
+      it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
98
+      it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
99
+      it { expect(cfg_file).to match(%r{TYPE=OVSPatchPort}) }
100
+      it { expect(cfg_file).to match(%r{OVS_BRIDGE=ovs-br1}) }
101
+      it { expect(cfg_file).to match(%r{OVS_PATCH_PEER=ovs2ovs-patch2}) }
102
+      it { expect(cfg_file).to match(%r{DEVICETYPE=ovs}) }
103
+      it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(7) }  #  no more lines in the interface file
104
+    end
105
+
106
+    context 'format ovs2ovs-patch2 file' do
107
+      subject { providers[:ovs2ovs_patch2] }
108
+      let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
109
+      it { expect(cfg_file).to match(%r{DEVICE=ovs2ovs-patch2}) }
110
+      it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
111
+      it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
112
+      it { expect(cfg_file).to match(%r{TYPE=OVSPatchPort}) }
113
+      it { expect(cfg_file).to match(%r{OVS_BRIDGE=ovs-br2}) }
114
+      it { expect(cfg_file).to match(%r{OVS_PATCH_PEER=ovs2ovs-patch1}) }
115
+      it { expect(cfg_file).to match(%r{DEVICETYPE=ovs}) }
116
+      it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(7) }  #  no more lines in the interface file
117
+    end
118
+
119
+    context 'format ovs2ovs-patch with tag file' do
120
+      subject { providers[:ovs2ovs_patch_with_tag] }
121
+      let(:cfg_file) { subject.class.format_file('filepath', [subject]) }
122
+      it { expect(cfg_file).to match(%r{DEVICE=ovs2ovs-tag}) }
123
+      it { expect(cfg_file).to match(%r{BOOTPROTO=none}) }
124
+      it { expect(cfg_file).to match(%r{ONBOOT=yes}) }
125
+      it { expect(cfg_file).to match(%r{TYPE=OVSPatchPort}) }
126
+      it { expect(cfg_file).to match(%r{OVS_BRIDGE=ovs-brt2}) }
127
+      it { expect(cfg_file).to match(%r{OVS_PATCH_PEER=ovs2ovs-patcht1}) }
128
+      it { expect(cfg_file).to match(%r{OVS_OPTIONS="tag=3"}) }
129
+      it { expect(cfg_file).to match(%r{DEVICETYPE=ovs}) }
130
+      it { expect(cfg_file.split(/\n/).reject{|x| x=~/^\s*$/}.length). to eq(8) }  #  no more lines in the interface file
131
+    end
132
+
133
+    context "parse ovs2ovs-patch1 data from fixture" do
134
+      let(:res) { subject.class.parse_file('ovs2ovs-patch1', fixture_data('ifcfg-ovs2ovs-patch1'))[0] }
135
+      it { expect(res[:name]).to eq 'ovs2ovs-patch1' }
136
+      it { expect(res[:if_type].to_s).to eq 'patch' }
137
+      it { expect(res[:bridge]).to match_array(['ovs-br1']) }
138
+      it { expect(res[:jacks]).to match_array(['ovs2ovs-patch2']) }
139
+      it { expect(res[:method].to_s).to eq 'manual' }
140
+      it { expect(res[:onboot]).to eq true }
141
+      it { expect(res[:provider].to_s).to eq 'ovs_centos7' }
142
+    end
143
+
144
+    context "parse ovs2ovs-patch2 data from fixture" do
145
+      let(:res) { subject.class.parse_file('ovs2ovs-patch2', fixture_data('ifcfg-ovs2ovs-patch2'))[0] }
146
+      it { expect(res[:name]).to eq 'ovs2ovs-patch2' }
147
+      it { expect(res[:if_type].to_s).to eq 'patch' }
148
+      it { expect(res[:bridge]).to match_array(['ovs-br2']) }
149
+      it { expect(res[:jacks]).to match_array(['ovs2ovs-patch1']) }
150
+      it { expect(res[:method].to_s).to eq 'manual' }
151
+      it { expect(res[:onboot]).to eq true }
152
+      it { expect(res[:provider].to_s).to eq 'ovs_centos7' }
153
+    end
154
+
155
+    context "parse ovs2ovs-tag data from fixture" do
156
+      let(:res) { subject.class.parse_file('ovs2ovs-tag', fixture_data('ifcfg-ovs2ovs-tag'))[0] }
157
+      it { expect(res[:name]).to eq 'ovs2ovs-tag' }
158
+      it { expect(res[:if_type].to_s).to eq 'patch' }
159
+      it { expect(res[:bridge]).to match_array(['ovs-brt2']) }
160
+      it { expect(res[:jacks]).to match_array(['ovs2ovs-patcht1']) }
161
+      it { expect(res[:vlan_id]).to eq('3') }
162
+      it { expect(res[:method].to_s).to eq 'manual' }
163
+      it { expect(res[:onboot]).to eq true }
164
+      it { expect(res[:provider].to_s).to eq 'ovs_centos7' }
165
+    end
166
+
167
+  end
168
+
169
+end

+ 96
- 0
deployment/puppet/l23network/spec/unit/puppet/provider/l23_stored_config/ovs_centos7__port__spec.rb View File

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

Loading…
Cancel
Save