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
f0990e0c
Commit
f0990e0c
authored
17 years ago
by
Michael Hanselmann
Browse files
Options
Downloads
Patches
Plain Diff
Compare file contents directly in unittests.
Reviewed-by: schreiberal, ultrotter
parent
fcb1f331
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/ganeti.utils_unittest.py
+59
-71
59 additions, 71 deletions
test/ganeti.utils_unittest.py
with
59 additions
and
71 deletions
test/ganeti.utils_unittest.py
+
59
−
71
View file @
f0990e0c
...
...
@@ -42,6 +42,18 @@ from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \
from
ganeti.errors
import
LockError
,
UnitParseError
class
GanetiTestCase
(
unittest
.
TestCase
):
def
assertFileContent
(
self
,
file_name
,
content
):
"""
Checks the content of a file.
"""
handle
=
open
(
file_name
,
'
r
'
)
try
:
self
.
assertEqual
(
handle
.
read
(),
content
)
finally
:
handle
.
close
()
class
TestIsProcessAlive
(
unittest
.
TestCase
):
"""
Testing case for IsProcessAlive
"""
def
setUp
(
self
):
...
...
@@ -334,16 +346,13 @@ class TestParseUnit(unittest.TestCase):
self
.
assertRaises
(
UnitParseError
,
ParseUnit
,
'
1,3
'
+
suffix
)
class
TestSshKeys
(
unittest
.
TestCase
):
class
TestSshKeys
(
Ganeti
TestCase
):
"""
Test case for the AddAuthorizedKey function
"""
KEY_A
=
'
ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a
'
KEY_B
=
(
'
command=
"
/usr/bin/fooserver -t --verbose
"
,from=
"
1.2.3.4
"
'
'
ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b
'
)
# NOTE: The MD5 sums below were calculated after manually
# checking the output files.
def
writeTestFile
(
self
):
(
fd
,
tmpname
)
=
tempfile
.
mkstemp
(
prefix
=
'
ganeti-test
'
)
f
=
os
.
fdopen
(
fd
,
'
w
'
)
...
...
@@ -362,12 +371,11 @@ class TestSshKeys(unittest.TestCase):
try
:
AddAuthorizedKey
(
tmpname
,
'
ssh-dss AAAAB3NzaC1kc3MAAACB root@test
'
)
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
ccc71523108ca6e9d0343797dc3e9f16
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a
\n
"
'
command=
"
/usr/bin/fooserver -t --verbose
"
,from=
"
1.2.3.4
"'
"
ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b
\n
"
"
ssh-dss AAAAB3NzaC1kc3MAAACB root@test
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
@@ -377,12 +385,11 @@ class TestSshKeys(unittest.TestCase):
AddAuthorizedKey
(
tmpname
,
'
ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@test
'
)
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
f2c939d57addb5b3a6846884be896b46
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a
\n
"
'
command=
"
/usr/bin/fooserver -t --verbose
"
,from=
"
1.2.3.4
"'
"
ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b
\n
"
"
ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@test
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
@@ -392,12 +399,10 @@ class TestSshKeys(unittest.TestCase):
AddAuthorizedKey
(
tmpname
,
'
ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a
'
)
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
4e612764808bd46337eb0f575415fc30
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a
\n
"
'
command=
"
/usr/bin/fooserver -t --verbose
"
,from=
"
1.2.3.4
"'
"
ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
@@ -407,12 +412,9 @@ class TestSshKeys(unittest.TestCase):
RemoveAuthorizedKey
(
tmpname
,
'
ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a
'
)
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
77516d987fca07f70e30b830b3e4f2ed
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
'
command=
"
/usr/bin/fooserver -t --verbose
"
,from=
"
1.2.3.4
"'
"
ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
@@ -422,17 +424,15 @@ class TestSshKeys(unittest.TestCase):
RemoveAuthorizedKey
(
tmpname
,
'
ssh-dss AAAAB3Nsdfj230xxjxJjsjwjsjdjU root@test
'
)
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
4e612764808bd46337eb0f575415fc30
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a
\n
"
'
command=
"
/usr/bin/fooserver -t --verbose
"
,from=
"
1.2.3.4
"'
"
ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
class
TestEtcHosts
(
unittest
.
TestCase
):
class
TestEtcHosts
(
Ganeti
TestCase
):
"""
Test functions modifying /etc/hosts
"""
def
writeTestFile
(
self
):
...
...
@@ -452,12 +452,11 @@ class TestEtcHosts(unittest.TestCase):
try
:
SetEtcHostsEntry
(
tmpname
,
'
1.2.3.4
'
,
'
myhost.domain.tld
'
,
[
'
myhost
'
])
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
284c3454c158d4c4284eeb59910ab00b
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
# This is a test file for /etc/hosts
\n
"
"
127.0.0.1
\t
localhost
\n
"
"
192.168.1.1 router gw
\n
"
"
1.2.3.4
\t
myhost.domain.tld myhost
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
@@ -466,12 +465,10 @@ class TestEtcHosts(unittest.TestCase):
try
:
SetEtcHostsEntry
(
tmpname
,
'
192.168.1.1
'
,
'
myhost.domain.tld
'
,
[
'
myhost
'
])
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
1486c19f1fcb626f893c243e3ce38c8d
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
# This is a test file for /etc/hosts
\n
"
"
127.0.0.1
\t
localhost
\n
"
"
192.168.1.1
\t
myhost.domain.tld myhost
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
@@ -480,12 +477,10 @@ class TestEtcHosts(unittest.TestCase):
try
:
RemoveEtcHostsEntry
(
tmpname
,
'
router
'
)
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
8b09207a23709d60240674601a3548b2
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
# This is a test file for /etc/hosts
\n
"
"
127.0.0.1
\t
localhost
\n
"
"
192.168.1.1 gw
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
@@ -494,12 +489,9 @@ class TestEtcHosts(unittest.TestCase):
try
:
RemoveEtcHostsEntry
(
tmpname
,
'
localhost
'
)
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
ec4e4589b56f82fdb88db5675de011b1
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
# This is a test file for /etc/hosts
\n
"
"
192.168.1.1 router gw
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
@@ -508,12 +500,10 @@ class TestEtcHosts(unittest.TestCase):
try
:
RemoveEtcHostsEntry
(
tmpname
,
'
myhost
'
)
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
aa005bddc6d9ee399c296953f194929e
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
# This is a test file for /etc/hosts
\n
"
"
127.0.0.1
\t
localhost
\n
"
"
192.168.1.1 router gw
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
@@ -522,12 +512,10 @@ class TestEtcHosts(unittest.TestCase):
try
:
RemoveEtcHostsEntry
(
tmpname
,
'
gw
'
)
f
=
open
(
tmpname
,
'
r
'
)
try
:
self
.
assertEqual
(
md5
.
new
(
f
.
read
(
8192
)).
hexdigest
(),
'
156dd3980a17b2ef934e2d0bf670aca2
'
)
finally
:
f
.
close
()
self
.
assertFileContent
(
tmpname
,
"
# This is a test file for /etc/hosts
\n
"
"
127.0.0.1
\t
localhost
\n
"
"
192.168.1.1 router
\n
"
)
finally
:
os
.
unlink
(
tmpname
)
...
...
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