Skip to content

Commit

Permalink
feat: Change ansible pull unittests from dict to list
Browse files Browse the repository at this point in the history
  • Loading branch information
shaerpour committed Feb 12, 2025
1 parent 2229bb8 commit 56ba447
Showing 1 changed file with 66 additions and 51 deletions.
117 changes: 66 additions & 51 deletions tests/unittests/config/test_cc_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,31 @@
"galaxy": {
"actions": [["ansible-galaxy", "install", "debops.apt"]],
},
"pull": {
"url": "https://github/holmanb/vmboot",
"playbook_name": "arch.yml",
"accept_host_key": True,
"clean": True,
"full": True,
"diff": False,
"ssh_common_args": "-y",
"scp_extra_args": "-l",
"sftp_extra_args": "-f",
"checkout": "tree",
"module_path": "~/.ansible/plugins/modules:"
"/usr/share/ansible/plugins/modules",
"timeout": "10",
"vault_id": "me",
"connection": "smart",
"vault_password_file": "/path/to/file",
"module_name": "git",
"sleep": "1",
"tags": "cumulus",
"skip_tags": "cisco",
"private_key": "{nope}",
},
"pull": [
{
"url": "https://github/holmanb/vmboot",
"playbook_name": "arch.yml",
"accept_host_key": True,
"clean": True,
"full": True,
"diff": False,
"ssh_common_args": "-y",
"scp_extra_args": "-l",
"sftp_extra_args": "-f",
"checkout": "tree",
"module_path": "~/.ansible/plugins/modules:"
"/usr/share/ansible/plugins/modules",
"timeout": "10",
"vault_id": "me",
"connection": "smart",
"vault_password_file": "/path/to/file",
"module_name": "git",
"sleep": "1",
"tags": "cumulus",
"skip_tags": "cisco",
"private_key": "{nope}",
},
],
}
}

Expand All @@ -138,10 +140,12 @@
"install_method": "pip",
"package_name": "ansible",
"run_user": "ansible",
"pull": {
"url": "https://github/holmanb/vmboot",
"playbook_name": "ubuntu.yml",
},
"pull": [
{
"url": "https://github/holmanb/vmboot",
"playbook_name": "ubuntu.yml",
},
],
}
}

Expand All @@ -159,11 +163,13 @@ class TestSchema:
{
"ansible": {
"install_method": "distro",
"pull": {
"url": "https://github/holmanb/vmboot",
"playbook_name": "centos.yml",
"dance": "bossa nova",
},
"pull": [
{
"url": "https://github/holmanb/vmboot",
"playbook_name": "centos.yml",
"dance": "bossa nova",
},
],
}
},
"Additional properties are not allowed ",
Expand All @@ -183,10 +189,12 @@ class TestSchema:
{
"ansible": {
"install_method": "true",
"pull": {
"url": "https://github/holmanb/vmboot",
"playbook_name": "debian.yml",
},
"pull": [
{
"url": "https://github/holmanb/vmboot",
"playbook_name": "debian.yml",
},
],
}
},
"'true' is not one of ['distro', 'pip']",
Expand All @@ -196,9 +204,11 @@ class TestSchema:
{
"ansible": {
"install_method": "pip",
"pull": {
"playbook_name": "fedora.yml",
},
"pull": [
{
"playbook_name": "fedora.yml",
},
],
}
},
"'url' is a required property",
Expand All @@ -208,9 +218,11 @@ class TestSchema:
{
"ansible": {
"install_method": "pip",
"pull": {
"url": "gophers://encrypted-gophers/",
},
"pull": [
{
"url": "gophers://encrypted-gophers/",
},
],
}
},
"'playbook_name' is a required property",
Expand All @@ -230,9 +242,8 @@ def test_schema_validation(self, config, error_msg):
class TestAnsible:
def test_filter_args(self):
"""only diff should be removed"""
out = cc_ansible.filter_args(
CFG_FULL_PULL.get("ansible", {}).get("pull", {})
)
for c in CFG_FULL_PULL.get("ansible", {}).get("pull", []):
out = cc_ansible.filter_args(c)
assert out == {
"url": "https://github/holmanb/vmboot",
"playbook-name": "arch.yml",
Expand Down Expand Up @@ -266,9 +277,11 @@ def test_filter_args(self):
"ansible": {
"package_name": "ansible-core",
"install_method": "distro",
"pull": {
"playbook_name": "ubuntu.yml",
},
"pull": [
{
"playbook_name": "ubuntu.yml",
},
],
}
},
ValueError,
Expand All @@ -277,9 +290,11 @@ def test_filter_args(self):
{
"ansible": {
"install_method": "pip",
"pull": {
"url": "https://github/holmanb/vmboot",
},
"pull": [
{
"url": "https://github/holmanb/vmboot",
},
],
}
},
ValueError,
Expand Down

0 comments on commit 56ba447

Please sign in to comment.