forked from theforeman/foreman-bats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb-setup-discovery.bats
executable file
·105 lines (86 loc) · 2.21 KB
/
fb-setup-discovery.bats
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
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bats
# vim: ft=sh:sw=2:et
set -o pipefail
load os_helper
load foreman_helper
URL=https://$(hostname -f)
CREDENTIALS=admin:changeme
TMP_DATA=$(mktemp /tmp/discover-host-XXXXXXXXXX)
trap "rm -f $TMP_DATA" EXIT
discover_host() {
MAC1=$(echo -n 52:54:00:; openssl rand -hex 3 | sed 's/\(..\)/\1:/g; s/.$//')
IP1="192.168.222.$(($RANDOM % 250 + 2))"
cat <<EOD > $TMP_DATA
{
"facts": {
"discovery_version": "3.1.0",
"interfaces": "fake1",
"macaddress_fake1": "$MAC1",
"ipaddress_fake1": "$IP1",
"macaddress": "$MAC1",
"ipaddress": "$IP1",
"discovery_bootif": "$MAC1",
"physicalprocessorcount": "3",
"memorysize_mb": "900",
"blockdevice.sda_size": "1234567890",
"blockdevice.sdb_size": "123456700",
"hardwaremodel": "Fake Host FH420"
}
}
EOD
cat $TMP_DATA
curl -iku "$CREDENTIALS" \
-H "Content-Type: application/json" \
-d @$TMP_DATA -X POST $URL/api/v2/discovered_hosts/facts
}
find_discovered_host() {
DID=$(hammer --csv discovery list | head -n2 | tail -n1 | cut -d, -f1)
}
@test "install discovery plugin" {
yum -y install tfm-rubygem-foreman_discovery tfm-rubygem-hammer_cli_foreman_discovery
}
@test "restart foreman" {
service httpd restart && sleep 15
}
@test "discover a host" {
discover_host
}
@test "discover a second host" {
discover_host
}
@test "list discovered hosts and refresh hammer cache" {
hammer -r discovery list
}
@test "find a discovered host id" {
find_discovered_host
test $DID -gt 0
}
@test "show discovered host" {
find_discovered_host
hammer discovery info --id $DID
}
@test "provision discovered host" {
find_discovered_host
hammer discovery provision --id $DID --hostgroup bats-centos
}
@test "create a rule" {
hammer discovery_rule create --name always-$RANDOM --search "cpu_count > 0" --hostgroup bats-centos
}
@test "list discovery rules" {
hammer discovery_rule list
}
@test "show discovery rule" {
hammer discovery_rule info --id 1
}
@test "find a discovered host id" {
find_discovered_host
test $DID -gt 0
}
@test "show discovered host" {
find_discovered_host
hammer discovery info --id $DID
}
@test "auto provision a host" {
find_discovered_host
hammer discovery auto-provision --id $DID
}