RIFT OSM R1 Initial Submission
Signed-off-by: Jeremy Mordkoff <jeremy.mordkoff@riftio.com>
diff --git a/common/python/test/CMakeLists.txt b/common/python/test/CMakeLists.txt
new file mode 100644
index 0000000..1abb50d
--- /dev/null
+++ b/common/python/test/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Creation Date: 2016/1/12
+# RIFT_IO_STANDARD_CMAKE_COPYRIGHT_HEADER(END)
+
+cmake_minimum_required(VERSION 2.8)
+
+rift_py3test(utest_juju_api
+ TEST_ARGS
+ ${CMAKE_CURRENT_SOURCE_DIR}/utest_juju_api.py
+ )
diff --git a/common/python/test/utest_config_data.py b/common/python/test/utest_config_data.py
new file mode 100644
index 0000000..8287c11
--- /dev/null
+++ b/common/python/test/utest_config_data.py
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+
+#
+# Copyright 2016 RIFT.IO Inc
+#
+# 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.
+#
+
+
+import argparse
+import logging
+import io
+import os
+import sys
+import tempfile
+import unittest
+import xmlrunner
+import yaml
+
+
+from rift.mano.config_data import config
+
+import gi
+gi.require_version('VnfdYang', '1.0')
+gi.require_version('RwYang', '1.0')
+
+from gi.repository import (
+ VnfdYang,
+ RwYang,
+ )
+
+class InitialPrimitiveReaderTest(unittest.TestCase):
+ def test_read_valid_config(self):
+ input_prim_data = [
+ {
+ "name": "prim_1",
+ "parameter": {
+ "hostname": "pe1",
+ #"pass": "6windos"
+ # Hard to compare with multiple elements because ordering of list
+ # element is not deterministic.
+ }
+ },
+ {
+ "name": "prim_2",
+ # No, parameters (use default values)
+ },
+ ]
+
+ with io.StringIO() as yaml_hdl:
+ yaml_hdl.write(yaml.safe_dump(input_prim_data))
+ yaml_hdl.seek(0)
+ reader = config.VnfInitialConfigPrimitiveReader.from_yaml_file_hdl(yaml_hdl)
+
+ expected_primitives = [
+ VnfdYang.InitialConfigPrimitive.from_dict({
+ "name": "prim_1", "seq": 0, "parameter": [
+ {
+ "name": "hostname",
+ "value": "pe1",
+ },
+ ]
+ }),
+ VnfdYang.InitialConfigPrimitive.from_dict({
+ "name": "prim_2", "seq": 1
+ }),
+ ]
+
+ for i, prim in enumerate(reader.primitives):
+ logging.debug("Expected: %s", str(expected_primitives[i]))
+ logging.debug("Got: %s", str(prim))
+ self.assertEqual(expected_primitives[i], prim)
+
+
+def main(argv=sys.argv[1:]):
+ logging.basicConfig(format='TEST %(message)s')
+
+ runner = xmlrunner.XMLTestRunner(output=os.environ["RIFT_MODULE_TEST"])
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-v', '--verbose', action='store_true')
+ parser.add_argument('-n', '--no-runner', action='store_true')
+
+ args, unknown = parser.parse_known_args(argv)
+ if args.no_runner:
+ runner = None
+
+ # Set the global logging level
+ logging.getLogger().setLevel(logging.DEBUG if args.verbose else logging.ERROR)
+
+ # The unittest framework requires a program name, so use the name of this
+ # file instead (we do not want to have to pass a fake program name to main
+ # when this is called from the interpreter).
+ unittest.main(argv=[__file__] + unknown + ["-v"], testRunner=runner)
+
+if __name__ == '__main__':
+ main()
diff --git a/common/python/test/utest_juju_api.py b/common/python/test/utest_juju_api.py
new file mode 100755
index 0000000..7da9e81
--- /dev/null
+++ b/common/python/test/utest_juju_api.py
@@ -0,0 +1,124 @@
+#!/usr/bin/env python3
+
+############################################################################
+# Copyright 2016 RIFT.io Inc #
+# #
+# 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. #
+############################################################################
+
+
+import argparse
+import asyncio
+import logging
+from unittest import mock
+import os
+import sys
+import unittest
+import xmlrunner
+
+import rift.mano.utils.juju_api as juju_api
+
+
+class JujuClientTest(unittest.TestCase):
+
+ log = None
+
+ @classmethod
+ def set_logger(cls, log):
+ cls.log = log
+
+ @asyncio.coroutine
+ def juju_client_test(self, mock_jujuclient, loop):
+ api = juju_api.JujuApi(secret='test', loop=loop, version=1)
+
+ env = yield from api.get_env()
+
+ self.assertTrue(env.login.called,
+ "Login to Juju not called")
+ env.login.assert_called_with('test', user='user-admin')
+
+ charm = 'test-charm'
+ service = 'test-service'
+ yield from api.deploy_service(charm, service)
+ # self.assertTrue(env.deploy.called,
+ # "Deploy failed")
+
+ config = {
+ 'test_param': 'test_value',
+ }
+ yield from api.apply_config(config, env=env)
+ self.assertTrue(env.set_config.called,
+ "Config failed")
+
+ try:
+ yield from api.resolve_error(env=env)
+ except KeyError as e:
+ # Since the status does have values, this throws error
+ pass
+ # resolved method will not be called due to error above
+ self.assertFalse(env.resolved.called,
+ "Resolve error failed")
+
+ action = 'test-action'
+ params = {}
+ api.units = ['test-service-0']
+ # yield from api.execute_action(action, params, service=service, env=env)
+
+ action_tag = 'test-123434352'
+ # yield from api.get_action_status(action_tag)
+
+ api.destroy_retries = 2
+ api.retry_delay = 0.1
+ try:
+ yield from api.destroy_service()
+
+ except Exception as e:
+ JujuClientTest.log.debug("Expected exception on destroy service: {}".
+ format(e))
+
+ self.assertTrue(env.destroy_service.called,
+ "Destroy failed")
+
+ @mock.patch('rift.mano.utils.juju_api.Env1', autospec=True)
+ def test_client(self, mock_jujuclient):
+ loop = asyncio.get_event_loop()
+
+ loop.run_until_complete(self.juju_client_test(mock_jujuclient,
+ loop))
+
+ loop.close()
+
+def main(argv=sys.argv[1:]):
+ logging.basicConfig(format='TEST %(message)s')
+
+ runner = xmlrunner.XMLTestRunner(output=os.environ["RIFT_MODULE_TEST"])
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-v', '--verbose', action='store_true')
+ parser.add_argument('-n', '--no-runner', action='store_true')
+
+ args, unknown = parser.parse_known_args(argv)
+ if args.no_runner:
+ runner = None
+
+ # Set the global logging level
+ log = logging.getLogger()
+ log.setLevel(logging.DEBUG if args.verbose else logging.ERROR)
+ JujuClientTest.set_logger(log)
+
+ # The unittest framework requires a program name, so use the name of this
+ # file instead (we do not want to have to pass a fake program name to main
+ # when this is called from the interpreter).
+ unittest.main(argv=[__file__] + unknown + ["-v"], testRunner=runner)
+
+if __name__ == '__main__':
+ main()