1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# (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
from units.utils.amazon_placebo_fixtures import placeboify, maybe_sleep
from ansible.modules.cloud.amazon import aws_direct_connect_connection
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
# When rerecording these tests, create a stand alone connection with default values in us-west-2
# with the name ansible-test-connection and set connection_id to the appropriate value
connection_id = "dxcon-fgq9rgot"
connection_name = 'ansible-test-connection'
def test_connection_status(placeboify, maybe_sleep):
client = placeboify.client('directconnect')
status = aws_direct_connect_connection.connection_status(client, connection_id)['connection']
assert status['connectionName'] == connection_name
assert status['connectionId'] == connection_id
def test_connection_exists_by_id(placeboify, maybe_sleep):
client = placeboify.client('directconnect')
exists = aws_direct_connect_connection.connection_exists(client, connection_id)
assert exists == connection_id
def test_connection_exists_by_name(placeboify, maybe_sleep):
client = placeboify.client('directconnect')
exists = aws_direct_connect_connection.connection_exists(client, None, connection_name)
assert exists == connection_id
def test_connection_does_not_exist(placeboify, maybe_sleep):
client = placeboify.client('directconnect')
exists = aws_direct_connect_connection.connection_exists(client, 'dxcon-notthere')
assert exists is False
def test_changed_properties(placeboify, maybe_sleep):
client = placeboify.client('directconnect')
status = aws_direct_connect_connection.connection_status(client, connection_id)['connection']
location = "differentlocation"
bandwidth = status['bandwidth']
assert aws_direct_connect_connection.changed_properties(status, location, bandwidth) is True
def test_associations_are_not_updated(placeboify, maybe_sleep):
client = placeboify.client('directconnect')
status = aws_direct_connect_connection.connection_status(client, connection_id)['connection']
lag_id = status.get('lagId')
assert aws_direct_connect_connection.update_associations(client, status, connection_id, lag_id) is False
def test_create_and_delete(placeboify, maybe_sleep):
client = placeboify.client('directconnect')
created_conn = verify_create_works(placeboify, maybe_sleep, client)
deleted_conn = verify_delete_works(placeboify, maybe_sleep, client, created_conn)
def verify_create_works(placeboify, maybe_sleep, client):
created = aws_direct_connect_connection.create_connection(client=client,
location="EqSE2",
bandwidth="1Gbps",
name="ansible-test-2",
lag_id=None)
assert created.startswith('dxcon')
return created
def verify_delete_works(placeboify, maybe_sleep, client, conn_id):
changed = aws_direct_connect_connection.ensure_absent(client, conn_id)
assert changed is True
|