Fix server resize
So apparently we've never resized a server??? Fixed command args and add some tests. Change-Id: I6c3f6fec22390e9d269b7117a42a190d2b4b80ba
This commit is contained in:
parent
b3736fd9df
commit
ea2ac77a46
@ -938,27 +938,32 @@ class RescueServer(show.ShowOne):
|
||||
|
||||
|
||||
class ResizeServer(command.Command):
|
||||
"""Convert server to a new flavor"""
|
||||
"""Scale server to a new flavor"""
|
||||
|
||||
log = logging.getLogger(__name__ + '.ResizeServer')
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ResizeServer, self).get_parser(prog_name)
|
||||
phase_group = parser.add_mutually_exclusive_group()
|
||||
parser.add_argument(
|
||||
'server',
|
||||
metavar='<server>',
|
||||
help='Server (name or ID)',
|
||||
)
|
||||
phase_group.add_argument(
|
||||
'--flavor',
|
||||
metavar='<flavor>',
|
||||
help='Resize server to this flavor',
|
||||
help='Resize server to specified flavor',
|
||||
)
|
||||
phase_group.add_argument(
|
||||
'--verify',
|
||||
action="store_true",
|
||||
help='Verify previous server resize',
|
||||
help='Verify server resize is complete',
|
||||
)
|
||||
phase_group.add_argument(
|
||||
'--revert',
|
||||
action="store_true",
|
||||
help='Restore server before resize',
|
||||
help='Restore server state before resize',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--wait',
|
||||
@ -980,7 +985,7 @@ class ResizeServer(command.Command):
|
||||
compute_client.flavors,
|
||||
parsed_args.flavor,
|
||||
)
|
||||
server.resize(flavor)
|
||||
compute_client.servers.resize(server, flavor)
|
||||
if parsed_args.wait:
|
||||
if utils.wait_for_status(
|
||||
compute_client.servers.get,
|
||||
@ -993,9 +998,9 @@ class ResizeServer(command.Command):
|
||||
sys.stdout.write('\nError resizing server')
|
||||
raise SystemExit
|
||||
elif parsed_args.verify:
|
||||
server.confirm_resize()
|
||||
compute_client.servers.confirm_resize(server)
|
||||
elif parsed_args.revert:
|
||||
server.revert_resize()
|
||||
compute_client.servers.revert_resize(server)
|
||||
|
||||
|
||||
class ResumeServer(command.Command):
|
||||
|
@ -47,6 +47,18 @@ EXTENSION = {
|
||||
'links': extension_links,
|
||||
}
|
||||
|
||||
flavor_id = 'm1.large'
|
||||
flavor_name = 'Large'
|
||||
flavor_ram = 8192
|
||||
flavor_vcpus = 4
|
||||
|
||||
FLAVOR = {
|
||||
'id': flavor_id,
|
||||
'name': flavor_name,
|
||||
'ram': flavor_ram,
|
||||
'vcpus': flavor_vcpus,
|
||||
}
|
||||
|
||||
|
||||
class FakeComputev2Client(object):
|
||||
def __init__(self, **kwargs):
|
||||
@ -56,6 +68,8 @@ class FakeComputev2Client(object):
|
||||
self.servers.resource_class = fakes.FakeResource(None, {})
|
||||
self.extensions = mock.Mock()
|
||||
self.extensions.resource_class = fakes.FakeResource(None, {})
|
||||
self.flavors = mock.Mock()
|
||||
self.flavors.resource_class = fakes.FakeResource(None, {})
|
||||
self.auth_token = kwargs['token']
|
||||
self.management_url = kwargs['endpoint']
|
||||
|
||||
|
@ -30,6 +30,10 @@ class TestServer(compute_fakes.TestComputev2):
|
||||
self.servers_mock = self.app.client_manager.compute.servers
|
||||
self.servers_mock.reset_mock()
|
||||
|
||||
# Get a shortcut to the FlavorManager Mock
|
||||
self.flavors_mock = self.app.client_manager.compute.flavors
|
||||
self.flavors_mock.reset_mock()
|
||||
|
||||
# Get a shortcut to the ImageManager Mock
|
||||
self.images_mock = self.app.client_manager.image.images
|
||||
self.images_mock.reset_mock()
|
||||
@ -148,3 +152,134 @@ class TestServerImageCreate(TestServer):
|
||||
image_fakes.image_owner,
|
||||
)
|
||||
self.assertEqual(data, datalist)
|
||||
|
||||
|
||||
class TestServerResize(TestServer):
|
||||
|
||||
def setUp(self):
|
||||
super(TestServerResize, self).setUp()
|
||||
|
||||
# This is the return value for utils.find_resource()
|
||||
self.servers_get_return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(compute_fakes.SERVER),
|
||||
loaded=True,
|
||||
)
|
||||
self.servers_mock.get.return_value = self.servers_get_return_value
|
||||
|
||||
self.servers_mock.resize.return_value = None
|
||||
self.servers_mock.confirm_resize.return_value = None
|
||||
self.servers_mock.revert_resize.return_value = None
|
||||
|
||||
# This is the return value for utils.find_resource()
|
||||
self.flavors_get_return_value = fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(compute_fakes.FLAVOR),
|
||||
loaded=True,
|
||||
)
|
||||
self.flavors_mock.get.return_value = self.flavors_get_return_value
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = server.ResizeServer(self.app, None)
|
||||
|
||||
def test_server_resize_no_options(self):
|
||||
arglist = [
|
||||
compute_fakes.server_id,
|
||||
]
|
||||
verifylist = [
|
||||
('verify', False),
|
||||
('revert', False),
|
||||
('server', compute_fakes.server_id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.servers_mock.get.assert_called_with(
|
||||
compute_fakes.server_id,
|
||||
)
|
||||
|
||||
self.assertNotCalled(self.servers_mock.resize)
|
||||
self.assertNotCalled(self.servers_mock.confirm_resize)
|
||||
self.assertNotCalled(self.servers_mock.revert_resize)
|
||||
|
||||
def test_server_resize(self):
|
||||
arglist = [
|
||||
'--flavor', compute_fakes.flavor_id,
|
||||
compute_fakes.server_id,
|
||||
]
|
||||
verifylist = [
|
||||
('flavor', compute_fakes.flavor_id),
|
||||
('verify', False),
|
||||
('revert', False),
|
||||
('server', compute_fakes.server_id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.servers_mock.get.assert_called_with(
|
||||
compute_fakes.server_id,
|
||||
)
|
||||
self.flavors_mock.get.assert_called_with(
|
||||
compute_fakes.flavor_id,
|
||||
)
|
||||
|
||||
self.servers_mock.resize.assert_called_with(
|
||||
self.servers_get_return_value,
|
||||
self.flavors_get_return_value,
|
||||
)
|
||||
self.assertNotCalled(self.servers_mock.confirm_resize)
|
||||
self.assertNotCalled(self.servers_mock.revert_resize)
|
||||
|
||||
def test_server_resize_confirm(self):
|
||||
arglist = [
|
||||
'--verify',
|
||||
compute_fakes.server_id,
|
||||
]
|
||||
verifylist = [
|
||||
('verify', True),
|
||||
('revert', False),
|
||||
('server', compute_fakes.server_id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.servers_mock.get.assert_called_with(
|
||||
compute_fakes.server_id,
|
||||
)
|
||||
|
||||
self.assertNotCalled(self.servers_mock.resize)
|
||||
self.servers_mock.confirm_resize.assert_called_with(
|
||||
self.servers_get_return_value,
|
||||
)
|
||||
self.assertNotCalled(self.servers_mock.revert_resize)
|
||||
|
||||
def test_server_resize_revert(self):
|
||||
arglist = [
|
||||
'--revert',
|
||||
compute_fakes.server_id,
|
||||
]
|
||||
verifylist = [
|
||||
('verify', False),
|
||||
('revert', True),
|
||||
('server', compute_fakes.server_id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.servers_mock.get.assert_called_with(
|
||||
compute_fakes.server_id,
|
||||
)
|
||||
|
||||
self.assertNotCalled(self.servers_mock.resize)
|
||||
self.assertNotCalled(self.servers_mock.confirm_resize)
|
||||
self.servers_mock.revert_resize.assert_called_with(
|
||||
self.servers_get_return_value,
|
||||
)
|
||||
|
@ -37,6 +37,14 @@ class TestCase(testtools.TestCase):
|
||||
stderr = self.useFixture(fixtures.StringStream("stderr")).stream
|
||||
self.useFixture(fixtures.MonkeyPatch("sys.stderr", stderr))
|
||||
|
||||
def assertNotCalled(self, m, msg=None):
|
||||
"""Assert a function was not called"""
|
||||
|
||||
if m.called:
|
||||
if not msg:
|
||||
msg = 'method %s should not have been called' % m
|
||||
self.fail(msg)
|
||||
|
||||
# 2.6 doesn't have the assert dict equals so make sure that it exists
|
||||
if tuple(sys.version_info)[0:2] < (2, 7):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user