Make volume mount path configurable for ContainerShareDriver

Mount volumes to /tmp/ on host is not suitable for some environments
 wheen operatpr wants for specify such path for any reason.

Change-Id: Ibbdd755721de3727bf779852be039ea5639310bc
This commit is contained in:
Ivan Kolodyazhny 2020-05-29 16:10:38 +03:00
parent d9c87098a5
commit 32f1c41042
6 changed files with 18 additions and 4 deletions

View File

@ -61,9 +61,11 @@ class DockerExecHelper(driver.ExecuteMixin):
# provide any more possibilities for an exploitation than other
# first-party drivers.
path = "{0}:/shares".format(
self.configuration.container_volume_mount_path)
cmd = ["docker", "run", "-d", "-i", "-t", "--privileged",
"-v", "/dev:/dev", "--name=%s" % name,
"-v", "/tmp/shares:/shares", image_name]
"-v", path, image_name]
try:
result = self._inner_execute(cmd)
except (exception.ProcessExecutionError, OSError):

View File

@ -70,6 +70,11 @@ container_opts = [
help="Helper which facilitates interaction with storage "
"solution used to actually store data. By default LVM "
"is used to provide storage for a share."),
cfg.StrOpt("container_volume_mount_path",
default="/tmp/shares",
help="Folder name in host to which logical volume will be "
"mounted prior to providing access to it from a "
"container."),
]

View File

@ -77,9 +77,8 @@ class LVMHelper(driver.ExecuteMixin):
share_name)
def _get_lv_folder(self, share_name):
# Provides folder name in hosts /tmp to which logical volume is
# mounted prior to providing access to it from a container.
return os.path.join("/tmp/shares", share_name)
return os.path.join(self.configuration.container_volume_mount_path,
share_name)
def provide_storage(self, share_name, size):
self._execute("lvcreate", "-p", "rw", "-L",

View File

@ -34,6 +34,7 @@ class DockerExecHelperTestCase(test.TestCase):
super(DockerExecHelperTestCase, self).setUp()
self.fake_conf = configuration.Configuration(None)
self.fake_conf.container_image_name = "fake_image"
self.fake_conf.container_volume_mount_path = "/tmp/shares"
self.DockerExecHelper = container_helper.DockerExecHelper(
configuration=self.fake_conf)

View File

@ -34,6 +34,7 @@ class LVMHelperTestCase(test.TestCase):
super(LVMHelperTestCase, self).setUp()
self.share = fake_share()
self.fake_conf = configuration.Configuration(None)
self.fake_conf.container_volume_mount_path = "/tmp/shares"
self.LVMHelper = storage_helper.LVMHelper(configuration=self.fake_conf)
def fake_exec_sync(self, *args, **kwargs):

View File

@ -0,0 +1,6 @@
---
upgrade:
- Added a new config option ``container_volume_mount_path``.
This option defines the path where ContainerShareDriver driver should
mount a logical volume on the host prior to providing access to it from
a container.