Fix PEP8 issues
Change-Id: I6cfebccba269c21e752307966093cfb216b81c2c
This commit is contained in:
parent
cf0635f306
commit
ae3df717de
16
createDB.py
16
createDB.py
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Create the MoltenIron user in mysql and grant it access.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,16 +19,20 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
|
||||
def SQL(query):
|
||||
print(os.popen("mysql -u root -p --execute=\"" + query + "\"").read())
|
||||
"""Perform a mysql command"""
|
||||
print os.popen("mysql -u root -p --execute=\"" + query + "\"").read()
|
||||
|
||||
|
||||
def main():
|
||||
"""The main routine"""
|
||||
path = sys.argv[0]
|
||||
dirs = path.split("/")
|
||||
newPath = "/".join(dirs[:-1]) + "/"
|
||||
|
@ -32,9 +40,9 @@ def main():
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
# Create the SQL User
|
||||
SQL("CREATE USER '"+conf["sqlUser"]+"'@'localhost' "
|
||||
"IDENTIFIED BY '"+conf["sqlPass"]+"';")
|
||||
SQL("GRANT ALL ON MoltenIron.* TO '"+conf["sqlUser"]+"'@'localhost';")
|
||||
SQL("CREATE USER '" + conf["sqlUser"] + "'@'localhost' "
|
||||
"IDENTIFIED BY '" + conf["sqlPass"] + "';")
|
||||
SQL("GRANT ALL ON MoltenIron.* TO '" + conf["sqlUser"] + "'@'localhost';")
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
"""
|
||||
This is the MoltenIron Command Line client that speaks to
|
||||
a MoltenIron server.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,21 +20,26 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
import argparse
|
||||
import httplib
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
import argparse
|
||||
|
||||
DEBUG = False
|
||||
|
||||
|
||||
# Create a decorator pattern that maintains a registry
|
||||
def makeRegistrar():
|
||||
"""Decorator that keeps track of tagged functions."""
|
||||
registry = {}
|
||||
|
||||
def registrar(func):
|
||||
"""Store the function pointer."""
|
||||
registry[func.__name__] = func
|
||||
# normally a decorator returns a wrapped function,
|
||||
# but here we return func unmodified, after registering it
|
||||
|
@ -42,6 +52,7 @@ command = makeRegistrar()
|
|||
|
||||
|
||||
class MoltenIron(object):
|
||||
"""This is the MoltenIron client object."""
|
||||
|
||||
def __init__(self):
|
||||
self.conf = None
|
||||
|
@ -51,15 +62,17 @@ class MoltenIron(object):
|
|||
self.response_str = None
|
||||
self.response_json = None
|
||||
|
||||
def setup_conf(self, conf):
|
||||
""" """
|
||||
self.conf = conf
|
||||
def setup_conf(self, _conf):
|
||||
"""Sets the class variable to what is passed in. """
|
||||
self.conf = _conf
|
||||
|
||||
def setup_argv(self, argv):
|
||||
self.argv = argv
|
||||
def setup_argv(self, _argv):
|
||||
"""Sets the class variable to what is passed in. """
|
||||
self.argv = _argv
|
||||
|
||||
def setup_parser(self, parser):
|
||||
self.parser = parser
|
||||
def setup_parser(self, _parser):
|
||||
"""Sets the class variable to what is passed in. """
|
||||
self.parser = _parser
|
||||
|
||||
def _setup_response(self):
|
||||
""" """
|
||||
|
@ -96,7 +109,7 @@ class MoltenIron(object):
|
|||
return self.response_json
|
||||
|
||||
@command
|
||||
def add(self, subparsers = None):
|
||||
def add(self, subparsers=None):
|
||||
"""Generate a request to add a node to the MoltenIron database """
|
||||
if subparsers is not None:
|
||||
sp = subparsers.add_parser("add")
|
||||
|
@ -145,7 +158,7 @@ class MoltenIron(object):
|
|||
return request
|
||||
|
||||
@command
|
||||
def allocate(self, subparsers = None):
|
||||
def allocate(self, subparsers=None):
|
||||
"""Generate request to checkout a node from the MoltenIron database """
|
||||
if subparsers is not None:
|
||||
sp = subparsers.add_parser("allocate")
|
||||
|
@ -170,7 +183,7 @@ class MoltenIron(object):
|
|||
return request
|
||||
|
||||
@command
|
||||
def release(self, subparsers = None):
|
||||
def release(self, subparsers=None):
|
||||
"""Generate a request to release an allocated node from the MoltenIron
|
||||
database
|
||||
"""
|
||||
|
@ -195,7 +208,7 @@ class MoltenIron(object):
|
|||
return request
|
||||
|
||||
@command
|
||||
def get_field(self, subparsers = None):
|
||||
def get_field(self, subparsers=None):
|
||||
"""Generate a request to return a field of data from an owned node from
|
||||
the MoltenIron database
|
||||
"""
|
||||
|
@ -223,7 +236,7 @@ class MoltenIron(object):
|
|||
return request
|
||||
|
||||
@command
|
||||
def set_field(self, subparsers = None):
|
||||
def set_field(self, subparsers=None):
|
||||
"""Generate request to set a field of data from an id in the MoltenIron
|
||||
database
|
||||
"""
|
||||
|
@ -250,7 +263,7 @@ class MoltenIron(object):
|
|||
return request
|
||||
|
||||
@command
|
||||
def status(self, subparsers = None):
|
||||
def status(self, subparsers=None):
|
||||
"""Return status """
|
||||
if subparsers is not None:
|
||||
sp = subparsers.add_parser("status")
|
||||
|
@ -270,7 +283,7 @@ class MoltenIron(object):
|
|||
return request
|
||||
|
||||
@command
|
||||
def delete_db(self, subparsers = None):
|
||||
def delete_db(self, subparsers=None):
|
||||
"""Delete all database entries"""
|
||||
if subparsers is not None:
|
||||
sp = subparsers.add_parser("delete_db")
|
||||
|
@ -291,7 +304,7 @@ class MoltenIron(object):
|
|||
if __name__ == "__main__":
|
||||
mi = MoltenIron()
|
||||
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -305,12 +318,12 @@ if __name__ == "__main__":
|
|||
# is running
|
||||
for (cmd_name, cmd_func) in command.all.items():
|
||||
func = getattr(mi, cmd_name)
|
||||
func (subparsers) # Tell the function to setup for argparse
|
||||
func(subparsers) # Tell the function to setup for argparse
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -326,12 +339,12 @@ if __name__ == "__main__":
|
|||
mi.setup_argv(args)
|
||||
mi.setup_parser(parser)
|
||||
|
||||
print(mi.get_response())
|
||||
print mi.get_response()
|
||||
|
||||
try:
|
||||
rc = mi.get_response_map()['status']
|
||||
except KeyError:
|
||||
print("Error: Server returned: %s" % (mi.get_response_map(),))
|
||||
print "Error: Server returned: %s" % (mi.get_response_map(),)
|
||||
rc = 444
|
||||
|
||||
if rc == 200:
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This is a helper program for the MoltenIron server.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,6 +19,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import os
|
||||
|
@ -27,16 +34,22 @@ PID = "/var/run/moltenirond.pid"
|
|||
YAML_CONF = "/usr/local/etc/molteniron/conf.yaml"
|
||||
ERROR_LOGFILE = "/tmp/MoltenIron-error-logfile"
|
||||
|
||||
|
||||
class MoltenIronPIDNotFound(RuntimeError):
|
||||
"""os.path.isfile() error: The PID file does not exist"""
|
||||
|
||||
|
||||
class MoltenIronKillError(RuntimeError):
|
||||
"""os.kill() error"""
|
||||
|
||||
|
||||
class MoltenIronReadLinesError(RuntimeError):
|
||||
"""fobj.readlines() error"""
|
||||
|
||||
|
||||
def get_moltenirond_pid():
|
||||
"""Return the PID of the MoltenIron server process."""
|
||||
|
||||
if not os.path.isfile(PID):
|
||||
raise MoltenIronPIDNotFound("isfile error %s" % (PID, ))
|
||||
|
||||
|
@ -55,17 +68,24 @@ def get_moltenirond_pid():
|
|||
except Exception as e:
|
||||
raise MoltenIronReadLinesError("readlines error: %s" % (e, ))
|
||||
|
||||
|
||||
def moltenirond_main():
|
||||
"""This is the main routine for the MoltenIron server."""
|
||||
|
||||
with open(YAML_CONF, "r") as fobj:
|
||||
conf = yaml.load(fobj)
|
||||
|
||||
moltenirond.listener(conf)
|
||||
|
||||
|
||||
def log_error(s):
|
||||
"""Log an error to stderr and to a file."""
|
||||
|
||||
with open(ERROR_LOGFILE, "a+") as fobj:
|
||||
fobj.writelines(s + "\n")
|
||||
print >> sys.stderr, s
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(description="Molteniron daemon helper")
|
||||
|
@ -89,10 +109,10 @@ if __name__ == "__main__":
|
|||
help="Set a verbose information mode")
|
||||
parser.add_argument("command", type=str, nargs=1, help="the command")
|
||||
|
||||
args = parser.parse_args ()
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -100,7 +120,7 @@ if __name__ == "__main__":
|
|||
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
|
||||
|
||||
if args.pid_dir:
|
||||
if not os.path.isdir (args.pid_dir):
|
||||
if not os.path.isdir(args.pid_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.pid_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -114,35 +134,37 @@ if __name__ == "__main__":
|
|||
if len(args.command) != 1:
|
||||
msg = "Error: Expecting one command? Received: %s" % (args.command, )
|
||||
log_error(msg)
|
||||
sys.exit (1)
|
||||
sys.exit(1)
|
||||
|
||||
if args.command[0].upper().lower() == "start":
|
||||
try:
|
||||
pid = get_moltenirond_pid()
|
||||
except MoltenIronPIDNotFound:
|
||||
pid = -1
|
||||
|
||||
if pid > 0:
|
||||
log_error("Error: The daemon is already running")
|
||||
sys.exit(1)
|
||||
|
||||
daemon = Daemonize(app="moltenirond",
|
||||
pid=PID,
|
||||
action=moltenirond_main)
|
||||
|
||||
daemon.start()
|
||||
elif args.command[0].upper().lower() == "stop":
|
||||
try:
|
||||
pid = get_moltenirond_pid()
|
||||
if pid > 0:
|
||||
os.remove (PID)
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
else:
|
||||
log_error("Error: The daemon doesn't exist?")
|
||||
log_error("Error: pid = %d" % (pid, ))
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
except MoltenIronPIDNotFound:
|
||||
pid = -1
|
||||
|
||||
if pid > 0:
|
||||
os.remove(PID)
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
else:
|
||||
log_error("Error: The daemon doesn't exist?")
|
||||
log_error("Error: %s" % (e, ))
|
||||
log_error("Error: pid = %d" % (pid, ))
|
||||
sys.exit(1)
|
||||
else:
|
||||
msg = "Error: Unknown command: %s" % (args.command[0], )
|
||||
log_error(msg)
|
||||
sys.exit (1)
|
||||
sys.exit(1)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This is the MoltenIron server.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,6 +19,14 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# flake8 disabling E242
|
||||
# https://pep8.readthedocs.io/en/latest/intro.html
|
||||
# https://gitlab.com/pycqa/flake8/issues/63
|
||||
# Gah!
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
# pylint: disable=redefined-outer-name
|
||||
|
||||
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
|
||||
import calendar
|
||||
from datetime import datetime
|
||||
|
@ -46,7 +58,9 @@ metadata = MetaData()
|
|||
|
||||
|
||||
class JSON_encoder_with_DateTime(json.JSONEncoder):
|
||||
"""Special class to allow json to encode datetime objects"""
|
||||
def default(self, o):
|
||||
"""Override default"""
|
||||
if isinstance(o, datetime):
|
||||
return o.isoformat()
|
||||
|
||||
|
@ -59,29 +73,36 @@ class JSON_encoder_with_DateTime(json.JSONEncoder):
|
|||
# http://stackoverflow.com/questions/1713038/super-fails-with-error-typeerror-
|
||||
# argument-1-must-be-type-not-classobj
|
||||
class OBaseHTTPRequestHandler(BaseHTTPRequestHandler, object):
|
||||
"""Converts BaseHTTPRequestHandler into a new-style class"""
|
||||
pass
|
||||
|
||||
|
||||
# We need to pass in conf into MoltenIronHandler, so make a class factory
|
||||
# to do that
|
||||
# NOTE: URL is over two lines :(
|
||||
# http://stackoverflow.com/questions/21631799/how-can-i-pass-parameters-to-a-
|
||||
# requesthandler
|
||||
def MakeMoltenIronHandlerWithConf(conf):
|
||||
"""Allows passing in conf to MoltenIronHandler,"""
|
||||
class MoltenIronHandler(OBaseHTTPRequestHandler):
|
||||
"""HTTP handler class"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Note this *needs* to be done before call to super's class!
|
||||
self.conf = conf
|
||||
self.data_string = None
|
||||
super(OBaseHTTPRequestHandler, self).__init__(*args, **kwargs)
|
||||
|
||||
def do_POST(self):
|
||||
"""HTTP POST support"""
|
||||
CL = 'Content-Length'
|
||||
self.data_string = self.rfile.read(int(self.headers[CL]))
|
||||
response = self.parse(self.data_string)
|
||||
self.send_reply(response)
|
||||
|
||||
def send_reply(self, response):
|
||||
"""Sends the HTTP reply"""
|
||||
if DEBUG:
|
||||
print("send_reply: response = %s" % (response,))
|
||||
print "send_reply: response = %s" % (response,)
|
||||
# get the status code off the response json and send it
|
||||
status_code = response['status']
|
||||
self.send_response(status_code)
|
||||
|
@ -121,7 +142,7 @@ def MakeMoltenIronHandlerWithConf(conf):
|
|||
response = {'status': 400, 'message': str(e)}
|
||||
|
||||
if DEBUG:
|
||||
print("parse: response = %s" % (response,))
|
||||
print "parse: response = %s" % (response,)
|
||||
|
||||
return response
|
||||
|
||||
|
@ -129,6 +150,7 @@ def MakeMoltenIronHandlerWithConf(conf):
|
|||
|
||||
|
||||
class Nodes(declarative_base()):
|
||||
"""Nodes database class"""
|
||||
|
||||
__tablename__ = 'Nodes'
|
||||
|
||||
|
@ -182,6 +204,7 @@ class Nodes(declarative_base()):
|
|||
timestamp)
|
||||
|
||||
def map(self):
|
||||
"""Returns a map of the database row contents"""
|
||||
return {key: value for key, value
|
||||
in self.__dict__.items()
|
||||
if not key.startswith('_') and not callable(key)}
|
||||
|
@ -216,6 +239,7 @@ timestamp='%s'/>"""
|
|||
|
||||
|
||||
class IPs(declarative_base()):
|
||||
"""IPs database class"""
|
||||
|
||||
__tablename__ = 'IPs'
|
||||
|
||||
|
@ -291,25 +315,26 @@ class DataBase():
|
|||
self.element_info = [
|
||||
# The following are returned from the query call
|
||||
|
||||
# field_name length special_fmt skip
|
||||
("id", 4, int, False),
|
||||
("name", 6, str, False),
|
||||
("ipmi_ip", 9, str, False),
|
||||
("ipmi_user", 11, str, False),
|
||||
("ipmi_password", 15, str, False),
|
||||
("port_hwaddr", 19, str, False),
|
||||
("cpu_arch", 10, str, False),
|
||||
("cpus", 6, int, False),
|
||||
("ram_mb", 8, int, False),
|
||||
("disk_gb", 9, int, False),
|
||||
("status", 8, str, False),
|
||||
("provisioned", 13, str, False),
|
||||
# field_name length special_fmt skip
|
||||
("id", 4, int, False),
|
||||
("name", 6, str, False),
|
||||
("ipmi_ip", 9, str, False),
|
||||
("ipmi_user", 11, str, False),
|
||||
("ipmi_password", 15, str, False),
|
||||
("port_hwaddr", 19, str, False),
|
||||
("cpu_arch", 10, str, False),
|
||||
("cpus", 6, int, False),
|
||||
("ram_mb", 8, int, False),
|
||||
("disk_gb", 9, int, False),
|
||||
("status", 8, str, False),
|
||||
("provisioned", 13, str, False),
|
||||
# We add timeString
|
||||
("time", 14, float, False),
|
||||
("time", 14, float, False),
|
||||
]
|
||||
self.setup_status()
|
||||
|
||||
def create_engine(self):
|
||||
"""Create the sqlalchemy database engine"""
|
||||
engine = None
|
||||
|
||||
if self.db_type == TYPE_MYSQL:
|
||||
|
@ -333,11 +358,12 @@ class DataBase():
|
|||
return engine
|
||||
|
||||
def close(self):
|
||||
"""Close the sqlalchemy database engine"""
|
||||
if DEBUG:
|
||||
print("close: Calling engine.dispose()")
|
||||
print "close: Calling engine.dispose()"
|
||||
self.engine.dispose()
|
||||
if DEBUG:
|
||||
print("close: Finished")
|
||||
print "close: Finished"
|
||||
|
||||
def get_session(self):
|
||||
"""Get a SQL academy session from the pool """
|
||||
|
@ -376,12 +402,13 @@ class DataBase():
|
|||
yield conn
|
||||
except Exception as e:
|
||||
if DEBUG:
|
||||
print("Exception caught in connection_scope: %s" % (e,))
|
||||
print "Exception caught in connection_scope: %s" % (e,)
|
||||
raise
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def delete_db(self):
|
||||
"""Delete the sqlalchemy database"""
|
||||
# Instead of:
|
||||
# IPs.__table__.drop(self.engine, checkfirst=True)
|
||||
# Nodes.__table__.drop(self.engine, checkfirst=True)
|
||||
|
@ -390,16 +417,18 @@ class DataBase():
|
|||
return {'status': 200}
|
||||
|
||||
def create_metadata(self):
|
||||
"""Create the sqlalchemy database metadata"""
|
||||
# Instead of:
|
||||
# Nodes.__table__.create(self.engine, checkfirst=True)
|
||||
# IPs.__table__.create(self.engine, checkfirst=True)
|
||||
if DEBUG:
|
||||
print("create_metadata: Calling metadata.create_all")
|
||||
print "create_metadata: Calling metadata.create_all"
|
||||
metadata.create_all(self.engine, checkfirst=True)
|
||||
if DEBUG:
|
||||
print("create_metadata: Finished")
|
||||
print "create_metadata: Finished"
|
||||
|
||||
def to_timestamp(self, ts):
|
||||
"""Convert from a database time stamp to a Python time stamp"""
|
||||
timestamp = None
|
||||
if self.db_type == TYPE_MYSQL:
|
||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S", ts)
|
||||
|
@ -409,6 +438,7 @@ class DataBase():
|
|||
return timestamp
|
||||
|
||||
def from_timestamp(self, timestamp):
|
||||
"""Convert from a Python time stamp to a database time stamp"""
|
||||
ts = None
|
||||
if self.db_type == TYPE_MYSQL:
|
||||
ts = time.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
|
||||
|
@ -421,13 +451,13 @@ class DataBase():
|
|||
|
||||
try:
|
||||
with self.session_scope() as session, \
|
||||
self.connection_scope() as conn:
|
||||
self.connection_scope() as conn:
|
||||
|
||||
# Get a list of IDs for nodes that are free
|
||||
count = session.query(Nodes).filter_by(status="ready").count()
|
||||
|
||||
# If we don't have enough nodes return an error
|
||||
if (count < how_many):
|
||||
if count < how_many:
|
||||
fmt = "Not enough available nodes found."
|
||||
fmt += " Found %d, requested %d"
|
||||
return {'status': 404,
|
||||
|
@ -435,22 +465,23 @@ class DataBase():
|
|||
|
||||
nodes_allocated = {}
|
||||
|
||||
for i in range(how_many):
|
||||
for _ in range(how_many):
|
||||
first_ready = session.query(Nodes)
|
||||
first_ready = first_ready.filter_by(status="ready")
|
||||
first_ready = first_ready.first()
|
||||
|
||||
id = first_ready.id
|
||||
node_id = first_ready.id
|
||||
# We have everything we need from node
|
||||
|
||||
log(self.conf,
|
||||
"allocating node id: %d for %s" % (id, owner_name, ))
|
||||
"allocating node id: %d for %s" % (node_id,
|
||||
owner_name, ))
|
||||
|
||||
timestamp = self.to_timestamp(time.gmtime())
|
||||
|
||||
# Update the node to the in use state
|
||||
stmt = update(Nodes)
|
||||
stmt = stmt.where(Nodes.id == id)
|
||||
stmt = stmt.where(Nodes.id == node_id)
|
||||
stmt = stmt.values(status="dirty",
|
||||
provisioned=owner_name,
|
||||
timestamp=timestamp)
|
||||
|
@ -460,7 +491,8 @@ class DataBase():
|
|||
session.close()
|
||||
session = self.get_session()
|
||||
|
||||
first_ready = session.query(Nodes).filter_by(id=id).one()
|
||||
first_ready = session.query(Nodes).filter_by(id=node_id)
|
||||
first_ready = first_ready.one()
|
||||
|
||||
first_ready_node = first_ready.map()
|
||||
|
||||
|
@ -474,19 +506,19 @@ class DataBase():
|
|||
= ','.join(allocation_pool)
|
||||
|
||||
# Add the node to the nodes dict
|
||||
nodes_allocated['node_%d' % (id, )] = first_ready_node
|
||||
nodes_allocated['node_%d' % (node_id, )] = first_ready_node
|
||||
|
||||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in deallocateBM: %s" % (e,))
|
||||
print "Exception caught in deallocateBM: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
||||
return {'status': 200, 'nodes': nodes_allocated}
|
||||
|
||||
def deallocateBM(self, id):
|
||||
def deallocateBM(self, node_id):
|
||||
"""Given the ID of a node (or the IPMI IP), de-allocate that node.
|
||||
|
||||
This changes the node status of that node from "used" to "ready."
|
||||
|
@ -494,15 +526,17 @@ class DataBase():
|
|||
|
||||
try:
|
||||
with self.session_scope() as session, \
|
||||
self.connection_scope() as conn:
|
||||
self.connection_scope() as conn:
|
||||
|
||||
query = session.query(Nodes.id, Nodes.ipmi_ip, Nodes.name)
|
||||
|
||||
if (type(id) == str or type(id) == unicode) and ("." in id):
|
||||
if (isinstance(node_id, str) or
|
||||
isinstance(node_id, unicode)) \
|
||||
and ("." in node_id):
|
||||
# If an ipmi_ip was passed
|
||||
query = query.filter_by(ipmi_ip=id)
|
||||
query = query.filter_by(ipmi_ip=node_id)
|
||||
else:
|
||||
query = query.filter_by(id=id)
|
||||
query = query.filter_by(id=node_id)
|
||||
|
||||
node = query.one()
|
||||
|
||||
|
@ -520,7 +554,7 @@ class DataBase():
|
|||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in deallocateBM: %s" % (e,))
|
||||
print "Exception caught in deallocateBM: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
@ -544,7 +578,7 @@ class DataBase():
|
|||
self.deallocateBM(node.id)
|
||||
except Exception as e:
|
||||
if DEBUG:
|
||||
print("Exception caught in deallocateOwner: %s" % (e,))
|
||||
print "Exception caught in deallocateOwner: %s" % (e,)
|
||||
message = "Failed to deallocate node with ID %d" % (node.id,)
|
||||
return {'status': 400, 'message': message}
|
||||
|
||||
|
@ -568,7 +602,7 @@ class DataBase():
|
|||
|
||||
try:
|
||||
if DEBUG:
|
||||
print("addBMNode: node = %s" % (node, ))
|
||||
print "addBMNode: node = %s" % (node, )
|
||||
|
||||
with self.session_scope() as session, \
|
||||
self.connection_scope() as conn:
|
||||
|
@ -604,15 +638,15 @@ class DataBase():
|
|||
if 'timestamp' in node:
|
||||
timestamp_str = node['timestamp']
|
||||
if DEBUG:
|
||||
print("timestamp_str = %s" % (timestamp_str, ))
|
||||
print "timestamp_str = %s" % (timestamp_str, )
|
||||
if len(timestamp_str) != 0 and timestamp_str != "-1":
|
||||
ts = time.gmtime(float(timestamp_str))
|
||||
timestamp = self.to_timestamp(ts)
|
||||
if DEBUG:
|
||||
print("timestamp = %s" % (timestamp, ))
|
||||
print "timestamp = %s" % (timestamp, )
|
||||
stmt = stmt.values(timestamp=timestamp)
|
||||
if DEBUG:
|
||||
print(stmt.compile().params)
|
||||
print stmt.compile().params
|
||||
|
||||
conn.execute(stmt)
|
||||
|
||||
|
@ -633,14 +667,14 @@ class DataBase():
|
|||
stmt = stmt.values(node_id=new_node.id, ip=ip)
|
||||
|
||||
if DEBUG:
|
||||
print(stmt.compile().params)
|
||||
print stmt.compile().params
|
||||
|
||||
conn.execute(stmt)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in addBMNode: %s" % (e,))
|
||||
print "Exception caught in addBMNode: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
@ -656,7 +690,7 @@ class DataBase():
|
|||
|
||||
try:
|
||||
with self.session_scope() as session, \
|
||||
self.connection_scope() as conn:
|
||||
self.connection_scope() as conn:
|
||||
|
||||
query = session.query(Nodes.id, Nodes.ipmi_ip, Nodes.name)
|
||||
query = query.filter_by(id=int(ID))
|
||||
|
@ -685,7 +719,7 @@ class DataBase():
|
|||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in removeBMNode: %s" % (e,))
|
||||
print "Exception caught in removeBMNode: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
@ -701,7 +735,7 @@ class DataBase():
|
|||
"""
|
||||
|
||||
if DEBUG:
|
||||
print("cull: maxSeconds = %s" % (maxSeconds, ))
|
||||
print "cull: maxSeconds = %s" % (maxSeconds, )
|
||||
|
||||
nodes_culled = {}
|
||||
|
||||
|
@ -711,12 +745,12 @@ class DataBase():
|
|||
nodes = session.query(Nodes)
|
||||
|
||||
if DEBUG:
|
||||
print("There are %d nodes" % (nodes.count(), ))
|
||||
print "There are %d nodes" % (nodes.count(), )
|
||||
|
||||
for node in nodes:
|
||||
|
||||
if DEBUG:
|
||||
print(node)
|
||||
print node
|
||||
|
||||
if node.timestamp in ('', '-1', None):
|
||||
continue
|
||||
|
@ -741,7 +775,7 @@ class DataBase():
|
|||
log(self.conf, logstring)
|
||||
|
||||
if DEBUG:
|
||||
print(logstring)
|
||||
print logstring
|
||||
|
||||
self.deallocateBM(node.id)
|
||||
|
||||
|
@ -751,7 +785,7 @@ class DataBase():
|
|||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in cull: %s" % (e,))
|
||||
print "Exception caught in cull: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
@ -763,7 +797,7 @@ class DataBase():
|
|||
|
||||
try:
|
||||
with self.session_scope() as session, \
|
||||
self.connection_scope() as conn:
|
||||
self.connection_scope() as conn:
|
||||
|
||||
query = session.query(Nodes)
|
||||
query = query.filter_by(id=node_id)
|
||||
|
@ -772,7 +806,7 @@ class DataBase():
|
|||
if node.status in ('ready', ''):
|
||||
return {'status': 400,
|
||||
'message': 'The node at %d has status %s'
|
||||
% (node.id, node.status,)}
|
||||
% (node.id, node.status,)}
|
||||
|
||||
logstring = "The node at %s has been cleaned." % \
|
||||
(node.ipmi_ip,)
|
||||
|
@ -787,7 +821,7 @@ class DataBase():
|
|||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in doClean: %s" % (e,))
|
||||
print "Exception caught in doClean: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
@ -815,7 +849,7 @@ class DataBase():
|
|||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in get_ips: %s" % (e,))
|
||||
print "Exception caught in get_ips: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
@ -855,14 +889,14 @@ class DataBase():
|
|||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in get_field: %s" % (e,))
|
||||
print "Exception caught in get_field: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
||||
return {'status': 200, 'result': results}
|
||||
|
||||
def set_field(self, id, key, value):
|
||||
def set_field(self, node_id, key, value):
|
||||
"""Given an identifying id, set specified key to the passed value. """
|
||||
|
||||
if not hasattr(Nodes, key):
|
||||
|
@ -871,22 +905,22 @@ class DataBase():
|
|||
|
||||
try:
|
||||
with self.session_scope() as session, \
|
||||
self.connection_scope() as conn:
|
||||
self.connection_scope() as conn:
|
||||
|
||||
query = session.query(Nodes)
|
||||
nodes = query.filter_by(id=id)
|
||||
nodes = query.filter_by(id=node_id)
|
||||
|
||||
if nodes.count() == 0:
|
||||
return {'status': 404,
|
||||
'message': 'Node with id of %s does not exist!'
|
||||
% id}
|
||||
% node_id}
|
||||
|
||||
nodes.one()
|
||||
|
||||
kv = {key: value}
|
||||
|
||||
stmt = update(Nodes)
|
||||
stmt = stmt.where(Nodes.id == id)
|
||||
stmt = stmt.where(Nodes.id == node_id)
|
||||
stmt = stmt.values(**kv)
|
||||
|
||||
conn.execute(stmt)
|
||||
|
@ -894,7 +928,7 @@ class DataBase():
|
|||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in set_field: %s" % (e,))
|
||||
print "Exception caught in set_field: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
@ -991,7 +1025,7 @@ class DataBase():
|
|||
except Exception as e:
|
||||
|
||||
if DEBUG:
|
||||
print("Exception caught in status: %s" % (e,))
|
||||
print "Exception caught in status: %s" % (e,)
|
||||
|
||||
# Don't send the exception object as it is not json serializable!
|
||||
return {'status': 400, 'message': str(e)}
|
||||
|
@ -1000,10 +1034,11 @@ class DataBase():
|
|||
|
||||
|
||||
def listener(conf):
|
||||
"""HTTP listener"""
|
||||
mi_addr = str(conf['serverIP'])
|
||||
mi_port = int(conf['mi_port'])
|
||||
handler_class = MakeMoltenIronHandlerWithConf(conf)
|
||||
print('Listening... to %s:%d' % (mi_addr, mi_port,))
|
||||
print 'Listening... to %s:%d' % (mi_addr, mi_port,)
|
||||
moltenirond = HTTPServer((mi_addr, mi_port), handler_class)
|
||||
moltenirond.serve_forever()
|
||||
|
||||
|
@ -1041,27 +1076,15 @@ def log(conf, message):
|
|||
logdir = conf["logdir"]
|
||||
now = datetime.today()
|
||||
|
||||
fname = ( "molteniron-"
|
||||
+ str(now.day)
|
||||
+ "-"
|
||||
+ str(now.month)
|
||||
+ "-"
|
||||
+ str(now.year)
|
||||
+ ".log"
|
||||
)
|
||||
fname = "molteniron-%d-%d-%d.log" % (now.day,
|
||||
now.month,
|
||||
now.year, )
|
||||
|
||||
timestamp = ( "{0:0>2}".format(str(now.hour))
|
||||
+ ":"
|
||||
+ "{0:0>2}".format(str(now.minute))
|
||||
+ ":"
|
||||
+ "{0:0>2}".format(str(now.second))
|
||||
)
|
||||
timestamp = "{0:0>2}".format(str(now.hour))
|
||||
timestamp += ":{0:0>2}".format(str(now.minute))
|
||||
timestamp += ":{0:0>2}".format(str(now.second))
|
||||
|
||||
message = ( timestamp
|
||||
+ " "
|
||||
+ message
|
||||
+ "\n"
|
||||
)
|
||||
message = timestamp + " " + message + "\n"
|
||||
|
||||
# check if logdir exists, if not create it
|
||||
if not os.path.isdir(logdir):
|
||||
|
@ -1102,10 +1125,10 @@ if __name__ == "__main__":
|
|||
dest="conf_dir",
|
||||
help="The directory where configuration is stored")
|
||||
|
||||
args = parser.parse_args ()
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
|
7
setup.py
7
setup.py
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Install the molteniron python package.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -23,5 +27,4 @@ setup(name="molteniron",
|
|||
url="https://github.com/openstack/third-party-ci-tools",
|
||||
py_modules=["molteniron/__init__", "molteniron/moltenirond"],
|
||||
scripts=["molteniron/moltenirond-helper", "molteniron/molteniron"],
|
||||
data_files=[("etc/molteniron/", ["conf.yaml"])]
|
||||
)
|
||||
data_files=[("etc/molteniron/", ["conf.yaml"])])
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Tests the addBMNode MoltenIron command.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,6 +19,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
|
@ -22,7 +28,7 @@ import argparse
|
|||
from molteniron import moltenirond
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -33,7 +39,7 @@ if __name__ == "__main__":
|
|||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -46,88 +52,88 @@ if __name__ == "__main__":
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
node1 = {
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "2f024600fc5ef6f7",
|
||||
"port_hwaddr": "97:c3:b0:47:0c:0d",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "2f024600fc5ef6f7",
|
||||
"port_hwaddr": "97: c3:b0: 47:0c:0d",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.10,10.228.112.11"
|
||||
}
|
||||
node2 = {
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "6cf0957c985b2deb",
|
||||
"port_hwaddr": "2d:9e:3c:83:8a:be",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "6cf0957c985b2deb",
|
||||
"port_hwaddr": "2d: 9e:3c:83:8a: be",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.8,10.228.112.9"
|
||||
}
|
||||
node3 = {
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "cc777c10196db585",
|
||||
"port_hwaddr": "47:b0:dc:d5:82:d9",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "cc777c10196db585",
|
||||
"port_hwaddr": "47: b0:dc:d5: 82:d9",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"allocation_pool": "10.228.112.12,10.228.112.13"
|
||||
}
|
||||
node4 = {
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "a700a2d789075276",
|
||||
"port_hwaddr": "44:94:1a:c7:8a:9f",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "a700a2d789075276",
|
||||
"port_hwaddr": "44: 94:1a: c7:8a:9f",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"allocation_pool": "10.228.112.14,10.228.112.15"
|
||||
}
|
||||
|
||||
# 8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret['status'] == 400
|
||||
assert ret['status'] == 400
|
||||
assert ret['message'] == "Node already exists"
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret['status'] == 400
|
||||
assert ret['status'] == 400
|
||||
assert ret['message'] == "Node already exists"
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret['status'] == 400
|
||||
assert ret['status'] == 400
|
||||
assert ret['message'] == "Node already exists"
|
||||
|
||||
database.close()
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Tests the MoltenIron allocateBM command.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,13 +19,17 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
import argparse
|
||||
from molteniron import moltenirond
|
||||
|
||||
|
||||
def compare_provisioned_nodes(lhs, rhs):
|
||||
"""Specially compares lhs against rhs."""
|
||||
lhs = lhs.copy()
|
||||
rhs = rhs.copy()
|
||||
rhs['provisioned'] = 'hamzy'
|
||||
|
@ -32,8 +40,9 @@ def compare_provisioned_nodes(lhs, rhs):
|
|||
del lhs['id']
|
||||
assert lhs == rhs
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -44,7 +53,7 @@ if __name__ == "__main__":
|
|||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -57,78 +66,78 @@ if __name__ == "__main__":
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
node1 = {
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "e05cc5f061426e34",
|
||||
"port_hwaddr": "f8:de:29:33:a4:ed",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "e05cc5f061426e34",
|
||||
"port_hwaddr": "f8: de: 29:33:a4:ed",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.10,10.228.112.11"
|
||||
}
|
||||
node2 = {
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "0614d63b6635ea3d",
|
||||
"port_hwaddr": "4c:c5:da:28:2c:2d",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "0614d63b6635ea3d",
|
||||
"port_hwaddr": "4c: c5:da: 28:2c:2d",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.8,10.228.112.9"
|
||||
}
|
||||
node3 = {
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "928b056134e4d770",
|
||||
"port_hwaddr": "53:76:c6:09:50:64",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "928b056134e4d770",
|
||||
"port_hwaddr": "53: 76: c6:09:50:64",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"allocation_pool": "10.228.112.12,10.228.112.13"
|
||||
}
|
||||
node4 = {
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "33f448a4fc176492",
|
||||
"port_hwaddr": "85:e0:73:e9:fc:ca",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "33f448a4fc176492",
|
||||
"port_hwaddr": "85: e0: 73:e9:fc:ca",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"allocation_pool": "10.228.112.14,10.228.112.15"
|
||||
}
|
||||
|
||||
# 8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
|
@ -136,7 +145,7 @@ if __name__ == "__main__":
|
|||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret["nodes"]) == 1
|
||||
compare_provisioned_nodes (ret["nodes"]["node_1"], node1)
|
||||
compare_provisioned_nodes(ret["nodes"]["node_1"], node1)
|
||||
|
||||
database.close()
|
||||
del database
|
||||
|
@ -148,16 +157,16 @@ if __name__ == "__main__":
|
|||
del database
|
||||
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
|
@ -165,8 +174,8 @@ if __name__ == "__main__":
|
|||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret["nodes"]) == 2
|
||||
compare_provisioned_nodes (ret["nodes"]["node_1"], node1)
|
||||
compare_provisioned_nodes (ret["nodes"]["node_2"], node2)
|
||||
compare_provisioned_nodes(ret["nodes"]["node_1"], node1)
|
||||
compare_provisioned_nodes(ret["nodes"]["node_2"], node2)
|
||||
|
||||
database.close()
|
||||
del database
|
||||
|
@ -178,24 +187,24 @@ if __name__ == "__main__":
|
|||
del database
|
||||
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
ret = database.allocateBM("hamzy", 3)
|
||||
print ret
|
||||
assert ret == {'status': 404,
|
||||
assert ret == {'status': 404,
|
||||
'message': ('Not enough available nodes found. '
|
||||
'Found 2, requested 3')}
|
||||
'Found 2, requested 3')}
|
||||
|
||||
database.close()
|
||||
del database
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Tests the MoltenIron cull command.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# http: //www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -15,6 +19,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
|
@ -22,7 +28,9 @@ import argparse
|
|||
import time
|
||||
from molteniron import moltenirond
|
||||
|
||||
|
||||
def compare_culled_nodes(lhs, rhs):
|
||||
"""Specially compares lhs against rhs."""
|
||||
lhs = lhs.copy()
|
||||
rhs = rhs.copy()
|
||||
del rhs['allocation_pool']
|
||||
|
@ -33,7 +41,7 @@ def compare_culled_nodes(lhs, rhs):
|
|||
assert lhs == rhs
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -44,7 +52,7 @@ if __name__ == "__main__":
|
|||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -57,89 +65,89 @@ if __name__ == "__main__":
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
node1 = {
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "34118fd3509621ba",
|
||||
"port_hwaddr": "ff:2c:e1:cc:8e:7c",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "34118fd3509621ba",
|
||||
"port_hwaddr": "ff: 2c: e1:cc:8e:7c",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.10,10.228.112.11"
|
||||
}
|
||||
node2 = {
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "fa2125690a95b43c",
|
||||
"port_hwaddr": "f6:58:13:02:64:59",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "-1",
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "fa2125690a95b43c",
|
||||
"port_hwaddr": "f6: 58:13:02:64:59",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "-1",
|
||||
"allocation_pool": "10.228.112.8,10.228.112.9"
|
||||
}
|
||||
node3 = {
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "3aee014d56425a6c",
|
||||
"port_hwaddr": "6e:d4:a5:ae:13:55",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "3aee014d56425a6c",
|
||||
"port_hwaddr": "6e: d4:a5:ae: 13:55",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
# NOTE: time() can return fractional values. Ex: 1460560140.47
|
||||
"timestamp": str (time.time() - 1000.0),
|
||||
"timestamp": str(time.time() - 1000.0),
|
||||
"allocation_pool": "10.228.112.12,10.228.112.13"
|
||||
}
|
||||
node4 = {
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "254dd9fb34ddcac7",
|
||||
"port_hwaddr": "a0:c9:22:23:22:9d",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": str (time.time() - 2000.0),
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "254dd9fb34ddcac7",
|
||||
"port_hwaddr": "a0: c9: 22:23:22:9d",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": str(time.time() - 2000.0),
|
||||
"allocation_pool": "10.228.112.14,10.228.112.15"
|
||||
}
|
||||
|
||||
# 8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
ret = database.cull (1000)
|
||||
ret = database.cull(1000)
|
||||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret['nodes']) == 2
|
||||
|
||||
compare_culled_nodes (ret['nodes']['node_3'], node3)
|
||||
compare_culled_nodes (ret['nodes']['node_4'], node4)
|
||||
compare_culled_nodes(ret['nodes']['node_3'], node3)
|
||||
compare_culled_nodes(ret['nodes']['node_4'], node4)
|
||||
|
||||
database.close()
|
||||
del database
|
||||
|
@ -151,25 +159,25 @@ if __name__ == "__main__":
|
|||
del database
|
||||
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
ret = database.cull (2000)
|
||||
ret = database.cull(2000)
|
||||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret['nodes']) == 1
|
||||
|
||||
compare_culled_nodes (ret['nodes']['node_4'], node4)
|
||||
compare_culled_nodes(ret['nodes']['node_4'], node4)
|
||||
|
||||
database.close()
|
||||
del database
|
||||
|
@ -181,20 +189,20 @@ if __name__ == "__main__":
|
|||
del database
|
||||
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
ret = database.cull (3000)
|
||||
ret = database.cull(3000)
|
||||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret['nodes']) == 0
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Tests the MoltenIron deallocateBM command.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,13 +19,17 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
import argparse
|
||||
from molteniron import moltenirond
|
||||
|
||||
|
||||
def compare_provisioned_nodes(lhs, rhs):
|
||||
"""Specially compares lhs against rhs."""
|
||||
lhs = lhs.copy()
|
||||
rhs = rhs.copy()
|
||||
rhs['provisioned'] = 'hamzy'
|
||||
|
@ -33,7 +41,7 @@ def compare_provisioned_nodes(lhs, rhs):
|
|||
assert lhs == rhs
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -44,7 +52,7 @@ if __name__ == "__main__":
|
|||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -57,78 +65,78 @@ if __name__ == "__main__":
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
node1 = {
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "16f6954d347c4de2",
|
||||
"port_hwaddr": "28:5a:e7:e3:fe:75",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "16f6954d347c4de2",
|
||||
"port_hwaddr": "28: 5a: e7:e3:fe:75",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.10,10.228.112.11"
|
||||
}
|
||||
node2 = {
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "3a23241cfa516699",
|
||||
"port_hwaddr": "7d:0a:e5:b9:41:9b",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "3a23241cfa516699",
|
||||
"port_hwaddr": "7d: 0a: e5:b9:41:9b",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.8,10.228.112.9"
|
||||
}
|
||||
node3 = {
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "4f7e47c57f27ec55",
|
||||
"port_hwaddr": "5a:e8:11:e9:11:a2",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "4f7e47c57f27ec55",
|
||||
"port_hwaddr": "5a: e8: 11:e9:11:a2",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"allocation_pool": "10.228.112.12,10.228.112.13"
|
||||
}
|
||||
node4 = {
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "aeff165ded2c2f9f",
|
||||
"port_hwaddr": "4d:18:82:dc:2c:d6",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "aeff165ded2c2f9f",
|
||||
"port_hwaddr": "4d: 18:82: dc:2c:d6",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"allocation_pool": "10.228.112.14,10.228.112.15"
|
||||
}
|
||||
|
||||
# 8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
|
@ -136,7 +144,7 @@ if __name__ == "__main__":
|
|||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret["nodes"]) == 1
|
||||
compare_provisioned_nodes (ret["nodes"]["node_1"], node1)
|
||||
compare_provisioned_nodes(ret["nodes"]["node_1"], node1)
|
||||
|
||||
session = database.get_session()
|
||||
n1 = session.query(moltenirond.Nodes).filter_by(name=node1["name"]).one()
|
||||
|
@ -155,16 +163,16 @@ if __name__ == "__main__":
|
|||
del database
|
||||
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
|
@ -172,7 +180,7 @@ if __name__ == "__main__":
|
|||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret["nodes"]) == 1
|
||||
compare_provisioned_nodes (ret["nodes"]["node_1"], node1)
|
||||
compare_provisioned_nodes(ret["nodes"]["node_1"], node1)
|
||||
|
||||
session = database.get_session()
|
||||
n1 = session.query(moltenirond.Nodes).filter_by(name=node1["name"]).one()
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Tests the MoltenIron deallocateOwner command.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,13 +19,17 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
import argparse
|
||||
from molteniron import moltenirond
|
||||
|
||||
|
||||
def compare_provisioned_nodes(lhs, rhs):
|
||||
"""Specially compares lhs against rhs."""
|
||||
lhs = lhs.copy()
|
||||
rhs = rhs.copy()
|
||||
rhs['provisioned'] = 'hamzy'
|
||||
|
@ -33,7 +41,7 @@ def compare_provisioned_nodes(lhs, rhs):
|
|||
assert lhs == rhs
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -44,7 +52,7 @@ if __name__ == "__main__":
|
|||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -57,78 +65,78 @@ if __name__ == "__main__":
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
node1 = {
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "f367d07be07d6358",
|
||||
"port_hwaddr": "6d:9a:78:f3:ed:3a",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "f367d07be07d6358",
|
||||
"port_hwaddr": "6d: 9a:78: f3:ed:3a",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.10,10.228.112.11"
|
||||
}
|
||||
node2 = {
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "1c6a27307f8fe79d",
|
||||
"port_hwaddr": "16:23:e8:07:b4:a9",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "1c6a27307f8fe79d",
|
||||
"port_hwaddr": "16: 23: e8:07:b4:a9",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.8,10.228.112.9"
|
||||
}
|
||||
node3 = {
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "1766d597a024dd8d",
|
||||
"port_hwaddr": "12:33:9f:04:07:9b",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "1766d597a024dd8d",
|
||||
"port_hwaddr": "12: 33:9f:04:07:9b",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"allocation_pool": "10.228.112.12,10.228.112.13"
|
||||
}
|
||||
node4 = {
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "7c55be8b4ef42869",
|
||||
"port_hwaddr": "c2:31:e9:8a:75:96",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "7c55be8b4ef42869",
|
||||
"port_hwaddr": "c2: 31: e9:8a:75:96",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"allocation_pool": "10.228.112.14,10.228.112.15"
|
||||
}
|
||||
|
||||
# 8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
|
@ -136,7 +144,7 @@ if __name__ == "__main__":
|
|||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret["nodes"]) == 1
|
||||
compare_provisioned_nodes (ret["nodes"]["node_1"], node1)
|
||||
compare_provisioned_nodes(ret["nodes"]["node_1"], node1)
|
||||
|
||||
ret = database.deallocateOwner("hamzy")
|
||||
print ret
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Tests the MoltenIron doClean command.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,6 +19,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
|
@ -22,7 +28,7 @@ import argparse
|
|||
from molteniron import moltenirond
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -33,7 +39,7 @@ if __name__ == "__main__":
|
|||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -46,78 +52,78 @@ if __name__ == "__main__":
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
node1 = {
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "e23af1e52896cf02",
|
||||
"port_hwaddr": "5d:7e:05:dd:fe:65",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "e23af1e52896cf02",
|
||||
"port_hwaddr": "5d: 7e:05: dd:fe:65",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.10,10.228.112.11"
|
||||
}
|
||||
node2 = {
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "57212373db56c76a",
|
||||
"port_hwaddr": "7e:41:89:e1:28:03",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "57212373db56c76a",
|
||||
"port_hwaddr": "7e: 41:89: e1:28:03",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.8,10.228.112.9"
|
||||
}
|
||||
node3 = {
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "c2f4b0bfa31fe9de",
|
||||
"port_hwaddr": "4f:a7:48:59:6a:a7",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "c2f4b0bfa31fe9de",
|
||||
"port_hwaddr": "4f: a7: 48:59:6a:a7",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"allocation_pool": "10.228.112.12,10.228.112.13"
|
||||
}
|
||||
node4 = {
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "f99d122fc129c1dd",
|
||||
"port_hwaddr": "a2:0d:bc:ca:c5:a5",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "f99d122fc129c1dd",
|
||||
"port_hwaddr": "a2: 0d: bc:ca:c5:a5",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"allocation_pool": "10.228.112.14,10.228.112.15"
|
||||
}
|
||||
|
||||
# 8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Tests the MoltenIron get_field command.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,6 +19,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
|
@ -22,7 +28,7 @@ import argparse
|
|||
from molteniron import moltenirond
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -33,7 +39,7 @@ if __name__ == "__main__":
|
|||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -46,85 +52,85 @@ if __name__ == "__main__":
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
node1 = {
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "7db1486ac9ea6533",
|
||||
"port_hwaddr": "ca:2c:ab:88:47:b0",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "hamzy",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "7db1486ac9ea6533",
|
||||
"port_hwaddr": "ca: 2c: ab:88:47:b0",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "hamzy",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.10,10.228.112.11"
|
||||
}
|
||||
node2 = {
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "c3f8e3f3407e880b",
|
||||
"port_hwaddr": "90:24:5c:d5:0e:b3",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "mjturek",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "c3f8e3f3407e880b",
|
||||
"port_hwaddr": "90: 24:5c: d5:0e:b3",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "mjturek",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.8,10.228.112.9"
|
||||
}
|
||||
node3 = {
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "1bcbf739c7108291",
|
||||
"port_hwaddr": "9c:6b:1b:31:a5:2d",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "1bcbf739c7108291",
|
||||
"port_hwaddr": "9c: 6b:1b:31: a5:2d",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"allocation_pool": "10.228.112.12,10.228.112.13"
|
||||
}
|
||||
node4 = {
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"cpu_arch": "ppc64el",
|
||||
"ipmi_password": "0c200c858ac46280",
|
||||
"port_hwaddr": "64:49:12:c6:3f:bd",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "mjturek",
|
||||
"timestamp": "1460491566",
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"cpu_arch": "ppc64el",
|
||||
"ipmi_password": "0c200c858ac46280",
|
||||
"port_hwaddr": "64: 49:12: c6:3f:bd",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "mjturek",
|
||||
"timestamp": "1460491566",
|
||||
"allocation_pool": "10.228.112.14,10.228.112.15"
|
||||
}
|
||||
|
||||
# 8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
ret = database.get_field("hamzy", "cpus")
|
||||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret['result']) ==1
|
||||
assert len(ret['result']) == 1
|
||||
assert ret['result'][0]['field'] == node1["cpus"]
|
||||
|
||||
ret = database.get_field("mjturek", "port_hwaddr")
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Tests the MoltenIron get_ips command.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,6 +19,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
|
@ -22,7 +28,7 @@ import argparse
|
|||
from molteniron import moltenirond
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -33,7 +39,7 @@ if __name__ == "__main__":
|
|||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -46,78 +52,78 @@ if __name__ == "__main__":
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
node1 = {
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "1aa328d7767653ad",
|
||||
"port_hwaddr": "17:e7:f1:ab:a5:9f",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "hamzy",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "1aa328d7767653ad",
|
||||
"port_hwaddr": "17: e7:f1:ab:a5: 9f",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "hamzy",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.10,10.228.112.11"
|
||||
}
|
||||
node2 = {
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "84b9d9ceb866f612",
|
||||
"port_hwaddr": "0b:f1:9c:9d:a6:eb",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "mjturek",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "84b9d9ceb866f612",
|
||||
"port_hwaddr": "0b: f1: 9c:9d:a6:eb",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "mjturek",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.8,10.228.112.9"
|
||||
}
|
||||
node3 = {
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "ba60285a1fd69800",
|
||||
"port_hwaddr": "da:e0:86:2a:80:9c",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "ba60285a1fd69800",
|
||||
"port_hwaddr": "da: e0: 86:2a:80:9c",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"allocation_pool": "10.228.112.12,10.228.112.13"
|
||||
}
|
||||
node4 = {
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"cpu_arch": "ppc64el",
|
||||
"ipmi_password": "7810c66057ef4f2d",
|
||||
"port_hwaddr": "d6:bc:ca:83:95:e7",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "mjturek",
|
||||
"timestamp": "1460491566",
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"cpu_arch": "ppc64el",
|
||||
"ipmi_password": "7810c66057ef4f2d",
|
||||
"port_hwaddr": "d6: bc:ca: 83:95:e7",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "mjturek",
|
||||
"timestamp": "1460491566",
|
||||
"allocation_pool": "10.228.112.14,10.228.112.15"
|
||||
}
|
||||
|
||||
# 8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
|
@ -125,13 +131,13 @@ if __name__ == "__main__":
|
|||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret['ips']) == 1
|
||||
assert ret['ips'] == [ node1["ipmi_ip"] ]
|
||||
assert ret['ips'] == [node1["ipmi_ip"]]
|
||||
|
||||
ret = database.get_ips("mjturek")
|
||||
print ret
|
||||
assert ret['status'] == 200
|
||||
assert len(ret['ips']) == 2
|
||||
assert ret['ips'] == [ node2["ipmi_ip"], node4["ipmi_ip"] ]
|
||||
assert ret['ips'] == [node2["ipmi_ip"], node4["ipmi_ip"]]
|
||||
|
||||
database.close()
|
||||
del database
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Tests the MoltenIron removeBMNode command.
|
||||
"""
|
||||
|
||||
# Copyright (c) 2016 IBM Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -15,6 +19,8 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# pylint: disable-msg=C0103
|
||||
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
|
@ -22,7 +28,7 @@ import argparse
|
|||
from molteniron import moltenirond
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Molteniron command line tool")
|
||||
parser = argparse.ArgumentParser(description="Molteniron CLI tool")
|
||||
parser.add_argument("-c",
|
||||
"--conf-dir",
|
||||
action="store",
|
||||
|
@ -33,7 +39,7 @@ if __name__ == "__main__":
|
|||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
if args.conf_dir:
|
||||
if not os.path.isdir (args.conf_dir):
|
||||
if not os.path.isdir(args.conf_dir):
|
||||
msg = "Error: %s is not a valid directory" % (args.conf_dir, )
|
||||
print >> sys.stderr, msg
|
||||
sys.exit(1)
|
||||
|
@ -46,78 +52,78 @@ if __name__ == "__main__":
|
|||
conf = yaml.load(fobj)
|
||||
|
||||
node1 = {
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "2703f5fee17f2073",
|
||||
"port_hwaddr": "b1:71:dd:02:9e:20",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci816",
|
||||
"ipmi_ip": "10.228.219.134",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "2703f5fee17f2073",
|
||||
"port_hwaddr": "b1: 71: dd:02:9e:20",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.10,10.228.112.11"
|
||||
}
|
||||
node2 = {
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "c3f06ff4b798a4ea",
|
||||
"port_hwaddr": "88:6e:9e:fa:65:d8",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"name": "pkvmci818",
|
||||
"ipmi_ip": "10.228.219.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "c3f06ff4b798a4ea",
|
||||
"port_hwaddr": "88: 6e:9e: fa:65:d8",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "ready",
|
||||
"provisioned": "",
|
||||
"timestamp": "",
|
||||
"allocation_pool": "10.228.112.8,10.228.112.9"
|
||||
}
|
||||
node3 = {
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "2885d1af50781461",
|
||||
"port_hwaddr": "a2:a2:64:79:6b:69",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"name": "pkvmci851",
|
||||
"ipmi_ip": "10.228.118.129",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "2885d1af50781461",
|
||||
"port_hwaddr": "a2: a2: 64:79:6b:69",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "7a72eccd-3153-4d08-9848-c6d3b1f18f9f",
|
||||
"timestamp": "1460489832",
|
||||
"allocation_pool": "10.228.112.12,10.228.112.13"
|
||||
}
|
||||
node4 = {
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "3e374dc88ca43b4f",
|
||||
"port_hwaddr": "50:4a:56:3c:e9:0f",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20L,
|
||||
"ram_mb": 51000L,
|
||||
"disk_gb": 500L,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"name": "pkvmci853",
|
||||
"ipmi_ip": "10.228.118.133",
|
||||
"ipmi_user": "user",
|
||||
"ipmi_password": "3e374dc88ca43b4f",
|
||||
"port_hwaddr": "50: 4a:56:3c: e9:0f",
|
||||
"cpu_arch": "ppc64el",
|
||||
"cpus": 20,
|
||||
"ram_mb": 51000,
|
||||
"disk_gb": 500,
|
||||
"status": "used",
|
||||
"provisioned": "6b8823ef-3e14-4811-98b9-32e27397540d",
|
||||
"timestamp": "1460491566",
|
||||
"allocation_pool": "10.228.112.14,10.228.112.15"
|
||||
}
|
||||
|
||||
# 8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
|
||||
database = moltenirond.DataBase(conf, moltenirond.TYPE_SQLITE_MEMORY)
|
||||
ret = database.addBMNode (node1)
|
||||
ret = database.addBMNode(node1)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node2)
|
||||
ret = database.addBMNode(node2)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node3)
|
||||
ret = database.addBMNode(node3)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
ret = database.addBMNode (node4)
|
||||
ret = database.addBMNode(node4)
|
||||
print ret
|
||||
assert ret == {'status': 200}
|
||||
|
||||
|
|
13
tox.ini
13
tox.ini
|
@ -83,9 +83,8 @@ commands = mkdir -p testenv/var/run/
|
|||
stop
|
||||
|
||||
[testenv:pep8]
|
||||
#@TODO - too many failures
|
||||
# pass pep8 in a later patch
|
||||
#commands = flake8
|
||||
deps = flake8
|
||||
commands = flake8
|
||||
|
||||
[testenv:venv]
|
||||
#@TODO - a separate patch
|
||||
|
@ -99,6 +98,8 @@ commands = python setup.py build_sphinx
|
|||
# E712 is ignored on purpose, since it is normal to use 'column == true'
|
||||
# in sqlalchemy.
|
||||
# The rest of the ignores are TODOs
|
||||
|
||||
ignore = E712
|
||||
exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools
|
||||
ignore = E712,E901
|
||||
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,testenv/*,devenv/*
|
||||
# F821 undefined name 'unicode'
|
||||
# if (type(id) == str or type(id) == unicode) and ("." in id):
|
||||
builtins = unicode
|
||||
|
|
Loading…
Reference in New Issue