summaryrefslogtreecommitdiff
path: root/test/units/modules
diff options
context:
space:
mode:
authorAnsible Core Team <info@ansible.com>2020-03-09 09:40:31 +0000
committerMatt Martz <matt@sivel.net>2020-03-23 11:14:21 -0500
commit6d910034a0a12f93b323e88b809c66afde6e713a (patch)
tree99aac704166cb859c6e366a9521b644fb5b6247c /test/units/modules
parent8f7e9f73ce69a413cd8d650b50635f55674492d1 (diff)
downloadansible-6d910034a0a12f93b323e88b809c66afde6e713a.tar.gz
Migrated to ansible.amazon
Diffstat (limited to 'test/units/modules')
-rw-r--r--test/units/modules/cloud/amazon/test_aws_s3.py38
-rw-r--r--test/units/modules/cloud/amazon/test_cloudformation.py205
-rw-r--r--test/units/modules/cloud/amazon/test_ec2_group.py83
3 files changed, 0 insertions, 326 deletions
diff --git a/test/units/modules/cloud/amazon/test_aws_s3.py b/test/units/modules/cloud/amazon/test_aws_s3.py
deleted file mode 100644
index a752c67fcb..0000000000
--- a/test/units/modules/cloud/amazon/test_aws_s3.py
+++ /dev/null
@@ -1,38 +0,0 @@
-# Make coding more python3-ish
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import pytest
-
-import unittest
-
-try:
- import ansible.modules.cloud.amazon.aws_s3 as s3
-except ImportError:
- pytestmark = pytest.mark.skip("This test requires the s3 Python libraries")
-
-from ansible.module_utils.six.moves.urllib.parse import urlparse
-
-boto3 = pytest.importorskip("boto3")
-
-
-class TestUrlparse(unittest.TestCase):
-
- def test_urlparse(self):
- actual = urlparse("http://test.com/here")
- self.assertEqual("http", actual.scheme)
- self.assertEqual("test.com", actual.netloc)
- self.assertEqual("/here", actual.path)
-
- def test_is_fakes3(self):
- actual = s3.is_fakes3("fakes3://bla.blubb")
- self.assertEqual(True, actual)
-
- def test_get_s3_connection(self):
- aws_connect_kwargs = dict(aws_access_key_id="access_key",
- aws_secret_access_key="secret_key")
- location = None
- rgw = True
- s3_url = "http://bla.blubb"
- actual = s3.get_s3_connection(None, aws_connect_kwargs, location, rgw, s3_url)
- self.assertEqual(bool("bla.blubb" in str(actual._endpoint)), True)
diff --git a/test/units/modules/cloud/amazon/test_cloudformation.py b/test/units/modules/cloud/amazon/test_cloudformation.py
deleted file mode 100644
index fe99a8510a..0000000000
--- a/test/units/modules/cloud/amazon/test_cloudformation.py
+++ /dev/null
@@ -1,205 +0,0 @@
-# (c) 2017 Red Hat Inc.
-#
-# This file is part of Ansible
-# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-
-# Make coding more python3-ish
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import pytest
-
-from units.utils.amazon_placebo_fixtures import placeboify, maybe_sleep
-from ansible.modules.cloud.amazon import cloudformation as cfn_module
-
-basic_yaml_tpl = """
----
-AWSTemplateFormatVersion: '2010-09-09'
-Description: 'Basic template that creates an S3 bucket'
-Resources:
- MyBucket:
- Type: "AWS::S3::Bucket"
-Outputs:
- TheName:
- Value:
- !Ref MyBucket
-"""
-
-bad_json_tpl = """{
- "AWSTemplateFormatVersion": "2010-09-09",
- "Description": "Broken template, no comma here ->"
- "Resources": {
- "MyBucket": {
- "Type": "AWS::S3::Bucket"
- }
- }
-}"""
-
-failing_yaml_tpl = """
----
-AWSTemplateFormatVersion: 2010-09-09
-Resources:
- ECRRepo:
- Type: AWS::ECR::Repository
- Properties:
- RepositoryPolicyText:
- Version: 3000-10-17 # <--- invalid version
- Statement:
- - Effect: Allow
- Action:
- - 'ecr:*'
- Principal:
- AWS: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:root
-"""
-
-default_events_limit = 10
-
-
-class FakeModule(object):
- def __init__(self, **kwargs):
- self.params = kwargs
-
- def fail_json(self, *args, **kwargs):
- self.exit_args = args
- self.exit_kwargs = kwargs
- raise Exception('FAIL')
-
- def exit_json(self, *args, **kwargs):
- self.exit_args = args
- self.exit_kwargs = kwargs
- raise Exception('EXIT')
-
-
-def test_invalid_template_json(placeboify):
- connection = placeboify.client('cloudformation')
- params = {
- 'StackName': 'ansible-test-wrong-json',
- 'TemplateBody': bad_json_tpl,
- }
- m = FakeModule(disable_rollback=False)
- with pytest.raises(Exception) as exc_info:
- cfn_module.create_stack(m, params, connection, default_events_limit)
- pytest.fail('Expected malformed JSON to have caused the call to fail')
-
- assert exc_info.match('FAIL')
- assert "ValidationError" in m.exit_kwargs['msg']
-
-
-def test_client_request_token_s3_stack(maybe_sleep, placeboify):
- connection = placeboify.client('cloudformation')
- params = {
- 'StackName': 'ansible-test-client-request-token-yaml',
- 'TemplateBody': basic_yaml_tpl,
- 'ClientRequestToken': '3faf3fb5-b289-41fc-b940-44151828f6cf',
- }
- m = FakeModule(disable_rollback=False)
- result = cfn_module.create_stack(m, params, connection, default_events_limit)
- assert result['changed']
- assert len(result['events']) > 1
- # require that the final recorded stack state was CREATE_COMPLETE
- # events are retrieved newest-first, so 0 is the latest
- assert 'CREATE_COMPLETE' in result['events'][0]
- connection.delete_stack(StackName='ansible-test-client-request-token-yaml')
-
-
-def test_basic_s3_stack(maybe_sleep, placeboify):
- connection = placeboify.client('cloudformation')
- params = {
- 'StackName': 'ansible-test-basic-yaml',
- 'TemplateBody': basic_yaml_tpl
- }
- m = FakeModule(disable_rollback=False)
- result = cfn_module.create_stack(m, params, connection, default_events_limit)
- assert result['changed']
- assert len(result['events']) > 1
- # require that the final recorded stack state was CREATE_COMPLETE
- # events are retrieved newest-first, so 0 is the latest
- assert 'CREATE_COMPLETE' in result['events'][0]
- connection.delete_stack(StackName='ansible-test-basic-yaml')
-
-
-def test_delete_nonexistent_stack(maybe_sleep, placeboify):
- connection = placeboify.client('cloudformation')
- result = cfn_module.stack_operation(connection, 'ansible-test-nonexist', 'DELETE', default_events_limit)
- assert result['changed']
- assert 'Stack does not exist.' in result['log']
-
-
-def test_get_nonexistent_stack(placeboify):
- connection = placeboify.client('cloudformation')
- assert cfn_module.get_stack_facts(connection, 'ansible-test-nonexist') is None
-
-
-def test_missing_template_body():
- m = FakeModule()
- with pytest.raises(Exception) as exc_info:
- cfn_module.create_stack(
- module=m,
- stack_params={},
- cfn=None,
- events_limit=default_events_limit
- )
- pytest.fail('Expected module to have failed with no template')
-
- assert exc_info.match('FAIL')
- assert not m.exit_args
- assert "Either 'template', 'template_body' or 'template_url' is required when the stack does not exist." == m.exit_kwargs['msg']
-
-
-def test_on_create_failure_delete(maybe_sleep, placeboify):
- m = FakeModule(
- on_create_failure='DELETE',
- disable_rollback=False,
- )
- connection = placeboify.client('cloudformation')
- params = {
- 'StackName': 'ansible-test-on-create-failure-delete',
- 'TemplateBody': failing_yaml_tpl
- }
- result = cfn_module.create_stack(m, params, connection, default_events_limit)
- assert result['changed']
- assert result['failed']
- assert len(result['events']) > 1
- # require that the final recorded stack state was DELETE_COMPLETE
- # events are retrieved newest-first, so 0 is the latest
- assert 'DELETE_COMPLETE' in result['events'][0]
-
-
-def test_on_create_failure_rollback(maybe_sleep, placeboify):
- m = FakeModule(
- on_create_failure='ROLLBACK',
- disable_rollback=False,
- )
- connection = placeboify.client('cloudformation')
- params = {
- 'StackName': 'ansible-test-on-create-failure-rollback',
- 'TemplateBody': failing_yaml_tpl
- }
- result = cfn_module.create_stack(m, params, connection, default_events_limit)
- assert result['changed']
- assert result['failed']
- assert len(result['events']) > 1
- # require that the final recorded stack state was ROLLBACK_COMPLETE
- # events are retrieved newest-first, so 0 is the latest
- assert 'ROLLBACK_COMPLETE' in result['events'][0]
- connection.delete_stack(StackName=params['StackName'])
-
-
-def test_on_create_failure_do_nothing(maybe_sleep, placeboify):
- m = FakeModule(
- on_create_failure='DO_NOTHING',
- disable_rollback=False,
- )
- connection = placeboify.client('cloudformation')
- params = {
- 'StackName': 'ansible-test-on-create-failure-do-nothing',
- 'TemplateBody': failing_yaml_tpl
- }
- result = cfn_module.create_stack(m, params, connection, default_events_limit)
- assert result['changed']
- assert result['failed']
- assert len(result['events']) > 1
- # require that the final recorded stack state was CREATE_FAILED
- # events are retrieved newest-first, so 0 is the latest
- assert 'CREATE_FAILED' in result['events'][0]
- connection.delete_stack(StackName=params['StackName'])
diff --git a/test/units/modules/cloud/amazon/test_ec2_group.py b/test/units/modules/cloud/amazon/test_ec2_group.py
deleted file mode 100644
index 14f597f69d..0000000000
--- a/test/units/modules/cloud/amazon/test_ec2_group.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# Make coding more python3-ish
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-from ansible.modules.cloud.amazon import ec2_group as group_module
-
-
-def test_from_permission():
- internal_http = {
- u'FromPort': 80,
- u'IpProtocol': 'tcp',
- u'IpRanges': [
- {
- u'CidrIp': '10.0.0.0/8',
- u'Description': 'Foo Bar Baz'
- },
- ],
- u'Ipv6Ranges': [
- {u'CidrIpv6': 'fe80::94cc:8aff:fef6:9cc/64'},
- ],
- u'PrefixListIds': [],
- u'ToPort': 80,
- u'UserIdGroupPairs': [],
- }
- perms = list(group_module.rule_from_group_permission(internal_http))
- assert len(perms) == 2
- assert perms[0].target == '10.0.0.0/8'
- assert perms[0].target_type == 'ipv4'
- assert perms[0].description == 'Foo Bar Baz'
- assert perms[1].target == 'fe80::94cc:8aff:fef6:9cc/64'
-
- global_egress = {
- 'IpProtocol': '-1',
- 'IpRanges': [{'CidrIp': '0.0.0.0/0'}],
- 'Ipv6Ranges': [],
- 'PrefixListIds': [],
- 'UserIdGroupPairs': []
- }
- perms = list(group_module.rule_from_group_permission(global_egress))
- assert len(perms) == 1
- assert perms[0].target == '0.0.0.0/0'
- assert perms[0].port_range == (None, None)
-
- internal_prefix_http = {
- u'FromPort': 80,
- u'IpProtocol': 'tcp',
- u'PrefixListIds': [
- {'PrefixListId': 'p-1234'}
- ],
- u'ToPort': 80,
- u'UserIdGroupPairs': [],
- }
- perms = list(group_module.rule_from_group_permission(internal_prefix_http))
- assert len(perms) == 1
- assert perms[0].target == 'p-1234'
-
-
-def test_rule_to_permission():
- tests = [
- group_module.Rule((22, 22), 'udp', 'sg-1234567890', 'group', None),
- group_module.Rule((1, 65535), 'tcp', '0.0.0.0/0', 'ipv4', "All TCP from everywhere"),
- group_module.Rule((443, 443), 'tcp', 'ip-123456', 'ip_prefix', "Traffic to privatelink IPs"),
- group_module.Rule((443, 443), 'tcp', 'feed:dead:::beef/64', 'ipv6', None),
- ]
- for test in tests:
- perm = group_module.to_permission(test)
- assert perm['FromPort'], perm['ToPort'] == test.port_range
- assert perm['IpProtocol'] == test.protocol
-
-
-def test_validate_ip():
- class Warner(object):
- def warn(self, msg):
- return
- ips = [
- ('1.1.1.1/24', '1.1.1.0/24'),
- ('192.168.56.101/16', '192.168.0.0/16'),
- # Don't modify IPv6 CIDRs, AWS supports /128 and device ranges
- ('1203:8fe0:fe80:b897:8990:8a7c:99bf:323d/128', '1203:8fe0:fe80:b897:8990:8a7c:99bf:323d/128'),
- ]
-
- for ip, net in ips:
- assert group_module.validate_ip(Warner(), ip) == net