Addition of host to host-aggregate should be case -sensitive

Bug #1709260 reported by Rajesh Tailor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Rajesh Tailor
Pike
Fix Committed
Low
Rajesh Tailor
Queens
Fix Committed
Low
Rajesh Tailor

Bug Description

I have multinode devstack setup with 2 compute and a controller node.
The hostnames of the nodes are as follows:
controller: controller.example.com
compute0: compute0.example.com
compute1: compute1.example.com

Reproduction steps:

1) I have created a host-aggregate in availability zone "nova".
    nova aggregate-create test_agg nova

2) Then I set metadata on that host-aggregate.
    nova aggregate-set-metadata 1 ssd=true

3) Then I added compute hosts mentioned above to host-aggregate.
    nova aggregate-add-host test_agg COMPUTE0.example.com
    nova aggregate-add-host test_agg compute1.example.com

While adding compute0 to host-aggregate, if I provide hostname as "COMPUTE0.example.com", instead of
throwing HostNotFound error, it is added to host-aggregate.

4) After that I have created a flavor.
nova flavor-create ssd.large 6 8192 80 4

5) Added metadata to flavor.
nova flavor-key ssd.large set ssd=true

Now when I try to create instance with above mentioned flavor, I can't spawn it on compute0 host. As scheduler is filtering only compute1 with AggregateInstanceExtraSpecsFilter filter.

Expected Result: while adding the case-sensitive host to host-aggregate, nova-api should have thrown HostNotFound error.

Note: when I add the correct hostname "compute0.example.com", I am able to spawn instance on with above mentioned flavor on compute0 host and it is filtered by AggregateInstanceExtraSpecFilter as well.

Rajesh Tailor (ratailor)
Changed in nova:
assignee: nobody → Rajesh Tailor (ratailor)
Rajesh Tailor (ratailor)
description: updated
Revision history for this message
Sylvain Bauza (sylvain-bauza) wrote :

For clarity on the bug report, could you please provide the nova-sceduler log that shows the filter missing that host because the name is different ?

TBC, all FQDNs are case-sensitive, so we should probably indeed return a 404 when you're trying to add a host with the wrong case. The only point I wonder is whether it would require a new API microversion since we were previously accepting that from a REST perpective (my guts tend to say yes to that :( )

Changed in nova:
status: New → Confirmed
importance: Undecided → Low
tags: added: api
Revision history for this message
Rajesh Tailor (ratailor) wrote :

Hi Sylvain,

I have debugged the issue and found that IMO it has nothing to do with scheduler.

While adding host to host-aggregate, the below db query should not matched to existing db record.
Since mysql doesn't support case-sensitive column.

The problematic block of code is below:
https://github.com/openstack/nova/blob/master/nova/objects/host_mapping.py#L90-L93

    def _get_by_host_from_db(context, host):
        db_mapping = (context.session.query(api_models.HostMapping)
                      .options(joinedload('cell_mapping'))
                      .filter(api_models.HostMapping.host == host)).first()

Revision history for this message
Alex Xu (xuhj) wrote :

I think it is the problem of inconsistent behavior between mysql DB and the in-memory cache in the nova scheduler.

The mysql Db doesn't support case-sensitive filtering, so the API layer can ensure the host existed. But there is in-memory cache build in the scheduler https://github.com/openstack/nova/blob/master/nova/scheduler/host_manager.py#L359, it becomes case-senstive for the key of a dict.

Revision history for this message
Rajesh Tailor (ratailor) wrote :

Please find the attached n-sch logs for more information.

Revision history for this message
Alex Xu (xuhj) wrote :
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/498334

Changed in nova:
status: Confirmed → In Progress
Revision history for this message
Jay Pipes (jaypipes) wrote :

For the record, MySQL *does* support case-sensitive matching. It's just not the default.

Adding case-sensitive matching is as simple as changing the default collation to latin1_swedish_cs instead of latin1_swedish_ci. Or utf8_general_cs instead of utf8_general_ci if the character set on the column in question is UTF8.

Revision history for this message
Jay Pipes (jaypipes) wrote :

According to https://github.com/openstack/nova/blob/c0350da4a1607d7aa113caceaefb5d29303c7eed/nova/db/sqlalchemy/api_models.py#L53, there is no character set specified for the aggregate_hosts.host field (and there is no default in the oslo_db.sqlalchemy.models.ModelBase class) so the default character set will be latin1_swedish_ci.

It would be a fairly massive undertaking to "fix" this in all of Nova. We'd have to add default character set + collation clauses to all models and add a single DB schema migration that would change the character set and collation for all columns in question. This would require an offline data migration since it wouldn't be a happy instantaneous schema change. So, we'd have to add duplicate columns with the "correct" collation, migrate/copy all the old data into the new columns, then delete the old columns.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/queens)

Fix proposed to branch: stable/queens
Review: https://review.openstack.org/585334

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/pike)

Fix proposed to branch: stable/pike
Review: https://review.openstack.org/585335

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/498334
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=0dc0db932e3ad5ad911f2072015cb9854f6e4e23
Submitter: Zuul
Branch: master

commit 0dc0db932e3ad5ad911f2072015cb9854f6e4e23
Author: Rajesh Tailor <email address hidden>
Date: Fri Aug 18 12:33:09 2017 +0530

    Make host_aggregate_map dictionary case-insensitive

    As of now, if hostname is set as "compute0.example.com" (in lower case)
    and user tries to add this host to host-aggregate but by-mistake types
    "COMPUTE0.example.com" (in capital case), then instead of throwing
    HostNotFound error, that host is successfully added to host-aggregate
    as "COMPUTE0.example.com". And after that if instance creation request
    with flavor matching metadata as host-aggregate metadata comes, this
    host is not filtered by scheduler, since there is no host with hostname
    COMPUTE0.example.com, as added in host-aggregate.

    Fixed the issue by lowercasing all hostnames in host_aggregate_map
    dictionary.

    Change-Id: Iee4b9bbf412adfdc6fdc62ea3429fb960d6ac2a2
    Closes-Bug: 1709260

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/queens)

Reviewed: https://review.openstack.org/585334
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=2caf8f65e414732fb1ef1ac32a5884a48af6655d
Submitter: Zuul
Branch: stable/queens

commit 2caf8f65e414732fb1ef1ac32a5884a48af6655d
Author: Rajesh Tailor <email address hidden>
Date: Fri Aug 18 12:33:09 2017 +0530

    Make host_aggregate_map dictionary case-insensitive

    As of now, if hostname is set as "compute0.example.com" (in lower case)
    and user tries to add this host to host-aggregate but by-mistake types
    "COMPUTE0.example.com" (in capital case), then instead of throwing
    HostNotFound error, that host is successfully added to host-aggregate
    as "COMPUTE0.example.com". And after that if instance creation request
    with flavor matching metadata as host-aggregate metadata comes, this
    host is not filtered by scheduler, since there is no host with hostname
    COMPUTE0.example.com, as added in host-aggregate.

    Fixed the issue by lowercasing all hostnames in host_aggregate_map
    dictionary.

    Change-Id: Iee4b9bbf412adfdc6fdc62ea3429fb960d6ac2a2
    Closes-Bug: 1709260
    (cherry picked from commit 0dc0db932e3ad5ad911f2072015cb9854f6e4e23)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 18.0.0.0b3

This issue was fixed in the openstack/nova 18.0.0.0b3 development milestone.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/pike)

Reviewed: https://review.openstack.org/585335
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=8f5fbd83de3759407b8f928159067211af156d60
Submitter: Zuul
Branch: stable/pike

commit 8f5fbd83de3759407b8f928159067211af156d60
Author: Rajesh Tailor <email address hidden>
Date: Fri Aug 18 12:33:09 2017 +0530

    Make host_aggregate_map dictionary case-insensitive

    As of now, if hostname is set as "compute0.example.com" (in lower case)
    and user tries to add this host to host-aggregate but by-mistake types
    "COMPUTE0.example.com" (in capital case), then instead of throwing
    HostNotFound error, that host is successfully added to host-aggregate
    as "COMPUTE0.example.com". And after that if instance creation request
    with flavor matching metadata as host-aggregate metadata comes, this
    host is not filtered by scheduler, since there is no host with hostname
    COMPUTE0.example.com, as added in host-aggregate.

    Fixed the issue by lowercasing all hostnames in host_aggregate_map
    dictionary.

    Change-Id: Iee4b9bbf412adfdc6fdc62ea3429fb960d6ac2a2
    Closes-Bug: 1709260
    (cherry picked from commit 0dc0db932e3ad5ad911f2072015cb9854f6e4e23)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 16.1.5

This issue was fixed in the openstack/nova 16.1.5 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 17.0.6

This issue was fixed in the openstack/nova 17.0.6 release.

Revision history for this message
Matt Riedemann (mriedem) wrote :

Note the change is being reverted https://review.openstack.org/#/c/604898/ due to it causing a regression, see bug 1793747.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/604906

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/rocky)

Fix proposed to branch: stable/rocky
Review: https://review.openstack.org/605261

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/queens)

Fix proposed to branch: stable/queens
Review: https://review.openstack.org/605267

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (stable/pike)

Fix proposed to branch: stable/pike
Review: https://review.openstack.org/605269

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/604906
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=c8e2de668434861b87495e0a0f715b2f90d8ec05
Submitter: Zuul
Branch: master

commit c8e2de668434861b87495e0a0f715b2f90d8ec05
Author: Dan Smith <email address hidden>
Date: Mon Sep 24 13:36:39 2018 -0700

    Enforce case-sensitive hostnames in aggregate host add

    If we are using a case-insensitive backend database like mysql, a
    user can request an aggregate host add with a non-matching hostname
    and we will not signal failure. We will create a mapping which will
    not actually include that host in the aggregate, which will be
    confusing later. This change makes us fail if the host name does not
    match exactly, which is the same behavior as if we are using a
    case-sensitive backend (like postgres).

    Change-Id: I597dee74d33de337913eddda74ab056fbf81a23c
    Closes-Bug: #1709260

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/rocky)

Reviewed: https://review.openstack.org/605261
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=c72bb2c747016b22e71109b9750d5899b776e67a
Submitter: Zuul
Branch: stable/rocky

commit c72bb2c747016b22e71109b9750d5899b776e67a
Author: Dan Smith <email address hidden>
Date: Mon Sep 24 13:36:39 2018 -0700

    Enforce case-sensitive hostnames in aggregate host add

    If we are using a case-insensitive backend database like mysql, a
    user can request an aggregate host add with a non-matching hostname
    and we will not signal failure. We will create a mapping which will
    not actually include that host in the aggregate, which will be
    confusing later. This change makes us fail if the host name does not
    match exactly, which is the same behavior as if we are using a
    case-sensitive backend (like postgres).

    Change-Id: I597dee74d33de337913eddda74ab056fbf81a23c
    Closes-Bug: #1709260
    (cherry picked from commit c8e2de668434861b87495e0a0f715b2f90d8ec05)

tags: added: in-stable-rocky
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/queens)

Reviewed: https://review.openstack.org/605267
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=22197f3d0156b9fb87a132e77ab44dbdd63bc826
Submitter: Zuul
Branch: stable/queens

commit 22197f3d0156b9fb87a132e77ab44dbdd63bc826
Author: Dan Smith <email address hidden>
Date: Mon Sep 24 13:36:39 2018 -0700

    Enforce case-sensitive hostnames in aggregate host add

    If we are using a case-insensitive backend database like mysql, a
    user can request an aggregate host add with a non-matching hostname
    and we will not signal failure. We will create a mapping which will
    not actually include that host in the aggregate, which will be
    confusing later. This change makes us fail if the host name does not
    match exactly, which is the same behavior as if we are using a
    case-sensitive backend (like postgres).

    Conflicts:
          nova/tests/unit/compute/test_compute.py
          nova/tests/unit/compute/test_host_api.py

    NOTE(mriedem): Conflicts are due to not having change
    Ibd7aa4f8c4ea787774becece324d9051521c44b6 in Queens.

    Change-Id: I597dee74d33de337913eddda74ab056fbf81a23c
    Closes-Bug: #1709260
    (cherry picked from commit c8e2de668434861b87495e0a0f715b2f90d8ec05)
    (cherry picked from commit c72bb2c747016b22e71109b9750d5899b776e67a)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 18.0.2

This issue was fixed in the openstack/nova 18.0.2 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 17.0.7

This issue was fixed in the openstack/nova 17.0.7 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (stable/pike)

Reviewed: https://review.openstack.org/605269
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=0bd38dbadcaeef59213e5471018649f7a9d2d9bf
Submitter: Zuul
Branch: stable/pike

commit 0bd38dbadcaeef59213e5471018649f7a9d2d9bf
Author: Dan Smith <email address hidden>
Date: Mon Sep 24 13:36:39 2018 -0700

    Enforce case-sensitive hostnames in aggregate host add

    If we are using a case-insensitive backend database like mysql, a
    user can request an aggregate host add with a non-matching hostname
    and we will not signal failure. We will create a mapping which will
    not actually include that host in the aggregate, which will be
    confusing later. This change makes us fail if the host name does not
    match exactly, which is the same behavior as if we are using a
    case-sensitive backend (like postgres).

    Change-Id: I597dee74d33de337913eddda74ab056fbf81a23c
    Closes-Bug: #1709260
    (cherry picked from commit c8e2de668434861b87495e0a0f715b2f90d8ec05)
    (cherry picked from commit c72bb2c747016b22e71109b9750d5899b776e67a)
    (cherry picked from commit 22197f3d0156b9fb87a132e77ab44dbdd63bc826)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 16.1.7

This issue was fixed in the openstack/nova 16.1.7 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/nova 19.0.0.0rc1

This issue was fixed in the openstack/nova 19.0.0.0rc1 release candidate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.