Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/55848.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Guard boto3_elasticsearch loading properly
10 changes: 7 additions & 3 deletions salt/modules/boto3_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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(
Expand Down
23 changes: 15 additions & 8 deletions tests/unit/modules/test_boto3_elasticsearch.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down