Beispiel #1
0
 def test_network(self):
     ServiceEnvironmentFactory.create(service__ci_uid=1,
                                      environment__name='env1')
     self.assertEqual(
         netflow.netflow(today=date(year=2014, month=1, day=1))[1],
         '1 new, 0 updated, 1 total',
     )
     self.assertEqual(DailyUsage.objects.get().value, 30)
Beispiel #2
0
 def test_network(self):
     ServiceEnvironmentFactory.create(
         service__ci_uid=1,
         environment__name='env1'
     )
     self.assertEqual(
         netflow.netflow(today=date(year=2014, month=1, day=1))[1],
         '1 new, 0 updated, 1 total',
     )
     self.assertEqual(DailyUsage.objects.get().value, 30)
Beispiel #3
0
 def test_update_virtual_virtual_info_with_hypervisor(self):
     service_env = ServiceEnvironmentFactory.create()
     hypervisor = DailyAssetInfoFactory(date=self.today)
     data = AttributeDict(
         device_id=1,
         name='sample',
         service_id=service_env.service.ci_id,
         environment_id=service_env.environment.ci_id,
         model_id=1,
         hypervisor_id=hypervisor.asset_info.device_id,
         model_name='sample model',
     )
     daily_virtual_info = virtual.update_virtual_info(
         'virtual_group',
         data,
         self.today,
         service_env,
     )
     self._compare_daily_virtual_info(
         daily_virtual_info,
         data,
         service_env,
         'virtual_group',
     )
     self.assertEqual(
         hypervisor.asset_info.device_id,
         daily_virtual_info.hypervisor.asset_info.device_id
     )
Beispiel #4
0
 def test_update_virtual_virtual_info_with_hypervisor(self):
     service_env = ServiceEnvironmentFactory.create()
     hypervisor = DailyAssetInfoFactory(date=self.today)
     data = AttributeDict(
         device_id=1,
         name='sample',
         service_id=service_env.service.ci_id,
         environment_id=service_env.environment.ci_id,
         model_id=1,
         hypervisor_id=hypervisor.asset_info.device_id,
         model_name='sample model',
     )
     daily_virtual_info = virtual.update_virtual_info(
         'virtual_group',
         data,
         self.today,
         service_env,
     )
     self._compare_daily_virtual_info(
         daily_virtual_info,
         data,
         service_env,
         'virtual_group',
     )
     self.assertEqual(hypervisor.asset_info.device_id,
                      daily_virtual_info.hypervisor.asset_info.device_id)
Beispiel #5
0
 def test_virtual(self):
     service_environment = ServiceEnvironmentFactory.create()
     asset_info = AssetInfoFactory.create(device_id=1)
     DailyAssetInfoFactory.create(asset_info=asset_info, date=self.today)
     virtual.ServiceEnvironment.objects.get = (
         lambda *args, **kwargs: service_environment)
     self.assertEqual(
         virtual.virtual(today=self.today),
         (True, 'Virtual: None new, 1 updated, 1 total'),
     )
Beispiel #6
0
 def test_virtual(self):
     service_environment = ServiceEnvironmentFactory.create()
     asset_info = AssetInfoFactory.create(device_id=1)
     DailyAssetInfoFactory.create(asset_info=asset_info, date=self.today)
     virtual.ServiceEnvironment.objects.get = (
         lambda *args, **kwargs: service_environment
     )
     self.assertEqual(
         virtual.virtual(today=self.today),
         (True, 'Virtual: None new, 1 updated, 1 total'),
     )
Beispiel #7
0
 def test_update(self):
     service_environment = ServiceEnvironmentFactory.create()
     virtual.update(
         'virtual_group',
         AttributeDict(
             device_id=1,
             service_id=service_environment.service.ci_id,
             environment_id=service_environment.environment.ci_id,
             model_id=1,
             model_name='sample model',
         ),
         {'key': 'value', 'key2': 'value2'},
         self.today,
     )
     self.assertEqual(virtual.update_virtual_usage.call_count, 2)
     self.assertEqual(virtual.update_virtual_info.call_count, 1)
