Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-ganeti
Commits
424908c1
Commit
424908c1
authored
Nov 12, 2007
by
Michael Hanselmann
Browse files
Rollback commit 356.
parent
2d6cfa31
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/utils.py
View file @
424908c1
...
...
@@ -815,47 +815,6 @@ def RemoveEtcHostsEntry(file_name, hostname):
raise
def
_SplitKnownHostsHosts
(
hosts
):
"""Parses the first field of a known_hosts file.
TODO: Support other formats.
"""
return
hosts
.
split
(
','
)
def
AddKnownHost
(
file_name
,
hostname
,
pubkey
):
"""Adds a new known host to a known_hosts file.
"""
f
=
open
(
file_name
,
'a+'
)
try
:
nl
=
True
for
line
in
f
:
fields
=
line
.
split
()
if
(
len
(
fields
)
<
3
or
fields
[
0
].
startswith
(
'#'
)
or
fields
[
1
]
!=
'ssh-rsa'
):
continue
hosts
=
_SplitKnownHostsHosts
(
fields
[
0
])
if
hostname
in
hosts
and
fields
[
2
]
==
pubkey
:
break
nl
=
line
.
endswith
(
'
\n
'
)
else
:
if
not
nl
:
f
.
write
(
"
\n
"
)
f
.
write
(
hostname
)
f
.
write
(
' ssh-rsa '
)
f
.
write
(
pubkey
)
f
.
write
(
"
\n
"
)
f
.
flush
()
finally
:
f
.
close
()
def
RemoveKnownHost
(
file_name
,
hostname
):
pass
def
CreateBackup
(
file_name
):
"""Creates a backup of a file.
...
...
test/ganeti.utils_unittest.py
View file @
424908c1
...
...
@@ -38,8 +38,7 @@ from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \
RemoveFile
,
CheckDict
,
MatchNameComponent
,
FormatUnit
,
\
ParseUnit
,
AddAuthorizedKey
,
RemoveAuthorizedKey
,
\
ShellQuote
,
ShellQuoteArgs
,
TcpPing
,
ListVisibleFiles
,
\
AddEtcHostsEntry
,
RemoveEtcHostsEntry
,
\
AddKnownHost
,
RemoveKnownHost
AddEtcHostsEntry
,
RemoveEtcHostsEntry
from
ganeti.errors
import
LockError
,
UnitParseError
...
...
@@ -519,51 +518,6 @@ class TestEtcHosts(unittest.TestCase):
os
.
unlink
(
tmpname
)
class
TestKnownHosts
(
unittest
.
TestCase
):
"""Test functions modifying known_hosts files"""
def
writeTestFile
(
self
):
(
fd
,
tmpname
)
=
tempfile
.
mkstemp
(
prefix
=
'ganeti-test'
)
f
=
os
.
fdopen
(
fd
,
'w'
)
try
:
f
.
write
(
'node1.tld,node1
\t
ssh-rsa AAAA1234567890=
\n
'
)
f
.
write
(
'node2,node2.tld ssh-rsa AAAA1234567890=
\n
'
)
finally
:
f
.
close
()
return
tmpname
def
testAddingNewHost
(
self
):
tmpname
=
self
.
writeTestFile
()
try
:
AddKnownHost
(
tmpname
,
'node3.tld'
,
'AAAA0987654321='
)
f
=
open
(
tmpname
,
'r'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'86cf3c7c7983a3bd5c475c4c1a3e5678'
)
finally
:
f
.
close
()
finally
:
os
.
unlink
(
tmpname
)
def
testAddingOldHost
(
self
):
tmpname
=
self
.
writeTestFile
()
try
:
AddKnownHost
(
tmpname
,
'node2.tld'
,
'AAAA0987654321='
)
f
=
open
(
tmpname
,
'r'
)
try
:
os
.
system
(
"vim %s"
%
tmpname
)
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'86cf3c7c7983a3bd5c475c4c1a3e5678'
)
finally
:
f
.
close
()
finally
:
os
.
unlink
(
tmpname
)
class
TestShellQuoting
(
unittest
.
TestCase
):
"""Test case for shell quoting functions"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment