Take admin password for server rebuild

Take admin password when rebuild a server.

Change-Id: Ia035083519dad2faa0f3ff6647553508f70a2608
Closes-Bug: #1397220
This commit is contained in:
huangtianhua 2014-11-28 16:38:55 +08:00
parent 7479227391
commit 80f5193750
3 changed files with 25 additions and 11 deletions

View File

@ -354,9 +354,11 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
dict(flavor=flavor, status=server.status))
@scheduler.wrappertask
def rebuild(self, server, image_id, preserve_ephemeral=False):
def rebuild(self, server, image_id, password=None,
preserve_ephemeral=False):
"""Rebuild the server and call check_rebuild to verify."""
server.rebuild(image_id, preserve_ephemeral=preserve_ephemeral)
server.rebuild(image_id, password=password,
preserve_ephemeral=preserve_ephemeral)
yield self.check_rebuild(server, image_id)
def check_rebuild(self, server, image_id):

View File

@ -803,9 +803,11 @@ class Server(stack_user.StackUser):
server = self.nova().servers.get(self.resource_id)
preserve_ephemeral = (
image_update_policy == 'REBUILD_PRESERVE_EPHEMERAL')
password = (prop_diff.get(self.ADMIN_PASS) or
self.properties.get(self.ADMIN_PASS))
return scheduler.TaskRunner(
self.client_plugin().rebuild, server, image_id,
password=password,
preserve_ephemeral=preserve_ephemeral)
def _update_networks(self, server, prop_diff):
@ -891,17 +893,16 @@ class Server(stack_user.StackUser):
if self.IMAGE in prop_diff:
checkers.append(self._update_image(server, prop_diff))
elif self.ADMIN_PASS in prop_diff:
if not server:
server = self.nova().servers.get(self.resource_id)
server.change_password(prop_diff[self.ADMIN_PASS])
if self.NAME in prop_diff:
if not server:
server = self.nova().servers.get(self.resource_id)
self.client_plugin().rename(server, prop_diff[self.NAME])
if self.ADMIN_PASS in prop_diff:
if not server:
server = self.nova().servers.get(self.resource_id)
server.change_password(prop_diff[self.ADMIN_PASS])
if self.NETWORKS in prop_diff:
checkers.extend(self._update_networks(server, prop_diff))

View File

@ -1432,7 +1432,8 @@ class ServersTest(common.HeatTestCase):
updater = scheduler.TaskRunner(server.update, update_template)
self.assertRaises(resource.UpdateReplace, updater)
def _test_server_update_image_rebuild(self, status, policy='REBUILD'):
def _test_server_update_image_rebuild(self, status, policy='REBUILD',
password=None):
# Server.handle_update supports changing the image, and makes
# the change making a rebuild API call against Nova.
return_server = self.fc.servers.list()[1]
@ -1445,8 +1446,11 @@ class ServersTest(common.HeatTestCase):
# current test demonstrate updating when image_update_policy was not
# changed, so image_update_policy will be used from self.properties
server.t['Properties']['image_update_policy'] = policy
update_template = copy.deepcopy(server.t)
update_template['Properties']['image'] = new_image
if password:
update_template['Properties']['admin_pass'] = password
self.m.StubOutWithMock(self.fc.servers, 'get')
self.fc.servers.get('1234').MultipleTimes().AndReturn(return_server)
@ -1454,10 +1458,12 @@ class ServersTest(common.HeatTestCase):
# 744 is a static lookup from the fake images list
if 'REBUILD' == policy:
self.fc.servers.rebuild(
return_server, 744, password=None, preserve_ephemeral=False)
return_server, 744, password=password,
preserve_ephemeral=False)
else:
self.fc.servers.rebuild(
return_server, 744, password=None, preserve_ephemeral=True)
return_server, 744, password=password,
preserve_ephemeral=True)
self.m.StubOutWithMock(self.fc.client, 'post_servers_1234_action')
for stat in status:
def activate_status(serv):
@ -1487,6 +1493,11 @@ class ServersTest(common.HeatTestCase):
self._test_server_update_image_rebuild(
policy='REBUILD_PRESERVE_EPHEMERAL', status=('ACTIVE'))
def test_server_update_image_rebuild_with_new_password(self):
# Normally we will see 'REBUILD' first and then 'ACTIVE".
self._test_server_update_image_rebuild(password='new_admin_password',
status=('REBUILD', 'ACTIVE'))
def test_server_update_image_rebuild_failed(self):
# If the status after a rebuild is not REBUILD or ACTIVE, it means the
# rebuild call failed, so we raise an explicit error.