예제 #1
0
    def trigger_deletion(self):
        serialized_order = core_utils.serialize_instance(self.order_item.order)
        serialized_user = core_utils.serialize_instance(self.fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        self.order_item.refresh_from_db()
        self.resource.refresh_from_db()
        self.tenant.refresh_from_db()
예제 #2
0
    def test_resource_is_created_when_order_item_is_processed(self):
        service_settings = rancher_factories.RancherServiceSettingsFactory()
        offering = marketplace_factories.OfferingFactory(
            type=PLUGIN_NAME, scope=service_settings)

        openstack_tenant_factories.FlavorFactory(
            settings=self.fixture.openstack_tenant_service_settings,
            ram=1024 * 8,
            cores=8,
        )
        image = openstack_tenant_factories.ImageFactory(
            settings=self.fixture.openstack_tenant_service_settings)
        openstack_tenant_factories.SecurityGroupFactory(
            name='default',
            settings=self.fixture.openstack_tenant_service_settings)
        service_settings.options['base_image_name'] = image.name
        service_settings.save()

        order = marketplace_factories.OrderFactory(
            project=self.fixture.project, created_by=self.fixture.owner)
        ssh_public_key = SshPublicKeyFactory(user=self.fixture.staff)
        order_item = marketplace_factories.OrderItemFactory(
            order=order,
            offering=offering,
            attributes={
                'name':
                'name',
                'tenant_settings':
                openstack_tenant_factories.
                OpenStackTenantServiceSettingsFactory.get_url(
                    self.fixture.openstack_tenant_service_settings),
                'project':
                ProjectFactory.get_url(self.fixture.project),
                'ssh_public_key':
                SshPublicKeyFactory.get_url(ssh_public_key),
                'nodes': [{
                    'subnet':
                    openstack_tenant_factories.SubNetFactory.get_url(
                        self.fixture.subnet),
                    'system_volume_size':
                    1024,
                    'memory':
                    1,
                    'cpu':
                    1,
                    'roles': ['controlplane', 'etcd', 'worker'],
                }],
            },
        )
        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(self.fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)
        self.assertTrue(
            marketplace_models.Resource.objects.filter(name='name').exists())
        self.assertTrue(
            rancher_models.Cluster.objects.filter(name='name').exists())
예제 #3
0
    def order_item_process(self, order_item):
        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(self.fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

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

        order_item.resource.scope.set_ok()
    def test_request_is_deleted(self):
        serialized_order = core_utils.serialize_instance(self.order_item.order)
        serialized_user = core_utils.serialize_instance(self.fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        self.order_item.refresh_from_db()
        self.resource.refresh_from_db()

        self.assertEqual(self.order_item.state,
                         marketplace_models.OrderItem.States.DONE)
        self.assertEqual(self.resource.state,
                         marketplace_models.Resource.States.TERMINATED)
        self.assertRaises(ObjectDoesNotExist, self.request.refresh_from_db)
예제 #5
0
    def submit_order_item(self):
        fixture = fixtures.ProjectFixture()
        offering = marketplace_factories.OfferingFactory(type=PLUGIN_NAME, options={'order': []})

        order_item = marketplace_factories.OrderItemFactory(
            offering=offering,
            attributes={'name': 'item_name', 'description': 'Description'}
        )

        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)
        return order_item
예제 #6
0
    def trigger_instance_creation(self, **kwargs):
        image = openstack_tenant_factories.ImageFactory(
            settings=self.service_settings, min_disk=10240, min_ram=1024)
        flavor = openstack_tenant_factories.FlavorFactory(
            settings=self.service_settings)

        subnet_url = openstack_tenant_factories.SubNetFactory.get_url(
            self.fixture.subnet)
        attributes = {
            'flavor':
            openstack_tenant_factories.FlavorFactory.get_url(flavor),
            'image':
            openstack_tenant_factories.ImageFactory.get_url(image),
            'name':
            'Virtual machine',
            'system_volume_size':
            image.min_disk,
            'internal_ips_set': [{
                'subnet': subnet_url
            }],
            'ssh_public_key':
            structure_factories.SshPublicKeyFactory.get_url(
                structure_factories.SshPublicKeyFactory(
                    user=self.fixture.manager)),
        }
        attributes.update(kwargs)

        offering = marketplace_factories.OfferingFactory(
            type=INSTANCE_TYPE, scope=self.service_settings)
        marketplace_factories.OfferingFactory(type=VOLUME_TYPE,
                                              scope=self.service_settings)
        # Ensure that SPL exists
        self.fixture.spl
        order = marketplace_factories.OrderFactory(
            project=self.fixture.project,
            state=marketplace_models.Order.States.EXECUTING,
        )
        order_item = marketplace_factories.OrderItemFactory(
            offering=offering,
            attributes=attributes,
            order=order,
        )

        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(self.fixture.owner)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        order_item.refresh_from_db()
        return order_item
예제 #7
0
    def test_resource_is_created_when_order_item_is_processed(self):
        service = rancher_factories.RancherServiceFactory(
            customer=self.fixture.customer)
        spl = rancher_factories.RancherServiceProjectLinkFactory(
            project=self.fixture.project, service=service)
        service_settings = spl.service.settings
        offering = marketplace_factories.OfferingFactory(
            type=PLUGIN_NAME, scope=service_settings)

        openstack_tenant_factories.FlavorFactory(
            settings=self.fixture.spl.service.settings)
        image = openstack_tenant_factories.ImageFactory(
            settings=self.fixture.spl.service.settings)
        openstack_tenant_factories.SecurityGroupFactory(
            name='default', settings=self.fixture.spl.service.settings)
        service_settings.options['base_image_name'] = image.name
        service_settings.save()

        order = marketplace_factories.OrderFactory(
            project=self.fixture.project, created_by=self.fixture.owner)
        order_item = marketplace_factories.OrderItemFactory(
            order=order,
            offering=offering,
            attributes={
                'name':
                'name',
                'nodes': [{
                    'subnet':
                    openstack_tenant_factories.SubNetFactory.get_url(
                        self.fixture.subnet),
                    'storage':
                    1024,
                    'memory':
                    1,
                    'cpu':
                    1,
                    'roles': ['controlplane', 'etcd', 'worker']
                }],
            })
        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(self.fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)
        self.assertTrue(
            marketplace_models.Resource.objects.filter(name='name').exists())
        self.assertTrue(
            rancher_models.Cluster.objects.filter(name='name').exists())
예제 #8
0
    def test_request_is_created_when_order_item_is_processed(self):
        fixture = fixtures.ProjectFixture()
        offering = marketplace_factories.OfferingFactory(type=PLUGIN_NAME, options={'order': []})

        order_item = marketplace_factories.OrderItemFactory(
            offering=offering,
            attributes={'name': 'item_name', 'description': 'Description'}
        )

        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        self.assertTrue(support_models.Offering.objects.filter(name='item_name').exists())
        support_offering = support_models.Offering.objects.get(name='item_name')
        resource = marketplace_models.Resource.objects.get(scope=support_offering)
        order_item = marketplace_models.OrderItem.objects.get(resource=resource)
        self.assertTrue(support_models.Issue.objects.filter(resource_object_id=order_item.id).exists())
예제 #9
0
    def test_create_offering_if_order_item_is_approved(self):
        fixture = fixtures.ProjectFixture()
        offering = marketplace_factories.OfferingFactory(type=PLUGIN_NAME,
                                                         options={'order': []})

        order_item = marketplace_factories.OrderItemFactory(offering=offering,
                                                            attributes={
                                                                'name':
                                                                'item_name',
                                                                'description':
                                                                'Description'
                                                            })

        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        self.assertTrue(
            support_models.Offering.objects.filter(name='item_name').exists())
예제 #10
0
    def test_issue_caller_is_equal_order_created_by(self):
        fixture = fixtures.ProjectFixture()
        offering = marketplace_factories.OfferingFactory(
            type=PLUGIN_NAME, options={'order': []}
        )

        order_item = marketplace_factories.OrderItemFactory(
            offering=offering,
            attributes={'name': 'item_name', 'description': 'Description'},
        )

        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        support_offering = support_models.Offering.objects.get(name='item_name')
        resource = marketplace_models.Resource.objects.get(scope=support_offering)
        order_item = marketplace_models.OrderItem.objects.get(resource=resource)
        issue = support_models.Issue.objects.get(resource_object_id=order_item.id)
        self.assertEqual(issue.caller, order_item.order.created_by)
예제 #11
0
    def test_when_order_item_is_processed_cost_estimate_is_initialized(self):
        # Arrange
        fixture = fixtures.ProjectFixture()
        offering = factories.OfferingFactory(type='Support.OfferingTemplate')
        plan = factories.PlanFactory(unit_price=10)

        order_item = factories.OrderItemFactory(
            offering=offering,
            plan=plan,
            attributes={'name': 'item_name', 'description': 'Description'},
        )

        # Act
        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        tasks.process_order(serialized_order, serialized_user)

        # Assert
        order_item.refresh_from_db()
        self.assertEqual(order_item.resource.cost, plan.unit_price)
예제 #12
0
    def test_resource_is_created_when_order_item_is_processed(self):
        fixture = fixtures.ProjectFixture()
        offering = marketplace_factories.OfferingFactory(type=PLUGIN_NAME)

        order_item = marketplace_factories.OrderItemFactory(
            offering=offering,
            attributes={
                'name': 'item_name',
                'description': 'Description',
                'schedules': [{'start': None, 'end': None}],
            },
        )

        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        self.assertTrue(
            marketplace_models.Resource.objects.filter(name='item_name').exists()
        )
        resource = marketplace_models.Resource.objects.get(name='item_name')
        self.assertEqual(resource.state, marketplace_models.Resource.States.CREATING)
    def trigger_volume_creation(self, **kwargs):
        fixture = openstack_tenant_fixtures.OpenStackTenantFixture()
        service_settings = fixture.openstack_tenant_service_settings

        image = openstack_tenant_factories.ImageFactory(
            settings=service_settings,
            min_disk=10240,
            min_ram=1024
        )

        attributes = {
            'image': openstack_tenant_factories.ImageFactory.get_url(image),
            'name': 'Volume',
            'size': 10 * 1024
        }
        attributes.update(kwargs)

        offering = marketplace_factories.OfferingFactory(type=VOLUME_TYPE, scope=service_settings)

        order_item = marketplace_factories.OrderItemFactory(offering=offering, attributes=attributes)
        order_item.order.approve()
        order_item.order.save()

        service = openstack_tenant_models.OpenStackTenantService.objects.create(
            customer=order_item.order.project.customer,
            settings=service_settings,
        )

        openstack_tenant_models.OpenStackTenantServiceProjectLink.objects.create(
            project=order_item.order.project,
            service=service,
        )

        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        order_item.refresh_from_db()
        return order_item
예제 #14
0
    def setUp(self):
        fixture = structure_fixtures.ProjectFixture()
        offering = marketplace_factories.OfferingFactory(type=PLUGIN_NAME)

        self.order_item = marketplace_factories.OrderItemFactory(
            offering=offering,
            attributes={
                'schedules': [
                    {
                        'start': '2019-01-03T00:00:00.000000Z',
                        'end': '2019-01-05T23:59:59.000000Z'
                    },
                ],
                'name':
                'booking'
            })

        serialized_order = core_utils.serialize_instance(self.order_item.order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        self.resource = marketplace_models.Resource.objects.filter(
            name='item_name').exists()
예제 #15
0
def process_order(order, user):
    serialized_order = core_utils.serialize_instance(order)
    serialized_user = core_utils.serialize_instance(user)
    marketplace_tasks.process_order(serialized_order, serialized_user)
예제 #16
0
 def trigger_creation(self):
     serialized_order = core_utils.serialize_instance(self.order_item.order)
     serialized_user = core_utils.serialize_instance(self.fixture.staff)
     marketplace_tasks.process_order(serialized_order, serialized_user)
예제 #17
0
    def _create_usage(self, mock_executors):
        order = marketplace_factories.OrderFactory(
            project=self.fixture.project, created_by=self.fixture.owner)
        order_item = marketplace_factories.OrderItemFactory(
            order=order,
            offering=self.offering,
            attributes={
                'name':
                'name',
                'tenant_settings':
                openstack_tenant_factories.
                OpenStackTenantServiceSettingsFactory.get_url(
                    self.fixture.openstack_tenant_service_settings),
                'nodes': [{
                    'subnet':
                    openstack_tenant_factories.SubNetFactory.get_url(
                        self.fixture.subnet),
                    'system_volume_size':
                    1024,
                    'memory':
                    1,
                    'cpu':
                    1,
                    'roles': ['controlplane', 'etcd', 'worker'],
                }],
            },
        )
        serialized_order = core_utils.serialize_instance(order_item.order)
        serialized_user = core_utils.serialize_instance(self.fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)
        self.assertTrue(
            marketplace_models.Resource.objects.filter(name='name').exists())
        self.assertTrue(
            rancher_models.Cluster.objects.filter(name='name').exists())

        self.cluster = rancher_models.Cluster.objects.get(name='name')
        self.cluster.backend_id = 'cluster_backend_id'
        self.cluster.save()

        create_node_task = tasks.CreateNodeTask()
        create_node_task.execute(
            mock_executors.ClusterCreateExecutor.execute.mock_calls[0][1]
            [0].node_set.first(),
            user_id=mock_executors.ClusterCreateExecutor.execute.mock_calls[0]
            [2]['user'].id,
        )
        self.assertTrue(
            self.cluster.node_set.filter(cluster=self.cluster).exists())

        today = datetime.date.today()
        self.resource = marketplace_models.Resource.objects.get(
            scope=self.cluster)
        self.plan_period = marketplace_models.ResourcePlanPeriod.objects.create(
            start=today,
            end=None,
            resource=self.resource,
            plan=self.plan,
        )
        invoices_tasks.create_monthly_invoices()
        tasks.pull_cluster_nodes(self.cluster.id)
        utils.update_cluster_nodes_states(self.cluster.id)