Skip to content

Commit

Permalink
Added tests Proxmox connection custom port
Browse files Browse the repository at this point in the history
- Added the test for the custom port feature
- Removed duplicated username call in proxmox.py
  • Loading branch information
piterpunk authored and dwoz committed Sep 29, 2020
1 parent 0e4a638 commit 6ad09b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
5 changes: 0 additions & 5 deletions salt/cloud/clouds/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ def _authenticate():
url = config.get_cloud_config_value(
"url", get_configured_provider(), __opts__, search_global=False
)
username = (
config.get_cloud_config_value(
"user", get_configured_provider(), __opts__, search_global=False
),
)
port = config.get_cloud_config_value(
"port", get_configured_provider(), __opts__, default=8006, search_global=False
)
Expand Down
26 changes: 24 additions & 2 deletions tests/unit/cloud/clouds/test_proxmox.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
"""
:codeauthor: Tyler Johnson <tjohnson@saltstack.com>
"""

# Import Salt Libs
from __future__ import absolute_import, print_function, unicode_literals

# Import Salt Libs
from salt.cloud.clouds import proxmox
Expand Down Expand Up @@ -140,3 +138,27 @@ def test_clone(self):
"post", "nodes/otherhost/qemu/123/clone", {"newid": ANY},
)
assert result == {}

def test__authenticate_with_custom_port(self):
"""
Test the use of a custom port for Proxmox connection
"""
get_cloud_config_mock = [
"proxmox.connection.url",
"9999",
"fakeuser",
"secretpassword",
True,
]
requests_post_mock = MagicMock()
with patch(
"salt.config.get_cloud_config_value",
autospec=True,
side_effect=get_cloud_config_mock,
), patch("requests.post", requests_post_mock):
proxmox._authenticate()
requests_post_mock.assert_called_with(
"https://proxmox.connection.url:9999/api2/json/access/ticket",
verify=True,
data={"username": ("fakeuser",), "password": "secretpassword"},
)

0 comments on commit 6ad09b8

Please sign in to comment.