Browse Source

Fix displaying of an unavailable flavor of a showing instance

Since then an instance was booted with a flavor, the flavor could be
deleted or become unavailable (private flavors). As a result novaclient
fails to show the instance with member role user.

This patch set adds handling of unavailable flavors to showing of
instances as it is done for unavailable images.

Closes-Bug: #1366168

Change-Id: I810dcac814b7523313112bb9151754659b85df51
tags/2.25.0
Feodor Tersin 4 years ago
parent
commit
a63aa515f5
3 changed files with 40 additions and 3 deletions
  1. +23
    -1
      novaclient/tests/unit/v2/fakes.py
  2. +12
    -0
      novaclient/tests/unit/v2/test_shell.py
  3. +5
    -2
      novaclient/v2/shell.py

+ 23
- 1
novaclient/tests/unit/v2/fakes.py View File

@@ -362,7 +362,19 @@ class FakeHTTPClient(base_client.HTTPClient):
"metadata": {
"Server Label": "DB 1"
}
}
},
{
"id": 9013,
"name": "sample-server4",
"flavor": {
"id": '80645cf4-6ad3-410a-bbc8-6f3e1e291f51',
},
"image": {
"id": '3e861307-73a6-4d1f-8d68-f68b03223032',
},
"hostId": "9e107d9d372bb6826bd81d3542a419d6",
"status": "ACTIVE",
},
]})

def post_servers(self, body, **kw):
@@ -416,6 +428,10 @@ class FakeHTTPClient(base_client.HTTPClient):
r = {'server': self.get_servers_detail()[2]['servers'][2]}
return (200, {}, r)

def get_servers_9013(self, **kw):
r = {'server': self.get_servers_detail()[2]['servers'][3]}
return (200, {}, r)

def put_servers_1234(self, body, **kw):
assert list(body) == ['server']
fakes.assert_has_keys(body['server'], optional=['name', 'adminPass'])
@@ -748,6 +764,9 @@ class FakeHTTPClient(base_client.HTTPClient):
def get_flavors_128_mb_server(self, **kw):
raise exceptions.NotFound('404')

def get_flavors_80645cf4_6ad3_410a_bbc8_6f3e1e291f51(self, **kw):
raise exceptions.NotFound('404')

def get_flavors_aa1(self, **kw):
# Alphanumeric flavor id are allowed.
return (
@@ -998,6 +1017,9 @@ class FakeHTTPClient(base_client.HTTPClient):
def get_images_456(self, **kw):
return (200, {}, {'image': self.get_images_detail()[2]['images'][1]})

def get_images_3e861307_73a6_4d1f_8d68_f68b03223032(self):
raise exceptions.NotFound('404')

def post_images(self, body, **kw):
assert list(body) == ['image']
fakes.assert_has_keys(body['image'], required=['serverId', 'name'])

+ 12
- 0
novaclient/tests/unit/v2/test_shell.py View File

@@ -1085,6 +1085,18 @@ class ShellTest(utils.TestCase):
self.assertRaises(exceptions.CommandError,
self.run_command, 'show xxx')

def test_show_unavailable_image_and_flavor(self):
output = self.run_command('show 9013')
self.assert_called('GET', '/servers/9013', pos=-8)
self.assert_called('GET',
'/flavors/80645cf4-6ad3-410a-bbc8-6f3e1e291f51',
pos=-7)
self.assert_called('GET',
'/images/3e861307-73a6-4d1f-8d68-f68b03223032',
pos=-3)
self.assertIn('Image not found', output)
self.assertIn('Flavor not found', output)

@mock.patch('novaclient.v2.shell.utils.print_dict')
def test_print_server(self, mock_print_dict):
self.run_command('show 5678')

+ 5
- 2
novaclient/v2/shell.py View File

@@ -1830,8 +1830,11 @@ def _print_server(cs, args, server=None):
if minimal:
info['flavor'] = flavor_id
else:
info['flavor'] = '%s (%s)' % (_find_flavor(cs, flavor_id).name,
flavor_id)
try:
info['flavor'] = '%s (%s)' % (_find_flavor(cs, flavor_id).name,
flavor_id)
except Exception:
info['flavor'] = '%s (%s)' % (_("Flavor not found"), flavor_id)

if 'security_groups' in info:
# when we have multiple nics the info will include the

Loading…
Cancel
Save