| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  | import json | 
					
						
							|  |  |  | from copy import deepcopy | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import moto.server as server | 
					
						
							|  |  |  | from moto import mock_eks | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  | from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  | from moto.eks.exceptions import ResourceInUseException, ResourceNotFoundException | 
					
						
							|  |  |  | from moto.eks.models import ( | 
					
						
							|  |  |  |     CLUSTER_EXISTS_MSG, | 
					
						
							|  |  |  |     CLUSTER_IN_USE_MSG, | 
					
						
							|  |  |  |     CLUSTER_NOT_FOUND_MSG, | 
					
						
							|  |  |  |     NODEGROUP_EXISTS_MSG, | 
					
						
							|  |  |  |     NODEGROUP_NOT_FOUND_MSG, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | from moto.eks.responses import DEFAULT_MAX_RESULTS, DEFAULT_NEXT_TOKEN | 
					
						
							|  |  |  | from tests.test_eks.test_eks import all_arn_values_should_be_valid | 
					
						
							|  |  |  | from tests.test_eks.test_eks_constants import ( | 
					
						
							|  |  |  |     AddonAttributes, | 
					
						
							|  |  |  |     ClusterAttributes, | 
					
						
							|  |  |  |     DEFAULT_ENCODING, | 
					
						
							|  |  |  |     DEFAULT_HTTP_HEADERS, | 
					
						
							|  |  |  |     DEFAULT_REGION, | 
					
						
							|  |  |  |     Endpoints, | 
					
						
							| 
									
										
										
										
											2021-08-18 22:44:56 -07:00
										 |  |  |     FargateProfileAttributes, | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |     HttpHeaders, | 
					
						
							|  |  |  |     NodegroupAttributes, | 
					
						
							|  |  |  |     NODEROLE_ARN_KEY, | 
					
						
							|  |  |  |     NODEROLE_ARN_VALUE, | 
					
						
							|  |  |  |     PARTITIONS, | 
					
						
							|  |  |  |     RegExTemplates, | 
					
						
							|  |  |  |     ResponseAttributes, | 
					
						
							|  |  |  |     ROLE_ARN_KEY, | 
					
						
							|  |  |  |     ROLE_ARN_VALUE, | 
					
						
							|  |  |  |     SERVICE, | 
					
						
							|  |  |  |     StatusCodes, | 
					
						
							|  |  |  |     SUBNETS_KEY, | 
					
						
							|  |  |  |     SUBNETS_VALUE, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | Test the different server responses | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NAME_LIST = ["foo", "bar", "baz", "qux"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestCluster: | 
					
						
							|  |  |  |     cluster_name = "example_cluster" | 
					
						
							|  |  |  |     data = {ClusterAttributes.NAME: cluster_name, ROLE_ARN_KEY: ROLE_ARN_VALUE} | 
					
						
							|  |  |  |     endpoint = Endpoints.CREATE_CLUSTER | 
					
						
							|  |  |  |     expected_arn_values = [ | 
					
						
							|  |  |  |         PARTITIONS, | 
					
						
							|  |  |  |         DEFAULT_REGION, | 
					
						
							|  |  |  |         ACCOUNT_ID, | 
					
						
							|  |  |  |         cluster_name, | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestNodegroup: | 
					
						
							|  |  |  |     cluster_name = TestCluster.cluster_name | 
					
						
							|  |  |  |     nodegroup_name = "example_nodegroup" | 
					
						
							|  |  |  |     data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: cluster_name, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: nodegroup_name, | 
					
						
							|  |  |  |         NODEROLE_ARN_KEY: NODEROLE_ARN_VALUE, | 
					
						
							|  |  |  |         SUBNETS_KEY: SUBNETS_VALUE, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     endpoint = Endpoints.CREATE_NODEGROUP.format(clusterName=cluster_name) | 
					
						
							|  |  |  |     expected_arn_values = [ | 
					
						
							|  |  |  |         PARTITIONS, | 
					
						
							|  |  |  |         DEFAULT_REGION, | 
					
						
							|  |  |  |         ACCOUNT_ID, | 
					
						
							|  |  |  |         cluster_name, | 
					
						
							|  |  |  |         nodegroup_name, | 
					
						
							|  |  |  |         None, | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-04 16:28:30 +00:00
										 |  |  | @pytest.fixture(autouse=True, name="test_client") | 
					
						
							|  |  |  | def fixture_test_client(): | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  |     backend = server.create_backend_app(service=SERVICE) | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |     yield backend.test_client() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-04 16:28:30 +00:00
										 |  |  | @pytest.fixture(scope="function", name="create_cluster") | 
					
						
							|  |  |  | def fixtue_create_cluster(test_client): | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |     def create_and_verify_cluster(client, name): | 
					
						
							|  |  |  |         """Creates one valid cluster and verifies return status code 200.""" | 
					
						
							|  |  |  |         data = deepcopy(TestCluster.data) | 
					
						
							|  |  |  |         data.update(name=name) | 
					
						
							|  |  |  |         response = client.post( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |             TestCluster.endpoint, data=json.dumps(data), headers=DEFAULT_HTTP_HEADERS | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         response.status_code.should.equal(StatusCodes.OK) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return json.loads(response.data.decode(DEFAULT_ENCODING))[ | 
					
						
							|  |  |  |             ResponseAttributes.CLUSTER | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _execute(name=TestCluster.cluster_name): | 
					
						
							|  |  |  |         return create_and_verify_cluster(test_client, name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     yield _execute | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-04 16:28:30 +00:00
										 |  |  | @pytest.fixture(scope="function", autouse=True, name="create_nodegroup") | 
					
						
							|  |  |  | def fixture_create_nodegroup(test_client): | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |     def create_and_verify_nodegroup(client, name): | 
					
						
							|  |  |  |         """Creates one valid nodegroup and verifies return status code 200.""" | 
					
						
							|  |  |  |         data = deepcopy(TestNodegroup.data) | 
					
						
							|  |  |  |         data.update(nodegroupName=name) | 
					
						
							|  |  |  |         response = client.post( | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  |             TestNodegroup.endpoint, data=json.dumps(data), headers=DEFAULT_HTTP_HEADERS | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |         ) | 
					
						
							|  |  |  |         response.status_code.should.equal(StatusCodes.OK) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return json.loads(response.data.decode(DEFAULT_ENCODING))[ | 
					
						
							|  |  |  |             ResponseAttributes.NODEGROUP | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def _execute(name=TestNodegroup.nodegroup_name): | 
					
						
							|  |  |  |         return create_and_verify_nodegroup(test_client, name=name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     yield _execute | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_create_single_cluster(create_cluster): | 
					
						
							|  |  |  |     result_cluster = create_cluster() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     result_cluster[ClusterAttributes.NAME].should.equal(TestCluster.cluster_name) | 
					
						
							|  |  |  |     all_arn_values_should_be_valid( | 
					
						
							|  |  |  |         expected_arn_values=TestCluster.expected_arn_values, | 
					
						
							|  |  |  |         pattern=RegExTemplates.CLUSTER_ARN, | 
					
						
							|  |  |  |         arn_under_test=result_cluster[ClusterAttributes.ARN], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_create_multiple_clusters_with_same_name(test_client, create_cluster): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  |     expected_exception = ResourceInUseException | 
					
						
							|  |  |  |     expected_msg = CLUSTER_EXISTS_MSG.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: TestCluster.cluster_name, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: None, | 
					
						
							|  |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.post( | 
					
						
							|  |  |  |         TestCluster.endpoint, | 
					
						
							|  |  |  |         data=json.dumps(TestCluster.data), | 
					
						
							|  |  |  |         headers=DEFAULT_HTTP_HEADERS, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_create_nodegroup_without_cluster(test_client): | 
					
						
							|  |  |  |     expected_exception = ResourceNotFoundException | 
					
						
							|  |  |  |     expected_msg = CLUSTER_NOT_FOUND_MSG.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: None, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-08-18 22:44:56 -07:00
										 |  |  |         FargateProfileAttributes.FARGATE_PROFILE_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     endpoint = Endpoints.CREATE_NODEGROUP.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.post( | 
					
						
							|  |  |  |         endpoint, data=json.dumps(TestNodegroup.data), headers=DEFAULT_HTTP_HEADERS | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_create_nodegroup_on_existing_cluster(create_cluster, create_nodegroup): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  |     result_data = create_nodegroup() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     result_data[NodegroupAttributes.NODEGROUP_NAME].should.equal( | 
					
						
							|  |  |  |         TestNodegroup.nodegroup_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     all_arn_values_should_be_valid( | 
					
						
							|  |  |  |         expected_arn_values=TestNodegroup.expected_arn_values, | 
					
						
							|  |  |  |         pattern=RegExTemplates.NODEGROUP_ARN, | 
					
						
							|  |  |  |         arn_under_test=result_data[NodegroupAttributes.ARN], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_create_multiple_nodegroups_with_same_name( | 
					
						
							|  |  |  |     test_client, create_cluster, create_nodegroup | 
					
						
							|  |  |  | ): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  |     create_nodegroup() | 
					
						
							|  |  |  |     expected_exception = ResourceInUseException | 
					
						
							|  |  |  |     expected_msg = NODEGROUP_EXISTS_MSG.format( | 
					
						
							|  |  |  |         clusterName=TestNodegroup.cluster_name, | 
					
						
							|  |  |  |         nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: TestNodegroup.cluster_name, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.post( | 
					
						
							|  |  |  |         TestNodegroup.endpoint, | 
					
						
							|  |  |  |         data=json.dumps(TestNodegroup.data), | 
					
						
							|  |  |  |         headers=DEFAULT_HTTP_HEADERS, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_list_clusters(test_client, create_cluster): | 
					
						
							|  |  |  |     [create_cluster(name) for name in NAME_LIST] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.get( | 
					
						
							|  |  |  |         Endpoints.LIST_CLUSTERS.format( | 
					
						
							|  |  |  |             maxResults=DEFAULT_MAX_RESULTS, nextToken=DEFAULT_NEXT_TOKEN | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result_data = json.loads(response.data.decode(DEFAULT_ENCODING))[ | 
					
						
							|  |  |  |         ResponseAttributes.CLUSTERS | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.status_code.should.equal(StatusCodes.OK) | 
					
						
							|  |  |  |     len(result_data).should.equal(len(NAME_LIST)) | 
					
						
							|  |  |  |     sorted(result_data).should.equal(sorted(NAME_LIST)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_list_nodegroups(test_client, create_cluster, create_nodegroup): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  |     [create_nodegroup(name) for name in NAME_LIST] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.get( | 
					
						
							|  |  |  |         Endpoints.LIST_NODEGROUPS.format( | 
					
						
							|  |  |  |             clusterName=TestCluster.cluster_name, | 
					
						
							|  |  |  |             maxResults=DEFAULT_MAX_RESULTS, | 
					
						
							|  |  |  |             nextToken=DEFAULT_NEXT_TOKEN, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result_data = json.loads(response.data.decode(DEFAULT_ENCODING))[ | 
					
						
							|  |  |  |         ResponseAttributes.NODEGROUPS | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.status_code.should.equal(StatusCodes.OK) | 
					
						
							|  |  |  |     sorted(result_data).should.equal(sorted(NAME_LIST)) | 
					
						
							|  |  |  |     len(result_data).should.equal(len(NAME_LIST)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_describe_existing_cluster(test_client, create_cluster): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.get( | 
					
						
							|  |  |  |         Endpoints.DESCRIBE_CLUSTER.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result_data = json.loads(response.data.decode(DEFAULT_ENCODING))[ | 
					
						
							|  |  |  |         ResponseAttributes.CLUSTER | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.status_code.should.equal(StatusCodes.OK) | 
					
						
							|  |  |  |     result_data[ClusterAttributes.NAME].should.equal(TestCluster.cluster_name) | 
					
						
							| 
									
										
										
										
											2022-03-29 22:40:23 +00:00
										 |  |  |     result_data[ClusterAttributes.ENCRYPTION_CONFIG].should.equal([]) | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |     all_arn_values_should_be_valid( | 
					
						
							|  |  |  |         expected_arn_values=TestCluster.expected_arn_values, | 
					
						
							|  |  |  |         pattern=RegExTemplates.CLUSTER_ARN, | 
					
						
							|  |  |  |         arn_under_test=result_data[ClusterAttributes.ARN], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_describe_nonexisting_cluster(test_client): | 
					
						
							|  |  |  |     expected_exception = ResourceNotFoundException | 
					
						
							|  |  |  |     expected_msg = CLUSTER_NOT_FOUND_MSG.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: None, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-08-18 22:44:56 -07:00
										 |  |  |         FargateProfileAttributes.FARGATE_PROFILE_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.get( | 
					
						
							|  |  |  |         Endpoints.DESCRIBE_CLUSTER.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_describe_existing_nodegroup(test_client, create_cluster, create_nodegroup): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  |     create_nodegroup() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.get( | 
					
						
							|  |  |  |         Endpoints.DESCRIBE_NODEGROUP.format( | 
					
						
							|  |  |  |             clusterName=TestNodegroup.cluster_name, | 
					
						
							|  |  |  |             nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result_data = json.loads(response.data.decode(DEFAULT_ENCODING))[ | 
					
						
							|  |  |  |         ResponseAttributes.NODEGROUP | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.status_code.should.equal(StatusCodes.OK) | 
					
						
							|  |  |  |     result_data[ClusterAttributes.CLUSTER_NAME].should.equal(TestNodegroup.cluster_name) | 
					
						
							|  |  |  |     result_data[NodegroupAttributes.NODEGROUP_NAME].should.equal( | 
					
						
							|  |  |  |         TestNodegroup.nodegroup_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     all_arn_values_should_be_valid( | 
					
						
							|  |  |  |         expected_arn_values=TestNodegroup.expected_arn_values, | 
					
						
							|  |  |  |         pattern=RegExTemplates.NODEGROUP_ARN, | 
					
						
							|  |  |  |         arn_under_test=result_data[NodegroupAttributes.ARN], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_describe_nonexisting_nodegroup(test_client, create_cluster): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  |     expected_exception = ResourceNotFoundException | 
					
						
							|  |  |  |     expected_msg = NODEGROUP_NOT_FOUND_MSG.format( | 
					
						
							|  |  |  |         clusterName=TestNodegroup.cluster_name, | 
					
						
							|  |  |  |         nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: TestNodegroup.cluster_name, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: TestNodegroup.nodegroup_name, | 
					
						
							| 
									
										
										
										
											2021-08-18 22:44:56 -07:00
										 |  |  |         FargateProfileAttributes.FARGATE_PROFILE_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.get( | 
					
						
							|  |  |  |         Endpoints.DESCRIBE_NODEGROUP.format( | 
					
						
							|  |  |  |             clusterName=TestCluster.cluster_name, | 
					
						
							|  |  |  |             nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_describe_nodegroup_nonexisting_cluster(test_client): | 
					
						
							|  |  |  |     expected_exception = ResourceNotFoundException | 
					
						
							|  |  |  |     expected_msg = CLUSTER_NOT_FOUND_MSG.format(clusterName=TestNodegroup.cluster_name) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: TestNodegroup.cluster_name, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: TestNodegroup.nodegroup_name, | 
					
						
							| 
									
										
										
										
											2021-08-18 22:44:56 -07:00
										 |  |  |         FargateProfileAttributes.FARGATE_PROFILE_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.get( | 
					
						
							|  |  |  |         Endpoints.DESCRIBE_NODEGROUP.format( | 
					
						
							|  |  |  |             clusterName=TestCluster.cluster_name, | 
					
						
							|  |  |  |             nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_delete_cluster(test_client, create_cluster): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.delete( | 
					
						
							|  |  |  |         Endpoints.DELETE_CLUSTER.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result_data = json.loads(response.data.decode(DEFAULT_ENCODING))[ | 
					
						
							|  |  |  |         ResponseAttributes.CLUSTER | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.status_code.should.equal(StatusCodes.OK) | 
					
						
							|  |  |  |     result_data[ClusterAttributes.NAME].should.equal(TestCluster.cluster_name) | 
					
						
							|  |  |  |     all_arn_values_should_be_valid( | 
					
						
							|  |  |  |         expected_arn_values=TestCluster.expected_arn_values, | 
					
						
							|  |  |  |         pattern=RegExTemplates.CLUSTER_ARN, | 
					
						
							|  |  |  |         arn_under_test=result_data[ClusterAttributes.ARN], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_delete_nonexisting_cluster(test_client): | 
					
						
							|  |  |  |     expected_exception = ResourceNotFoundException | 
					
						
							|  |  |  |     expected_msg = CLUSTER_NOT_FOUND_MSG.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: None, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-08-18 22:44:56 -07:00
										 |  |  |         FargateProfileAttributes.FARGATE_PROFILE_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.delete( | 
					
						
							|  |  |  |         Endpoints.DELETE_CLUSTER.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_delete_cluster_with_nodegroups( | 
					
						
							|  |  |  |     test_client, create_cluster, create_nodegroup | 
					
						
							|  |  |  | ): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  |     create_nodegroup() | 
					
						
							|  |  |  |     expected_exception = ResourceInUseException | 
					
						
							|  |  |  |     expected_msg = CLUSTER_IN_USE_MSG.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: TestCluster.cluster_name, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.delete( | 
					
						
							|  |  |  |         Endpoints.DELETE_CLUSTER.format(clusterName=TestCluster.cluster_name) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_delete_nodegroup(test_client, create_cluster, create_nodegroup): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  |     create_nodegroup() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.delete( | 
					
						
							|  |  |  |         Endpoints.DELETE_NODEGROUP.format( | 
					
						
							|  |  |  |             clusterName=TestNodegroup.cluster_name, | 
					
						
							|  |  |  |             nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     result_data = json.loads(response.data.decode(DEFAULT_ENCODING))[ | 
					
						
							|  |  |  |         ResponseAttributes.NODEGROUP | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.status_code.should.equal(StatusCodes.OK) | 
					
						
							|  |  |  |     result_data[ClusterAttributes.CLUSTER_NAME].should.equal(TestNodegroup.cluster_name) | 
					
						
							|  |  |  |     result_data[NodegroupAttributes.NODEGROUP_NAME].should.equal( | 
					
						
							|  |  |  |         TestNodegroup.nodegroup_name | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     all_arn_values_should_be_valid( | 
					
						
							|  |  |  |         expected_arn_values=TestNodegroup.expected_arn_values, | 
					
						
							|  |  |  |         pattern=RegExTemplates.NODEGROUP_ARN, | 
					
						
							|  |  |  |         arn_under_test=result_data[NodegroupAttributes.ARN], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_delete_nonexisting_nodegroup(test_client, create_cluster): | 
					
						
							|  |  |  |     create_cluster() | 
					
						
							|  |  |  |     expected_exception = ResourceNotFoundException | 
					
						
							|  |  |  |     expected_msg = NODEGROUP_NOT_FOUND_MSG.format( | 
					
						
							|  |  |  |         clusterName=TestNodegroup.cluster_name, | 
					
						
							|  |  |  |         nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: TestNodegroup.cluster_name, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: TestNodegroup.nodegroup_name, | 
					
						
							| 
									
										
										
										
											2021-08-18 22:44:56 -07:00
										 |  |  |         FargateProfileAttributes.FARGATE_PROFILE_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.delete( | 
					
						
							|  |  |  |         Endpoints.DELETE_NODEGROUP.format( | 
					
						
							|  |  |  |             clusterName=TestNodegroup.cluster_name, | 
					
						
							|  |  |  |             nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_eks | 
					
						
							|  |  |  | def test_eks_delete_nodegroup_nonexisting_cluster(test_client): | 
					
						
							|  |  |  |     expected_exception = ResourceNotFoundException | 
					
						
							|  |  |  |     expected_msg = CLUSTER_NOT_FOUND_MSG.format( | 
					
						
							|  |  |  |         clusterName=TestNodegroup.cluster_name, | 
					
						
							|  |  |  |         nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     expected_data = { | 
					
						
							|  |  |  |         ClusterAttributes.CLUSTER_NAME: None, | 
					
						
							|  |  |  |         NodegroupAttributes.NODEGROUP_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-08-18 22:44:56 -07:00
										 |  |  |         FargateProfileAttributes.FARGATE_PROFILE_NAME: None, | 
					
						
							| 
									
										
										
										
											2021-06-20 03:34:31 -07:00
										 |  |  |         AddonAttributes.ADDON_NAME: None, | 
					
						
							|  |  |  |         ResponseAttributes.MESSAGE: expected_msg, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = test_client.delete( | 
					
						
							|  |  |  |         Endpoints.DELETE_NODEGROUP.format( | 
					
						
							|  |  |  |             clusterName=TestNodegroup.cluster_name, | 
					
						
							|  |  |  |             nodegroupName=TestNodegroup.nodegroup_name, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     should_return_expected_exception(response, expected_exception, expected_data) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def should_return_expected_exception(response, expected_exception, expected_data): | 
					
						
							|  |  |  |     result_data = json.loads(response.data.decode(DEFAULT_ENCODING)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response.status_code.should.equal(expected_exception.STATUS) | 
					
						
							|  |  |  |     response.headers.get(HttpHeaders.ErrorType).should.equal(expected_exception.TYPE) | 
					
						
							|  |  |  |     result_data.should.equal(expected_data) |