diff --git a/TODO.md b/TODO.md index ddd23f8e..6b0ff87a 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/orchestra/contrib/orders/apps.py b/orchestra/contrib/orders/apps.py index ae588789..2e54e2b2 100644 --- a/orchestra/contrib/orders/apps.py +++ b/orchestra/contrib/orders/apps.py @@ -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 diff --git a/orchestra/contrib/services/tests/functional_tests/test_domain.py b/orchestra/contrib/services/tests/functional_tests/test_domain.py index 188a7334..990b39a1 100644 --- a/orchestra/contrib/services/tests/functional_tests/test_domain.py +++ b/orchestra/contrib/services/tests/functional_tests/test_domain.py @@ -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, diff --git a/orchestra/contrib/services/tests/functional_tests/test_ftp.py b/orchestra/contrib/services/tests/functional_tests/test_ftp.py index 9a2b6def..a7fdc81b 100644 --- a/orchestra/contrib/services/tests/functional_tests/test_ftp.py +++ b/orchestra/contrib/services/tests/functional_tests/test_ftp.py @@ -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()) diff --git a/orchestra/contrib/services/tests/functional_tests/test_job.py b/orchestra/contrib/services/tests/functional_tests/test_job.py index 5d9e3dbf..db8b23e4 100644 --- a/orchestra/contrib/services/tests/functional_tests/test_job.py +++ b/orchestra/contrib/services/tests/functional_tests/test_job.py @@ -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, diff --git a/orchestra/contrib/services/tests/functional_tests/test_mailbox.py b/orchestra/contrib/services/tests/functional_tests/test_mailbox.py index 162227ed..64bf61f9 100644 --- a/orchestra/contrib/services/tests/functional_tests/test_mailbox.py +++ b/orchestra/contrib/services/tests/functional_tests/test_mailbox.py @@ -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, diff --git a/orchestra/contrib/services/tests/functional_tests/test_plan.py b/orchestra/contrib/services/tests/functional_tests/test_plan.py index 19a7a61c..d6c98af0 100644 --- a/orchestra/contrib/services/tests/functional_tests/test_plan.py +++ b/orchestra/contrib/services/tests/functional_tests/test_plan.py @@ -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, diff --git a/orchestra/contrib/services/tests/functional_tests/test_traffic.py b/orchestra/contrib/services/tests/functional_tests/test_traffic.py index 0cb13ecc..cc27a06a 100644 --- a/orchestra/contrib/services/tests/functional_tests/test_traffic.py +++ b/orchestra/contrib/services/tests/functional_tests/test_traffic.py @@ -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)): diff --git a/orchestra/contrib/systemusers/backends.py b/orchestra/contrib/systemusers/backends.py index 2be5847d..2a43254a 100644 --- a/orchestra/contrib/systemusers/backends.py +++ b/orchestra/contrib/systemusers/backends.py @@ -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 diff --git a/orchestra/contrib/webapps/types/php.py b/orchestra/contrib/webapps/types/php.py index a79a7e18..21a6e94b 100644 --- a/orchestra/contrib/webapps/types/php.py +++ b/orchestra/contrib/webapps/types/php.py @@ -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: