Skip to content

Commit

Permalink
Added system_uuid and localhost fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien committed Oct 23, 2011
1 parent 40f1fc8 commit f4dc4ba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
21 changes: 19 additions & 2 deletions src/cuisine.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import fabric, fabric.api, fabric.context_managers


VERSION = "0.0.9"
VERSION = "0.1.0"
# FIXME: MODE should be in the fabric env, as this is definitely not thread-safe
MODE = "user"
RE_SPACES = re.compile("[\s\t]+")
Expand Down Expand Up @@ -445,7 +445,7 @@ def ssh_authorize( user, key ):
else:
return True
else:
file_write(keyf, key)
file_write(keyf, key, owner=user, group=user)
return False

def upstart_ensure( name ):
Expand All @@ -455,4 +455,21 @@ def upstart_ensure( name ):
else:
sudo("start " + name)

def system_uuid_alias_add():
"""Adds system UUID alias to /etc/hosts.
Some tools/processes rely/want the hostname as an alias in
/etc/hosts e.g. 127.0.0.1 localhost <hostname>.
"""
with mode_sudo(), cd('/etc'):
old = "127.0.0.1 localhost"
new = old + " " + system_uuid()
file_update('hosts', lambda x: text_replace_line(x, old, new)[0])

def system_uuid():
"""Gets a machines UUID (Universally Unique Identifier)."""
return sudo('dmidecode -s system-uuid | tr "[A-Z]" "[a-z]"')


# EOF - vim: ts=4 sw=4 noet
22 changes: 19 additions & 3 deletions tests/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,35 @@ def custom_run( cmd ):
def custom_sudo( cmd ):
return os.popen("sudo " + cmd).read()[:-1]

class Text(unittest.TestCase):

def testEnsureLine( self ):
some_text = "foo"
some_text = cuisine.text_ensure_line(some_text, "bar")
assert some_text == 'foo\nbar'
some_text = cuisine.text_ensure_line(some_text, "bar")
assert some_text == 'foo\nbar'

class Users(unittest.TestCase):

def testUserCheck( self ):
user_data = cuisine.user_check(USER)
print "USER_DATA", user_data

class Files(unittest.TestCase):

def testB( self ):
print cuisine.file_read("/etc/passwd")
cuisine.file_read("/etc/passwd")

def testC( self ):
pass

class Packages(unittest.TestCase):

def testInstall( self ):
with cuisine.mode_sudo():
cuisine.package_ensure("tmux")
pass
#with cuisine.mode_sudo():
# cuisine.package_ensure("tmux")

class SSHKeys(unittest.TestCase):

Expand Down

0 comments on commit f4dc4ba

Please sign in to comment.