Ejemplo n.º 1
0
    def test_profile(self):
        name = "dummy_profile_name %d" % time.time()
        copyname = "copy_%s" % name
        renamedname = "move_%s" % name
        dummy_profile = {"aaa": [1, 2, 3]}
        io.run_sync(profile.Upload(self.storage, name, dummy_profile).execute,
                    timeout=2)

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

        listing = io.run_sync(profile.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

        pr = io.run_sync(profile.View(self.storage, name).execute, timeout=2)
        assert pr == dummy_profile

        io.run_sync(profile.Remove(self.storage, name).execute, timeout=2)
        try:
            io.run_sync(profile.View(self.storage, name).execute, timeout=2)
        except ServiceError:
            pass
        else:
            raise AssertionError("an exception is expected")
Ejemplo n.º 2
0
 def test_ProfileUploadActionRethrowsExceptions(self):
     storage = mock()
     jsonEncoder = mock()
     action = profile.Upload(storage, **{'name': 'ProfileName', 'profile': 'p.json'})
     action.jsonEncoder = jsonEncoder
     when(jsonEncoder).encode('p.json').thenRaise(ValueError)
     self.assertRaises(ValueError, action.execute)
Ejemplo n.º 3
0
def profile_upload(task, response):
    try:
        profilename = task["profilename"]
        profilebody = task["profile"]
        yield profile.Upload(storage, profilename, profilebody).execute()
    except Exception as err:
        log.error("Unable to upload profile %s" % err)
        response.error(-99, "Unable to upload profile %s" % err)
    finally:
        response.close()
Ejemplo n.º 4
0
    def test_ProfileUploadAction(self):
        storage = mock()
        jsonEncoder = mock()
        action = profile.Upload(storage, **{'name': 'ProfileName', 'profile': 'p.json'})
        action.jsonEncoder = jsonEncoder
        when(jsonEncoder).encode('p.json').thenReturn('{-encodedJson-}')
        when(storage).write(any(str), any(str), any(str), any(tuple)).thenReturn(Chain([lambda: 'Ok']))
        action.execute().get()

        verify(storage).write('profiles', 'ProfileName', '{-encodedJson-}', PROFILES_TAGS)
Ejemplo n.º 5
0
    def test_app_b_start(self):
        name = "random_name"
        io.run_sync(profile.Upload(self.storage, "random_profile",
                                   "{}").execute,
                    timeout=2)
        result = io.run_sync(app.Start(self.node, name,
                                       "random_profile").execute,
                             timeout=2)
        assert "application `random_name` has been started with profile `random_profile`" == result, result

        result = io.run_sync(app.Check(self.node, self.storage, self.locator,
                                       name).execute,
                             timeout=2)
        assert result['state'] == "running"
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def upload(self, data):
     return profile.Upload(self.storage, self.name, data).execute()
Ejemplo n.º 8
0
 def test_upload_invalid_value(self):
     profile.Upload(self.storage, "dummy", None)
Ejemplo n.º 9
0
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")
    try:
        print("Update profile")
        profile_json = os.path.dirname(__file__) + "/profile.json"
        if not os.path.exists(profile_json):
            print("Use default profile")
            profile_json = os.path.dirname(__file__) + "/profile-default.json"
        profile.Upload(s, "default", 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)