Merge "Remount container volume on host reboot"
This commit is contained in:
commit
b77686412b
|
@ -86,6 +86,8 @@ class Manager(periodic_task.PeriodicTasks):
|
|||
for container in containers:
|
||||
current_status = uuid_to_status_map[container.uuid]
|
||||
self._init_container(context, container)
|
||||
if CONF.compute.remount_container_volume:
|
||||
self._remount_volume(context, container)
|
||||
if CONF.compute.resume_container_state:
|
||||
self.restore_running_container(context,
|
||||
container,
|
||||
|
@ -159,12 +161,30 @@ class Manager(periodic_task.PeriodicTasks):
|
|||
self.container_kill(context, container)
|
||||
return
|
||||
|
||||
def _remount_volume(self, context, container):
|
||||
driver = self._get_driver(container)
|
||||
volmaps = objects.VolumeMapping.list_by_container(context,
|
||||
container.uuid)
|
||||
for volmap in volmaps:
|
||||
LOG.info('Re-attaching volume %(volume_id)s to %(host)s',
|
||||
{'volume_id': volmap.cinder_volume_id,
|
||||
'host': CONF.host})
|
||||
try:
|
||||
driver.attach_volume(context, volmap)
|
||||
except Exception as e:
|
||||
LOG.exception("Failed to re-attach volume %(volume_id)s to "
|
||||
"container %(container_id)s: %(error)s",
|
||||
{'volume_id': volmap.cinder_volume_id,
|
||||
'container_id': volmap.container_uuid,
|
||||
'error': str(e)})
|
||||
msg = _("Internal error on recovering container volume")
|
||||
self._fail_container(context, container, msg, unset_host=False)
|
||||
|
||||
def _fail_container(self, context, container, error, unset_host=False):
|
||||
try:
|
||||
self._detach_volumes(context, container)
|
||||
except Exception as e:
|
||||
LOG.exception("Failed to detach volumes: %s",
|
||||
str(e))
|
||||
LOG.exception("Failed to detach volumes: %s", str(e))
|
||||
|
||||
container.status = consts.ERROR
|
||||
container.status_reason = error
|
||||
|
|
|
@ -21,6 +21,11 @@ compute_opts = [
|
|||
default=False,
|
||||
help='restart the containers which are running '
|
||||
'before the host reboots.'),
|
||||
cfg.BoolOpt(
|
||||
'remount_container_volume',
|
||||
default=True,
|
||||
help='remount the volumes of the containers when zun-compute '
|
||||
'restarts.'),
|
||||
cfg.FloatOpt(
|
||||
'reserve_disk_for_image',
|
||||
default=0.2,
|
||||
|
|
|
@ -56,6 +56,7 @@ class CinderVolumeDriverTestCase(base.TestCase):
|
|||
mock_get_mountpoint.return_value = self.fake_mountpoint
|
||||
|
||||
volume_driver = driver.Cinder()
|
||||
self.volmap.connection_info = None
|
||||
volume_driver.attach(self.context, self.volmap)
|
||||
|
||||
mock_cinder_workflow.attach_volume.assert_called_once_with(self.volmap)
|
||||
|
@ -90,6 +91,7 @@ class CinderVolumeDriverTestCase(base.TestCase):
|
|||
mock_get_mountpoint.return_value = self.fake_mountpoint
|
||||
|
||||
volume_driver = driver.Cinder()
|
||||
self.volmap.connection_info = None
|
||||
self.assertRaises(exception.ZunException,
|
||||
volume_driver.attach, self.context, self.volmap)
|
||||
|
||||
|
@ -112,6 +114,7 @@ class CinderVolumeDriverTestCase(base.TestCase):
|
|||
mock_do_mount.side_effect = exception.ZunException()
|
||||
|
||||
volume_driver = driver.Cinder()
|
||||
self.volmap.connection_info = None
|
||||
self.assertRaises(exception.ZunException,
|
||||
volume_driver.attach, self.context, self.volmap)
|
||||
|
||||
|
@ -144,6 +147,7 @@ class CinderVolumeDriverTestCase(base.TestCase):
|
|||
mock_cinder_workflow.detach_volume.side_effect = TestException2()
|
||||
|
||||
volume_driver = driver.Cinder()
|
||||
self.volmap.connection_info = None
|
||||
self.assertRaises(TestException1,
|
||||
volume_driver.attach, self.context, self.volmap)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import functools
|
|||
import shutil
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import fileutils
|
||||
from stevedore import driver as stevedore_driver
|
||||
|
@ -131,7 +132,21 @@ class Cinder(VolumeDriver):
|
|||
@validate_volume_provider(supported_providers)
|
||||
def attach(self, context, volmap):
|
||||
cinder = cinder_workflow.CinderWorkflow(context)
|
||||
devpath = cinder.attach_volume(volmap)
|
||||
if volmap.connection_info:
|
||||
# this is a re-attach of the volume
|
||||
connection_info = jsonutils.loads(volmap.connection_info)
|
||||
device_info = cinder._connect_volume(connection_info)
|
||||
connection_info['data']['device_path'] = device_info['path']
|
||||
try:
|
||||
volmap.connection_info = jsonutils.dumps(connection_info)
|
||||
except TypeError:
|
||||
pass
|
||||
volmap.save(context)
|
||||
devpath = connection_info['data']['device_path']
|
||||
else:
|
||||
# this is the first time to attach the volume
|
||||
devpath = cinder.attach_volume(volmap)
|
||||
|
||||
try:
|
||||
self._mount_device(volmap, devpath)
|
||||
except Exception:
|
||||
|
|
Loading…
Reference in New Issue