forked from openstack/nova
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[scheduler] Consolidate host_info/passes steps in filter & weigher #365
Open
fwiesel
wants to merge
1
commit into
stable/rocky-m3
Choose a base branch
from
scheduler_filter_host_info_requiring_instance_ids_reuse
base: stable/rocky-m3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,15 +32,22 @@ class DifferentHostFilter(filters.BaseHostFilter): | |||||
RUN_ON_REBUILD = False | ||||||
|
||||||
def host_passes(self, host_state, spec_obj): | ||||||
affinity_uuids = spec_obj.get_scheduler_hint('different_host') | ||||||
affinity_uuids = self.host_info_requiring_instance_ids(spec_obj) | ||||||
if affinity_uuids: | ||||||
overlap = utils.instance_uuids_overlap(host_state, affinity_uuids) | ||||||
return not overlap | ||||||
# With no different_host key | ||||||
return True | ||||||
|
||||||
def host_info_requiring_instance_ids(self, spec_obj): | ||||||
return set(spec_obj.get_scheduler_hint('different_host')) | ||||||
different_host = spec_obj.get_scheduler_hint('different_host') | ||||||
if not different_host: | ||||||
return different_host | ||||||
|
||||||
if isinstance(different_host, str): | ||||||
return set([different_host]) | ||||||
|
||||||
return set(different_host) | ||||||
|
||||||
|
||||||
class SameHostFilter(filters.BaseHostFilter): | ||||||
|
@@ -53,15 +60,22 @@ class SameHostFilter(filters.BaseHostFilter): | |||||
RUN_ON_REBUILD = False | ||||||
|
||||||
def host_passes(self, host_state, spec_obj): | ||||||
affinity_uuids = spec_obj.get_scheduler_hint('same_host') | ||||||
affinity_uuids = self.host_info_requiring_instance_ids(spec_obj) | ||||||
if affinity_uuids: | ||||||
overlap = utils.instance_uuids_overlap(host_state, affinity_uuids) | ||||||
return overlap | ||||||
# With no same_host key | ||||||
return True | ||||||
|
||||||
def host_info_requiring_instance_ids(self, spec_obj): | ||||||
return set(spec_obj.get_scheduler_hint('same_host')) | ||||||
same_host = spec_obj.get_scheduler_hint('same_host') | ||||||
if not same_host: | ||||||
return same_host | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above.
Suggested change
|
||||||
|
||||||
if isinstance(same_host, str): | ||||||
return set([same_host]) | ||||||
|
||||||
return set(same_host) | ||||||
|
||||||
|
||||||
class SimpleCIDRAffinityFilter(filters.BaseHostFilter): | ||||||
|
@@ -93,24 +107,25 @@ class _GroupAntiAffinityFilter(filters.BaseHostFilter): | |||||
RUN_ON_REBUILD = False | ||||||
|
||||||
def host_passes(self, host_state, spec_obj): | ||||||
# Only invoke the filter if 'anti-affinity' is configured | ||||||
instance_group = spec_obj.instance_group | ||||||
policy = instance_group.policy if instance_group else None | ||||||
if self.policy_name != policy: | ||||||
members = self.host_info_requiring_instance_ids(spec_obj) | ||||||
# Only invoke the filter if 'anti-affinity' is configured, | ||||||
# and there are any instances to consider | ||||||
if not members: | ||||||
return True | ||||||
|
||||||
# NOTE(hanrong): Move operations like resize can check the same source | ||||||
# compute node where the instance is. That case, AntiAffinityFilter | ||||||
# must not return the source as a non-possible destination. | ||||||
if spec_obj.instance_uuid in host_state.instances.keys(): | ||||||
return True | ||||||
|
||||||
# The list of instances UUIDs on the given host | ||||||
instances = set(host_state.instances.keys()) | ||||||
# The list of instances UUIDs which are members of this group | ||||||
members = set(spec_obj.instance_group.members) | ||||||
# The set of instances on the host that are also members of this group | ||||||
servers_on_host = instances.intersection(members) | ||||||
|
||||||
instance_group = spec_obj.instance_group | ||||||
|
||||||
rules = instance_group.rules | ||||||
if rules and 'max_server_per_host' in rules: | ||||||
max_server_per_host = rules['max_server_per_host'] | ||||||
|
@@ -137,9 +152,11 @@ def host_passes(self, host_state, spec_obj): | |||||
def host_info_requiring_instance_ids(self, spec_obj): | ||||||
instance_group = spec_obj.instance_group | ||||||
policy = instance_group.policy if instance_group else None | ||||||
|
||||||
if self.policy_name != policy: | ||||||
return set() | ||||||
|
||||||
# The list of instances UUIDs which are members of this group | ||||||
return set(spec_obj.instance_group.members) | ||||||
|
||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to return a
set
always? If you do, then I'd do it explicitly, or else risk returningNone
or even an empty string: