Beispiel #1
0
 def __init__(self,
              cluster_name: str = None,
              cluster_prefix: str = None,
              input_tags: dict = None,
              region: str = 'us-east-2',
              dry_run: str = 'yes'):
     self.ec2_client = boto3.client('ec2', region_name=region)
     self.elb_client = boto3.client('elb', region_name=region)
     self.elbv2_client = boto3.client('elbv2', region_name=region)
     self.iam_client = boto3.client('iam', region_name=region)
     self.iam_operations = IAMOperations()
     self.s3_client = boto3.client('s3')
     self.cluster_prefix = cluster_prefix
     self.cluster_name = cluster_name
     self.cluster_key = self.__init_cluster_name()
     self.input_tags = input_tags
     self.__get_details_resource_list = Utils().get_details_resource_list
     self.__get_username_from_instance_id_and_time = CloudTrailOperations(
         region_name=region).get_username_by_instance_id_and_time
     self.dry_run = dry_run
     self.non_cluster_update = TagNonClusterResources(region=region,
                                                      dry_run=dry_run,
                                                      input_tags=input_tags)
     self.ids = []
     self.ec2_operations = EC2Operations()
Beispiel #2
0
def test_delete_iam_cluster_role():
    """
    This method tests the role is deleted or not
    --> This method is not working because of Describing the role_policies have empty list
    :return:
    """
    iam_resource = boto3.client('iam')
    assume_role_policy_document = {
        "Version":
        "2012-10-17",
        "Statement": [{
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": "ec2.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }]
    }
    tags = [{
        'Key': 'kubernetes.io/cluster/unittest-test-cluster',
        'Value': 'Owned'
    }, {
        'Key': 'Owner',
        'Value': 'unitest'
    }]
    iam_resource.create_role(
        AssumeRolePolicyDocument=json.dumps(assume_role_policy_document),
        RoleName='unittest-ocp-test-worker-role',
        Tags=tags)
    policy_output = iam_resource.create_policy(
        PolicyName='unittest-ocp-test-worker-policy',
        PolicyDocument=json.dumps(EC2_POLICY),
        Tags=tags)
    iam_resource.attach_role_policy(RoleName='unittest-ocp-test-worker-role',
                                    PolicyArn=policy_output['Policy']['Arn'])

    iam_resource.create_instance_profile(
        InstanceProfileName='unittest-ocp-test-worker-profile', Tags=tags)
    iam_resource.add_role_to_instance_profile(
        InstanceProfileName='unittest-ocp-test-worker-profile',
        RoleName='unittest-ocp-test-worker-role')

    zombie_cluster_resources = ZombieClusterResources(
        cluster_prefix='kubernetes.io/cluster/',
        delete=True,
        cluster_tag='kubernetes.io/cluster/unittest-test-cluster',
        resource_name='zombie_cluster_role')
    zombie_cluster_resources.zombie_cluster_role()
    iam_roles = Utils().get_details_resource_list(
        func_name=iam_resource.list_roles,
        input_tag='Roles',
        check_tag='Marker')
    find = False
    for role in iam_roles:
        if role['RoleName'] == 'unittest-ocp-test-worker-role':
            find = True
            break
    assert not find
 def __init__(self, region: str = 'us-east-2'):
     """
     Initializing the AWS resources
     """
     self.elb1_client = boto3.client('elb', region_name=region)
     self.elbv2_client = boto3.client('elbv2', region_name=region)
     self.ec2_client = boto3.client('ec2', region_name=region)
     self.get_full_list = Utils().get_details_resource_list
Beispiel #4
0
 def __init__(self, input_tags: dict, cluster_name: str = None, cluster_prefix: str = None,
              region: str = 'us-east-2'):
     self.ec2_client = boto3.client('ec2', region_name=region)
     self.elb_client = boto3.client('elb', region_name=region)
     self.elbv2_client = boto3.client('elbv2', region_name=region)
     self.iam_client = boto3.client('iam', region_name=region)
     self.iam_operations = IAMOperations()
     self.s3_client = boto3.client('s3')
     self.cluster_prefix = cluster_prefix
     self.cluster_name = cluster_name
     self.input_tags = input_tags
     self.__get_details_resource_list = Utils().get_details_resource_list
     self.__get_username_from_instance_id_and_time = CloudTrailOperations(
         region_name=region).get_username_by_instance_id_and_time
     self.ec2_operations = EC2Operations()
def test_delete_iam_cluster_user():
    """
    This method tests the user has successfully deleted or not
    :return:
    """
    iam_resource = boto3.client('iam')
    zombie_cluster_resources = ZombieClusterResources(
        cluster_prefix='kubernetes.io/cluster/',
        delete=True,
        cluster_tag=f'kubernetes.io/cluster/{USER_NAME}',
        resource_name='zombie_cluster_user')
    zombie_cluster_resources.zombie_cluster_user()
    iam_users = Utils().get_details_resource_list(
        func_name=iam_resource.list_users,
        input_tag='Users',
        check_tag='Marker')
    find = False
    for role in iam_users:
        if role['UserName'] == USER_NAME:
            find = True
            break
    assert not find
Beispiel #6
0
 def __init__(self, client: BaseClient, elb_client: BaseClient,
              elbv2_client: BaseClient):
     self.client = client
     self.elb_client = elb_client
     self.elbv2_client = elbv2_client
     self.get_detail_list = Utils().get_details_resource_list
 def __init__(self, file_name: str):
     self.iam_client = boto3.client('iam')
     self.get_detail_resource_list = Utils().get_details_resource_list
     self.IAMOperations = IAMOperations()
     self.file_name = file_name
 def __init__(self, remove_keys: list, username: str = ''):
     self.remove_keys = remove_keys
     self.username = username
     self.iam_client = boto3.client('iam')
     self.IAMOperations = IAMOperations()
     self.get_detail_resource_list = Utils().get_details_resource_list