File: ovn_northd_spec.rb

package info (click to toggle)
puppet-module-ovn 25.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 428 kB
  • sloc: ruby: 588; python: 41; sh: 10; makefile: 10
file content (279 lines) | stat: -rw-r--r-- 10,787 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
require 'spec_helper'

describe 'ovn::northd' do

  shared_examples_for 'systemd env' do
    context 'with default parameters' do
      let :params do
        {}
      end
      it 'creates systemd conf' do
        is_expected.to contain_augeas('config-ovn-northd').with({
          :context => platform_params[:ovn_northd_context],
          :changes => "set " + platform_params[:ovn_northd_opts_envvar_name] + " '\"" +
                      "--db-nb-addr=0.0.0.0 --db-sb-addr=0.0.0.0" +
                      " --db-nb-create-insecure-remote=yes --db-sb-create-insecure-remote=yes" +
                      "\"'",
        })
      end
      it 'does not configure db connections' do
        is_expected.to_not contain_exec('ovn-nb-set-connection')
        is_expected.to_not contain_exec('ovn-sb-set-connection')
      end
    end

    context 'with ipv6' do
      let :params do
        {
          :dbs_listen_ip => '::1'
        }
      end
      it 'creates systemd conf' do
        is_expected.to contain_augeas('config-ovn-northd').with({
          :context => platform_params[:ovn_northd_context],
          :changes => "set " + platform_params[:ovn_northd_opts_envvar_name] +
                      " '\"--db-nb-addr=[::1] --db-sb-addr=[::1] --db-nb-create-insecure-remote=yes --db-sb-create-insecure-remote=yes\"'",
        })
      end
    end

    context 'with parameters' do
      let :params do
        {
          :ovn_northd_nb_db       => 'ssl:192.0.2.1:6645,ssl:192.0.2.2:6645,ssl:192.0.2.3:6645',
          :ovn_northd_sb_db       => ['ssl:192.0.2.1:6646', 'ssl:192.0.2.2:6646', 'ssl:192.0.2.3:6646'],
          :ovn_northd_ssl_key     => '/path/to/key.pem',
          :ovn_northd_ssl_cert    => '/path/to/cert.pem',
          :ovn_northd_ssl_ca_cert => '/path/to/cacert.pem',
        }
      end

      it 'creates systemd conf' do
        is_expected.to contain_augeas('config-ovn-northd').with({
          :context => platform_params[:ovn_northd_context],
          :changes => "set " + platform_params[:ovn_northd_opts_envvar_name] + " '\"" +
                      "--db-nb-addr=0.0.0.0 --db-sb-addr=0.0.0.0" +
                      " --db-nb-create-insecure-remote=yes --db-sb-create-insecure-remote=yes" +
                      " --ovn-northd-nb-db=ssl:192.0.2.1:6645,ssl:192.0.2.2:6645,ssl:192.0.2.3:6645" +
                      " --ovn-northd-sb-db=ssl:192.0.2.1:6646,ssl:192.0.2.2:6646,ssl:192.0.2.3:6646" +
                      " --ovn-northd-ssl-key=/path/to/key.pem --ovn-northd-ssl-cert=/path/to/cert.pem --ovn-northd-ssl-ca-cert=/path/to/cacert.pem" +
                      "\"'",
        })
      end
      it 'does not configures db connections' do
        is_expected.to_not contain_exec('ovn-nb-set-connection')
        is_expected.to_not contain_exec('ovn-sb-set-connection')
      end
    end

    context 'with nb db ssl enabled' do
      let :params do
        {
          :ovn_nb_db_ssl_key     => '/path/to/dbkey.pem',
          :ovn_nb_db_ssl_cert    => '/path/to/dbcert.pem',
          :ovn_nb_db_ssl_ca_cert => '/path/to/dbcacert.pem',
        }
      end

      it 'creates systemd conf' do
        is_expected.to contain_augeas('config-ovn-northd').with({
          :context => platform_params[:ovn_northd_context],
          :changes => "set " + platform_params[:ovn_northd_opts_envvar_name] + " '\"" +
                      "--db-nb-addr=0.0.0.0 --db-sb-addr=0.0.0.0" +
                      " --db-nb-create-insecure-remote=no --db-sb-create-insecure-remote=yes" +
                      " --ovn-nb-db-ssl-key=/path/to/dbkey.pem --ovn-nb-db-ssl-cert=/path/to/dbcert.pem --ovn-nb-db-ssl-ca-cert=/path/to/dbcacert.pem" +
                      "\"'",
        })
      end

      it 'configures db connections' do
        is_expected.to contain_exec('ovn-nb-set-connection').with({
          :command => 'ovn-nbctl set-connection pssl:6641:0.0.0.0',
          :path    => ['/sbin', '/usr/sbin', '/bin', '/usr/bin'],
          :unless  => 'ovn-nbctl get-connection | egrep -e \'^pssl:6641:0.0.0.0$\'',
          :tag     => 'ovn-db-set-connections',
        })
        is_expected.to_not contain_exec('ovn-sb-set-connection')
      end
    end

    context 'with ipv6 and nb db ssl enabled' do
      let :params do
        {
          :dbs_listen_ip         => '::1',
          :ovn_nb_db_ssl_key     => '/path/to/dbkey.pem',
          :ovn_nb_db_ssl_cert    => '/path/to/dbcert.pem',
          :ovn_nb_db_ssl_ca_cert => '/path/to/dbcacert.pem',
        }
      end

      it 'creates systemd conf' do
        is_expected.to contain_augeas('config-ovn-northd').with({
          :context => platform_params[:ovn_northd_context],
          :changes => "set " + platform_params[:ovn_northd_opts_envvar_name] + " '\"" +
                      "--db-nb-addr=[::1] --db-sb-addr=[::1]" +
                      " --db-nb-create-insecure-remote=no --db-sb-create-insecure-remote=yes" +
                      " --ovn-nb-db-ssl-key=/path/to/dbkey.pem --ovn-nb-db-ssl-cert=/path/to/dbcert.pem --ovn-nb-db-ssl-ca-cert=/path/to/dbcacert.pem" +
                      "\"'",
        })
      end

      it 'configures db connections' do
        is_expected.to contain_exec('ovn-nb-set-connection').with({
          :command => 'ovn-nbctl set-connection pssl:6641:[::1]',
          :path    => ['/sbin', '/usr/sbin', '/bin', '/usr/bin'],
          :unless  => 'ovn-nbctl get-connection | egrep -e \'^pssl:6641:\\[::1\\]$\'',
          :tag     => 'ovn-db-set-connections',
        })
        is_expected.to_not contain_exec('ovn-sb-set-connection')
      end
    end

    context 'with sb db ssl enabled' do
      let :params do
        {
          :ovn_sb_db_ssl_key     => '/path/to/dbkey.pem',
          :ovn_sb_db_ssl_cert    => '/path/to/dbcert.pem',
          :ovn_sb_db_ssl_ca_cert => '/path/to/dbcacert.pem',
        }
      end

      it 'creates systemd conf' do
        is_expected.to contain_augeas('config-ovn-northd').with({
          :context => platform_params[:ovn_northd_context],
          :changes => "set " + platform_params[:ovn_northd_opts_envvar_name] + " '\"" +
                      "--db-nb-addr=0.0.0.0 --db-sb-addr=0.0.0.0" +
                      " --db-nb-create-insecure-remote=yes --db-sb-create-insecure-remote=no" +
                      " --ovn-sb-db-ssl-key=/path/to/dbkey.pem --ovn-sb-db-ssl-cert=/path/to/dbcert.pem --ovn-sb-db-ssl-ca-cert=/path/to/dbcacert.pem" +
                      "\"'",
        })
      end

      it 'configures db connections' do
        is_expected.to_not contain_exec('ovn-nb-set-connection')
        is_expected.to contain_exec('ovn-sb-set-connection').with({
          :command => 'ovn-sbctl set-connection pssl:6642:0.0.0.0',
          :path    => ['/sbin', '/usr/sbin', '/bin', '/usr/bin'],
          :unless  => 'ovn-sbctl get-connection | egrep -e \' pssl:6642:0.0.0.0$\'',
          :tag     => 'ovn-db-set-connections',
        })
      end
    end

    context 'with ipv6 and sb db ssl enabled' do
      let :params do
        {
          :dbs_listen_ip         => '::1',
          :ovn_sb_db_ssl_key     => '/path/to/dbkey.pem',
          :ovn_sb_db_ssl_cert    => '/path/to/dbcert.pem',
          :ovn_sb_db_ssl_ca_cert => '/path/to/dbcacert.pem',
        }
      end

      it 'creates systemd conf' do
        is_expected.to contain_augeas('config-ovn-northd').with({
          :context => platform_params[:ovn_northd_context],
          :changes => "set " + platform_params[:ovn_northd_opts_envvar_name] + " '\"" +
                      "--db-nb-addr=[::1] --db-sb-addr=[::1]" +
                      " --db-nb-create-insecure-remote=yes --db-sb-create-insecure-remote=no" +
                      " --ovn-sb-db-ssl-key=/path/to/dbkey.pem --ovn-sb-db-ssl-cert=/path/to/dbcert.pem --ovn-sb-db-ssl-ca-cert=/path/to/dbcacert.pem" +
                      "\"'",
        })
      end

      it 'configures db connections' do
        is_expected.to_not contain_exec('ovn-nb-set-connection')
        is_expected.to contain_exec('ovn-sb-set-connection').with({
          :command => 'ovn-sbctl set-connection pssl:6642:[::1]',
          :path    => ['/sbin', '/usr/sbin', '/bin', '/usr/bin'],
          :unless  => 'ovn-sbctl get-connection | egrep -e \' pssl:6642:\\[::1\\]$\'',
          :tag     => 'ovn-db-set-connections',
        })
      end
    end

    context 'with bad northd ssl parameters' do
      let :params do
        {
          :ovn_northd_ssl_key => '/path/to/key.pem',
        }
      end

      it { should raise_error(Puppet::Error, /The ovn_northd_ssl_key, cert and ca_cert are required to use SSL/) }
    end

    context 'with bad nb db ssl parameters' do
      let :params do
        {
          :ovn_nb_db_ssl_key => '/path/to/key.pem',
        }
      end

      it { should raise_error(Puppet::Error, /The ovn_nb_db_ssl_key, cert and ca_cert are required to use SSL/) }
    end

    context 'with bad sb db ssl parameters' do
      let :params do
        {
          :ovn_sb_db_ssl_key => '/path/to/key.pem',
        }
      end

      it { should raise_error(Puppet::Error, /The ovn_sb_db_ssl_key, cert and ca_cert are required to use SSL/) }
    end
  end

  shared_examples_for 'ovn northd' do
    it 'starts northd' do
      is_expected.to contain_service('northd').with(
        :ensure => true,
        :name   => platform_params[:ovn_northd_service_name],
        :enable => true,
      )
    end

    it 'installs package' do
      is_expected.to contain_package('ovn-northd').with(
        :ensure => 'present',
        :name   => platform_params[:ovn_northd_package_name],
        :notify => 'Service[northd]'
      )
    end
  end

  on_supported_os({
    :supported_os   => OSDefaults.get_supported_os
  }).each do |os,facts|
    context "on #{os}" do
      let (:facts) do
        facts.merge!(OSDefaults.get_facts())
      end

      case facts[:os]['family']
      when 'Debian'
        let(:platform_params) do
          {
            :ovn_northd_package_name     => 'ovn-central',
            :ovn_northd_service_name     => 'ovn-central',
            :ovn_northd_context          => '/files/etc/default/ovn-central',
            :ovn_northd_opts_envvar_name => 'OVN_CTL_OPTS'
          }
        end
        it_behaves_like 'ovn northd'
        it_behaves_like 'systemd env'
      when 'RedHat'
        let(:platform_params) do
          {
            :ovn_northd_package_name     => 'openvswitch-ovn-central',
            :ovn_northd_service_name     => 'ovn-northd',
            :ovn_northd_context          => '/files/etc/sysconfig/ovn-northd',
            :ovn_northd_opts_envvar_name => 'OVN_NORTHD_OPTS'
          }
        end
        it_behaves_like 'ovn northd'
        it_behaves_like 'systemd env'
      end
    end
  end
end