Skip to content

Commit

Permalink
Fix: Credential id set in operation was not sent to AWX
Browse files Browse the repository at this point in the history
Closes #790
  • Loading branch information
Sispheor committed Nov 20, 2024
1 parent 55b6e22 commit 306ef43
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
19 changes: 19 additions & 0 deletions service_catalog/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ def perform_processing(self, inventory_override=None, credentials_override=None,
"squest_host": settings.SQUEST_HOST,
"request": AdminRequestSerializer(self).data
}

# load default override from the operation
if inventory_override is None:
inventory_override = self.operation.default_inventory_id
if credentials_override is None:
credentials_override = self.operation.default_credentials_ids.split(",")
if tags_override is None:
tags_override = self.operation.default_tags.split(",")
if skip_tags_override is None:
skip_tags_override = self.operation.default_skip_tags.split(",")
if limit_override is None:
limit_override = self.operation.default_limits.split(",")
if verbosity_override is None:
verbosity_override = self.operation.default_verbosity
if job_type_override is None:
job_type_override = self.operation.default_job_type
if diff_mode_override is None:
diff_mode_override = self.operation.default_diff_mode

tower_job_id = None
try:
tower_job_id, error_message = self.operation.job_template.execute(extra_vars=tower_extra_vars,
Expand Down
39 changes: 39 additions & 0 deletions tests/test_service_catalog/test_models/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,42 @@ def test_date_submitted_not_update_on_save(self):
old_submitted_date = new_request.date_submitted
new_request.save()
self.assertEqual(old_submitted_date, new_request.date_submitted)

def setup_default_on_operation(self):
self.create_operation_test.default_inventory_id = 1
self.create_operation_test.default_limits = "machine_one,machine_two"
self.create_operation_test.default_tags = "tag1,tag2"
self.create_operation_test.default_skip_tags = "skipped_tag1,skipped_tag2"
self.create_operation_test.default_credentials_ids = "4,5"
self.create_operation_test.default_verbosity = "3"
self.create_operation_test.default_diff_mode = "new_diff"
self.create_operation_test.default_job_type = "new_job"
self.create_operation_test.save()

def test_perform_processing_uses_default_from_operation(self):
self.create_operation_test.auto_process = True
self.setup_default_on_operation()

with mock.patch("service_catalog.models.job_templates.JobTemplate.execute") as mock_job_execute:
mock_job_execute.return_value = 10, ""
self.test_request.accept(user=self.superuser)
args, called_args = mock_job_execute.call_args
self.assertEqual(called_args["inventory_override"],1)
self.assertEqual(called_args["credentials_override"],['4','5'])
self.assertEqual(called_args["tags_override"],["tag1", "tag2"])
self.assertEqual(called_args["skip_tags_override"],["skipped_tag1","skipped_tag2"])
self.assertEqual(called_args["limit_override"],["machine_one", "machine_two"])
self.assertEqual(called_args["verbosity_override"],"3")
self.assertEqual(called_args["job_type_override"],"new_job")
self.assertEqual(called_args["diff_mode_override"],"new_diff")

def test_perform_processing_uses_default_from_operation_override_on_accept(self):
# in this test we've set default credentials on the operation, but we override them on the process request page
self.setup_default_on_operation()
self.test_request.state = RequestState.PROCESSING
self.test_request.save()
with mock.patch("service_catalog.models.job_templates.JobTemplate.execute") as mock_job_execute:
mock_job_execute.return_value = 10, ""
self.test_request.perform_processing(inventory_override=3)
args, called_args = mock_job_execute.call_args
self.assertEqual(called_args["inventory_override"], 3)

0 comments on commit 306ef43

Please sign in to comment.