Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
slapos.core
Commits
d297716e
Commit
d297716e
authored
May 15, 2014
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[slapos.collect] Include test for Database API
parent
23de5db5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
142 additions
and
1 deletion
+142
-1
slapos/tests/collect.py
slapos/tests/collect.py
+142
-1
No files found.
slapos/tests/collect.py
View file @
d297716e
...
...
@@ -34,7 +34,7 @@ import slapos.cli.collect
import
slapos.slap
import
psutil
from
slapos.cli.collect
import
CollectCommand
from
slapos.collect
import
entity
,
snapshot
from
slapos.collect
import
entity
,
snapshot
,
db
from
slapos.cli.entry
import
SlapOSApp
from
argparse
import
Namespace
from
ConfigParser
import
ConfigParser
...
...
@@ -64,6 +64,147 @@ class FakeDatabase(object):
def
insertDiskPartitionSnapshot
(
self
,
*
args
,
**
kw
):
self
.
invoked_method_list
.
append
((
"insertDiskPartitionSnapshot"
,
(
args
,
kw
)))
class
TestCollectDatabase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
instance_root
=
tempfile
.
mkdtemp
()
def
tearDown
(
self
):
if
os
.
path
.
exists
(
self
.
instance_root
):
shutil
.
rmtree
(
self
.
instance_root
)
def
test_database_bootstrap
(
self
):
self
.
assertFalse
(
os
.
path
.
exists
(
"%s/collector.db"
%
self
.
instance_root
))
database
=
db
.
Database
(
self
.
instance_root
)
database
.
connect
()
try
:
table_list
=
database
.
_execute
(
"SELECT name FROM sqlite_master WHERE type='table'"
)
self
.
assertEquals
(
[(
u'user'
,),
(
u'computer'
,),
(
u'system'
,),
(
u'disk'
,)],
[
i
for
i
in
table_list
])
finally
:
database
.
close
()
self
.
assertTrue
(
os
.
path
.
exists
(
"%s/collector.db"
%
self
.
instance_root
))
def
test_insert_user_snapshot
(
self
):
database
=
db
.
Database
(
self
.
instance_root
)
database
.
connect
()
try
:
database
.
insertUserSnapshot
(
'fakeuser0'
,
10
,
'10-12345'
,
'0.1'
,
'10.0'
,
'1'
,
'10.0'
,
'10.0'
,
'0.1'
,
'0.1'
,
'DATE'
,
'TIME'
)
database
.
commit
()
self
.
assertEquals
([
i
for
i
in
database
.
select
(
'user'
)],
[(
u'fakeuser0'
,
10.0
,
u'10-12345'
,
0.1
,
10.0
,
1.0
,
10.0
,
10.0
,
0.1
,
0.1
,
u'DATE'
,
u'TIME'
,
0
)])
finally
:
database
.
close
()
def
test_insert_computer_snapshot
(
self
):
database
=
db
.
Database
(
self
.
instance_root
)
database
.
connect
()
try
:
database
.
insertComputerSnapshot
(
'1'
,
'0'
,
'0'
,
'100'
,
'0'
,
'/dev/sdx1'
,
'DATE'
,
'TIME'
)
database
.
commit
()
self
.
assertEquals
([
i
for
i
in
database
.
select
(
'computer'
)],
[(
1.0
,
0.0
,
u'0'
,
100.0
,
u'0'
,
u'/dev/sdx1'
,
u'DATE'
,
u'TIME'
,
0
)])
finally
:
database
.
close
()
def
test_insert_disk_partition_snapshot
(
self
):
database
=
db
.
Database
(
self
.
instance_root
)
database
.
connect
()
try
:
database
.
insertDiskPartitionSnapshot
(
'/dev/sdx1'
,
'10'
,
'20'
,
'/mnt'
,
'DATE'
,
'TIME'
)
database
.
commit
()
self
.
assertEquals
([
i
for
i
in
database
.
select
(
'disk'
)],
[(
u'/dev/sdx1'
,
u'10'
,
u'20'
,
u'/mnt'
,
u'DATE'
,
u'TIME'
,
0
)])
finally
:
database
.
close
()
def
test_insert_system_snapshot
(
self
):
database
=
db
.
Database
(
self
.
instance_root
)
database
.
connect
()
try
:
database
.
insertSystemSnapshot
(
"0.1"
,
'10.0'
,
'100.0'
,
'100.0'
,
'10.0'
,
'1'
,
'2'
,
'12.0'
,
'1'
,
'1'
,
'DATE'
,
'TIME'
)
database
.
commit
()
self
.
assertEquals
([
i
for
i
in
database
.
select
(
'system'
)],
[(
0.1
,
10.0
,
100.0
,
100.0
,
10.0
,
1.0
,
2.0
,
12.0
,
1.0
,
1.0
,
u'DATE'
,
u'TIME'
,
0
)])
finally
:
database
.
close
()
def
test_date_scope
(
self
):
database
=
db
.
Database
(
self
.
instance_root
)
database
.
connect
()
try
:
database
.
insertSystemSnapshot
(
"0.1"
,
'10.0'
,
'100.0'
,
'100.0'
,
'10.0'
,
'1'
,
'2'
,
'12.0'
,
'1'
,
'1'
,
'EXPECTED-DATE'
,
'TIME'
)
database
.
commit
()
self
.
assertEquals
([
i
for
i
in
database
.
getDateScopeList
()],
[(
'EXPECTED-DATE'
,
1
)])
self
.
assertEquals
([
i
for
i
in
\
database
.
getDateScopeList
(
ignore_date
=
'EXPECTED-DATE'
)],
[])
self
.
assertEquals
([
i
for
i
in
\
database
.
getDateScopeList
(
reported
=
1
)],
[])
finally
:
database
.
close
()
def
test_mark_day_as_reported
(
self
):
database
=
db
.
Database
(
self
.
instance_root
)
database
.
connect
()
try
:
database
.
insertSystemSnapshot
(
"0.1"
,
'10.0'
,
'100.0'
,
'100.0'
,
'10.0'
,
'1'
,
'2'
,
'12.0'
,
'1'
,
'1'
,
'EXPECTED-DATE'
,
'TIME'
)
database
.
insertSystemSnapshot
(
"0.1"
,
'10.0'
,
'100.0'
,
'100.0'
,
'10.0'
,
'1'
,
'2'
,
'12.0'
,
'1'
,
'1'
,
'NOT-EXPECTED-DATE'
,
'TIME'
)
database
.
commit
()
self
.
assertEquals
([
i
for
i
in
database
.
select
(
'system'
)],
[(
0.1
,
10.0
,
100.0
,
100.0
,
10.0
,
1.0
,
2.0
,
12.0
,
1.0
,
1.0
,
u'EXPECTED-DATE'
,
u'TIME'
,
0
),
(
0.1
,
10.0
,
100.0
,
100.0
,
10.0
,
1.0
,
2.0
,
12.0
,
1.0
,
1.0
,
u'NOT-EXPECTED-DATE'
,
u'TIME'
,
0
)])
database
.
markDayAsReported
(
date_scope
=
"EXPECTED-DATE"
,
table_list
=
[
"system"
])
database
.
commit
()
self
.
assertEquals
([
i
for
i
in
database
.
select
(
'system'
)],
[(
0.1
,
10.0
,
100.0
,
100.0
,
10.0
,
1.0
,
2.0
,
12.0
,
1.0
,
1.0
,
u'EXPECTED-DATE'
,
u'TIME'
,
1
),
(
0.1
,
10.0
,
100.0
,
100.0
,
10.0
,
1.0
,
2.0
,
12.0
,
1.0
,
1.0
,
u'NOT-EXPECTED-DATE'
,
u'TIME'
,
0
)])
finally
:
database
.
close
()
class
TestCollectSnapshot
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
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