Commit 8baca1c5 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos.package: Run more often and upgrade from safe place

Restrict upgrade egg from a safe hardcoded source only
parent db06e9d5
...@@ -40,10 +40,12 @@ def do_update(): ...@@ -40,10 +40,12 @@ def do_update():
_run_command('slappkg-update-raw') _run_command('slappkg-update-raw')
def _run_command(command): def _run_command(command):
if '--no-update' in sys.argv: if '--self-update' in sys.argv:
sys.argv.remove('--no-update') sys.argv.remove('--self-update')
else: subprocess.call(['easy_install', '-U',
subprocess.call(['easy_install', '-U', 'slapos.package']) "-f", "http://www.nexedi.org/static/packages/source/",
"--allow-hosts", "http://www.nexedi.org/static/packages/source/",
'slapos.package'])
args = [ args = [
os.path.join(os.path.dirname(sys.argv[0]), command) os.path.join(os.path.dirname(sys.argv[0]), command)
......
...@@ -4,5 +4,6 @@ SHELL=/bin/sh ...@@ -4,5 +4,6 @@ SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin:/usr/local/bin PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin:/usr/local/bin
MAILTO=root MAILTO=root
# This file expects that # This file expects that
0 */6 * * * root slappkg-update --slapos-configuration=%(configuration_path)s -v >> %(slapos_location)s/log/slappkg-update.log 2>&1 0 1 * * * root slappkg-update --self-update --slapos-configuration=%(configuration_path)s -v >> %(slapos_location)s/log/slappkg-update.log 2>&1
10 * * * * root slappkg-update --wait --slapos-configuration=%(configuration_path)s -v >> %(slapos_location)s/log/slappkg-update.log 2>&1
...@@ -38,8 +38,9 @@ SHELL=/bin/sh ...@@ -38,8 +38,9 @@ SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin:/usr/local/bin PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/lib/news/bin:/usr/local/bin
MAILTO=root MAILTO=root
# This file expects that # This file expects that
0 */6 * * * root slappkg-update --slapos-configuration=/tmp/SOMEFILENAME -v >> /opt/slapos/log/slappkg-update.log 2>&1""" 0 1 * * * root slappkg-update --self-update --slapos-configuration=/tmp/SOMEFILENAME -v >> /opt/slapos/log/slappkg-update.log 2>&1
10 * * * * root slappkg-update --wait --slapos-configuration=/tmp/SOMEFILENAME -v >> /opt/slapos/log/slappkg-update.log 2>&1"""
def _fake_call(self, *args, **kw): def _fake_call(self, *args, **kw):
self.last_call = (args, kw) self.last_call = (args, kw)
...@@ -47,6 +48,7 @@ def _fake_call(self, *args, **kw): ...@@ -47,6 +48,7 @@ def _fake_call(self, *args, **kw):
class testSlappkgCronTestCase(unittest.TestCase): class testSlappkgCronTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.maxDiff = None
self.configuration_file_path = "/tmp/test_promise_testing_slappkg.cron" self.configuration_file_path = "/tmp/test_promise_testing_slappkg.cron"
slappkgcron.Promise._call = _fake_call slappkgcron.Promise._call = _fake_call
if os.path.exists(self.configuration_file_path): if os.path.exists(self.configuration_file_path):
......
...@@ -32,9 +32,17 @@ import datetime ...@@ -32,9 +32,17 @@ import datetime
import logging import logging
from optparse import OptionParser, Option from optparse import OptionParser, Option
import sys import sys
import random
import time
from signature import Signature from signature import Signature
from promise import promise_list from promise import promise_list
def _wait_before_run():
wait_period = random.randint(1, 50)
print "Sleep few seconds before start (%s) ..." % wait_period
time.sleep(wait_period)
class Parser(OptionParser): class Parser(OptionParser):
""" """
Parse all arguments. Parse all arguments.
...@@ -51,6 +59,10 @@ class Parser(OptionParser): ...@@ -51,6 +59,10 @@ class Parser(OptionParser):
Option("--srv-file", Option("--srv-file",
default='/srv/slapupdate', default='/srv/slapupdate',
help="Server status file."), help="Server status file."),
Option("--wait",
default=False,
action="store_true",
help="Wait random seconds to call upgrade."),
Option("-v", "--verbose", Option("-v", "--verbose",
default=False, default=False,
action="store_true", action="store_true",
...@@ -73,6 +85,9 @@ def do_update(): ...@@ -73,6 +85,9 @@ def do_update():
usage = "usage: %s [options] " % sys.argv[0] usage = "usage: %s [options] " % sys.argv[0]
config_dict = Parser(usage=usage).check_args() config_dict = Parser(usage=usage).check_args()
if config_dict.wait:
_wait_before_run()
for promise_klass in promise_list: for promise_klass in promise_list:
# Parse arguments # Parse arguments
upgrader = promise_klass(config_dict) upgrader = promise_klass(config_dict)
......
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