def setUp(self): self.anonymous_user = AnonymousUserFactory() self.user = UserFactory.create(username='******') self.provider = ProviderFactory.create(type__name='mock') self.user_identity = IdentityFactory.create_identity( created_by=self.user, provider=self.provider) self.machine = ProviderMachineFactory.create_provider_machine( self.user, self.user_identity) start_date = timezone.now() self.active_instance = InstanceFactory.create( name="Instance in active", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=start_date) self.status_active = InstanceStatusFactory.create(name='active') delta_time = timezone.timedelta(minutes=2) InstanceHistoryFactory.create(status=self.status_active, activity="", instance=self.active_instance, start_date=start_date + delta_time * 3) self.view = InstanceViewSet.as_view({'post': 'actions'}) self.url = reverse('api:v2:instance-list') self.url += "/" + str(self.active_instance.provider_alias) + "/actions" self.mock_driver = get_esh_driver(self.user_identity) self.mock_driver.add_core_instance(self.active_instance) start_date_second = timezone.now() self.active_instance_second = InstanceFactory.create( name="Instance in active", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=start_date_second) self.status_active_second = InstanceStatusFactory.create(name='active') delta_time = timezone.timedelta(minutes=2) self.size_small = SizeFactory.create(provider=self.provider, cpu=2, disk=20, root=0, mem=128) self.size_large = SizeFactory.create(provider=self.provider, cpu=4, disk=40, root=0, mem=256) InstanceHistoryFactory.create(status=self.status_active_second, size=self.size_small, activity="", instance=self.active_instance_second, start_date=start_date_second + delta_time * 3) self.mock_driver_second = get_esh_driver(self.user_identity) self.mock_driver.add_core_instance(self.active_instance_second)
def setUp(self): self.list_view = InstanceViewSet.as_view({'get': 'list'}) self.detailed_view = InstanceViewSet.as_view({'get': 'retrieve'}) self.anonymous_user = AnonymousUserFactory() self.user = UserFactory.create(username='******') self.admin_user = UserFactory.create(username='******', is_superuser=True, is_staff=True) self.provider = ProviderFactory.create() self.user_identity = IdentityFactory.create_identity( created_by=self.user, provider=self.provider) self.admin_identity = IdentityFactory.create_identity( provider=self.provider, created_by=self.admin_user) self.machine = ProviderMachineFactory.create_provider_machine(self.user, self.user_identity) self.active_instance = InstanceFactory.create( name="Instance in active", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=timezone.now()) self.networking_instance = InstanceFactory.create( name="Instance in networking", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=timezone.now()) self.deploying_instance = InstanceFactory.create( name="Instance in deploying", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=timezone.now()) self.deploy_error_instance = InstanceFactory.create( name="Instance in deploy_error", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=timezone.now()) active = InstanceStatusFactory.create(name='active') networking = InstanceStatusFactory.create(name='networking') deploying = InstanceStatusFactory.create(name='deploying') deploy_error = InstanceStatusFactory.create(name='deploy_error') InstanceHistoryFactory.create( status=deploy_error, activity="", instance=self.deploy_error_instance ) InstanceHistoryFactory.create( status=deploying, activity="", instance=self.deploying_instance ) InstanceHistoryFactory.create( status=active, activity="", instance=self.active_instance ) InstanceHistoryFactory.create( status=networking, activity="", instance=self.networking_instance )
def setUp(self): self.anonymous_user = AnonymousUserFactory() self.user = UserFactory.create(username='******') self.provider = ProviderFactory.create(type__name='mock') self.user_identity = IdentityFactory.create_identity( created_by=self.user, provider=self.provider ) self.machine = ProviderMachineFactory.create_provider_machine( self.user, self.user_identity ) start_date = timezone.now() self.active_instance = InstanceFactory.create( name="Instance in active", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=start_date ) self.size_small = SizeFactory.create( provider=self.provider, cpu=2, disk=20, root=0, mem=128 ) self.status_active = InstanceStatusFactory.create(name='active') delta_time = timezone.timedelta(minutes=2) InstanceHistoryFactory.create( status=self.status_active, size=self.size_small, activity="", instance=self.active_instance, start_date=start_date + delta_time * 3 ) self.view = InstanceViewSet.as_view({'post': 'actions'}) self.url = reverse('api:v2:instance-list') self.url += "/" + str(self.active_instance.provider_alias) + "/actions" self.mock_driver = get_esh_driver(self.user_identity) self.mock_driver.add_core_instance(self.active_instance) start_date_second = timezone.now() self.active_instance_second = InstanceFactory.create( name="Instance in active", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=start_date_second ) delta_time = timezone.timedelta(minutes=2) self.size_small = SizeFactory.create( provider=self.provider, cpu=2, disk=20, root=0, mem=128 ) self.size_large = SizeFactory.create( provider=self.provider, cpu=4, disk=40, root=0, mem=256 ) InstanceHistoryFactory.create( status=self.status_active, size=self.size_small, activity="", instance=self.active_instance_second, start_date=start_date_second + delta_time * 3 ) self.mock_driver.add_core_instance(self.active_instance_second) self.allocation_source_1 = AllocationSourceFactory.create( name='TEST_INSTANCE_ALLOCATION_SOURCE_01', compute_allowed=1000 ) UserAllocationSource.objects.create( allocation_source=self.allocation_source_1, user=self.user ) UserAllocationSnapshot.objects.create( allocation_source=self.allocation_source_1, user=self.user, burn_rate=1, compute_used=0 ) AllocationSourceSnapshot.objects.create( allocation_source=self.allocation_source_1, compute_used=0, compute_allowed=168, global_burn_rate=1 ) InstanceAllocationSourceSnapshot.objects.update_or_create( instance=self.active_instance, allocation_source=self.allocation_source_1 )
def setUp(self): self.anonymous_user = AnonymousUserFactory() self.user = UserFactory.create(username='******') self.provider = ProviderFactory.create(type__name='mock') self.user_identity = IdentityFactory.create_identity( created_by=self.user, provider=self.provider) self.machine = ProviderMachineFactory.create_provider_machine(self.user, self.user_identity) start_date = timezone.now() self.active_instance = InstanceFactory.create( name="Instance in active", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=start_date) self.size_small = SizeFactory.create(provider=self.provider, cpu=2, disk=20, root=0, mem=128) self.status_active = InstanceStatusFactory.create(name='active') delta_time = timezone.timedelta(minutes=2) InstanceHistoryFactory.create( status=self.status_active, size=self.size_small, activity="", instance=self.active_instance, start_date=start_date + delta_time*3) self.view = InstanceViewSet.as_view({'post': 'actions'}) self.url = reverse('api:v2:instance-list') self.url += "/" + str(self.active_instance.provider_alias) + "/actions" self.mock_driver = get_esh_driver(self.user_identity) self.mock_driver.add_core_instance(self.active_instance) start_date_second = timezone.now() self.active_instance_second = InstanceFactory.create( name="Instance in active", provider_alias=uuid.uuid4(), source=self.machine.instance_source, created_by=self.user, created_by_identity=self.user_identity, start_date=start_date_second) delta_time = timezone.timedelta(minutes=2) self.size_small = SizeFactory.create(provider=self.provider, cpu=2, disk=20, root=0, mem=128) self.size_large = SizeFactory.create(provider=self.provider, cpu=4, disk=40, root=0, mem=256) InstanceHistoryFactory.create( status=self.status_active, size=self.size_small, activity="", instance=self.active_instance_second, start_date=start_date_second + delta_time*3) self.mock_driver.add_core_instance(self.active_instance_second) self.allocation_source_1 = AllocationSourceFactory.create(name='TEST_INSTANCE_ALLOCATION_SOURCE_01', compute_allowed=1000) UserAllocationSource.objects.create( allocation_source=self.allocation_source_1, user=self.user) UserAllocationSnapshot.objects.create( allocation_source=self.allocation_source_1, user=self.user, burn_rate=1, compute_used=0) AllocationSourceSnapshot.objects.create( allocation_source=self.allocation_source_1, compute_used=0, compute_allowed=168, global_burn_rate=1 ) InstanceAllocationSourceSnapshot.objects.update_or_create(instance=self.active_instance, allocation_source=self.allocation_source_1)