Fixed services tests

This commit is contained in:
Marc Aymerich 2015-05-13 17:22:54 +00:00
parent a0ccb5c420
commit a78c7e2769
10 changed files with 55 additions and 36 deletions

View File

@ -361,9 +361,10 @@ resorce monitoring more efficient, less mem an better queries for calc current d
# autoresponses on mailboxes, not addresses or remove them
# Async particular actions?
# Async specific backend actions? systemusers.set_permission
# gevent for python3
apt-get install cython3
export CYTHON='cython3'
pip3 install https://github.com/fantix/gevent/archive/master.zip

View File

@ -11,5 +11,4 @@ class OrdersConfig(AppConfig):
def ready(self):
from .models import Order
accounts.register(Order, icon='basket.png')
if database_ready():
from . import signals
from . import signals

View File

@ -18,7 +18,7 @@ class DomainBillingTest(BaseTestCase):
is_fee=False,
metric='',
pricing_period=Service.BILLING_PERIOD,
rate_algorithm='STEP_PRICE',
rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.NOTHING,
payment_style=Service.PREPAY,
tax=0,

View File

@ -13,6 +13,12 @@ from ...models import Service
class FTPBillingTest(BaseTestCase):
DEPENDENCIES = (
'orchestra.contrib.orders',
'orchestra.contrib.plans',
'orchestra.contrib.systemusers',
)
def create_ftp_service(self):
return Service.objects.create(
description="FTP Account",
@ -23,7 +29,7 @@ class FTPBillingTest(BaseTestCase):
is_fee=False,
metric='',
pricing_period=Service.NEVER,
rate_algorithm='STEP_PRICE',
rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.COMPENSATE,
payment_style=Service.PREPAY,
tax=0,
@ -39,6 +45,7 @@ class FTPBillingTest(BaseTestCase):
def test_ftp_account_1_year_fiexed(self):
service = self.create_ftp_service()
self.create_ftp()
self.assertEqual(1, service.orders.count())
bp = timezone.now().date() + relativedelta(years=1)
bills = service.orders.bill(billing_point=bp, fixed_point=True)
self.assertEqual(10, bills[0].get_total())

View File

@ -18,7 +18,7 @@ class JobBillingTest(BaseTestCase):
is_fee=False,
metric='miscellaneous.amount',
pricing_period=Service.BILLING_PERIOD,
rate_algorithm='MATCH_PRICE',
rate_algorithm='orchestra.contrib.plans.ratings.match_price',
on_cancel=Service.NOTHING,
payment_style=Service.POSTPAY,
tax=0,

View File

@ -22,7 +22,7 @@ class MailboxBillingTest(BaseTestCase):
is_fee=False,
metric='',
pricing_period=Service.NEVER,
rate_algorithm='STEP_PRICE',
rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.COMPENSATE,
payment_style=Service.PREPAY,
tax=0,
@ -43,7 +43,7 @@ class MailboxBillingTest(BaseTestCase):
is_fee=False,
metric='max((mailbox.resources.disk.allocated or 0) -1, 0)',
pricing_period=Service.NEVER,
rate_algorithm='STEP_PRICE',
rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.DISCOUNT,
payment_style=Service.PREPAY,
tax=0,

View File

@ -17,7 +17,7 @@ class PlanBillingTest(BaseTestCase):
is_fee=True,
metric='',
pricing_period=Service.BILLING_PERIOD,
rate_algorithm='STEP_PRICE',
rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.DISCOUNT,
payment_style=Service.PREPAY,
tax=0,

View File

@ -7,11 +7,16 @@ from orchestra.contrib.accounts.models import Account
from orchestra.contrib.miscellaneous.models import MiscService, Miscellaneous
from orchestra.contrib.plans.models import Plan
from orchestra.contrib.resources.models import Resource, ResourceData, MonitorData
from orchestra.contrib.resources.backends import ServiceMonitor
from orchestra.utils.tests import BaseTestCase
from ...models import Service
class FTPTrafficMonitor(ServiceMonitor):
model = 'systemusers.SystemUser'
class BaseTrafficBillingTest(BaseTestCase):
TRAFFIC_METRIC = 'account.resources.traffic.used'
@ -25,7 +30,7 @@ class BaseTrafficBillingTest(BaseTestCase):
is_fee=False,
metric=self.TRAFFIC_METRIC,
pricing_period=Service.BILLING_PERIOD,
rate_algorithm='STEP_PRICE',
rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.NOTHING,
payment_style=Service.POSTPAY,
tax=0,
@ -45,12 +50,13 @@ class BaseTrafficBillingTest(BaseTestCase):
unit='GB',
scale='10**9',
on_demand=True,
monitors='FTPTraffic',
# TODO
monitors=FTPTrafficMonitor.get_name(),
)
return self.resource
def report_traffic(self, account, value):
MonitorData.objects.create(monitor='FTPTraffic', content_object=account.systemusers.get(), value=value)
MonitorData.objects.create(monitor=FTPTrafficMonitor.get_name(), content_object=account.systemusers.get(), value=value)
data, __ = ResourceData.get_or_create(account, self.resource)
data.update()
@ -107,7 +113,7 @@ class TrafficPrepayBillingTest(BaseTrafficBillingTest):
is_fee=False,
metric="miscellaneous.amount",
pricing_period=Service.NEVER,
rate_algorithm='STEP_PRICE',
rate_algorithm='orchestra.contrib.plans.ratings.step_price',
on_cancel=Service.NOTHING,
payment_style=Service.PREPAY,
tax=0,
@ -139,7 +145,6 @@ class TrafficPrepayBillingTest(BaseTrafficBillingTest):
bill = account.orders.bill(proforma=True, new_open=True)[0]
self.assertEqual(2*10*50 + 0*10, bill.get_total())
# TODO dateutils.relativedelta is buggy with fakedatetime
# TODO RuntimeWarning: DateTimeField MetricStorage.updated_on received a naive
self.report_traffic(account, 10**10)
with freeze_time(now+relativedelta(months=1)):

