|
2 | 2 | import json |
3 | 3 | import os |
4 | 4 |
|
5 | | -from moto import mock_ec2, mock_cloudtrail, mock_iam, mock_s3 |
| 5 | +import pytest |
| 6 | +from moto import mock_ec2, mock_cloudtrail, mock_iam, mock_s3, mock_elb, mock_elbv2 |
6 | 7 | import boto3 |
7 | 8 |
|
8 | 9 | from cloud_governance.policy.policy_operations.aws.tag_cluster.tag_cluster_resouces import TagClusterResources |
9 | 10 |
|
10 | | -cluster_prefix=["kubernetes.io/cluster", "sigs.k8s.io/cluster-api-provider-aws/cluster"] |
| 11 | +cluster_prefix = ["kubernetes.io/cluster", "sigs.k8s.io/cluster-api-provider-aws/cluster"] |
11 | 12 | cluster_name = '' |
12 | | -# cluster_name = 'ocs-test-jlhpd' |
13 | | -# cluster_name = 'opc464-k7jml' |
14 | | - |
15 | 13 | os.environ['SLEEP_SECONDS'] = '0' |
16 | | -# input tags |
17 | 14 | mandatory_tags = {} |
18 | | -# mandatory_tags = { |
19 | | -# "Name": "test-opc464", |
20 | | -# "Owner": "Eli Battat", |
21 | | -# "Email": "ebattat@redhat.com", |
22 | | -# "Purpose": "test", |
23 | | -# "Date": strftime("%Y/%m/%d %H:%M:%S") |
24 | | -# } |
25 | | -# print(strftime("%Y/%m/%d %H:%M:%S", gmtime())) |
26 | 15 |
|
27 | | -tag_cluster_resources = TagClusterResources(cluster_prefix=cluster_prefix, cluster_name=cluster_name, |
28 | | - input_tags=mandatory_tags, region='us-east-2') |
| 16 | + |
| 17 | +@pytest.fixture(scope="module") |
| 18 | +def tag_cluster_resources(): |
| 19 | + """Create TagClusterResources under mocks so __init__ (IAM list_users, EC2, etc.) does not hit real AWS.""" |
| 20 | + with mock_ec2(), mock_iam(), mock_cloudtrail(), mock_s3(), mock_elb(), mock_elbv2(): |
| 21 | + yield TagClusterResources( |
| 22 | + cluster_prefix=cluster_prefix, |
| 23 | + cluster_name=cluster_name, |
| 24 | + input_tags=mandatory_tags, |
| 25 | + region='us-east-2', |
| 26 | + ) |
29 | 27 |
|
30 | 28 |
|
31 | | -def test_init_cluster_name(): |
| 29 | +def test_init_cluster_name(tag_cluster_resources): |
32 | 30 | """ |
33 | 31 | This method search for full cluster key stamp according to part of cluster name |
34 | 32 | :return: |
35 | 33 | """ |
36 | 34 | assert len(tag_cluster_resources._TagClusterResources__init_cluster_name()) >= 0 |
37 | 35 |
|
38 | 36 |
|
39 | | -def test_cluster_instance(): |
| 37 | +def test_cluster_instance(tag_cluster_resources): |
40 | 38 | """ |
41 | 39 | This method return all cluster instances |
42 | 40 | :return: |
43 | 41 | """ |
44 | 42 | assert len(tag_cluster_resources.cluster_instance()) >= 0 |
45 | 43 |
|
46 | 44 |
|
47 | | -def test_cluster_volume(): |
| 45 | +def test_cluster_volume(tag_cluster_resources): |
48 | 46 | """ |
49 | 47 | This method return all cluster volumes |
50 | 48 | :return: |
51 | 49 | """ |
52 | 50 | assert len(tag_cluster_resources.cluster_volume()) >= 0 |
53 | 51 |
|
54 | 52 |
|
55 | | -def test_cluster_ami(): |
| 53 | +def test_cluster_ami(tag_cluster_resources): |
56 | 54 | """ |
57 | 55 | This method return all cluster ami |
58 | 56 | :return: |
59 | 57 | """ |
60 | 58 | assert len(tag_cluster_resources.cluster_ami()) >= 0 |
61 | 59 |
|
62 | 60 |
|
63 | | -def test_cluster_snapshot(): |
| 61 | +def test_cluster_snapshot(tag_cluster_resources): |
64 | 62 | """ |
65 | 63 | This method return all cluster snapshot |
66 | 64 | :return: |
67 | 65 | """ |
68 | 66 | assert len(tag_cluster_resources.cluster_snapshot()) >= 0 |
69 | 67 |
|
70 | 68 |
|
71 | | -def test_cluster_security_group(): |
| 69 | +def test_cluster_security_group(tag_cluster_resources): |
72 | 70 | """ |
73 | 71 | This method return all cluster security_group |
74 | 72 | :return: |
75 | 73 | """ |
76 | 74 | print(tag_cluster_resources.cluster_security_group()) |
77 | 75 |
|
78 | 76 |
|
79 | | -def test_cluster_elastic_ip(): |
| 77 | +def test_cluster_elastic_ip(tag_cluster_resources): |
80 | 78 | """ |
81 | 79 | This method return all cluster elastic_ip |
82 | 80 | :return: |
83 | 81 | """ |
84 | 82 | assert len(tag_cluster_resources.cluster_elastic_ip()) >= 0 |
85 | 83 |
|
86 | 84 |
|
87 | | -def test_cluster_network_interface(): |
| 85 | +def test_cluster_network_interface(tag_cluster_resources): |
88 | 86 | """ |
89 | 87 | This method return all cluster network_interface |
90 | 88 | :return: |
91 | 89 | """ |
92 | 90 | assert len(tag_cluster_resources.cluster_network_interface()) >= 0 |
93 | 91 |
|
94 | 92 |
|
95 | | -def test_cluster_load_balancer(): |
| 93 | +def test_cluster_load_balancer(tag_cluster_resources): |
96 | 94 | """ |
97 | 95 | This method return all cluster load_balancer |
98 | 96 | :return: |
99 | 97 | """ |
100 | 98 | assert len(tag_cluster_resources.cluster_load_balancer()) >= 0 |
101 | 99 |
|
102 | 100 |
|
103 | | -def test_cluster_load_balancer_v2(): |
| 101 | +def test_cluster_load_balancer_v2(tag_cluster_resources): |
104 | 102 | """ |
105 | 103 | This method return all cluster load_balancer |
106 | 104 | :return: |
107 | 105 | """ |
108 | 106 | assert len(tag_cluster_resources.cluster_load_balancer_v2()) >= 0 |
109 | 107 |
|
110 | 108 |
|
111 | | -def test_cluster_vpc(): |
| 109 | +def test_cluster_vpc(tag_cluster_resources): |
112 | 110 | """ |
113 | 111 | This method return all cluster cluster_vpc |
114 | 112 | :return: |
115 | 113 | """ |
116 | 114 | assert len(tag_cluster_resources.cluster_vpc()) >= 0 |
117 | 115 |
|
118 | 116 |
|
119 | | -def test_cluster_subnet(): |
| 117 | +def test_cluster_subnet(tag_cluster_resources): |
120 | 118 | """ |
121 | 119 | This method return all cluster cluster_subnet |
122 | 120 | :return: |
123 | 121 | """ |
124 | 122 | assert len(tag_cluster_resources.cluster_subnet()) >= 0 |
125 | 123 |
|
126 | 124 |
|
127 | | -def test_cluster_route_table(): |
| 125 | +def test_cluster_route_table(tag_cluster_resources): |
128 | 126 | """ |
129 | 127 | This method return all cluster route_table |
130 | 128 | :return: |
131 | 129 | """ |
132 | 130 | assert len(tag_cluster_resources.cluster_route_table()) >= 0 |
133 | 131 |
|
134 | 132 |
|
135 | | -def test_cluster_internet_gateway(): |
| 133 | +def test_cluster_internet_gateway(tag_cluster_resources): |
136 | 134 | """ |
137 | 135 | This method return all cluster internet_gateway |
138 | 136 | :return: |
139 | 137 | """ |
140 | 138 | assert len(tag_cluster_resources.cluster_internet_gateway()) >= 0 |
141 | 139 |
|
142 | 140 |
|
143 | | -def test_cluster_dhcp_option(): |
| 141 | +def test_cluster_dhcp_option(tag_cluster_resources): |
144 | 142 | """ |
145 | 143 | This method return all cluster dhcp_option |
146 | 144 | :return: |
147 | 145 | """ |
148 | 146 | assert len(tag_cluster_resources.cluster_dhcp_option()) >= 0 |
149 | 147 |
|
150 | 148 |
|
151 | | -def test_cluster_vpc_endpoint(): |
| 149 | +def test_cluster_vpc_endpoint(tag_cluster_resources): |
152 | 150 | """ |
153 | 151 | This method return all cluster vpc_endpoint |
154 | 152 | :return: |
155 | 153 | """ |
156 | 154 | assert len(tag_cluster_resources.cluster_vpc_endpoint()) >= 0 |
157 | 155 |
|
158 | 156 |
|
159 | | -def test_cluster_nat_gateway(): |
| 157 | +def test_cluster_nat_gateway(tag_cluster_resources): |
160 | 158 | """ |
161 | 159 | This method return all cluster nat_gateway |
162 | 160 | :return: |
163 | 161 | """ |
164 | 162 | assert len(tag_cluster_resources.cluster_nat_gateway()) >= 0 |
165 | 163 |
|
166 | 164 |
|
167 | | -def test_cluster_network_acl(): |
| 165 | +def test_cluster_network_acl(tag_cluster_resources): |
168 | 166 | """ |
169 | 167 | This method return all cluster network_acl |
170 | 168 | :return: |
171 | 169 | """ |
172 | 170 | assert len(tag_cluster_resources.cluster_network_acl()) >= 0 |
173 | 171 |
|
174 | 172 |
|
175 | | -def test_cluster_role(): |
| 173 | +def test_cluster_role(tag_cluster_resources): |
176 | 174 | """ |
177 | 175 | This method return all cluster role |
178 | 176 | :return: |
179 | 177 | """ |
180 | 178 | assert len(tag_cluster_resources.cluster_role()) >= 0 |
181 | 179 |
|
182 | 180 |
|
183 | | -def test_cluster_user(): |
| 181 | +def test_cluster_user(tag_cluster_resources): |
184 | 182 | """ |
185 | 183 | This method return all cluster role |
186 | 184 | :return: |
187 | 185 | """ |
188 | 186 | print(tag_cluster_resources.cluster_user()) |
189 | 187 |
|
190 | 188 |
|
191 | | -def test_cluster_s3_bucket(): |
| 189 | +def test_cluster_s3_bucket(tag_cluster_resources): |
192 | 190 | """ |
193 | 191 | This method return all cluster s3_bucket |
194 | 192 | :return: |
|
0 commit comments