-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AAP-17357 is hard to maintain, only cover a subset of what AAP-24049 will do and finally complexify the refactoring of the Schema1 event managment, See: #1147)
- Loading branch information
Showing
8 changed files
with
10 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,135 +319,6 @@ def test_insert_set_fact_task(self): | |
self.assertTrue("ansible.builtin.set_fact" in data[0]) | ||
self.assertEqual(data[0]["ansible.builtin.set_fact"], merged_vars) | ||
|
||
def test_restore_original_task_names(self): | ||
single_task_prompt = "- name: Install ssh\n" | ||
multi_task_prompt = "# Install Apache & say hello [email protected]\n" | ||
multi_task_prompt_with_loop = ( | ||
"# Delete all virtual machines in my Azure resource group called 'melisa' that " | ||
"exists longer than 24 hours. Do not delete virtual machines that exists less " | ||
"than 24 hours." | ||
) | ||
multi_task_prompt_with_loop_extra_task = ( | ||
"# Delete all virtual machines in my Azure resource group " | ||
"& say hello to [email protected]" | ||
) | ||
|
||
multi_task_yaml = ( | ||
"- name: Install Apache\n ansible.builtin.apt:\n " | ||
"name: apache2\n state: latest\n- name: say hello [email protected]\n " | ||
"ansible.builtin.debug:\n msg: Hello there [email protected]\n" | ||
) | ||
multi_task_yaml_extra_task = ( | ||
"- name: Install Apache\n ansible.builtin.apt:\n " | ||
"name: apache2\n state: latest\n- name: say hello [email protected]\n " | ||
"ansible.builtin.debug:\n msg: Hello there [email protected]" | ||
"\n- name: say hi [email protected]\n " | ||
"ansible.builtin.debug:\n msg: Hello there [email protected]\n" | ||
) | ||
multi_task_yaml_with_loop = ( | ||
"- name: Delete all virtual machines in my " | ||
"Azure resource group called 'test' that exists longer than 24 hours. Do not " | ||
"delete virtual machines that exists less than 24 hours.\n" | ||
" azure.azcollection.azure_rm_virtualmachine:\n" | ||
' name: "{{ _name_ }}"\n state: absent\n resource_group: myResourceGroup\n' | ||
" vm_size: Standard_A0\n" | ||
' image: "{{ _image_ }}"\n loop:\n - name: "{{ vm_name }}"\n' | ||
' password: "{{ _password_ }}"\n' | ||
' user: "{{ vm_user }}"\n location: "{{ vm_location }}"\n' | ||
) | ||
multi_task_yaml_with_loop_extra_task = ( | ||
"- name: Delete all virtual machines in my Azure resource group\n" | ||
" azure.azcollection.azure_rm_virtualmachine:\n" | ||
' name: "{{ _name_ }}"\n state: absent\n resource_group: myResourceGroup\n' | ||
" vm_size: Standard_A0\n" | ||
' image: "{{ _image_ }}"\n loop:\n - name: "{{ vm_name }}"\n' | ||
' password: "{{ _password_ }}"\n' | ||
' user: "{{ vm_user }}"\n location: "{{ vm_location }}"\n' | ||
"- name: say hello to [email protected]\n " | ||
"ansible.builtin.debug:\n msg: Hello there [email protected]\n" | ||
) | ||
single_task_yaml = ( | ||
" ansible.builtin.package:\n name: openssh-server\n state: present\n when:\n" | ||
" - enable_ssh | bool\n - ansible_distribution == 'Ubuntu'" | ||
) | ||
expected_multi_task_yaml = ( | ||
"- name: Install Apache\n ansible.builtin.apt:\n " | ||
"name: apache2\n state: latest\n- name: say hello [email protected]\n " | ||
"ansible.builtin.debug:\n msg: Hello there [email protected]\n" | ||
) | ||
expected_multi_task_yaml_with_loop = ( | ||
"- name: Delete all virtual machines in my " | ||
"Azure resource group called 'melisa' that exists longer than 24 hours. Do not " | ||
"delete virtual machines that exists less than 24 hours.\n" | ||
" azure.azcollection.azure_rm_virtualmachine:\n" | ||
' name: "{{ _name_ }}"\n state: absent\n resource_group: myResourceGroup\n' | ||
" vm_size: Standard_A0\n" | ||
' image: "{{ _image_ }}"\n loop:\n - name: "{{ vm_name }}"\n' | ||
' password: "{{ _password_ }}"\n' | ||
' user: "{{ vm_user }}"\n location: "{{ vm_location }}"\n' | ||
) | ||
expected_multi_task_yaml_with_loop_extra_task = ( | ||
"- name: Delete all virtual machines in my Azure resource group\n" | ||
" azure.azcollection.azure_rm_virtualmachine:\n" | ||
' name: "{{ _name_ }}"\n state: absent\n resource_group: myResourceGroup\n' | ||
" vm_size: Standard_A0\n" | ||
' image: "{{ _image_ }}"\n loop:\n - name: "{{ vm_name }}"\n' | ||
' password: "{{ _password_ }}"\n' | ||
' user: "{{ vm_user }}"\n location: "{{ vm_location }}"\n' | ||
"- name: say hello to [email protected]\n " | ||
"ansible.builtin.debug:\n msg: Hello there [email protected]\n" | ||
) | ||
|
||
self.assertEqual( | ||
expected_multi_task_yaml, | ||
fmtr.restore_original_task_names(multi_task_yaml, multi_task_prompt), | ||
) | ||
|
||
with self.assertLogs(logger="root", level="ERROR") as log: | ||
fmtr.restore_original_task_names(multi_task_yaml_extra_task, multi_task_prompt), | ||
self.assertInLog( | ||
"There is no match for the enumerated prompt task in the suggestion yaml", log | ||
) | ||
|
||
self.assertEqual( | ||
expected_multi_task_yaml_with_loop, | ||
fmtr.restore_original_task_names( | ||
multi_task_yaml_with_loop, multi_task_prompt_with_loop | ||
), | ||
) | ||
|
||
self.assertEqual( | ||
expected_multi_task_yaml_with_loop_extra_task, | ||
fmtr.restore_original_task_names( | ||
multi_task_yaml_with_loop_extra_task, multi_task_prompt_with_loop_extra_task | ||
), | ||
) | ||
|
||
self.assertEqual( | ||
single_task_yaml, | ||
fmtr.restore_original_task_names(single_task_yaml, single_task_prompt), | ||
) | ||
|
||
self.assertEqual( | ||
"", | ||
fmtr.restore_original_task_names("", multi_task_prompt), | ||
) | ||
|
||
def test_restore_original_task_names_for_index_error(self): | ||
# The following prompt simulates a mismatch between requested tasks and received tasks | ||
multi_task_prompt = "# Install Apache\n" | ||
multi_task_yaml = ( | ||
"- name: Install Apache\n ansible.builtin.apt:\n " | ||
"name: apache2\n state: latest\n- name: say hello [email protected]\n " | ||
"ansible.builtin.debug:\n msg: Hello there [email protected]\n" | ||
) | ||
|
||
with self.assertLogs(logger="root", level="ERROR") as log: | ||
fmtr.restore_original_task_names(multi_task_yaml, multi_task_prompt) | ||
self.assertInLog( | ||
"There is no match for the enumerated prompt task in the suggestion yaml", log | ||
) | ||
|
||
def test_strip_task_preamble_from_multi_task_prompt_no_preamble_unchanged_multi(self): | ||
prompt = " # install ffmpeg" | ||
self.assertEqual(prompt, fmtr.strip_task_preamble_from_multi_task_prompt(prompt)) | ||
|
@@ -731,7 +602,6 @@ def test_get_fqcn_module_from_prediction_with_task_keywords(self): | |
tests.test_get_task_names_multi() | ||
tests.test_load_and_merge_vars_in_context() | ||
tests.test_insert_set_fact_task() | ||
tests.test_restore_original_task_names() | ||
tests.test_strip_task_preamble_from_multi_task_prompt_no_preamble_unchanged_multi() | ||
tests.test_strip_task_preamble_from_multi_task_prompt_no_preamble_unchanged_single() | ||
tests.test_strip_task_preamble_from_multi_task_prompt_one_preamble_changed() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters