From 6b5c4338cc91e96003d5aa741d46fbb3a621803c Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Wed, 30 Mar 2016 14:35:32 -0400 Subject: [PATCH 1/5] Removed superfluous method definition --- awx/api/serializers.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index a35dae2a7a..1aa0f88572 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -521,10 +521,6 @@ class BaseSerializer(serializers.ModelSerializer): raise ValidationError(d) return attrs - def to_representation(self, obj): - ret = super(BaseSerializer, self).to_representation(obj) - return ret - class EmptySerializer(serializers.Serializer): pass From 156aeb931f5b7fa47e6806aae54ecbb06f8face7 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Wed, 30 Mar 2016 15:40:39 -0400 Subject: [PATCH 2/5] count -> exists --- awx/main/access.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/access.py b/awx/main/access.py index 36bfa33da0..85f716fa98 100644 --- a/awx/main/access.py +++ b/awx/main/access.py @@ -644,7 +644,7 @@ class ProjectAccess(BaseAccess): if self.user.is_superuser: return True qs = Organization.accessible_objects(self.user, ALL_PERMISSIONS) - return bool(qs.count() > 0) + return qs.exists() def can_change(self, obj, data): if self.user.is_superuser: From 534faf011c3f7faa9323fdbb21934b45c30d4683 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Wed, 30 Mar 2016 15:50:58 -0400 Subject: [PATCH 3/5] count->exists --- awx/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/api/views.py b/awx/api/views.py index 8d7332ef4c..f797d4afe9 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -569,7 +569,7 @@ class OrganizationList(ListCreateAPIView): # by the license, then we are only willing to create this organization # if no organizations exist in the system. if (not feature_enabled('multiple_organizations') and - self.model.objects.count() > 0): + self.model.objects.exists()): raise LicenseForbids('Your Tower license only permits a single ' 'organization to exist.') From 728c41f03a1ee51bbef6ec197628da8c974bb04c Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Thu, 31 Mar 2016 09:35:05 -0400 Subject: [PATCH 4/5] Split active flag removal migration into two migrations Re #1344 https://docs.djangoproject.com/en/1.8/ref/migration-operations/#runpython --- .../migrations/0006_v300_active_flag_cleanup.py | 16 ++++++++++++++++ ...moval.py => 0007_v300_active_flag_removal.py} | 5 +---- ...rbac_changes.py => 0008_v300_rbac_changes.py} | 2 +- ...igrations.py => 0009_v300_rbac_migrations.py} | 2 +- ... => 0010_v300_create_system_job_templates.py} | 2 +- ...d.py => 0011_v300_credential_domain_field.py} | 2 +- ...eate_labels.py => 0012_v300_create_labels.py} | 2 +- 7 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 awx/main/migrations/0006_v300_active_flag_cleanup.py rename awx/main/migrations/{0006_v300_active_flag_removal.py => 0007_v300_active_flag_removal.py} (89%) rename awx/main/migrations/{0007_v300_rbac_changes.py => 0008_v300_rbac_changes.py} (99%) rename awx/main/migrations/{0008_v300_rbac_migrations.py => 0009_v300_rbac_migrations.py} (92%) rename awx/main/migrations/{0009_v300_create_system_job_templates.py => 0010_v300_create_system_job_templates.py} (98%) rename awx/main/migrations/{0010_v300_credential_domain_field.py => 0011_v300_credential_domain_field.py} (88%) rename awx/main/migrations/{0011_v300_create_labels.py => 0012_v300_create_labels.py} (97%) diff --git a/awx/main/migrations/0006_v300_active_flag_cleanup.py b/awx/main/migrations/0006_v300_active_flag_cleanup.py new file mode 100644 index 0000000000..59dee6c3da --- /dev/null +++ b/awx/main/migrations/0006_v300_active_flag_cleanup.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from awx.main.migrations import _cleanup_deleted as cleanup_deleted +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0005_v300_migrate_facts'), + ] + + operations = [ + migrations.RunPython(cleanup_deleted.cleanup_deleted), + ] diff --git a/awx/main/migrations/0006_v300_active_flag_removal.py b/awx/main/migrations/0007_v300_active_flag_removal.py similarity index 89% rename from awx/main/migrations/0006_v300_active_flag_removal.py rename to awx/main/migrations/0007_v300_active_flag_removal.py index 9f2dfb6534..888b63d85f 100644 --- a/awx/main/migrations/0006_v300_active_flag_removal.py +++ b/awx/main/migrations/0007_v300_active_flag_removal.py @@ -1,19 +1,16 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from awx.main.migrations import _cleanup_deleted as cleanup_deleted from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ('main', '0005_v300_migrate_facts'), + ('main', '0006_v300_active_flag_cleanup'), ] operations = [ - migrations.RunPython(cleanup_deleted.cleanup_deleted), - migrations.RemoveField( model_name='credential', name='active', diff --git a/awx/main/migrations/0007_v300_rbac_changes.py b/awx/main/migrations/0008_v300_rbac_changes.py similarity index 99% rename from awx/main/migrations/0007_v300_rbac_changes.py rename to awx/main/migrations/0008_v300_rbac_changes.py index cfe8432da9..759b362ba2 100644 --- a/awx/main/migrations/0007_v300_rbac_changes.py +++ b/awx/main/migrations/0008_v300_rbac_changes.py @@ -14,7 +14,7 @@ class Migration(migrations.Migration): ('taggit', '0002_auto_20150616_2121'), ('contenttypes', '0002_remove_content_type_name'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('main', '0006_v300_active_flag_removal'), + ('main', '0007_v300_active_flag_removal'), ] operations = [ diff --git a/awx/main/migrations/0008_v300_rbac_migrations.py b/awx/main/migrations/0009_v300_rbac_migrations.py similarity index 92% rename from awx/main/migrations/0008_v300_rbac_migrations.py rename to awx/main/migrations/0009_v300_rbac_migrations.py index db0f197e8d..b652c1067a 100644 --- a/awx/main/migrations/0008_v300_rbac_migrations.py +++ b/awx/main/migrations/0009_v300_rbac_migrations.py @@ -8,7 +8,7 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ('main', '0007_v300_rbac_changes'), + ('main', '0008_v300_rbac_changes'), ] operations = [ diff --git a/awx/main/migrations/0009_v300_create_system_job_templates.py b/awx/main/migrations/0010_v300_create_system_job_templates.py similarity index 98% rename from awx/main/migrations/0009_v300_create_system_job_templates.py rename to awx/main/migrations/0010_v300_create_system_job_templates.py index b95fac8079..665b967ff3 100644 --- a/awx/main/migrations/0009_v300_create_system_job_templates.py +++ b/awx/main/migrations/0010_v300_create_system_job_templates.py @@ -107,7 +107,7 @@ def create_system_job_templates(apps, schema_editor): class Migration(migrations.Migration): dependencies = [ - ('main', '0008_v300_rbac_migrations'), + ('main', '0009_v300_rbac_migrations'), ] operations = [ diff --git a/awx/main/migrations/0010_v300_credential_domain_field.py b/awx/main/migrations/0011_v300_credential_domain_field.py similarity index 88% rename from awx/main/migrations/0010_v300_credential_domain_field.py rename to awx/main/migrations/0011_v300_credential_domain_field.py index fc77d9999e..7b8aa0fa49 100644 --- a/awx/main/migrations/0010_v300_credential_domain_field.py +++ b/awx/main/migrations/0011_v300_credential_domain_field.py @@ -7,7 +7,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('main', '0009_v300_create_system_job_templates'), + ('main', '0010_v300_create_system_job_templates'), ] operations = [ diff --git a/awx/main/migrations/0011_v300_create_labels.py b/awx/main/migrations/0012_v300_create_labels.py similarity index 97% rename from awx/main/migrations/0011_v300_create_labels.py rename to awx/main/migrations/0012_v300_create_labels.py index 77c58b0139..ae1b9df932 100644 --- a/awx/main/migrations/0011_v300_create_labels.py +++ b/awx/main/migrations/0012_v300_create_labels.py @@ -12,7 +12,7 @@ class Migration(migrations.Migration): dependencies = [ ('taggit', '0002_auto_20150616_2121'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('main', '0010_v300_credential_domain_field'), + ('main', '0011_v300_credential_domain_field'), ] operations = [ From c61c8b2b45a211a748397ee609e9de1e0cde0a3f Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Thu, 31 Mar 2016 09:48:14 -0400 Subject: [PATCH 5/5] Revert accidental active_flag removal changes in south_migrations Fixes #1349 --- awx/main/south_migrations/0018_v14_changes.py | 10 +++++----- awx/main/south_migrations/0044_v1411_changes.py | 2 +- awx/main/south_migrations/0070_v221_changes.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/awx/main/south_migrations/0018_v14_changes.py b/awx/main/south_migrations/0018_v14_changes.py index 980c4293d6..ea4fde18ab 100644 --- a/awx/main/south_migrations/0018_v14_changes.py +++ b/awx/main/south_migrations/0018_v14_changes.py @@ -13,7 +13,7 @@ class Migration(DataMigration): # and orm['appname.ModelName'] for models in other applications. # Refresh has_active_failures for all hosts. - for host in orm.Host.objects: + for host in orm.Host.objects.filter(active=True): has_active_failures = bool(host.last_job_host_summary and host.last_job_host_summary.job.active and host.last_job_host_summary.failed) @@ -30,9 +30,9 @@ class Migration(DataMigration): for subgroup in group.children.exclude(pk__in=except_group_pks): qs = qs | get_all_hosts_for_group(subgroup, except_group_pks) return qs - for group in orm.Group.objects: + for group in orm.Group.objects.filter(active=True): all_hosts = get_all_hosts_for_group(group) - failed_hosts = all_hosts.filter( + failed_hosts = all_hosts.filter(active=True, last_job_host_summary__job__active=True, last_job_host_summary__failed=True) hosts_with_active_failures = failed_hosts.count() @@ -49,8 +49,8 @@ class Migration(DataMigration): # Now update has_active_failures and hosts_with_active_failures for all # inventories. - for inventory in orm.Inventory.objects: - failed_hosts = inventory.hosts.filter( has_active_failures=True) + for inventory in orm.Inventory.objects.filter(active=True): + failed_hosts = inventory.hosts.filter(active=True, has_active_failures=True) hosts_with_active_failures = failed_hosts.count() has_active_failures = bool(hosts_with_active_failures) changed = False diff --git a/awx/main/south_migrations/0044_v1411_changes.py b/awx/main/south_migrations/0044_v1411_changes.py index c58dc8d155..137f4cb220 100644 --- a/awx/main/south_migrations/0044_v1411_changes.py +++ b/awx/main/south_migrations/0044_v1411_changes.py @@ -8,7 +8,7 @@ from django.db import models class Migration(DataMigration): def forwards(self, orm): - for iu in orm.InventoryUpdate.objects: + for iu in orm.InventoryUpdate.objects.filter(active=True): if iu.inventory_source is None or iu.inventory_source.group is None or iu.inventory_source.inventory is None: continue iu.name = "%s (%s)" % (iu.inventory_source.group.name, iu.inventory_source.inventory.name) diff --git a/awx/main/south_migrations/0070_v221_changes.py b/awx/main/south_migrations/0070_v221_changes.py index c27edf8e9c..0bc36f27ac 100644 --- a/awx/main/south_migrations/0070_v221_changes.py +++ b/awx/main/south_migrations/0070_v221_changes.py @@ -12,7 +12,7 @@ from django.conf import settings class Migration(DataMigration): def forwards(self, orm): - for j in orm.UnifiedJob.objects: + for j in orm.UnifiedJob.objects.filter(active=True): cur = connection.cursor() stdout_filename = os.path.join(settings.JOBOUTPUT_ROOT, "%d-%s.out" % (j.pk, str(uuid.uuid1()))) fd = open(stdout_filename, 'w')