Browse Source

Merge "Handle vlan_id in dpdk/vxlan mode"

Jenkins 2 years ago
parent
commit
ec5d01b6ad

+ 22
- 26
deployment/puppet/osnailyfacter/lib/puppet/parser/functions/remove_ovs_usage.rb View File

@@ -1,42 +1,29 @@
1 1
 require 'yaml'
2 2
 
3 3
 Puppet::Parser::Functions::newfunction( :remove_ovs_usage,
4
-                                        :type => :rvalue, :doc => <<-EOS
4
+                                        :type => :rvalue, :arity => 1, :doc => <<-EOS
5 5
     This function get network_scheme and returns mangled
6 6
     network scheme without ovs-based elements.
7 7
     EOS
8 8
   ) do |argv|
9 9
 
10
-    def bridge_name_max_len
11
-      15
12
-    end
10
+    raise(
11
+      Puppet::ParseError,
12
+      "remove_ovs_usage(): Wrong network_scheme. Should be non-empty Hash."
13
+    ) unless argv[0].is_a?(Hash)
13 14
 
14
-    if argv.size != 1
15
-      raise(
16
-        Puppet::ParseError,
17
-        "remove_ovs_usage(): Wrong number of arguments. Should be two."
18
-      )
19
-    end
20
-    if !argv[0].is_a?(Hash)
21
-      raise(
22
-        Puppet::ParseError,
23
-        "remove_ovs_usage(): Wrong network_scheme. Should be non-empty Hash."
24
-      )
25
-    end
26
-    if argv[0]['version'].to_s.to_f < 1.1
27
-      raise(
28
-        Puppet::ParseError,
29
-        "remove_ovs_usage(): You network_scheme hash has wrong format.\nThis parser can work with v1.1 format, please convert you config."
30
-      )
31
-    end
15
+    raise(
16
+      Puppet::ParseError,
17
+      "remove_ovs_usage(): You network_scheme hash has wrong format.\nThis parser can work with v1.1 format, please convert you config."
18
+    ) if argv[0]['version'].to_s.to_f < 1.1
32 19
 
33
-    network_scheme = argv[0]
20
+    transformations = argv[0]['transformations']
34 21
     rv = {
35 22
       'use_ovs' => false
36 23
     }
37 24
     overrides = []
38 25
 
39
-    network_scheme['transformations'].each do |tr|
26
+    transformations.each do |tr|
40 27
       # get all dependent ovs providers
41 28
       if tr['provider'] =~ /ovs/
42 29
         if tr['action'] == 'add-patch'
@@ -46,16 +33,25 @@ Puppet::Parser::Functions::newfunction( :remove_ovs_usage,
46 33
             'provider' => 'lnx'
47 34
           }
48 35
         else
49
-          overrides << {
36
+          override_lnx = {
50 37
             'action'   => 'override',
51 38
             'override' => tr['name'],
52 39
             'provider' => 'lnx'
53 40
           }
41
+
42
+          # handle vxlan mode
43
+          if tr['provider'] == 'dpdkovs'
44
+            bridge = transformations.select { |t| tr['bridge'] == t['name'] }
45
+            bridge_vlan_id = bridge[0]['vendor_specific']['vlan_id']
46
+            override_lnx.merge!({'name' => "#{tr['name']}.#{bridge_vlan_id}"}) if bridge_vlan_id
47
+          end
48
+
49
+          overrides << override_lnx
54 50
         end
55 51
       end
56 52
     end
57 53
 
58
-    if ! overrides.empty?
54
+    unless overrides.empty?
59 55
       rv['network_scheme'] = {
60 56
         'transformations' => overrides
61 57
       }

+ 17
- 2
deployment/puppet/osnailyfacter/spec/functions/remove_ovs_usage_spec.rb View File

@@ -29,6 +29,15 @@ describe 'remove_ovs_usage' do
29 29
           'bridge' => 'bridge-0',
30 30
           'action' => 'add-port',
31 31
           'name' => 'ethx',
32
+        },
33
+        {
34
+          'provider' => 'ovs',
35
+          'action' => 'add-br',
36
+          'name' => 'bridge-0',
37
+          'vendor_specific' => {
38
+            'datapath_type' => 'netdev',
39
+            'vlan_id' => 909,
40
+          },
32 41
         }
33 42
       ],
34 43
     }
@@ -48,6 +57,12 @@ describe 'remove_ovs_usage' do
48 57
             'action' => 'override',
49 58
             'override' => 'ethx',
50 59
             'provider' => 'lnx',
60
+            'name' => 'ethx.909',
61
+          },
62
+          {
63
+            'action' => 'override',
64
+            'override' => 'bridge-0',
65
+            'provider' => 'lnx',
51 66
           }
52 67
         ]
53 68
       }
@@ -91,8 +106,8 @@ describe 'remove_ovs_usage' do
91 106
   end
92 107
 
93 108
   it 'should expect 1 argument' do
94
-    is_expected.to run.with_params().and_raise_error(Puppet::ParseError)
95
-    is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError)
109
+    is_expected.to run.with_params().and_raise_error(ArgumentError)
110
+    is_expected.to run.with_params(1, 2).and_raise_error(ArgumentError)
96 111
   end
97 112
 
98 113
   it 'should expect a hash as given argument' do

Loading…
Cancel
Save