Revision e81d80bd qa/qa_instance.py
b/qa/qa_instance.py | ||
---|---|---|
29 | 29 |
|
30 | 30 |
from ganeti import utils |
31 | 31 |
from ganeti import constants |
32 |
from ganeti import query |
|
33 | 32 |
from ganeti import pathutils |
33 |
from ganeti import query |
|
34 |
from ganeti.netutils import IP4Address |
|
34 | 35 |
|
35 | 36 |
import qa_config |
36 | 37 |
import qa_daemon |
37 | 38 |
import qa_utils |
38 | 39 |
import qa_error |
39 | 40 |
|
40 |
from qa_utils import AssertCommand, AssertEqual |
|
41 |
from qa_utils import AssertCommand, AssertEqual, AssertIn
|
|
41 | 42 |
from qa_utils import InstanceCheck, INST_DOWN, INST_UP, FIRST_ARG, RETURN_VALUE |
42 | 43 |
from qa_instance_utils import CheckSsconfInstanceList, \ |
43 | 44 |
CreateInstanceDrbd8, \ |
... | ... | |
1191 | 1192 |
% hv |
1192 | 1193 |
|
1193 | 1194 |
|
1195 |
@InstanceCheck(INST_UP, INST_UP, FIRST_ARG) |
|
1196 |
def TestInstanceCommunication(instance, master): |
|
1197 |
"""Tests instance communication via 'gnt-instance modify'""" |
|
1198 |
|
|
1199 |
# Enable instance communication network at the cluster level |
|
1200 |
network_name = "mynetwork" |
|
1201 |
|
|
1202 |
cmd = ["gnt-cluster", "modify", |
|
1203 |
"--instance-communication-network=%s" % network_name] |
|
1204 |
result_output = qa_utils.GetCommandOutput(master.primary, |
|
1205 |
utils.ShellQuoteArgs(cmd)) |
|
1206 |
print result_output |
|
1207 |
|
|
1208 |
# Enable instance communication mechanism for this instance |
|
1209 |
AssertCommand(["gnt-instance", "modify", "-c", "yes", instance.name]) |
|
1210 |
|
|
1211 |
# Reboot instance for changes to NIC to take effect |
|
1212 |
AssertCommand(["gnt-instance", "reboot", instance.name]) |
|
1213 |
|
|
1214 |
# Check if the instance is properly configured for instance |
|
1215 |
# communication. |
|
1216 |
nic_name = "%s%s" % (constants.INSTANCE_COMMUNICATION_NIC_PREFIX, |
|
1217 |
instance.name) |
|
1218 |
|
|
1219 |
## Check the output of 'gnt-instance list' |
|
1220 |
nic_names = _GetInstanceField(instance.name, "nic.names") |
|
1221 |
nic_names = map(lambda x: x.strip(" '"), nic_names.strip("[]").split(",")) |
|
1222 |
|
|
1223 |
AssertIn(nic_name, nic_names, |
|
1224 |
msg="Looking for instance communication TAP interface") |
|
1225 |
|
|
1226 |
nic_n = nic_names.index(nic_name) |
|
1227 |
|
|
1228 |
nic_ip = _GetInstanceField(instance.name, "nic.ip/%d" % nic_n) |
|
1229 |
nic_network = _GetInstanceField(instance.name, "nic.network.name/%d" % nic_n) |
|
1230 |
nic_mode = _GetInstanceField(instance.name, "nic.mode/%d" % nic_n) |
|
1231 |
|
|
1232 |
AssertEqual(IP4Address.InNetwork(constants.INSTANCE_COMMUNICATION_NETWORK4, |
|
1233 |
nic_ip), |
|
1234 |
True, |
|
1235 |
msg="Checking if NIC's IP if part of the expected network") |
|
1236 |
|
|
1237 |
AssertEqual(network_name, nic_network, |
|
1238 |
msg="Checking if NIC's network name matches the expected value") |
|
1239 |
|
|
1240 |
AssertEqual(constants.INSTANCE_COMMUNICATION_NETWORK_MODE, nic_mode, |
|
1241 |
msg="Checking if NIC's mode name matches the expected value") |
|
1242 |
|
|
1243 |
## Check the output of 'ip route' |
|
1244 |
cmd = ["ip", "route", "show", nic_ip] |
|
1245 |
result_output = qa_utils.GetCommandOutput(master.primary, |
|
1246 |
utils.ShellQuoteArgs(cmd)) |
|
1247 |
result = result_output.split() |
|
1248 |
|
|
1249 |
AssertEqual(len(result), 5, msg="Checking if the IP route is established") |
|
1250 |
|
|
1251 |
route_ip = result[0] |
|
1252 |
route_dev = result[1] |
|
1253 |
route_tap = result[2] |
|
1254 |
route_scope = result[3] |
|
1255 |
route_link = result[4] |
|
1256 |
|
|
1257 |
AssertEqual(route_ip, nic_ip, |
|
1258 |
msg="Checking if IP route shows the expected IP") |
|
1259 |
AssertEqual(route_dev, "dev", |
|
1260 |
msg="Checking if IP route shows the expected device") |
|
1261 |
AssertEqual(route_scope, "scope", |
|
1262 |
msg="Checking if IP route shows the expected scope") |
|
1263 |
AssertEqual(route_link, "link", |
|
1264 |
msg="Checking if IP route shows the expected link-level scope") |
|
1265 |
|
|
1266 |
## Check the output of 'ip address' |
|
1267 |
cmd = ["ip", "address", "show", "dev", route_tap] |
|
1268 |
result_output = qa_utils.GetCommandOutput(master.primary, |
|
1269 |
utils.ShellQuoteArgs(cmd)) |
|
1270 |
result = result_output.splitlines() |
|
1271 |
|
|
1272 |
AssertEqual(len(result), 3, |
|
1273 |
msg="Checking if the IP address is established") |
|
1274 |
|
|
1275 |
result = result.pop().split() |
|
1276 |
|
|
1277 |
AssertEqual(len(result), 7, |
|
1278 |
msg="Checking if the IP address has the expected value") |
|
1279 |
|
|
1280 |
address_ip = result[1] |
|
1281 |
address_netmask = result[3] |
|
1282 |
|
|
1283 |
AssertEqual(address_ip, "169.254.169.254/32", |
|
1284 |
msg="Checking if the TAP interface has the expected IP") |
|
1285 |
AssertEqual(address_netmask, "169.254.255.255", |
|
1286 |
msg="Checking if the TAP interface has the expected netmask") |
|
1287 |
|
|
1288 |
# Disable instance communication mechanism for this instance |
|
1289 |
AssertCommand(["gnt-instance", "modify", "-c", "no", instance.name]) |
|
1290 |
|
|
1291 |
# Reboot instance for changes to NIC to take effect |
|
1292 |
AssertCommand(["gnt-instance", "reboot", instance.name]) |
|
1293 |
|
|
1294 |
# Disable instance communication network at cluster level |
|
1295 |
cmd = ["gnt-cluster", "modify", |
|
1296 |
"--instance-communication-network=%s" % network_name] |
|
1297 |
result_output = qa_utils.GetCommandOutput(master.primary, |
|
1298 |
utils.ShellQuoteArgs(cmd)) |
|
1299 |
print result_output |
|
1300 |
|
|
1301 |
|
|
1194 | 1302 |
available_instance_tests = [ |
1195 | 1303 |
("instance-add-plain-disk", constants.DT_PLAIN, |
1196 | 1304 |
TestInstanceAddWithPlainDisk, 1), |
Also available in: Unified diff