diff --git a/README.md b/README.md index 6823349..295ce17 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,14 @@ Artifice requires: * pyaml * mock * requests - * + * sqlalchemy >= 0.8.0 * OpenStack Grizzly. *currently untested with Havana* * Openstack-Keystone * Openstack-Ceilometer +Despite using SQLAlchemy, Artifice does NOT currently support SQLite or MySQL. Instead, it takes advantage of range exclusive +columns in Postgres, which is not supported on other systems. + ## Configuration Configuring Artifice is handled through its primary configuration file, stored in `/etc/openstack/artifice.conf`. @@ -45,7 +48,7 @@ This is a yaml-format config file, in the format of: database: artifice host: localhost password: aurynn - port: '5433' + port: '5432' username: aurynn # Configuration passed to the invoice system. This is an arbitrary dictionary # and may be anything that the invoice object may require. @@ -135,6 +138,22 @@ Actions one can perform with Artifice are: * *usage* +## Running Tests + +The tests are currently expected to run with Nosetests, against a pre-provisioned database. + +### Expected environment + +The test environment expects that the *DATABASE_URL* envar will be populated. +*DATABASE_URL* **must** be populated in the form: + + export DATABASE_URL=postgres://user:password@server/database + + +Provisioning the database is handled via: + + + ### Future things Eventually we also want Artifice to: diff --git a/bin/bill.py b/bin/bill.py index 7eb2360..92a01b0 100644 --- a/bin/bill.py +++ b/bin/bill.py @@ -20,7 +20,7 @@ import yaml date_format = "%Y-%m-%dT%H:%M:%S" other_date_format = "%Y-%m-%dT%H:%M:%S.%f" -date_fmt_fnc = lambda x: datetime.datetime.strptime(date_fmt) +date_fmt_fnc = lambda x: datetime.datetime.strptime(date_format) if __name__ == '__main__': import argparse @@ -54,7 +54,13 @@ if __name__ == '__main__': # Make ourselves a nice interaction object - n = interface.Artifice(conf["username"], conf["password"], conf["admin_tenant"]) + # Password needs to be loaded from /etc/artifice/database + fh = open(conf["database"]["password_path"]) + password = fh.read() + fh.close() + # Make ourselves a nice interaction object + conf["database"]["password"] = password + n = interface.Artifice(conf) tenants = args.tenants if not args.tenants: # only parse this list of tenants diff --git a/bin/usage.py b/bin/usage.py index a5b252f..cce42d8 100644 --- a/bin/usage.py +++ b/bin/usage.py @@ -59,8 +59,12 @@ if __name__ == '__main__': # Whoops print "couldn't load %s " % args.config sys.exit(1) - + + fh = open(conf["database"]["password_path"]) + password = fh.read() + fh.close() # Make ourselves a nice interaction object + conf["database"]["password"] = password instance = interface.Artifice(conf) tenants = args.tenants if not args.tenants: @@ -88,4 +92,4 @@ if __name__ == '__main__': invoice.bill(usage.volumes) invoice.bill(usage.objects) - print "Total invoice value: %s" % invoice.total() \ No newline at end of file + print "Total invoice value: %s" % invoice.total() diff --git a/examples/conf.yaml b/examples/conf.yaml index 5e60620..82d644e 100644 --- a/examples/conf.yaml +++ b/examples/conf.yaml @@ -4,9 +4,9 @@ ceilometer: database: database: artifice host: localhost - password: aurynn - port: '5433' - username: aurynn + password_path: /etc/artifice/database + port: '5432' + username: artifice invoice_object: delimiter: ',' output_file: '%(tenant)s-%(start)s-%(end)s.csv' @@ -19,8 +19,8 @@ invoice_object: - amount - cost rates: - file: /opt/stack/artifice/etc/artifice/csv_rates.csv - names: /opt/stack/artifice/etc/artifice/csv_names.csv + file: /etc/artifice/csv_rates.csv + names: /etc/artifice/csv_names.csv main: invoice:object: billing.csv_invoice:Csv openstack: diff --git a/packaging/scripts/post_install.sh b/packaging/scripts/post_install.sh index 3dc0c56..1acde37 100644 --- a/packaging/scripts/post_install.sh +++ b/packaging/scripts/post_install.sh @@ -21,13 +21,19 @@ virtualenv <%= install_path %>/env cat > /usr/local/bin/artifice-bill </env/bin/python <%=install_path%>/bin/bill.py $@ +<%=install_path%>/env/bin/python <%=install_path%>/bin/bill.py \$@ EOF cat > /usr/local/bin/artifice-usage </env/bin/python <%=install_path%>/bin/usage.py $@ +<%=install_path%>/env/bin/python <%=install_path%>/bin/usage.py \$@ EOF +chmod 0755 /usr/local/bin/artifice-usage +chmod 0755 /usr/local/bin/artifice-bill + +cp <%=install_path%>/etc/artifice/conf.yaml /etc/artifice/conf.yaml +cp <%=install_path%>/etc/artifice/database /etc/artifice/database +# chown 0640 /etc/artifice/database diff --git a/packaging/scripts/pre_install.sh b/packaging/scripts/pre_install.sh index cb93d1d..55ab55d 100644 --- a/packaging/scripts/pre_install.sh +++ b/packaging/scripts/pre_install.sh @@ -3,6 +3,9 @@ # Loads a SQL script into postgres that creates the artifice DB. # Post-install script is going to load all the DB stuff via pythons +if [ ! -e /etc/artifice ]; then + mkdir /etc/artifice +fi if [ -e <%=install_path%>/etc/artifice/database ]; then @@ -23,4 +26,4 @@ CREATE DATABASE <%=pg_database%>; CREATE EXTENSION btree_gist; CREATE USER <%=pg_user%> WITH ENCRYPTED PASSWORD '$PASSWORD'; ALTER DATABASE <%=pg_database%> OWNER TO <%=pg_user%>; -EOF \ No newline at end of file +EOF