diff --git a/awx/main/management/commands/_base_instance.py b/awx/main/management/commands/_base_instance.py index be2b0abd3c..c92fa3b640 100644 --- a/awx/main/management/commands/_base_instance.py +++ b/awx/main/management/commands/_base_instance.py @@ -21,6 +21,7 @@ class BaseCommandInstance(BaseCommand): def __init__(self): super(BaseCommandInstance, self).__init__() + self.enforce_primary_role = False self.enforce_roles = False self.enforce_hostname_set = False self.enforce_unique_find = False diff --git a/awx/main/tests/commands/__init__.py b/awx/main/tests/commands/__init__.py index 9c099516c1..683950169f 100644 --- a/awx/main/tests/commands/__init__.py +++ b/awx/main/tests/commands/__init__.py @@ -7,3 +7,5 @@ from .run_fact_cache_receiver import * # noqa from .commands_monolithic import * # noqa from .cleanup_facts import * # noqa from .age_deleted import * # noqa +from .remove_instance import * # noqa + diff --git a/awx/main/tests/commands/remove_instance.py b/awx/main/tests/commands/remove_instance.py new file mode 100644 index 0000000000..d93285ea7e --- /dev/null +++ b/awx/main/tests/commands/remove_instance.py @@ -0,0 +1,39 @@ +# Copyright (c) 2015 Ansible, Inc. +# All Rights Reserved + +# Python +import uuid + +# AWX +from awx.main.tests.base import BaseTest +from awx.main.tests.commands.base import BaseCommandMixin +from awx.main.models import * # noqa + +__all__ = ['RemoveInstanceCommandFunctionalTest'] + +class RemoveInstanceCommandFunctionalTest(BaseCommandMixin, BaseTest): + uuids = [] + instances = [] + + def setup_instances(self): + self.uuids = [uuid.uuid4().hex for x in range(0, 3)] + self.instances.append(Instance(uuid=settings.SYSTEM_UUID, primary=True, hostname='127.0.0.1')) + self.instances.append(Instance(uuid=self.uuids[0], primary=False, hostname='127.0.0.2')) + self.instances.append(Instance(uuid=self.uuids[1], primary=False, hostname='127.0.0.3')) + self.instances.append(Instance(uuid=self.uuids[2], primary=False, hostname='127.0.0.4')) + for x in self.instances: + x.save() + + def setUp(self): + super(RemoveInstanceCommandFunctionalTest, self).setUp() + self.create_test_license_file() + self.setup_instances() + self.setup_users() + + def test_default(self): + self.assertEqual(Instance.objects.filter(hostname="127.0.0.2").count(), 1) + result, stdout, stderr = self.run_command('remove_instance', hostname='127.0.0.2') + self.assertIsNone(result) + self.assertEqual(stdout, 'Successfully removed instance (uuid="%s",hostname="127.0.0.2",role="secondary").\n' % (self.uuids[0])) + self.assertEqual(Instance.objects.filter(hostname="127.0.0.2").count(), 0) +