Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,193 +2,191 @@
import json
import os

from moto import mock_ec2, mock_cloudtrail, mock_iam, mock_s3
import pytest
from moto import mock_ec2, mock_cloudtrail, mock_iam, mock_s3, mock_elb, mock_elbv2
import boto3

from cloud_governance.policy.policy_operations.aws.tag_cluster.tag_cluster_resouces import TagClusterResources

cluster_prefix=["kubernetes.io/cluster", "sigs.k8s.io/cluster-api-provider-aws/cluster"]
cluster_prefix = ["kubernetes.io/cluster", "sigs.k8s.io/cluster-api-provider-aws/cluster"]
cluster_name = ''
# cluster_name = 'ocs-test-jlhpd'
# cluster_name = 'opc464-k7jml'

os.environ['SLEEP_SECONDS'] = '0'
# input tags
mandatory_tags = {}
# mandatory_tags = {
# "Name": "test-opc464",
# "Owner": "Eli Battat",
# "Email": "ebattat@redhat.com",
# "Purpose": "test",
# "Date": strftime("%Y/%m/%d %H:%M:%S")
# }
# print(strftime("%Y/%m/%d %H:%M:%S", gmtime()))

tag_cluster_resources = TagClusterResources(cluster_prefix=cluster_prefix, cluster_name=cluster_name,
input_tags=mandatory_tags, region='us-east-2')

@pytest.fixture(scope="module")
def tag_cluster_resources():
"""Create TagClusterResources under mocks so __init__ (IAM list_users, EC2, etc.) does not hit real AWS."""
with mock_ec2(), mock_iam(), mock_cloudtrail(), mock_s3(), mock_elb(), mock_elbv2():
yield TagClusterResources(
cluster_prefix=cluster_prefix,
cluster_name=cluster_name,
input_tags=mandatory_tags,
region='us-east-2',
)


def test_init_cluster_name():
def test_init_cluster_name(tag_cluster_resources):
"""
This method search for full cluster key stamp according to part of cluster name
:return:
"""
assert len(tag_cluster_resources._TagClusterResources__init_cluster_name()) >= 0


def test_cluster_instance():
def test_cluster_instance(tag_cluster_resources):
"""
This method return all cluster instances
:return:
"""
assert len(tag_cluster_resources.cluster_instance()) >= 0


def test_cluster_volume():
def test_cluster_volume(tag_cluster_resources):
"""
This method return all cluster volumes
:return:
"""
assert len(tag_cluster_resources.cluster_volume()) >= 0


def test_cluster_ami():
def test_cluster_ami(tag_cluster_resources):
"""
This method return all cluster ami
:return:
"""
assert len(tag_cluster_resources.cluster_ami()) >= 0


def test_cluster_snapshot():
def test_cluster_snapshot(tag_cluster_resources):
"""
This method return all cluster snapshot
:return:
"""
assert len(tag_cluster_resources.cluster_snapshot()) >= 0


def test_cluster_security_group():
def test_cluster_security_group(tag_cluster_resources):
"""
This method return all cluster security_group
:return:
"""
print(tag_cluster_resources.cluster_security_group())


def test_cluster_elastic_ip():
def test_cluster_elastic_ip(tag_cluster_resources):
"""
This method return all cluster elastic_ip
:return:
"""
assert len(tag_cluster_resources.cluster_elastic_ip()) >= 0


def test_cluster_network_interface():
def test_cluster_network_interface(tag_cluster_resources):
"""
This method return all cluster network_interface
:return:
"""
assert len(tag_cluster_resources.cluster_network_interface()) >= 0


def test_cluster_load_balancer():
def test_cluster_load_balancer(tag_cluster_resources):
"""
This method return all cluster load_balancer
:return:
"""
assert len(tag_cluster_resources.cluster_load_balancer()) >= 0


def test_cluster_load_balancer_v2():
def test_cluster_load_balancer_v2(tag_cluster_resources):
"""
This method return all cluster load_balancer
:return:
"""
assert len(tag_cluster_resources.cluster_load_balancer_v2()) >= 0


def test_cluster_vpc():
def test_cluster_vpc(tag_cluster_resources):
"""
This method return all cluster cluster_vpc
:return:
"""
assert len(tag_cluster_resources.cluster_vpc()) >= 0


def test_cluster_subnet():
def test_cluster_subnet(tag_cluster_resources):
"""
This method return all cluster cluster_subnet
:return:
"""
assert len(tag_cluster_resources.cluster_subnet()) >= 0


def test_cluster_route_table():
def test_cluster_route_table(tag_cluster_resources):
"""
This method return all cluster route_table
:return:
"""
assert len(tag_cluster_resources.cluster_route_table()) >= 0


def test_cluster_internet_gateway():
def test_cluster_internet_gateway(tag_cluster_resources):
"""
This method return all cluster internet_gateway
:return:
"""
assert len(tag_cluster_resources.cluster_internet_gateway()) >= 0


def test_cluster_dhcp_option():
def test_cluster_dhcp_option(tag_cluster_resources):
"""
This method return all cluster dhcp_option
:return:
"""
assert len(tag_cluster_resources.cluster_dhcp_option()) >= 0


def test_cluster_vpc_endpoint():
def test_cluster_vpc_endpoint(tag_cluster_resources):
"""
This method return all cluster vpc_endpoint
:return:
"""
assert len(tag_cluster_resources.cluster_vpc_endpoint()) >= 0


def test_cluster_nat_gateway():
def test_cluster_nat_gateway(tag_cluster_resources):
"""
This method return all cluster nat_gateway
:return:
"""
assert len(tag_cluster_resources.cluster_nat_gateway()) >= 0


def test_cluster_network_acl():
def test_cluster_network_acl(tag_cluster_resources):
"""
This method return all cluster network_acl
:return:
"""
assert len(tag_cluster_resources.cluster_network_acl()) >= 0


def test_cluster_role():
def test_cluster_role(tag_cluster_resources):
"""
This method return all cluster role
:return:
"""
assert len(tag_cluster_resources.cluster_role()) >= 0


def test_cluster_user():
def test_cluster_user(tag_cluster_resources):
"""
This method return all cluster role
:return:
"""
print(tag_cluster_resources.cluster_user())


def test_cluster_s3_bucket():
def test_cluster_s3_bucket(tag_cluster_resources):
"""
This method return all cluster s3_bucket
:return:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

mandatory_tags = {'test': 'ec2-update'}
region_name = 'us-east-2'
tag_resources = TagNonClusterResources(input_tags=mandatory_tags, dry_run='no')
# Do not instantiate at module level: __init__ calls IAM list_users. Each test creates its own under mocks.
os.environ['SLEEP_SECONDS'] = '0'


Expand Down
Loading