Beispiel #8
0
 def test_update_virtual_usage(self):
     service_env = ServiceEnvironmentFactory.create()
     daily_virtual_info = DailyVirtualInfoFactory()
     usage_type = UsageTypeFactory.create()
     daily_usage = virtual.update_virtual_usage(
         daily_virtual_info,
         service_env,
         usage_type,
         self.today,
         100,
     )
     self.assertEqual(models.VirtualInfo.objects.all().count(), 1)
     self.assertEqual(daily_usage.service_environment, service_env)
     self.assertEqual(daily_usage.type, usage_type)
     self.assertEqual(daily_usage.date, self.today)
     self.assertEqual(daily_usage.value, 100)
     self.assertEqual(daily_usage.daily_pricing_object, daily_virtual_info)
Beispiel #9
0
 def test_update_virtual_usage(self):
     service_env = ServiceEnvironmentFactory.create()
     daily_virtual_info = DailyVirtualInfoFactory()
     usage_type = UsageTypeFactory.create()
     daily_usage = virtual.update_virtual_usage(
         daily_virtual_info,
         service_env,
         usage_type,
         self.today,
         100,
     )
     self.assertEqual(models.VirtualInfo.objects.all().count(), 1)
     self.assertEqual(daily_usage.service_environment, service_env)
     self.assertEqual(daily_usage.type, usage_type)
     self.assertEqual(daily_usage.date, self.today)
     self.assertEqual(daily_usage.value, 100)
     self.assertEqual(daily_usage.daily_pricing_object, daily_virtual_info)
Beispiel #10
0
 def test_update(self):
     service_environment = ServiceEnvironmentFactory.create()
     virtual.update(
         'virtual_group',
         AttributeDict(
             device_id=1,
             service_id=service_environment.service.ci_id,
             environment_id=service_environment.environment.ci_id,
             model_id=1,
             model_name='sample model',
         ),
         {
             'key': 'value',
             'key2': 'value2'
         },
         self.today,
     )
     self.assertEqual(virtual.update_virtual_usage.call_count, 2)
     self.assertEqual(virtual.update_virtual_info.call_count, 1)
Beispiel #11
0
 def test_update_virtual_virtual_info(self):
     service_env = ServiceEnvironmentFactory.create()
     data = AttributeDict(
         device_id=1,
         name='sample',
         service_id=service_env.service.ci_id,
         environment_id=service_env.environment.ci_id,
         model_id=1,
         model_name='sample model',
     )
     daily_virtual_info = virtual.update_virtual_info(
         'virtual_group',
         data,
         self.today,
         service_env,
     )
     self._compare_daily_virtual_info(
         daily_virtual_info,
         data,
         service_env,
         'virtual_group',
     )
     self.assertIsNone(daily_virtual_info.hypervisor)
Beispiel #12
0
 def test_update_virtual_virtual_info(self):
     service_env = ServiceEnvironmentFactory.create()
     data = AttributeDict(
         device_id=1,
         name='sample',
         service_id=service_env.service.ci_id,
         environment_id=service_env.environment.ci_id,
         model_id=1,
         model_name='sample model',
     )
     daily_virtual_info = virtual.update_virtual_info(
         'virtual_group',
         data,
         self.today,
         service_env,
     )
     self._compare_daily_virtual_info(
         daily_virtual_info,
         data,
         service_env,
         'virtual_group',
     )
     self.assertIsNone(daily_virtual_info.hypervisor)
    def setUp(self):
        self.maxDiff = None
        self.today = date(2013, 10, 10)
        self.start = date(2013, 10, 1)
        self.end = date(2013, 10, 30)

        # TODO: unify with usages generator

        # base usages
        self.base_usage_type = UsageTypeFactory(
            usage_type='BU',
            by_cost=True,
        )

        # regular usage
        self.regular_usage_type = UsageTypeFactory(
            usage_type='RU',
            by_cost=False,
        )

        # team
        self.team = TeamFactory()

        # extra cost
        self.extra_cost_type = ExtraCostTypeFactory()

        # pricing services
        self.pricing_service1 = PricingServiceFactory()
        self.pricing_service1.regular_usage_types.add(self.regular_usage_type)
        self.pricing_service1.save()

        # NOTICE THAT PRICING SERVICE 2 IS NOT CHARGED FOR REGULAR USAGE
        self.pricing_service2 = PricingServiceFactory()

        # services
        self.service_environments = ServiceEnvironmentFactory.create_batch(
            2,
            service__pricing_service=self.pricing_service1,
        )
        self.service_environments.append(
            ServiceEnvironmentFactory.create(
                service__pricing_service=self.pricing_service2, ))
        self.service_environments.extend(
            ServiceEnvironmentFactory.create_batch(3))

        # pricing service usages
        self.service_usage_types = UsageTypeFactory.create_batch(
            3,
            usage_type='SU',
        )
        models.ServiceUsageTypes.objects.create(
            usage_type=self.service_usage_types[0],
            pricing_service=self.pricing_service1,
            start=self.start,
            end=self.end,
            percent=30,
        )
        models.ServiceUsageTypes.objects.create(
            usage_type=self.service_usage_types[1],
            pricing_service=self.pricing_service1,
            start=self.start,
            end=self.end,
            percent=70,
        )
        models.ServiceUsageTypes.objects.create(
            usage_type=self.service_usage_types[2],
            pricing_service=self.pricing_service2,
            start=self.start,
            end=self.end,
            percent=100,
        )

        # daily pricing objects
        # in pricing service 1 (& use pricing service 2)
        self.se1_dpo = DailyPricingObjectFactory.create_batch(
            2, service_environment=self.service_environments[0])
        self.se2_dpo = DailyPricingObjectFactory.create_batch(
            2, service_environment=self.service_environments[1])
        # in pricing service 2
        self.se3_dpo = DailyPricingObjectFactory.create_batch(
            2, service_environment=self.service_environments[2])
        # use pricing service 1
        self.se4_dpo = DailyPricingObjectFactory.create_batch(
            2, service_environment=self.service_environments[3])
        self.se5_dpo = DailyPricingObjectFactory.create_batch(
            2, service_environment=self.service_environments[4])
        # use pricing service 2 (besides se1_dpo and se2_dpo)
        self.se6_dpo = DailyPricingObjectFactory.create_batch(
            2, service_environment=self.service_environments[5])
        # other
        self.se7_dpo = DailyPricingObjectFactory.create_batch(
            2, service_environment=self.service_environments[5])

        # SO FAR SUMMARY:
        # there are 2 pricing services:
        # pricing service 1: collect costs from 2 services (4 pricing objects:
        # se1_dpo and se2_dpo); is distributed according to usages of 2 service
        # usage types: sut[0] (30%) and sut[1] (70%)
        # pricing service 2: collect costs from 1 service (2 pricing objects:
        # se3_dpo); is distributed according to usages of 1 service usage type
        # (sut[2] -  100%)
        # there are also another 2 service environments (each has 2 pricing
        # objects)
        # TOTAL DAILY PRICING OBJECTS: 14

        # USAGES
        # base usage type
        models.UsagePrice(
            type=self.base_usage_type,
            # cost per unit: 1, daily cost (usages are the same for each date):
            # 140, cost per daily pricing object: 10
            cost=4200,
            forecast_cost=8400,  # cost per unit: 2
            start=self.start,
            end=self.end,
        ).save()
        # regular usage type
        models.UsagePrice(
            type=self.regular_usage_type,
            price=10,
            forecast_price=20,
            start=self.start,
            end=self.end,
        ).save()
        days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end)
        for day in days:
            # TODO: fix assigning DPO with wrong date to DailyUsage
            for dpo in models.DailyPricingObject.objects.all():
                DailyUsageFactory(
                    date=day,
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=10,
                    type=self.base_usage_type,
                )
                DailyUsageFactory(
                    date=day,
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=5,
                    type=self.regular_usage_type,
                )

        # team
        team_cost = models.TeamCost(
            team=self.team,
            cost=300,  # daily cost: 10
            forecast_cost=600,  # daily cost: 20
            start=self.start,
            end=self.end,
        )
        team_cost.save()
        for se in self.service_environments[:5]:
            models.TeamServiceEnvironmentPercent(
                team_cost=team_cost,
                service_environment=se,
                percent=20,  # 2 per day per se
            ).save()

        # extra cost
        for se in self.service_environments[:5]:
            models.ExtraCost(
                extra_cost_type=self.extra_cost_type,
                start=self.start,
                end=self.end,
                service_environment=se,
                cost=3000,  # daily cost: 100
                forecast_cost=6000,  # daily cost: 200
            ).save()

        # pricing service 1 service usage types usages
        for dpo, multiplier in zip(self.se4_dpo + self.se5_dpo, [1, 1, 3, 3]):
            days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end)
            for day in days:
                DailyUsageFactory(
                    type=self.service_usage_types[0],
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=10 * multiplier,
                    date=day,
                )
                DailyUsageFactory(
                    type=self.service_usage_types[1],
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=50 * multiplier,
                    date=day,
                )

        # pricing service 2 service usage types usages
        for dpo in self.se1_dpo + self.se6_dpo:
            days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end)
            for day in days:
                DailyUsageFactory(
                    type=self.service_usage_types[2],
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=100,
                    date=day,
                )
    def setUp(self):
        self.maxDiff = None
        self.today = date(2013, 10, 10)
        self.start = date(2013, 10, 1)
        self.end = date(2013, 10, 30)

        # TODO: unify with usages generator

        # base usages
        self.base_usage_type = UsageTypeFactory(
            usage_type='BU',
            by_cost=True,
        )

        # regular usage
        self.regular_usage_type = UsageTypeFactory(
            usage_type='RU',
            by_cost=False,
        )

        # team
        self.team = TeamFactory()

        # extra cost
        self.extra_cost_type = ExtraCostTypeFactory()

        # pricing services
        self.pricing_service1 = PricingServiceFactory()
        self.pricing_service1.regular_usage_types.add(self.regular_usage_type)
        self.pricing_service1.save()

        # NOTICE THAT PRICING SERVICE 2 IS NOT CHARGED FOR REGULAR USAGE
        self.pricing_service2 = PricingServiceFactory()

        # services
        self.service_environments = ServiceEnvironmentFactory.create_batch(
            2,
            service__pricing_service=self.pricing_service1,
        )
        self.service_environments.append(ServiceEnvironmentFactory.create(
            service__pricing_service=self.pricing_service2,
        ))
        self.service_environments.extend(
            ServiceEnvironmentFactory.create_batch(3)
        )

        # pricing service usages
        self.service_usage_types = UsageTypeFactory.create_batch(
            3,
            usage_type='SU',
        )
        models.ServiceUsageTypes.objects.create(
            usage_type=self.service_usage_types[0],
            pricing_service=self.pricing_service1,
            start=self.start,
            end=self.end,
            percent=30,
        )
        models.ServiceUsageTypes.objects.create(
            usage_type=self.service_usage_types[1],
            pricing_service=self.pricing_service1,
            start=self.start,
            end=self.end,
            percent=70,
        )
        models.ServiceUsageTypes.objects.create(
            usage_type=self.service_usage_types[2],
            pricing_service=self.pricing_service2,
            start=self.start,
            end=self.end,
            percent=100,
        )

        # daily pricing objects
        # in pricing service 1 (& use pricing service 2)
        self.se1_dpo = DailyPricingObjectFactory.create_batch(
            2,
            service_environment=self.service_environments[0]
        )
        self.se2_dpo = DailyPricingObjectFactory.create_batch(
            2,
            service_environment=self.service_environments[1]
        )
        # in pricing service 2
        self.se3_dpo = DailyPricingObjectFactory.create_batch(
            2,
            service_environment=self.service_environments[2]
        )
        # use pricing service 1
        self.se4_dpo = DailyPricingObjectFactory.create_batch(
            2,
            service_environment=self.service_environments[3]
        )
        self.se5_dpo = DailyPricingObjectFactory.create_batch(
            2,
            service_environment=self.service_environments[4]
        )
        # use pricing service 2 (besides se1_dpo and se2_dpo)
        self.se6_dpo = DailyPricingObjectFactory.create_batch(
            2,
            service_environment=self.service_environments[5]
        )
        # other
        self.se7_dpo = DailyPricingObjectFactory.create_batch(
            2,
            service_environment=self.service_environments[5]
        )

        # SO FAR SUMMARY:
        # there are 2 pricing services:
        # pricing service 1: collect costs from 2 services (4 pricing objects:
        # se1_dpo and se2_dpo); is distributed according to usages of 2 service
        # usage types: sut[0] (30%) and sut[1] (70%)
        # pricing service 2: collect costs from 1 service (2 pricing objects:
        # se3_dpo); is distributed according to usages of 1 service usage type
        # (sut[2] -  100%)
        # there are also another 2 service environments (each has 2 pricing
        # objects)
        # TOTAL DAILY PRICING OBJECTS: 14

        # USAGES
        # base usage type
        models.UsagePrice(
            type=self.base_usage_type,
            # cost per unit: 1, daily cost (usages are the same for each date):
            # 140, cost per daily pricing object: 10
            cost=4200,
            forecast_cost=8400,  # cost per unit: 2
            start=self.start,
            end=self.end,
        ).save()
        # regular usage type
        models.UsagePrice(
            type=self.regular_usage_type,
            price=10,
            forecast_price=20,
            start=self.start,
            end=self.end,
        ).save()
        days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end)
        for day in days:
            # TODO: fix assigning DPO with wrong date to DailyUsage
            for dpo in models.DailyPricingObject.objects.all():
                DailyUsageFactory(
                    date=day,
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=10,
                    type=self.base_usage_type,
                )
                DailyUsageFactory(
                    date=day,
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=5,
                    type=self.regular_usage_type,
                )

        # team
        team_cost = models.TeamCost(
            team=self.team,
            cost=300,  # daily cost: 10
            forecast_cost=600,  # daily cost: 20
            start=self.start,
            end=self.end,
        )
        team_cost.save()
        for se in self.service_environments[:5]:
            models.TeamServiceEnvironmentPercent(
                team_cost=team_cost,
                service_environment=se,
                percent=20,  # 2 per day per se
            ).save()

        # extra cost
        for se in self.service_environments[:5]:
            models.ExtraCost(
                extra_cost_type=self.extra_cost_type,
                start=self.start,
                end=self.end,
                service_environment=se,
                cost=3000,  # daily cost: 100
                forecast_cost=6000,  # daily cost: 200
            ).save()

        # pricing service 1 service usage types usages
        for dpo, multiplier in zip(self.se4_dpo + self.se5_dpo, [1, 1, 3, 3]):
            days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end)
            for day in days:
                DailyUsageFactory(
                    type=self.service_usage_types[0],
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=10 * multiplier,
                    date=day,
                )
                DailyUsageFactory(
                    type=self.service_usage_types[1],
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=50 * multiplier,
                    date=day,
                )

        # pricing service 2 service usage types usages
        for dpo in self.se1_dpo + self.se6_dpo:
            days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end)
            for day in days:
                DailyUsageFactory(
                    type=self.service_usage_types[2],
                    daily_pricing_object=dpo,
                    service_environment=dpo.service_environment,
                    value=100,
                    date=day,
                )