Exemple #1
0
    def test_RunlistUploadActionRawRunlistProvided(self):
        storage = mock()
        action = runlist.Upload(storage, **{'name': 'RunlistName', 'runlist': '{}'})
        when(storage).write(any(str), any(str), any(str), any(tuple)).thenReturn(Chain([lambda: 'Ok']))
        action.execute().get()

        verify(storage).write('runlists', 'RunlistName', msgpack.dumps({}), RUNLISTS_TAGS)
Exemple #2
0
    def test_RunlistUploadAction(self):
        storage = mock()
        jsonEncoder = mock()
        action = runlist.Upload(storage, **{'name': 'RunlistName', 'runlist': 'r.json'})
        action.jsonEncoder = jsonEncoder
        when(jsonEncoder).encode('r.json').thenReturn('{-encodedJson-}')
        when(storage).write(any(str), any(str), any(str), any(tuple)).thenReturn(Chain([lambda: 'Ok']))
        action.execute().get()

        verify(storage).write('runlists', 'RunlistName', '{-encodedJson-}', RUNLISTS_TAGS)
Exemple #3
0
#!/usr/bin/env python
import os

from cocaine.tools.actions import runlist, profile
from cocaine.services import Service
from cocaine.exceptions import ChokeEvent

COMBAINE_RUNLIST = "combaine"

try:
    s = Service("storage")
    if "default" not in profile.List(s).execute().get():
        try:
            print("Create empty profile")
            profile.Upload(s, "default",
                           os.path.dirname(__file__) + "/profile.json").execute().get()
        except ChokeEvent:
            pass
    if COMBAINE_RUNLIST not in runlist.List(s).execute().get():
        try:
            print("Create empty runlist")
            runlist.Upload(s, COMBAINE_RUNLIST,
                           os.path.dirname(__file__) + "/runlist.json").execute().get()
        except ChokeEvent:
            pass
except Exception as err:
    print('%s' % repr(err))
    exit(1)
 def upload(self, data):
     return runlist.Upload(self.storage, self.name, data).execute()
Exemple #5
0
 def test_upload_value_error(self):
     runlist.Upload(None, "the_same", None)
Exemple #6
0
    def test_runlist(self):
        name = "dummy_runlist %d" % time.time()
        copyname = "copy_%s" % name
        renamedname = "move_%s" % name
        app_name = "test_app"
        profile_name = "test_profile"
        dummy_runlist = {app_name: profile_name}
        io.run_sync(runlist.Upload(self.storage, name, dummy_runlist).execute,
                    timeout=2)

        io.run_sync(runlist.Copy(self.storage, name, copyname).execute,
                    timeout=2)
        io.run_sync(runlist.Rename(self.storage, copyname,
                                   renamedname).execute,
                    timeout=2)

        listing = io.run_sync(runlist.List(self.storage).execute, timeout=2)
        assert isinstance(listing, (list, tuple)), listing
        assert name in listing
        assert copyname not in listing
        assert renamedname in listing

        res = io.run_sync(runlist.View(self.storage, name).execute, timeout=2)
        assert isinstance(res, dict), res
        assert res == dummy_runlist, res

        io.run_sync(runlist.Remove(self.storage, name).execute, timeout=2)
        try:
            io.run_sync(runlist.View(self.storage, name).execute, timeout=2)
        except ServiceError:
            pass

        io.run_sync(runlist.Create(self.storage, name).execute, timeout=2)
        res = io.run_sync(runlist.View(self.storage, name).execute, timeout=2)
        assert res == {}, res

        res = io.run_sync(runlist.AddApplication(self.storage,
                                                 name,
                                                 app_name,
                                                 profile_name,
                                                 force=False).execute,
                          timeout=2)
        assert isinstance(res, dict), res
        assert "added" in res, res
        assert app_name == res["added"]["app"] and profile_name == res[
            "added"]["profile"], res

        res = io.run_sync(runlist.AddApplication(self.storage,
                                                 "ZZ" + name,
                                                 app_name,
                                                 profile_name,
                                                 force=True).execute,
                          timeout=2)
        assert isinstance(res, dict), res
        assert "added" in res, res
        assert app_name == res["added"]["app"] and profile_name == res[
            "added"]["profile"], res

        missing_name = "ZZZZ" + app_name
        res = io.run_sync(runlist.RemoveApplication(self.storage, name,
                                                    missing_name).execute,
                          timeout=2)
        assert res[
            'status'] == "the application named %s is not in runlist" % missing_name

        res = io.run_sync(runlist.RemoveApplication(self.storage, name,
                                                    app_name).execute,
                          timeout=2)
        assert isinstance(res, dict), res