Commit 71545053 authored by Kristopher Ruzic's avatar Kristopher Ruzic

Restructures things, makes test-suite into a role

Since it has a file that needs installing (log-uploader), this is currently needed. Fixes issues from prior commit, utilising ansible modules properly
parent 862adc84
#!/usr/bin/python2.7
import sys
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class MyHandler(FileSystemEventHandler):
def on_modified(self, event):
print vars(event)
def on_created(self, event):
if ".completed" in event.file:
print "partition completed!"
f = open("tmp/tmpupload", 'w')
f.write(fmt_date() + ": partition completed")
f.close()
upload_file(event.file, open("tmp/tmpupload", 'rb')
else:
return
def fmt_date():
return time.strftime("[ %Y%m%d %H:%M:%S ]")
class uploader():
system_name = ""
url = 'LATER'
# takes a file handler and a name (where it should be saved on server)
def upload_file(file_name, contents):
files = {'file': f}
values = {'file_path': system_name+file_name}
r = requests.post(url, files=files, data=values)
if __name__ == "__main__":
event_handler = MyHandler()
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
observer.schedule(event_handler, path='/opt/slapgrid/', recursive=True, patterns=".completed")
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
---
- stat: path=/tmp/playbook_software_name
register: software_release
- name: download software_release name
get_url: url=https://lab.nexedi.cn/krruzic/test-repository/raw/master/software
dest=software_release
- name: create log-uploader
copy: src=log-uploader dest=/usr/local/bin/log-uploader mode=755
- name: add log_uploader to cron
cron: name="Ensure log_uploader is running"
minute="*/6"
job="usr/local/bin/log_uploader"
- name: run ansible playbook
shell: ansible-playbook "{{ lookup('file', {{ software_release }}) }}" -i hosts
  • Just noticed this line won't work anymore... Will need to define hosts in global_vars(?)

Please register or sign in to reply
# install dependencies
- easy_install: name=watchdog state=latest
- easy_install: name=pip state=latest
- pip: name=requests
---
- file: path=/opt/ansible-install state=directory mode=0755
- stat path=/opt/ansible-install/software
register: software_release
- name: download software_release name
get_url: url=https://lab.nexedi.cn/krruzic/test-repository/raw/master/software
dest=software_release
roles:
- test-suite
- standalone-shared
- name: download log_uploader
get_url: url=https://lab.nexedi.cn/krruzic/test-repository/raw/master/log_uploader
dest=/usr/local/bin/log_uploader
- name: run ansible playbook
shell: ansible-playbook "{{ lookup('file', {{ software_release }}) }}" -i hosts
- name: add log_uploader to cron
cron: name="Ensure log_uploader is running"
second="10"
job="usr/local/bin/log_uploader"
- name: install watchdog
shell: easy_install watchdog
- name: install pip
shell: easy_install pip
- name: install python requests from pip
shell: pip install requests
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment