Debian Codegraph @

ansible_collections/community/aws/tests/unit/plugins/modules/test_directconnect_connection.py

raw
1 # (c) 2017 Red Hat Inc.
2 #
3 # This file is part of Ansible
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 # Make coding more python3-ish
7 from __future__ import absolute_import
8 from __future__ import division
9 from __future__ import print_function
10
11 __metaclass__ = type
12
13 import pytest
14
15 from ansible_collections.amazon.aws.plugins.module_utils.botocore import HAS_BOTO3
16
17 from ansible_collections.community.aws.plugins.modules import directconnect_connection
18
19 if not HAS_BOTO3:
20 pytestmark = pytest.mark.skip(
21 "test_directconnect_confirm_connection.py requires the `boto3` and `botocore` modules"
22 )
23
24
25 # When rerecording these tests, create a stand alone connection with default values in us-west-2
26 # with the name ansible-test-connection and set connection_id to the appropriate value
27 connection_id = "dxcon-fgq9rgot"
28 connection_name = "ansible-test-connection"
29
30
31 def test_connection_status(placeboify, maybe_sleep):
32 client = placeboify.client("directconnect")
33 status = directconnect_connection.connection_status(client, connection_id)["connection"]
34 assert status["connectionName"] == connection_name
35 assert status["connectionId"] == connection_id
36
37
38 def test_connection_exists_by_id(placeboify, maybe_sleep):
39 client = placeboify.client("directconnect")
40 exists = directconnect_connection.connection_exists(client, connection_id)
41 assert exists == connection_id
42
43
44 def test_connection_exists_by_name(placeboify, maybe_sleep):
45 client = placeboify.client("directconnect")
46 exists = directconnect_connection.connection_exists(client, None, connection_name)
47 assert exists == connection_id
48
49
50 def test_connection_does_not_exist(placeboify, maybe_sleep):
51 client = placeboify.client("directconnect")
52 exists = directconnect_connection.connection_exists(client, "dxcon-notthere")
53 assert exists is False
54
55
56 def test_changed_properties(placeboify, maybe_sleep):
57 client = placeboify.client("directconnect")
58 status = directconnect_connection.connection_status(client, connection_id)["connection"]
59 location = "differentlocation"
60 bandwidth = status["bandwidth"]
61 assert directconnect_connection.changed_properties(status, location, bandwidth) is True
62
63
64 def test_associations_are_not_updated(placeboify, maybe_sleep):
65 client = placeboify.client("directconnect")
66 status = directconnect_connection.connection_status(client, connection_id)["connection"]
67 lag_id = status.get("lagId")
68 assert directconnect_connection.update_associations(client, status, connection_id, lag_id) is False
69
70
71 def test_create_and_delete(placeboify, maybe_sleep):
72 client = placeboify.client("directconnect")
73 created_conn = verify_create_works(placeboify, maybe_sleep, client)
74 verify_delete_works(placeboify, maybe_sleep, client, created_conn)
75
76
77 def verify_create_works(placeboify, maybe_sleep, client):
78 created = directconnect_connection.create_connection(
79 client=client, location="EqSE2", bandwidth="1Gbps", name="ansible-test-2", lag_id=None
80 )
81 assert created.startswith("dxcon")
82 return created
83
84
85 def verify_delete_works(placeboify, maybe_sleep, client, conn_id):
86 changed = directconnect_connection.ensure_absent(client, conn_id)
87 assert changed is True