示例#1
0
文件: admin.py 项目: rajivraj/vmc
    def run_configs(self, request, queryset):
        started = 0
        dropped = 0

        for config in queryset:
            if not workflow_in_progress(
                    config
            ) and config.last_update_status != self.model.Status.PENDING.value:
                started += 1
                config.set_status(status=self.model.Status.PENDING)
                workflow = self.update_workflow(config)
                start_workflow(workflow, config)
            else:
                dropped += 1

        if started:
            self.message_user(
                request, '{0} config{1} {2} successfully run'.format(
                    started,
                    pluralize(started),
                    pluralize(started, 'was,were'),
                ))

        if dropped:
            self.message_user(
                request,
                '{0} config{1} {2} dropped because {3} already run'.format(
                    dropped, pluralize(dropped),
                    pluralize(dropped, 'was,were'),
                    pluralize(dropped, 'it is, there are')), messages.WARNING)

        if not started and not dropped:
            self.message_user(request,
                              'There are no configs to perform import')
示例#2
0
文件: admin.py 项目: rajivraj/vmc
 def has_delete_permission(self, request, obj=None):
     if obj:
         for tenant in obj.tenant_set.all():
             if workflow_in_progress(ConfigMock(tenant)):
                 return False
     return super().has_delete_permission(request, obj)
示例#3
0
文件: admin.py 项目: rajivraj/vmc
 def has_delete_permission(self, request, obj=None):
     if obj and workflow_in_progress(ConfigMock(obj)):
         return False
     return super().has_delete_permission(request, obj)
示例#4
0
文件: tests.py 项目: rajivraj/vmc
 def test_global_workflow_running(self):
     cache.add(ALL_TENANTS_KEY, True)
     self.assertTrue(workflow_in_progress(self.config))
示例#5
0
文件: tests.py 项目: rajivraj/vmc
    def test_tenant_workflow_running_global_check(self):
        cache.keys = MagicMock()
        cache.keys.return_value = True

        self.assertTrue(workflow_in_progress(self.config, True))
        cache.keys.assert_called_once_with('workflow-*')
示例#6
0
文件: tests.py 项目: rajivraj/vmc
    def test_no_global_workflow(self):
        cache.keys = MagicMock()
        cache.keys.return_value = False

        self.assertFalse(workflow_in_progress(self.config, True))
        cache.keys.assert_called_once_with('workflow-*')
示例#7
0
文件: tests.py 项目: rajivraj/vmc
 def test_no_workflow_in_progress(self):
     self.assertFalse(workflow_in_progress(self.config))