Support both Ubuntu and CentOS

CentOS installs molteniron into /usr/etc/molteniron instead of
/usr/local/etc/molteniron/ so we have moved the conf.yaml file
into the molteniron Python directory and started using
pkg_resources.resource_filename to find our data file.

Change-Id: I75330d51475051a04bb2dff903f54727b9be9b6e
This commit is contained in:
Mark Hamzy 2017-02-21 20:09:31 +00:00
parent 4c4609e10c
commit b3b6dda18d
19 changed files with 77 additions and 75 deletions

View File

@ -1,6 +1,7 @@
include AUTHORS
include ChangeLog
exclude .gitignore
exclude .gitreview
global-exclude *.pyc
include AUTHORS
include ChangeLog
include molteniron/conf.yaml

View File

@ -29,6 +29,7 @@ import argparse
import json
from molteniron import molteniron
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -77,11 +78,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
mi.setup_conf(conf)

View File

@ -25,15 +25,16 @@ This is a helper program for the MoltenIron server.
from __future__ import print_function
import argparse
import sys
import os
import signal
import yaml
from daemonize import Daemonize
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import signal
import sys
import yaml
PID = "/var/run/moltenirond.pid"
YAML_CONF = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = None
ERROR_LOGFILE = "/tmp/MoltenIron-error-logfile"
@ -120,6 +121,12 @@ if __name__ == "__main__":
sys.exit(1)
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
YAML_CONF = resource_filename("molteniron", "conf.yaml")
# Test for read ability
fobj = open(YAML_CONF, "r")
fobj.close()
if args.pid_dir:
if not os.path.isdir(args.pid_dir):

View File

@ -34,6 +34,7 @@ import calendar
from datetime import datetime
import json
import os
from pkg_resources import resource_filename
import sys
import time
import traceback
@ -1334,11 +1335,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
listener(conf)

View File

