diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 6ca73cf6a0..e48f12e6c4 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1484,7 +1484,8 @@ class CredentialSerializer(BaseSerializer): class Meta: model = Credential fields = ('*', 'user', 'team', 'kind', 'cloud', 'host', 'username', - 'password', 'security_token', 'project', 'ssh_key_data', 'ssh_key_unlock', + 'password', 'security_token', 'project', 'domain', + 'ssh_key_data', 'ssh_key_unlock', 'become_method', 'become_username', 'become_password', 'vault_password') diff --git a/awx/main/migrations/0007_v300_changes.py b/awx/main/migrations/0007_v300_changes.py new file mode 100644 index 0000000000..f6d0ec1410 --- /dev/null +++ b/awx/main/migrations/0007_v300_changes.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0006_v300_changes'), + ] + + operations = [ + migrations.AddField( + model_name='credential', + name='domain', + field=models.CharField(default=b'', help_text='The identifier for the domain.', max_length=100, verbose_name='Domain', blank=True), + ), + ] diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index 82e0f576e1..328c738cc0 100644 --- a/awx/main/models/credential.py +++ b/awx/main/models/credential.py @@ -114,6 +114,13 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique): verbose_name=_('Project'), help_text=_('The identifier for the project.'), ) + domain = models.CharField( + blank=True, + default='', + max_length=100, + verbose_name=_('Domain'), + help_text=_('The identifier for the domain.'), + ) ssh_key_data = models.TextField( blank=True, default='', diff --git a/awx/main/tasks.py b/awx/main/tasks.py index ec34886632..ba54e17e9b 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -712,6 +712,8 @@ class RunJob(BaseTask): username=credential.username, password=decrypt_field(credential, "password"), project_name=credential.project) + if credential.domain not in (None, ''): + openstack_auth['domain_name'] = credential.domain openstack_data = { 'clouds': { 'devstack': { @@ -1151,6 +1153,8 @@ class RunInventoryUpdate(BaseTask): username=credential.username, password=decrypt_field(credential, "password"), project_name=credential.project) + if credential.domain not in (None, ''): + openstack_auth['domain_name'] = credential.domain private_state = str(inventory_update.source_vars_dict.get('private', 'true')) # Retrieve cache path from inventory update vars if available, # otherwise create a temporary cache path only for this update. diff --git a/awx/main/tests/old/inventory.py b/awx/main/tests/old/inventory.py index 5c48f30bb6..ccfb7138c2 100644 --- a/awx/main/tests/old/inventory.py +++ b/awx/main/tests/old/inventory.py @@ -2068,6 +2068,26 @@ class InventoryUpdatesTest(BaseTransactionTest): self.check_inventory_source(inventory_source) self.assertFalse(self.group.all_hosts.filter(instance_id='').exists()) + def test_update_from_openstack_v3(self): + # Check that update works with Keystone v3 identity service + api_url = getattr(settings, 'TEST_OPENSTACK_HOST_V3', '') + api_user = getattr(settings, 'TEST_OPENSTACK_USER', '') + api_password = getattr(settings, 'TEST_OPENSTACK_PASSWORD', '') + api_project = getattr(settings, 'TEST_OPENSTACK_PROJECT', '') + api_domain = getattr(settings, 'TEST_OPENSTACK_DOMAIN', '') + if not all([api_url, api_user, api_password, api_project, api_domain]): + self.skipTest("No test openstack v3 credentials defined") + self.create_test_license_file() + credential = Credential.objects.create(kind='openstack', + host=api_url, + username=api_user, + password=api_password, + project=api_project, + domain=api_domain) + inventory_source = self.update_inventory_source(self.group, source='openstack', credential=credential) + self.check_inventory_source(inventory_source) + self.assertFalse(self.group.all_hosts.filter(instance_id='').exists()) + def test_update_from_azure(self): source_username = getattr(settings, 'TEST_AZURE_USERNAME', '') source_key_data = getattr(settings, 'TEST_AZURE_KEY_DATA', '')