def add_service(sess, name): ''' reusable add service code for other tests ''' svc = sess.query(Service).filter_by(name=name).first() if not svc: svc = Service(name=name) create(sess, svc) return svc
def render(self, session, logger, service, instance, comments, **arguments): dbservice = session.query(Service).filter_by(name=service).first() if dbservice and instance is None: raise ArgumentError("Service %s already exists." % dbservice.name) if not dbservice: # "add_service --service foo --comments blah" should add the comments # to Service, # "add_service --service foo --instance bar --comments blah" should # add the comments to ServiceInstance if instance: srvcomments = None else: srvcomments = comments dbservice = Service(name=service, comments=srvcomments) session.add(dbservice) plenaries = PlenaryCollection(logger=logger) plenaries.append(Plenary.get_plenary(dbservice)) if instance: ServiceInstance.get_unique(session, service=dbservice, name=instance, preclude=True) dbsi = ServiceInstance(service=dbservice, name=instance, comments=comments) session.add(dbsi) plenaries.append(Plenary.get_plenary(dbsi)) session.flush() plenaries.write() return