Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs #517

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Logs #517

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ settings_local.py
# Distribution / packaging
.Python
env/
venv/
build/
cover/
develop-eggs/
Expand Down
2 changes: 1 addition & 1 deletion drivers/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.3
2.4.7.1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def deploy(self, ec2_session, s3_session, name, reservation, aws_ec2_cp_resource
"""
ami_deployment_model = ami_deploy_action.actionParams.deployment.customModel
vpc = self.vpc_service.find_vpc_for_reservation(ec2_session=ec2_session,
reservation_id=reservation.reservation_id)
reservation_id=reservation.reservation_id, logger=logger)
if not vpc:
raise ValueError('VPC is not set for this reservation')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def cleanup(self, ec2_client, ec2_session, s3_session, aws_ec2_data_model, reser
try:
# need to remove the keypair before we try to find the VPC
self._remove_keypair(aws_ec2_data_model, ec2_session, logger, reservation_id, s3_session)
vpc = self.vpc_service.find_vpc_for_reservation(ec2_session, reservation_id)
vpc = self.vpc_service.find_vpc_for_reservation(ec2_session, reservation_id, logger)

if not vpc:
raise ValueError('No VPC was created for this reservation')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _prepare_network(self, ec2_client, ec2_session, reservation, aws_ec2_datamod
# will get or create a vpc for the reservation
self.cancellation_service.check_if_cancelled(cancellation_context)
logger.info("Get or create existing VPC (no subnets yet)")
vpc = self._get_or_create_vpc(cidr, ec2_session, reservation)
vpc = self._get_or_create_vpc(cidr, ec2_session, reservation, logger)

# will enable dns for the vpc
self.cancellation_service.check_if_cancelled(cancellation_context)
Expand Down Expand Up @@ -363,13 +363,15 @@ def _get_or_create_sandbox_isolated_security_group(self, ec2_session, management

return security_group

def _get_or_create_vpc(self, cidr, ec2_session, reservation):
def _get_or_create_vpc(self, cidr, ec2_session, reservation, logger):
vpc = self.vpc_service.find_vpc_for_reservation(ec2_session=ec2_session,
reservation_id=reservation.reservation_id)
reservation_id=reservation.reservation_id,
logger = logger)
if not vpc:
vpc = self.vpc_service.create_vpc_for_reservation(ec2_session=ec2_session,
reservation=reservation,
cidr=cidr)
cidr=cidr,
logger = logger)
return vpc
def _create_prepare_create_keys_result(self, action, access_key):
action_result = CreateKeysActionResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def execute(self, subnet_actions):
action_items = [PrepareSubnetExecutor.ActionItem(a) for a in subnet_actions]

# get vpc and availability_zone
vpc = self.vpc_service.find_vpc_for_reservation(ec2_session=self.ec2_session, reservation_id=self.reservation.reservation_id)
vpc = self.vpc_service.find_vpc_for_reservation(ec2_session=self.ec2_session, reservation_id=self.reservation.reservation_id, logger=self.logger)

if not vpc:
vpcs_count = self.vpc_service.get_active_vpcs_count(self.ec2_client, self.logger)
Expand Down
9 changes: 6 additions & 3 deletions package/cloudshell/cp/aws/domain/services/ec2/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, tag_service, subnet_service, instance_service, vpc_waiter, vp
self.route_table_service = route_table_service
self.traffic_mirror_service = traffic_mirror_service

def create_vpc_for_reservation(self, ec2_session, reservation, cidr):
def create_vpc_for_reservation(self, ec2_session, reservation, cidr, logger):
"""
Will create a vpc for reservation and will save it in a folder in the s3 bucket
:param ec2_session: Ec2 Session
Expand All @@ -51,6 +51,7 @@ def create_vpc_for_reservation(self, ec2_session, reservation, cidr):
:return: vpc
"""
vpc = ec2_session.create_vpc(CidrBlock=cidr)
logger.info("Created VPC for reservation {0}. Id is {1}".format(reservation.reservation_id, vpc.id))

self.vpc_waiter.wait(vpc=vpc, state=self.vpc_waiter.AVAILABLE)

Expand Down Expand Up @@ -104,18 +105,20 @@ def get_or_create_private_route_table(self, ec2_session, reservation, vpc_id):
route_table_name)
return route_table

def find_vpc_for_reservation(self, ec2_session, reservation_id):
def find_vpc_for_reservation(self, ec2_session, reservation_id, logger):
filters = [{'Name': 'tag:Name',
'Values': [self.VPC_RESERVATION.format(reservation_id)]}]

vpcs = list(ec2_session.vpcs.filter(Filters=filters))

if not vpcs:
logger.info("No VPC found for reservation {0}".format(reservation_id))
return None

if len(vpcs) > 1:
raise ValueError('Too many vpcs for the reservation')

logger.info("VPC found for reservation {0}. Id is {1}".format(reservation_id, vpcs[0].id))
return vpcs[0]

def peer_vpcs(self, ec2_session, vpc_id1, vpc_id2, reservation_model, logger):
Expand All @@ -133,7 +136,7 @@ def peer_vpcs(self, ec2_session, vpc_id1, vpc_id2, reservation_model, logger):
"""

# create peering connection
logger.info("Creating VPC Peering between {0} to {1} ".format(vpc_id1, vpc_id1))
logger.info("Creating VPC Peering between {0} to {1}".format(vpc_id1, vpc_id2))
vpc_peer_connection = ec2_session.create_vpc_peering_connection(VpcId=vpc_id1, PeerVpcId=vpc_id2)
logger.info(
"VPC Peering created {0} ,State : {1} ".format(vpc_peer_connection.id, vpc_peer_connection.status['Code']))
Expand Down
9 changes: 6 additions & 3 deletions package/tests/test_connectivity/test_prepare_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,16 @@ def test_get_or_create_vpc(self):

result = prepare_conn._get_or_create_vpc(cidr=cidr,
ec2_session=self.ec2_session,
reservation=self.reservation)
reservation=self.reservation,
logger=Mock())

