def setUp(self):
        self.aws_shell_api = AWSShell()

        self.aws_shell_api.credentials_manager = Mock()
        self.aws_shell_api.ec2_instance_waiter = Mock()
        self.aws_shell_api.cloudshell_session_helper = Mock()
        self.aws_shell_api.aws_session_manager.get_ec2_session = 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_api.model_parser.convert_to_aws_resource_model = Mock(
            return_value=(AWSEc2CloudProviderResourceModel()))
Exemple #2
0
    def convert_to_aws_resource_model(resource):
        """
        :rtype AWSEc2CloudProviderResourceModel:
        """
        resource_context = resource.attributes
        aws_ec2_resource_model = AWSEc2CloudProviderResourceModel()
        aws_ec2_resource_model.region = resource_context['Region']
        aws_ec2_resource_model.max_storage_iops = resource_context[
            'Max Storage IOPS']
        aws_ec2_resource_model.max_storage_size = resource_context[
            'Max Storage Size']
        aws_ec2_resource_model.aws_secret_access_key = resource_context[
            'AWS Secret Access Key']
        aws_ec2_resource_model.aws_access_key_id = resource_context[
            'AWS Access Key ID']
        aws_ec2_resource_model.key_pairs_location = resource_context[
            'Keypairs Location']
        aws_ec2_resource_model.aws_management_vpc_id = resource_context[
            'AWS Mgmt VPC ID']
        aws_ec2_resource_model.aws_management_sg_id = resource_context[
            'AWS Mgmt SG ID']
        aws_ec2_resource_model.instance_type = resource_context[
            'Instance Type']
        # aws_ec2_resource_model.reserved_ips_in_subnet = resource_context['Reserved IPs in Subnet']

        return aws_ec2_resource_model
    def test_deploying_ami_returns_deploy_result(self):
        # arrange
        deploymock = DeployAWSEc2AMIInstanceResourceModel()
        deploymock.auto_power_off = "True"
        deploymock.wait_for_ip = "True"
        deploymock.auto_delete = "True"
        deploymock.autoload = "True"
        deploymock.cloud_provider = "some_name"
        deploymock.app_name = 'my instance name'
        cancellation_context = Mock()

        result = DeployResult(vm_name=deploymock.app_name,
                              vm_uuid='my instance id',
                              cloud_provider_resource_name=deploymock.cloud_provider,
                              autoload=deploymock.autoload,
                              auto_delete=deploymock.auto_delete,
                              wait_for_ip=deploymock.wait_for_ip,
                              auto_power_off=deploymock.auto_power_off,
                              inbound_ports='',
                              deployed_app_attributes=dict(),
                              deployed_app_address='',
                              public_ip='',
                              network_configuration_results=[],
                              vm_details_data=dict())

        self.aws_shell.model_parser.convert_to_deployment_resource_model = Mock(return_value=deploymock)
        self.aws_shell.deploy_ami_operation.deploy = Mock(return_value=result)
        aws_cloud_provider = AWSEc2CloudProviderResourceModel()

        res = None
        with patch('cloudshell.cp.aws.aws_shell.AwsShellContext') as shell_context:
            shell_context.return_value = self.mock_context

            # act
            res = self.aws_shell.deploy_ami(self.command_context, aws_cloud_provider, cancellation_context)

        decoded_res = jsonpickle.decode(res)
        self.assertEqual(decoded_res['vm_name'], deploymock.app_name)
        self.assertEqual(decoded_res['vm_uuid'], result.vm_uuid)
        self.assertEqual(decoded_res['auto_power_off'], deploymock.auto_power_off)
        self.assertEqual(decoded_res['wait_for_ip'], deploymock.wait_for_ip)
        self.assertEqual(decoded_res['auto_delete'], deploymock.auto_delete)
        self.assertEqual(decoded_res['autoload'], deploymock.autoload)
        self.assertEqual(decoded_res['cloud_provider_resource_name'], deploymock.cloud_provider)
        self.aws_shell.deploy_ami_operation.deploy.assert_called_with(
                ec2_session=self.expected_shell_context.aws_api.ec2_session,
                s3_session=self.expected_shell_context.aws_api.s3_session,
                name=deploymock.app_name,
                reservation=self.reservation_model,
                aws_ec2_cp_resource_model=self.expected_shell_context.aws_ec2_resource_model,
                ami_deployment_model=deploymock,
                ec2_client=self.expected_shell_context.aws_api.ec2_client,
                cancellation_context=cancellation_context,
                logger=self.expected_shell_context.logger)
Exemple #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 test_deploying_ami_returns_deploy_result(self):
        name = 'my instance name'
        result = Mock()
        result.instance_id = 'my instance id'

        deploymock = DeployAWSEc2AMIInstanceResourceModel()
        deploymock.auto_power_on = "True"
        deploymock.auto_power_off = "True"
        deploymock.wait_for_ip = "True"
        deploymock.auto_delete = "True"
        deploymock.autoload = "True"
        deploymock.aws_ec2 = "some_name"

        self.aws_shell_api.model_parser.convert_to_deployment_resource_model = Mock(
            return_value=(deploymock, name))

        self.aws_shell_api.deploy_ami_operation.deploy = Mock(
            return_value=(result, name))

        aws_cloud_provider = AWSEc2CloudProviderResourceModel()

        res = self.aws_shell_api.deploy_ami(self.command_context,
                                            aws_cloud_provider)

        self.assertEqual(jsonpickle.decode(res)['vm_name'], name)
        self.assertEqual(jsonpickle.decode(res)['vm_uuid'], result.instance_id)
        self.assertEqual(
            jsonpickle.decode(res)['auto_power_on'], deploymock.auto_power_on)
        self.assertEqual(
            jsonpickle.decode(res)['auto_power_off'],
            deploymock.auto_power_off)
        self.assertEqual(
            jsonpickle.decode(res)['wait_for_ip'], deploymock.wait_for_ip)
        self.assertEqual(
            jsonpickle.decode(res)['auto_delete'], deploymock.auto_delete)
        self.assertEqual(
            jsonpickle.decode(res)['autoload'], deploymock.autoload)
        self.assertEqual(
            jsonpickle.decode(res)['cloud_provider_resource_name'],
            deploymock.aws_ec2)
Exemple #6
0
 def convert_to_aws_resource_model(resource):
     resource_context = resource.attributes
     aws_ec2_resource_model = AWSEc2CloudProviderResourceModel()
     aws_ec2_resource_model.default_storage_size = resource_context[
         'Default Storage Size']
     aws_ec2_resource_model.default_storage_iops = resource_context[
         'Default Storage IOPS']
     aws_ec2_resource_model.region = AWSModelsParser.convert_region(
         resource_context['Region'])
     aws_ec2_resource_model.device_name = resource_context['Device Name']
     aws_ec2_resource_model.max_storage_iops = resource_context[
         'Max Storage IOPS']
     aws_ec2_resource_model.max_storage_size = resource_context[
         'Max Storage Size']
     aws_ec2_resource_model.vpc = resource_context['VPC']
     aws_ec2_resource_model.aws_secret_access_key = resource_context[
         'AWS Secret Access Key']
     aws_ec2_resource_model.aws_access_key_id = resource_context[
         'AWS Access Key ID']
     aws_ec2_resource_model.default_instance_type = resource_context[
         'Default Instance Type']
     aws_ec2_resource_model.subnet = resource_context['Subnet']
     return aws_ec2_resource_model
 def convert_to_aws_resource_model(
         resource) -> AWSEc2CloudProviderResourceModel:
     return AWSEc2CloudProviderResourceModel.from_resource(resource)