[SEBA-450] (part 2)

Add tox testing support on additional XOS library modules:

- xos-api
- xos-kafka (has no tests)
- xos-migrate (has no tests)
- xos-synchronizer

Change-Id: I98195bc9747971d3515882d517affe058dd86ac5
diff --git a/lib/xos-migrate/.gitignore b/lib/xos-migrate/.gitignore
index ed8b98a..81c7233 100644
--- a/lib/xos-migrate/.gitignore
+++ b/lib/xos-migrate/.gitignore
@@ -1,6 +1,2 @@
-build
-dist
-XosMigrate.egg-info
-.coverage
-coverage.xml
-cover
+# setup.py copies this, don't commit it
+xosmigrate/VERSION
diff --git a/lib/xos-migrate/MANIFEST.in b/lib/xos-migrate/MANIFEST.in
index a38c6ba..7b800b6 100644
--- a/lib/xos-migrate/MANIFEST.in
+++ b/lib/xos-migrate/MANIFEST.in
@@ -1,2 +1,4 @@
-include xosmigrate/migration_cfg_schema.yaml
+include requirements.txt
+include xosmigrate/VERSION
 include xosmigrate/migration_cfg.yaml
+include xosmigrate/migration_cfg_schema.yaml
diff --git a/lib/xos-migrate/bin/xos-migrate b/lib/xos-migrate/bin/xos-migrate
old mode 100644
new mode 100755
index 574bc40..243e915
--- a/lib/xos-migrate/bin/xos-migrate
+++ b/lib/xos-migrate/bin/xos-migrate
@@ -1,5 +1,18 @@
 #!/usr/bin/env python
 
-# from xosmigrate import run
+# Copyright 2017-present Open Networking Foundation
+#
+# 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
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 from xosmigrate.main import run
 run()
diff --git a/lib/xos-migrate/requirements.txt b/lib/xos-migrate/requirements.txt
new file mode 100644
index 0000000..803fecb
--- /dev/null
+++ b/lib/xos-migrate/requirements.txt
@@ -0,0 +1,4 @@
+PyYAML~=3.12
+multistructlog~=2.1.0
+xosconfig~=2.2.6
+xosgenx~=2.2.6
diff --git a/lib/xos-migrate/setup.py b/lib/xos-migrate/setup.py
index fe795de..97dc454 100644
--- a/lib/xos-migrate/setup.py
+++ b/lib/xos-migrate/setup.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
 # Copyright 2017-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,24 +12,41 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-try:
-    from xosutil.autoversion_setup import setup_with_auto_version as setup
-except ImportError:
-    # xosutil is not installed. Expect this to happen when we build an egg, in which case xosgenx.version will
-    # automatically have the right version.
-    from setuptools import setup
+from __future__ import absolute_import
 
-from xosgenx.version import __version__
+import os
+from shutil import copyfile
+
+from setuptools import setup
+
+
+def version():
+    # Copy VERSION file of parent to module directory if not found
+    if not os.path.exists("xosmigrate/VERSION"):
+        copyfile("../../VERSION", "xosmigrate/VERSION")
+    with open("xosmigrate/VERSION") as f:
+        return f.read().strip()
+
+
+def parse_requirements(filename):
+    # parse a requirements.txt file, allowing for blank lines and comments
+    requirements = []
+    for line in open(filename):
+        if line and not line.startswith("#"):
+            requirements.append(line)
+    return requirements
+
 
 setup(
-    name="XosMigrate",
-    version=__version__,
+    name="xosmigrate",
+    version=version(),
     description="XOS Migrations Toolkit",
     author="Matteo Scandolo",
     author_email="teo@opennetworking.org",
+    classifiers=["License :: OSI Approved :: Apache Software License"],
+    license="Apache v2",
     packages=["xosmigrate"],
     scripts=["bin/xos-migrate"],
+    install_requires=parse_requirements("requirements.txt"),
     include_package_data=True,
-    # TODO add all deps to the install_requires section
-    install_requires=[],
 )
diff --git a/lib/xos-migrate/tox.ini b/lib/xos-migrate/tox.ini
new file mode 100644
index 0000000..92ae12f
--- /dev/null
+++ b/lib/xos-migrate/tox.ini
@@ -0,0 +1,44 @@
+; Copyright 2017-present Open Networking Foundation
+;
+; 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
+;
+; Unless required by applicable law or agreed to in writing, software
+; distributed under the License is distributed on an "AS IS" BASIS,
+; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+; See the License for the specific language governing permissions and
+; limitations under the License.
+
+[tox]
+envlist = py27,py35,py36,py37
+skip_missing_interpreters = true
+
+[testenv]
+deps =
+  -r requirements.txt
+  nose2
+  flake8
+
+commands =
+  nose2 -c tox.ini --verbose --junit-xml
+  flake8
+
+[flake8]
+max-line-length = 119
+
+[unittest]
+plugins=nose2.plugins.junitxml
+
+[junit-xml]
+path=nose2-results.xml
+
+[coverage]
+always-on = True
+coverage = xosmigrate
+coverage-report =
+  xml
+  term
+
diff --git a/lib/xos-migrate/xosmigrate/__init__.py b/lib/xos-migrate/xosmigrate/__init__.py
index 0612f4f..b0fb0b2 100644
--- a/lib/xos-migrate/xosmigrate/__init__.py
+++ b/lib/xos-migrate/xosmigrate/__init__.py
@@ -11,4 +11,3 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-import main
diff --git a/lib/xos-migrate/xosmigrate/main.py b/lib/xos-migrate/xosmigrate/main.py
index 338474d..f8f5d6b 100644
--- a/lib/xos-migrate/xosmigrate/main.py
+++ b/lib/xos-migrate/xosmigrate/main.py
@@ -32,6 +32,7 @@
 from xosconfig import Config
 from multistructlog import create_logger
 
+
 def get_abs_path(dir_):
     """ Convert a path specified by the user, which might be relative or based on
         home directory location, into an absolute path.
@@ -330,7 +331,6 @@
 
     # find absolute path to the code
     xos_path = get_abs_path(os.path.join(args.repo_root, "orchestration/xos/xos/"))
-    django_path = get_abs_path(os.path.join(xos_path, "manage.py"))
     core_dir = get_abs_path(os.path.join(xos_path, "core/models/"))
     service_base_dir = get_abs_path(os.path.join(xos_path, "../../xos_services/"))
     service_dest_dir = get_abs_path(os.path.join(xos_path, "services/"))