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")
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)
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()
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)
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"
#!/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 profile.Upload(self.storage, self.name, data).execute()
def test_upload_invalid_value(self): profile.Upload(self.storage, "dummy", None)
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)