Merge ~rgildein/charm-telegraf:update/bootstack-template into charm-telegraf:master
- Git
- lp:~rgildein/charm-telegraf
- update/bootstack-template
- Merge into master
Status: | Merged |
---|---|
Approved by: | Eric Chen |
Approved revision: | b9f7aa60c27a41fbcdac6f95e429f27ac7c9e143 |
Merged at revision: | 3202b0a91d6a3f13ce6946490be7b22d2887b90f |
Proposed branch: | ~rgildein/charm-telegraf:update/bootstack-template |
Merge into: | charm-telegraf:master |
Diff against target: |
739 lines (+216/-156) 26 files modified
.pre-commit-config.yaml (+22/-0) Makefile (+48/-42) charmcraft.yaml (+26/-18) rename.sh (+4/-0) src/hooks/apache-relation-changed (+3/-0) src/hooks/exec-relation-changed (+3/-0) src/hooks/haproxy-relation-changed (+3/-0) src/hooks/relations/telegraf-exec/interface.yaml (+1/-1) src/icon.svg (+1/-1) src/pyproject.toml (+35/-0) src/reactive/telegraf.py (+4/-9) src/templates/apache-server-status.tmpl (+0/-1) src/templates/influxdb-api.conf.tmpl (+1/-2) src/templates/sudoers/telegraf_intel_rdt.tmpl (+0/-1) src/templates/sudoers/telegraf_ipmi.tmpl (+0/-1) src/templates/sudoers/telegraf_iptables.tmpl (+0/-1) src/templates/sudoers/telegraf_ovs.tmpl (+0/-1) src/templates/sudoers/telegraf_smart.tmpl (+0/-1) src/templates/telegraf.conf.tmpl (+3/-3) src/tests/functional/tests/base.py (+0/-2) src/tests/functional/tests/test_telegraf.py (+0/-1) src/tests/functional/tests/tests.yaml (+0/-1) src/tests/unit/requirements.txt (+1/-10) src/tests/unit/test_telegraf.py (+4/-8) src/tests/unit/test_templates_sudoers.py (+13/-8) src/tox.ini (+44/-44) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Eric Chen | Approve | ||
Tianqi Xiao (community) | Approve | ||
BootStack Reviewers | Pending | ||
Review via email: mp+428255@code.launchpad.net |
Commit message
Update templates file from bootstack-
- update rename.sh, Makefile, charmcraft.yaml, tox.ini and
.pre-
- clean requirements
- moved check of sudoers templates from lint to unit tests
Description of the change
Update templates file from bootstack-
- update rename.sh, Makefile, charmcraft.yaml, tox.ini and
.pre-
- clean requirements
- moved check of sudoers templates from lint to unit tests
Robert Gildein (rgildein) wrote : | # |
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
This merge proposal is being monitored by mergebot. Change the status to Approved to merge.
Eric Chen (eric-chen) : | # |
Robert Gildein (rgildein) : | # |
Tianqi Xiao (txiao) wrote : | # |
Overall LGTM. Just one small thing that I would need clarification of. Please see my inline command.
Eric Chen (eric-chen) : | # |
Robert Gildein (rgildein) : | # |
Robert Gildein (rgildein) : | # |
Robert Gildein (rgildein) wrote (last edit ): | # |
This is blocked / should not be merged before [1].
---
[1]: https:/
Robert Gildein (rgildein) wrote : | # |
result from new unit tests: https:/
couple of tests are broken, but it's not related with my changes
https:/
Tianqi Xiao (txiao) : | # |
Eric Chen (eric-chen) : | # |
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Change successfully merged at revision 3202b0a91d6a3f1
Preview Diff
1 | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml |
2 | new file mode 100644 |
3 | index 0000000..18d9070 |
4 | --- /dev/null |
5 | +++ b/.pre-commit-config.yaml |
6 | @@ -0,0 +1,22 @@ |
7 | +# This is a template `.pre-commit-config.yaml` file for reactive charms |
8 | +# This file is managed by bootstack-charms-spec and should not be modified |
9 | +# within individual charm repos. https://launchpad.net/bootstack-charms-spec |
10 | + |
11 | +repos: |
12 | + - repo: https://github.com/pre-commit/pre-commit-hooks |
13 | + rev: v4.3.0 |
14 | + hooks: |
15 | + - id: check-executables-have-shebangs |
16 | + - id: check-merge-conflict |
17 | + - id: end-of-file-fixer |
18 | + - id: trailing-whitespace |
19 | + - id: check-added-large-files |
20 | + - id: check-json |
21 | + - id: check-yaml |
22 | + - repo: local |
23 | + hooks: |
24 | + - id: lint |
25 | + name: lint |
26 | + entry: make lint |
27 | + language: system |
28 | + types: [ python ] |
29 | diff --git a/Makefile b/Makefile |
30 | index dd167dd..b35c74e 100644 |
31 | --- a/Makefile |
32 | +++ b/Makefile |
33 | @@ -1,45 +1,42 @@ |
34 | +# This is a template `Makefile` file for reactive charms |
35 | +# This file is managed by bootstack-charms-spec and should not be modified |
36 | +# within individual charm repos. https://launchpad.net/bootstack-charms-spec |
37 | + |
38 | PYTHON := /usr/bin/python3 |
39 | |
40 | PROJECTPATH=$(dir $(realpath $(MAKEFILE_LIST))) |
41 | -ifndef CHARM_BUILD_DIR |
42 | - CHARM_BUILD_DIR=${PROJECTPATH}.build |
43 | -endif |
44 | -ifndef CHARM_LAYERS_DIR |
45 | - CHARM_LAYERS_DIR=${PROJECTPATH}/layers |
46 | -endif |
47 | -ifndef CHARM_INTERFACES_DIR |
48 | - CHARM_INTERFACES_DIR=${PROJECTPATH}/interfaces |
49 | -endif |
50 | -ifdef CONTAINER |
51 | - BUILD_ARGS="--destructive-mode" |
52 | -endif |
53 | +CHARM_BUILD_DIR:=${PROJECTPATH}.build |
54 | +CHARM_LAYERS_DIR:=${PROJECTPATH}/layers |
55 | +CHARM_INTERFACES_DIR:=${PROJECTPATH}/interfaces |
56 | +RELEASE_CHANNEL:=edge |
57 | METADATA_FILE="src/metadata.yaml" |
58 | -CHARM_NAME=$(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E "^name:" | awk '{print $$2}') |
59 | +CHARM_NAME=$(shell cat ${PROJECTPATH}/${METADATA_FILE} | grep -E '^name:' | awk '{print $$2}') |
60 | |
61 | help: |
62 | @echo "This project supports the following targets" |
63 | @echo "" |
64 | @echo " make help - show this text" |
65 | - @echo " make clean - remove unneeded files" |
66 | - @echo " make submodules - make sure that the submodules are up-to-date" |
67 | + @echo " make dev-environment - setup the development environment" |
68 | + @echo " make pre-commit - run pre-commit checks on all the files" |
69 | + @echo " make submodules - initialize, fetch, and checkout any nested submodules" |
70 | @echo " make submodules-update - update submodules to latest changes on remote branch" |
71 | + @echo " make clean - remove unneeded files and clean charmcraft environment" |
72 | @echo " make build - build the charm" |
73 | - @echo " make release - run clean, submodules, and build targets" |
74 | - @echo " make lint - run flake8 and black --check" |
75 | - @echo " make black - run black and reformat files" |
76 | @echo " make proof - run charm proof" |
77 | + @echo " make release - run clean, build and proof target and upload charm to channel" |
78 | + @echo " make lint - run flake8, black --check and isort --check" |
79 | + @echo " make reformat - run black and isort and reformat files" |
80 | @echo " make unittests - run the tests defined in the unittest subdirectory" |
81 | @echo " make functional - run the tests defined in the functional subdirectory" |
82 | - @echo " make test - run lint, proof, unittests and functional targets" |
83 | + @echo " make test - run lint, unittests and functional targets" |
84 | @echo "" |
85 | |
86 | -clean: |
87 | - @echo "Cleaning files" |
88 | - @git clean -ffXd -e '!.idea' |
89 | - @echo "Cleaning existing build" |
90 | - @rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME} |
91 | - @rm -rf ${PROJECTPATH}/${CHARM_NAME}*.charm |
92 | - @charmcraft clean |
93 | +dev-environment: |
94 | + @echo "Creating virtualenv with pre-commit installed" |
95 | + @cd src && tox -r -e dev-environment |
96 | + |
97 | +pre-commit: |
98 | + @cd src && tox -e pre-commit |
99 | |
100 | submodules: |
101 | @echo "Cloning submodules" |
102 | @@ -49,39 +46,48 @@ submodules-update: |
103 | @echo "Pulling latest updates for submodules" |
104 | @git submodule update --init --recursive --remote --merge |
105 | |
106 | -build: clean submodules-update |
107 | - @echo "Building charm to directory ${CHARM_BUILD_DIR}/${CHARM_NAME}" |
108 | - @-git rev-parse --abbrev-ref HEAD > ./src/repo-info |
109 | +clean: |
110 | + @echo "Cleaning files" |
111 | + @git clean -ffXd -e '!.idea' -e '!.vscode' |
112 | + @echo "Cleaning existing build" |
113 | + @rm -rf ${CHARM_BUILD_DIR}/${CHARM_NAME} |
114 | + @rm -rf ${PROJECTPATH}/${CHARM_NAME}*.charm |
115 | + @echo "Cleaning charmcraft" |
116 | + @charmcraft clean |
117 | + |
118 | +build: clean |
119 | + @echo "Building charm" |
120 | @charmcraft -v pack ${BUILD_ARGS} |
121 | @bash -c ./rename.sh |
122 | + |
123 | +proof: build |
124 | + @echo "Running charm proof" |
125 | @mkdir -p ${CHARM_BUILD_DIR}/${CHARM_NAME} |
126 | @unzip ${PROJECTPATH}/${CHARM_NAME}.charm -d ${CHARM_BUILD_DIR}/${CHARM_NAME} |
127 | + @charm proof ${CHARM_BUILD_DIR}/${CHARM_NAME} |
128 | |
129 | -release: build |
130 | - @echo "Charm is built at ${CHARM_BUILD_DIR}/${CHARM_NAME}" |
131 | +release: proof |
132 | + @echo "Releasing charm to ${RELEASE_CHANNEL} channel" |
133 | + @charmcraft upload nrpe.charm --release ${RELEASE_CHANNEL} |
134 | |
135 | lint: |
136 | @echo "Running lint checks" |
137 | @cd src && tox -e lint |
138 | |
139 | -black: |
140 | - @echo "Reformat files with black" |
141 | - @cd src && tox -e black |
142 | - |
143 | -proof: build |
144 | - @echo "Running charm proof" |
145 | - @charm proof ${CHARM_BUILD_DIR}/${CHARM_NAME} |
146 | +reformat: |
147 | + @echo "Reformat files with black and isort" |
148 | + @cd src && tox -e reformat |
149 | |
150 | unittests: |
151 | @echo "Running unit tests" |
152 | - @cd src && tox -e unit |
153 | + @cd src && tox -e unit -- ${UNIT_ARGS} |
154 | |
155 | functional: build |
156 | - @echo "Executing functional tests in ${CHARM_BUILD_DIR}" |
157 | - @cd src && CHARM_LOCATION=${PROJECTPATH} tox -e func |
158 | + @echo "Executing functional tests using built charm at ${PROJECTPATH}" |
159 | + @cd src && CHARM_LOCATION=${PROJECTPATH} tox -e func -- ${FUNC_ARGS} |
160 | |
161 | test: lint proof unittests functional |
162 | @echo "Tests completed for charm ${CHARM_NAME}." |
163 | |
164 | # The targets below don't depend on a file |
165 | -.PHONY: help submodules submodules-update clean build release lint black proof unittests functional test |
166 | +.PHONY: help dev-environment pre-commit submodules submodules-update clean build lint reformat proof unittests functional |
167 | diff --git a/charmcraft.yaml b/charmcraft.yaml |
168 | index faaf9a0..4988a80 100644 |
169 | --- a/charmcraft.yaml |
170 | +++ b/charmcraft.yaml |
171 | @@ -1,24 +1,32 @@ |
172 | +# Learn more about charmcraft.yaml configuration at: |
173 | +# https://juju.is/docs/sdk/charmcraft-config |
174 | +# This is a template `charmcraft.yaml` file for reactive charms |
175 | +# This file is managed by bootstack-charms-spec and should not be modified |
176 | +# within individual charm repos. https://launchpad.net/bootstack-charms-spec |
177 | + |
178 | type: charm |
179 | + |
180 | parts: |
181 | charm: |
182 | source: src |
183 | plugin: reactive |
184 | - build-snaps: [charm] |
185 | + build-snaps: [ charm ] |
186 | + |
187 | bases: |
188 | - - build-on: |
189 | - - name: ubuntu |
190 | - channel: "20.04" |
191 | - architectures: ["amd64"] |
192 | - run-on: |
193 | - - name: ubuntu |
194 | - channel: "22.04" |
195 | - architectures: |
196 | - - amd64 |
197 | - - name: ubuntu |
198 | - channel: "20.04" |
199 | - architectures: |
200 | - - amd64 |
201 | - - name: ubuntu |
202 | - channel: "18.04" |
203 | - architectures: |
204 | - - amd64 |
205 | + - build-on: |
206 | + - name: ubuntu |
207 | + channel: "20.04" |
208 | + architectures: ["amd64"] |
209 | + run-on: |
210 | + - name: ubuntu |
211 | + channel: "22.04" |
212 | + architectures: |
213 | + - amd64 |
214 | + - name: ubuntu |
215 | + channel: "20.04" |
216 | + architectures: |
217 | + - amd64 |
218 | + - name: ubuntu |
219 | + channel: "18.04" |
220 | + architectures: |
221 | + - amd64 |
222 | diff --git a/rename.sh b/rename.sh |
223 | index bc8697f..88e476f 100755 |
224 | --- a/rename.sh |
225 | +++ b/rename.sh |
226 | @@ -1,4 +1,8 @@ |
227 | #!/bin/bash |
228 | +# This is a template `rename.sh` file for reactive charms |
229 | +# This file is managed by bootstack-charms-spec and should not be modified |
230 | +# within individual charm repos. https://launchpad.net/bootstack-charms-spec |
231 | + |
232 | charm=$(grep -E "^name:" src/metadata.yaml | awk '{print $2}') |
233 | echo "renaming ${charm}_*.charm to ${charm}.charm" |
234 | echo -n "pwd: " |
235 | diff --git a/src/hooks/apache-relation-changed b/src/hooks/apache-relation-changed |
236 | index 76907b4..f05785f 100755 |
237 | --- a/src/hooks/apache-relation-changed |
238 | +++ b/src/hooks/apache-relation-changed |
239 | @@ -18,9 +18,11 @@ |
240 | |
241 | # Load modules from $CHARM_DIR/lib |
242 | import sys |
243 | + |
244 | sys.path.append('lib') |
245 | |
246 | from charms.layer import basic |
247 | + |
248 | basic.bootstrap_charm_deps() |
249 | basic.init_config_states() |
250 | |
251 | @@ -32,4 +34,5 @@ basic.init_config_states() |
252 | # See https://jujucharms.com/docs/stable/authors-charm-building |
253 | # for more information on this pattern. |
254 | from charms.reactive import main |
255 | + |
256 | main() |
257 | diff --git a/src/hooks/exec-relation-changed b/src/hooks/exec-relation-changed |
258 | index 76907b4..f05785f 100755 |
259 | --- a/src/hooks/exec-relation-changed |
260 | +++ b/src/hooks/exec-relation-changed |
261 | @@ -18,9 +18,11 @@ |
262 | |
263 | # Load modules from $CHARM_DIR/lib |
264 | import sys |
265 | + |
266 | sys.path.append('lib') |
267 | |
268 | from charms.layer import basic |
269 | + |
270 | basic.bootstrap_charm_deps() |
271 | basic.init_config_states() |
272 | |
273 | @@ -32,4 +34,5 @@ basic.init_config_states() |
274 | # See https://jujucharms.com/docs/stable/authors-charm-building |
275 | # for more information on this pattern. |
276 | from charms.reactive import main |
277 | + |
278 | main() |
279 | diff --git a/src/hooks/haproxy-relation-changed b/src/hooks/haproxy-relation-changed |
280 | index 76907b4..f05785f 100755 |
281 | --- a/src/hooks/haproxy-relation-changed |
282 | +++ b/src/hooks/haproxy-relation-changed |
283 | @@ -18,9 +18,11 @@ |
284 | |
285 | # Load modules from $CHARM_DIR/lib |
286 | import sys |
287 | + |
288 | sys.path.append('lib') |
289 | |
290 | from charms.layer import basic |
291 | + |
292 | basic.bootstrap_charm_deps() |
293 | basic.init_config_states() |
294 | |
295 | @@ -32,4 +34,5 @@ basic.init_config_states() |
296 | # See https://jujucharms.com/docs/stable/authors-charm-building |
297 | # for more information on this pattern. |
298 | from charms.reactive import main |
299 | + |
300 | main() |
301 | diff --git a/src/hooks/relations/telegraf-exec/interface.yaml b/src/hooks/relations/telegraf-exec/interface.yaml |
302 | index 4a5a57f..a4fafe5 100644 |
303 | --- a/src/hooks/relations/telegraf-exec/interface.yaml |
304 | +++ b/src/hooks/relations/telegraf-exec/interface.yaml |
305 | @@ -1,4 +1,4 @@ |
306 | -name: telegraf-exec |
307 | +name: telegraf-exec |
308 | summary: Interface to configure exec plugin from a service |
309 | version: 1 |
310 | repo: https://git.launchpad.net/~verterok/charms/+source/interface-telegraf-exec |
311 | diff --git a/src/icon.svg b/src/icon.svg |
312 | index 8f01af7..36d0a10 100644 |
313 | --- a/src/icon.svg |
314 | +++ b/src/icon.svg |
315 | @@ -10,4 +10,4 @@ |
316 | <path d="M77.1614039,55.7822278 L71.8347455,32.5131414 C71.5543951,31.2515645 70.3629057,29.9899875 69.1013288,29.6395494 L44.640753,22.1401752 C44.290315,22.0700876 43.9398769,22 43.5894389,22 C42.5381248,22 41.416723,22.4205257 40.7859345,23.0513141 L23.2640321,39.3116395 C22.3528932,40.1526909 21.7921923,41.8347935 22.0725428,43.0963705 L27.7496391,67.9774718 C28.0299896,69.2390488 29.2214789,70.5006258 30.4830559,70.8510638 L53.3316166,77.8598248 C53.6820547,77.9299124 54.0324927,78 54.3829308,78 C55.4342449,78 56.5556467,77.5794743 57.1864351,76.9486859 L75.8998269,59.5669587 C76.951141,58.7259074 77.4417543,57.0438048 77.1614039,55.7822278 Z M47.163907,27.6070088 L63.9148457,32.7234043 C64.5456341,32.9336671 64.5456341,33.2140175 63.9148457,33.3541927 L55.0838069,35.3867334 C54.3829308,35.5269086 53.4717918,35.2465582 53.0512662,34.7559449 L46.8835565,28.097622 C46.3929433,27.6770964 46.5331185,27.4668335 47.163907,27.6070088 Z M57.6069608,57.6745932 C57.747136,58.3754693 57.3266104,58.7259074 56.6958219,58.5156446 L38.6132186,52.9787234 C37.9824301,52.7684606 37.8422549,52.2077597 38.3328682,51.787234 L52.2102149,38.8911139 C52.7008281,38.4005006 53.261529,38.6107635 53.4017042,39.2415519 L57.6069608,57.6745932 Z M27.8197268,41.2740926 L42.5381248,27.6070088 C43.028738,27.1163955 43.7997017,27.1864831 44.290315,27.6770964 L51.649514,35.5969962 C52.1401273,36.0876095 52.0700397,36.8585732 51.5794264,37.3491865 L36.8610284,51.0162703 C36.3704151,51.5068836 35.5994514,51.436796 35.1088381,50.9461827 L27.7496391,43.0262829 C27.3291135,42.5356696 27.3291135,41.7647059 27.8197268,41.2740926 Z M31.3941948,63.0012516 L27.4692887,45.9699625 C27.3291135,45.2690864 27.5393763,45.1989987 28.0299896,45.689612 L34.1976992,52.3479349 C34.6883125,52.8385482 34.8985753,53.8197747 34.6883125,54.4505632 L32.0249833,63.0713392 C31.8848081,63.6320401 31.5343701,63.6320401 31.3941948,63.0012516 Z M52.911091,72.8836045 L33.7771736,66.9962453 C33.1463851,66.7859825 32.7258594,66.0851064 32.9361223,65.4543179 L36.0900647,55.0813517 C36.3003275,54.4505632 37.0012036,54.0300375 37.6319921,54.2403004 L56.7659095,60.1276596 C57.396698,60.3379224 57.8172236,61.0387985 57.6069608,61.669587 L54.4530184,72.0425532 C54.2427555,72.7434293 53.5418795,73.0938673 52.911091,72.8836045 Z M69.9423801,58.9361702 L57.1163475,70.8510638 C56.6257343,71.3416771 56.3453838,71.1314143 56.5556467,70.5006258 L59.2189758,61.8798498 C59.4292386,61.2490613 60.1301147,60.5481852 60.8309908,60.40801 L69.6620296,58.3754693 C70.2928181,58.2352941 70.4329933,58.5156446 69.9423801,58.9361702 Z M71.3441323,56.4130163 L60.7609032,58.795995 C60.0600271,58.9361702 59.4292386,58.5156446 59.2890634,57.8848561 L54.8034564,38.330413 C54.6632812,37.6295369 55.0838069,36.9987484 55.7145953,36.8585732 L66.2978244,34.4755945 C66.9987005,34.3354193 67.629489,34.7559449 67.7696642,35.3867334 L72.2552712,54.9411765 C72.3954464,55.571965 71.9749208,56.2728411 71.3441323,56.4130163 Z" id="symbol_2_" fill="#FFFFFF"></path> |
317 | </g> |
318 | </g> |
319 | -</svg> |
320 | \ No newline at end of file |
321 | +</svg> |
322 | diff --git a/src/pyproject.toml b/src/pyproject.toml |
323 | new file mode 100644 |
324 | index 0000000..7ae7f41 |
325 | --- /dev/null |
326 | +++ b/src/pyproject.toml |
327 | @@ -0,0 +1,35 @@ |
328 | +# This is a template `pyproject.toml` file for reactive charms |
329 | +# This file is managed by bootstack-charms-spec and should not be modified |
330 | +# within individual charm repos. https://launchpad.net/bootstack-charms-spec |
331 | + |
332 | +[tool.flake8] |
333 | +ignore = ["D100", "D101", "D102", "D103"] |
334 | +exclude = ['.eggs', '.git', '.tox', '.venv', '.build', 'report'] |
335 | +max-line-length = 88 |
336 | +max-complexity = 10 |
337 | + |
338 | +[tool.black] |
339 | +line-length = 88 |
340 | +exclude = ''' |
341 | +/( |
342 | + | .eggs |
343 | + | .git |
344 | + | .tox |
345 | + | .venv |
346 | + | .build |
347 | + | report |
348 | +)/ |
349 | +''' |
350 | + |
351 | +[tool.isort] |
352 | +profile = "black" |
353 | +skip_glob = ''' |
354 | +/( |
355 | + | .eggs |
356 | + | .git |
357 | + | .tox |
358 | + | .venv |
359 | + | .build |
360 | + | report |
361 | +)/ |
362 | +''' |
363 | diff --git a/src/reactive/telegraf.py b/src/reactive/telegraf.py |
364 | index 5548956..61aabcf 100644 |
365 | --- a/src/reactive/telegraf.py |
366 | +++ b/src/reactive/telegraf.py |
367 | @@ -30,13 +30,14 @@ import sys |
368 | import time |
369 | from distutils.version import LooseVersion |
370 | |
371 | +import charms.promreg |
372 | +import netifaces |
373 | +import yaml |
374 | from charmhelpers import context, fetch |
375 | from charmhelpers.contrib.charmsupport import nrpe |
376 | from charmhelpers.core import hookenv, host, kernel, unitdata |
377 | from charmhelpers.core.host import is_container |
378 | from charmhelpers.core.templating import render |
379 | - |
380 | -import charms.promreg |
381 | from charms import apt |
382 | from charms.layer import snap |
383 | from charms.reactive import ( |
384 | @@ -50,15 +51,9 @@ from charms.reactive import ( |
385 | when_not, |
386 | ) |
387 | from charms.reactive.bus import get_states |
388 | - |
389 | -from files.telegraf_exec_metrics import METRICS |
390 | - |
391 | from jinja2 import Environment, FileSystemLoader, Template, exceptions |
392 | |
393 | -import netifaces |
394 | - |
395 | -import yaml |
396 | - |
397 | +from files.telegraf_exec_metrics import METRICS |
398 | |
399 | DEB_BASE_DIR = "/etc/telegraf" |
400 | SNAP_BASE_DIR = "/var/snap/telegraf/current" |
401 | diff --git a/src/templates/apache-server-status.tmpl b/src/templates/apache-server-status.tmpl |
402 | index 18f8871..38e027c 100644 |
403 | --- a/src/templates/apache-server-status.tmpl |
404 | +++ b/src/templates/apache-server-status.tmpl |
405 | @@ -13,4 +13,3 @@ |
406 | Allow from localhost |
407 | </Location> |
408 | </VirtualHost> |
409 | - |
410 | diff --git a/src/templates/influxdb-api.conf.tmpl b/src/templates/influxdb-api.conf.tmpl |
411 | index 9d76988..0466afe 100644 |
412 | --- a/src/templates/influxdb-api.conf.tmpl |
413 | +++ b/src/templates/influxdb-api.conf.tmpl |
414 | @@ -4,7 +4,7 @@ |
415 | # Multiple urls can be specified but it is assumed that they are part of the same |
416 | # cluster, this means that only ONE of the urls will be written to each interval. |
417 | # urls = ["udp://localhost:8089"] # UDP endpoint example |
418 | - urls = {{ urls }} |
419 | + urls = {{ urls }} |
420 | # The target database for metrics (telegraf will create it if not exists) |
421 | database = "telegraf" # required |
422 | # Precision of writes, valid values are n, u, ms, s, m, and h |
423 | @@ -20,4 +20,3 @@ |
424 | user_agent = "telegraf" |
425 | # Set UDP payload size, defaults to InfluxDB UDP Client default (512 bytes) |
426 | # udp_payload = 512 |
427 | - |
428 | diff --git a/src/templates/sudoers/telegraf_intel_rdt.tmpl b/src/templates/sudoers/telegraf_intel_rdt.tmpl |
429 | index 0324a77..fb8edfd 100644 |
430 | --- a/src/templates/sudoers/telegraf_intel_rdt.tmpl |
431 | +++ b/src/templates/sudoers/telegraf_intel_rdt.tmpl |
432 | @@ -1,4 +1,3 @@ |
433 | Cmnd_Alias PQOS = /usr/sbin/pqos -r --iface-os --mon-file-type=csv --mon-interval=* |
434 | {{ telegraf_user }} ALL=(root) NOPASSWD: PQOS |
435 | Defaults!PQOS !logfile, !syslog, !pam_session |
436 | - |
437 | diff --git a/src/templates/sudoers/telegraf_ipmi.tmpl b/src/templates/sudoers/telegraf_ipmi.tmpl |
438 | index 463a608..14e2076 100644 |
439 | --- a/src/templates/sudoers/telegraf_ipmi.tmpl |
440 | +++ b/src/templates/sudoers/telegraf_ipmi.tmpl |
441 | @@ -1,4 +1,3 @@ |
442 | Cmnd_Alias IPMITOOL = /usr/bin/ipmitool sdr elist |
443 | {{ telegraf_user }} ALL=(root) NOPASSWD: IPMITOOL |
444 | Defaults!IPMITOOL !logfile, !syslog, !pam_session |
445 | - |
446 | diff --git a/src/templates/sudoers/telegraf_iptables.tmpl b/src/templates/sudoers/telegraf_iptables.tmpl |
447 | index 49354db..8e5f67d 100644 |
448 | --- a/src/templates/sudoers/telegraf_iptables.tmpl |
449 | +++ b/src/templates/sudoers/telegraf_iptables.tmpl |
450 | @@ -1,4 +1,3 @@ |
451 | Cmnd_Alias IPTABLESSHOW = /sbin/iptables -w 5 -nvL * |
452 | {{ telegraf_user }} ALL=(root) NOPASSWD: IPTABLESSHOW |
453 | Defaults!IPTABLESSHOW !logfile, !syslog, !pam_session |
454 | - |
455 | diff --git a/src/templates/sudoers/telegraf_ovs.tmpl b/src/templates/sudoers/telegraf_ovs.tmpl |
456 | index 27087b4..f53f1b7 100644 |
457 | --- a/src/templates/sudoers/telegraf_ovs.tmpl |
458 | +++ b/src/templates/sudoers/telegraf_ovs.tmpl |
459 | @@ -8,4 +8,3 @@ Cmnd_Alias OVSAPPCTL = /usr/bin/ovs-appctl |
460 | Defaults!OVSOFCTL !logfile, !syslog, !pam_session |
461 | Defaults!OVSVSCTL !logfile, !syslog, !pam_session |
462 | Defaults!OVSAPPCTL !logfile, !syslog, !pam_session |
463 | - |
464 | diff --git a/src/templates/sudoers/telegraf_smart.tmpl b/src/templates/sudoers/telegraf_smart.tmpl |
465 | index 1ceaf74..1f8d88c 100644 |
466 | --- a/src/templates/sudoers/telegraf_smart.tmpl |
467 | +++ b/src/templates/sudoers/telegraf_smart.tmpl |
468 | @@ -5,4 +5,3 @@ Defaults!SMARTCTL !logfile, !syslog, !pam_session |
469 | Cmnd_Alias NVME = /usr/sbin/nvme |
470 | {{ telegraf_user }} ALL=(root) NOPASSWD: NVME |
471 | Defaults!NVME !logfile, !syslog, !pam_session |
472 | - |
473 | diff --git a/src/templates/telegraf.conf.tmpl b/src/templates/telegraf.conf.tmpl |
474 | index 966b4a9..fe64b76 100644 |
475 | --- a/src/templates/telegraf.conf.tmpl |
476 | +++ b/src/templates/telegraf.conf.tmpl |
477 | @@ -46,7 +46,7 @@ |
478 | |
479 | # Telegraf will cache metric_buffer_limit metrics for each output, and will |
480 | # flush this buffer on a successful write. |
481 | - metric_buffer_limit = {{ metric_buffer_limit }} |
482 | + metric_buffer_limit = {{ metric_buffer_limit }} |
483 | |
484 | # Collection jitter is used to jitter the collection by a random amount. |
485 | # Each plugin will sleep for a random time within jitter before collecting. |
486 | @@ -63,9 +63,9 @@ |
487 | flush_jitter = "{{ flush_jitter }}" |
488 | |
489 | # Run telegraf in debug mode |
490 | - debug = {% if debug %}true{% else %}false{% endif %} |
491 | + debug = {% if debug %}true{% else %}false{% endif %} |
492 | # Run telegraf in quiet mode |
493 | - quiet = {% if quiet %}true{% else %}false{% endif %} |
494 | + quiet = {% if quiet %}true{% else %}false{% endif %} |
495 | # Override default hostname, if empty use os.Hostname() |
496 | hostname = "{{ hostname }}" |
497 | |
498 | diff --git a/src/tests/functional/tests/base.py b/src/tests/functional/tests/base.py |
499 | index 5f097ca..30d5667 100644 |
500 | --- a/src/tests/functional/tests/base.py |
501 | +++ b/src/tests/functional/tests/base.py |
502 | @@ -5,11 +5,9 @@ import time |
503 | import unittest |
504 | |
505 | import requests |
506 | - |
507 | from zaza import model |
508 | from zaza.utilities import juju |
509 | |
510 | - |
511 | DEFAULT_HTTPGET_TIMEOUT = 10 |
512 | DEFAULT_RETRIES = 12 |
513 | DEFAULT_RETRIES_TIMEOUT = 5 |
514 | diff --git a/src/tests/functional/tests/test_telegraf.py b/src/tests/functional/tests/test_telegraf.py |
515 | index 44e46e6..4ba7202 100644 |
516 | --- a/src/tests/functional/tests/test_telegraf.py |
517 | +++ b/src/tests/functional/tests/test_telegraf.py |
518 | @@ -16,7 +16,6 @@ |
519 | import logging |
520 | |
521 | from tenacity import retry, stop_after_attempt, wait_fixed |
522 | - |
523 | from zaza import model |
524 | |
525 | from .base import BaseTelegrafTest |
526 | diff --git a/src/tests/functional/tests/tests.yaml b/src/tests/functional/tests/tests.yaml |
527 | index a2265ab..7bc01f7 100644 |
528 | --- a/src/tests/functional/tests/tests.yaml |
529 | +++ b/src/tests/functional/tests/tests.yaml |
530 | @@ -33,4 +33,3 @@ tests: |
531 | - tests.test_telegraf.TestTelegraf |
532 | - compute: |
533 | - tests.test_compute.TestTelegrafCompute |
534 | - |
535 | diff --git a/src/tests/unit/requirements.txt b/src/tests/unit/requirements.txt |
536 | index eddbac0..49e57e1 100644 |
537 | --- a/src/tests/unit/requirements.txt |
538 | +++ b/src/tests/unit/requirements.txt |
539 | @@ -1,12 +1,3 @@ |
540 | -coverage |
541 | -flake8 |
542 | -pytest |
543 | -pytest-cov |
544 | pytest-mock |
545 | -pytest-xdist |
546 | netifaces |
547 | -insights-core |
548 | -charms.reactive>=1.3.0 |
549 | -requests |
550 | -pbr |
551 | -urllib3 |
552 | +jinja2 |
553 | diff --git a/src/tests/unit/test_telegraf.py b/src/tests/unit/test_telegraf.py |
554 | index 43ffbd0..7f409e4 100644 |
555 | --- a/src/tests/unit/test_telegraf.py |
556 | +++ b/src/tests/unit/test_telegraf.py |
557 | @@ -28,21 +28,17 @@ from textwrap import dedent |
558 | from unittest import mock |
559 | from unittest.mock import MagicMock, call, patch |
560 | |
561 | +import charms |
562 | +import py |
563 | +import pytest |
564 | +import yaml |
565 | from charmhelpers import fetch |
566 | from charmhelpers.core import host, kernel |
567 | from charmhelpers.core.hookenv import Config |
568 | from charmhelpers.core.templating import render |
569 | from charmhelpers.fetch import apt_pkg |
570 | - |
571 | -import charms |
572 | from charms.reactive import RelationBase, bus, helpers, set_flag |
573 | |
574 | -import py |
575 | - |
576 | -import pytest |
577 | - |
578 | -import yaml |
579 | - |
580 | # Mock layer modules |
581 | apt = MagicMock() |
582 | layer = MagicMock() |
583 | diff --git a/src/tests/lint/render_sudoers.py b/src/tests/unit/test_templates_sudoers.py |
584 | similarity index 50% |
585 | rename from src/tests/lint/render_sudoers.py |
586 | rename to src/tests/unit/test_templates_sudoers.py |
587 | index 4005ce1..8e50262 100644 |
588 | --- a/src/tests/lint/render_sudoers.py |
589 | +++ b/src/tests/unit/test_templates_sudoers.py |
590 | @@ -1,12 +1,17 @@ |
591 | import os |
592 | +import subprocess |
593 | +import tempfile |
594 | |
595 | from jinja2 import Environment, FileSystemLoader |
596 | |
597 | -template_dir = os.path.join("templates/sudoers") |
598 | -for template in os.listdir(template_dir): |
599 | - environment = Environment(loader=FileSystemLoader(template_dir)) |
600 | - template = environment.get_template(template) |
601 | - # A simple print(telegraf_user="test-user") would append a newline. |
602 | - # We want to detect if the rendered template lacks a trailing |
603 | - # newline, as it would break sudo when deployed. Hence end=''. |
604 | - print(template.render(telegraf_user="test-user"), end="") |
605 | + |
606 | +def test_sudoers_templates(): |
607 | + template_dir = os.path.join("templates/sudoers") |
608 | + for template in os.listdir(template_dir): |
609 | + environment = Environment(loader=FileSystemLoader(template_dir)) |
610 | + template = environment.get_template(template) |
611 | + with tempfile.NamedTemporaryFile(mode="w") as tmp: |
612 | + tmp.write(template.render(telegraf_user="test-user")) |
613 | + tmp.flush() |
614 | + # check the templates with visudo check-only mode |
615 | + subprocess.check_call(["visudo", "-csf", tmp.name]) |
616 | diff --git a/src/tox.ini b/src/tox.ini |
617 | index 4b7128f..d371a80 100644 |
618 | --- a/src/tox.ini |
619 | +++ b/src/tox.ini |
620 | @@ -1,6 +1,9 @@ |
621 | +# This is a template `tox.ini` file for reactive charms |
622 | +# This file is managed by bootstack-charms-spec and should not be modified |
623 | +# within individual charm repos. https://launchpad.net/bootstack-charms-spec |
624 | + |
625 | [tox] |
626 | skipsdist=True |
627 | -skip_missing_interpreters = True |
628 | envlist = lint, unit, func |
629 | |
630 | [testenv] |
631 | @@ -21,68 +24,65 @@ passenv = |
632 | NO_PROXY |
633 | SNAP_HTTP_PROXY |
634 | SNAP_HTTPS_PROXY |
635 | - OS_REGION_NAME |
636 | - OS_AUTH_VERSION |
637 | - OS_AUTH_URL |
638 | - OS_PROJECT_DOMAIN_NAME |
639 | - OS_USERNAME |
640 | - OS_PASSWORD |
641 | - OS_PROJECT_ID |
642 | - OS_USER_DOMAIN_NAME |
643 | - OS_PROJECT_NAME |
644 | - OS_IDENTITY_API_VERSION |
645 | + OS_* |
646 | + |
647 | +[testenv:dev-environment] |
648 | +envdir = {toxinidir}/.venv |
649 | +deps = |
650 | + pre-commit |
651 | + {[testenv:lint]deps} |
652 | + {[testenv:unit]deps} |
653 | + {[testenv:func]deps} |
654 | + |
655 | +[testenv:pre-commit] |
656 | +envdir = {[testenv:dev-environment]envdir} |
657 | +deps = {[testenv:dev-environment]deps} # ensure that dev-environment is installed |
658 | +commands = pre-commit run --all-files |
659 | |
660 | [testenv:lint] |
661 | commands = |
662 | - flake8 |
663 | - black --check --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" . |
664 | - bash -c "python3 tests/lint/render_sudoers.py | visudo -csf -" |
665 | + pflake8 |
666 | + black --check --diff --color . |
667 | + isort --check --diff --color . |
668 | +whitelist_externals = bash |
669 | deps = |
670 | black |
671 | - flake8 |
672 | - flake8-colors |
673 | + # NOTE(rgildein): It is necessary to limit flake8 with version 5.0.0, due |
674 | + # to the problem https://github.com/csachs/pyproject-flake8/issues/13. |
675 | + flake8 < 5.0.0 |
676 | + pyproject-flake8 |
677 | flake8-docstrings |
678 | - flake8-import-order |
679 | - jinja2 |
680 | pep8-naming |
681 | -whitelist_externals = bash |
682 | - |
683 | -[flake8] |
684 | -exclude = |
685 | - .git, |
686 | - __pycache__, |
687 | - .tox, |
688 | - charmhelpers, |
689 | - mod, |
690 | - .build |
691 | -#ignore = I100, D101, D102, D103, I201, D205, W504, D400, D401, D403, D209, D100, E403, I101, E501, N803, E226, E128, D200, E741, D202, E261, E402, D104, W503, E231 # TODO |
692 | -ignore = D100, D101, D102, D103 |
693 | - |
694 | -max-line-length = 88 |
695 | -max-complexity = 10 |
696 | + flake8-colors |
697 | + colorama |
698 | + isort |
699 | |
700 | -[testenv:black] |
701 | +[testenv:reformat] |
702 | +envdir = {toxworkdir}/lint |
703 | commands = |
704 | - black --exclude "/(\.eggs|\.git|\.tox|\.venv|\.build|dist|charmhelpers|mod)/" . |
705 | -deps = |
706 | - black |
707 | + black . |
708 | + isort . |
709 | +deps = {[testenv:lint]deps} |
710 | |
711 | [testenv:unit] |
712 | -commands = |
713 | - pytest {posargs:-vvv -s -n auto --ignore {toxinidir}/tests/functional \ |
714 | - --cov=lib \ |
715 | +commands = pytest {toxinidir}/tests/unit \ |
716 | + {posargs:-v \ |
717 | --cov=reactive \ |
718 | --cov=actions \ |
719 | --cov=hooks \ |
720 | - --cov=src \ |
721 | + --cov=files \ |
722 | + --cov=lib \ |
723 | --cov-report=term \ |
724 | - --cov-report=annotate:report/annotated \ |
725 | --cov-report=html:report/html} |
726 | -deps = -r{toxinidir}/tests/unit/requirements.txt |
727 | +deps = |
728 | + -r {toxinidir}/requirements.txt |
729 | + -r {toxinidir}/tests/unit/requirements.txt |
730 | + pytest |
731 | + pytest-cov |
732 | |
733 | [testenv:func] |
734 | changedir = {toxinidir}/tests/functional |
735 | commands = functest-run-suite {posargs:--keep-faulty-model} |
736 | deps = |
737 | - git+https://github.com/openstack-charmers/zaza.git#egg=zaza |
738 | -r {toxinidir}/tests/functional/requirements.txt |
739 | + git+https://github.com/openstack-charmers/zaza.git#egg=zaza |
tested with scrip: https:/ /pastebin. ubuntu. com/p/vQ96wzpJt 4/ /pastebin. ubuntu. com/p/CJy93VVq7 C/ netifaces, python3- yaml,sysstat, telegraf" message
result from tests: https:/
- tests for focal-postgres failed, so I tried to run
`make functional FUNC_ARGS="--dev"` <==> run only focal-compute,
but same result
- those tested failed because unit is in "maintenance" state with
"Installing python3-
- I do not think that this changes is responsible for that