View | Details | Raw Unified | Return to bug 225530
Collapse All | Expand All

(-)b/sysutils/py-salt/files/patch-salt_modules_freebsd_sysctl.py (-1 / +153 lines)
Added Link Here
0
- 
1
From 89ba86602ffe4c27f4498c11f18abf3e3d417d92 Mon Sep 17 00:00:00 2001
2
From: Fabian Keil <fk@fabiankeil.de>
3
Date: Sat, 5 Aug 2017 10:52:23 +0200
4
Subject: [PATCH 1/2] salt/modules/freebsd_sysctl.py: Figure out the available
5
 sysctl roots automatically
6
7
show() requires a complete list of sysctl roots to properly parse
8
sysctl values that are split across multiple lines. Every line of
9
the "sysctl -ae" output that doesn't start with the name of a known
10
sysctl root is treated as continuation of the previous line.
11
12
Previously the kstat sysctl root was unknown and this resulted in
13
whole kstat tree getting add to the p1003_1b.timer_max value:
14
15
    fk@electrobsd ~ $salt-ssh salt-client-1 sysctl.show
16
    [...]
17
        p1003_1b.synchronized_io:
18
            0
19
        p1003_1b.timer_max:
20
            32kstat.zfs.misc.vdev_cache_stats.misses=0
21
            kstat.zfs.misc.vdev_cache_stats.hits=0
22
            kstat.zfs.misc.vdev_cache_stats.delegations=0
23
            kstat.zfs.misc.arcstats.demand_hit_predictive_prefetch=0
24
    [...]
25
            kstat.zfs.misc.zio_trim.failed=0
26
            kstat.zfs.misc.zio_trim.unsupported=0
27
            kstat.zfs.misc.zio_trim.success=0
28
            kstat.zfs.misc.zio_trim.bytes=0
29
        p1003_1b.timers:
30
            200112
31
        security.bsd.conservative_signals:
32
            1
33
    [...]
34
35
Detecting the available sysctl roots automatically avoids the problem.
36
---
37
 salt/modules/freebsd_sysctl.py | 26 +++++++++++---------------
38
 1 file changed, 11 insertions(+), 15 deletions(-)
39
40
diff --git salt/modules/freebsd_sysctl.py salt/modules/freebsd_sysctl.py
41
index 05119f40c4..0f65123092 100644
42
--- salt/modules/freebsd_sysctl.py
43
+++ salt/modules/freebsd_sysctl.py
44
@@ -37,6 +37,16 @@ def _formatfor(name, value, config, tail=''):
45
     else:
46
         return '{0}={1}{2}'.format(name, value, tail)
47
 
48
+def _get_sysctl_roots():
49
+    sysctl_roots = []
50
+    sysctl = salt.utils.which('sysctl')
51
+    out = __salt__['cmd.run']('{0} -aN'.format(sysctl), output_loglevel='trace')
52
+
53
+    for line in out.splitlines():
54
+        sysctl_root = line.split('.')[0]
55
+        if sysctl_root not in (sysctl_roots):
56
+            sysctl_roots.append(sysctl_root)
57
+    return sysctl_roots
58
 
59
 def show(config_file=False):
60
     '''
61
@@ -48,21 +58,6 @@ def show(config_file=False):
62
 
63
         salt '*' sysctl.show
64
     '''
65
-    roots = (
66
-        'compat',
67
-        'debug',
68
-        'dev',
69
-        'hptmv',
70
-        'hw',
71
-        'kern',
72
-        'machdep',
73
-        'net',
74
-        'p1003_1b',
75
-        'security',
76
-        'user',
77
-        'vfs',
78
-        'vm'
79
-    )
80
     cmd = 'sysctl -ae'
81
     ret = {}
82
     comps = ['']
83
@@ -80,6 +75,7 @@ def show(config_file=False):
84
             log.error('Could not open sysctl config file')
85
             return None
86
     else:
87
+        roots = _get_sysctl_roots()
88
         out = __salt__['cmd.run'](cmd, output_loglevel='trace')
89
         for line in out.splitlines():
90
             if any([line.startswith('{0}.'.format(root)) for root in roots]):
91
-- 
92
2.14.1
93
94
95
From 1515f38d64b0e4dc995aa611f7aa8128caf10c2c Mon Sep 17 00:00:00 2001
96
From: Fabian Keil <fk@fabiankeil.de>
97
Date: Sat, 5 Aug 2017 12:54:25 +0200
98
Subject: [PATCH 2/2] salt/modules/freebsd_sysctl.py: Fix multi-line values in
99
 the sysctl.show output
100
101
Previously the linebreak between the first two lines got lost for
102
multi-line values whose first line starts on the same line as the
103
sysctl name. Additionally multi-line values got an empty line added
104
to the end.
105
106
Before:
107
    fk@electrobsd ~ $salt-call --local sysctl.show
108
        [...]
109
        kern.geom.confxml:
110
            <mesh>  <class id="0xffffffff81b33358">
111
                <name>ELI</name>
112
        [...]
113
        hw.dri.0.vm:
114
            slot offset	        size       type flags address            mtrr
115
               0 0x00000000f0000000 0x00200000  REG  0x88 0xfffff800f0000000 no
116
117
        hw.dri.0.wedged:
118
119
After:
120
    fk@electrobsd ~ $salt-call --local sysctl.show
121
        [...]
122
        kern.geom.confxml:
123
            <mesh>
124
              <class id="0xffffffff81b33358">
125
                <name>ELI</name>
126
        [...]
127
        hw.dri.0.vm:
128
            slot offset	        size       type flags address            mtrr
129
               0 0x00000000f0000000 0x00200000  REG  0x88 0xfffff800f0000000 no
130
        hw.dri.0.wedged:
131
---
132
 salt/modules/freebsd_sysctl.py | 5 ++++-
133
 1 file changed, 4 insertions(+), 1 deletion(-)
134
135
diff --git salt/modules/freebsd_sysctl.py salt/modules/freebsd_sysctl.py
136
index 0f65123092..b82ea2b124 100644
137
--- salt/modules/freebsd_sysctl.py
138
+++ salt/modules/freebsd_sysctl.py
139
@@ -82,7 +82,10 @@ def show(config_file=False):
140
                 comps = line.split('=', 1)
141
                 ret[comps[0]] = comps[1]
142
             elif comps[0]:
143
-                ret[comps[0]] += '{0}\n'.format(line)
144
+                # Add a new line character unless the value is empty
145
+                if len(ret[comps[0]].strip()) != 0:
146
+                    ret[comps[0]] += '\n'
147
+                ret[comps[0]] += line
148
             else:
149
                 continue
150
         return ret
151
-- 
152
2.14.1
153

Return to bug 225530