Browse Source

Adding support for sphinx docs and tox support

In order to add the project to OpenStack Jenkins, Zuul we need to enable
the following:
* Running the test through tox (added tox.ini)
* Making sure the project can be packaged and uploaded into pypi (moved
  all python files to the mors package)
* Adding support for Sphinx Docunentation

Part of the changes were autogenerated using OpenStack cookiecutter
project which creates a template
Roopak Parikh 2 years ago
parent
commit
3eb6c95424

+ 17
- 0
CONTRIBUTING.rst View File

@@ -0,0 +1,17 @@
1
+If you would like to contribute to the development of OpenStack, you must
2
+follow the steps in this page:
3
+
4
+   http://docs.openstack.org/infra/manual/developers.html
5
+
6
+If you already have a good understanding of how the system works and your
7
+OpenStack accounts are set up, you can skip to the development workflow
8
+section of this documentation to learn how changes to OpenStack should be
9
+submitted for review via the Gerrit tool:
10
+
11
+   http://docs.openstack.org/infra/manual/developers.html#development-workflow
12
+
13
+Pull requests submitted through GitHub will be ignored.
14
+
15
+Bugs should be filed on Launchpad, not GitHub:
16
+
17
+   https://bugs.launchpad.net/mors

+ 79
- 0
README.rst View File

@@ -0,0 +1,79 @@
1
+Mors - OpenStack Lease Manager
2
+==============================
3
+
4
+|Mors| https://en.wikipedia.org/wiki/Mors\_(mythology) is a simple lease
5
+manager for OpenStack objects like Instances.
6
+
7
+Mors is a useful tool for OpenStack based cloud used for dev, test or
8
+lab setups. Typical usage in these scenarios include automatically or
9
+manual creation of Instances for demo, test or experiments. In most
10
+cases these Instances are forgotten and never deleted eating up valuable
11
+resources.
12
+
13
+Mors is a simple service that helps enforce a policy per Tenant or
14
+Instance and automatically delete Instances after a specified duration.
15
+
16
+Details
17
+-------
18
+
19
+Mors works by specification of lease policy in a hierarchical fashion,
20
+first at a Tenant level and further at individual Instance level.
21
+
22
+Tenant Lease Policy
23
+~~~~~~~~~~~~~~~~~~~
24
+
25
+Mors lease policy can be enabled or disabled at Tenant level. If Mors
26
+policy is disabled (default for each tenant) no lease policies apply to
27
+the instances within that tenant.
28
+
29
+At Tenant level, policy is specified in terms of *duration* . Once Mors
30
+policy is enabled, any Instance will be deleted after
31
+``instance.created_time + tenant.lease duration = instance_expiration``
32
+
33
+Roles
34
+^^^^^
35
+
36
+Tenant leases can be viewed by user with ‘member’ role and modified by
37
+users with ‘admin’ role
38
+
39
+Instance Lease Policy
40
+~~~~~~~~~~~~~~~~~~~~~
41
+
42
+By default Instance leases are governed by the policies at Instance’s
43
+Tenant level. As mentioned earlier:
44
+``instance.created_time + tenant.lease duration = instance_expiration``
45
+
46
+A member of tenant can change the Instance expiry at any time, but it
47
+can never be later than now + tenant.lease duration
48
+
49
+``max instance lease <= now + tenant.lease duration``
50
+
51
+A user can always come back at a later point of time and renew the
52
+release again.
53
+
54
+Roles
55
+^^^^^
56
+
57
+Instance leases can be modified by both ‘member’ and ‘admin’ roles.
58
+
59
+Build & Installation
60
+--------------------
61
+
62
+Support subdirectory contains Makefile to build a RPM, apart from python
63
+2.7, virtualenv it needs `fpm`_, *fpm* is a simple package build utility
64
+that can build both RPM and deb packages. RPM itself is a thin wrapper
65
+on top of the virtualenv.
66
+
67
+Configuration files are expected to be in /etc/pf9 directory. These are
68
+usual OpenStack style config files: \* pf9-mors.ini: configure the nova
69
+section with the user/password that can be used by mors to perform
70
+delete operations on nova instances. The user needs to be an
71
+administrator. \* pf9-mors-api-paste.ini: configure the keystone
72
+middleware with keystone auth tokens.
73
+
74
+The packages comes with an init script that works on RHEL 7 compatible
75
+systems
76
+
77
+.. _fpm: https://github.com/jordansissel/fpm
78
+
79
+.. |Mors| image:: https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRIzc5fgaiZfJnbym_ZEx4CsZJ7qIiYjcrxth5hi80Q0IhfnxOg

+ 75
- 0
doc/source/conf.py View File

