mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07:00
[cloud] New module: AWS Direct Connect connection (#26152)
* New module for AWS Direct Connect connections Unittests for new module Added utils that will be used by other Direct Connect modules * pep8 fixes * Correct aws_direct_connect_connection EXAMPLES to be valid yaml * Make requested changes * remove use of the variable changed get rid of unnecessary parentheses * Fix unit test * Rename variable. * Fix metadata version
This commit is contained in:
parent
1d4ca0fd51
commit
24b49c2539
10 changed files with 621 additions and 0 deletions
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"ResponseMetadata": {
|
||||
"RetryAttempts": 0,
|
||||
"HTTPHeaders": {
|
||||
"x-amzn-requestid": "df6f9966-5b55-11e7-a69f-95e467ba41d7",
|
||||
"content-type": "application/x-amz-json-1.1",
|
||||
"date": "Tue, 27 Jun 2017 16:30:03 GMT",
|
||||
"content-length": "214"
|
||||
},
|
||||
"RequestId": "df6f9966-5b55-11e7-a69f-95e467ba41d7",
|
||||
"HTTPStatusCode": 200
|
||||
},
|
||||
"connections": [
|
||||
{
|
||||
"connectionState": "requested",
|
||||
"connectionId": "dxcon-fgq9rgot",
|
||||
"location": "EqSe2",
|
||||
"connectionName": "ansible-test-connection",
|
||||
"bandwidth": "1Gbps",
|
||||
"ownerAccount": "448830907657",
|
||||
"region": "us-west-2"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"ResponseMetadata": {
|
||||
"RetryAttempts": 1,
|
||||
"HTTPHeaders": {
|
||||
"x-amzn-requestid": "ded68d99-5b55-11e7-8bdd-db27cb754a2c",
|
||||
"content-type": "application/x-amz-json-1.1",
|
||||
"date": "Tue, 27 Jun 2017 16:30:02 GMT",
|
||||
"content-length": "214"
|
||||
},
|
||||
"RequestId": "ded68d99-5b55-11e7-8bdd-db27cb754a2c",
|
||||
"HTTPStatusCode": 200
|
||||
},
|
||||
"connections": [
|
||||
{
|
||||
"connectionState": "requested",
|
||||
"connectionId": "dxcon-fgq9rgot",
|
||||
"location": "EqSe2",
|
||||
"connectionName": "ansible-test-connection",
|
||||
"bandwidth": "1Gbps",
|
||||
"ownerAccount": "448830907657",
|
||||
"region": "us-west-2"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"ResponseMetadata": {
|
||||
"RetryAttempts": 0,
|
||||
"HTTPHeaders": {
|
||||
"x-amzn-requestid": "b9e352dd-5b55-11e7-9750-d97c605bdcae",
|
||||
"content-type": "application/x-amz-json-1.1",
|
||||
"date": "Tue, 27 Jun 2017 16:29:00 GMT",
|
||||
"content-length": "18"
|
||||
},
|
||||
"RequestId": "b9e352dd-5b55-11e7-9750-d97c605bdcae",
|
||||
"HTTPStatusCode": 200
|
||||
},
|
||||
"connections": []
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"ResponseMetadata": {
|
||||
"RetryAttempts": 0,
|
||||
"HTTPHeaders": {
|
||||
"x-amzn-requestid": "b8f5493c-5b55-11e7-a718-2b51b84a4672",
|
||||
"content-type": "application/x-amz-json-1.1",
|
||||
"date": "Tue, 27 Jun 2017 16:28:58 GMT",
|
||||
"content-length": "214"
|
||||
},
|
||||
"RequestId": "b8f5493c-5b55-11e7-a718-2b51b84a4672",
|
||||
"HTTPStatusCode": 200
|
||||
},
|
||||
"connections": [
|
||||
{
|
||||
"connectionState": "requested",
|
||||
"connectionId": "dxcon-fgq9rgot",
|
||||
"location": "EqSe2",
|
||||
"connectionName": "ansible-test-connection",
|
||||
"bandwidth": "1Gbps",
|
||||
"ownerAccount": "448830907657",
|
||||
"region": "us-west-2"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"ResponseMetadata": {
|
||||
"RetryAttempts": 0,
|
||||
"HTTPHeaders": {
|
||||
"x-amzn-requestid": "b9a0566c-5b55-11e7-9750-d97c605bdcae",
|
||||
"content-type": "application/x-amz-json-1.1",
|
||||
"date": "Tue, 27 Jun 2017 16:29:00 GMT",
|
||||
"content-length": "586"
|
||||
},
|
||||
"RequestId": "b9a0566c-5b55-11e7-9750-d97c605bdcae",
|
||||
"HTTPStatusCode": 200
|
||||
},
|
||||
"connections": [
|
||||
{
|
||||
"connectionState": "requested",
|
||||
"connectionId": "dxcon-fgq9rgot",
|
||||
"location": "EqSe2",
|
||||
"connectionName": "ansible-test-connection",
|
||||
"bandwidth": "1Gbps",
|
||||
"ownerAccount": "448830907657",
|
||||
"region": "us-west-2"
|
||||
},
|
||||
{
|
||||
"connectionState": "requested",
|
||||
"connectionId": "dxcon-fh69i7ez",
|
||||
"location": "PEH51",
|
||||
"connectionName": "test2shertel",
|
||||
"bandwidth": "1Gbps",
|
||||
"ownerAccount": "448830907657",
|
||||
"region": "us-west-2"
|
||||
},
|
||||
{
|
||||
"connectionState": "deleted",
|
||||
"connectionId": "dxcon-fgcw1bgr",
|
||||
"location": "EqSe2",
|
||||
"connectionName": "ansible-test-2",
|
||||
"bandwidth": "1Gbps",
|
||||
"ownerAccount": "448830907657",
|
||||
"region": "us-west-2"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"ResponseMetadata": {
|
||||
"RetryAttempts": 0,
|
||||
"HTTPHeaders": {
|
||||
"x-amzn-requestid": "b85f71db-5b55-11e7-a718-2b51b84a4672",
|
||||
"content-type": "application/x-amz-json-1.1",
|
||||
"date": "Tue, 27 Jun 2017 16:28:58 GMT",
|
||||
"content-length": "214"
|
||||
},
|
||||
"RequestId": "b85f71db-5b55-11e7-a718-2b51b84a4672",
|
||||
"HTTPStatusCode": 200
|
||||
},
|
||||
"connections": [
|
||||
{
|
||||
"connectionState": "requested",
|
||||
"connectionId": "dxcon-fgq9rgot",
|
||||
"location": "EqSe2",
|
||||
"connectionName": "ansible-test-connection",
|
||||
"bandwidth": "1Gbps",
|
||||
"ownerAccount": "448830907657",
|
||||
"region": "us-west-2"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"connectionState": "requested",
|
||||
"connectionId": "dxcon-fgbw50lg",
|
||||
"location": "EqSe2",
|
||||
"ResponseMetadata": {
|
||||
"RetryAttempts": 0,
|
||||
"HTTPHeaders": {
|
||||
"x-amzn-requestid": "dfb3ce3c-5b55-11e7-8bdd-db27cb754a2c",
|
||||
"content-type": "application/x-amz-json-1.1",
|
||||
"date": "Tue, 27 Jun 2017 16:30:03 GMT",
|
||||
"content-length": "187"
|
||||
},
|
||||
"RequestId": "dfb3ce3c-5b55-11e7-8bdd-db27cb754a2c",
|
||||
"HTTPStatusCode": 200
|
||||
},
|
||||
"connectionName": "ansible-test-2",
|
||||
"bandwidth": "1Gbps",
|
||||
"ownerAccount": "448830907657",
|
||||
"region": "us-west-2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"status_code": 200,
|
||||
"data": {
|
||||
"connectionState": "deleted",
|
||||
"connectionId": "dxcon-fgbw50lg",
|
||||
"location": "EqSe2",
|
||||
"ResponseMetadata": {
|
||||
"RetryAttempts": 0,
|
||||
"HTTPHeaders": {
|
||||
"x-amzn-requestid": "dfccd47d-5b55-11e7-8bdd-db27cb754a2c",
|
||||
"content-type": "application/x-amz-json-1.1",
|
||||
"date": "Tue, 27 Jun 2017 16:30:03 GMT",
|
||||
"content-length": "185"
|
||||
},
|
||||
"RequestId": "dfccd47d-5b55-11e7-8bdd-db27cb754a2c",
|
||||
"HTTPStatusCode": 200
|
||||
},
|
||||
"connectionName": "ansible-test-2",
|
||||
"bandwidth": "1Gbps",
|
||||
"ownerAccount": "448830907657",
|
||||
"region": "us-west-2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
# (c) 2017 Red Hat Inc.
|
||||
#
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from . placebo_fixtures import placeboify, maybe_sleep
|
||||
from ansible.modules.cloud.amazon import aws_direct_connect_connection
|
||||
from ansible.module_utils.ec2 import get_aws_connection_info, boto3_conn
|
||||
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue