Change deprecated policies to policy
The policies is deprecated in
8fa70e5dfc
, and is replaced with
policy field.
This patch changes deprecated policies to policy.
Change-Id: Iac3f666d53a48cdef26be4d17754fd0a481306a5
This commit is contained in:
parent
2afc5fed1f
commit
020edde12f
|
@ -349,7 +349,7 @@ class RequestSpec(base.NovaObject):
|
||||||
# the existing dictionary as a primitive.
|
# the existing dictionary as a primitive.
|
||||||
return {'group_updated': True,
|
return {'group_updated': True,
|
||||||
'group_hosts': set(self.instance_group.hosts),
|
'group_hosts': set(self.instance_group.hosts),
|
||||||
'group_policies': set(self.instance_group.policies),
|
'group_policies': set([self.instance_group.policy]),
|
||||||
'group_members': set(self.instance_group.members)}
|
'group_members': set(self.instance_group.members)}
|
||||||
|
|
||||||
def to_legacy_request_spec_dict(self):
|
def to_legacy_request_spec_dict(self):
|
||||||
|
|
|
@ -41,7 +41,7 @@ LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF = nova.conf.CONF
|
CONF = nova.conf.CONF
|
||||||
|
|
||||||
GroupDetails = collections.namedtuple('GroupDetails', ['hosts', 'policies',
|
GroupDetails = collections.namedtuple('GroupDetails', ['hosts', 'policy',
|
||||||
'members'])
|
'members'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -795,29 +795,28 @@ def _get_group_details(context, instance_uuid, user_group_hosts=None):
|
||||||
|
|
||||||
policies = set(('anti-affinity', 'affinity', 'soft-affinity',
|
policies = set(('anti-affinity', 'affinity', 'soft-affinity',
|
||||||
'soft-anti-affinity'))
|
'soft-anti-affinity'))
|
||||||
if any((policy in policies) for policy in group.policies):
|
if group.policy in policies:
|
||||||
if not _SUPPORTS_AFFINITY and 'affinity' in group.policies:
|
if not _SUPPORTS_AFFINITY and 'affinity' == group.policy:
|
||||||
msg = _("ServerGroupAffinityFilter not configured")
|
msg = _("ServerGroupAffinityFilter not configured")
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exception.UnsupportedPolicyException(reason=msg)
|
raise exception.UnsupportedPolicyException(reason=msg)
|
||||||
if not _SUPPORTS_ANTI_AFFINITY and 'anti-affinity' in group.policies:
|
if not _SUPPORTS_ANTI_AFFINITY and 'anti-affinity' == group.policy:
|
||||||
msg = _("ServerGroupAntiAffinityFilter not configured")
|
msg = _("ServerGroupAntiAffinityFilter not configured")
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exception.UnsupportedPolicyException(reason=msg)
|
raise exception.UnsupportedPolicyException(reason=msg)
|
||||||
if (not _SUPPORTS_SOFT_AFFINITY
|
if (not _SUPPORTS_SOFT_AFFINITY and 'soft-affinity' == group.policy):
|
||||||
and 'soft-affinity' in group.policies):
|
|
||||||
msg = _("ServerGroupSoftAffinityWeigher not configured")
|
msg = _("ServerGroupSoftAffinityWeigher not configured")
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exception.UnsupportedPolicyException(reason=msg)
|
raise exception.UnsupportedPolicyException(reason=msg)
|
||||||
if (not _SUPPORTS_SOFT_ANTI_AFFINITY
|
if (not _SUPPORTS_SOFT_ANTI_AFFINITY
|
||||||
and 'soft-anti-affinity' in group.policies):
|
and 'soft-anti-affinity' == group.policy):
|
||||||
msg = _("ServerGroupSoftAntiAffinityWeigher not configured")
|
msg = _("ServerGroupSoftAntiAffinityWeigher not configured")
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise exception.UnsupportedPolicyException(reason=msg)
|
raise exception.UnsupportedPolicyException(reason=msg)
|
||||||
group_hosts = set(group.get_hosts())
|
group_hosts = set(group.get_hosts())
|
||||||
user_hosts = set(user_group_hosts) if user_group_hosts else set()
|
user_hosts = set(user_group_hosts) if user_group_hosts else set()
|
||||||
return GroupDetails(hosts=user_hosts | group_hosts,
|
return GroupDetails(hosts=user_hosts | group_hosts,
|
||||||
policies=group.policies, members=group.members)
|
policy=group.policy, members=group.members)
|
||||||
|
|
||||||
|
|
||||||
def setup_instance_group(context, request_spec):
|
def setup_instance_group(context, request_spec):
|
||||||
|
@ -835,7 +834,7 @@ def setup_instance_group(context, request_spec):
|
||||||
group_info = _get_group_details(context, instance_uuid, group_hosts)
|
group_info = _get_group_details(context, instance_uuid, group_hosts)
|
||||||
if group_info is not None:
|
if group_info is not None:
|
||||||
request_spec.instance_group.hosts = list(group_info.hosts)
|
request_spec.instance_group.hosts = list(group_info.hosts)
|
||||||
request_spec.instance_group.policies = group_info.policies
|
request_spec.instance_group.policy = group_info.policy
|
||||||
request_spec.instance_group.members = group_info.members
|
request_spec.instance_group.members = group_info.members
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ class _SoftAffinityWeigherBase(weights.BaseHostWeigher):
|
||||||
if not request_spec.instance_group:
|
if not request_spec.instance_group:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
policies = request_spec.instance_group.policies
|
policy = request_spec.instance_group.policy
|
||||||
|
|
||||||
if self.policy_name not in policies:
|
if self.policy_name != policy:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
instances = set(host_state.instances.keys())
|
instances = set(host_state.instances.keys())
|
||||||
|
|
|
@ -466,7 +466,7 @@ class _TestRequestSpecObject(object):
|
||||||
disk_gb=10.0,
|
disk_gb=10.0,
|
||||||
memory_mb=8192.0),
|
memory_mb=8192.0),
|
||||||
instance_group=objects.InstanceGroup(hosts=['fake1'],
|
instance_group=objects.InstanceGroup(hosts=['fake1'],
|
||||||
policies=['affinity'],
|
policy='affinity',
|
||||||
members=['inst1', 'inst2']),
|
members=['inst1', 'inst2']),
|
||||||
scheduler_hints={'foo': ['bar']},
|
scheduler_hints={'foo': ['bar']},
|
||||||
requested_destination=fake_dest)
|
requested_destination=fake_dest)
|
||||||
|
|
|
@ -307,7 +307,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase):
|
||||||
group.name = 'pele'
|
group.name = 'pele'
|
||||||
group.uuid = uuids.fake
|
group.uuid = uuids.fake
|
||||||
group.members = [instance.uuid]
|
group.members = [instance.uuid]
|
||||||
group.policies = [policy]
|
group.policy = policy
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def _get_group_details(self, group, policy=None):
|
def _get_group_details(self, group, policy=None):
|
||||||
|
@ -324,7 +324,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase):
|
||||||
group_info = scheduler_utils._get_group_details(
|
group_info = scheduler_utils._get_group_details(
|
||||||
self.context, 'fake_uuid', group_hosts)
|
self.context, 'fake_uuid', group_hosts)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
(set(['hostA', 'hostB']), [policy], group.members),
|
(set(['hostA', 'hostB']), policy, group.members),
|
||||||
group_info)
|
group_info)
|
||||||
|
|
||||||
def test_get_group_details(self):
|
def test_get_group_details(self):
|
||||||
|
@ -347,7 +347,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase):
|
||||||
group = objects.InstanceGroup()
|
group = objects.InstanceGroup()
|
||||||
group.uuid = uuids.fake
|
group.uuid = uuids.fake
|
||||||
group.members = [instance.uuid]
|
group.members = [instance.uuid]
|
||||||
group.policies = [policy]
|
group.policy = policy
|
||||||
|
|
||||||
with test.nested(
|
with test.nested(
|
||||||
mock.patch.object(objects.InstanceGroup, 'get_by_instance_uuid',
|
mock.patch.object(objects.InstanceGroup, 'get_by_instance_uuid',
|
||||||
|
@ -370,7 +370,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase):
|
||||||
@mock.patch.object(scheduler_utils, '_get_group_details')
|
@mock.patch.object(scheduler_utils, '_get_group_details')
|
||||||
def test_setup_instance_group_in_request_spec(self, mock_ggd):
|
def test_setup_instance_group_in_request_spec(self, mock_ggd):
|
||||||
mock_ggd.return_value = scheduler_utils.GroupDetails(
|
mock_ggd.return_value = scheduler_utils.GroupDetails(
|
||||||
hosts=set(['hostA', 'hostB']), policies=['policy'],
|
hosts=set(['hostA', 'hostB']), policy='policy',
|
||||||
members=['instance1'])
|
members=['instance1'])
|
||||||
spec = objects.RequestSpec(instance_uuid=uuids.instance)
|
spec = objects.RequestSpec(instance_uuid=uuids.instance)
|
||||||
spec.instance_group = objects.InstanceGroup(hosts=['hostC'])
|
spec.instance_group = objects.InstanceGroup(hosts=['hostC'])
|
||||||
|
@ -381,7 +381,7 @@ class SchedulerUtilsTestCase(test.NoDBTestCase):
|
||||||
['hostC'])
|
['hostC'])
|
||||||
# Given it returns a list from a set, make sure it's sorted.
|
# Given it returns a list from a set, make sure it's sorted.
|
||||||
self.assertEqual(['hostA', 'hostB'], sorted(spec.instance_group.hosts))
|
self.assertEqual(['hostA', 'hostB'], sorted(spec.instance_group.hosts))
|
||||||
self.assertEqual(['policy'], spec.instance_group.policies)
|
self.assertEqual('policy', spec.instance_group.policy)
|
||||||
self.assertEqual(['instance1'], spec.instance_group.members)
|
self.assertEqual(['instance1'], spec.instance_group.members)
|
||||||
|
|
||||||
@mock.patch.object(scheduler_utils, '_get_group_details')
|
@mock.patch.object(scheduler_utils, '_get_group_details')
|
||||||
|
|
|
@ -32,7 +32,7 @@ class SoftWeigherTestBase(test.NoDBTestCase):
|
||||||
def _get_weighed_host(self, hosts, policy):
|
def _get_weighed_host(self, hosts, policy):
|
||||||
request_spec = objects.RequestSpec(
|
request_spec = objects.RequestSpec(
|
||||||
instance_group=objects.InstanceGroup(
|
instance_group=objects.InstanceGroup(
|
||||||
policies=[policy],
|
policy=policy,
|
||||||
members=['member1',
|
members=['member1',
|
||||||
'member2',
|
'member2',
|
||||||
'member3',
|
'member3',
|
||||||
|
|
Loading…
Reference in New Issue