Key-pair is not updated during the rebuild

Bug #1843708 reported by Quentin GROLLEAU on 2019-09-12
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Undecided
Stephen Finucane
Queens
Undecided
Stephen Finucane
Rocky
Undecided
Stephen Finucane
Stein
Undecided
Stephen Finucane
Train
Undecided
Unassigned
Ussuri
Undecided
Unassigned

Bug Description

Description
===========

When we want to rebuild an instance and change the keypair we can specified it with :
openstack --os-compute-api-version 2.54 server rebuild --image "Debian 10" --key-name key1 instance1

This comes from this implementation :
https://review.opendev.org/#/c/379128/
https://specs.openstack.org/openstack/nova-specs/specs/queens/implemented/rebuild-keypair-reset.html

But when rebuilding the instance, Cloud-Init will set the key in authorized_keys from
http://169.254.169.254/openstack/latest/meta_data.json

And this meta_data.json uses the keys from instance_extra tables
But the keypair will be updated in the 'instances' table but not in the 'instance_extra' table.

So the keypair is not updated inside the VM

May be this is the function for saving the keypair, but the save() do nothing :
https://opendev.org/openstack/nova/src/branch/master/nova/objects/instance.py#L714

Steps to reproduce
==================

- Deploy a DevStack
- Boot an instance with keypair key1
- Rebuild it with key2
- A nova show will show the key_name key2, keypairs object in table instance_extra is not updated and you cannot connect with key2 to the instance

Expected result
===============
Connecte to the Vm with the new keypair added during the rebuild call

Actual result
=============
The keypair added during the rebuild call is not set in the VM

Environment
===========
I tested it on a Devstack from master and we have the behaviour.
NOVA : commit 5fa49cd0b8b6015aa61b4312b2ce1ae780c42c64

Matt Riedemann (mriedem) on 2019-09-12
tags: added: keypairs rebuild
Changed in nova:
assignee: nobody → Takashi NATSUME (natsume-takashi)
Changed in nova:
status: New → Confirmed

Fix proposed to branch: master
Review: https://review.opendev.org/683043

Changed in nova:
status: Confirmed → In Progress
Changed in nova:
assignee: Takashi Natsume (natsume-takashi) → nobody
Changed in nova:
assignee: nobody → Stephen Finucane (stephenfinucane)

Change abandoned by Stephen Finucane (<email address hidden>) on branch: master
Review: https://review.opendev.org/738583

Changed in nova:
assignee: Stephen Finucane (stephenfinucane) → Takashi Natsume (natsume-takashi)
Changed in nova:
assignee: Takashi Natsume (natsume-takashi) → Stephen Finucane (stephenfinucane)

Reviewed: https://review.opendev.org/683043
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=086796021b189c3ac64805ed8f6bde833906d284
Submitter: Zuul
Branch: master

commit 086796021b189c3ac64805ed8f6bde833906d284
Author: Takashi NATSUME <email address hidden>
Date: Thu Sep 19 15:57:44 2019 +0900

    objects: Update keypairs when saving an instance

    The keypair of a server is updated when rebuilding the server with a
    keypair. This function has been added since API microversion 2.54.
    However the 'keypairs' of the instance object is not saved when saving
    the instance object currently.

    Make the instance object update the 'keypairs' field when saving the
    instance object.

    Change-Id: I8a2726b39d0444de8c35480024078a97430f5d0c
    Closes-Bug: #1843708
    Co-authored-by: Stephen Finucane <email address hidden>

Changed in nova:
status: In Progress → Fix Released

Reviewed: https://review.opendev.org/742631
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=aed86ee5d6289edf1baf9fe0b2a9e509031fdd25
Submitter: Zuul
Branch: stable/ussuri

commit aed86ee5d6289edf1baf9fe0b2a9e509031fdd25
Author: Takashi NATSUME <email address hidden>
Date: Thu Sep 19 15:57:44 2019 +0900

    objects: Update keypairs when saving an instance

    The keypair of a server is updated when rebuilding the server with a
    keypair. This function has been added since API microversion 2.54.
    However the 'keypairs' of the instance object is not saved when saving
    the instance object currently.

    Make the instance object update the 'keypairs' field when saving the
    instance object.

    Change-Id: I8a2726b39d0444de8c35480024078a97430f5d0c
    Closes-Bug: #1843708
    Co-authored-by: Stephen Finucane <email address hidden>
    (cherry picked from commit 086796021b189c3ac64805ed8f6bde833906d284)

Reviewed: https://review.opendev.org/742709
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=b971dc82cb524fe86284c95ec671e2bad1c2874f
Submitter: Zuul
Branch: stable/train

commit b971dc82cb524fe86284c95ec671e2bad1c2874f
Author: Takashi NATSUME <email address hidden>
Date: Thu Sep 19 15:57:44 2019 +0900

    objects: Update keypairs when saving an instance

    The keypair of a server is updated when rebuilding the server with a
    keypair. This function has been added since API microversion 2.54.
    However the 'keypairs' of the instance object is not saved when saving
    the instance object currently.

    Make the instance object update the 'keypairs' field when saving the
    instance object.

    Conflicts:
            nova/tests/unit/fake_instance.py

    NOTE(stephenfin): Conflicts are due to change
    I44ad826f0edb39d770bb3201c675dff78154cbf3 ("partial support for live
    migration with specific resources"), which initialized the
    'migration_context' attribute of the instance created as part of the
    'fake_instance_obj' function.

    Changes:
            nova/tests/functional/regressions/test_bug_1843708.py

    NOTE(stephenfin): The 'IntegratedTestBase' and 'InstanceHelperMixin'
    base classes for functional tests are not fully integrated yet in
    stable/train, which requires reinventing the wheel somewhat.

    Change-Id: I8a2726b39d0444de8c35480024078a97430f5d0c
    Closes-Bug: #1843708
    Co-authored-by: Stephen Finucane <email address hidden>
    (cherry picked from commit 086796021b189c3ac64805ed8f6bde833906d284)
    (cherry picked from commit aed86ee5d6289edf1baf9fe0b2a9e509031fdd25)

Reviewed: https://review.opendev.org/743264
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=0bc5a4ecb524a73aacb5d0dd2887799885bdbb14
Submitter: Zuul
Branch: stable/stein

commit 0bc5a4ecb524a73aacb5d0dd2887799885bdbb14
Author: Takashi NATSUME <email address hidden>
Date: Thu Sep 19 15:57:44 2019 +0900

    objects: Update keypairs when saving an instance

    The keypair of a server is updated when rebuilding the server with a
    keypair. This function has been added since API microversion 2.54.
    However the 'keypairs' of the instance object is not saved when saving
    the instance object currently.

    Make the instance object update the 'keypairs' field when saving the
    instance object.

    Conflicts:
            nova/tests/unit/fake_instance.py
            nova/tests/unit/objects/test_instance.py

    NOTE(stephenfin): Conflicts in 'fake_instance.py' are due to change
    If7f48933db10fcca3b9a05e1e978dfc51f6dabd0 ("Claim resources in resource
    tracker"), which is related to the vPMEM work and shouldn't be
    backported, while the conflicts in 'test_instance.py' are due to change
    Ic89352a9900515484bffe961475feb1cefc6b2a9 ("Remove
    'instance_update_at_top', 'instance_destroy_at_top'") which removed some
    cells v1 tests but shouldn't be removed here where cells v1 is
    technically still a thing.

    Change-Id: I8a2726b39d0444de8c35480024078a97430f5d0c
    Closes-Bug: #1843708
    Co-authored-by: Stephen Finucane <email address hidden>
    (cherry picked from commit 086796021b189c3ac64805ed8f6bde833906d284)
    (cherry picked from commit aed86ee5d6289edf1baf9fe0b2a9e509031fdd25)
    (cherry picked from commit b971dc82cb524fe86284c95ec671e2bad1c2874f)

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

commit aa7a6939d5177c0dd8c9f5a7bf7975264d2f5a2a
Author: Takashi NATSUME <email address hidden>
Date: Thu Sep 19 15:57:44 2019 +0900

    objects: Update keypairs when saving an instance

    The keypair of a server is updated when rebuilding the server with a
    keypair. This function has been added since API microversion 2.54.
    However the 'keypairs' of the instance object is not saved when saving
    the instance object currently.

    Make the instance object update the 'keypairs' field when saving the
    instance object.

    Changes:
            nova/tests/functional/regressions/test_bug_1843708.py

    NOTE(stephenfin): Changes are necessary since 'PlacementFixture' moved
    in stable/stein with change Idaed39629095f86d24a54334c699a26c218c6593
    but it's still in the old place here.

    Change-Id: I8a2726b39d0444de8c35480024078a97430f5d0c
    Closes-Bug: #1843708
    Co-authored-by: Stephen Finucane <email address hidden>
    (cherry picked from commit 086796021b189c3ac64805ed8f6bde833906d284)
    (cherry picked from commit aed86ee5d6289edf1baf9fe0b2a9e509031fdd25)
    (cherry picked from commit b971dc82cb524fe86284c95ec671e2bad1c2874f)
    (cherry picked from commit 0bc5a4ecb524a73aacb5d0dd2887799885bdbb14)

Reviewed: https://review.opendev.org/743271
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=6a7a78a44ea19497ea3e331ddd672f95cd49c50e
Submitter: Zuul
Branch: stable/queens

commit 6a7a78a44ea19497ea3e331ddd672f95cd49c50e
Author: Takashi NATSUME <email address hidden>
Date: Thu Sep 19 15:57:44 2019 +0900

    objects: Update keypairs when saving an instance

    The keypair of a server is updated when rebuilding the server with a
    keypair. This function has been added since API microversion 2.54.
    However the 'keypairs' of the instance object is not saved when saving
    the instance object currently.

    Make the instance object update the 'keypairs' field when saving the
    instance object.

    Change-Id: I8a2726b39d0444de8c35480024078a97430f5d0c
    Closes-Bug: #1843708
    Co-authored-by: Stephen Finucane <email address hidden>
    (cherry picked from commit 086796021b189c3ac64805ed8f6bde833906d284)
    (cherry picked from commit aed86ee5d6289edf1baf9fe0b2a9e509031fdd25)
    (cherry picked from commit b971dc82cb524fe86284c95ec671e2bad1c2874f)
    (cherry picked from commit 0bc5a4ecb524a73aacb5d0dd2887799885bdbb14)
    (cherry picked from commit aa7a6939d5177c0dd8c9f5a7bf7975264d2f5a2a)

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

Other bug subscribers