1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

fix inventory import bug with enabled_var

This commit is contained in:
AlanCoding 2017-11-28 14:26:38 -05:00
parent 5602b5d2d7
commit 2c06bfc9ce
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
2 changed files with 36 additions and 1 deletions

View File

@ -347,7 +347,12 @@ class Command(BaseCommand):
enabled = bool(unicode(enabled_value) == unicode(enabled))
else:
enabled = bool(enabled)
return enabled
if enabled is default:
return None
elif isinstance(enabled, bool):
return enabled
else:
raise NotImplementedError('Value of enabled {} not understood.'.format(enabled))
def load_inventory_from_database(self):
'''

View File

@ -220,3 +220,33 @@ class TestINIImports:
def test_recursive_group_error(self, inventory):
cmd = inventory_import.Command()
cmd.handle(inventory_id=inventory.pk, source='doesnt matter')
@pytest.mark.django_db
@pytest.mark.inventory_import
class TestEnabledVar:
'''
Meaning of return values
None - import script did not give an indication of enablement
True - host is enabled
False - host is not enabled
'''
@pytest.fixture
def cmd(self):
cmd = inventory_import.Command()
cmd.enabled_var = 'foo.bar'
cmd.enabled_value = 'barfoo'
return cmd
def test_enabled_var_not_present(self, cmd):
assert cmd._get_enabled({'ansible_connection': 'local'}) is None
def test_enabled_dot_var_not_present(self, cmd):
assert cmd._get_enabled({'foo': 'barfoo'}) is None
def test_enabled_var_not_enabled_value(self, cmd):
assert cmd._get_enabled({'foo': {'bar': 'foooooo'}}) is False
def test_enabled_var_is_enabled_value(self, cmd):
assert cmd._get_enabled({'foo': {'bar': 'barfoo'}}) is True