-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
chore: create additional test case for testing workflows
- Loading branch information
Showing
6 changed files
with
114 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import sys | ||
import pytest | ||
import pathlib | ||
import json | ||
|
||
from understack_workflows.main.sync_bmc_creds import get_args | ||
from understack_workflows.node_configuration import IronicNodeConfiguration | ||
|
||
|
||
def read_json_samples(file_path): | ||
here = pathlib.Path(__file__).parent | ||
ref = here.joinpath(file_path) | ||
with ref.open("r") as f: | ||
return f.read() | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_args(monkeypatch): | ||
monkeypatch.setattr(sys, "argv", ["pytest", | ||
read_json_samples("json_samples/event-interface-update.json")]) | ||
|
||
|
||
@pytest.fixture | ||
def fake_ironic_client(mocker): | ||
return mocker.patch("understack_workflows.ironic.client.IronicClient") | ||
|
||
|
||
def get_ironic_node_state(fake_ironic_client, node_data): | ||
node = IronicNodeConfiguration.from_event(json.loads(read_json_samples("json_samples/event-interface-update.json"))) | ||
|
||
ironic_node = fake_ironic_client.get_node(node.uuid) | ||
ironic_node.return_value = node_data | ||
|
||
return ironic_node.return_value['provision_state'] | ||
|
||
|
||
def test_args(): | ||
var = get_args() | ||
assert var['data']['ip_addresses'][0]['host'] == "10.46.96.156" | ||
|
||
|
||
def test_ironic_non_allowing_states(fake_ironic_client): | ||
ironic_node_state = get_ironic_node_state(fake_ironic_client, | ||
json.loads(read_json_samples( | ||
"json_samples/ironic-active-node-data.json"))) | ||
with pytest.raises(SystemExit) as sys_exit: | ||
if ironic_node_state not in ["enroll", "manageable"]: | ||
print('checking') | ||
sys.exit(0) | ||
assert sys_exit.value.code == 0 | ||
|
||
|
||
def test_ironic_node_allowing_states(fake_ironic_client): | ||
ironic_node_state = get_ironic_node_state(fake_ironic_client, | ||
json.loads(read_json_samples( | ||
"json_samples/ironic-enroll-node-data.json"))) | ||
assert ironic_node_state in ["enroll", "manageable"] |
28 changes: 28 additions & 0 deletions
28
python/understack-workflows/tests/test_sync_nautobot_system_info.py
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
|
||
from understack_workflows.main.sync_nautobot_system_info import argument_parser, do_sync | ||
from understack_workflows.models import Systeminfo | ||
|
||
|
||
@pytest.fixture | ||
def fakebot(mocker): | ||
return mocker.patch("understack_workflows.nautobot.Nautobot", autospec=True) | ||
|
||
|
||
def test_parse_device_name(): | ||
parser = argument_parser(__name__) | ||
with pytest.raises(SystemExit): | ||
parser.parse_args(["--device-id", "FOO", "--bmc_username", "root", "--bmc_password", "password"]) | ||
|
||
|
||
def test_parse_device_id(device_id, bmc_username, bmc_password): | ||
parser = argument_parser(__name__) | ||
args = parser.parse_args(["--device-id", str(device_id), "--bmc_username", bmc_username, | ||
"--bmc_password", bmc_password]) | ||
|
||
assert args.device_id == device_id | ||
assert args.bmc_username == bmc_username | ||
assert args.bmc_password == bmc_password | ||
|
||
|
||
|
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