Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
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
Boxiang Sun
slapos.package
Commits
aa10b24e
Commit
aa10b24e
authored
Jun 29, 2015
by
Kristopher Ruzic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds checking for .completed
finishes up needed features
parent
b2722b90
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
25 deletions
+36
-25
playbook/roles/test-suite/files/log-uploader
playbook/roles/test-suite/files/log-uploader
+36
-25
No files found.
playbook/roles/test-suite/files/log-uploader
View file @
aa10b24e
...
@@ -3,21 +3,16 @@
...
@@ -3,21 +3,16 @@
import
os
import
os
import
sys
import
sys
import
time
import
time
from
glob
import
glob
import
requests
import
requests
from
watchdog.observers
import
Observer
from
watchdog.observers
import
Observer
from
watchdog.events
import
FileSystemEventHandler
from
watchdog.events
import
FileSystemEventHandler
class
MyHandler
(
FileSystemEventHandler
):
class
MyHandler
(
FileSystemEventHandler
):
def
on_modified
(
self
,
event
):
print
vars
(
event
)
def
on_created
(
self
,
event
):
def
on_created
(
self
,
event
):
if
".completed"
in
event
.
file
:
if
".completed"
in
event
.
file
:
print
"partition completed!"
print
"partition completed!"
f
=
open
(
"tmp/tmpupload"
,
'w'
)
upload_file
(
event
.
file
,
fmt_date
()
+
": partition completed"
)
f
.
write
(
fmt_date
()
+
": partition completed"
)
f
.
close
()
upload_file
(
event
.
file
,
open
(
"tmp/tmpupload"
,
'rb'
))
def
fmt_date
():
def
fmt_date
():
return
time
.
strftime
(
"[ %Y%m%d %H:%M:%S ]"
)
return
time
.
strftime
(
"[ %Y%m%d %H:%M:%S ]"
)
...
@@ -32,13 +27,24 @@ class uploader():
...
@@ -32,13 +27,24 @@ class uploader():
values
=
{
'file_path'
:
dir_date
()
+
file_name
,
'contents'
:
contents
}
values
=
{
'file_path'
:
dir_date
()
+
file_name
,
'contents'
:
contents
}
r
=
requests
.
post
(
self
.
url
,
data
=
values
)
r
=
requests
.
post
(
self
.
url
,
data
=
values
)
def
check_startup
():
pid
=
str
(
os
.
getpid
())
pidfile
=
"/tmp/slaplogger.pid"
if
os
.
path
.
isfile
(
pidfile
):
print
"%s already exists, exiting"
%
pidfile
sys
.
exit
()
else
:
file
(
pidfile
,
'w'
).
write
(
pid
)
os
.
unlink
(
pidfile
)
def
scan_files
(
files
):
def
scan_files
(
files
):
try
:
try
:
with
open
(
"lines"
,
'r'
)
as
myfile
:
with
open
(
"
/opt/slapos/
lines"
,
'r'
)
as
myfile
:
software_line
=
myfile
.
readlines
()
software_line
=
myfile
.
readlines
()
except
:
except
:
software_line
=
[
0
]
*
len
(
files
)
software_line
=
[
0
]
*
len
(
files
)
with
open
(
"lines"
,
'w'
):
with
open
(
"
/opt/slapos/
lines"
,
'w'
):
pass
pass
place
=
0
place
=
0
...
@@ -47,7 +53,7 @@ def scan_files(files):
...
@@ -47,7 +53,7 @@ def scan_files(files):
print
software_line
print
software_line
with
open
(
f
,
'r'
)
as
myfile
:
with
open
(
f
,
'r'
)
as
myfile
:
new_lines
=
myfile
.
readlines
()[
software_line
[
place
]:]
new_lines
=
myfile
.
readlines
()[
software_line
[
place
]:]
with
open
(
"lines"
,
'a'
)
as
myfile
:
with
open
(
"
/opt/slapos/
lines"
,
'a'
)
as
myfile
:
myfile
.
write
(
str
(
software_line
[
place
])
+
str
(
len
(
new_lines
)))
myfile
.
write
(
str
(
software_line
[
place
])
+
str
(
len
(
new_lines
)))
print
"Uploading "
+
f
+
"..."
print
"Uploading "
+
f
+
"..."
c
.
upload_file
(
os
.
path
.
basename
(
f
),
new_lines
)
c
.
upload_file
(
os
.
path
.
basename
(
f
),
new_lines
)
...
@@ -57,25 +63,30 @@ def scan_files(files):
...
@@ -57,25 +63,30 @@ def scan_files(files):
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
check_startup
()
c
=
uploader
()
c
=
uploader
()
files
=
[
"/opt/slapos/log/slapos-node-software.log"
,
"/opt/slapos/log/slapos-node-format.log"
,
"/opt/slapos/log/slapos-node-instance.log"
]
files
=
[
"/opt/slapos/log/slapos-node-software.log"
,
"/opt/slapos/log/slapos-node-format.log"
,
"/opt/slapos/log/slapos-node-instance.log"
]
scan_files
(
files
)
# first check if .completed exists in any partitions
paths
=
[
"/opt/slapgrid/slappart"
+
p
+
".completed"
for
p
in
glob
(
'/opt/slapgrid/*'
)]
for
p
in
paths
:
try
:
f
=
open
(
p
,
'r'
)
upload_file
(
p
,
fmt_date
()
+
": partition completed"
)
except
IOError
as
e
:
pass
# event_handler = MyHandler()
event_handler
=
MyHandler
()
# observer = Observer()
observer
=
Observer
()
# observer.schedule(event_handler, path='/opt/slapos/log', recursive=False)
# observer.start()
# check if .completed exists or not, and write it to the server log
# check if .completed exists or not, and write it to the server log
# """ observer.schedule(event_handler, path='/opt/slapgrid/', recursive=True)
observer
.
schedule
(
event_handler
,
path
=
'/opt/slapgrid/'
,
recursive
=
True
)
# observer.start()
observer
.
start
()
# try:
try
:
# while True:
while
True
:
# time.sleep(1)
scan
.
files
(
files
)
# except KeyboardInterrupt:
except
KeyboardInterrupt
:
# observer.stop()
observer
.
stop
()
# observer.join()
observer
.
join
()
#"""
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