Exemple #1
0
    def setUp(self):
        self.fixture = structure_fixtures.CustomerFixture()
        self.offering = marketplace_factories.OfferingFactory(
            customer=self.fixture.customer, type=PLUGIN_NAME)
        self.schedules = [
            {
                'start': '2020-02-12T02:00:00+03:00',
                'end': '2020-02-15T02:00:00+03:00',
                'id': '123',
            },
            {
                'start': '2020-03-01T02:00:00+03:00',
                'end': '2020-03-05T02:00:00+03:00',
                'id': '456',
            },
        ]

        self.resource_1 = marketplace_factories.ResourceFactory(
            offering=self.offering,
            state=marketplace_models.Resource.States.OK,
            attributes={'schedules': [self.schedules[0]]},
        )

        self.resource_2 = marketplace_factories.ResourceFactory(
            offering=self.offering,
            state=marketplace_models.Resource.States.OK,
            attributes={'schedules': [self.schedules[1]]},
        )
 def setUp(self):
     self.fixture = structure_fixtures.UserFixture()
     self.resource = marketplace_factories.ResourceFactory()
     marketplace_factories.ResourceFactory()
     self.request = support_factories.OfferingFactory(
         backend_id='offering_backend_id')
     self.resource.scope = self.request
     self.resource.save()
     self.url = marketplace_factories.ResourceFactory.get_list_url()
Exemple #3
0
    def setUp(self):
        self.provider = marketplace_factories.ServiceProviderFactory()
        self.provider_2 = marketplace_factories.ServiceProviderFactory()

        self.offering = marketplace_factories.OfferingFactory(
            type=PACKAGE_TYPE, customer=self.provider.customer)

        self.offering_component = marketplace_factories.OfferingComponentFactory(
            offering=self.offering)
        self.plan = marketplace_factories.PlanFactory(
            offering=self.offering,
            unit=UnitPriceMixin.Units.PER_DAY,
        )
        self.component = marketplace_factories.PlanComponentFactory(
            component=self.offering_component,
            price=Decimal(5),
            plan=self.plan)

        self.offering_2 = marketplace_factories.OfferingFactory(
            type=PACKAGE_TYPE, customer=self.provider_2.customer)

        self.offering_component_2 = marketplace_factories.OfferingComponentFactory(
            offering=self.offering_2)
        self.plan_2 = marketplace_factories.PlanFactory(
            offering=self.offering_2,
            unit=UnitPriceMixin.Units.PER_DAY,
        )
        self.component_2 = marketplace_factories.PlanComponentFactory(
            component=self.offering_component_2,
            price=Decimal(7),
            plan=self.plan_2)

        self.resource_1 = marketplace_factories.ResourceFactory(
            state=marketplace_models.Resource.States.OK,
            offering=self.offering,
            plan=self.plan,
            limits={'cpu': 1},
        )

        self.resource_2 = marketplace_factories.ResourceFactory(
            state=marketplace_models.Resource.States.OK,
            offering=self.offering,
            project=self.resource_1.project,
            plan=self.plan,
            limits={'cpu': 1},
        )

        self.resource_3 = marketplace_factories.ResourceFactory(
            state=marketplace_models.Resource.States.OK,
            offering=self.offering_2,
            project=self.resource_1.project,
            plan=self.plan_2,
            limits={'cpu': 1},
        )

        self.customer = self.resource_1.project.customer
    def setUp(self):
        self.fixture = structure_fixtures.UserFixture()
        self.resource_1 = factories.ResourceFactory(
            backend_metadata={
                'external_ips': ['200.200.200.200', '200.200.200.201'],
                'internal_ips': ['192.168.42.1', '192.168.42.2'],
            },
            backend_id='backend_id',
        )
        factories.ResourceFactory(backend_id='other_backend_id')

        self.url = factories.ResourceFactory.get_list_url()
    def setUp(self):
        super(VolumeMetadataTest, self).setUp()
        self.fixture = openstack_tenant_fixtures.OpenStackTenantFixture()

        self.volume = self.fixture.volume
        self.resource = marketplace_factories.ResourceFactory(
            scope=self.volume)
    def test_when_resource_is_terminated_old_period_is_closed(self):
        # Arrange
        start = parse_datetime('2018-10-01')
        end = parse_datetime('2018-11-01')

        plan = factories.PlanFactory()
        resource = factories.ResourceFactory(plan=plan)

        period = models.ResourcePlanPeriod.objects.create(resource=resource,
                                                          plan=plan,
                                                          start=start,
                                                          end=None)
        order_item = factories.OrderItemFactory(
            state=models.OrderItem.States.EXECUTING,
            type=models.OrderItem.Types.TERMINATE,
            resource=resource,
            plan=plan,
        )

        # Act
        callbacks.resource_deletion_succeeded(resource)

        # Assert
        order_item.refresh_from_db()
        self.assertEqual(order_item.state, models.OrderItem.States.DONE)

        period.refresh_from_db()
        self.assertEqual(period.end, end)
    def test_when_plan_is_changed_old_period_is_closed_new_is_opened(self):
        # Arrange
        old_start = parse_datetime('2018-10-01')
        new_start = parse_datetime('2018-11-01')

        old_plan = factories.PlanFactory()
        new_plan = factories.PlanFactory()

        resource = factories.ResourceFactory(plan=old_plan)
        old_period = models.ResourcePlanPeriod.objects.create(
            resource=resource, plan=old_plan, start=old_start, end=None)
        order_item = factories.OrderItemFactory(
            state=models.OrderItem.States.EXECUTING,
            type=models.OrderItem.Types.UPDATE,
            resource=resource,
            plan=new_plan,
        )

        # Act
        callbacks.resource_update_succeeded(resource)

        # Assert
        order_item.refresh_from_db()
        self.assertEqual(order_item.state, models.OrderItem.States.DONE)

        old_period.refresh_from_db()
        self.assertEqual(old_period.end, new_start)

        self.assertTrue(
            models.ResourcePlanPeriod.objects.filter(resource=resource,
                                                     plan=new_plan,
                                                     start=new_start,
                                                     end=None).exists())
