27 |
27 |
import random
|
28 |
28 |
import re
|
29 |
29 |
import itertools
|
|
30 |
import functools
|
30 |
31 |
|
31 |
32 |
from ganeti import utils
|
32 |
33 |
from ganeti import constants
|
... | ... | |
622 |
623 |
raise
|
623 |
624 |
|
624 |
625 |
|
|
626 |
def _GenInstanceAllocationDict(node, instance):
|
|
627 |
"""Creates an instance allocation dict to be used with the RAPI"""
|
|
628 |
instance.SetDiskTemplate(constants.DT_PLAIN)
|
|
629 |
|
|
630 |
disks = [{"size": utils.ParseUnit(d.get("size")),
|
|
631 |
"name": str(d.get("name"))}
|
|
632 |
for d in qa_config.GetDiskOptions()]
|
|
633 |
|
|
634 |
nic0_mac = instance.GetNicMacAddr(0, constants.VALUE_GENERATE)
|
|
635 |
nics = [{
|
|
636 |
constants.INIC_MAC: nic0_mac,
|
|
637 |
}]
|
|
638 |
|
|
639 |
beparams = {
|
|
640 |
constants.BE_MAXMEM: utils.ParseUnit(qa_config.get(constants.BE_MAXMEM)),
|
|
641 |
constants.BE_MINMEM: utils.ParseUnit(qa_config.get(constants.BE_MINMEM)),
|
|
642 |
}
|
|
643 |
|
|
644 |
return _rapi_client.InstanceAllocation(constants.INSTANCE_CREATE,
|
|
645 |
instance.name,
|
|
646 |
constants.DT_PLAIN,
|
|
647 |
disks, nics,
|
|
648 |
os=qa_config.get("os"),
|
|
649 |
pnode=node.primary,
|
|
650 |
beparams=beparams)
|
|
651 |
|
|
652 |
|
|
653 |
def TestRapiInstanceMultiAlloc(node):
|
|
654 |
"""Test adding two new instances via the RAPI instance-multi-alloc method"""
|
|
655 |
if not qa_config.IsTemplateSupported(constants.DT_PLAIN):
|
|
656 |
return
|
|
657 |
|
|
658 |
JOBS_KEY = "jobs"
|
|
659 |
|
|
660 |
instance_one = qa_config.AcquireInstance()
|
|
661 |
instance_two = qa_config.AcquireInstance()
|
|
662 |
instance_list = [instance_one, instance_two]
|
|
663 |
try:
|
|
664 |
rapi_dicts = map(functools.partial(_GenInstanceAllocationDict, node),
|
|
665 |
instance_list)
|
|
666 |
|
|
667 |
job_id = _rapi_client.InstancesMultiAlloc(rapi_dicts)
|
|
668 |
|
|
669 |
results, = _WaitForRapiJob(job_id)
|
|
670 |
|
|
671 |
if JOBS_KEY not in results:
|
|
672 |
raise qa_error.Error("RAPI instance-multi-alloc did not deliver "
|
|
673 |
"information about created jobs")
|
|
674 |
|
|
675 |
if len(results[JOBS_KEY]) != len(instance_list):
|
|
676 |
raise qa_error.Error("RAPI instance-multi-alloc failed to return the "
|
|
677 |
"desired number of jobs!")
|
|
678 |
|
|
679 |
for success, job in results[JOBS_KEY]:
|
|
680 |
if success:
|
|
681 |
_WaitForRapiJob(job)
|
|
682 |
else:
|
|
683 |
raise qa_error.Error("Failed to create instance in "
|
|
684 |
"instance-multi-alloc call")
|
|
685 |
except:
|
|
686 |
# Note that although released, it may be that some of the instance creations
|
|
687 |
# have in fact succeeded. Handling this in a better way may be possible, but
|
|
688 |
# is not necessary as the QA has already failed at this point.
|
|
689 |
for instance in instance_list:
|
|
690 |
instance.Release()
|
|
691 |
raise
|
|
692 |
|
|
693 |
return (instance_one, instance_two)
|
|
694 |
|
|
695 |
|
625 |
696 |
@InstanceCheck(None, INST_DOWN, FIRST_ARG)
|
626 |
697 |
def TestRapiInstanceRemove(instance, use_client):
|
627 |
698 |
"""Test removing instance via RAPI"""
|