66"""
77# pylint: disable=resource-leakage
88
9+ import getpass
910import hashlib
1011import optparse # pylint: disable=deprecated-module
1112import os
1718import tempfile
1819import time
1920import uuid
20- import getpass
21+
22+ import support .runtests
2123
2224import salt .utils .files
2325import salt .utils .yaml
24- import support .runtests
2526
2627OSES = [
2728 "Arch" ,
4041 "3007.1" ,
4142]
4243
44+
4345def parse ():
4446 """
4547 Parse the cli options
4648 """
4749 guidance = (
48- "\n \n To execute salt commands against minionswarm you must include the configuration\n "
49- " file using the -c option. For commands such as salt, salt-key, salt-cp,\n "
50- " and salt-run use -c <temp-dir>/master. For example, when using the\n "
51- " default for --temp-dir, the configuration directory would be\n "
52- " /tmp/sroot/master. If the master runs on a different machine you\n "
53- " must execute the command on that machine using the master config file\n "
54- " there. For the salt-call command, which is a minion side\n "
55- " command, use -c <tmp-dir>/<name>-<minion number>. For example to\n "
56- " execute salt-call on the first minion using the default values for\n "
57- " temp-dir and name use -c /tmp/sroot/minion-0. The commands salt-api,\n "
58- " salt-cloud, salt-extend, salt-master, salt-minion, salt-proxy,\n "
59- " salt-ssh, salt-syndic and spm are not supported."
50+ "\n \n To execute salt commands against minionswarm you must include the configuration\n "
51+ " file using the -c option. For commands such as salt, salt-key, salt-cp,\n "
52+ " and salt-run use -c <temp-dir>/master. For example, when using the\n "
53+ " default for --temp-dir, the configuration directory would be\n "
54+ " /tmp/sroot/master. If the master runs on a different machine you\n "
55+ " must execute the command on that machine using the master config file\n "
56+ " there. For the salt-call command, which is a minion side\n "
57+ " command, use -c <tmp-dir>/<name>-<minion number>. For example to\n "
58+ " execute salt-call on the first minion using the default values for\n "
59+ " temp-dir and name use -c /tmp/sroot/minion-0. The commands salt-api,\n "
60+ " salt-cloud, salt-extend, salt-master, salt-minion, salt-proxy,\n "
61+ " salt-ssh, salt-syndic and spm are not supported."
6062 )
6163 usage = "usage: python %prog [options]" + guidance
6264 parser = optparse .OptionParser (usage )
@@ -80,17 +82,17 @@ def parse():
8082 dest = "master" ,
8183 default = "localhost" ,
8284 help = "The location of the salt master that this swarm will serve. (default = localhost) "
83- "The standard port used by daemon masters is 4506. Masters can be specified using "
84- "<IP address>:<port>. For example, 192.168.1.2:4506" ,
85+ "The standard port used by daemon masters is 4506. Masters can be specified using "
86+ "<IP address>:<port>. For example, 192.168.1.2:4506" ,
8587 )
8688 parser .add_option (
8789 "--name" ,
8890 "-n" ,
8991 dest = "name" ,
9092 default = "minion" ,
9193 help = "Give the minions an alternative id prefix, this is used "
92- "when minions from many systems are being aggregated onto "
93- "a single master. (default = minion)" ,
94+ "when minions from many systems are being aggregated onto "
95+ "a single master. (default = minion)" ,
9496 )
9597 parser .add_option (
9698 "--rand-os" ,
@@ -146,10 +148,10 @@ def parse():
146148 action = "store_true" ,
147149 default = False ,
148150 help = "Don't cleanup temporary files/directories. "
149- "If specified, you must manually recursively delete "
150- "the swarm root (see --temp-dir) before running "
151- "minionswarm again, e.g., using the default swarm "
152- "root, rm -fr /tmp/srooot" ,
151+ "If specified, you must manually recursively delete "
152+ "the swarm root (see --temp-dir) before running "
153+ "minionswarm again, e.g., using the default swarm "
154+ "root, rm -fr /tmp/srooot" ,
153155 )
154156 parser .add_option (
155157 "--root-dir" ,
@@ -162,9 +164,9 @@ def parse():
162164 dest = "transport" ,
163165 default = "zeromq" ,
164166 help = "Declare which transport to use, (default = zeromq). Currently, "
165- "tcp/TLS and ws/TLS are not supported, since they require the "
166- "establishment of a certificate infrastructure and use of PKI "
167- "keys manaaged by that infrastructure."
167+ "tcp/TLS and ws/TLS are not supported, since they require the "
168+ "establishment of a certificate infrastructure and use of PKI "
169+ "keys manaaged by that infrastructure." ,
168170 )
169171 parser .add_option (
170172 "--start-delay" ,
@@ -178,17 +180,17 @@ def parse():
178180 "--config-dir" ,
179181 default = "" ,
180182 help = "Pass in a configuration directory containing base configuration. "
181- "If a configuration directory is specified, at a minimum, it must "
182- "have a master and minion configuration file and these files "
183- "must not be empty. For example, each could have a user: <username> "
184- "entry."
183+ "If a configuration directory is specified, at a minimum, it must "
184+ "have a master and minion configuration file and these files "
185+ "must not be empty. For example, each could have a user: <username> "
186+ "entry." ,
185187 )
186188 parser .add_option (
187189 "--open-mode" ,
188190 dest = "open_mode" ,
189191 default = True ,
190192 help = "Turn off authentication at the Master. Default is True to align "
191- "this version of minionswarm with previous version."
193+ "this version of minionswarm with previous version." ,
192194 )
193195 parser .add_option ("-u" , "--user" , default = support .runtests .this_user ())
194196
@@ -320,7 +322,9 @@ def start_minions(self):
320322 self .prep_configs ()
321323 username = getpass .getuser ()
322324 for path in self .confs :
323- cmd = "salt-minion -c {} --user={} --pid-file {}" .format (path , username , f"{ path } .pid" )
325+ cmd = "salt-minion -c {} --user={} --pid-file {}" .format (
326+ path , username , f"{ path } .pid"
327+ )
324328 if self .opts ["foreground" ]:
325329 cmd += " -l debug &"
326330 else :
@@ -408,7 +412,9 @@ def _update_minion_conf(self, data): # pylint: disable=W0221
408412
409413 cachdir_path = os .path .join (self .swarm_root , "var/cache/salt/minion" )
410414 sock_dir_path = os .path .join (self .swarm_root , "var/run/salt/minion" )
411- extension_modules_dir_path = os .path .join (self .swarm_root , "var/cache/salt/minion/extmods" )
415+ extension_modules_dir_path = os .path .join (
416+ self .swarm_root , "var/cache/salt/minion/extmods"
417+ )
412418 pki_dir_path = os .path .join (self .swarm_root , "etc/salt/pki/minion" )
413419
414420 try :
@@ -426,7 +432,7 @@ def _update_minion_conf(self, data): # pylint: disable=W0221
426432 {
427433 "cachedir" : cachdir_path ,
428434 "sock_dir" : sock_dir_path ,
429- "extension_modules" : extension_modules_dir_path ,
435+ "extension_modules" : extension_modules_dir_path ,
430436 "pki_dir" : pki_dir_path ,
431437 }
432438 )
@@ -465,10 +471,12 @@ def start(self):
465471 def start_master (self ):
466472 """
467473 Do the master start.. Run the master as the user under which minionswarm runs.
468- """
474+ """
469475
470476 username = getpass .getuser ()
471- cmd = "salt-master '--config-dir={}' --user={} --pid-file {}" .format (self .conf , username , f"{ self .conf } .pid" )
477+ cmd = "salt-master '--config-dir={}' --user={} --pid-file {}" .format (
478+ self .conf , username , f"{ self .conf } .pid"
479+ )
472480 if self .opts ["foreground" ]:
473481 cmd += " -l debug &"
474482 else :
@@ -534,7 +542,7 @@ def _update_master_conf(self, data): # pylint: disable=W0221
534542 "key_logfile" : key_logfile_path ,
535543 "cachedir" : cachdir_path ,
536544 "sock_dir" : sock_dir_path ,
537- "sqlite_queue_dir" : sqlite_queue_dir_path ,
545+ "sqlite_queue_dir" : sqlite_queue_dir_path ,
538546 }
539547 )
540548
0 commit comments