Ejemplo n.º 1
0
 def test_get_assets_without_service(self):
     DCAssetFactory(
         service=None,
     )
     today = date(2013, 11, 12)
     result = [a for a in api_scrooge.get_assets(today)]
     self.assertEquals(result, [])
Ejemplo n.º 2
0
 def test_get_assets_without_environment(self):
     DCAssetFactory(
         service=None,
         device_environment=None,
     )
     today = date(2013, 11, 12)
     result = [a for a in api_scrooge.get_assets(today)]
     self.assertEquals(result, [])
Ejemplo n.º 3
0
 def test_get_asset_liquidated(self, logger_mock, is_liquidated_mock):
     is_liquidated_mock.return_value = True
     today = date(2013, 11, 12)
     date_before_today = date(2012, 1, 1)
     DCAssetFactory(invoice_date=date_before_today)
     result = [a for a in api_scrooge.get_assets(today)]
     self.assertEquals(result, [])
     self.assertTrue(logger_mock.info.called)
Ejemplo n.º 4
0
 def test_get_asset_without_hostname(self):
     asset = DCAssetFactory()
     asset.device_info.ralph_device_id = None
     asset.device_info.save()
     today = date(2013, 11, 12)
     result = [a for a in api_scrooge.get_assets(today)]
     self._compare_asset(
         asset,
         result[0],
         today,
         None,
     )
Ejemplo n.º 5
0
 def test_get_assets(self):
     asset = DCAssetFactory(
         invoice_date=date(2013, 10, 11),
     )
     today = date(2013, 11, 12)
     result = [a for a in api_scrooge.get_assets(today)]
     self._compare_asset(
         asset,
         result[0],
         today,
         asset.device_info.get_ralph_device().name
     )
Ejemplo n.º 6
0
 def test_get_asset_without_hostname(self):
     asset = DCAssetFactory(
         region=Region.get_default_region(),
         invoice_date=date(2013, 11, 11),
     )
     asset.device_info.ralph_device_id = None
     asset.device_info.save()
     today = date(2013, 11, 12)
     result = [a for a in api_scrooge.get_assets(today)]
     self._compare_asset(
         asset,
         result[0],
         today,
         None,
     )
Ejemplo n.º 7
0
 def test_get_assets_without_invoice(self):
     asset = DCAssetFactory(invoice_date=None, )
     today = date(2013, 11, 12)
     result = [a for a in api_scrooge.get_assets(today)]
     self._compare_asset(asset, result[0], today,
                         asset.device_info.get_ralph_device().name)
Ejemplo n.º 8
0
 def test_get_assets_without_device_info(self):
     DCAssetFactory(device_info=None, )
     today = date(2013, 11, 12)
     result = [a for a in api_scrooge.get_assets(today)]
     self.assertEquals(result, [])
Ejemplo n.º 9
0
def asset(**kwargs):
    """
    Updates assets and usages

    :returns tuple: Plugin status and statistics
    :rtype tuple:
    """
    date = kwargs['today']
    depreciation_usage = get_usage(
        'depreciation',
        'Depreciation',
        by_warehouse=False,
        by_cost=False,
        average=True,
        type='BU',
    )
    try:
        usage_price = UsagePrice.objects.get(type=depreciation_usage)
    except UsagePrice.DoesNotExist:
        usage_price = UsagePrice(type=depreciation_usage)
    usage_price.start = date.min
    usage_price.end = date.max
    usage_price.price = D('1')
    usage_price.forecast_price = D('1')
    usage_price.save()

    usages = {
        'depreciation':
        depreciation_usage,
        'assets_count':
        get_usage(
            'assets_count',
            'Assets Count',
            by_warehouse=False,
            by_cost=False,
            average=True,
            type='SU',
        ),
        'cores_count':
        get_usage(
            'physical_cpu_cores',
            'Physical CPU cores count',
            by_warehouse=False,
            by_cost=False,
            average=True,
            type='SU',
        ),
        'power_consumption':
        get_usage(
            'power_consumption',
            'Power consumption',
            by_warehouse=True,
            by_cost=True,
            average=False,
            type='BU',
        ),
        'collocation':
        get_usage(
            'collocation',
            'Collocation',
            by_warehouse=True,
            by_cost=True,
            average=True,
            type='BU',
        ),
    }

    new = update = total = 0
    for data in get_assets(date):
        total += 1
        try:
            if update_assets(data, date, usages):
                new += 1
            else:
                update += 1
        except ServiceEnvironmentDoesNotExistError:
            logger.error(
                'Asset {}: Service environment {} - {} does not exist'.format(
                    data['asset_id'],
                    data['service_id'],
                    data['environment_id'],
                ))
            continue
        except WarehouseDoesNotExistError:
            logger.error('Warehouse {0} does not exist'.format(
                data['warehouse_id']))
            continue

    return True, '{0} new, {1} updated, {2} total'.format(new, update, total)
Ejemplo n.º 10
0
def asset(**kwargs):
    """
    Updates assets and usages

    :returns tuple: Plugin status and statistics
    :rtype tuple:
    """
    date = kwargs['today']
    depreciation_usage = get_usage(
        'depreciation',
        'Depreciation',
        by_warehouse=False,
        by_cost=False,
        average=True,
        type='BU',
    )
    try:
        usage_price = UsagePrice.objects.get(
            type=depreciation_usage
        )
    except UsagePrice.DoesNotExist:
        usage_price = UsagePrice(type=depreciation_usage)
    usage_price.start = date.min
    usage_price.end = date.max
    usage_price.price = D('1')
    usage_price.forecast_price = D('1')
    usage_price.save()

    usages = {
        'depreciation': depreciation_usage,
        'assets_count': get_usage(
            'assets_count',
            'Assets Count',
            by_warehouse=False,
            by_cost=False,
            average=True,
            type='SU',
        ),
        'cores_count': get_usage(
            'physical_cpu_cores',
            'Physical CPU cores count',
            by_warehouse=False,
            by_cost=False,
            average=True,
            type='SU',
        ),
        'power_consumption': get_usage(
            'power_consumption',
            'Power consumption',
            by_warehouse=True,
            by_cost=True,
            average=False,
            type='BU',
        ),
        'collocation': get_usage(
            'collocation',
            'Collocation',
            by_warehouse=True,
            by_cost=True,
            average=True,
            type='BU',
        ),
    }

    new = update = total = 0
    for data in get_assets(date):
        total += 1
        try:
            if update_assets(data, date, usages):
                new += 1
            else:
                update += 1
        except ServiceEnvironmentDoesNotExistError:
            logger.error(
                'Asset {}: Service environment {} - {} does not exist'.format(
                    data['asset_id'],
                    data['service_id'],
                    data['environment_id'],
                )
            )
            continue
        except WarehouseDoesNotExistError:
            logger.error('Warehouse {0} does not exist'.format(
                data['warehouse_id']
            ))
            continue

    return True, '{0} new, {1} updated, {2} total'.format(new, update, total)