Exemple #1
0
    def test_node(self):
        print("\n --- NODE TESTS ---")

        nodes = []
        nodes.append(slurm.Slurm.Node("034"))
        nodes.append(slurm.Slurm.Node(100))
        nodes.append(slurm.Slurm.Node("node123"))

        for n in nodes:
            self.assertTrue(n.__class__.__name__ == "Node")
        cp.printOK("OK : All nodes are Slurm.Node objects")

        for n in nodes:
            self.assertTrue(n.found or not n.data)
        cp.printOK(
            "OK : All nodes either found or (if not found) have no data")

        for n in nodes:
            if n.found:
                self.assertTrue(n.state and n.data)
        cp.printOK("OK : All found nodes have state and data attributes")

        for n in nodes:
            self.assertTrue(type(n.data) is dict)
        cp.printOK("OK : All nodes' data attribute are type dictionary")

        for n in nodes:
            self.assertTrue(n.name == slurm.Slurm.normalizeNodeName(n.name))
        cp.printOK("OK : All nodes' names are in normalized format")
Exemple #2
0
    def test_reservation(self):
        print("\n --- RESERVATION TESTS ---")

        reservations = slurm.Slurm.getReservations()

        self.assertTrue(reservations)
        cp.printOK("OK : List of reservations exists")

        for r in reservations:
            self.assertTrue(r.__class__.__name__ == "Reservation")
        cp.printOK("OK : All reservations are Slurm.Reservation objects")

        for r in reservations:
            self.assertTrue(r.name and r.nodes and r.state and r.data)
        cp.printOK(
            "OK : All reservations have name, nodes, state, and data attributes"
        )

        for r in reservations:
            for n in r.nodes:
                self.assertTrue(n == slurm.Slurm.normalizeNodeName(n))
        cp.printOK("OK : All reserved nodes are in normalized format")

        for r in reservations:
            self.assertTrue(type(r.data) is dict)
        cp.printOK("OK : All reservations' data attribute are type dictionary")
Exemple #3
0
    def test_state(self):
        print("\n --- STATE TESTS ---")

        states = slurm.Slurm.getNonEmptyStates()

        self.assertTrue(states)
        cp.printOK("OK : List of states exists")

        for s in states.values():
            self.assertTrue(s.__class__.__name__ == "State")
        cp.printOK("OK : All states are Slurm.State objects")

        for s in states.values():
            self.assertTrue(s.hasEntries())
        cp.printOK("OK : All states have entries")

        for s in states.values():
            for e in s.entries:
                self.assertTrue(e.__class__.__name__ == "Entry")
        cp.printOK("OK : All entries are Slurm.Entry objects")

        for s in states.values():
            for e in s.entries:
                self.assertTrue(e.nodes and e.time and e.reason)
        cp.printOK("OK : All entries have nodes, time, and reason attributes")
Exemple #4
0
def send_records():
  """ Uses modu.crypto to encrypt and send records pulled with the name and date cookies ; redirects to GET /hours """
  # TODO: test this ; not sure if it's going to be used
  #######################################################

  name = Cookies.get.name(bottle.request)
  date = Cookies.get.date(bottle.request)
  
  confirm = (bottle.request.forms.get('confirm') == "true")
  
  # will use form-supplied values but defaults to values read from config file
  address = bottle.request.forms.get('address').strip() or ENV.LOGGING_SERVER_ADDRESS
  port = bottle.request.forms.get('port').strip() or ENV.LOGGING_SERVER_PORT
  
  #######################################################
  
  if all((confirm, name, address, port)):
        
    # parse records from file
    records = recorder.parseRecordsFromFile(name, date)
    
    # turn records into a '\n'-separated string
    recordString = '\n'.join([r.emailFormat() for r in records])
    
    # if in debug mode and about to send records, display info
    if ENV.DEBUG:
      cp.printOk("SENDING TO: {0}:{1}".format(address, port))
      cp.printOK("-- RECORDS --\n{records}".format(records=recordString))
    
    try:
      # encrypt and encode recordString
      encryptedRecords = crypto.getEncodedString(recordString)
      
      address = "/".join(bottle.request.url.split("/")[:-1]) + "/ack"
      
      # encrypts and encodes host address for rerouting back to hours
      encryptedAddress = crypto.getEncodedString(address)
      
      # send name, date, and encoded records to receiving server
      bottle.redirect('http://{address}:{port}/receive?n={name}&d={date}&r={encryptedRecords}&a={encryptedAddress}'
        .format(address=address, port=port,
                name=name, date=date,
                encryptedRecords=encryptedRecords, encryptedAddress=encryptedAddress))
    
    # thrown if config/crypto not found
    # TODO: is this error too specific or even accurate?
    except TypeError as e:
      cp.printFail(e)

  bottle.redirect('hours')
Exemple #5
0
  cp.printHeader(border)

######################################

print("APP RUNNING FROM : {project_dir}".format(project_dir=ENV.ROOT))
print("HOST ADDRESS     : {hostAddress}".format(hostAddress=ENV.HOST))
print("HOST PORT        : {hostPort}".format(hostPort=ENV.PORT))

sender = "SMTP SENDER      : {senderStr}".format(senderStr=ENV.SENDER)
receivers = "SMTP RECEIVERS   : {receiversStr}".format(receiversStr=", ".join(ENV.RECEIVERS))
debug = "DEBUG            : {devMode}".format(devMode=ENV.DEBUG)
reloader = "LIVE RELOAD      : {liveReload}".format(liveReload=ENV.RELOAD)

# True -> print ; False -> cp.printWarn
print(sender) if ENV.SENDER else cp.printWarn(sender)
print(receivers) if ENV.RECEIVERS else cp.printWarn(receivers)

# True -> cp.printOk ; False -> print
cp.printOK(debug) if ENV.DEBUG else print(debug)
cp.printOK(reloader) if ENV.RELOAD else print(reloader)

cp.printHeader(border)

######################################

app.run(host=ENV.HOST, port=ENV.PORT, debug=ENV.DEBUG, reloader=ENV.RELOAD)

########################################################################################################
########################################################################################################
########################################################################################################