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

Additional function to fs module #39

Merged
merged 13 commits into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from 9 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
45 changes: 45 additions & 0 deletions rrmngmnt/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,48 @@ def create_script(self, content, path):
raise errors.CommandExecutionFailure(
executor, cmd, rc, err,
)

def mkdir(self, path):
"""
Create directory on host

:param path: directory path
:type path: str
:return: True, if action succeed, otherwise False
:rtype: bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would raise exception, with all relevant info

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see ':rtype: bool' but it doesn't return bool.

"""
return self.host.run_command(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that host.run_command will be removed, read #24 .

['mkdir', path]
)[0] == 0

def chown(self, path, username, groupname):
"""
Change owner of file or directory

:param path: file or directory path
:type path: str
:param username: change user owner to username
:type username: str
:param groupname: change group owner to groupname
:type groupname: str
:return: True, if action succeed, otherwise False
:rtype: bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

"""
return self.host.run_command(
['chown', '%s:%s' % (username, groupname), path]
)[0] == 0

def chmod(self, path, mode):
"""
Change permission of directory or file

:param path: file or directory path
:type path: str
:param mode: permission mode(600 for example or u+x)
:type mode: str
:return: True, if action succeed, otherwise False
:rtype: bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks that you raise exception instead of bools. please update doc as well.
and please add one negative test, and verify that exception contains expected message.

"""
return self.host.run_command(
['chmod', mode, path]
)[0] == 0
12 changes: 12 additions & 0 deletions tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class TestFilesystem(object):
'rm -rf /dir/to/remove': (0, '', ''),
'cat %s' % "/tmp/file": (0, 'data', ''),
'chmod +x /tmp/hello.sh': (0, '', ''),
'mkdir /dir/to/remove': (0, '', ''),
'chown root:root /dir/to/remove': (0, '', ''),
'chmod 600 /dir/to/remove': (0, '', '')
}
files = {}

Expand Down Expand Up @@ -84,3 +87,12 @@ def test_create_sctript(self):
path = '/tmp/hello.sh'
self.get_host().fs.create_script(data, path)
assert self.files[path].data == data

def test_mkdir_positive(self):
assert self.get_host().fs.mkdir('/dir/to/remove')

def test_chown_positive(self):
assert self.get_host().fs.chown('/dir/to/remove', 'root', 'root')

def test_chmod_positive(self):
assert self.get_host().fs.chmod('/dir/to/remove', '600')