vpc_service.find_vpc_for_reservation.assert_called_once_with(ec2_session=self.ec2_session,
reservation_id=self.reservation.reservation_id)
reservation_id=self.reservation.reservation_id,
logger=Mock())

vpc_service.create_vpc_for_reservation.assert_called_once_with(ec2_session=self.ec2_session,
reservation=self.reservation,
cidr=cidr)
cidr=cidr,
logger=Mock())

self.assertEqual(vpc, result)
8 changes: 4 additions & 4 deletions package/tests/test_domain_services/test_vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_create_and_attach_internet_gateway(self):
self.assertEqual(internet_gateway_id, internet_gate.id)

def test_create_vpc_for_reservation(self):
vpc = self.vpc_service.create_vpc_for_reservation(self.ec2_session, self.reservation, self.cidr)
vpc = self.vpc_service.create_vpc_for_reservation(self.ec2_session, self.reservation, self.cidr, self.logger)
vpc_name = self.vpc_service.VPC_RESERVATION.format(self.reservation.reservation_id)

self.vpc_waiter.wait.assert_called_once_with(vpc=vpc, state=self.vpc_waiter.AVAILABLE)
Expand All @@ -84,19 +84,19 @@ def test_create_vpc_for_reservation(self):
def test_find_vpc_for_reservation(self):
self.ec2_session.vpcs = Mock()
self.ec2_session.vpcs.filter = Mock(return_value=[self.vpc])
vpc = self.vpc_service.find_vpc_for_reservation(self.ec2_session, self.reservation)
vpc = self.vpc_service.find_vpc_for_reservation(self.ec2_session, self.reservation, self.logger)
self.assertEqual(vpc, self.vpc)

def test_find_vpc_for_reservation_no_vpc(self):
self.ec2_session.vpcs = Mock()
self.ec2_session.vpcs.filter = Mock(return_value=[])
vpc = self.vpc_service.find_vpc_for_reservation(self.ec2_session, self.reservation)
vpc = self.vpc_service.find_vpc_for_reservation(self.ec2_session, self.reservation, self.logger)
self.assertIsNone(vpc)

def test_find_vpc_for_reservation_too_many(self):
self.ec2_session.vpcs = Mock()
self.ec2_session.vpcs.filter = Mock(return_value=[1, 2])
self.assertRaises(ValueError, self.vpc_service.find_vpc_for_reservation, self.ec2_session, self.reservation)
self.assertRaises(ValueError, self.vpc_service.find_vpc_for_reservation, self.ec2_session, self.reservation, self.logger)

def test_peer_vpc(self):
def change_to_active(vpc_peering_connection):
Expand Down
2 changes: 1 addition & 1 deletion package/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.3
2.4.7.1
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.3
2.4.7.1