Commit 0b609d5a authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Merge branch 'feature-server-resize' into develop

parents 6325d148 8a8faf8c
......@@ -35,4 +35,5 @@ Features:
- Expose more astakosclient methods in a 1to1 fashion [#4115]:
resources, feedback, endpoints,
commission_pending/info/action/accept/reject/resolve/issuejson/issue
- Implement resize_server and expose it as server resize [#4153]
......@@ -160,6 +160,7 @@ server (Compute/Cyclades)
shutdown: Shutdown a server
start : Start a server
stats : Get server statistics
resize : Set a different flavor for an existing server
wait : Wait for server to finish
Showcase: Create a server
......
......@@ -130,6 +130,7 @@ server commands
* shutdown Shutdown an active server (VM)
* start Start an existing server (VM)
* stats Get server (VM) statistics
* resize Set a different flavor for an existing server
* wait Wait for server to finish [BUILD, STOPPED, REBOOT, ACTIVE]
......
......@@ -183,6 +183,7 @@ and of a command in that group (list) are shown.
shutdown: Shutdown an active server (VM)
start : Start an existing server (VM)
stats : Get server (VM) statistics
resize : Set a different flavor for an existing server
wait : Wait for server to finish [BUILD, STOPPED, REBOOT, ACTIVE]
.. code-block:: console
......
......@@ -430,6 +430,26 @@ class server_console(_init_cyclades, _optional_json):
self._run(server_id=server_id)
@command(server_cmds)
class server_resize(_init_cyclades, _optional_output_cmd):
"""Set a different flavor for an existing server
To get server ids and flavor ids:
/server list
/flavor list
"""
@errors.generic.all
@errors.cyclades.connection
@errors.cyclades.server_id
@errors.cyclades.flavor_id
def _run(self, server_id, flavor_id):
self._optional_output(self.client.resize_server(server_id, flavor_id))
def main(self, server_id, flavor_id):
super(self.__class__, self)._run()
self._run(server_id=server_id, flavor_id=flavor_id)
@command(server_cmds)
class server_firewall(_init_cyclades):
"""Manage server (VM) firewall profiles for public networks"""
......
......@@ -143,6 +143,18 @@ class ComputeClient(ComputeRestClient):
r = self.servers_post(server_id, 'action', json_data=req)
return r.headers
def resize_server(self, server_id, flavor_id):
"""
:param server_id: (str)
:param flavor_id: (int)
:returns: (dict) request headers
"""
req = {'resize': {'flavorRef': flavor_id}}
r = self.servers_post(server_id, 'action', json_data=req)
return r.headers
def get_server_metadata(self, server_id, key=''):
"""
:param server_id: integer (str or int)
......
......@@ -375,6 +375,13 @@ class ComputeClient(TestCase):
vm_id, 'action',
json_data=dict(reboot=dict(type='HARD' if hard else 'SOFT'))))
@patch('%s.servers_post' % compute_pkg, return_value=FR())
def test_resize_server(self, SP):
vm_id, flavor = vm_recv['server']['id'], flavor_list['flavors'][1]
self.client.resize_server(vm_id, flavor['id'])
exp = dict(resize=dict(flavorRef=flavor['id']))
SP.assert_called_once_with(vm_id, 'action', json_data=exp)
@patch('%s.servers_put' % compute_pkg, return_value=FR())
def test_create_server_metadata(self, SP):
vm_id = vm_recv['server']['id']
......
......@@ -77,13 +77,9 @@ class Cyclades(livetest.Generic):
def test_000(self):
"Prepare a full Cyclades test scenario"
self.server1 = self._create_server(
self.servname1,
self.flavorid,
self.img)
self.servname1, self.flavorid, self.img)
self.server2 = self._create_server(
self.servname2,
self.flavorid,
self.img)
self.servname2, self.flavorid, self.img)
super(self.__class__, self).test_000()
def _create_server(self, servername, flavorid, imageid, personality=None):
......@@ -340,6 +336,20 @@ class Cyclades(livetest.Generic):
self.client.reboot_server(self.server2['id'], hard=True)
self.assertTrue(self._has_status(self.server2['id'], 'REBOOT'))
def test_resize_server(self):
"""Modify the flavor of a server"""
self.server1 = self._create_server(
self.servname1, self.flavorid, self.img)
self._test_0065_resize_server()
self.delete_server(self.server1['id'])
self.server1 = self._create_server(
self.servname1, self.flavorid, self.img)
def test_0065_resize_server(self):
self.client.resize_server(self.servname1, self.flavorid + 1, self.img)
srv = self.client.get_flavor_details(self.server1['id'])
self.assertEqual(srv['flavor']['id'], self.flavorid + 1)
def _test_0070_wait_test_servers_to_reboot(self):
"""Pseudo-test to wait for VMs to load"""
print('')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment