Beispiel #1
0
    def test_find_usage_instances(self):
        iusage = {
            "us-east-1": {"t2.micro": 2, "r3.2xlarge": 10, "c4.4xlarge": 3},
            "fooaz": {"t2.micro": 32},
            "us-west-1": {"t2.micro": 5, "r3.2xlarge": 5, "c4.4xlarge": 2},
        }

        ri_count = {"us-east-1": {"t2.micro": 10, "r3.2xlarge": 2}, "us-west-1": {"t2.micro": 1, "r3.2xlarge": 5}}

        mock_t2_micro = Mock(spec_set=AwsLimit)
        mock_r3_2xlarge = Mock(spec_set=AwsLimit)
        mock_c4_4xlarge = Mock(spec_set=AwsLimit)
        mock_all_ec2 = Mock(spec_set=AwsLimit)
        limits = {
            "Running On-Demand t2.micro instances": mock_t2_micro,
            "Running On-Demand r3.2xlarge instances": mock_r3_2xlarge,
            "Running On-Demand c4.4xlarge instances": mock_c4_4xlarge,
            "Running On-Demand EC2 instances": mock_all_ec2,
        }

        cls = _Ec2Service(21, 43)
        mock_conn = Mock(spec_set=EC2Connection)
        cls.conn = mock_conn
        cls.limits = limits
        with patch("awslimitchecker.services.ec2._Ec2Service." "_instance_usage", autospec=True) as mock_inst_usage:
            with patch(
                "awslimitchecker.services.ec2._Ec2Service." "_get_reserved_instance_count", autospec=True
            ) as mock_res_inst_count:
                mock_inst_usage.return_value = iusage
                mock_res_inst_count.return_value = ri_count
                cls._find_usage_instances()
        assert mock_t2_micro.mock_calls == [call._add_current_usage(36, aws_type="AWS::EC2::Instance")]
        assert mock_r3_2xlarge.mock_calls == [call._add_current_usage(8, aws_type="AWS::EC2::Instance")]
        assert mock_c4_4xlarge.mock_calls == [call._add_current_usage(5, aws_type="AWS::EC2::Instance")]
        assert mock_all_ec2.mock_calls == [call._add_current_usage(49, aws_type="AWS::EC2::Instance")]
        assert mock_inst_usage.mock_calls == [call(cls)]
        assert mock_res_inst_count.mock_calls == [call(cls)]
Beispiel #2
0
    def test_find_usage_instances(self):
        iusage = {
            'us-east-1': {
                't2.micro': 2,
                'r3.2xlarge': 10,
                'c4.4xlarge': 3,
            },
            'fooaz': {
                't2.micro': 32,
            },
            'us-west-1': {
                't2.micro': 5,
                'r3.2xlarge': 5,
                'c4.4xlarge': 2,
            },
        }

        ri_count = {
            'us-east-1': {
                't2.micro': 10,
                'r3.2xlarge': 2,
            },
            'us-west-1': {
                't2.micro': 1,
                'r3.2xlarge': 5,
            },
        }

        mock_t2_micro = Mock(spec_set=AwsLimit)
        mock_r3_2xlarge = Mock(spec_set=AwsLimit)
        mock_c4_4xlarge = Mock(spec_set=AwsLimit)
        mock_all_ec2 = Mock(spec_set=AwsLimit)
        limits = {
            'Running On-Demand t2.micro instances': mock_t2_micro,
            'Running On-Demand r3.2xlarge instances': mock_r3_2xlarge,
            'Running On-Demand c4.4xlarge instances': mock_c4_4xlarge,
            'Running On-Demand EC2 instances': mock_all_ec2,
        }

        cls = _Ec2Service(21, 43)
        mock_conn = Mock(spec_set=EC2Connection)
        cls.conn = mock_conn
        cls.limits = limits
        with patch('awslimitchecker.services.ec2._Ec2Service.'
                   '_instance_usage', autospec=True) as mock_inst_usage:
            with patch('awslimitchecker.services.ec2._Ec2Service.'
                       '_get_reserved_instance_count',
                       autospec=True) as mock_res_inst_count:
                mock_inst_usage.return_value = iusage
                mock_res_inst_count.return_value = ri_count
                cls._find_usage_instances()
        assert mock_t2_micro.mock_calls == [call._add_current_usage(
            36,
            aws_type='AWS::EC2::Instance'
        )]
        assert mock_r3_2xlarge.mock_calls == [call._add_current_usage(
            8,
            aws_type='AWS::EC2::Instance'
        )]
        assert mock_c4_4xlarge.mock_calls == [call._add_current_usage(
            5,
            aws_type='AWS::EC2::Instance'
        )]
        assert mock_all_ec2.mock_calls == [call._add_current_usage(
            49,
            aws_type='AWS::EC2::Instance'
        )]
        assert mock_inst_usage.mock_calls == [call(cls)]
        assert mock_res_inst_count.mock_calls == [call(cls)]
        assert mock_conn.mock_calls == []
Beispiel #3
0
    def test_find_usage_instances(self):
        iusage = {
            'us-east-1': {
                't2.micro': 2,
                'r3.2xlarge': 10,
                'c4.4xlarge': 3,
            },
            'fooaz': {
                't2.micro': 32,
            },
            'us-west-1': {
                't2.micro': 5,
                'r3.2xlarge': 5,
                'c4.4xlarge': 2,
            },
        }

        ri_count = {
            'us-east-1': {
                't2.micro': 10,
                'r3.2xlarge': 2,
            },
            'us-west-1': {
                't2.micro': 1,
                'r3.2xlarge': 5,
            },
        }

        mock_t2_micro = Mock(spec_set=AwsLimit)
        mock_r3_2xlarge = Mock(spec_set=AwsLimit)
        mock_c4_4xlarge = Mock(spec_set=AwsLimit)
        mock_all_ec2 = Mock(spec_set=AwsLimit)
        limits = {
            'Running On-Demand t2.micro instances': mock_t2_micro,
            'Running On-Demand r3.2xlarge instances': mock_r3_2xlarge,
            'Running On-Demand c4.4xlarge instances': mock_c4_4xlarge,
            'Running On-Demand EC2 instances': mock_all_ec2,
        }

        cls = _Ec2Service(21, 43)
        mock_conn = Mock()
        cls.resource_conn = mock_conn
        cls.limits = limits
        with patch('%s._instance_usage' % self.pb,
                   autospec=True) as mock_inst_usage:
            with patch('%s._get_reserved_instance_count' % self.pb,
                       autospec=True) as mock_res_inst_count:
                mock_inst_usage.return_value = iusage
                mock_res_inst_count.return_value = ri_count
                cls._find_usage_instances()
        assert mock_t2_micro.mock_calls == [
            call._add_current_usage(36, aws_type='AWS::EC2::Instance')
        ]
        assert mock_r3_2xlarge.mock_calls == [
            call._add_current_usage(8, aws_type='AWS::EC2::Instance')
        ]
        assert mock_c4_4xlarge.mock_calls == [
            call._add_current_usage(5, aws_type='AWS::EC2::Instance')
        ]
        assert mock_all_ec2.mock_calls == [
            call._add_current_usage(49, aws_type='AWS::EC2::Instance')
        ]
        assert mock_inst_usage.mock_calls == [call(cls)]
        assert mock_res_inst_count.mock_calls == [call(cls)]
        assert mock_conn.mock_calls == []