diff --git a/changelog/55848.fixed b/changelog/55848.fixed new file mode 100644 index 000000000000..695830489268 --- /dev/null +++ b/changelog/55848.fixed @@ -0,0 +1 @@ +Guard boto3_elasticsearch loading properly diff --git a/salt/modules/boto3_elasticsearch.py b/salt/modules/boto3_elasticsearch.py index dfbb41738059..bb46bb44009c 100644 --- a/salt/modules/boto3_elasticsearch.py +++ b/salt/modules/boto3_elasticsearch.py @@ -68,8 +68,9 @@ from botocore.exceptions import ClientError, ParamValidationError, WaiterError logging.getLogger("boto3").setLevel(logging.INFO) + HAS_BOTO = True except ImportError: - pass + HAS_BOTO = False log = logging.getLogger(__name__) @@ -79,12 +80,15 @@ def __virtual__(): Only load if boto libraries exist and if boto libraries are greater than a given version. """ - return salt.utils.versions.check_boto_reqs(boto3_ver="1.2.7") + return HAS_BOTO and salt.utils.versions.check_boto_reqs( + boto3_ver="1.2.7", check_boto=False + ) def __init__(opts): _ = opts - __utils__["boto3.assign_funcs"](__name__, "es") + if HAS_BOTO: + __utils__["boto3.assign_funcs"](__name__, "es") def add_tags( diff --git a/tests/unit/modules/test_boto3_elasticsearch.py b/tests/unit/modules/test_boto3_elasticsearch.py index 0252d5737120..346ea4f8934e 100644 --- a/tests/unit/modules/test_boto3_elasticsearch.py +++ b/tests/unit/modules/test_boto3_elasticsearch.py @@ -1,28 +1,21 @@ -# -*- coding: utf-8 -*- """ Tests for salt.modules.boto3_elasticsearch """ -# Import Python libs -from __future__ import absolute_import, print_function, unicode_literals import datetime import random import string import textwrap -# Import Salt libs import salt.loader import salt.modules.boto3_elasticsearch as boto3_elasticsearch from salt.ext.six.moves import range from salt.utils.versions import LooseVersion - -# Import Salt Testing libs from tests.support.mixins import LoaderModuleMockMixin from tests.support.mock import MagicMock, patch from tests.support.unit import TestCase, skipIf -# Import 3rd-party libs try: import boto3 from botocore.exceptions import ClientError @@ -150,7 +143,7 @@ def setup_loader_modules(self): return {boto3_elasticsearch: {"__utils__": utils}} def setUp(self): - super(Boto3ElasticsearchTestCase, self).setUp() + super().setUp() boto3_elasticsearch.__init__(self.opts) del self.opts @@ -383,6 +376,20 @@ def test_add_tags_positive(self): {"result": True}, ) + def test_add_tags_default(self): + """ + Test that when tags are not provided, no error is raised. + """ + with patch.object( + self.conn, + "describe_elasticsearch_domain", + return_value={"DomainStatus": DOMAIN_RET}, + ): + self.assertEqual( + boto3_elasticsearch.add_tags("testdomain", **CONN_PARAMETERS), + {"result": True}, + ) + def test_add_tags_error(self): """ Test that when adding tags fails, and boto3 returns an error,