Exemplo n.º 1
0
    def test_group(self):
        name = "dummy_group %d" % time.time()
        copyname = "copy_%s" % name
        renamedname = "move_%s" % name
        app_name = "test_app"
        weight = 100
        dummy_group = {app_name: weight}
        io.run_sync(group.Create(self.storage, name, dummy_group).execute,
                    timeout=2)

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

        listing = io.run_sync(group.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(group.View(self.storage, name).execute, timeout=2)
        assert isinstance(res, dict), res
        assert res == dummy_group, res

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

        io.run_sync(group.Create(self.storage, name, '{"A": 1}').execute,
                    timeout=2)
        res = io.run_sync(group.View(self.storage, name).execute, timeout=2)
        assert res == {'A': 1}, res

        res = io.run_sync(group.AddApplication(self.storage, name, app_name,
                                               weight).execute,
                          timeout=2)
        assert res is None, res

        res = io.run_sync(group.RemoveApplication(self.storage, name,
                                                  app_name).execute,
                          timeout=2)
        assert res is None, res

        io.run_sync(group.Refresh(self.locator, self.storage, name).execute,
                    timeout=2)
Exemplo n.º 2
0
def group_create(name, response):
    try:
        yield group.Create(storage, name).execute()
    except Exception as err:
        log.error(repr(err))
        response.error(-100, "Unable to read groups")
    finally:
        response.close()
Exemplo n.º 3
0
def app_deploy(task, response):
    s = list()
    f = list()
    try:
        name = task["appname"]
        version = task['version']
        appname = appname_from_name_version(name, version)
        profilename = task["profile"]
        runlistname = task["runlist"]
        weight = task.get("weight", 0)

        # get routing groups
        groups = yield group.List(storage).execute()
        if name not in groups:
            log.info("Create routing group %s" % name)
            # create routing group for given application
            yield group.Create(storage, name).execute()
        # add application into routing group
        log.info("Add %s to groups %s with weight %d" % (appname,
                                                         name,
                                                         weight))
        yield group.AddApplication(storage, name, appname, weight).execute()

        log.info("Add %s to runlist %s" % (appname, runlistname))
        yield runlist.AddApplication(storage,
                                     runlistname,
                                     appname,
                                     profilename, force=True).execute()
        hosts = yield hostdb.hosts()
        cluster = NodeCluster(hosts, response.write)
        (s, f) = yield cluster.start_app(appname, profilename)
    except Exception as err:
        log.error("Unknown error %s" % repr(err))
        response.error(-100, "Unknown error %s" % repr(err))
    else:
        response.write("Done")
    finally:
        response.close()
Exemplo n.º 4
0
 def upload(self, data):
     return group.Create(self.storage, self.name, data).execute()
Exemplo n.º 5
0
 def test_validation_in_create(self):
     bad_content = {"A": 1.0}
     io.run_sync(group.Create(self.storage, "bad_group",
                              bad_content).execute,
                 timeout=2)