Compare commits

...

4 Commits

Author SHA1 Message Date
50c638a000
roles.py: repair role walking
Improve nested role support introduced with
442ff683d1e5b3c15a7ef90b27c4be2b3e70ff30 by correctly converting
subdirectories into nested state references.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2023-01-21 19:40:19 +01:00
ab2f6802a9
Remove test-webserver role
No longer used, referenced profile removed in
a1782581bb5124ecee97baa86ef8a312ad4828d0.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2023-01-21 19:37:16 +01:00
a42961e982
Update mocking base
- adapt preparation script to new environment
- add sample mocking pillar including README

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2023-01-21 18:54:58 +01:00
97db5ef6db
Add nbroles_to_grains script + add note
Script allows for testing and pipeline minions to work without access to
the roles API. Additionally added a note about this in prepare_minion.py.

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
2023-01-21 18:54:58 +01:00
7 changed files with 61 additions and 8 deletions

4
bin/nbroles_to_grains.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
# This rewrites top-files to fetch roles from grains instead of our custom roles API. Useful for testing outside of the LibertaCasa infrastructure, but not recommended for production.
sed -i "s/salt\['nbroles.get'\](id)/grains\['roles'\]/" */top.sls

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3
# Prepares a minion for local testing of Salt code in this repository. Requires roles to be written as grains, as development and pipeline containers generally do not have access to our roles API. Consider nbroles_to_grains.sh first if this is the case.
import roles
import os

View File

@ -6,8 +6,9 @@ import socket
iddir = 'pillar/id/'
secretiddir = 'pillar/secret/id/'
baseidfile = 'atvkdev02_home_lysergic_dev.sls'
baseidfile = 'pillar/mock/example.sls'
myidfile = socket.gethostname() + '.sls'
shutil.copyfile(iddir + baseidfile, iddir + myidfile)
shutil.copyfile(secretiddir + baseidfile, secretiddir + myidfile)
shutil.copyfile(baseidfile, os.path.join(iddir, myidfile))
os.makedirs(secretiddir)
shutil.copyfile(baseidfile, os.path.join(secretiddir, myidfile))

View File

@ -8,10 +8,17 @@ excluded = ['common-suse', 'minion']
def get():
for root in ['pillar', 'salt']:
for rootdir, subdirs, files in os.walk(os.path.join(root, 'role')):
myrootdir = rootdir.split('/')
if len(myrootdir) > 2:
level = myrootdir[2:]
for file in files:
role = os.path.splitext(file)[0]
if not role in excluded and not role in roles:
roles.append(role)
splitfile = os.path.splitext(file)
if len(splitfile) == 2 and splitfile[1] == '.sls':
role = os.path.splitext(file)[0]
if len(myrootdir) > 2:
role = '.'.join(level) + '.' + role
if not role in excluded and not role in roles:
roles.append(role)
return roles
if __name__ == '__main__':

1
pillar/mock/README.md Normal file
View File

@ -0,0 +1 @@
This directory contains a sample pillar which is used for mocking and testing runs - the production infrastructure will ignore it. If new pillar options are introduced, it is encouraged to add them along with sample values here.

41
pillar/mock/example.sls Normal file
View File

@ -0,0 +1,41 @@
include:
- secret.id.{{ salt['grains.get']('id').replace('.', '_') }}
profile:
matterbridge:
instances:
libertacasa-general:
RemoteNickFormat: "{NOPINGNICK}/{LABEL}: "
IgnoreFailureOnStart: True
MessageSplit: True
MediaDownloadPath: /var/lib/matterbridge/libertacasa-general
MediaServerDownload: "https://dummy.load.casa"
accounts:
libertacasa:
protocol: irc
Nick: mocker02
NickServNick: mocker
Server: 'irc.casa:6697'
UseTLS: True
UseSASL: True
Label: libcasa
Charset: utf8
IgnoreNicks: HistServ
UseRelayMsg: True
RemoteNickFormat: "{NICK}/{PROTOCOL}-{LABEL}"
ergo:
protocol: irc
Nick: mocker
Server: 'irc.ergo.chat:6697'
UseTLS: True
Label: ergo
UseRelayMsg: True
gateways:
foobar:
irc.libertacasa: '#dev'
irc.ergo: '#chat'
lighttpd:
vhosts:
matterbridge-general:
host: mocker.example.com
root: /var/lib/matterbridge/libertacasa-general

View File

@ -1,2 +0,0 @@
include:
- profile.test-webserver