Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-ganeti
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
snf-ganeti
Commits
424908c1
Commit
424908c1
authored
17 years ago
by
Michael Hanselmann
Browse files
Options
Downloads
Patches
Plain Diff
Rollback commit 356.
parent
2d6cfa31
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/utils.py
+0
-41
0 additions, 41 deletions
lib/utils.py
test/ganeti.utils_unittest.py
+1
-47
1 addition, 47 deletions
test/ganeti.utils_unittest.py
with
1 addition
and
88 deletions
lib/utils.py
+
0
−
41
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.
...
...
This diff is collapsed.
Click to expand it.
test/ganeti.utils_unittest.py
+
1
−
47
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
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment