diff --git a/kollacli/commands/upgrade.py b/kollacli/commands/upgrade.py index 2dd3901..56d0bd1 100644 --- a/kollacli/commands/upgrade.py +++ b/kollacli/commands/upgrade.py @@ -14,8 +14,6 @@ import logging import traceback -import kollacli.i18n as u - from kollacli.common.ansible.actions import upgrade from cliff.command import Command diff --git a/kollacli/common/inventory.py b/kollacli/common/inventory.py index 26e6fe9..83dcaa6 100644 --- a/kollacli/common/inventory.py +++ b/kollacli/common/inventory.py @@ -314,8 +314,8 @@ class Inventory(object): # the pickle decode. if 'kollacli.common.inventory' not in data: data = data.replace( - '"py/object": "kollacli.ansible.inventory.', - '"py/object": "kollacli.common.inventory.') + '"py/object": "kollacli.ansible.inventory.', + '"py/object": "kollacli.common.inventory.') if data.strip(): inventory = jsonpickle.decode(data) diff --git a/tests/common.py b/tests/common.py index b63cd06..ac751a0 100644 --- a/tests/common.py +++ b/tests/common.py @@ -14,7 +14,6 @@ # import logging import os -import pxssh import subprocess import sys import testtools @@ -23,6 +22,8 @@ import yaml import kollacli.common.utils as utils +from pexpect import pxssh + TEST_SUFFIX = 'test/' VENV_PY_PATH = '.venv/bin/python' KOLLA_CMD = 'kollacli' diff --git a/tests/deploy.py b/tests/deploy.py index ada6965..c61a9bb 100644 --- a/tests/deploy.py +++ b/tests/deploy.py @@ -19,7 +19,6 @@ from kollacli.common.inventory import SERVICES import json import os -import tarfile import unittest @@ -136,40 +135,6 @@ class TestFunctional(KollaCliTest): self.run_cli_cmd('deploy --serial') self.run_cli_cmd('deploy --groups=control') - def test_dump(self): - check_files = [ - 'var/log/kolla/kolla.log', - 'kolla/etc/globals.yml', - 'kolla/etc/config/nova/nova-api.conf', - 'kolla/etc/kollacli/ansible/inventory.json', - 'kolla/share/ansible/site.yml', - 'kolla/share/docs/ansible-deployment.rst', - ] - # dump success output is: - # dump successful to /tmp/kollacli_dump_Umxu6d.tgz - dump_path = None - try: - msg = self.run_cli_cmd('dump') - self.assertIn('/', msg, 'path not found in dump output: %s' % msg) - - dump_path = '/' + msg.strip().split('/', 1)[1] - is_file = os.path.isfile(dump_path) - self.assertTrue(is_file, - 'dump file not found at %s' % dump_path) - file_paths = [] - with tarfile.open(dump_path, 'r') as tar: - file_paths = tar.getnames() - - for check_file in check_files: - self.assertIn(check_file, file_paths, - 'dump: check file: %s, not in files:\n%s' - % (check_file, file_paths)) - except Exception as e: - raise e - finally: - if dump_path and os.path.exists(dump_path): - os.remove(dump_path) - def check_json(self, msg, groups, hosts, included_groups, included_hosts): err_msg = ('included groups: %s\n' % included_groups + 'included hosts: %s\n' % included_hosts) diff --git a/tests/support.py b/tests/support.py new file mode 100644 index 0000000..a1849bb --- /dev/null +++ b/tests/support.py @@ -0,0 +1,82 @@ +# Copyright(c) 2016, Oracle and/or its affiliates. All Rights Reserved. +# +# 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 os +import tarfile +import unittest + +from kollacli.common.utils import get_kollacli_home +from tests.common import KollaCliTest + +LOGS_PREFIX = '/tmp/kolla_support_logs_' + + +class TestFunctional(KollaCliTest): + + def test_log_collector(self): + zip_path = '' + host1 = 'host_test1' + try: + path = os.path.join(get_kollacli_home(), + 'tools', 'log_collector.py') + retval, msg = self.run_command('%s %s' % (path, host1)) + self.assertEqual(0, retval, + 'log_collector command failed: %s' % msg) + self.assertIn(LOGS_PREFIX, msg) + zip_path = '/tmp' + msg.split('/tmp')[1].strip() + self.assertTrue(os.path.exists(zip_path), + 'Zip file %s does not exist' % zip_path) + except Exception as e: + raise e + finally: + if zip_path: + os.remove(zip_path) + + def test_dump(self): + check_files = [ + 'var/log/kolla/kolla.log', + 'kolla/etc/globals.yml', + 'kolla/etc/config/nova/nova-api.conf', + 'kolla/etc/kollacli/ansible/inventory.json', + 'kolla/share/ansible/site.yml', + 'kolla/share/docs/ansible-deployment.rst', + ] + # dump success output is: + # dump successful to /tmp/kollacli_dump_Umxu6d.tgz + dump_path = None + try: + msg = self.run_cli_cmd('dump') + self.assertIn('/', msg, 'path not found in dump output: %s' % msg) + + dump_path = '/' + msg.strip().split('/', 1)[1] + is_file = os.path.isfile(dump_path) + self.assertTrue(is_file, + 'dump file not found at %s' % dump_path) + file_paths = [] + with tarfile.open(dump_path, 'r') as tar: + file_paths = tar.getnames() + + for check_file in check_files: + self.assertIn(check_file, file_paths, + 'dump: check file: %s, not in files:\n%s' + % (check_file, file_paths)) + except Exception as e: + raise e + finally: + if dump_path and os.path.exists(dump_path): + os.remove(dump_path) + + +if __name__ == '__main__': + unittest.main() diff --git a/tools/log_collector.py b/tools/log_collector.py index 62b26fa..25937e9 100755 --- a/tools/log_collector.py +++ b/tools/log_collector.py @@ -19,11 +19,11 @@ import sys import tarfile import tempfile -from kollacli.ansible.inventory import Inventory -from kollacli.ansible import properties -from kollacli.utils import get_admin_user -from kollacli.utils import get_ansible_command -from kollacli.utils import safe_decode +from kollacli.common.inventory import Inventory +from kollacli.common import properties +from kollacli.common.utils import get_admin_user +from kollacli.common.utils import get_ansible_command +from kollacli.common.utils import safe_decode tar_file_descr = None