update log_collector tool for 2.1.1

- fix imports in log collector tool
- add new unit test for it
- move dump test to new support test module
- can no longer import pxssh after upgrade to pexpect 4.0.1, change to
  import from pexpect module
- fix a couple of pep8 issues

Jira-Issue: OPENSTACK-297
This commit is contained in:
Steve Noyes 2016-02-11 11:38:15 -05:00
parent e698e1c81c
commit c679272ea2
6 changed files with 91 additions and 45 deletions

View File

@ -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

View File

@ -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)

View File

@ -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'

View File

@ -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)

82
tests/support.py Normal file
View File

@ -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()

View File

@ -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