diff --git a/changelog/66147.removed.md b/changelog/66147.removed.md new file mode 100644 index 00000000000..c72f46820ac --- /dev/null +++ b/changelog/66147.removed.md @@ -0,0 +1,7 @@ +Removed deprecated code scheduled to be removed on 2024-01-01: + +* ``TemporaryLoggingHandler`` and ``QueueHandler`` in ``salt/_logging/handlers.py`` +* All of the ``salt/log`` package. +* The ``salt/modules/cassandra_mod.py`` module. +* The ``salt/returners/cassandra_return.py`` returner. +* The ``salt/returners/django_return.py`` returner. diff --git a/doc/ref/modules/all/index.rst b/doc/ref/modules/all/index.rst index abd40e0bc77..d2050df3403 100644 --- a/doc/ref/modules/all/index.rst +++ b/doc/ref/modules/all/index.rst @@ -93,7 +93,6 @@ execution modules cabal capirca_acl cassandra_cql - cassandra_mod celery ceph chassis diff --git a/doc/ref/modules/all/salt.modules.cassandra_mod.rst b/doc/ref/modules/all/salt.modules.cassandra_mod.rst deleted file mode 100644 index 68f64c0e313..00000000000 --- a/doc/ref/modules/all/salt.modules.cassandra_mod.rst +++ /dev/null @@ -1,5 +0,0 @@ -salt.modules.cassandra_mod -========================== - -.. automodule:: salt.modules.cassandra_mod - :members: diff --git a/doc/ref/returners/all/index.rst b/doc/ref/returners/all/index.rst index 54e4555544d..edce578d4b8 100644 --- a/doc/ref/returners/all/index.rst +++ b/doc/ref/returners/all/index.rst @@ -13,10 +13,8 @@ returner modules appoptics_return carbon_return cassandra_cql_return - cassandra_return couchbase_return couchdb_return - django_return elasticsearch_return etcd_return highstate_return diff --git a/doc/ref/returners/all/salt.returners.cassandra_return.rst b/doc/ref/returners/all/salt.returners.cassandra_return.rst deleted file mode 100644 index a67ef5f0eff..00000000000 --- a/doc/ref/returners/all/salt.returners.cassandra_return.rst +++ /dev/null @@ -1,5 +0,0 @@ -salt.returners.cassandra_return -=============================== - -.. automodule:: salt.returners.cassandra_return - :members: diff --git a/doc/ref/returners/all/salt.returners.django_return.rst b/doc/ref/returners/all/salt.returners.django_return.rst deleted file mode 100644 index b63df7ff19d..00000000000 --- a/doc/ref/returners/all/salt.returners.django_return.rst +++ /dev/null @@ -1,5 +0,0 @@ -salt.returners.django_return -============================ - -.. automodule:: salt.returners.django_return - :members: diff --git a/doc/topics/development/modules/index.rst b/doc/topics/development/modules/index.rst index 3fc59f9d0b2..1e499733562 100644 --- a/doc/topics/development/modules/index.rst +++ b/doc/topics/development/modules/index.rst @@ -128,7 +128,7 @@ Execution ``salt.modules`` (:ref:`index `) `` Executor ``salt.executors`` (:ref:`index `) ``executors`` ``executor_dirs`` File Server ``salt.fileserver`` (:ref:`index `) ``fileserver`` ``fileserver_dirs`` Grain ``salt.grains`` (:ref:`index `) ``grains`` ``grains_dirs`` -Log Handler ``salt.log.handlers`` (:ref:`index `) ``log_handlers`` ``log_handlers_dirs`` +Log Handler ``salt.log_handlers`` (:ref:`index `) ``log_handlers`` ``log_handlers_dirs`` Matcher ``salt.matchers`` ``matchers`` ``matchers_dirs`` Metaproxy ``salt.metaproxy`` ``metaproxy`` [#no-fs]_ ``metaproxy_dirs`` Net API ``salt.netapi`` (:ref:`index `) ``netapi`` [#no-fs]_ ``netapi_dirs`` diff --git a/salt/_logging/handlers.py b/salt/_logging/handlers.py index f4b0b6fec3d..da3aef54512 100644 --- a/salt/_logging/handlers.py +++ b/salt/_logging/handlers.py @@ -5,67 +5,16 @@ Salt's logging handlers """ -import copy import logging import logging.handlers -import queue as _queue import sys from collections import deque from salt._logging.mixins import ExcInfoOnLogLevelFormatMixin -from salt.utils.versions import warn_until_date log = logging.getLogger(__name__) -class TemporaryLoggingHandler(logging.NullHandler): - """ - This logging handler will store all the log records up to its maximum - queue size at which stage the first messages stored will be dropped. - - Should only be used as a temporary logging handler, while the logging - system is not fully configured. - - Once configured, pass any logging handlers that should have received the - initial log messages to the function - :func:`TemporaryLoggingHandler.sync_with_handlers` and all stored log - records will be dispatched to the provided handlers. - - .. versionadded:: 0.17.0 - """ - - def __init__(self, level=logging.NOTSET, max_queue_size=10000): - warn_until_date( - "20240101", - "Please stop using '{name}.TemporaryLoggingHandler'. " - "'{name}.TemporaryLoggingHandler' will go away after " - "{{date}}.".format(name=__name__), - ) - super().__init__(level=level) - self.__messages = deque(maxlen=max_queue_size) - - def handle(self, record): - self.acquire() - self.__messages.append(record) - self.release() - - def sync_with_handlers(self, handlers=()): - """ - Sync the stored log records to the provided log handlers. - """ - if not handlers: - return - - while self.__messages: - record = self.__messages.popleft() - for handler in handlers: - if handler.level > record.levelno: - # If the handler's level is higher than the log record one, - # it should not handle the log record - continue - handler.handle(record) - - class StreamHandler(ExcInfoOnLogLevelFormatMixin, logging.StreamHandler): """ Stream handler which properly handles exc_info on a per handler basis @@ -214,94 +163,3 @@ class WatchedFileHandler( """ Watched file handler which properly handles exc_info on a per handler basis """ - - -if sys.version_info < (3, 7): - # On python versions lower than 3.7, we sill subclass and overwrite prepare to include the fix for: - # https://bugs.python.org/issue35726 - class QueueHandler( - ExcInfoOnLogLevelFormatMixin, logging.handlers.QueueHandler - ): # pylint: disable=no-member,inconsistent-mro - def __init__(self, queue): # pylint: disable=useless-super-delegation - super().__init__(queue) - warn_until_date( - "20240101", - "Please stop using '{name}.QueueHandler' and instead " - "use 'logging.handlers.QueueHandler'. " - "'{name}.QueueHandler' will go away after " - "{{date}}.".format(name=__name__), - ) - - def enqueue(self, record): - """ - Enqueue a record. - - The base implementation uses put_nowait. You may want to override - this method if you want to use blocking, timeouts or custom queue - implementations. - """ - try: - self.queue.put_nowait(record) - except _queue.Full: - sys.stderr.write( - "[WARNING ] Message queue is full, " - 'unable to write "{}" to log.\n'.format(record) - ) - - def prepare(self, record): - """ - Prepares a record for queuing. The object returned by this method is - enqueued. - The base implementation formats the record to merge the message - and arguments, and removes unpickleable items from the record - in-place. - You might want to override this method if you want to convert - the record to a dict or JSON string, or send a modified copy - of the record while leaving the original intact. - """ - # The format operation gets traceback text into record.exc_text - # (if there's exception data), and also returns the formatted - # message. We can then use this to replace the original - # msg + args, as these might be unpickleable. We also zap the - # exc_info and exc_text attributes, as they are no longer - # needed and, if not None, will typically not be pickleable. - msg = self.format(record) - # bpo-35726: make copy of record to avoid affecting other handlers in the chain. - record = copy.copy(record) - record.message = msg - record.msg = msg - record.args = None - record.exc_info = None - record.exc_text = None - return record - -else: - - class QueueHandler( - ExcInfoOnLogLevelFormatMixin, logging.handlers.QueueHandler - ): # pylint: disable=no-member,inconsistent-mro - def __init__(self, queue): # pylint: disable=useless-super-delegation - super().__init__(queue) - warn_until_date( - "20240101", - "Please stop using '{name}.QueueHandler' and instead " - "use 'logging.handlers.QueueHandler'. " - "'{name}.QueueHandler' will go away after " - "{{date}}.".format(name=__name__), - ) - - def enqueue(self, record): - """ - Enqueue a record. - - The base implementation uses put_nowait. You may want to override - this method if you want to use blocking, timeouts or custom queue - implementations. - """ - try: - self.queue.put_nowait(record) - except _queue.Full: - sys.stderr.write( - "[WARNING ] Message queue is full, " - 'unable to write "{}" to log.\n'.format(record) - ) diff --git a/salt/log/__init__.py b/salt/log/__init__.py deleted file mode 100644 index 3458474f2ca..00000000000 --- a/salt/log/__init__.py +++ /dev/null @@ -1,31 +0,0 @@ -""" - :codeauthor: Pedro Algarvio (pedro@algarvio.me) - - - salt.log - ~~~~~~~~ - - This is where Salt's logging gets set up. Currently, the required imports - are made to assure backwards compatibility. -""" - -# Import several classes/functions from salt.log.setup for backwards compatibility -from salt._logging import LOG_LEVELS, SORTED_LEVEL_NAMES -from salt.log.setup import ( - is_console_configured, - is_logfile_configured, - is_logging_configured, - is_temp_logging_configured, - set_logger_level, - setup_console_logger, - setup_logfile_logger, - setup_temp_logger, -) -from salt.utils.versions import warn_until_date - -warn_until_date( - "20240101", - "Please stop using '{name}' and instead use 'salt._logging'. " - "'{name}' will go away after {{date}}.".format(name=__name__), - stacklevel=3, -) diff --git a/salt/log/handlers/__init__.py b/salt/log/handlers/__init__.py deleted file mode 100644 index 8bc740e20f1..00000000000 --- a/salt/log/handlers/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -import logging - -from salt._logging.handlers import ( - FileHandler, - QueueHandler, - RotatingFileHandler, - StreamHandler, - SysLogHandler, - TemporaryLoggingHandler, - WatchedFileHandler, -) -from salt.utils.versions import warn_until_date - -warn_until_date( - "20240101", - "Please stop using '{name}' and instead use 'salt._logging.handlers'. " - "'{name}' will go away after {{date}}.".format(name=__name__), -) - -NullHandler = logging.NullHandler diff --git a/salt/log/mixins.py b/salt/log/mixins.py deleted file mode 100644 index 6619b564198..00000000000 --- a/salt/log/mixins.py +++ /dev/null @@ -1,17 +0,0 @@ -# pylint: disable=unused-import -from salt._logging.mixins import ( - ExcInfoOnLogLevelFormatMixin as ExcInfoOnLogLevelFormatMixIn, -) -from salt._logging.mixins import LoggingGarbageMixin as LoggingGarbageMixIn -from salt._logging.mixins import LoggingMixinMeta as LoggingMixInMeta -from salt._logging.mixins import LoggingProfileMixin as LoggingProfileMixIn -from salt._logging.mixins import LoggingTraceMixin as LoggingTraceMixIn -from salt.utils.versions import warn_until_date - -# pylint: enable=unused-import - -warn_until_date( - "20240101", - "Please stop using '{name}' and instead use 'salt._logging.mixins'. " - "'{name}' will go away after {{date}}.".format(name=__name__), -) diff --git a/salt/log/setup.py b/salt/log/setup.py deleted file mode 100644 index 74bd7bbd3e1..00000000000 --- a/salt/log/setup.py +++ /dev/null @@ -1,201 +0,0 @@ -# pylint: disable=unused-import -from functools import wraps - -from salt._logging.handlers import ( - FileHandler, - QueueHandler, - RotatingFileHandler, - StreamHandler, - SysLogHandler, - WatchedFileHandler, -) -from salt._logging.impl import ( - LOG_COLORS, - LOG_LEVELS, - LOG_VALUES_TO_LEVELS, - SORTED_LEVEL_NAMES, - SaltColorLogRecord, - SaltLogRecord, -) -from salt._logging.impl import set_log_record_factory as setLogRecordFactory -from salt.utils.versions import warn_until_date - -warn_until_date( - "20240101", - "Please stop using '{name}' and instead use 'salt._logging'. " - "'{name}' will go away after {{date}}. Do note however that " - "'salt._logging' is now considered a non public implementation " - "and is subject to change without deprecations.".format(name=__name__), - stacklevel=4, -) - - -def _deprecated_warning(func): - @wraps(func) - def wrapper(*args, **kwargs): - warn_until_date( - "20240101", - "Please stop using 'salt.log.setup.{name}()' as it no longer does anything and " - "will go away after {{date}}.".format(name=func.__qualname__), - stacklevel=4, - ) - - return wrapper - - -@_deprecated_warning -def is_console_configured(): - pass - - -@_deprecated_warning -def is_logfile_configured(): - pass - - -@_deprecated_warning -def is_logging_configured(): - pass - - -@_deprecated_warning -def is_temp_logging_configured(): - pass - - -@_deprecated_warning -def is_mp_logging_listener_configured(): - pass - - -@_deprecated_warning -def is_mp_logging_configured(): - pass - - -@_deprecated_warning -def is_extended_logging_configured(): - pass - - -class SaltLogQueueHandler(QueueHandler): - """ - Subclassed just to differentiate when debugging - """ - - -@_deprecated_warning -def getLogger(name): - pass - - -@_deprecated_warning -def setup_temp_logger(log_level="error"): - pass - - -@_deprecated_warning -def setup_console_logger(log_level="error", log_format=None, date_format=None): - pass - - -@_deprecated_warning -def setup_logfile_logger( - log_path, - log_level="error", - log_format=None, - date_format=None, - max_bytes=0, - backup_count=0, -): - pass - - -@_deprecated_warning -def setup_extended_logging(opts): - pass - - -@_deprecated_warning -def get_multiprocessing_logging_queue(): - pass - - -@_deprecated_warning -def set_multiprocessing_logging_queue(queue): - pass - - -@_deprecated_warning -def get_multiprocessing_logging_level(): - pass - - -@_deprecated_warning -def set_multiprocessing_logging_level(log_level): - pass - - -@_deprecated_warning -def set_multiprocessing_logging_level_by_opts(opts): - pass - - -@_deprecated_warning -def setup_multiprocessing_logging(queue=None): - pass - - -@_deprecated_warning -def shutdown_console_logging(): - pass - - -@_deprecated_warning -def shutdown_logfile_logging(): - pass - - -@_deprecated_warning -def shutdown_temp_logging(): - pass - - -@_deprecated_warning -def shutdown_multiprocessing_logging(): - pass - - -@_deprecated_warning -def shutdown_multiprocessing_logging_listener(daemonizing=False): - pass - - -@_deprecated_warning -def set_logger_level(logger_name, log_level="error"): - pass - - -@_deprecated_warning -def patch_python_logging_handlers(): - pass - - -@_deprecated_warning -def __process_multiprocessing_logging_queue(opts, queue): - pass - - -@_deprecated_warning -def __remove_null_logging_handler(): - pass - - -@_deprecated_warning -def __remove_queue_logging_handler(): - pass - - -@_deprecated_warning -def __remove_temp_logging_handler(): - pass diff --git a/salt/modules/cassandra_mod.py b/salt/modules/cassandra_mod.py deleted file mode 100644 index 029fd08fb9b..00000000000 --- a/salt/modules/cassandra_mod.py +++ /dev/null @@ -1,218 +0,0 @@ -""" - -.. warning:: - - The `cassandra` module is deprecated in favor of the `cassandra_cql` - module. - -Cassandra NoSQL Database Module - -:depends: - pycassa Cassandra Python adapter -:configuration: - The location of the 'nodetool' command, host, and thrift port needs to be - specified via pillar:: - - cassandra.nodetool: /usr/local/bin/nodetool - cassandra.host: localhost - cassandra.thrift_port: 9160 -""" - -import logging - -import salt.utils.path -from salt.utils.versions import warn_until_date - -log = logging.getLogger(__name__) - - -HAS_PYCASSA = False -try: - from pycassa.system_manager import SystemManager - - HAS_PYCASSA = True -except ImportError: - pass - - -def __virtual__(): - """ - Only load if pycassa is available and the system is configured - """ - if not HAS_PYCASSA: - return ( - False, - "The cassandra execution module cannot be loaded: pycassa not installed.", - ) - - warn_until_date( - "20240101", - "The cassandra returner is broken and deprecated, and will be removed" - " after {date}. Use the cassandra_cql returner instead", - ) - - if HAS_PYCASSA and salt.utils.path.which("nodetool"): - return "cassandra" - return ( - False, - "The cassandra execution module cannot be loaded: nodetool not found.", - ) - - -def _nodetool(cmd): - """ - Internal cassandra nodetool wrapper. Some functions are not - available via pycassa so we must rely on nodetool. - """ - nodetool = __salt__["config.option"]("cassandra.nodetool") - host = __salt__["config.option"]("cassandra.host") - return __salt__["cmd.run_stdout"]("{} -h {} {}".format(nodetool, host, cmd)) - - -def _sys_mgr(): - """ - Return a pycassa system manager connection object - """ - thrift_port = str(__salt__["config.option"]("cassandra.THRIFT_PORT")) - host = __salt__["config.option"]("cassandra.host") - return SystemManager("{}:{}".format(host, thrift_port)) - - -def compactionstats(): - """ - Return compactionstats info - - CLI Example: - - .. code-block:: bash - - salt '*' cassandra.compactionstats - """ - return _nodetool("compactionstats") - - -def version(): - """ - Return the cassandra version - - CLI Example: - - .. code-block:: bash - - salt '*' cassandra.version - """ - return _nodetool("version") - - -def netstats(): - """ - Return netstats info - - CLI Example: - - .. code-block:: bash - - salt '*' cassandra.netstats - """ - return _nodetool("netstats") - - -def tpstats(): - """ - Return tpstats info - - CLI Example: - - .. code-block:: bash - - salt '*' cassandra.tpstats - """ - return _nodetool("tpstats") - - -def info(): - """ - Return cassandra node info - - CLI Example: - - .. code-block:: bash - - salt '*' cassandra.info - """ - return _nodetool("info") - - -def ring(): - """ - Return cassandra ring info - - CLI Example: - - .. code-block:: bash - - salt '*' cassandra.ring - """ - return _nodetool("ring") - - -def keyspaces(): - """ - Return existing keyspaces - - CLI Example: - - .. code-block:: bash - - salt '*' cassandra.keyspaces - """ - sys = _sys_mgr() - return sys.list_keyspaces() - - -def column_families(keyspace=None): - """ - Return existing column families for all keyspaces - or just the provided one. - - CLI Example: - - .. code-block:: bash - - salt '*' cassandra.column_families - salt '*' cassandra.column_families - """ - sys = _sys_mgr() - ksps = sys.list_keyspaces() - - if keyspace: - if keyspace in ksps: - return list(sys.get_keyspace_column_families(keyspace).keys()) - else: - return None - else: - ret = {} - for kspace in ksps: - ret[kspace] = list(sys.get_keyspace_column_families(kspace).keys()) - - return ret - - -def column_family_definition(keyspace, column_family): - """ - Return a dictionary of column family definitions for the given - keyspace/column_family - - CLI Example: - - .. code-block:: bash - - salt '*' cassandra.column_family_definition - - """ - sys = _sys_mgr() - - try: - return vars(sys.get_keyspace_column_families(keyspace)[column_family]) - except Exception: # pylint: disable=broad-except - log.debug("Invalid Keyspace/CF combination") - return None diff --git a/salt/returners/cassandra_return.py b/salt/returners/cassandra_return.py deleted file mode 100644 index ac01a4e46cb..00000000000 --- a/salt/returners/cassandra_return.py +++ /dev/null @@ -1,96 +0,0 @@ -""" -.. warning:: - - The `cassandra` returner is deprecated in favor of the `cassandra_cql` - returner. - -Return data to a Cassandra ColumnFamily - -Here's an example Keyspace / ColumnFamily setup that works with this -returner:: - - create keyspace salt; - use salt; - create column family returns - with key_validation_class='UTF8Type' - and comparator='UTF8Type' - and default_validation_class='UTF8Type'; - -Required python modules: pycassa - - To use the cassandra returner, append '--return cassandra' to the salt command. ex: - - salt '*' test.ping --return cassandra -""" - - -import logging - -import salt.utils.jid -from salt.utils.versions import warn_until_date - -try: - import pycassa # pylint: disable=import-error - - HAS_PYCASSA = True -except ImportError: - HAS_PYCASSA = False - -log = logging.getLogger(__name__) - -__opts__ = { - "cassandra.servers": ["localhost:9160"], - "cassandra.keyspace": "salt", - "cassandra.column_family": "returns", - "cassandra.consistency_level": "ONE", -} - -# Define the module's virtual name -__virtualname__ = "cassandra" - - -def __virtual__(): - if not HAS_PYCASSA: - return False, "Could not import cassandra returner; pycassa is not installed." - warn_until_date( - "20240101", - "The cassandra returner is broken and deprecated, and will be removed" - " after {date}. Use the cassandra_cql returner instead", - ) - return __virtualname__ - - -def returner(ret): - """ - Return data to a Cassandra ColumnFamily - """ - - consistency_level = getattr( - pycassa.ConsistencyLevel, __opts__["cassandra.consistency_level"] - ) - - pool = pycassa.ConnectionPool( - __opts__["cassandra.keyspace"], __opts__["cassandra.servers"] - ) - ccf = pycassa.ColumnFamily( - pool, - __opts__["cassandra.column_family"], - write_consistency_level=consistency_level, - ) - - columns = {"fun": ret["fun"], "id": ret["id"]} - if isinstance(ret["return"], dict): - for key, value in ret["return"].items(): - columns["return.{}".format(key)] = str(value) - else: - columns["return"] = str(ret["return"]) - - log.debug(columns) - ccf.insert(ret["jid"], columns) - - -def prep_jid(nocache=False, passed_jid=None): # pylint: disable=unused-argument - """ - Do any work necessary to prepare a JID, including sending a custom id - """ - return passed_jid if passed_jid is not None else salt.utils.jid.gen_jid(__opts__) diff --git a/salt/returners/django_return.py b/salt/returners/django_return.py deleted file mode 100644 index 36386875552..00000000000 --- a/salt/returners/django_return.py +++ /dev/null @@ -1,103 +0,0 @@ -""" -.. deprecated:: 3006.0 - -.. warning:: - - This module has been deprecated and will be removed after January 2024. - -A returner that will inform a Django system that -returns are available using Django's signal system. - -https://docs.djangoproject.com/en/dev/topics/signals/ - -It is up to the Django developer to register necessary -handlers with the signals provided by this returner -and process returns as necessary. - -The easiest way to use signals is to import them from -this returner directly and then use a decorator to register -them. - -An example Django module that registers a function called -'returner_callback' with this module's 'returner' function: - -.. code-block:: python - - import salt.returners.django_return - from django.dispatch import receiver - - @receiver(salt.returners.django_return, sender=returner) - def returner_callback(sender, ret): - print('I received {0} from {1}'.format(ret, sender)) - -""" -# Import Python libraries - -import logging - -# Import Salt libraries -import salt.returners -import salt.utils.jid -from salt.utils.versions import warn_until_date - -log = logging.getLogger(__name__) - -HAS_DJANGO = False - -try: - from django import dispatch # pylint: disable=E0611 - - HAS_DJANGO = True -except ImportError: - HAS_DJANGO = False - -# Define this module's virtual name -__virtualname__ = "django" - - -def __virtual__(): - warn_until_date( - "20240101", - "The django returner is broken and deprecated, and will be removed" - " after {date}.", - ) - if not HAS_DJANGO: - return False, "Could not import django returner; django is not installed." - return True - - -def returner(ret): - """ - Signal a Django server that a return is available - """ - signaled = dispatch.Signal(providing_args=["ret"]).send(sender="returner", ret=ret) - - for signal in signaled: - log.debug( - "Django returner function 'returner' signaled %s which responded with %s", - signal[0], - signal[1], - ) - - -def save_load(jid, load, minions=None): - """ - Save the load to the specified jid - """ - signaled = dispatch.Signal(providing_args=["jid", "load"]).send( - sender="save_load", jid=jid, load=load - ) - - for signal in signaled: - log.debug( - "Django returner function 'save_load' signaled %s which responded with %s", - signal[0], - signal[1], - ) - - -def prep_jid(nocache=False, passed_jid=None): - """ - Do any work necessary to prepare a JID, including sending a custom ID - """ - return passed_jid if passed_jid is not None else salt.utils.jid.gen_jid(__opts__) diff --git a/tests/pytests/unit/modules/test_cassandra_mod.py b/tests/pytests/unit/modules/test_cassandra_mod.py deleted file mode 100644 index a2c3f95d852..00000000000 --- a/tests/pytests/unit/modules/test_cassandra_mod.py +++ /dev/null @@ -1,129 +0,0 @@ -""" - :codeauthor: Rupesh Tare - - Test cases for salt.modules.cassandra_mod -""" - -import pytest - -import salt.modules.cassandra_mod as cassandra -from tests.support.mock import MagicMock, patch - - -@pytest.fixture -def configure_loader_modules(): - return {cassandra: {}} - - -def test_compactionstats(): - """ - Test for Return compactionstats info - """ - mock = MagicMock(return_value="A") - with patch.object(cassandra, "_nodetool", mock): - assert cassandra.compactionstats() == "A" - - -def test_version(): - """ - Test for Return the cassandra version - """ - mock = MagicMock(return_value="A") - with patch.object(cassandra, "_nodetool", mock): - assert cassandra.version() == "A" - - -def test_netstats(): - """ - Test for Return netstats info - """ - mock = MagicMock(return_value="A") - with patch.object(cassandra, "_nodetool", mock): - assert cassandra.netstats() == "A" - - -def test_tpstats(): - """ - Test for Return tpstats info - """ - mock = MagicMock(return_value="A") - with patch.object(cassandra, "_nodetool", mock): - assert cassandra.tpstats() == "A" - - -def test_info(): - """ - Test for Return cassandra node info - """ - mock = MagicMock(return_value="A") - with patch.object(cassandra, "_nodetool", mock): - assert cassandra.info() == "A" - - -def test_ring(): - """ - Test for Return ring info - """ - mock = MagicMock(return_value="A") - with patch.object(cassandra, "_nodetool", mock): - assert cassandra.ring() == "A" - - -def test_keyspaces(): - """ - Test for Return existing keyspaces - """ - mock_keyspaces = ["A", "B", "C", "D"] - - class MockSystemManager: - def list_keyspaces(self): - return mock_keyspaces - - mock_sys_mgr = MagicMock(return_value=MockSystemManager()) - - with patch.object(cassandra, "_sys_mgr", mock_sys_mgr): - assert cassandra.keyspaces() == mock_keyspaces - - -def test_column_families(): - """ - Test for Return existing column families for all keyspaces - """ - mock_keyspaces = ["A", "B"] - - class MockSystemManager: - def list_keyspaces(self): - return mock_keyspaces - - def get_keyspace_column_families(self, keyspace): - if keyspace == "A": - return {"a": "saltines", "b": "biscuits"} - if keyspace == "B": - return {"c": "cheese", "d": "crackers"} - - mock_sys_mgr = MagicMock(return_value=MockSystemManager()) - - with patch.object(cassandra, "_sys_mgr", mock_sys_mgr): - assert cassandra.column_families("Z") is None - assert cassandra.column_families("A") == ["a", "b"] - assert cassandra.column_families() == {"A": ["a", "b"], "B": ["c", "d"]} - - -def test_column_family_definition(): - """ - Test for Return a dictionary of column family definitions for the given - keyspace/column_family - """ - - class MockSystemManager: - def get_keyspace_column_families(self, keyspace): - if keyspace == "A": - return {"a": object, "b": object} - if keyspace == "B": - raise Exception - - mock_sys_mgr = MagicMock(return_value=MockSystemManager()) - - with patch.object(cassandra, "_sys_mgr", mock_sys_mgr): - assert cassandra.column_family_definition("A", "a") == vars(object) - assert cassandra.column_family_definition("B", "a") is None