@@ -0,0 +1,75 @@
1
+# -*- coding: utf-8 -*-
2
+# Licensed under the Apache License, Version 2.0 (the "License");
3
+# you may not use this file except in compliance with the License.
4
+# You may obtain a copy of the License at
5
+#
6
+#    http://www.apache.org/licenses/LICENSE-2.0
7
+#
8
+# Unless required by applicable law or agreed to in writing, software
9
+# distributed under the License is distributed on an "AS IS" BASIS,
10
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11
+# implied.
12
+# See the License for the specific language governing permissions and
13
+# limitations under the License.
14
+
15
+import os
16
+import sys
17
+
18
+sys.path.insert(0, os.path.abspath('../..'))
19
+# -- General configuration ----------------------------------------------------
20
+
21
+# Add any Sphinx extension module names here, as strings. They can be
22
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
23
+extensions = [
24
+    'sphinx.ext.autodoc',
25
+    #'sphinx.ext.intersphinx',
26
+    'oslosphinx'
27
+]
28
+
29
+# autodoc generation is a bit aggressive and a nuisance when doing heavy
30
+# text edit cycles.
31
+# execute "export SPHINX_DEBUG=1" in your terminal to disable
32
+
33
+# The suffix of source filenames.
34
+source_suffix = '.rst'
35
+
36
+# The master toctree document.
37
+master_doc = 'index'
38
+
39
+# General information about the project.
40
+project = u'mors'
41
+copyright = u'2016, OpenStack Foundation'
42
+
43
+# If true, '()' will be appended to :func: etc. cross-reference text.
44
+add_function_parentheses = True
45
+
46
+# If true, the current module name will be prepended to all description
47
+# unit titles (such as .. function::).
48
+add_module_names = True
49
+
50
+# The name of the Pygments (syntax highlighting) style to use.
51
+pygments_style = 'sphinx'
52
+
53
+# -- Options for HTML output --------------------------------------------------
54
+
55
+# The theme to use for HTML and HTML Help pages.  Major themes that come with
56
+# Sphinx are currently 'default' and 'sphinxdoc'.
57
+# html_theme_path = ["."]
58
+# html_theme = '_theme'
59
+# html_static_path = ['static']
60
+
61
+# Output file base name for HTML help builder.
62
+htmlhelp_basename = '%sdoc' % project
63
+
64
+# Grouping the document tree into LaTeX files. List of tuples
65
+# (source start file, target name, title, author, documentclass
66
+# [howto/manual]).
67
+latex_documents = [
68
+    ('index',
69
+     '%s.tex' % project,
70
+     u'%s Documentation' % project,
71
+     u'OpenStack Foundation', 'manual'),
72
+]
73
+
74
+# Example configuration for intersphinx: refer to the Python standard library.
75
+#intersphinx_mapping = {'http://docs.python.org/': None}

+ 4
- 0
doc/source/contributing.rst View File

@@ -0,0 +1,4 @@
1
+============
2
+Contributing
3
+============
4
+.. include:: ../../CONTRIBUTING.rst

+ 25
- 0
doc/source/index.rst View File

@@ -0,0 +1,25 @@
1
+.. mors documentation master file, created by
2
+   sphinx-quickstart on Tue Jul  9 22:26:36 2013.
3
+   You can adapt this file completely to your liking, but it should at least
4
+   contain the root `toctree` directive.
5
+
6
+Welcome to mors's documentation!
7
+========================================================
8
+
9
+Contents:
10
+
11
+.. toctree::
12
+   :maxdepth: 2
13
+
14
+   readme
15
+   installation
16
+   usage
17
+   contributing
18
+
19
+Indices and tables
20
+==================
21
+
22
+* :ref:`genindex`
23
+* :ref:`modindex`
24
+* :ref:`search`
25
+

+ 38
- 0
doc/source/installation.rst View File

@@ -0,0 +1,38 @@
1
+============
2
+Installation
3
+============
4
+
5
+From PyPi
6
+~~~~~~~~~~~~~~~~~~~~~
7
+At the command line::
8
+
9
+    $ pip install mors
10
+
11
+Or, if you have virtualenvwrapper installed::
12
+
13
+    $ mkvirtualenv mors
14
+    $ pip install mors
15
+
16
+
17
+RPM BUILD
18
+~~~~~~~~~~~~~~~~~~~~~
19
+
20
+Mors comes with an RPM installation and associated init.d scripts. Run the makefile under 'support' directory
21
+and it will produce RPM under the build directory.
22
+
23
+Support subdirectory contains Makefile to build a RPM, apart from python
24
+2.7, virtualenv it needs `fpm`_, *fpm* is a simple package build utility
25
+that can build both RPM and deb packages. RPM itself is a thin wrapper
26
+on top of the virtualenv.
27
+
28
+Configuration files are expected to be in /etc/pf9 directory. These are
29
+usual OpenStack style config files: \* pf9-mors.ini: configure the nova
30
+section with the user/password that can be used by mors to perform
31
+delete operations on nova instances. The user needs to be an
32
+administrator. \* pf9-mors-api-paste.ini: configure the keystone
33
+middleware with keystone auth tokens.
34
+
35
+The packages comes with an init script that works on RHEL 7 compatible
36
+systems
37
+
38
+.. _fpm: https://github.com/jordansissel/fpm

