Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLOC-3847] Prototype a dataset agent for remote filesystems like NFS #2461

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions flocker/node/agents/blockdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,7 @@ class BlockDeviceCalculator(PClass):
transitions = field(TransitionTable, mandatory=True,
factory=TransitionTable.create,
initial=DATASET_TRANSITIONS)
dataset_states = field(initial=DatasetStates)

def _calculate_dataset_change(self, discovered_dataset, desired_dataset):
"""
Expand All @@ -1460,12 +1461,12 @@ def _calculate_dataset_change(self, discovered_dataset, desired_dataset):
# we detach it.
desired_state = (desired_dataset.state
if desired_dataset is not None
else DatasetStates.NON_MANIFEST)
else self.dataset_states.NON_MANIFEST)
# If we haven't discovered a dataset, then it is doesn't
# exist.
discovered_state = (discovered_dataset.state
if discovered_dataset is not None
else DatasetStates.NON_EXISTENT)
else self.dataset_states.NON_EXISTENT)
if desired_state != discovered_state:
transition = self.transitions[desired_state][discovered_state]
return transition.from_state_and_config(
Expand Down
61 changes: 61 additions & 0 deletions flocker/node/agents/localfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
Localhost implementation of ``IRemoteFilesystemAPI``, for testing.
"""

from uuid import UUID
from subprocess import check_call

from zope.interface import implementer

from twisted.python.filepath import FilePath

from .remotefs import IRemoteFilesystemAPI, RemoteFilesystem


@implementer(IRemoteFilesystemAPI)
class LocalFilesystem(object):
"""
Local filesystem pretending to be remote filesystem.

Can't be used for movement across nodes, but otherwise useful for testing.
"""
def __init__(self, root):
if not root.exists():
root.makedirs()
self.root = root()

def list(self):
return [self._to_fs(UUID(child))
for child in self.root.listdir()]

def _child(self, dataset_id):
return self.root.child(unicode(dataset_id))

def _to_fs(self, dataset_id):
storage_path = self._child(dataset_id)
local_mount_point = None
for line in FilePath(
b"/proc/self/mountinfo").getContent().splitlines():
# let's pretend there's no spaces in paths...
parts = line.split()
origin = parts[3]
destination = parts[4]
if origin == storage_path.path:
local_mount_point = FilePath(destination)
break
return RemoteFilesystem(dataset_id=dataset_id,
local_mount_point=local_mount_point)

def create(self, dataset_id, metadata):
self._child(dataset_id).mkdir()
return self._to_fs(dataset_id)

def destroy(self, dataset_id):
self._child(dataset_id).remove()

def mount(self, dataset_id, path):
check_call([b"mount", b"--bind", self._child(dataset_id).path,
path.path])

def umount(self, dataset_id, path):
check_call([b"umount", path.path])
Loading