Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
K
kedifa
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Aurel
kedifa
Commits
73a14b0e
Commit
73a14b0e
authored
Mar 29, 2019
by
Łukasz Nowak
Committed by
Łukasz Nowak
Apr 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updater: Unlink lock file
Also cover loop method.
parent
1f273c26
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
2 deletions
+70
-2
kedifa/test.py
kedifa/test.py
+62
-0
kedifa/updater.py
kedifa/updater.py
+8
-2
No files found.
kedifa/test.py
View file @
73a14b0e
...
...
@@ -34,6 +34,7 @@ import sys
import
tempfile
import
time
import
unittest
import
zc.lockfile
from
cryptography
import
x509
from
cryptography.hazmat.backends
import
default_backend
...
...
@@ -1337,3 +1338,64 @@ class KedifaUpdaterUpdateCertificateTest(
self
.
assertEqual
(
'content'
,
certificate
)
self
.
assertTrue
(
update
)
self
.
assertState
({
self
.
certificate_file_name
:
True
})
class
KedifaUpdaterLoopTest
(
KedifaUpdaterMixin
,
unittest
.
TestCase
):
def
test
(
self
):
u
=
updater
.
Updater
(
1
,
None
,
self
.
state
,
None
,
None
,
None
,
None
,
True
)
lock_file
=
u
.
state_lock_file
os
.
unlink
(
self
.
state
)
self
.
assertFalse
(
os
.
path
.
exists
(
lock_file
))
self
.
assertFalse
(
os
.
path
.
exists
(
self
.
state
))
with
mock
.
patch
.
object
(
updater
.
Updater
,
'action'
,
return_value
=
None
)
as
mock_object
:
u
.
loop
()
mock_object
.
assert_called
()
self
.
assertFalse
(
os
.
path
.
exists
(
lock_file
))
self
.
assertFalse
(
os
.
path
.
exists
(
self
.
state
))
def
test_raises
(
self
):
u
=
updater
.
Updater
(
1
,
None
,
self
.
state
,
None
,
None
,
None
,
None
,
True
)
lock_file
=
u
.
state_lock_file
self
.
assertFalse
(
os
.
path
.
exists
(
lock_file
))
with
mock
.
patch
.
object
(
updater
.
Updater
,
'action'
,
side_effect
=
Exception
())
as
mock_object
:
self
.
assertRaises
(
Exception
,
u
.
loop
)
mock_object
.
assert_called
()
self
.
assertFalse
(
os
.
path
.
exists
(
lock_file
))
def
test_lock
(
self
):
u
=
updater
.
Updater
(
1
,
None
,
self
.
state
,
None
,
None
,
None
,
None
,
True
)
lock_file
=
u
.
state_lock_file
lock
=
zc
.
lockfile
.
LockFile
(
lock_file
)
try
:
self
.
assertTrue
(
os
.
path
.
exists
(
lock_file
))
with
mock
.
patch
.
object
(
updater
.
Updater
,
'action'
,
return_value
=
None
)
as
mock_object
:
self
.
assertRaises
(
SystemExit
,
u
.
loop
)
mock_object
.
assert_not_called
()
self
.
assertTrue
(
os
.
path
.
exists
(
lock_file
))
finally
:
lock
.
close
()
def
test_infinite
(
self
):
u
=
updater
.
Updater
(
1
,
None
,
self
.
state
,
None
,
None
,
None
,
None
,
False
)
lock_file
=
u
.
state_lock_file
os
.
unlink
(
self
.
state
)
self
.
assertFalse
(
os
.
path
.
exists
(
lock_file
))
self
.
assertFalse
(
os
.
path
.
exists
(
self
.
state
))
with
mock
.
patch
.
object
(
updater
.
Updater
,
'action'
,
return_value
=
None
)
as
mock_object
:
with
mock
.
patch
.
object
(
updater
.
time
,
'sleep'
,
side_effect
=
ValueError
(
'timer'
))
as
timer
:
self
.
assertRaises
(
ValueError
,
u
.
loop
)
timer
.
assert_called_with
(
1
)
mock_object
.
assert_called
()
self
.
assertFalse
(
os
.
path
.
exists
(
lock_file
))
self
.
assertFalse
(
os
.
path
.
exists
(
self
.
state
))
kedifa/updater.py
View file @
73a14b0e
...
...
@@ -156,8 +156,14 @@ class Updater(object):
else
:
print
"...will try again later."
else
:
self
.
action
()
lock
.
close
()
try
:
self
.
action
()
finally
:
lock
.
close
()
try
:
os
.
unlink
(
self
.
state_lock_file
)
except
Exception
as
e
:
print
'Problem while unlinking %r'
%
(
self
.
state_lock_file
,)
if
self
.
once
:
break
print
'Sleeping for %is'
%
(
self
.
sleep
,)
...
...
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