Example #1
0
    def test_get_default_tags(self):
        reservation_context = Mock()
        reservation_context.reservation_id = 'ReservationId'
        reservation_context.owner_user = '******'
        reservation_context.environment_name = 'Blueprint'
        reservation_context.domain = 'Global'

        reservation = ReservationModel(reservation_context)

        res = self.tag_service.get_default_tags(name='name',
                                                reservation=reservation)

        self.assertEqual(res, [{
            'Value': 'name',
            'Key': 'Name'
        }, {
            'Value': 'Cloudshell',
            'Key': 'CreatedBy'
        }, {
            'Value': 'Blueprint',
            'Key': 'Blueprint'
        }, {
            'Value': 'Owner',
            'Key': 'Owner'
        }, {
            'Value': 'Global',
            'Key': 'Domain'
        }, {
            'Value': 'ReservationId',
            'Key': 'ReservationId'
        }])
Example #2
0
    def test_get_security_group_tags(self):
        reservation_context = Mock()
        reservation_context.reservation_id = "ReservationId"
        reservation_context.owner_user = "******"
        reservation_context.environment_name = "Blueprint"
        reservation_context.domain = "Global"

        reservation = ReservationModel(reservation_context)

        res = self.tag_service.get_security_group_tags("name", "shared",
                                                       reservation,
                                                       "InboundPorts")
        self.assertEqual(
            res,
            [
                {
                    "Value": "name",
                    "Key": "Name"
                },
                {
                    "Value": "Cloudshell",
                    "Key": "CreatedBy"
                },
                {
                    "Value": "Blueprint",
                    "Key": "Blueprint"
                },
                {
                    "Value": "Owner",
                    "Key": "Owner"
                },
                {
                    "Value": "Global",
                    "Key": "Domain"
                },
                {
                    "Value": "ReservationId",
                    "Key": "ReservationId"
                },
                {
                    "Value": "shared",
                    "Key": "Isolation"
                },
                {
                    "Value": "InboundPorts",
                    "Key": "Type"
                },
            ],
        )
Example #3
0
 def _init_reservation_model():
     reservation_context = ReservationContextDetails(
         environment_name="",
         environment_path="",
         domain="Global",
         description="",
         owner_user="",
         owner_email="",
         reservation_id="77bf1176-25d2-4dd0-ac58-05f8aee534a5",
         saved_sandbox_name="",
         saved_sandbox_id="",
         running_user="",
     )
     reservation_model = ReservationModel(reservation_context)
     return reservation_model
Example #4
0
    def setUp(self):
        self.aws_shell = AWSShell()

        self.aws_shell.credentials_manager = Mock()
        self.aws_shell.ec2_storage_service = Mock()
        self.aws_shell.ec2_instance_waiter = Mock()
        self.aws_shell.cloudshell_session_helper = Mock()
        self.aws_shell.aws_session_manager.get_ec2_session = Mock(
            return_value=Mock())
        self.aws_shell.aws_session_manager.get_s3_session = Mock(
            return_value=Mock())
        self.aws_shell.aws_session_manager.get_ec2_client = Mock(
            return_value=Mock())

        self.command_context = Mock()
        self.command_context.resource = Mock()
        self.command_context.remote_endpoints = []

        self.command_context.connectivity = Mock()
        self.command_context.connectivity.server_address = Mock()
        self.command_context.connectivity.admin_auth_token = Mock()

        self.command_context.reservation = Mock()
        self.command_context.reservation.domain = Mock()

        self.command_context.remote_reservation = Mock()
        self.command_context.remote_reservation.domain = Mock()

        self.aws_shell.model_parser.convert_to_aws_resource_model = Mock(
            return_value=(AWSEc2CloudProviderResourceModel()))
        self.reservation_model = ReservationModel(
            self.command_context.reservation)
        self.aws_shell.model_parser.convert_to_reservation_model = Mock(
            return_value=self.reservation_model)

        self.expected_shell_context = Mock(spec=AwsShellContextModel)
        self.expected_shell_context.logger = Mock()
        self.expected_shell_context.cloudshell_session = Mock()
        self.expected_shell_context.aws_ec2_resource_model = Mock()
        self.expected_shell_context.aws_api = Mock()
        self.expected_shell_context.aws_api.ec2_session = Mock()
        self.expected_shell_context.aws_api.s3_session = Mock()
        self.expected_shell_context.aws_api.ec2_client = Mock()

        self.mock_context = Mock()
        self.mock_context.__enter__ = Mock(
            return_value=self.expected_shell_context)
        self.mock_context.__exit__ = Mock(return_value=False)
 def remote_restore_snapshot(self, context, snapshot_name):
     with AwsShellContext(
             context=context,
             aws_session_manager=self.aws_session_manager) as shell_context:
         shell_context.logger.info("Save Snapshot")
         resource = context.remote_endpoints[0]
         reservation = ReservationModel(context.remote_reservation)
         tags = self.tag_service.get_default_tags(snapshot_name,
                                                  reservation)
         data_holder = self.model_parser.convert_app_resource_to_deployed_app(
             resource)
         self.snapshot_operation.save_snapshot(
             ec2_client=shell_context.aws_api.ec2_client,
             ec2_session=shell_context.aws_api.ec2_session,
             instance_id=data_holder.vmdetails.uid,
             snapshot_name=snapshot_name,
             tags=tags,
         )
Example #6
0
    def test_get_default_tags(self):
        reservation_context = Mock()
        reservation_context.reservation_id = "ReservationId"
        reservation_context.owner_user = "******"
        reservation_context.environment_name = "Blueprint"
        reservation_context.domain = "Global"

        reservation = ReservationModel(reservation_context)

        res = self.tag_service.get_default_tags(name="name",
                                                reservation=reservation)

        self.assertEqual(
            res,
            [
                {
                    "Value": "name",
                    "Key": "Name"
                },
                {
                    "Value": "Cloudshell",
                    "Key": "CreatedBy"
                },
                {
                    "Value": "Blueprint",
                    "Key": "Blueprint"
                },
                {
                    "Value": "Owner",
                    "Key": "Owner"
                },
                {
                    "Value": "Global",
                    "Key": "Domain"
                },
                {
                    "Value": "ReservationId",
                    "Key": "ReservationId"
                },
            ],
        )
Example #7
0
    def test_get_security_group_tags(self):
        reservation_context = Mock()
        reservation_context.reservation_id = 'ReservationId'
        reservation_context.owner_user = '******'
        reservation_context.environment_name = 'Blueprint'
        reservation_context.domain = 'Global'

        reservation = ReservationModel(reservation_context)

        res = self.tag_service.get_security_group_tags('name', 'shared',
                                                       reservation,
                                                       'InboundPorts')
        self.assertEqual(res, [{
            'Value': 'name',
            'Key': 'Name'
        }, {
            'Value': 'Cloudshell',
            'Key': 'CreatedBy'
        }, {
            'Value': 'Blueprint',
            'Key': 'Blueprint'
        }, {
            'Value': 'Owner',
            'Key': 'Owner'
        }, {
            'Value': 'Global',
            'Key': 'Domain'
        }, {
            'Value': 'ReservationId',
            'Key': 'ReservationId'
        }, {
            'Value': 'shared',
            'Key': 'Isolation'
        }, {
            'Value': 'InboundPorts',
            'Key': 'Type'
        }])
 def convert_to_reservation_model(reservation_context):
     """# noqa
     :param ReservationContextDetails reservation_context:
     :rtype: ReservationModel
     """
     return ReservationModel(reservation_context)
 def _init_reservation_model():
     reservation_context = ReservationContextDetails()
     reservation_model = ReservationModel(reservation_context)
     reservation_model.reservation_id = "77bf1176-25d2-4dd0-ac58-05f8aee534a5"
     return reservation_model
Example #10
0
    def test_valid_create_returns_success_actions(self):
        tag_service = TagService(Mock())
        session_number_service = SessionNumberService()
        traffic_mirror_service = TrafficMirrorService()
        cancellation_service = CommandCancellationService()
        reservation_context = Mock()
        reservation_context.reservation_id = str(uuid4())
        reservation = ReservationModel(reservation_context)
        reservation.blueprint = "lalala"
        reservation.owner = "admin"
        reservation.domain = "global"
        describe_mirror_targets_result = {
            "TrafficMirrorTargets": [{
                "NetworkInterfaceId": "bbbb",
                "TrafficMirrorTargetId": "cccc"
            }]
        }

        create_traffic_mirror_target_result = {
            "TrafficMirrorTarget": {
                "TrafficMirrorTargetId": "tmt-5050"
            }
        }

        create_filter_result = {
            "TrafficMirrorFilter": {
                "TrafficMirrorFilterId": "tmf-5050"
            }
        }

        create_traffic_mirror_session_result = {
            "TrafficMirrorSession": {
                "TrafficMirrorSessionId": "tms-5050"
            }
        }

        ec2_client = Mock()
        ec2_client.describe_traffic_mirror_targets = Mock(
            return_value=describe_mirror_targets_result)
        ec2_client.create_traffic_mirror_target = Mock(
            return_value=create_traffic_mirror_target_result)
        ec2_client.create_traffic_mirror_filter = Mock(
            return_value=create_filter_result)
        ec2_client.create_traffic_mirror_session = Mock(
            return_value=create_traffic_mirror_session_result)

        cancellation_context = Mock()
        cancellation_context.is_cancelled = False
        logger = Mock()
        cloudshell = Mock()
        checkout_result = Mock()
        checkout_result.Items = [5]
        cloudshell.CheckoutFromPool = Mock(return_value=checkout_result)

        action = CreateTrafficMirroring()
        action.actionId = str(uuid4())
        action.actionParams = CreateTrafficMirroringParams()
        action.actionParams.sessionNumber = "5"
        action.actionParams.sourceNicId = "a"
        action.actionParams.targetNicId = "b"
        actions = [action]

        op = TrafficMirrorOperation(
            tag_service,
            session_number_service,
            traffic_mirror_service,
            cancellation_service,
        )

        results = op.create(
            ec2_client=ec2_client,
            reservation=reservation,
            actions=actions,
            cancellation_context=cancellation_context,
            logger=logger,
            cloudshell=cloudshell,
        )

        self.assertTrue([x for x in results if x.success])
 def _init_reservation_model():
     reservation_context = ReservationContextDetails()
     reservation_model = ReservationModel(reservation_context)
     reservation_model.reservation_id = "77bf1176-25d2-4dd0-ac58-05f8aee534a5"
     return reservation_model