forked from RedHatInsights/insights-host-inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_host_dedup_logic.py
93 lines (60 loc) · 3.16 KB
/
test_host_dedup_logic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import uuid
from pytest import mark
from api.host import find_existing_host
from app import db
from app.models import Host
ACCOUNT_NUMBER = "000102"
def create_host(canonical_facts):
host = Host(canonical_facts, display_name=None, account=ACCOUNT_NUMBER)
db.session.add(host)
db.session.commit()
return host
# FIXME: DRY
def generate_uuid():
return str(uuid.uuid4())
def basic_host_dedup_test(initial_canonical_facts, search_canonical_facts):
original_host = create_host(initial_canonical_facts)
found_host = find_existing_host(ACCOUNT_NUMBER, search_canonical_facts)
assert original_host.id == found_host.id
def test_find_host_using_subset_canonical_fact_match(flask_app_fixture):
fqdn = "fred.flintstone.com"
canonical_facts = {"fqdn": fqdn, "bios_uuid": generate_uuid(), "rhel_machine_id": generate_uuid()}
# Create the subset of canonical facts to search by
subset_canonical_facts = {"fqdn": fqdn}
basic_host_dedup_test(canonical_facts, subset_canonical_facts)
def test_find_host_using_superset_canonical_fact_match(flask_app_fixture):
canonical_facts = {"fqdn": "fred", "bios_uuid": generate_uuid()}
# Create the superset of canonical facts to search by
superset_canonical_facts = canonical_facts.copy()
superset_canonical_facts["rhel_machine_id"] = generate_uuid()
superset_canonical_facts["satellite_id"] = generate_uuid()
basic_host_dedup_test(canonical_facts, superset_canonical_facts)
def test_find_host_using_insights_id_match(flask_app_fixture):
canonical_facts = {"fqdn": "fred", "bios_uuid": generate_uuid(), "insights_id": generate_uuid()}
# Change the canonical facts except the insights_id...match on insights_id
search_canonical_facts = {
"fqdn": "barney",
"bios_uuid": generate_uuid(),
"insights_id": canonical_facts["insights_id"],
}
basic_host_dedup_test(canonical_facts, search_canonical_facts)
def test_find_host_using_subscription_manager_id_match(flask_app_fixture):
canonical_facts = {"fqdn": "fred", "bios_uuid": generate_uuid(), "subscription_manager_id": generate_uuid()}
# Change the bios_uuid so that falling back to subset match will fail
search_canonical_facts = {
"bios_uuid": generate_uuid(),
"subscription_manager_id": canonical_facts["subscription_manager_id"],
}
basic_host_dedup_test(canonical_facts, search_canonical_facts)
@mark.parametrize(("host_create_order", "expected_host"), (((0, 1), 1), ((1, 0), 0)))
def test_find_host_using_elevated_ids_match(flask_app_fixture, host_create_order, expected_host):
hosts_canonical_facts = ({"subscription_manager_id": generate_uuid()}, {"insights_id": generate_uuid()})
created_hosts = []
for host_canonical_facts in host_create_order:
created_host = create_host(hosts_canonical_facts[host_canonical_facts])
created_hosts.append(created_host)
search_canonical_facts = {
key: value for host_canonical_facts in hosts_canonical_facts for key, value in host_canonical_facts.items()
}
found_host = find_existing_host(ACCOUNT_NUMBER, search_canonical_facts)
assert created_hosts[expected_host].id == found_host.id