Module: check_mk
Branch: master
Commit: b80de985feb15a3399a9a511f2d75a88f53234f4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b80de985feb15a…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Apr 26 13:58:06 2019 +0200
Started AWS/ELBv2 tests
Change-Id: I1033e3886547e47e3a8abc84e9eba6f8857f80ca
---
cmk/special_agents/agent_aws.py | 2 +-
.../agent_aws/test_agent_aws_elbv2.py | 108 +++++++++++++++++++++
2 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/cmk/special_agents/agent_aws.py b/cmk/special_agents/agent_aws.py
index 15d63df..63a050a 100644
--- a/cmk/special_agents/agent_aws.py
+++ b/cmk/special_agents/agent_aws.py
@@ -2149,7 +2149,7 @@ class ELBv2Limits(AWSSectionLimits):
rules = []
for listener in listeners:
response =
self._client.describe_rules(ListenerArn=listener['ListenerArn'])
- rules.append(self._get_response_content(response, 'Rules'))
+ rules.extend(self._get_response_content(response, 'Rules'))
# Limit 100 holds for rules which are not default, see AWS docs:
#
https://docs.aws.amazon.com/de_de/general/latest/gr/aws_service_limits.html
diff --git a/tests/unit/cmk/special_agents/agent_aws/test_agent_aws_elbv2.py
b/tests/unit/cmk/special_agents/agent_aws/test_agent_aws_elbv2.py
new file mode 100644
index 0000000..334cbfa
--- /dev/null
+++ b/tests/unit/cmk/special_agents/agent_aws/test_agent_aws_elbv2.py
@@ -0,0 +1,108 @@
+# pylint: disable=redefined-outer-name
+
+import pytest
+from agent_aws_fake_clients import (
+ ELBv2DescribeLoadBalancersIB,
+ ELBv2DescribeTargetGroupsIB,
+ ELBv2DescribeListenersIB,
+ ELBv2DescribeRulesIB,
+ ELBv2DescribeAccountLimitsIB,
+ ELBv2DescribeTargetHealthIB,
+)
+
+from cmk.special_agents.agent_aws import (
+ AWSConfig,
+ ResultDistributor,
+ ELBv2Limits,
+ ELBSummaryGeneric,
+ ELBv2TargetGroups,
+)
+
+
+class FakeELBv2Client(object):
+ def describe_load_balancers(self):
+ return {
+ 'LoadBalancers':
ELBv2DescribeLoadBalancersIB.create_instances(amount=1),
+ 'NextMarker': 'string',
+ }
+
+ def describe_target_groups(self, LoadBalancerArn=None):
+ return {
+ 'TargetGroups':
ELBv2DescribeTargetGroupsIB.create_instances(amount=1),
+ 'NextMarker': 'string',
+ }
+
+ def describe_listeners(self, LoadBalancerArn=None):
+ return {
+ 'Listeners': ELBv2DescribeListenersIB.create_instances(amount=1),
+ 'NextMarker': 'string',
+ }
+
+ def describe_rules(self, ListenerArn=None):
+ return {
+ 'Rules': ELBv2DescribeRulesIB.create_instances(amount=1),
+ 'NextMarker': 'string',
+ }
+
+ def describe_account_limits(self):
+ return {
+ 'Limits':
ELBv2DescribeAccountLimitsIB.create_instances(amount=1)[0]['Limits'],
+ 'NextMarker': 'string',
+ }
+
+ def describe_target_health(self, TargetGroupArn=None):
+ return {
+ 'TargetHealthDescriptions':
ELBv2DescribeTargetHealthIB.create_instances(amount=1),
+ }
+
+
+(a)pytest.fixture()
+def get_elbv2_sections():
+ def _create_elbv2_sections(names, tags):
+ region = 'region'
+ config = AWSConfig('hostname', (None, None))
+ config.add_single_service_config('elbv2_names', names)
+ config.add_service_tags('elbv2_tags', tags)
+
+ fake_elbv2_client = FakeELBv2Client()
+
+ elbv2_limits_distributor = ResultDistributor()
+ elbv2_summary_distributor = ResultDistributor()
+
+ elbv2_limits = ELBv2Limits(fake_elbv2_client, region, config,
elbv2_limits_distributor)
+ elbv2_summary = ELBSummaryGeneric(
+ fake_elbv2_client, region, config, elbv2_summary_distributor,
resource='elbv2')
+ elbv2_target_groups = ELBv2TargetGroups(fake_elbv2_client, region, config)
+
+ elbv2_limits_distributor.add(elbv2_summary)
+ elbv2_summary_distributor.add(elbv2_target_groups)
+ return elbv2_limits, elbv2_summary, elbv2_target_groups
+
+ return _create_elbv2_sections
+
+
+def test_agent_aws_elbv2_limits(get_elbv2_sections):
+ elbv2_limits, _elbv2_summary, _elbv2_target_groups = get_elbv2_sections(None, (None,
None))
+ _elbv2_limits_results = elbv2_limits.run().results
+
+ assert elbv2_limits.interval == 300
+ assert elbv2_limits.name == "elbv2_limits"
+
+
+def test_agent_aws_elbv2_summary(get_elbv2_sections):
+ elbv2_limits, elbv2_summary, _elbv2_target_groups = get_elbv2_sections(None, (None,
None))
+ _elbv2_limits_results = elbv2_limits.run().results
+ _elbv2_summary_results = elbv2_summary.run().results
+
+ assert elbv2_summary.interval == 300
+ assert elbv2_summary.name == "elbv2_summary"
+
+
+def test_agent_aws_elbv2_target_groups(get_elbv2_sections):
+ elbv2_limits, elbv2_summary, elbv2_target_groups = get_elbv2_sections(None, (None,
None))
+ _elbv2_limits_results = elbv2_limits.run().results
+ _elbv2_summary_results = elbv2_summary.run().results
+ _elbv2_target_groups_results = elbv2_target_groups.run().results
+
+ assert elbv2_target_groups.interval == 300
+ assert elbv2_target_groups.name == "elbv2_target_groups"