@ -26,6 +26,7 @@ from __future__ import print_function
import argparse
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -46,11 +47,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
request1 = {

View File

@ -27,6 +27,7 @@ import argparse
import json
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -88,11 +89,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
request1 = {

View File

@ -27,6 +27,7 @@ import argparse
import json
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import sys
import time
import yaml
@ -86,11 +87,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
request1 = {

View File

@ -27,6 +27,7 @@ import argparse
import json
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -88,11 +89,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
request1 = {

View File

@ -27,6 +27,7 @@ import argparse
import json
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -88,11 +89,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
request1 = {

View File

@ -26,6 +26,7 @@ from __future__ import print_function
import argparse
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -47,11 +48,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
request1 = {

View File

@ -26,6 +26,7 @@ from __future__ import print_function
import argparse
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -47,11 +48,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
request1 = {

View File

@ -26,6 +26,7 @@ from __future__ import print_function
import argparse
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -47,11 +48,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
request1 = {

View File

@ -26,6 +26,7 @@ from __future__ import print_function
import argparse
from molteniron import moltenirond
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -47,11 +48,11 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as fobj:
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
request1 = {

View File

@ -34,6 +34,7 @@ setup(name="molteniron",
"molteniron/molteniron",
"utils/test_hook_mi_ipmiblob.py",
"utils/test_hook_mi_ipmiblob.sh"],
data_files=[("etc/molteniron/", ["conf.yaml"])],
package_data={"molteniron": ["*.yaml"]},
include_package_data=True,
setup_requires=['pbr'],
pbr=True)

36
tox.ini
View File

@ -22,17 +22,13 @@ commands = mkdir -p testenv/var/run/
--install-scripts=testenv/bin/ \
--install-purelib=testenv/lib/python2.7/site-packages/
moltenirond-helper \
--conf-dir=testenv/etc/molteniron/ \
--pid-dir=testenv/var/run/ \
start
molteniron \
--conf-dir=testenv/etc/molteniron/ \
delete_db
molteniron \
--conf-dir=testenv/etc/molteniron/ \
add_baremetal test1 10.1.2.1 user password 10.1.2.3,10.1.2.4 de:ad:be:ef:00:01 ppc64el 8 2048 32
molteniron \
--conf-dir=testenv/etc/molteniron/ \
add_keyvalue_pairs test2 \
10.1.2.2 \
10.1.2.5,10.1.2.6 \
@ -51,53 +47,39 @@ commands = mkdir -p testenv/var/run/
# passes in '\\{"ipmi_user": "user"\\}' which breaks json.loads()
# ValueError: No JSON object could be decoded
# molteniron \
# --conf-dir=testenv/etc/molteniron/ \
# add_json_blob test3 \
# 10.1.2.3 \
# 10.1.2.7,10.1.2.8 \
# '{"ipmi_user": "user", "ipmi_password": "password", "port_hwaddr": "de:ad:be:ef:00:01", "cpu_arch": "ppc64el", "cpus": 8, "ram_mb": 2048, "disk_gb": 32''}'
molteniron \
--conf-dir=testenv/etc/molteniron/ \
allocate hamzy 1
molteniron \
--conf-dir=testenv/etc/molteniron/ \
get_field hamzy port_hwaddr
molteniron \
--conf-dir=testenv/etc/molteniron/ \
release hamzy
# Sadly needs a bash shell to run uuidgen
test_hook_mi_ipmiblob.sh
diff testenv/tmp/hardware_info molteniron/tests/hardware_info.good
diff testenv/tmp/localrc molteniron/tests/localrc.good
python \
molteniron/tests/testAllocateBM.py \
--conf-dir=testenv/etc/molteniron/
molteniron/tests/testAllocateBM.py
python \
molteniron/tests/testAddBMNode.py \
--conf-dir=testenv/etc/molteniron/
molteniron/tests/testAddBMNode.py
python \
molteniron/tests/testCull.py \
--conf-dir=testenv/etc/molteniron/
molteniron/tests/testCull.py
python \
molteniron/tests/testDeallocateBM.py \
--conf-dir=testenv/etc/molteniron/
molteniron/tests/testDeallocateBM.py
python \
molteniron/tests/testDeallocateOwner.py \
--conf-dir=testenv/etc/molteniron/
molteniron/tests/testDeallocateOwner.py
python \
molteniron/tests/testDoClean.py \
--conf-dir=testenv/etc/molteniron/
molteniron/tests/testDoClean.py
python \
molteniron/tests/testGetField.py \
--conf-dir=testenv/etc/molteniron/
molteniron/tests/testGetField.py
python \
molteniron/tests/testGetIps.py \
--conf-dir=testenv/etc/molteniron/
molteniron/tests/testGetIps.py
python \
molteniron/tests/testRemoveBMNode.py \
--conf-dir=testenv/etc/molteniron/
molteniron/tests/testRemoveBMNode.py
moltenirond-helper \
--conf-dir=testenv/etc/molteniron/ \
--pid-dir=testenv/var/run/ \
stop

View File

@ -40,7 +40,7 @@ def main():
# This program is located in molteniron/utils/ directory.
# The conf.yaml is located in the molteniron/ directory.
newPath = "/".join(dirs[:-2]) + "/"
fobj = open(newPath + "conf.yaml", "r")
fobj = open(newPath + "molteniron/conf.yaml", "r")
conf = yaml.load(fobj)
# Create the SQL User

View File

@ -29,6 +29,7 @@ import argparse
import json
from molteniron import molteniron
import os
from pkg_resources import resource_filename
import sys
import yaml
@ -72,12 +73,12 @@ if __name__ == "__main__":
print(msg, file=sys.stderr)
sys.exit(1)
yaml_file = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
YAML_CONF = os.path.realpath("%s/conf.yaml" % (args.conf_dir, ))
else:
yaml_file = "/usr/local/etc/molteniron/conf.yaml"
YAML_CONF = resource_filename("molteniron", "conf.yaml")
with open(yaml_file, "r") as f_obj:
conf = yaml.load(f_obj)
with open(YAML_CONF, "r") as fobj:
conf = yaml.load(fobj)
mi.setup_conf(conf)
mi.setup_parser(parser)

View File

@ -16,7 +16,6 @@
# limitations under the License.
test_hook_mi_ipmiblob.py \
--conf-dir=testenv/etc/molteniron/ \
--hardware-info=testenv/tmp/hardware_info \
--localrc=testenv/tmp/localrc \
$(uuidgen) \