From 237a66191295cce2cd52d78bcdb7cbe57e399e56 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 26 Jun 2015 15:22:35 -0400 Subject: [PATCH 1/4] Fix verbage around why we are disallowing removing a primary --- awx/main/management/commands/remove_instance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/management/commands/remove_instance.py b/awx/main/management/commands/remove_instance.py index bcbd757b41..6eb5c35a02 100644 --- a/awx/main/management/commands/remove_instance.py +++ b/awx/main/management/commands/remove_instance.py @@ -33,7 +33,7 @@ class Command(BaseCommandInstance): # Sanity check: Do not remove the primary instance. if instance.primary: - raise CommandError('I cowardly refuse to remove the primary instance %s.' % instance_str(instance)) + raise CommandError('Can not remove primary instance %s. Another instance must be promoted to primary first.' % instance_str(instance)) # Remove the instance. instance.delete() From 80a6f22c0cddad0303d59d77d1309dd941eca2ed Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 26 Jun 2015 15:23:07 -0400 Subject: [PATCH 2/4] Move HA license check logic to the promotion step and allow registering HA instances. Registration is allowed but promotion/demotion is not allowed without the HA feature --- awx/main/management/commands/register_instance.py | 8 -------- awx/main/management/commands/update_instance.py | 6 +++++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/awx/main/management/commands/register_instance.py b/awx/main/management/commands/register_instance.py index 5072f5195e..942eb9af4d 100644 --- a/awx/main/management/commands/register_instance.py +++ b/awx/main/management/commands/register_instance.py @@ -3,7 +3,6 @@ from django.core.management.base import CommandError -from awx.api.license import feature_enabled from awx.main.management.commands._base_instance import BaseCommandInstance from awx.main.models import Instance @@ -33,13 +32,6 @@ class Command(BaseCommandInstance): uuid = self.get_UUID() - # Are we attempting to register a secondary instance? - # If so, we are only willing to do that if the Tower license allows - # it. - if self.is_option_secondary() and not feature_enabled('ha'): - raise CommandError('Your Tower license does not permit creation ' - 'of secondary instances.') - # Is there an existing record for this machine? If so, retrieve that record and look for issues. try: instance = Instance.objects.get(uuid=uuid) diff --git a/awx/main/management/commands/update_instance.py b/awx/main/management/commands/update_instance.py index cd3e53f711..ee8d359f8d 100644 --- a/awx/main/management/commands/update_instance.py +++ b/awx/main/management/commands/update_instance.py @@ -5,7 +5,7 @@ from django.core.management.base import CommandError from django.db import transaction from awx.main.management.commands._base_instance import BaseCommandInstance - +from awx.api.license import feature_enabled from awx.main.models import Instance instance_str = BaseCommandInstance.instance_str @@ -33,6 +33,10 @@ class Command(BaseCommandInstance): def handle(self, *args, **options): super(Command, self).handle(*args, **options) + # You can only promote/demote if your license allows HA + if feature_enabled('ha'): + raise CommandError('Your Tower license does not permit promoting a secondary instance') + # Is there an existing record for this machine? If so, retrieve that record and look for issues. try: instance = Instance.objects.get(**self.get_unique_fields()) From 05f56c805a0b382eac7c1df775b0a866330f4d51 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 26 Jun 2015 15:28:41 -0400 Subject: [PATCH 3/4] Logic should check for the condition where HA is NOT enabled --- awx/main/management/commands/update_instance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/management/commands/update_instance.py b/awx/main/management/commands/update_instance.py index ee8d359f8d..7ffffa62a7 100644 --- a/awx/main/management/commands/update_instance.py +++ b/awx/main/management/commands/update_instance.py @@ -34,7 +34,7 @@ class Command(BaseCommandInstance): super(Command, self).handle(*args, **options) # You can only promote/demote if your license allows HA - if feature_enabled('ha'): + if not feature_enabled('ha'): raise CommandError('Your Tower license does not permit promoting a secondary instance') # Is there an existing record for this machine? If so, retrieve that record and look for issues. From 414394afa0c4c3f8de6396c8ba9fe0cf8236cf36 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 26 Jun 2015 15:35:33 -0400 Subject: [PATCH 4/4] can not -> cannot (even though they are both correct) --- awx/main/management/commands/remove_instance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/management/commands/remove_instance.py b/awx/main/management/commands/remove_instance.py index 6eb5c35a02..d8712137be 100644 --- a/awx/main/management/commands/remove_instance.py +++ b/awx/main/management/commands/remove_instance.py @@ -33,7 +33,7 @@ class Command(BaseCommandInstance): # Sanity check: Do not remove the primary instance. if instance.primary: - raise CommandError('Can not remove primary instance %s. Another instance must be promoted to primary first.' % instance_str(instance)) + raise CommandError('Cannot remove primary instance %s. Another instance must be promoted to primary first.' % instance_str(instance)) # Remove the instance. instance.delete()