Exemple #8
0
 def create_issue(self):
     self.issue = support_factories.IssueFactory(backend_id='', key='')
     support_offering = support_factories.OfferingFactory(issue=self.issue)
     resource = marketplace_factories.ResourceFactory(scope=support_offering)
     self.order_item = marketplace_factories.OrderItemFactory(resource=resource, offering=self.offering)
     self.issue.backend_id = 'TST-1'
     self.issue.save()
 def setUp(self):
     self.resource = marketplace_factories.ResourceFactory()
     self.downtime = models.ServiceDowntime.objects.create(
         resource=self.resource,
         start=parse_datetime('2018-10-05'),
         end=parse_datetime('2018-10-15'),
     )
    def test_order_item_set_state_done_if_offering_set_state_ok(self):
        fixture = fixtures.ProjectFixture()
        offering = support_factories.OfferingFactory()
        resource = marketplace_factories.ResourceFactory(
            project=fixture.project, scope=offering)

        order_item = marketplace_factories.OrderItemFactory(resource=resource)
        order_item.set_state_executing()
        order_item.save()

        order_item.order.state = marketplace_models.Order.States.EXECUTING
        order_item.order.save()

        offering.state = support_models.Offering.States.OK
        offering.save()

        order_item.refresh_from_db()
        self.assertEqual(order_item.state, order_item.States.DONE)

        order_item.resource.refresh_from_db()
        self.assertEqual(order_item.resource.state,
                         marketplace_models.Resource.States.OK)

        order_item.order.refresh_from_db()
        self.assertEqual(order_item.order.state,
                         marketplace_models.Order.States.DONE)
Exemple #11
0
    def setUp(self):
        self.tenant = openstack_factories.TenantFactory()
        self.project = self.tenant.service_project_link.project
        self.resource = marketplace_factories.ResourceFactory(
            project=self.project)
        self.resource.scope = self.tenant
        self.resource.save()
        self.order = marketplace_factories.OrderFactory(project=self.project)
        marketplace_factories.OrderItemFactory(resource=self.resource,
                                               order=self.order)
        self.new_project = structure_factories.ProjectFactory()

        self.start_invoice = invoices_factories.InvoiceFactory(
            customer=self.project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )

        invoices_factories.InvoiceItemFactory(
            invoice=self.start_invoice,
            project=self.project,
            scope=self.resource,
        )

        self.target_invoice = invoices_factories.InvoiceFactory(
            customer=self.new_project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )
Exemple #12
0
 def setUp(self):
     fixture = package_fixtures.OpenStackFixture()
     offering = marketplace_factories.OfferingFactory(
         type=PACKAGE_TYPE, scope=fixture.openstack_service_settings
     )
     create_offering_components(offering)
     for name in 'Basic', 'Advanced':
         plan = marketplace_factories.PlanFactory(offering=offering, name=name)
         prices = {
             CORES_TYPE: 1,
             RAM_TYPE: 0.1,
             STORAGE_TYPE: 0.01,
         }
         for key, value in prices.items():
             component = marketplace_models.OfferingComponent.objects.get(
                 offering=offering, type=key,
             )
             marketplace_models.PlanComponent.objects.create(
                 plan=plan, component=component, price=value,
             )
         resource = marketplace_factories.ResourceFactory(
             offering=offering, plan=plan,
         )
         marketplace_factories.OrderItemFactory(
             offering=offering, plan=plan, resource=resource,
         )
     self.offering = offering
    def setUp(self):
        self.fixture = ServiceFixture()
        self.project = self.fixture.project
        self.resource = marketplace_factories.ResourceFactory(
            project=self.project)
        self.resource.scope = self.fixture.volume
        self.resource.save()
        resource_offering = self.resource.offering
        resource_offering.scope = self.fixture.service_settings
        resource_offering.save()
        self.order = marketplace_factories.OrderFactory(project=self.project)
        marketplace_factories.OrderItemFactory(resource=self.resource,
                                               order=self.order)
        self.new_project = structure_factories.ProjectFactory()

        self.start_invoice = invoices_factories.InvoiceFactory(
            customer=self.project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )

        invoices_factories.InvoiceItemFactory(
            invoice=self.start_invoice,
            project=self.project,
            resource=self.resource,
        )

        self.target_invoice = invoices_factories.InvoiceFactory(
            customer=self.new_project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )
Exemple #14
0
    def setUp(self):
        self.fixture = structure_fixtures.UserFixture()
        self.offering_1 = support_factories.OfferingFactory(
            backend_id='backend_id')
        self.offering_2 = support_factories.OfferingFactory(
            backend_id='backend_id')
        self.offering_3 = support_factories.OfferingFactory(
            backend_id='other_backend_id')

        ct = ContentType.objects.get_for_model(support_models.Offering)
        self.resource_1 = factories.ResourceFactory(
            object_id=self.offering_1.id, content_type=ct)
        factories.ResourceFactory(object_id=self.offering_3.id,
                                  content_type=ct)

        self.url = factories.ResourceFactory.get_list_url()
Exemple #15
0
    def test_order_item_set_state_done(self):
        tenant = package_factories.OpenStackPackageFactory().tenant
        resource = marketplace_factories.ResourceFactory(scope=tenant)

        order_item = marketplace_factories.OrderItemFactory(resource=resource)
        order_item.set_state_executing()
        order_item.save()

        order_item.order.approve()
        order_item.order.save()

        tenant.state = openstack_models.Tenant.States.CREATING
        tenant.save()

        tenant.state = openstack_models.Tenant.States.OK
        tenant.save()

        order_item.refresh_from_db()
        self.assertEqual(order_item.state, order_item.States.DONE)

        order_item.resource.refresh_from_db()
        self.assertEqual(order_item.resource.state,
                         marketplace_models.Resource.States.OK)

        order_item.order.refresh_from_db()
        self.assertEqual(order_item.order.state,
                         marketplace_models.Order.States.DONE)
Exemple #16
0
    def test_service_settings_should_be_disabled_if_offering_is_archived(
        self, ):
        marketplace_handlers.connect_resource_metadata_handlers(
            structure_tests_models.TestNewInstance)
        instance = structure_factories.TestNewInstanceFactory()
        resource: marketplace_models.Resource = factories.ResourceFactory(
            scope=instance)

        offering: marketplace_models.Offering = resource.offering
        service_settings = structure_factories.ServiceSettingsFactory()
        offering.scope = service_settings
        offering.save()

        resource.set_state_terminated()
        resource.save()

        service_settings.refresh_from_db()
        self.assertTrue(service_settings.is_active)

        offering.archive()
        offering.save()

        service_settings.refresh_from_db()

        self.assertFalse(service_settings.is_active)
Exemple #17
0
    def setUp(self):
        # Arrange
        super(StorageModeInvoiceTest, self).setUp()
        fixture = OpenStackFixture()
        tenant = fixture.openstack_tenant
        offering_component = marketplace_models.OfferingComponent.objects.create(
            offering=self.offering,
            type='gigabytes_gpfs',
            billing_type=marketplace_models.OfferingComponent.BillingTypes.
            LIMIT,
        )

        plan = self.create_plan(self.prices)
        marketplace_models.PlanComponent.objects.create(
            component=offering_component,
            plan=plan,
            price=10,
        )
        self.resource = marketplace_factories.ResourceFactory(
            offering=self.offering,
            plan=plan,
            limits=self.limits,
            state=marketplace_models.Resource.States.CREATING,
        )

        callbacks.resource_creation_succeeded(self.resource)
        self.resource.scope = tenant
        self.resource.save()
        tenant.set_quota_limit('vcpu', 6)
        tenant.set_quota_limit('ram', 10 * 1024)
        tenant.set_quota_usage('storage', 30 * 1024)
        tenant.set_quota_usage('gigabytes_gpfs', 100 * 1024)
 def resource(self) -> marketplace_models.Resource:
     return marketplace_factories.ResourceFactory(
         offering=self.offering,
         state=marketplace_models.Resource.States.CREATING,
         project=self.project,
         plan=self.plan,
     )
Exemple #19
0
 def setUp(self):
     self.fixture = openstack_tenant_fixtures.OpenStackTenantFixture()
     self.offering = marketplace_factories.OfferingFactory(
         type=PACKAGE_TYPE)
     self.plan = marketplace_factories.PlanFactory(offering=self.offering)
     self.resource = marketplace_factories.ResourceFactory(
         offering=self.offering,
         project=self.fixture.project,
         plan=self.plan,
         state=marketplace_models.Resource.States.OK)
     tenant = self.fixture.tenant
     self.mock_get_backend = mock.MagicMock()
     tenant.get_backend = self.mock_get_backend
     self.resource.scope = tenant
     self.resource.save()
     self.quotas = {
         'network_count': 100,
         'cores': 4,
         'ram': 1024,
         'storage': 1024,
         'snapshots': 50,
         'instances': 30,
         'floating_ip_count': 50,
         'subnet_count': 100,
         'volumes': 50,
         'security_group_rule_count': 100,
         'security_group_count': 100
     }
Exemple #20
0
 def setUp(self):
     self.offering = marketplace_factories.OfferingFactory(
         type=PACKAGE_TYPE)
     self.plan = marketplace_factories.PlanFactory(offering=self.offering)
     self.limits = {
         RAM_TYPE: 1 * 1024,
         CORES_TYPE: 2,
         STORAGE_TYPE: 3 * 1024,
     }
     self.prices = {
         RAM_TYPE: 10,
         CORES_TYPE: 100,
         STORAGE_TYPE: 1,
     }
     for ct in self.prices.keys():
         marketplace_factories.PlanComponentFactory(
             plan=self.plan,
             component=marketplace_factories.OfferingComponentFactory(
                 offering=self.offering,
                 type=ct,
             ),
             price=self.prices[ct],
         )
     self.resource = marketplace_factories.ResourceFactory(
         offering=self.offering,
         plan=self.plan,
         limits=self.limits,
         state=marketplace_models.Resource.States.OK,
     )
Exemple #21
0
 def test_notify_about_resource_change(self, log_func_name, mock_tasks):
     resource = factories.ResourceFactory()
     log_func = getattr(log, log_func_name)
     log_func(resource)
     if log_func_name != 'log_resource_update_succeeded':
         mock_tasks.notify_about_resource_change.delay.assert_called_once()
     else:
         mock_tasks.notify_about_resource_change.delay.assert_not_called()
    def setUp(self):
        self.fixture1 = structure_fixtures.ServiceFixture()
        self.customer1 = self.fixture1.customer
        self.offering = factories.OfferingFactory(customer=self.customer1)
        self.resource1 = factories.ResourceFactory(offering=self.offering, project=self.fixture1.project)

        self.fixture2 = structure_fixtures.ServiceFixture()
        self.customer2 = self.fixture2.customer
Exemple #23
0
 def setUp(self):
     self.fixture = fixtures.ProjectFixture()
     self.project = self.fixture.project
     self.offering = factories.OfferingFactory(customer=self.fixture.customer)
     self.offering.add_user(self.fixture.user)
     self.resource = factories.ResourceFactory(
         project=self.project, offering=self.offering
     )
    def test_filter_when_creating_missing_support_offerings(self):
        offering = support_factories.OfferingFactory()
        category = marketplace_factories.CategoryFactory()
        customer = structure_factories.CustomerFactory()
        new_project = structure_factories.ProjectFactory()
        marketplace_factories.ResourceFactory(scope=offering, project=new_project)

        marketplace_support_utils.init_offerings_and_resources(category, customer)
        self.assertFalse(marketplace_models.Resource.objects.filter(scope=offering, project=offering.project).exists())
Exemple #25
0
    def test_filter_order_items_by_marketplace_resource_uuid(self):
        resource_1 = marketplace_factories.ResourceFactory()
        resource_2 = marketplace_factories.ResourceFactory()
        factories.InvoiceItemFactory(
            name='OFFERING-002',
            project=self.fixture.project,
            invoice=self.fixture.invoice,
            unit_price=10,
            resource=resource_1,
            quantity=1,
        )
        factories.InvoiceItemFactory(
            name='OFFERING-003',
            project=self.fixture.project,
            invoice=self.fixture.invoice,
            unit_price=10,
            resource=resource_2,
            quantity=1,
        )
        user = self.fixture.staff
        self.client.force_authenticate(user)

        response = self.client.get(
            factories.InvoiceFactory.get_url(self.fixture.invoice))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['items']), 3)

        response = self.client.get(factories.InvoiceFactory.get_list_url())
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data[0]['items']), 3)

        response = self.client.get(
            factories.InvoiceFactory.get_url(self.fixture.invoice),
            {'resource_uuid': resource_1.uuid.hex},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['items']), 1)

        response = self.client.get(
            factories.InvoiceFactory.get_list_url(),
            {'resource_uuid': resource_1.uuid.hex},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data[0]['items']), 1)
Exemple #26
0
    def test_quantity(self):
        from waldur_slurm.tests.factories import AllocationFactory

        item = self.get_invoice_item(UnitPriceMixin.Units.QUANTITY)
        resource = marketplace_factories.ResourceFactory()
        resource.scope = AllocationFactory()
        resource.save()
        item.resource = resource
        item.save()
        self.assertEqual(item.get_measured_unit(), _('allocations'))
Exemple #27
0
 def create_issue(self, **kwargs):
     resource = marketplace_factories.ResourceFactory()
     self.order_item = marketplace_factories.OrderItemFactory(
         resource=resource, offering=self.offering, **kwargs)
     self.issue = support_factories.IssueFactory(backend_id='',
                                                 key='',
                                                 resource=self.order_item)
     # Trigger handler
     self.issue.backend_id = 'TST-1'
     self.issue.save()
Exemple #28
0
 def test_marketplace_resource_name_should_be_updated_if_resource_name_in_plugin_is_updated(
     self, ):
     marketplace_handlers.connect_resource_metadata_handlers(
         structure_tests_models.TestNewInstance)
     instance = structure_factories.TestNewInstanceFactory()
     resource = factories.ResourceFactory(scope=instance)
     instance.name = 'New name'
     instance.save()
     resource.refresh_from_db()
     self.assertEqual(resource.name, 'New name')
Exemple #29
0
 def setUp(self):
     fixture_1 = structure_fixtures.CustomerFixture()
     fixture_1.owner
     fixture_2 = structure_fixtures.CustomerFixture()
     fixture_2.owner
     offering_1 = marketplace_factories.OfferingFactory(
         customer=fixture_1.customer, type=PLUGIN_NAME)
     offering_2 = marketplace_factories.OfferingFactory(
         customer=fixture_2.customer, type=PLUGIN_NAME)
     self.resource = marketplace_factories.ResourceFactory(
         offering=offering_1,
         state=marketplace_models.Resource.States.CREATING)
     self.order_item = marketplace_factories.OrderItemFactory(
         resource=self.resource,
         offering=offering_1,
         state=marketplace_models.OrderItem.States.EXECUTING)
     self.resource_2 = marketplace_factories.ResourceFactory(
         offering=offering_2)
     self.owner = self.resource.offering.customer.get_owners()[0]
     self.client.force_authenticate(self.owner)
Exemple #30
0
    def trigger_offering_creation(self):
        fixture = package_fixtures.OpenStackFixture()
        tenant = openstack_models.Tenant.objects.create(
            service_project_link=fixture.openstack_spl,
            state=openstack_models.Tenant.States.CREATING,
        )
        resource = marketplace_factories.ResourceFactory(scope=tenant)
        marketplace_factories.OrderItemFactory(resource=resource)

        tenant.set_ok()
        tenant.save()
        return tenant