update build spec to remove etc and share, fix warnings

- remove /etc and /usr/share refs in build spec
- suppress warning when deleting eggs
- if no message on failed ansible playbook, show
entire ugly results structure
- if lock file is not present, throw error

Jira-Issue: OPENSTACK-781

Fixed py34 safe_decode dict issue

Jira-Issue: OSTACKDEV-19
This commit is contained in:
Steve Noyes 2016-04-13 14:32:17 -04:00
parent 6338975d90
commit c96c508b01
3 changed files with 32 additions and 28 deletions

View File

@ -133,7 +133,7 @@ esac
if [[ "${inst_type}" == "update" ]]
then
rm -rf %{python_sitelib}/kollacli-*egg-info
rm -rf %{python_sitelib}/kollacli-*egg-info 2> /dev/null
fi
%post
@ -160,21 +160,21 @@ then
fi
# disable ansible retry files (bug 22806271)
sed -i "s/#retry_files_enabled = False/retry_files_enabled = False/" /etc/ansible/ansible.cfg
sed -i "s/#retry_files_enabled = False/retry_files_enabled = False/" %{ansible_cfg}
/usr/bin/kollacli complete >/etc/bash_completion.d/kollacli 2>/dev/null
/usr/bin/kollacli complete >%{_sysconfdir}/bash_completion.d/kollacli 2>/dev/null
# Update the sudoers file
if ! grep -q 'kollacli/tools/kolla_actions' /etc/sudoers.d/%{kolla_user}
if ! grep -q 'kollacli/tools/kolla_actions' %{_sysconfdir}/sudoers.d/%{kolla_user}
then
sed -i \
'/^Cmnd_Alias.*KOLLA_CMDS/ s:$:, %{_datadir}/kolla/kollacli/tools/kolla_actions.py:'\
/etc/sudoers.d/%{kolla_user}
%{_sysconfdir}/sudoers.d/%{kolla_user}
fi
# remove obsolete password editor from sudoers file
sed -i \
'/^Cmnd_Alias.*KOLLA_CMDS/ s:, /usr/share/kolla/kollacli/tools/passwd_editor.py::'\
/etc/sudoers.d/%{kolla_user}
'/^Cmnd_Alias.*KOLLA_CMDS/ s:, %{_datadir}/kolla/kollacli/tools/passwd_editor.py::'\
%{_sysconfdir}/sudoers.d/%{kolla_user}
# remove obsolete json_generator script
if test -f %{_datadir}/kolla/kollacli/tools/json_generator.py
@ -240,11 +240,11 @@ then
fi
%changelog
* Wed Apr 13 2016 - Steve Noyes <steve.noyes@oracle.com>
- add kolla-ansible-plugin subpackage
- suppress warning on egg removal
- remove etc and usr/share refs
* Thu Apr 07 2016 - Borne Mace <borne.mace@oracle.com>
- added ansible.lock file to coordinate ansible synchronization

View File

@ -23,12 +23,12 @@ import time
import kollacli.i18n as u
from kollacli.common.inventory import remove_temp_inventory
from kollacli.common.utils import PidManager
from kollacli.common.utils import get_kolla_actions_path
from kollacli.common.utils import get_admin_uids
from kollacli.common.utils import get_admin_user
from kollacli.common.utils import get_ansible_lock_path
from kollacli.common.utils import get_kolla_actions_path
from kollacli.common.utils import Lock
from kollacli.common.utils import PidManager
from kollacli.common.utils import run_cmd
from kollacli.common.utils import safe_decode
@ -128,7 +128,8 @@ class AnsibleJob(object):
# job has completed
if self._kill_uname:
status = 2
msg = u._('Job killed by user (%s)' % self._kill_uname)
msg = (u._('Job killed by user ({name})')
.format(name=self._kill_uname))
self._errors = [msg]
else:
status = self._process.returncode
@ -335,7 +336,7 @@ class AnsibleJob(object):
if sub_errs:
err_msg = ''.join([err_msg, ' [', sub_errs, ']'])
if not err_msg:
if not err_msg or not err_msg.strip():
# sometimes the error message is in std_out
# eg- "stdout": 'localhost | FAILED! => {"changed": false,
# "failed": true, "msg": "...msg..."}'
@ -346,6 +347,12 @@ class AnsibleJob(object):
if not err_msg:
err_msg = stdout
if not err_msg or not err_msg.strip():
# if still no err_msg, provide entire result
try:
err_msg = json.dumps(results)
except Exception as e:
LOG.debug('unable to convert results to string' % str(e))
msg = ('Host: %s, Task: %s, Status: %s, Message: %s' %
(host, taskname, status, err_msg))
return msg

View File

@ -260,7 +260,7 @@ def sync_read_file(path, mode='r'):
finally:
if lock:
lock.release()
return data
return safe_decode(data)
def sync_write_file(path, data, mode='w'):
@ -295,9 +295,9 @@ def sync_write_file(path, data, mode='w'):
def safe_decode(obj_to_decode):
"""Convert bytes or string to unicode string
"""Convert bytes or strings to unicode string
Convert either a string or list of strings to
Converts strings, lists, or dictionaries to
unicode.
"""
if obj_to_decode is None:
@ -307,22 +307,15 @@ def safe_decode(obj_to_decode):
if isinstance(obj_to_decode, list):
new_obj = []
for text in obj_to_decode:
try:
text = text.decode('utf-8')
except AttributeError: # nosec
# py3 will raise if text is already a string
pass
text = safe_decode(text)
new_obj.append(text)
elif isinstance(obj_to_decode, dict):
new_obj = {}
for key, value in obj_to_decode.items():
try:
new_key = key.decode('utf-8')
new_value = value.decode('utf-8')
new_obj[new_key] = new_value
except AttributeError: # nosec
# py3 will raise if it is already a string
pass
key = safe_decode(key)
value = safe_decode(value)
new_obj[key] = value
else:
try:
new_obj = obj_to_decode.decode('utf-8')
@ -387,6 +380,10 @@ class Lock(object):
else:
return self._acquire_pidfile()
except Exception as e:
if not os.path.exists(self.lockpath):
raise Exception('Lock file (%s) is missing'
% self.lockpath)
# it is ok to fail to acquire, we just return that we failed
LOG.debug('Exception in acquire lock. '
'path: %s pid: %s owner: %s error: %s' %