Skip to content

Commit ed87f79

Browse files
committed
Correct REST API response fields for /os-migrations API
The compute APIs are unfortunately inconsistent with regard to the response parameters for migrations. * GET /servers/{server_id}/migrations returns server_uuid * GET /os-migrations returns instance_uuid Because the 'Server UUID' column is being specified for parsing the response from GET /os-migrations, it is always showing as an empty string to users. There are a few other mismatches between the column names and the REST API response fields [1]: * 'Old Flavor' vs 'old_instance_type_id' * 'New Flavor' vs 'new_instance_type_id' * 'Type' vs 'migration_type' This adds a new list containing the REST API response field names to pass to utils.get_item_properties so that the responses are correctly parsed and the client output contains the response data instead of empty strings. Story: 2009078 Task: 42890 [1] https://docs.openstack.org/api-ref/compute/?expanded=list-migrations-detail#list-migrations Change-Id: I8aab60619e0225047f6a1c31e44917ca8fcc799e
1 parent 59256be commit ed87f79

3 files changed

Lines changed: 77 additions & 12 deletions

File tree

openstackclient/compute/v2/server.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,28 +2781,41 @@ def get_parser(self, prog_name):
27812781
return parser
27822782

27832783
def print_migrations(self, parsed_args, compute_client, migrations):
2784-
columns = [
2784+
column_headers = [
27852785
'Source Node', 'Dest Node', 'Source Compute', 'Dest Compute',
27862786
'Dest Host', 'Status', 'Server UUID', 'Old Flavor', 'New Flavor',
27872787
'Created At', 'Updated At',
27882788
]
27892789

2790+
# Response fields coming back from the REST API are not always exactly
2791+
# the same as the column header names.
2792+
columns = [
2793+
'source_node', 'dest_node', 'source_compute', 'dest_compute',
2794+
'dest_host', 'status', 'instance_uuid', 'old_instance_type_id',
2795+
'new_instance_type_id', 'created_at', 'updated_at',
2796+
]
2797+
27902798
# Insert migrations UUID after ID
27912799
if compute_client.api_version >= api_versions.APIVersion("2.59"):
2792-
columns.insert(0, "UUID")
2800+
column_headers.insert(0, "UUID")
2801+
columns.insert(0, "uuid")
27932802

27942803
if compute_client.api_version >= api_versions.APIVersion("2.23"):
2795-
columns.insert(0, "Id")
2796-
columns.insert(len(columns) - 2, "Type")
2804+
column_headers.insert(0, "Id")
2805+
columns.insert(0, "id")
2806+
column_headers.insert(len(column_headers) - 2, "Type")
2807+
columns.insert(len(columns) - 2, "migration_type")
27972808

27982809
if compute_client.api_version >= api_versions.APIVersion("2.80"):
27992810
if parsed_args.project:
2800-
columns.insert(len(columns) - 2, "Project")
2811+
column_headers.insert(len(column_headers) - 2, "Project")
2812+
columns.insert(len(columns) - 2, "project_id")
28012813
if parsed_args.user:
2802-
columns.insert(len(columns) - 2, "User")
2814+
column_headers.insert(len(column_headers) - 2, "User")
2815+
columns.insert(len(columns) - 2, "user_id")
28032816

28042817
return (
2805-
columns,
2818+
column_headers,
28062819
(utils.get_item_properties(mig, columns) for mig in migrations),
28072820
)
28082821

openstackclient/tests/unit/compute/v2/fakes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,20 +1587,20 @@ def create_one_migration(attrs=None, methods=None):
15871587
migration_info = {
15881588
"dest_host": "10.0.2.15",
15891589
"status": "migrating",
1590-
"type": "migration",
1590+
"migration_type": "migration",
15911591
"updated_at": "2017-01-31T08:03:25.000000",
15921592
"created_at": "2017-01-31T08:03:21.000000",
15931593
"dest_compute": "compute-" + uuid.uuid4().hex,
15941594
"id": random.randint(1, 999),
15951595
"source_node": "node-" + uuid.uuid4().hex,
1596-
"server": uuid.uuid4().hex,
1596+
"instance_uuid": uuid.uuid4().hex,
15971597
"dest_node": "node-" + uuid.uuid4().hex,
15981598
"source_compute": "compute-" + uuid.uuid4().hex,
15991599
"uuid": uuid.uuid4().hex,
16001600
"old_instance_type_id": uuid.uuid4().hex,
16011601
"new_instance_type_id": uuid.uuid4().hex,
1602-
"project": uuid.uuid4().hex,
1603-
"user": uuid.uuid4().hex
1602+
"project_id": uuid.uuid4().hex,
1603+
"user_id": uuid.uuid4().hex
16041604
}
16051605

16061606
# Overwrite default attributes.

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4909,6 +4909,13 @@ class TestListMigration(TestServer):
49094909
'Old Flavor', 'New Flavor', 'Created At', 'Updated At'
49104910
]
49114911

4912+
# These are the fields that come back in the response from the REST API.
4913+
MIGRATION_FIELDS = [
4914+
'source_node', 'dest_node', 'source_compute', 'dest_compute',
4915+
'dest_host', 'status', 'instance_uuid', 'old_instance_type_id',
4916+
'new_instance_type_id', 'created_at', 'updated_at'
4917+
]
4918+
49124919
def setUp(self):
49134920
super(TestListMigration, self).setUp()
49144921

@@ -4920,7 +4927,7 @@ def setUp(self):
49204927
self.migrations_mock.list.return_value = self.migrations
49214928

49224929
self.data = (common_utils.get_item_properties(
4923-
s, self.MIGRATION_COLUMNS) for s in self.migrations)
4930+
s, self.MIGRATION_FIELDS) for s in self.migrations)
49244931

49254932
# Get the command object to test
49264933
self.cmd = server.ListMigration(self.app, None)
@@ -4982,6 +4989,13 @@ class TestListMigrationV223(TestListMigration):
49824989
'Type', 'Created At', 'Updated At'
49834990
]
49844991

4992+
# These are the fields that come back in the response from the REST API.
4993+
MIGRATION_FIELDS = [
4994+
'id', 'source_node', 'dest_node', 'source_compute', 'dest_compute',
4995+
'dest_host', 'status', 'instance_uuid', 'old_instance_type_id',
4996+
'new_instance_type_id', 'migration_type', 'created_at', 'updated_at'
4997+
]
4998+
49854999
def setUp(self):
49865000
super(TestListMigrationV223, self).setUp()
49875001

@@ -5019,6 +5033,14 @@ class TestListMigrationV259(TestListMigration):
50195033
'Old Flavor', 'New Flavor', 'Type', 'Created At', 'Updated At'
50205034
]
50215035

5036+
# These are the fields that come back in the response from the REST API.
5037+
MIGRATION_FIELDS = [
5038+
'id', 'uuid', 'source_node', 'dest_node', 'source_compute',
5039+
'dest_compute', 'dest_host', 'status', 'instance_uuid',
5040+
'old_instance_type_id', 'new_instance_type_id', 'migration_type',
5041+
'created_at', 'updated_at'
5042+
]
5043+
50225044
def setUp(self):
50235045
super(TestListMigrationV259, self).setUp()
50245046

@@ -5125,6 +5147,14 @@ class TestListMigrationV266(TestListMigration):
51255147
'Old Flavor', 'New Flavor', 'Type', 'Created At', 'Updated At'
51265148
]
51275149

5150+
# These are the fields that come back in the response from the REST API.
5151+
MIGRATION_FIELDS = [
5152+
'id', 'uuid', 'source_node', 'dest_node', 'source_compute',
5153+
'dest_compute', 'dest_host', 'status', 'instance_uuid',
5154+
'old_instance_type_id', 'new_instance_type_id', 'migration_type',
5155+
'created_at', 'updated_at'
5156+
]
5157+
51285158
def setUp(self):
51295159
super(TestListMigrationV266, self).setUp()
51305160

