|
| 1 | +# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). |
| 4 | +# You may not use this file except in compliance with the License. |
| 5 | +# A copy of the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "LICENSE.txt" file accompanying this file. |
| 10 | +# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. |
| 11 | +# See the License for the specific language governing permissions and limitations under the License. |
| 12 | +import pytest |
| 13 | +from assertpy import assert_that |
| 14 | +from common.ec2_utils import get_private_ip_address_and_dns_name |
| 15 | + |
| 16 | + |
| 17 | +@pytest.mark.parametrize( |
| 18 | + "instance_info, expected_private_ip, expected_private_dns_name", |
| 19 | + [ |
| 20 | + ( |
| 21 | + { |
| 22 | + "InstanceId": "i-12345", |
| 23 | + "InstanceType": "c5.xlarge", |
| 24 | + "PrivateIpAddress": "ip.1.0.0.1", |
| 25 | + "PrivateDnsName": "ip-1-0-0-1", |
| 26 | + "NetworkInterfaces": [ |
| 27 | + { |
| 28 | + "Attachment": { |
| 29 | + "DeviceIndex": 0, |
| 30 | + "NetworkCardIndex": 0, |
| 31 | + }, |
| 32 | + "PrivateIpAddress": "ip.1.0.0.1", |
| 33 | + "PrivateDnsName": "ip-1-0-0-1", |
| 34 | + }, |
| 35 | + ], |
| 36 | + }, |
| 37 | + "ip.1.0.0.1", |
| 38 | + "ip-1-0-0-1", |
| 39 | + ), |
| 40 | + ( |
| 41 | + { |
| 42 | + "InstanceId": "i-12345", |
| 43 | + "InstanceType": "c5.xlarge", |
| 44 | + "PrivateIpAddress": "ip.1.0.0.1", |
| 45 | + "PrivateDnsName": "ip-1-0-0-1", |
| 46 | + "NetworkInterfaces": [ |
| 47 | + { |
| 48 | + "Attachment": { |
| 49 | + "DeviceIndex": 0, |
| 50 | + "NetworkCardIndex": 0, |
| 51 | + }, |
| 52 | + }, |
| 53 | + ], |
| 54 | + }, |
| 55 | + "ip.1.0.0.1", |
| 56 | + "ip-1-0-0-1", |
| 57 | + ), |
| 58 | + ( |
| 59 | + { |
| 60 | + "InstanceId": "i-12345", |
| 61 | + "InstanceType": "c5.xlarge", |
| 62 | + "PrivateIpAddress": "ip.1.0.0.1", |
| 63 | + "PrivateDnsName": "ip-1-0-0-1", |
| 64 | + "NetworkInterfaces": [ |
| 65 | + { |
| 66 | + "Attachment": {}, |
| 67 | + }, |
| 68 | + ], |
| 69 | + }, |
| 70 | + "ip.1.0.0.1", |
| 71 | + "ip-1-0-0-1", |
| 72 | + ), |
| 73 | + ( |
| 74 | + { |
| 75 | + "InstanceId": "i-12345", |
| 76 | + "InstanceType": "c5.xlarge", |
| 77 | + "PrivateIpAddress": "ip.1.0.0.1", |
| 78 | + "PrivateDnsName": "ip-1-0-0-1", |
| 79 | + "NetworkInterfaces": [ |
| 80 | + { |
| 81 | + "Attachment": { |
| 82 | + "DeviceIndex": 0, |
| 83 | + "NetworkCardIndex": 1, |
| 84 | + }, |
| 85 | + "PrivateIpAddress": "ip.1.0.0.1", |
| 86 | + "PrivateDnsName": "ip-1-0-0-1", |
| 87 | + }, |
| 88 | + { |
| 89 | + "Attachment": { |
| 90 | + "DeviceIndex": 0, |
| 91 | + "NetworkCardIndex": 0, |
| 92 | + }, |
| 93 | + "PrivateIpAddress": "ip.1.0.0.2", |
| 94 | + "PrivateDnsName": "ip-1-0-0-2", |
| 95 | + }, |
| 96 | + ], |
| 97 | + }, |
| 98 | + "ip.1.0.0.2", |
| 99 | + "ip-1-0-0-2", |
| 100 | + ), |
| 101 | + ( |
| 102 | + { |
| 103 | + "InstanceId": "i-12345", |
| 104 | + "InstanceType": "c5.xlarge", |
| 105 | + "PrivateIpAddress": "ip.1.0.0.1", |
| 106 | + "PrivateDnsName": "ip-1-0-0-1", |
| 107 | + "NetworkInterfaces": [ |
| 108 | + { |
| 109 | + "Attachment": { |
| 110 | + "DeviceIndex": 0, |
| 111 | + "NetworkCardIndex": 0, |
| 112 | + }, |
| 113 | + "PrivateIpAddress": "ip.1.0.0.1", |
| 114 | + "PrivateDnsName": "ip-1-0-0-1", |
| 115 | + }, |
| 116 | + { |
| 117 | + "Attachment": { |
| 118 | + "DeviceIndex": 0, |
| 119 | + "NetworkCardIndex": 1, |
| 120 | + }, |
| 121 | + "PrivateIpAddress": "ip.1.0.0.2", |
| 122 | + "PrivateDnsName": "ip-1-0-0-2", |
| 123 | + }, |
| 124 | + ], |
| 125 | + }, |
| 126 | + "ip.1.0.0.1", |
| 127 | + "ip-1-0-0-1", |
| 128 | + ), |
| 129 | + ], |
| 130 | +) |
| 131 | +def test_get_private_ip_address_and_dns_name(mocker, instance_info, expected_private_ip, expected_private_dns_name): |
| 132 | + actual_private_ip, actual_private_dns_name = get_private_ip_address_and_dns_name(instance_info) |
| 133 | + assert_that(actual_private_ip).is_equal_to(expected_private_ip) |
| 134 | + assert_that(actual_private_dns_name).is_equal_to(expected_private_dns_name) |
0 commit comments