View File

@ -32,19 +32,25 @@ class UNIXUserBackend(ServiceController):
# TODO userd add will fail if %(user)s group already exists
self.append(textwrap.dedent("""
if [[ $( id %(user)s ) ]]; then
usermod %(user)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s
usermod %(user)s --home %(home)s \\
--password '%(password)s' \\
--shell %(shell)s %(groups_arg)s
else
useradd %(user)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s || {
useradd_code=$?
# User is logged in, kill and retry
if [[ $useradd_code -eq 8 ]]; then
pkill -u %(user)s; sleep 2
pkill -9 -u %(user)s; sleep 1
useradd %(user)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s
else
exit $useradd_code
fi
}
useradd %(user)s --home %(home)s \\
--password '%(password)s' \\
--shell %(shell)s %(groups_arg)s || {
useradd_code=$?
# User is logged in, kill and retry
if [[ $useradd_code -eq 8 ]]; then
pkill -u %(user)s; sleep 2
pkill -9 -u %(user)s; sleep 1
useradd %(user)s --home %(home)s \\
--password '%(password)s' \\
--shell %(shell)s %(groups_arg)s
else
exit $useradd_code
fi
}
fi
mkdir -p %(base_home)s
chmod 750 %(base_home)s

View File

@ -82,16 +82,17 @@ class PHPApp(AppType):
options += list(webapp.options.all())
init_vars = OrderedDict((opt.name, opt.value) for opt in options)
# Enable functions
enable_functions = init_vars.pop('enable_functions', '')
if enable_functions or self.is_fpm:
# FPM: Defining 'disable_functions' or 'disable_classes' will not overwrite previously
# defined php.ini values, but will append the new value
enable_functions = set(enable_functions.split(','))
disable_functions = []
for function in self.PHP_DISABLED_FUNCTIONS:
if function not in enable_functions:
disable_functions.append(function)
init_vars['disable_functions'] = ','.join(disable_functions)
if self.PHP_DISABLED_FUNCTIONS:
enable_functions = init_vars.pop('enable_functions', '')
if enable_functions or self.is_fpm:
# FPM: Defining 'disable_functions' or 'disable_classes' will not overwrite previously
# defined php.ini values, but will append the new value
enable_functions = set(enable_functions.split(','))
disable_functions = []
for function in self.PHP_DISABLED_FUNCTIONS:
if function not in enable_functions:
disable_functions.append(function)
init_vars['disable_functions'] = ','.join(disable_functions)
# process timeout
timeout = self.instance.options.filter(name='timeout').first()
if timeout: