From 090ca81fa0b347b13cc873aaf00aaa343380a001 Mon Sep 17 00:00:00 2001 From: Pavlo Shchelokovskyy Date: Wed, 5 Jul 2023 13:27:46 +0300 Subject: [PATCH] Fix list of server migrations the _list method goes straight through to formatting base_path with attrs, and for server migrations the attr in the base path is server_uuid, not server_id. This patch fixes the base_path of the ServerMigration resource to use server_id stanza. Change-Id: I44335a22846f1a11ba60e8bb758b10c39e728897 Story: 2010633 Task: 47591 (cherry picked from commit 8c988b7e627ef802c019979c26fd5cac24871473) --- openstack/compute/v2/server_migration.py | 15 ++++++--------- .../unit/compute/v2/test_server_migration.py | 5 +++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/openstack/compute/v2/server_migration.py b/openstack/compute/v2/server_migration.py index eb89de1c8..42585ab32 100644 --- a/openstack/compute/v2/server_migration.py +++ b/openstack/compute/v2/server_migration.py @@ -18,15 +18,15 @@ from openstack import utils class ServerMigration(resource.Resource): resource_key = 'migration' resources_key = 'migrations' - base_path = '/servers/%(server_uuid)s/migrations' + base_path = '/servers/%(server_id)s/migrations' # capabilities allow_fetch = True allow_list = True allow_delete = True - #: The ID for the server. - server_id = resource.URI('server_uuid') + #: The ID for the server from the URI of the resource + server_id = resource.URI('server_id') #: The date and time when the resource was created. created_at = resource.Body('created_at') @@ -53,11 +53,8 @@ class ServerMigration(resource.Resource): #: The ID of the project that initiated the server migration (since #: microversion 2.80) project_id = resource.Body('project_id') - # FIXME(stephenfin): This conflicts since there is a server ID in the URI - # *and* in the body. We need a field that handles both or we need to use - # different names. - # #: The UUID of the server - # server_id = resource.Body('server_uuid') + #: The UUID of the server from the response body + server_uuid = resource.Body('server_uuid') #: The source compute of the migration. source_compute = resource.Body('source_compute') #: The source node of the migration. @@ -80,7 +77,7 @@ class ServerMigration(resource.Resource): microversion = self._get_microversion(session, action='list') url = utils.urljoin( - self.base_path % {'server_uuid': self.server_id}, + self.base_path % {'server_id': self.server_id}, self.id, 'action', ) diff --git a/openstack/tests/unit/compute/v2/test_server_migration.py b/openstack/tests/unit/compute/v2/test_server_migration.py index cc309f683..936a6ca9b 100644 --- a/openstack/tests/unit/compute/v2/test_server_migration.py +++ b/openstack/tests/unit/compute/v2/test_server_migration.py @@ -17,6 +17,7 @@ from openstack.tests.unit import base EXAMPLE = { 'id': 4, + 'server_id': '4cfba335-03d8-49b2-8c52-e69043d1e8fe', 'server_uuid': '4cfba335-03d8-49b2-8c52-e69043d1e8fe', 'user_id': '8dbaa0f0-ab95-4ffe-8cb4-9c89d2ac9d24', 'project_id': '5f705771-3aa9-4f4c-8660-0d9522ffdbea', @@ -51,7 +52,7 @@ class TestServerMigration(base.TestCase): sot = server_migration.ServerMigration() self.assertEqual('migration', sot.resource_key) self.assertEqual('migrations', sot.resources_key) - self.assertEqual('/servers/%(server_uuid)s/migrations', sot.base_path) + self.assertEqual('/servers/%(server_id)s/migrations', sot.base_path) self.assertFalse(sot.allow_create) self.assertTrue(sot.allow_fetch) self.assertTrue(sot.allow_list) @@ -105,7 +106,7 @@ class TestServerMigration(base.TestCase): self.assertIsNone(sot.force_complete(self.sess)) url = 'servers/%s/migrations/%s/action' % ( - EXAMPLE['server_uuid'], + EXAMPLE['server_id'], EXAMPLE['id'], ) body = {'force_complete': None}