def test_builds_from_today(self, session): models.Build(project=models.Project(name='ceph'), status="ready") models.commit() result = session.app.get('/') now = datetime.datetime.utcnow() today_str = now.strftime('%Y-%m-%d') assert today_str in result.namespace['area_data']
def is_node_healthy(node, only_check=False): """ Pings the chacra node's health check endpoint to verify it is healthy and ready for use. If it fails the health, the node's ``down_count`` will be incremented. If the ``down_count`` reaches the value set for ``health_check_retries`` it will be marked down and removed from the pool. """ if not check_node_health(node): node.down_count = node.down_count + 1 logger.warning("node: %s has failed a health check. current count: %s", node.host, node.down_count) if node.down_count == getattr(conf, 'health_check_retries', 3): logger.warning( "node: %s has reached the limit for health check retires and will marked down", node.host) node.healthy = False models.commit() return False # reset the down_count when the node is healthy node.down_count = 0 node.healthy = True models.commit() return True
def connection(app, request): """Session-wide test database.""" # Connect and create the temporary database print "=" * 80 print "CREATING TEMPORARY DATABASE FOR TESTS" print "=" * 80 subprocess.call(['dropdb', DBNAME]) subprocess.call(['createdb', DBNAME]) # Bind and create the database tables _db.clear() engine_url = '%s/%s' % (BIND, DBNAME) db_engine = create_engine(engine_url, encoding='utf-8', poolclass=NullPool) # AKA models.start() _db.Session.bind = db_engine _db.metadata.bind = _db.Session.bind _db.Base.metadata.create_all(db_engine) _db.commit() _db.clear() def teardown(): _db.Base.metadata.drop_all(db_engine) request.addfinalizer(teardown) # Slap our test app on it _db.app = app return _db
def connection(app, request): """Session-wide test database.""" # Connect and create the temporary database print "=" * 80 print "CREATING TEMPORARY DATABASE FOR TESTS" print "=" * 80 subprocess.call(['dropdb', DBNAME]) subprocess.call(['createdb', DBNAME]) # Bind and create the database tables _db.clear() engine_url = '%s/%s' % (BIND, DBNAME) db_engine = create_engine( engine_url, encoding='utf-8', poolclass=NullPool) # AKA models.start() _db.Session.bind = db_engine _db.metadata.bind = _db.Session.bind _db.Base.metadata.create_all(db_engine) _db.commit() _db.clear() def teardown(): _db.Base.metadata.drop_all(db_engine) request.addfinalizer(teardown) # Slap our test app on it _db.app = app return _db
def test_list_flavors_by_id(self, session): project = Project(name='ceph') Build(build_id=1, project=project, ref='master', sha1='1234', flavor='default') Build(build_id=2, project=project, ref='master', sha1='1234', flavor='default') Build(build_id=100, project=project, ref='master', sha1='1234', flavor='default') commit() result = session.app.get('/builds/ceph/master/1234/default/') assert result.namespace['builds'][0].build_id == '100' assert result.namespace['builds'][1].build_id == '2' assert result.namespace['builds'][2].build_id == '1'
def test_list_builds_by_id(self, session): project = Project(name='ceph') Build(build_id=1, project=project, ref='master') Build(build_id=2, project=project, ref='master') Build(build_id=100, project=project, ref='master') commit() result = session.app.get('/builds/ceph/') assert result.namespace['builds'][0].build_id == '100' assert result.namespace['builds'][1].build_id == '2' assert result.namespace['builds'][2].build_id == '1'
def test_list_sha1s_by_id(self, session): project = Project(name='ceph') Build(build_id=1, project=project, ref='master', sha1='1234') Build(build_id=2, project=project, ref='master', sha1='1234') Build(build_id=100, project=project, ref='master', sha1='1234') commit() result = session.app.get('/builds/ceph/master/1234/') assert result.namespace['builds'][0].build_id == '100' assert result.namespace['builds'][1].build_id == '2' assert result.namespace['builds'][2].build_id == '1'
def test_repos_from_today(self, session): models.Repo(project=models.Project(name='ceph'), distro="ubuntu", distro_version="xenial", status="ready") models.commit() result = session.app.get('/') now = datetime.datetime.utcnow() today_str = now.strftime('%Y-%m-%d') assert "'ceph': 1" in result.namespace['area_data'] assert today_str in result.namespace['area_data']
def test_repos_from_today(self, session): models.Repo( project=models.Project(name='ceph'), distro="ubuntu", distro_version="xenial", status="ready") models.commit() result = session.app.get('/') now = datetime.datetime.utcnow() today_str = now.strftime('%Y-%m-%d') assert "'ceph': 1" in result.namespace['area_data'] assert today_str in result.namespace['area_data']
def get_next_node(): """ Retrieves the next chacra node in the rotation and returns it. """ nodes = models.Node.query.filter_by(healthy=True).order_by( asc(models.Node.last_used), ) for node in nodes: if is_node_healthy(node): node.last_used = datetime.datetime.utcnow() models.commit() logger.info("node: %s was chosen as the next in rotation", node.host) return node return None
def run(self, args): super(PopulateCommand, self).run(args) out("LOADING ENVIRONMENT") self.load_app() out("BUILDING SCHEMA") try: out("STARTING A TRANSACTION...") models.start() models.Base.metadata.create_all(conf.sqlalchemy_w.engine) except: models.rollback() out("ROLLING BACK... ") raise else: out("COMMITING... ") models.commit() out("STAMPING INITIAL STATE WITH ALEMBIC... ") alembic_cfg = Config(get_alembic_config()) command.stamp(alembic_cfg, "head")
def is_node_healthy(node, only_check=False): """ Pings the chacra node's health check endpoint to verify it is healthy and ready for use. If it fails the health, the node's ``down_count`` will be incremented. If the ``down_count`` reaches the value set for ``health_check_retries`` it will be marked down and removed from the pool. """ if not check_node_health(node): node.down_count = node.down_count + 1 logger.warning("node: %s has failed a health check. current count: %s", node.host, node.down_count) if node.down_count == getattr(conf, 'health_check_retries', 3): logger.warning("node: %s has reached the limit for health check retires and will marked down", node.host) node.healthy = False models.commit() return False # reset the down_count when the node is healthy node.down_count = 0 models.commit() return True
def test_no_builds_from_today(self, session): # create a build, no repos models.Build(project=models.Project(name='ceph'), status="ready") models.commit() result = session.app.get('/') assert "'ceph': 0" not in result.namespace['area_data']