Beispiel #1
0
    def test_update_vpc_private_zone(self, find_zones_mock, time_mock,
                                     client_mock, check_mode, response):
        client_mock.return_value.get_hosted_zone.return_value = {
            'HostedZone': {
                'Id': '/hostedzone/ZONE_ID',
                'Name': 'example.com.',
                'Config': {
                    'Comment': 'foobar',
                    'PrivateZone': True
                },
            },
            'VPCs': [{
                'VPCRegion': 'eu-central-1',
                'VPCId': 'vpc-1'
            }],
        }
        client_mock.return_value.create_hosted_zone.return_value = {
            'HostedZone': {
                'Id': '/hostedzone/ZONE_ID_2',
                'Name': 'example.com.',
                'Config': {
                    'Comment': 'foobar',
                    'PrivateZone': True
                },
            },
        }

        with self.assertRaises(AnsibleExitJson) as exec_info:
            set_module_args({
                'secret_key': 'SECRET_KEY',
                'access_key': 'ACCESS_KEY',
                'region': 'us-east-2',
                'zone': 'example.com',
                'comment': 'foobar',
                'vpc_id': 'vpc-2',
                'vpc_region': 'us-east-2',
                'state': 'present',
                '_ansible_check_mode': check_mode,
            })
            route53_zone.main()

        if check_mode:
            client_mock.return_value.create_hosted_zone.assert_not_called()
        else:
            client_mock.return_value.create_hosted_zone.assert_called_once_with(
                **{
                    'HostedZoneConfig': {
                        'Comment': 'foobar',
                        'PrivateZone': True,
                    },
                    'Name': 'example.com.',
                    'CallerReference': 'example.com.-1',
                    'VPC': {
                        'VPCRegion': 'us-east-2',
                        'VPCId': 'vpc-2',
                    },
                })

        self.assertEqual(exec_info.exception.args[0]['changed'], True)
        self.assertTrue(is_subdict(response, exec_info.exception.args[0]))
Beispiel #2
0
    def test_update_public_zone_no_changes(self, find_zones_mock, time_mock,
                                           client_mock):
        client_mock.return_value.get_hosted_zone.return_value = {
            'HostedZone': {
                'Id': '/hostedzone/ZONE_ID',
                'Name': 'example.com.',
                'Config': {
                    'Comment': '',
                    'PrivateZone': False
                },
            },
        }

        with self.assertRaises(AnsibleExitJson) as exec_info:
            set_module_args({
                'secret_key': 'SECRET_KEY',
                'access_key': 'ACCESS_KEY',
                'region': 'eu-central-1',
                'zone': 'example.com',
                'comment': '',
                'state': 'present',
            })
            route53_zone.main()

        client_mock.return_value.update_hosted_zone_comment.assert_not_called()
        self.assertEqual(exec_info.exception.args[0]['changed'], False)
Beispiel #3
0
    def test_delete_absent_zone(self, find_zones_mock, time_mock, client_mock):
        with self.assertRaises(AnsibleExitJson) as exec_info:
            set_module_args({
                'secret_key': 'SECRET_KEY',
                'access_key': 'ACCESS_KEY',
                'region': 'eu-central-1',
                'zone': 'example.com',
                'state': 'absent',
            })
            route53_zone.main()

        client_mock.return_value.delete_hosted_zone.assert_not_called()
        self.assertEqual(exec_info.exception.args[0]['changed'], False)
Beispiel #4
0
    def test_update_private_zone_no_changes(self, find_zones_mock, time_mock,
                                            client_mock):
        client_mock.return_value.get_hosted_zone.return_value = {
            'HostedZone': {
                'Id': '/hostedzone/ZONE_ID',
                'Name': 'example.com.',
                'Config': {
                    'Comment': 'foobar',
                    'PrivateZone': True
                },
            },
            'VPCs': [{
                'VPCRegion': 'eu-central-1',
                'VPCId': 'vpc-1'
            }],
        }

        with self.assertRaises(AnsibleExitJson) as exec_info:
            set_module_args({
                'secret_key': 'SECRET_KEY',
                'access_key': 'ACCESS_KEY',
                'region': 'eu-central-1',
                'zone': 'example.com',
                'comment': 'foobar',
                'vpc_id': 'vpc-1',
                'vpc_region': 'eu-central-1',
                'state': 'present',
            })
            route53_zone.main()

        client_mock.return_value.update_hosted_zone_comment.assert_not_called()
        self.assertEqual(exec_info.exception.args[0]['changed'], False)

        response = {
            'private_zone': True,
            'vpc_id': 'vpc-1',
            'vpc_region': 'eu-central-1',
            'comment': 'foobar',
            'name': 'example.com.',
            'delegation_set_id': None,
            'zone_id': 'ZONE_ID',
        }
        self.assertTrue(is_subdict(response, exec_info.exception.args[0]))
Beispiel #5
0
    def test_mutually_exclusive(self, *args):
        with self.assertRaises(AnsibleFailJson) as exec_info:
            set_module_args({
                'secret_key': 'SECRET_KEY',
                'access_key': 'ACCESS_KEY',
                'region': 'eu-central-1',
                'zone': 'example.com',
                'vpc_id': 'vpc-94ccc2ff',
                'vpc_region': 'eu-central-1',
                'comment': 'foobar',
                'delegation_set_id': 'A1BCDEF2GHIJKL',
                'state': 'present',
            })
            route53_zone.main()

        self.assertEqual(
            exec_info.exception.args[0]['msg'],
            'parameters are mutually exclusive: delegation_set_id|vpc_id, delegation_set_id|vpc_region',
        )
Beispiel #6
0
    def test_delete_by_zone_id(self, find_zones_mock, time_mock, client_mock,
                               hosted_zone_id, call_params, check_mode):
        with self.assertRaises(AnsibleExitJson) as exec_info:
            set_module_args({
                'secret_key': 'SECRET_KEY',
                'access_key': 'ACCESS_KEY',
                'region': 'eu-central-1',
                'zone': 'example.com',
                'hosted_zone_id': hosted_zone_id,
                'state': 'absent',
                '_ansible_check_mode': check_mode,
            })
            route53_zone.main()

        if check_mode:
            client_mock.return_value.delete_hosted_zone.assert_not_called()
        else:
            client_mock.return_value.delete_hosted_zone.assert_has_calls(
                call_params)

        self.assertEqual(exec_info.exception.args[0]['changed'], True)