Skip to content

Commit 824bc35

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Set instance CPU policy to 'share' through image property"
2 parents 4270ed4 + 569ad14 commit 824bc35

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed

nova/tests/unit/virt/test_hardware.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,127 @@ def test_best_config(self):
848848

849849
class NUMATopologyTest(test.NoDBTestCase):
850850

851+
def test_cpu_policy_constraint(self):
852+
testdata = [
853+
{
854+
"flavor": objects.Flavor(extra_specs={
855+
"hw:cpu_policy": "dedicated"
856+
}),
857+
"image": {
858+
"properties": {
859+
"hw_cpu_policy": "dedicated"
860+
}
861+
},
862+
"expect": fields.CPUAllocationPolicy.DEDICATED
863+
},
864+
{
865+
"flavor": objects.Flavor(extra_specs={
866+
"hw:cpu_policy": "dedicated"
867+
}),
868+
"image": {
869+
"properties": {
870+
"hw_cpu_policy": "shared"
871+
}
872+
},
873+
"expect": fields.CPUAllocationPolicy.DEDICATED
874+
},
875+
{
876+
"flavor": objects.Flavor(extra_specs={
877+
"hw:cpu_policy": "dedicated"
878+
}),
879+
"image": {
880+
"properties": {
881+
}
882+
},
883+
"expect": fields.CPUAllocationPolicy.DEDICATED
884+
},
885+
{
886+
"flavor": objects.Flavor(extra_specs={
887+
"hw:cpu_policy": "shared"
888+
}),
889+
"image": {
890+
"properties": {
891+
"hw_cpu_policy": "dedicated"
892+
}
893+
},
894+
"expect": exception.ImageCPUPinningForbidden
895+
},
896+
{
897+
"flavor": objects.Flavor(extra_specs={
898+
"hw:cpu_policy": "shared"
899+
}),
900+
"image": {
901+
"properties": {
902+
"hw_cpu_policy": "shared"
903+
}
904+
},
905+
"expect": fields.CPUAllocationPolicy.SHARED
906+
},
907+
{
908+
"flavor": objects.Flavor(extra_specs={
909+
"hw:cpu_policy": "shared"
910+
}),
911+
"image": {
912+
"properties": {
913+
}
914+
},
915+
"expect": fields.CPUAllocationPolicy.SHARED
916+
},
917+
{
918+
"flavor": objects.Flavor(),
919+
"image": {
920+
"properties": {
921+
"hw_cpu_policy": "dedicated"
922+
}
923+
},
924+
"expect": fields.CPUAllocationPolicy.DEDICATED
925+
},
926+
{
927+
"flavor": objects.Flavor(),
928+
"image": {
929+
"properties": {
930+
"hw_cpu_policy": "shared"
931+
}
932+
},
933+
"expect": fields.CPUAllocationPolicy.SHARED
934+
},
935+
{
936+
"flavor": objects.Flavor(),
937+
"image": {
938+
"properties": {
939+
}
940+
},
941+
"expect": None
942+
},
943+
{
944+
"flavor": objects.Flavor(extra_specs={
945+
"hw:cpu_policy": "invalid"
946+
}),
947+
"image": {
948+
"properties": {
949+
}
950+
},
951+
"expect": exception.InvalidCPUAllocationPolicy
952+
},
953+
]
954+
955+
for testitem in testdata:
956+
image_meta = objects.ImageMeta.from_dict(testitem["image"])
957+
if testitem["expect"] is None:
958+
cpu_policy = hw.get_cpu_policy_constraint(
959+
testitem["flavor"], image_meta)
960+
self.assertIsNone(cpu_policy)
961+
elif type(testitem["expect"]) == type:
962+
self.assertRaises(testitem["expect"],
963+
hw.get_cpu_policy_constraint,
964+
testitem["flavor"],
965+
image_meta)
966+
else:
967+
cpu_policy = hw.get_cpu_policy_constraint(
968+
testitem["flavor"], image_meta)
969+
self.assertIsNotNone(cpu_policy)
970+
self.assertEqual(testitem["expect"], cpu_policy)
971+
851972
def test_topology_constraints(self):
852973
testdata = [
853974
{

nova/virt/hardware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ def get_cpu_policy_constraint(flavor, image_meta):
15121512
if image_policy == fields.CPUAllocationPolicy.DEDICATED:
15131513
raise exception.ImageCPUPinningForbidden()
15141514
cpu_policy = flavor_policy
1515-
elif image_policy == fields.CPUAllocationPolicy.DEDICATED:
1515+
elif image_policy in fields.CPUAllocationPolicy.ALL:
15161516
cpu_policy = image_policy
15171517
else:
15181518
cpu_policy = None

0 commit comments

Comments
 (0)