From d0c7c760af7caa10e0d3f7c00d4eb26a0b25889e Mon Sep 17 00:00:00 2001 From: Marc Date: Tue, 28 Oct 2014 09:51:27 +0000 Subject: [PATCH] Fixes on tests0 --- orchestra/apps/mailboxes/backends.py | 5 +++-- orchestra/apps/orchestration/manager.py | 1 + orchestra/apps/orders/helpers.py | 7 ++++++- orchestra/apps/services/handlers.py | 8 ++++---- orchestra/apps/systemusers/backends.py | 10 ++++++---- .../apps/systemusers/tests/functional_tests/tests.py | 12 ++++++++---- orchestra/apps/webapps/backends/phpfpm.py | 2 +- .../apps/webapps/tests/functional_tests/tests.py | 3 ++- 8 files changed, 31 insertions(+), 17 deletions(-) diff --git a/orchestra/apps/mailboxes/backends.py b/orchestra/apps/mailboxes/backends.py index 5150bd50..0ad80e50 100644 --- a/orchestra/apps/mailboxes/backends.py +++ b/orchestra/apps/mailboxes/backends.py @@ -51,6 +51,7 @@ class PasswdVirtualUserBackend(ServiceController): filtering = mailbox.get_filtering() if filtering: context['filtering'] = '# %(banner)s\n' + filtering + self.append("mkdir -p $(dirname '%(filtering_path)s')" % context) self.append("echo '%(filtering)s' > %(filtering_path)s" % context) else: self.append("rm -f %(filtering_path)s" % context) @@ -159,10 +160,10 @@ class PostfixAddressBackend(ServiceController): def exclude_virtual_alias_maps(self, context): self.append(textwrap.dedent(""" - if [[ $(grep "^%(email)s\s") ]]; then + if [[ $(grep "^%(email)s\s" %(virtual_alias_maps)s) ]]; then sed -i "/^%(email)s\s.*$/d" %(virtual_alias_maps)s UPDATED_VIRTUAL_ALIAS_MAPS=1 - fi""" + fi""" % context )) def save(self, address): diff --git a/orchestra/apps/orchestration/manager.py b/orchestra/apps/orchestration/manager.py index 7c770d88..86284f74 100644 --- a/orchestra/apps/orchestration/manager.py +++ b/orchestra/apps/orchestration/manager.py @@ -33,6 +33,7 @@ def close_connection(execute): try: log = execute(*args, **kwargs) except: + logger.error('EXCEPTION executing backend %s %s' % (str(args), str(kwargs))) raise else: # Using the wrapper function as threader messenger for the execute output diff --git a/orchestra/apps/orders/helpers.py b/orchestra/apps/orders/helpers.py index e543e0f0..4ee9513a 100644 --- a/orchestra/apps/orders/helpers.py +++ b/orchestra/apps/orders/helpers.py @@ -1,3 +1,5 @@ +from django.core.exceptions import ObjectDoesNotExist + from orchestra.apps.accounts.models import Account from orchestra.core import services @@ -16,7 +18,10 @@ def get_related_objects(origin, max_depth=2): yield getattr(node, field.name) for field in node._meta.fields: if field.rel: - yield getattr(node, field.name) + try: + yield getattr(node, field.name) + except ObjectDoesNotExist: + pass # BFS model relation transversal queue = [[origin]] diff --git a/orchestra/apps/services/handlers.py b/orchestra/apps/services/handlers.py index 3bb375bd..0dc8405e 100644 --- a/orchestra/apps/services/handlers.py +++ b/orchestra/apps/services/handlers.py @@ -61,10 +61,10 @@ class ServiceHandler(plugins.Plugin): return None value, unit = self.ignore_period.split('_') value = text2int(value) - if unit.lowe().startswith('day'): - return timedelta(days=value) - if unit.lowe().startswith('month'): - return timedelta(months=value) + if unit.lower().startswith('day'): + return datetime.timedelta(days=value) + if unit.lower().startswith('month'): + return datetime.timedelta(months=value) else: raise ValueError("Unknown unit %s" % unit) diff --git a/orchestra/apps/systemusers/backends.py b/orchestra/apps/systemusers/backends.py index 363c5176..c2a2ef30 100644 --- a/orchestra/apps/systemusers/backends.py +++ b/orchestra/apps/systemusers/backends.py @@ -22,11 +22,15 @@ class SystemUserBackend(ServiceController): usermod %(username)s --password '%(password)s' --shell %(shell)s %(groups_arg)s else useradd %(username)s --home %(home)s --password '%(password)s' --shell %(shell)s %(groups_arg)s - usermod -a -G %(username)s %(mainusername)s fi mkdir -p %(home)s chown %(username)s.%(username)s %(home)s""" % context )) + for member in settings.SYSTEMUSERS_DEFAULT_GROUP_MEMBERS: + context['member'] = member + self.append('usermod -a -G %(username)s %(member)s' % context) + if not user.is_main: + self.append('usermod -a -G %(username)s %(mainusername)s' % context) def delete(self, user): context = self.get_context(user) @@ -45,9 +49,7 @@ class SystemUserBackend(ServiceController): def get_groups(self, user): if user.is_main: return user.account.systemusers.exclude(username=user.username).values_list('username', flat=True) - groups = list(user.groups.values_list('username', flat=True)) - groups += list(settings.SYSTEMUSERS_DEFAULT_GROUP_MEMBERS) - return groups + return list(user.groups.values_list('username', flat=True)) def get_context(self, user): context = { diff --git a/orchestra/apps/systemusers/tests/functional_tests/tests.py b/orchestra/apps/systemusers/tests/functional_tests/tests.py index 40ac949f..1d88273e 100644 --- a/orchestra/apps/systemusers/tests/functional_tests/tests.py +++ b/orchestra/apps/systemusers/tests/functional_tests/tests.py @@ -263,7 +263,8 @@ class AdminSystemUserMixin(SystemUserMixin): @snapshot_on_error def delete_account(self, username): - self.admin_delete(self.account) + account = Account.objects.get(username=username) + self.admin_delete(account) @snapshot_on_error def disable(self, username): @@ -317,6 +318,10 @@ class AdminSystemUserTest(AdminSystemUserMixin, BaseLiveServerTestCase): password = self.selenium.find_element_by_id('id_password2') password.send_keys(account_password) + full_name = random_ascii(10) + full_name_field = self.selenium.find_element_by_id('id_full_name') + full_name_field.send_keys(full_name) + account_email = 'orchestra@orchestra.lan' email = self.selenium.find_element_by_id('id_email') email.send_keys(account_email) @@ -330,9 +335,8 @@ class AdminSystemUserTest(AdminSystemUserMixin, BaseLiveServerTestCase): email.submit() self.assertNotEqual(url, self.selenium.current_url) - account = Account.objects.get(username=account_username) self.addCleanup(self.delete_account, account_username) - self.assertEqual(0, sshr(self.MASTER_SERVER, "id %s" % account.username).return_code) + self.assertEqual(0, sshr(self.MASTER_SERVER, "id %s" % account_username).return_code) @snapshot_on_error def test_delete_account(self): @@ -368,4 +372,4 @@ class AdminSystemUserTest(AdminSystemUserMixin, BaseLiveServerTestCase): # Reenable for test cleanup self.account.is_active = True self.account.save() -# self.admin_login() + self.admin_login() diff --git a/orchestra/apps/webapps/backends/phpfpm.py b/orchestra/apps/webapps/backends/phpfpm.py index c5b6e62b..eb5e001a 100644 --- a/orchestra/apps/webapps/backends/phpfpm.py +++ b/orchestra/apps/webapps/backends/phpfpm.py @@ -30,7 +30,7 @@ class PHPFPMBackend(WebAppServiceMixin, ServiceController): def delete(self, webapp): context = self.get_context(webapp) - self.append("rm '%(fpm_config)s'" % context) + self.append("rm '%(fpm_path)s'" % context) self.delete_webapp_dir(context) def commit(self): diff --git a/orchestra/apps/webapps/tests/functional_tests/tests.py b/orchestra/apps/webapps/tests/functional_tests/tests.py index 2d991379..27466aba 100644 --- a/orchestra/apps/webapps/tests/functional_tests/tests.py +++ b/orchestra/apps/webapps/tests/functional_tests/tests.py @@ -99,7 +99,8 @@ class RESTWebAppMixin(object): @save_response_on_error def save_systemuser(self): - self.rest.systemusers.retrieve().get().save() + systemuser = self.rest.systemusers.retrieve().get() + systemuser.update(is_active=True) @save_response_on_error def add_webapp(self, name, options=[]):