+ 1
- 0
doc/source/readme.rst View File

@@ -0,0 +1 @@
1
+.. include:: ../../README.rst

+ 5
- 0
doc/source/usage.rst View File

@@ -0,0 +1,5 @@
1
+========
2
+Usage
3
+========
4
+
5
+Refer to README for details on the policies and how the API is structured.

mors_manage.py → mors/mors_manage.py View File


pf9_mors.py → mors/pf9_mors.py View File


+ 29
- 0
setup.cfg View File

@@ -0,0 +1,29 @@
1
+[metadata]
2
+name = mors
3
+summary = OpenStack project for lease management of Instance and other OpenStack objects
4
+description-file =
5
+    README.rst
6
+author = OpenStack
7
+author-email = openstack-dev@lists.openstack.org
8
+home-page = http://www.openstack.org/
9
+classifier =
10
+    Environment :: OpenStack
11
+    Intended Audience :: Information Technology
12
+    Intended Audience :: System Administrators
13
+    License :: OSI Approved :: Apache Software License
14
+    Operating System :: POSIX :: Linux
15
+    Programming Language :: Python
16
+    Programming Language :: Python :: 2.7
17
+
18
+[files]
19
+packages =
20
+    mors
21
+
22
+[build_sphinx]
23
+source-dir = doc/source
24
+build-dir = doc/build
25
+all_files = 1
26
+
27
+[upload_sphinx]
28
+upload-dir = doc/build/html
29
+

+ 2
- 2
setup.py View File

@@ -16,7 +16,7 @@ limitations under the License.
16 16
 """
17 17
 from setuptools import setup
18 18
 
19
-setup(name='pf9-mors',
19
+setup(name='mors',
20 20
       version='0.1',
21 21
       description='Platform9 Mors (lease manager)',
22 22
       author='Platform9',
@@ -46,5 +46,5 @@ setup(name='pf9-mors',
46 46
           'nose',
47 47
           'proboscis'
48 48
       ],
49
-      scripts=['pf9_mors.py', 'mors_manage.py']
49
+      scripts=['mors/pf9_mors.py', 'mors/mors_manage.py']
50 50
       )

+ 1
- 2
test/run_tests.py View File

@@ -15,12 +15,11 @@ limitations under the License.
15 15
 """
16 16
 def run_tests():
17 17
     from proboscis import TestProgram
18
+
18 19
     import test_api, test_persistence
19 20
 
20 21
     # Run Proboscis and exit.
21
-    print "Starting tests ---"
22 22
     TestProgram().run_and_exit()
23
-    print "Tests done ---"
24 23
 
25 24
 if __name__ == '__main__':
26 25
     print "Run tests"

+ 9
- 8
test/test_api.py View File

@@ -13,19 +13,20 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 13
 See the License for the specific language governing permissions and
14 14
 limitations under the License.
15 15
 """
16
-from migrate.versioning.api import upgrade, create, version_control
17
-import ConfigParser, os
18
-import requests
16
+import ConfigParser
17
+import os
18
+import sys;
19
+
19 20
 import eventlet
20
-from pf9_mors import start_server
21
+import requests
22
+from migrate.versioning.api import upgrade, version_control
23
+
24
+print sys.path
25
+from mors.pf9_mors import start_server
21 26
 from mors.mors_wsgi import DATE_FORMAT
22 27
 import logging, sys
23 28
 from datetime import datetime, timedelta
24 29
 from proboscis.asserts import assert_equal
25
-from proboscis.asserts import assert_false
26
-from proboscis.asserts import assert_raises
27
-from proboscis.asserts import assert_true
28
-from proboscis import SkipTest
29 30
 from proboscis import test
30 31
 import shutil
31 32
 from mors.leasehandler.fake_lease_handler import FakeLeaseHandler

+ 9
- 0
tox.ini View File

@@ -0,0 +1,9 @@
1
+[tox]
2
+envlist = py27
3
+
4
+[testenv:py27]
5
+deps =
6
+    nose
7
+    proboscis
8
+commands =
9
+    python test/run_tests.py

Loading…
Cancel
Save