Tuple[Dict[str, Any], bool]: [description]
"""
numa = {}
+ numa_list = []
epa_vcpu_set = False
if guest_epa_quota.get("numa-node-policy"):
numa_node_policy = guest_epa_quota.get("numa-node-policy")
if numa_node_policy.get("node"):
- numa_node = numa_node_policy["node"][0]
-
- if numa_node.get("num-cores"):
- numa["cores"] = numa_node["num-cores"]
- epa_vcpu_set = True
-
- paired_threads = numa_node.get("paired-threads", {})
- if paired_threads.get("num-paired-threads"):
- numa["paired-threads"] = int(
- numa_node["paired-threads"]["num-paired-threads"]
- )
- epa_vcpu_set = True
+ for numa_node in numa_node_policy["node"]:
+ vcpu_list = []
+ if numa_node.get("id"):
+ numa["id"] = int(numa_node["id"])
+
+ if numa_node.get("vcpu"):
+ for vcpu in numa_node.get("vcpu"):
+ vcpu_id = int(vcpu.get("id"))
+ vcpu_list.append(vcpu_id)
+ numa["vcpu"] = vcpu_list
+
+ if numa_node.get("num-cores"):
+ numa["cores"] = numa_node["num-cores"]
+ epa_vcpu_set = True
+
+ paired_threads = numa_node.get("paired-threads", {})
+ if paired_threads.get("num-paired-threads"):
+ numa["paired_threads"] = int(
+ numa_node["paired-threads"]["num-paired-threads"]
+ )
+ epa_vcpu_set = True
- if paired_threads.get("paired-thread-ids"):
- numa["paired-threads-id"] = []
+ if paired_threads.get("paired-thread-ids"):
+ numa["paired-threads-id"] = []
- for pair in paired_threads["paired-thread-ids"]:
- numa["paired-threads-id"].append(
- (
- str(pair["thread-a"]),
- str(pair["thread-b"]),
+ for pair in paired_threads["paired-thread-ids"]:
+ numa["paired-threads-id"].append(
+ (
+ str(pair["thread-a"]),
+ str(pair["thread-b"]),
+ )
)
- )
- if numa_node.get("num-threads"):
- numa["threads"] = int(numa_node["num-threads"])
- epa_vcpu_set = True
+ if numa_node.get("num-threads"):
+ numa["threads"] = int(numa_node["num-threads"])
+ epa_vcpu_set = True
- if numa_node.get("memory-mb"):
- numa["memory"] = max(int(int(numa_node["memory-mb"]) / 1024), 1)
+ if numa_node.get("memory-mb"):
+ numa["memory"] = max(int(int(numa_node["memory-mb"]) / 1024), 1)
- return numa, epa_vcpu_set
+ numa_list.append(numa)
+ numa = {}
+
+ return numa_list, epa_vcpu_set
@staticmethod
def _process_guest_epa_cpu_pinning_params(
"""
extended = {}
numa = {}
+ numa_list = []
if target_flavor.get("guest-epa"):
guest_epa = target_flavor["guest-epa"]
- numa, epa_vcpu_set = Ns._process_guest_epa_numa_params(
+ numa_list, epa_vcpu_set = Ns._process_guest_epa_numa_params(
guest_epa_quota=guest_epa
)
if guest_epa.get("mempage-size"):
extended["mempage-size"] = guest_epa.get("mempage-size")
+ if guest_epa.get("cpu-pinning-policy"):
+ extended["cpu-pinning-policy"] = guest_epa.get("cpu-pinning-policy")
+
+ if guest_epa.get("cpu-thread-pinning-policy"):
+ extended["cpu-thread-pinning-policy"] = guest_epa.get(
+ "cpu-thread-pinning-policy"
+ )
+
+ if guest_epa.get("numa-node-policy"):
+ if guest_epa.get("numa-node-policy").get("mem-policy"):
+ extended["mem-policy"] = guest_epa.get("numa-node-policy").get(
+ "mem-policy"
+ )
+
tmp_numa, epa_vcpu_set = Ns._process_guest_epa_cpu_pinning_params(
guest_epa_quota=guest_epa,
vcpu_count=int(target_flavor.get("vcpu-count", 1)),
epa_vcpu_set=epa_vcpu_set,
)
- numa.update(tmp_numa)
+ for numa in numa_list:
+ numa.update(tmp_numa)
extended.update(
Ns._process_guest_epa_quota_params(
)
if numa:
- extended["numas"] = [numa]
+ extended["numas"] = numa_list
return extended
self.assertDictEqual(expected_result, result)
def test__process_guest_epa_numa_params_with_empty_numa_params(self):
- expected_numa_result = {}
+ expected_numa_result = []
expected_epa_vcpu_set_result = False
guest_epa_quota = {}
numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
guest_epa_quota=guest_epa_quota,
)
-
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_numa_params_with_wrong_numa_params(self):
- expected_numa_result = {}
+ expected_numa_result = []
expected_epa_vcpu_set_result = False
guest_epa_quota = {"no_nume": "here"}
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_numa_params_with_numa_node_policy(self):
- expected_numa_result = {}
+ expected_numa_result = []
expected_epa_vcpu_set_result = False
guest_epa_quota = {"numa-node-policy": {}}
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_numa_params_with_no_node(self):
- expected_numa_result = {}
+ expected_numa_result = []
expected_epa_vcpu_set_result = False
guest_epa_quota = {
"numa-node-policy": {
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_numa_params_with_1_node_num_cores(self):
- expected_numa_result = {"cores": 3}
+ expected_numa_result = [{"cores": 3}]
expected_epa_vcpu_set_result = True
guest_epa_quota = {
"numa-node-policy": {
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_numa_params_with_1_node_paired_threads(self):
- expected_numa_result = {"paired-threads": 3}
+ expected_numa_result = [{"paired_threads": 3}]
expected_epa_vcpu_set_result = True
guest_epa_quota = {
"numa-node-policy": {
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_numa_params_with_1_node_paired_threads_ids(self):
- expected_numa_result = {
- "paired-threads-id": [("0", "1"), ("4", "5")],
- }
+ expected_numa_result = [
+ {
+ "paired-threads-id": [("0", "1"), ("4", "5")],
+ }
+ ]
expected_epa_vcpu_set_result = False
guest_epa_quota = {
"numa-node-policy": {
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_numa_params_with_1_node_num_threads(self):
- expected_numa_result = {"threads": 3}
+ expected_numa_result = [{"threads": 3}]
expected_epa_vcpu_set_result = True
guest_epa_quota = {
"numa-node-policy": {
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_numa_params_with_1_node_memory_mb(self):
- expected_numa_result = {"memory": 2}
+ expected_numa_result = [{"memory": 2}]
expected_epa_vcpu_set_result = False
guest_epa_quota = {
"numa-node-policy": {
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
- def test__process_guest_epa_numa_params_with_1_node(self):
- expected_numa_result = {
- "cores": 3,
- "paired-threads": 3,
- "paired-threads-id": [("0", "1"), ("4", "5")],
- "threads": 3,
- "memory": 2,
+ def test__process_guest_epa_numa_params_with_1_node_vcpu(self):
+ expected_numa_result = [
+ {
+ "id": 0,
+ "vcpu": [0, 1],
+ }
+ ]
+ expected_epa_vcpu_set_result = False
+ guest_epa_quota = {
+ "numa-node-policy": {
+ "node": [{"id": "0", "vcpu": [{"id": "0"}, {"id": "1"}]}],
+ },
}
+
+ numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
+ guest_epa_quota=guest_epa_quota,
+ )
+
+ self.assertEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
+
+ def test__process_guest_epa_numa_params_with_2_node_vcpu(self):
+ expected_numa_result = [
+ {
+ "id": 0,
+ "vcpu": [0, 1],
+ },
+ {
+ "id": 1,
+ "vcpu": [2, 3],
+ },
+ ]
+
+ expected_epa_vcpu_set_result = False
+ guest_epa_quota = {
+ "numa-node-policy": {
+ "node": [
+ {"id": "0", "vcpu": [{"id": "0"}, {"id": "1"}]},
+ {"id": "1", "vcpu": [{"id": "2"}, {"id": "3"}]},
+ ],
+ },
+ }
+
+ numa_result, epa_vcpu_set_result = Ns._process_guest_epa_numa_params(
+ guest_epa_quota=guest_epa_quota,
+ )
+
+ self.assertEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
+
+ def test__process_guest_epa_numa_params_with_1_node(self):
+ expected_numa_result = [
+ {
+ # "id": 0,
+ # "vcpu": [0, 1],
+ "cores": 3,
+ "paired_threads": 3,
+ "paired-threads-id": [("0", "1"), ("4", "5")],
+ "threads": 3,
+ "memory": 2,
+ }
+ ]
expected_epa_vcpu_set_result = True
guest_epa_quota = {
"numa-node-policy": {
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_numa_params_with_2_nodes(self):
- expected_numa_result = {
- "cores": 3,
- "paired-threads": 3,
- "paired-threads-id": [("0", "1"), ("4", "5")],
- "threads": 3,
- "memory": 2,
- }
+ expected_numa_result = [
+ {
+ "cores": 3,
+ "paired_threads": 3,
+ "paired-threads-id": [("0", "1"), ("4", "5")],
+ "threads": 3,
+ "memory": 2,
+ },
+ {
+ "cores": 7,
+ "paired_threads": 7,
+ "paired-threads-id": [("2", "3"), ("5", "6")],
+ "threads": 4,
+ "memory": 4,
+ },
+ ]
expected_epa_vcpu_set_result = True
guest_epa_quota = {
"numa-node-policy": {
guest_epa_quota=guest_epa_quota,
)
- self.assertDictEqual(expected_numa_result, numa_result)
+ self.assertEqual(expected_numa_result, numa_result)
self.assertEqual(expected_epa_vcpu_set_result, epa_vcpu_set_result)
def test__process_guest_epa_cpu_pinning_params_with_empty_params(self):
guest_epa_cpu_pinning_params,
guest_epa_quota_params,
):
- expected_result = {}
+ expected_result = {
+ "mem-policy": "STRICT",
+ }
target_flavor = {
"guest-epa": {
"vcpu-count": 1,
+ "numa-node-policy": {
+ "mem-policy": "STRICT",
+ },
},
}
):
expected_result = {
"mempage-size": "1G",
+ "mem-policy": "STRICT",
}
target_flavor = {
- "guest-epa": {"vcpu-count": 1, "mempage-size": "1G"},
+ "guest-epa": {
+ "vcpu-count": 1,
+ "mempage-size": "1G",
+ "numa-node-policy": {
+ "mem-policy": "STRICT",
+ },
+ },
}
guest_epa_numa_params.return_value = ({}, False)
):
expected_result = {
"mempage-size": "1G",
+ "cpu-pinning-policy": "DEDICATED",
+ "cpu-thread-pinning-policy": "PREFER",
"numas": [
{
"cores": 3,
}
guest_epa_numa_params.return_value = (
- {
- "cores": 3,
- "paired-threads": 3,
- "paired-threads-id": [("0", "1"), ("4", "5")],
- "threads": 3,
- "memory": 2,
- },
+ [
+ {
+ "cores": 3,
+ "paired-threads": 3,
+ "paired-threads-id": [("0", "1"), ("4", "5")],
+ "threads": 3,
+ "memory": 2,
+ },
+ ],
True,
)
guest_epa_cpu_pinning_params.return_value = (
result = Ns._process_epa_params(
target_flavor=target_flavor,
)
-
- self.assertDictEqual(expected_result, result)
+ self.assertEqual(expected_result, result)
self.assertTrue(guest_epa_numa_params.called)
self.assertTrue(guest_epa_cpu_pinning_params.called)
self.assertTrue(guest_epa_quota_params.called)