Merge pull request #64467 from cmcmarrow/remove_payload_Serial

[master] remove salt.payload.Serial
This commit is contained in:
Megan Wilhite 2023-08-15 20:12:28 +00:00 committed by GitHub
commit 4f03b1d6ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 79 deletions

View file

@ -0,0 +1 @@
Remove salt.payload.Serial

View file

@ -233,26 +233,6 @@ def dump(msg, fn_):
fn_.close()
class Serial:
"""
Create a serialization object, this object manages all message
serialization in Salt
"""
def __init__(self, *args, **kwargs):
salt.utils.versions.warn_until(
3007,
"The `salt.payload.Serial` class has been deprecated, "
"and is set to be removed in {version}. "
"Please use `salt.payload.loads` and `salt.payload.dumps`.",
)
loads = staticmethod(loads)
dumps = staticmethod(dumps)
dump = staticmethod(dump)
load = staticmethod(load)
class SREQ:
"""
Create a generic interface to wrap salt zeromq req calls.

View file

@ -235,26 +235,6 @@ class MockState:
pass
class MockSerial:
"""
Mock Class
"""
@staticmethod
def load(data):
"""
Mock load method
"""
return {"A": "B"}
@staticmethod
def dump(data, data1):
"""
Mock dump method
"""
return True
class MockTarFile:
"""
Mock tarfile class
@ -798,36 +778,33 @@ def test_highstate():
mock = MagicMock(return_value=True)
with patch.object(state, "_filter_running", mock):
mock = MagicMock(return_value=True)
with patch.object(salt.payload, "Serial", mock):
with patch.object(os.path, "join", mock):
with patch.object(state, "_set" "_retcode", mock):
assert state.highstate(arg)
with patch.object(os.path, "join", mock):
with patch.object(state, "_set" "_retcode", mock):
assert state.highstate(arg)
def test_clear_request():
"""
Test to clear out the state execution request without executing it
"""
mock = MagicMock(return_value=True)
with patch.object(salt.payload, "Serial", mock):
mock = MagicMock(side_effect=[False, True, True])
with patch.object(os.path, "isfile", mock):
assert state.clear_request("A")
mock = MagicMock(side_effect=[False, True, True])
with patch.object(os.path, "isfile", mock):
assert state.clear_request("A")
mock = MagicMock(return_value=True)
with patch.object(os, "remove", mock):
assert state.clear_request()
mock = MagicMock(return_value=True)
with patch.object(os, "remove", mock):
assert state.clear_request()
mock = MagicMock(return_value={})
with patch.object(state, "check_request", mock):
assert not state.clear_request("A")
mock = MagicMock(return_value={})
with patch.object(state, "check_request", mock):
assert not state.clear_request("A")
def test_check_request():
"""
Test to return the state request information
"""
with patch("salt.modules.state.salt.payload", MockSerial):
with patch("salt.payload.load", MagicMock(return_value={"A": "B"})):
mock = MagicMock(side_effect=[True, True, False])
with patch.object(os.path, "isfile", mock):
with patch("salt.utils.files.fopen", mock_open(b"")):
@ -933,42 +910,42 @@ def test_get_test_value():
with patch.dict(state.__opts__, {test_arg: True}):
assert state._get_test_value(
test=None
), "Failure when {} is True in __opts__".format(test_arg)
), f"Failure when {test_arg} is True in __opts__"
with patch.dict(config.__pillar__, {test_arg: "blah"}):
assert not state._get_test_value(
test=None
), "Failure when {} is blah in __opts__".format(test_arg)
), f"Failure when {test_arg} is blah in __opts__"
with patch.dict(config.__pillar__, {test_arg: "true"}):
assert not state._get_test_value(
test=None
), "Failure when {} is true in __opts__".format(test_arg)
), f"Failure when {test_arg} is true in __opts__"
with patch.dict(config.__opts__, {test_arg: False}):
assert not state._get_test_value(
test=None
), "Failure when {} is False in __opts__".format(test_arg)
), f"Failure when {test_arg} is False in __opts__"
with patch.dict(config.__opts__, {}):
assert not state._get_test_value(
test=None
), "Failure when {} does not exist in __opts__".format(test_arg)
), f"Failure when {test_arg} does not exist in __opts__"
with patch.dict(config.__pillar__, {test_arg: None}):
assert (
state._get_test_value(test=None) is None
), "Failure when {} is None in __opts__".format(test_arg)
), f"Failure when {test_arg} is None in __opts__"
with patch.dict(config.__pillar__, {test_arg: True}):
assert state._get_test_value(
test=None
), "Failure when {} is True in __pillar__".format(test_arg)
), f"Failure when {test_arg} is True in __pillar__"
with patch.dict(config.__pillar__, {"master": {test_arg: True}}):
assert state._get_test_value(
test=None
), "Failure when {} is True in master __pillar__".format(test_arg)
), f"Failure when {test_arg} is True in master __pillar__"
with patch.dict(config.__pillar__, {"master": {test_arg: False}}):
with patch.dict(config.__pillar__, {test_arg: True}):
@ -989,13 +966,13 @@ def test_get_test_value():
with patch.dict(state.__opts__, {"test": False}):
assert not state._get_test_value(
test=None
), "Failure when {} is False in __opts__".format(test_arg)
), f"Failure when {test_arg} is False in __opts__"
with patch.dict(state.__opts__, {"test": False}):
with patch.dict(config.__pillar__, {"master": {test_arg: True}}):
assert state._get_test_value(
test=None
), "Failure when {} is False in __opts__".format(test_arg)
), f"Failure when {test_arg} is False in __opts__"
with patch.dict(state.__opts__, {}):
assert state._get_test_value(test=True), "Failure when test is True as arg"
@ -1264,7 +1241,7 @@ def test_event():
"tag": "a_event_tag",
}
_expected = '"date": "{}"'.format(now)
_expected = f'"date": "{now}"'
with patch.object(SaltEvent, "get_event", return_value=event_returns):
print_cli_mock = MagicMock()
with patch.object(salt.utils.stringutils, "print_cli", print_cli_mock):

