From cc4ecee4ddd610ad93f408b686d67e853d7882b7 Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Wed, 13 May 2015 13:52:20 +0000 Subject: [PATCH] Random fixes --- INSTALL.md | 2 - README.md | 1 - TODO.md | 4 +- .../contrib/services/tests/test_handler.py | 42 +++++++++++++----- orchestra/contrib/systemusers/backends.py | 13 +++++- orchestra/contrib/systemusers/forms.py | 44 ++++++++++--------- orchestra/contrib/systemusers/validators.py | 1 + orchestra/utils/tests.py | 2 +- requirements.txt | 2 +- scripts/container/deploy.sh | 1 - 10 files changed, 70 insertions(+), 42 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index ed52fa49..557e0e9c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -38,8 +38,6 @@ Django-orchestra can be installed on any Linux system, however it is **strongly ```bash sudo apt-get install python3-psycopg2 postgresql sudo python3 manage.py setuppostgres --db_password - # admin_tools needs accounts and does not have migrations - python3 manage.py migrate accounts python3 manage.py migrate ``` diff --git a/README.md b/README.md index a8be5feb..aa4df85c 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,6 @@ pip3 install -r \ # Create a new Orchestra site orchestra-admin startproject panel -python3 panel/manage.py migrate accounts python3 panel/manage.py migrate python3 panel/manage.py runserver diff --git a/TODO.md b/TODO.md index 6e75682b..90528bdc 100644 --- a/TODO.md +++ b/TODO.md @@ -57,7 +57,7 @@ * print open invoices as proforma? -* env ORCHESTRA_MASTER_SERVER='test1.orchestra.lan' ORCHESTRA_SECOND_SERVER='test2.orchestra.lan' ORCHESTRA_SLAVE_SERVER='test3.orchestra.lan' python manage.py test orchestra.apps.domains.tests.functional_tests.tests:AdminBind9BackendDomainTest --nologcapture +* env ORCHESTRA_MASTER_SERVER='test1.orchestra.lan' ORCHESTRA_SECOND_SERVER='test2.orchestra.lan' ORCHESTRA_SLAVE_SERVER='test3.orchestra.lan' python3 manage.py test orchestra.contrib.domains.tests.functional_tests.tests:AdminBind9BackendDomainTest --nologcapture * ForeignKey.swappable * Field.editable @@ -360,3 +360,5 @@ resorce monitoring more efficient, less mem an better queries for calc current d # Tests can not run because django.db.utils.ProgrammingError: relation "accounts_account" does not exist # autoresponses on mailboxes, not addresses or remove them + +# Async particular actions? diff --git a/orchestra/contrib/services/tests/test_handler.py b/orchestra/contrib/services/tests/test_handler.py index ddf1e9cc..fc3a611e 100644 --- a/orchestra/contrib/services/tests/test_handler.py +++ b/orchestra/contrib/services/tests/test_handler.py @@ -5,10 +5,12 @@ from django.contrib.contenttypes.models import ContentType from django.utils import timezone from orchestra.contrib.systemusers.models import SystemUser +from orchestra.contrib.plans.models import Plan +from orchestra.utils.python import cmp_to_key from orchestra.utils.tests import BaseTestCase from .. import helpers -from ..models import Service, Plan +from ..models import Service class Order(object): @@ -40,7 +42,7 @@ class HandlerTests(BaseTestCase): is_fee=False, metric='', 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, @@ -144,7 +146,7 @@ class HandlerTests(BaseTestCase): order6 = Order( registered_on=now+datetime.timedelta(days=8)) orders = [order3, order, order1, order2, order4, order5, order6] - self.assertEqual(orders, sorted(orders, cmp=helpers.cmp_billed_until_or_registered_on)) + self.assertEqual(orders, sorted(orders, key=cmp_to_key(helpers.cmp_billed_until_or_registered_on))) def test_compensation(self): now = timezone.now().date() @@ -192,7 +194,7 @@ class HandlerTests(BaseTestCase): [now+datetime.timedelta(days=100), now+datetime.timedelta(days=102), order], ]) porders = [order3, order, order1, order2, order4, order5, order6] - porders = sorted(porders, cmp=helpers.cmp_billed_until_or_registered_on) + porders = sorted(porders, key=cmp_to_key(helpers.cmp_billed_until_or_registered_on)) compensations = [] receivers = [] for order in porders: @@ -223,10 +225,19 @@ class HandlerTests(BaseTestCase): results = service.get_rates(account, cache=False) results = service.rate_method(results, 30) rates = [ - {'price': decimal.Decimal('0.00'), 'quantity': 2}, - {'price': decimal.Decimal('10.00'), 'quantity': 1}, - {'price': decimal.Decimal('9.00'), 'quantity': 6}, - {'price': decimal.Decimal('1.00'), 'quantity': 21} + { + 'price': decimal.Decimal('0.00'), + 'quantity': 2 + }, { + 'price': decimal.Decimal('10.00'), + 'quantity': 1 + }, { + 'price': decimal.Decimal('9.00'), + 'quantity': 6 + }, { + 'price': decimal.Decimal('1.00'), + 'quantity': 21 + } ] for rate, result in zip(rates, results): self.assertEqual(rate['price'], result.price) @@ -280,7 +291,7 @@ class HandlerTests(BaseTestCase): self.assertEqual(rate['price'], result.price) self.assertEqual(rate['quantity'], result.quantity) - service.rate_algorithm = service.MATCH_PRICE + service.rate_algorithm = 'orchestra.contrib.plans.ratings.match_price' service.save() results = service.get_rates(account, cache=False) results = service.rate_method(results, 30) @@ -313,9 +324,16 @@ class HandlerTests(BaseTestCase): results = service.get_rates(account, cache=False) results = service.rate_method(results, 30) rates = [ - {'price': decimal.Decimal('10.00'), 'quantity': 3}, - {'price': decimal.Decimal('9.00'), 'quantity': 6}, - {'price': decimal.Decimal('1.00'), 'quantity': 21} + { + 'price': decimal.Decimal('10.00'), + 'quantity': 3 + }, { + 'price': decimal.Decimal('9.00'), + 'quantity': 6 + }, { + 'price': decimal.Decimal('1.00'), + 'quantity': 21 + } ] for rate, result in zip(rates, results): self.assertEqual(rate['price'], result.price) diff --git a/orchestra/contrib/systemusers/backends.py b/orchestra/contrib/systemusers/backends.py index 4cca82f2..67f89408 100644 --- a/orchestra/contrib/systemusers/backends.py +++ b/orchestra/contrib/systemusers/backends.py @@ -32,9 +32,16 @@ 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 --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 %(user)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s || { + # User is logged in, kill and retry + if [[ $? -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 + fi + } fi mkdir -p %(base_home)s chmod 750 %(base_home)s @@ -43,7 +50,9 @@ class UNIXUserBackend(ServiceController): if context['home'] != context['base_home']: self.append(textwrap.dedent(""" if [[ $(mount | grep "^$(df %(home)s|grep '^/')\s" | grep acl) ]]; then + # Accountn group as the owner chown %(mainuser)s:%(mainuser)s %(home)s + chmod g+s %(home)s # Home access setfacl -m u:%(user)s:--x '%(mainuser_home)s' # Grant perms to future files within the directory diff --git a/orchestra/contrib/systemusers/forms.py b/orchestra/contrib/systemusers/forms.py index cfca1b57..47c734ef 100644 --- a/orchestra/contrib/systemusers/forms.py +++ b/orchestra/contrib/systemusers/forms.py @@ -33,44 +33,46 @@ class SystemUserFormMixin(object): self.fields['home'].widget = forms.Select(choices=choices) if self.instance.pk and (self.instance.is_main or self.instance.has_shell): # hidde home option for shell users - self.fields['home'].widget = forms.HiddenInput() - self.fields['directory'].widget = forms.HiddenInput() + self.fields['home'].widget.input_type = 'hidden' + self.fields['directory'].widget.input_type = 'hidden' elif self.instance.pk and (self.instance.get_base_home() == self.instance.home): self.fields['directory'].widget = forms.HiddenInput() else: self.fields['directory'].widget = forms.TextInput(attrs={'size':'70'}) if not self.instance.pk or not self.instance.is_main: # Some javascript for hidde home/directory inputs when convinient - self.fields['shell'].widget.attrs = { - 'onChange': textwrap.dedent("""\ - field = $(".field-home, .field-directory"); - input = $("#id_home, #id_directory"); - if ($.inArray(this.value, %s) < 0) { - field.addClass("hidden"); - } else { - field.removeClass("hidden"); - input.removeAttr("type"); - };""" % str(list(settings.SYSTEMUSERS_DISABLED_SHELLS))) - } - self.fields['home'].widget.attrs = { - 'onChange': textwrap.dedent("""\ - field = $(".field-box.field-directory"); - input = $("#id_directory"); - if (this.value.search("%s") > 0) { - field.addClass("hidden"); + self.fields['shell'].widget.attrs['onChange'] = textwrap.dedent("""\ + field = $(".field-home, .field-directory"); + input = $("#id_home, #id_directory"); + if ($.inArray(this.value, %s) < 0) { + field.addClass("hidden"); } else { field.removeClass("hidden"); input.removeAttr("type"); - };""" % username) - } + };""" % str(list(settings.SYSTEMUSERS_DISABLED_SHELLS)) + ) + self.fields['home'].widget.attrs['onChange'] = textwrap.dedent("""\ + field = $(".field-box.field-directory"); + input = $("#id_directory"); + if (this.value.search("%s") > 0) { + field.addClass("hidden"); + } else { + field.removeClass("hidden"); + input.removeAttr("type"); + };""" % username + ) def clean(self): super(SystemUserFormMixin, self).clean() cleaned_data = self.cleaned_data home = cleaned_data.get('home') + shell = cleaned_data.get('shell') if home and self.MOCK_USERNAME in home: username = cleaned_data.get('username', '') cleaned_data['home'] = home.replace(self.MOCK_USERNAME, username) + elif home and shell not in settings.SYSTEMUSERS_DISABLED_SHELLS: + cleaned_data['home'] = '' + cleaned_data['directory'] = '' validate_home(self.instance, cleaned_data, self.account) return cleaned_data diff --git a/orchestra/contrib/systemusers/validators.py b/orchestra/contrib/systemusers/validators.py index 95e9714c..3c5f0839 100644 --- a/orchestra/contrib/systemusers/validators.py +++ b/orchestra/contrib/systemusers/validators.py @@ -1,6 +1,7 @@ import os from django.core.exceptions import ValidationError +from django.utils.translation import ugettext_lazy as _ from orchestra.contrib.orchestration import Operation diff --git a/orchestra/utils/tests.py b/orchestra/utils/tests.py index 75a73d46..98b75ff5 100644 --- a/orchestra/utils/tests.py +++ b/orchestra/utils/tests.py @@ -7,7 +7,6 @@ from django.contrib.auth import BACKEND_SESSION_KEY, SESSION_KEY from django.contrib.sessions.backends.db import SessionStore from django.core.urlresolvers import reverse from django.test import LiveServerTestCase, TestCase -from orm.api import Api from selenium.webdriver.firefox.webdriver import WebDriver from xvfbwrapper import Xvfb @@ -88,6 +87,7 @@ class BaseLiveServerTestCase(AppDependencyMixin, LiveServerTestCase): return Account.objects.create_user(username, password=password, email='orchestra@orchestra.org') def setUp(self): + from orm.api import Api super(BaseLiveServerTestCase, self).setUp() self.rest = Api(self.live_server_url + '/api/') self.rest.enable_logging() diff --git a/requirements.txt b/requirements.txt index 7ee081dd..aa074415 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ django==1.8.1 django-celery-email==1.0.4 django-fluent-dashboard==0.5 -https://bitbucket.org/izi/django-admin-tools/get/a0abfffd76a0.zip +https://github.com/glic3rinu/django-admin-tools/archive/master.zip IPy==0.81 django-extensions==1.5.2 django-transaction-signals==1.0.0 diff --git a/scripts/container/deploy.sh b/scripts/container/deploy.sh index 94a08e59..d894cc3d 100755 --- a/scripts/container/deploy.sh +++ b/scripts/container/deploy.sh @@ -94,7 +94,6 @@ chown $USER:$USER /home/orchestra/panel/orchestra.log # admin_tools needs accounts and does not have migrations if [[ ! $(sudo su postgres -c "psql orchestra -q -c 'SELECT * FROM accounts_account LIMIT 1;' 2> /dev/null") ]]; then - surun "$PYTHON_BIN $MANAGE migrate --noinput accounts" surun "$PYTHON_BIN $MANAGE migrate --noinput" else surun "$PYTHON_BIN $MANAGE postupgradeorchestra --from $CURRENT_VERSION"