Spawning platform fix

This commit is contained in:
Daniel A. Wozniak 2023-08-21 00:05:17 -07:00 committed by Gareth J. Greenaway
parent c2a4baf11f
commit af2c268347
5 changed files with 55 additions and 12 deletions

View file

@ -19,7 +19,6 @@ import salt.crypt
import salt.master
import salt.payload
import salt.transport.frame
import salt.transport.ipc
import salt.utils.channel
import salt.utils.event
import salt.utils.files

View file

@ -1612,7 +1612,7 @@ class Crypticle:
self.serial = serial
@classmethod
def generate_key_string(cls, key_size=192):
def generate_key_string(cls, key_size=192, **kwargs):
key = os.urandom(key_size // 8 + cls.SIG_SIZE)
b64key = base64.b64encode(key)
b64key = b64key.decode("utf-8")

View file

@ -749,21 +749,15 @@ class Master(SMaster):
"reload": cluster_keygen,
}
# Wrap generate_key_string to ignore remove keyward arg.
def master_keygen(*args, **kwargs):
return salt.crypt.Crypticle.generate_key_string()
SMaster.secrets["aes"] = {
"secret": multiprocessing.Array(
ctypes.c_char,
salt.utils.stringutils.to_bytes(
salt.crypt.Crypticle.generate_key_string()
),
salt.utils.stringutils.to_bytes(salt.crypt.Crypticle.generate_key_string()),
),
"serial": multiprocessing.Value(
ctypes.c_longlong, lock=False # We'll use the lock from 'secret'
),
"reload": master_keygen,
"reload": salt.crypt.Crypticle.generate_key_string,
}
log.info("Creating master process manager")

View file

@ -41,6 +41,7 @@ def cluster_master_1(request, salt_factories, cluster_pki_path, cluster_cache_pa
"cluster_id": "master_cluster",
"cluster_peers": [
"127.0.0.2",
"127.0.0.3",
],
"cluster_pki_dir": str(cluster_pki_path),
"cache_dir": str(cluster_cache_path),
@ -74,6 +75,7 @@ def cluster_master_2(salt_factories, cluster_master_1):
"cluster_id": "master_cluster",
"cluster_peers": [
"127.0.0.1",
"127.0.0.3",
],
"cluster_pki_dir": cluster_master_1.config["cluster_pki_dir"],
"cache_dir": cluster_master_1.config["cache_dir"],
@ -95,6 +97,42 @@ def cluster_master_2(salt_factories, cluster_master_1):
yield factory
@pytest.fixture
def cluster_master_3(salt_factories, cluster_master_1):
if salt.utils.platform.is_darwin() or salt.utils.platform.is_freebsd():
subprocess.check_output(["ifconfig", "lo0", "alias", "127.0.0.3", "up"])
config_defaults = {
"open_mode": True,
"transport": cluster_master_1.config["transport"],
}
config_overrides = {
"interface": "127.0.0.3",
"cluster_id": "master_cluster",
"cluster_peers": [
"127.0.0.1",
"127.0.0.2",
],
"cluster_pki_dir": cluster_master_1.config["cluster_pki_dir"],
"cache_dir": cluster_master_1.config["cache_dir"],
}
# Use the same ports for both masters, they are binding to different interfaces
for key in (
"ret_port",
"publish_port",
):
config_overrides[key] = cluster_master_1.config[key]
factory = salt_factories.salt_master_daemon(
"127.0.0.3",
defaults=config_defaults,
overrides=config_overrides,
extra_cli_arguments_after_first_start_failure=["--log-level=info"],
)
with factory.started(start_timeout=120):
yield factory
#
# @pytest.fixture(scope="package")
# def cluster_master_2_salt_cli(cluster_master_2):

View file

@ -10,7 +10,8 @@ def test_basic_cluster_setup(
ret = cli1.run("config.get", "cache_dir")
assert str(cluster_cache_path) == ret.stdout
ret = cli1.run("config.get", "cluster_peers")
assert ["127.0.0.2"] == ret.data
ret.data.sort()
assert ["127.0.0.2", "127.0.0.3"] == ret.data
cli2 = cluster_master_2.salt_run_cli(timeout=120)
ret = cli2.run("config.get", "cluster_pki_dir")
@ -18,8 +19,11 @@ def test_basic_cluster_setup(
ret = cli2.run("config.get", "cache_dir")
assert str(cluster_cache_path) == ret.stdout
ret = cli2.run("config.get", "cluster_peers")
assert ["127.0.0.1"] == ret.data
ret.data.sort()
assert ["127.0.0.1", "127.0.0.3"] == ret.data
# Check for shared keys. Note: The third master 127.0.0.3 was never
# started.
peers_path = cluster_pki_path / "peers"
unexpected = False
found = []
@ -62,3 +66,11 @@ def test_basic_cluster_minion_1_from_master_2(
cli = cluster_master_2.salt_cli(timeout=120)
ret = cli.run("test.ping", minion_tgt="cluster-minion-1")
assert ret.data is True
def test_basic_cluster_minion_1_from_master_3(
cluster_master_1, cluster_master_2, cluster_master_3, cluster_minion_1
):
cli = cluster_master_3.salt_cli(timeout=120)
ret = cli.run("test.ping", minion_tgt="cluster-minion-1")
assert ret.data is True