From c8ceff0358de5ee48a3a943a9030d65efb6ee03f Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Fri, 5 Jun 2015 09:57:06 +0000 Subject: [PATCH] Fixed PHP timeout option merging bug --- TODO.md | 3 +++ orchestra/contrib/webapps/admin.py | 2 +- orchestra/contrib/webapps/backends/php.py | 4 ++-- orchestra/contrib/webapps/models.py | 14 ++------------ orchestra/contrib/webapps/types/__init__.py | 6 +++--- orchestra/contrib/webapps/types/php.py | 16 +++++++++++++++- 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/TODO.md b/TODO.md index 67d4336a..7f20be38 100644 --- a/TODO.md +++ b/TODO.md @@ -421,3 +421,6 @@ serailzer self.instance on create. # use namedtuples! # Negative transactionsx + + +# check certificate: websites directive ssl + domains search on miscellaneous diff --git a/orchestra/contrib/webapps/admin.py b/orchestra/contrib/webapps/admin.py index d592f7a1..7484790e 100644 --- a/orchestra/contrib/webapps/admin.py +++ b/orchestra/contrib/webapps/admin.py @@ -40,7 +40,7 @@ class WebAppOptionInline(admin.TabularInline): webapp_modeladmin = get_modeladmin(self.parent_model) plugin_value = webapp_modeladmin.get_plugin_value(request) plugin = AppType.get(plugin_value) - kwargs['choices'] = plugin.get_options_choices() + kwargs['choices'] = plugin.get_group_options_choices() # Help text based on select widget target = 'this.id.replace("name", "value")' kwargs['widget'] = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT) diff --git a/orchestra/contrib/webapps/backends/php.py b/orchestra/contrib/webapps/backends/php.py index e9d5c739..b8586d59 100644 --- a/orchestra/contrib/webapps/backends/php.py +++ b/orchestra/contrib/webapps/backends/php.py @@ -163,7 +163,7 @@ class PHPBackend(WebAppServiceMixin, ServiceController): super(PHPBackend, self).commit() def get_fpm_config(self, webapp, context): - options = webapp.get_options(merge=self.MERGE) + options = webapp.type_instance.get_options() context.update({ 'init_vars': webapp.type_instance.get_php_init_vars(merge=self.MERGE), 'max_children': options.get('processes', settings.WEBAPPS_FPM_DEFAULT_MAX_CHILDREN), @@ -217,7 +217,7 @@ class PHPBackend(WebAppServiceMixin, ServiceController): exec %(php_binary_path)s%(php_init_vars)s""") % context def get_fcgid_cmd_options(self, webapp, context): - options = webapp.get_options(merge=self.MERGE) + options = webapp.type_instance.get_options() maps = OrderedDict( MaxProcesses=options.get('processes', None), IOTimeout=options.get('timeout', None), diff --git a/orchestra/contrib/webapps/models.py b/orchestra/contrib/webapps/models.py index 80a26271..95fdeca6 100644 --- a/orchestra/contrib/webapps/models.py +++ b/orchestra/contrib/webapps/models.py @@ -55,17 +55,7 @@ class WebApp(models.Model): a = apptype.clean_data() self.data = apptype.clean_data() - @cached - def get_options(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS): - kwargs = { - 'webapp_id': self.pk, - } - if merge: - kwargs = { - 'webapp__account': self.account_id, - 'webapp__type': self.type, - 'webapp__data__contains': '"php_version":"%s"' % self.data['php_version'], - } + def get_options(self, **kwargs): options = OrderedDict() qs = WebAppOption.objects.filter(**kwargs) for name, value in qs.values_list('name', 'value').order_by('name'): @@ -102,7 +92,7 @@ class WebApp(models.Model): class WebAppOption(models.Model): webapp = models.ForeignKey(WebApp, verbose_name=_("Web application"), related_name='options') - name = models.CharField(_("name"), max_length=128, choices=AppType.get_options_choices()) + name = models.CharField(_("name"), max_length=128, choices=AppType.get_group_options_choices()) value = models.CharField(_("value"), max_length=256) class Meta: diff --git a/orchestra/contrib/webapps/types/__init__.py b/orchestra/contrib/webapps/types/__init__.py index 43f40be6..69ab2f22 100644 --- a/orchestra/contrib/webapps/types/__init__.py +++ b/orchestra/contrib/webapps/types/__init__.py @@ -39,7 +39,7 @@ class AppType(plugins.Plugin): @classmethod @cached - def get_options(cls): + def get_group_options(cls): """ Get enabled options based on cls.option_groups """ groups = AppOption.get_option_groups() options = [] @@ -52,11 +52,11 @@ class AppType(plugins.Plugin): return options @classmethod - def get_options_choices(cls): + def get_group_options_choices(cls): """ Generates grouped choices ready to use in Field.choices """ # generators can not be @cached yield (None, '-------') - for group, options in cls.get_options(): + for group, options in cls.get_group_options(): if group is None: for option in options: yield (option.name, option.verbose_name) diff --git a/orchestra/contrib/webapps/types/php.py b/orchestra/contrib/webapps/types/php.py index 81595d07..b22340c5 100644 --- a/orchestra/contrib/webapps/types/php.py +++ b/orchestra/contrib/webapps/types/php.py @@ -59,10 +59,24 @@ class PHPApp(AppType): def get_detail(self): return self.instance.data.get('php_version', '') + @cached + def get_options(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS): + """ adapter to webapp.get_options that performs merging of PHP options """ + kwargs = { + 'webapp_id': self.instance.pk, + } + if merge: + kwargs = { + # webapp__type is not used because wordpress != php != symlink... + 'webapp__account': self.instance.account_id, + 'webapp__data__contains': '"php_version":"%s"' % self.instance.data['php_version'], + } + return self.instance.get_options(**kwargs) + def get_php_init_vars(self, merge=settings.WEBAPPS_MERGE_PHP_WEBAPPS): """ Prepares PHP options for inclusion on php.ini """ init_vars = OrderedDict() - options = self.instance.get_options(merge=merge) + options = self.get_options(merge=merge) php_version_number = float(self.get_php_version_number()) timeout = None for name, value in options.items():