Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
Lu Xu
slapos.toolbox
Commits
e5c544ed
Commit
e5c544ed
authored
Sep 30, 2021
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
promise/plugin: Allow asserting absence in check_file_state
parent
d0effe69
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
5 deletions
+53
-5
slapos/promise/plugin/check_file_state.py
slapos/promise/plugin/check_file_state.py
+12
-0
slapos/test/promise/plugin/test_check_file_state.py
slapos/test/promise/plugin/test_check_file_state.py
+41
-5
No files found.
slapos/promise/plugin/check_file_state.py
View file @
e5c544ed
from
zope.interface
import
implementer
from
zope.interface
import
implementer
from
slapos.grid.promise
import
interface
from
slapos.grid.promise
import
interface
from
slapos.grid.promise.generic
import
GenericPromise
from
slapos.grid.promise.generic
import
GenericPromise
import
os
@
implementer
(
interface
.
IPromise
)
@
implementer
(
interface
.
IPromise
)
...
@@ -21,6 +22,17 @@ class RunPromise(GenericPromise):
...
@@ -21,6 +22,17 @@ class RunPromise(GenericPromise):
state
=
self
.
getConfig
(
'state'
)
state
=
self
.
getConfig
(
'state'
)
url
=
(
self
.
getConfig
(
'url'
)
or
''
).
strip
()
url
=
(
self
.
getConfig
(
'url'
)
or
''
).
strip
()
exists
=
os
.
path
.
exists
(
filename
)
if
state
==
'absent'
:
if
exists
:
self
.
logger
.
error
(
"ERROR %r not absent"
,
filename
)
else
:
self
.
logger
.
info
(
"OK %r state %r"
%
(
filename
,
state
))
return
if
not
exists
:
self
.
logger
.
error
(
"ERROR %r not present"
,
filename
)
return
try
:
try
:
with
open
(
filename
)
as
f
:
with
open
(
filename
)
as
f
:
result
=
f
.
read
()
result
=
f
.
read
()
...
...
slapos/test/promise/plugin/test_check_file_state.py
View file @
e5c544ed
...
@@ -76,7 +76,7 @@ extra_config_dict = {
...
@@ -76,7 +76,7 @@ extra_config_dict = {
filename
)
filename
)
)
)
def
test_check_file_not_exists
(
self
):
def
test_check_file_not_exists
_fail
(
self
):
filename
=
os
.
path
.
join
(
self
.
tempdir
,
'test.file'
)
filename
=
os
.
path
.
join
(
self
.
tempdir
,
'test.file'
)
content
=
self
.
base_content
%
{
content
=
self
.
base_content
%
{
'filename'
:
filename
,
'filename'
:
filename
,
...
@@ -91,10 +91,46 @@ extra_config_dict = {
...
@@ -91,10 +91,46 @@ extra_config_dict = {
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
self
.
assertEqual
(
result
[
'result'
][
'message'
],
result
[
'result'
][
'message'
],
"ERROR %s(2, 'No such file or directory') "
"ERROR %r not present"
%
(
filename
,)
"during opening and reading file %r"
%
(
)
"FileNotFoundError"
if
six
.
PY3
else
"IOError"
,
filename
)
def
test_check_file_not_exists_absent
(
self
):
filename
=
os
.
path
.
join
(
self
.
tempdir
,
'test.file'
)
state
=
'absent'
content
=
self
.
base_content
%
{
'filename'
:
filename
,
'state'
:
state
,
'url'
:
'https://www.example.com/'
,
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"OK %r state %r"
%
(
filename
,
state
)
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
False
)
def
test_check_file_not_exists_absent_fail
(
self
):
filename
=
os
.
path
.
join
(
self
.
tempdir
,
'test.file'
)
with
open
(
filename
,
'w'
)
as
fh
:
fh
.
write
(
''
)
state
=
'absent'
content
=
self
.
base_content
%
{
'filename'
:
filename
,
'state'
:
state
,
'url'
:
'https://www.example.com/'
,
}
self
.
writePromise
(
self
.
promise_name
,
content
)
self
.
configureLauncher
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
result
=
self
.
getPromiseResult
(
self
.
promise_name
)
self
.
assertEqual
(
result
[
'result'
][
'failed'
],
True
)
self
.
assertEqual
(
result
[
'result'
][
'message'
],
"ERROR %r not absent"
%
(
filename
,)
)
)
def
test_check_file_empty
(
self
):
def
test_check_file_empty
(
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