File: Add-support-for-mistral_api_uwsgi_config-in-Debian.patch

package info (click to toggle)
puppet-module-mistral 25.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,064 kB
  • sloc: ruby: 2,240; python: 38; makefile: 11; sh: 10
file content (307 lines) | stat: -rw-r--r-- 10,134 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
From 92ca9b40e299829168a10d15219483b7ec9dbe2a Mon Sep 17 00:00:00 2001
From: Thomas Goirand <zigo@debian.org>
Date: Fri, 03 Oct 2025 11:08:19 +0200
Subject: [PATCH] Add support for mistral_api_uwsgi_config in Debian

This patch is adding the configuration of the number of workers,
threads, and the size of the listen queue in Debian, which uses
uwsgi to run Mistral API. Therefore, this patch adds a new
mistral_api_uwsgi_config provider as well as a new
mistral::wsgi::uwsgi class.

Signed-off-by: Thomas Goirand <zigo@debian.org>
Change-Id: I3e1a7b170c9840b0de83e0eb97c596154790d019
---

diff --git a/lib/puppet/provider/mistral_api_uwsgi_config/ini_setting.rb b/lib/puppet/provider/mistral_api_uwsgi_config/ini_setting.rb
new file mode 100644
index 0000000..5f42db4
--- /dev/null
+++ b/lib/puppet/provider/mistral_api_uwsgi_config/ini_setting.rb
@@ -0,0 +1,10 @@
+Puppet::Type.type(:mistral_api_uwsgi_config).provide(
+  :ini_setting,
+  :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
+) do
+
+  def self.file_path
+    '/etc/mistral/mistral-api-uwsgi.ini'
+  end
+
+end
diff --git a/lib/puppet/type/mistral_api_uwsgi_config.rb b/lib/puppet/type/mistral_api_uwsgi_config.rb
new file mode 100644
index 0000000..b33456d
--- /dev/null
+++ b/lib/puppet/type/mistral_api_uwsgi_config.rb
@@ -0,0 +1,29 @@
+Puppet::Type.newtype(:mistral_api_uwsgi_config) do
+
+  ensurable
+
+  newparam(:name, :namevar => true) do
+    desc 'Section/setting name to manage from /etc/mistral/mistral-api-uwsgi.ini'
+    newvalues(/\S\/\S/)
+  end
+
+  newproperty(:value) do
+    desc 'The value of the setting to be defined.'
+    munge do |value|
+      value = value.to_s.strip
+      value.capitalize! if value =~ /^(true|false)$/i
+      value
+    end
+    newvalues(/^[\S ]*$/)
+  end
+
+  newparam(:ensure_absent_val) do
+    desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
+    defaultto('<SERVICE DEFAULT>')
+  end
+
+  autorequire(:anchor) do
+    ['mistral::install::end']
+  end
+
+end
diff --git a/manifests/api.pp b/manifests/api.pp
index ca845eb..17fc44c 100644
--- a/manifests/api.pp
+++ b/manifests/api.pp
@@ -102,6 +102,8 @@
         hasrestart => true,
         tag        => 'mistral-service',
       }
+      # On any uwsgi config change, we must restart Mistral API.
+      Mistral_api_uwsgi_config<||> ~> Service['mistral-api']
     } elsif $service_name == 'httpd' {
       service { 'mistral-api':
         ensure => 'stopped',
diff --git a/manifests/deps.pp b/manifests/deps.pp
index 302f38a..470b28f 100644
--- a/manifests/deps.pp
+++ b/manifests/deps.pp
@@ -24,6 +24,10 @@
   ~> Service<| tag == 'mistral-service' |>
   ~> anchor { 'mistral::service::end': }
 
+  Anchor['mistral::config::begin']
+  -> Mistral_api_uwsgi_config<||>
+  -> Anchor['mistral::config::end']
+
   # We need openstackclient before marking service end so that mistral
   # will have clients available to create resources. This tag handles the
   # openstackclient but indirectly since the client is not available in
diff --git a/manifests/wsgi/uwsgi.pp b/manifests/wsgi/uwsgi.pp
new file mode 100644
index 0000000..d31fd88
--- /dev/null
+++ b/manifests/wsgi/uwsgi.pp
@@ -0,0 +1,40 @@
+#
+# Copyright 2025 Thomas Goirand <zigo@debian.org>
+#
+# Author: Thomas Goirand <zigo@debian.org>
+#
+# == Class: mistral::wsgi::uwsgi
+#
+# Configure the UWSGI service for Mistral API.
+#
+# == Parameters
+#
+# [*processes*]
+#   (Optional) Number of processes.
+#   Defaults to $facts['os_workers'].
+#
+# [*threads*]
+#   (Optional) Number of threads.
+#   Defaults to 1.
+#
+# [*listen_queue_size*]
+#   (Optional) Socket listen queue size.
+#   Defaults to 100
+#
+class mistral::wsgi::uwsgi (
+  $processes         = $facts['os_workers'],
+  $threads           = 1,
+  $listen_queue_size = 100,
+) {
+  include mistral::deps
+
+  if $facts['os']['name'] != 'Debian' {
+    warning('This class is only valid for Debian, as other operating systems are not using uwsgi by default.')
+  }
+
+  mistral_api_uwsgi_config {
+    'uwsgi/processes': value => $processes;
+    'uwsgi/threads':   value => $threads;
+    'uwsgi/listen':    value => $listen_queue_size;
+  }
+}
diff --git a/releasenotes/notes/uwsgi-b797b91577f2d1e6.yaml b/releasenotes/notes/uwsgi-b797b91577f2d1e6.yaml
new file mode 100644
index 0000000..03708d0
--- /dev/null
+++ b/releasenotes/notes/uwsgi-b797b91577f2d1e6.yaml
@@ -0,0 +1,7 @@
+---
+features:
+  - |
+    A new class mistral::wsgi::wsgi exists to allow configuring uwsgi in
+    operating systems that support this (ie: currently Debian). This helps
+    configuring the number of processes, threads and listen socket.
+    Also, a new mistral_api_uwsgi_config provider now exist.
diff --git a/spec/classes/mistral_wsgi_uwsgi_spec.rb b/spec/classes/mistral_wsgi_uwsgi_spec.rb
new file mode 100644
index 0000000..fd5d07d
--- /dev/null
+++ b/spec/classes/mistral_wsgi_uwsgi_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe 'mistral::wsgi::uwsgi' do
+
+  shared_examples 'mistral::wsgi::uwsgi' do
+    context 'with default parameters' do
+      it {
+        should contain_class('mistral::deps')
+      }
+
+      it {
+        is_expected.to contain_mistral_api_uwsgi_config('uwsgi/processes').with_value(facts[:os_workers])
+        is_expected.to contain_mistral_api_uwsgi_config('uwsgi/threads').with_value('1')
+        is_expected.to contain_mistral_api_uwsgi_config('uwsgi/listen').with_value('100')
+      }
+    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({
+          :os_workers => 8,
+        }))
+      end
+      it_behaves_like 'mistral::wsgi::uwsgi'
+    end
+  end
+end
diff --git a/spec/unit/provider/mistral_api_uwsgi_config/openstackconfig_spec.rb b/spec/unit/provider/mistral_api_uwsgi_config/openstackconfig_spec.rb
new file mode 100644
index 0000000..a72d625
--- /dev/null
+++ b/spec/unit/provider/mistral_api_uwsgi_config/openstackconfig_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+provider_class = Puppet::Type.type(:mistral_api_uwsgi_config).provider(:ini_setting)
+describe provider_class do
+
+  it 'should default to the default setting when no other one is specified' do
+    resource = Puppet::Type::Mistral_api_uwsgi_config.new(
+      {:name => 'DEFAULT/foo', :value => 'bar'}
+    )
+    provider = provider_class.new(resource)
+    expect(provider.section).to eq('DEFAULT')
+    expect(provider.setting).to eq('foo')
+  end
+
+  it 'should allow setting to be set explicitly' do
+    resource = Puppet::Type::Mistral_api_uwsgi_config.new(
+      {:name => 'dude/foo', :value => 'bar'}
+    )
+    provider = provider_class.new(resource)
+    expect(provider.section).to eq('dude')
+    expect(provider.setting).to eq('foo')
+  end
+
+  it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
+    resource = Puppet::Type::Mistral_api_uwsgi_config.new(
+      {:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
+    )
+    provider = provider_class.new(resource)
+    provider.exists?
+    expect(resource[:ensure]).to eq :absent
+  end
+
+  it 'should ensure absent when value matches ensure_absent_val' do
+    resource = Puppet::Type::Mistral_api_uwsgi_config.new(
+      {:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
+    )
+    provider = provider_class.new(resource)
+    provider.exists?
+    expect(resource[:ensure]).to eq :absent
+  end
+
+end
diff --git a/spec/unit/type/mistral_api_uwsgi_config_spec.rb b/spec/unit/type/mistral_api_uwsgi_config_spec.rb
new file mode 100644
index 0000000..b350ee7
--- /dev/null
+++ b/spec/unit/type/mistral_api_uwsgi_config_spec.rb
@@ -0,0 +1,64 @@
+require 'puppet'
+require 'puppet/type/mistral_api_uwsgi_config'
+
+describe 'Puppet::Type.type(:mistral_api_uwsgi_config)' do
+  before :each do
+    @mistral_api_uwsgi_config = Puppet::Type.type(:mistral_api_uwsgi_config).new(:name => 'DEFAULT/foo', :value => 'bar')
+  end
+
+ it 'should require a name' do
+    expect {
+      Puppet::Type.type(:mistral_api_uwsgi_config).new({})
+    }.to raise_error(Puppet::Error, 'Title or name must be provided')
+  end
+
+  it 'should not expect a name with whitespace' do
+    expect {
+      Puppet::Type.type(:mistral_api_uwsgi_config).new(:name => 'f oo')
+    }.to raise_error(Puppet::Error, /Parameter name failed/)
+  end
+
+  it 'should fail when there is no section' do
+    expect {
+      Puppet::Type.type(:mistral_api_uwsgi_config).new(:name => 'foo')
+    }.to raise_error(Puppet::Error, /Parameter name failed/)
+  end
+
+  it 'should not require a value when ensure is absent' do
+    Puppet::Type.type(:mistral_api_uwsgi_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
+  end
+
+  it 'should accept a valid value' do
+    @mistral_api_uwsgi_config[:value] = 'bar'
+    expect(@mistral_api_uwsgi_config[:value]).to eq('bar')
+  end
+
+  it 'should not accept a value with whitespace' do
+    @mistral_api_uwsgi_config[:value] = 'b ar'
+    expect(@mistral_api_uwsgi_config[:value]).to eq('b ar')
+  end
+
+  it 'should accept valid ensure values' do
+    @mistral_api_uwsgi_config[:ensure] = :present
+    expect(@mistral_api_uwsgi_config[:ensure]).to eq(:present)
+    @mistral_api_uwsgi_config[:ensure] = :absent
+    expect(@mistral_api_uwsgi_config[:ensure]).to eq(:absent)
+  end
+
+  it 'should not accept invalid ensure values' do
+    expect {
+      @mistral_api_uwsgi_config[:ensure] = :latest
+    }.to raise_error(Puppet::Error, /Invalid value/)
+  end
+
+  it 'should autorequire the package that install the file' do
+    catalog = Puppet::Resource::Catalog.new
+    anchor = Puppet::Type.type(:anchor).new(:name => 'mistral::install::end')
+    catalog.add_resource anchor, @mistral_api_uwsgi_config
+    dependency = @mistral_api_uwsgi_config.autorequire
+    expect(dependency.size).to eq(1)
+    expect(dependency[0].target).to eq(@mistral_api_uwsgi_config)
+    expect(dependency[0].source).to eq(anchor)
+  end
+
+end