View file

@ -31,14 +31,13 @@ def test_load():
"""
Test if it return all of the data in the minion datastore
"""
with patch("salt.payload.Serial.load", MagicMock(return_value=True)):
mocked_fopen = MagicMock(return_value=True)
mocked_fopen.__enter__ = MagicMock(return_value=mocked_fopen)
mocked_fopen.__exit__ = MagicMock()
with patch("salt.utils.files.fopen", MagicMock(return_value=mocked_fopen)):
with patch("salt.payload.loads", MagicMock(return_value=True)):
with patch.dict(data.__opts__, {"cachedir": "/"}):
assert data.load()
mocked_fopen = MagicMock(return_value=True)
mocked_fopen.__enter__ = MagicMock(return_value=mocked_fopen)
mocked_fopen.__exit__ = MagicMock()
with patch("salt.utils.files.fopen", MagicMock(return_value=mocked_fopen)):
with patch("salt.payload.loads", MagicMock(return_value=True)):
with patch.dict(data.__opts__, {"cachedir": "/"}):
assert data.load()
# 'dump' function tests: 3

View file

@ -12,7 +12,6 @@ from tests.support.mock import MagicMock, call, patch
@pytest.fixture
def load_auth():
patches = (
("salt.payload.Serial", None),
(
"salt.loader.auth",
MagicMock(
@ -100,7 +99,7 @@ def master_acl_clear_funcs(master_acl_master_opts):
fire_event_mock = MagicMock(return_value="dummy_tag")
patches = (
("zmq.Context", MagicMock()),
("salt.payload.Serial.dumps", MagicMock()),
("salt.payload.dumps", MagicMock()),
("salt.master.tagify", MagicMock()),
("salt.utils.event.SaltEvent.fire_event", fire_event_mock),
("salt.auth.LoadAuth.time_auth", MagicMock(return_value=True)),
@ -450,11 +449,11 @@ async def test_master_minion_glob(master_acl_clear_funcs, master_acl_valid_load)
await master_acl_clear_funcs.publish(master_acl_valid_load)
assert (
master_acl_clear_funcs.event.fire_event.called is True
), "Did not fire {} for minion tgt {}".format(requested_function, requested_tgt)
), f"Did not fire {requested_function} for minion tgt {requested_tgt}"
assert (
master_acl_clear_funcs.event.fire_event.call_args[0][0]["fun"]
== requested_function
), "Did not fire {} for minion glob".format(requested_function)
), f"Did not fire {requested_function} for minion glob"
@pytest.mark.skip_on_windows(reason="PAM eauth not available on Windows")