@@ -5194,6 +5224,14 @@ class TestListMigrationV280(TestListMigration):
51945224
'Old Flavor', 'New Flavor', 'Type', 'Created At', 'Updated At'
51955225
]
51965226

5227+
# These are the fields that come back in the response from the REST API.
5228+
MIGRATION_FIELDS = [
5229+
'id', 'uuid', 'source_node', 'dest_node', 'source_compute',
5230+
'dest_compute', 'dest_host', 'status', 'instance_uuid',
5231+
'old_instance_type_id', 'new_instance_type_id', 'migration_type',
5232+
'created_at', 'updated_at'
5233+
]
5234+
51975235
project = identity_fakes.FakeProject.create_one_project()
51985236
user = identity_fakes.FakeUser.create_one_user()
51995237

@@ -5247,10 +5285,14 @@ def test_server_migration_list_with_project(self):
52475285

52485286
self.MIGRATION_COLUMNS.insert(
52495287
len(self.MIGRATION_COLUMNS) - 2, "Project")
5288+
self.MIGRATION_FIELDS.insert(
5289+
len(self.MIGRATION_FIELDS) - 2, "project_id")
52505290
self.assertEqual(self.MIGRATION_COLUMNS, columns)
52515291
self.assertEqual(tuple(self.data), tuple(data))
52525292
# Clean up global variables MIGRATION_COLUMNS
52535293
self.MIGRATION_COLUMNS.remove('Project')
5294+
# Clean up global variables MIGRATION_FIELDS
5295+
self.MIGRATION_FIELDS.remove('project_id')
52545296

52555297
def test_get_migrations_with_project_pre_v280(self):
52565298
self.app.client_manager.compute.api_version = api_versions.APIVersion(
@@ -5309,10 +5351,14 @@ def test_server_migration_list_with_user(self):
53095351

53105352
self.MIGRATION_COLUMNS.insert(
53115353
len(self.MIGRATION_COLUMNS) - 2, "User")
5354+
self.MIGRATION_FIELDS.insert(
5355+
len(self.MIGRATION_FIELDS) - 2, "user_id")
53125356
self.assertEqual(self.MIGRATION_COLUMNS, columns)
53135357
self.assertEqual(tuple(self.data), tuple(data))
53145358
# Clean up global variables MIGRATION_COLUMNS
53155359
self.MIGRATION_COLUMNS.remove('User')
5360+
# Clean up global variables MIGRATION_FIELDS
5361+
self.MIGRATION_FIELDS.remove('user_id')
53165362

53175363
def test_get_migrations_with_user_pre_v280(self):
53185364
self.app.client_manager.compute.api_version = api_versions.APIVersion(
@@ -5371,13 +5417,19 @@ def test_server_migration_list_with_project_and_user(self):
53715417

53725418
self.MIGRATION_COLUMNS.insert(
53735419
len(self.MIGRATION_COLUMNS) - 2, "Project")
5420+
self.MIGRATION_FIELDS.insert(
5421+
len(self.MIGRATION_FIELDS) - 2, "project_id")
53745422
self.MIGRATION_COLUMNS.insert(
53755423
len(self.MIGRATION_COLUMNS) - 2, "User")
5424+
self.MIGRATION_FIELDS.insert(
5425+
len(self.MIGRATION_FIELDS) - 2, "user_id")
53765426
self.assertEqual(self.MIGRATION_COLUMNS, columns)
53775427
self.assertEqual(tuple(self.data), tuple(data))
53785428
# Clean up global variables MIGRATION_COLUMNS
53795429
self.MIGRATION_COLUMNS.remove('Project')
5430+
self.MIGRATION_FIELDS.remove('project_id')
53805431
self.MIGRATION_COLUMNS.remove('User')
5432+
self.MIGRATION_FIELDS.remove('user_id')
53815433

53825434
def test_get_migrations_with_project_and_user_pre_v280(self):
53835435
self.app.client_manager.compute.api_version = api_versions.APIVersion(

0 commit comments

Comments
 (0)