Resync charmhelpers for py3 fixes

Includes fix for write_file encoding under py3.

Change-Id: Id0e3677f4f877b23c95902140cc4f24736f2768c
Closes-Bug: 1735068
This commit is contained in:
James Page 2017-11-29 09:24:19 +00:00
parent f5a7315c2f
commit ffd60c0cc6
4 changed files with 20 additions and 8 deletions

View File

@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import logging import logging
import os
import re import re
import sys import sys
import six import six
@ -185,7 +186,7 @@ class OpenStackAmuletDeployment(AmuletDeployment):
self.d.configure(service, config) self.d.configure(service, config)
def _auto_wait_for_status(self, message=None, exclude_services=None, def _auto_wait_for_status(self, message=None, exclude_services=None,
include_only=None, timeout=1800): include_only=None, timeout=None):
"""Wait for all units to have a specific extended status, except """Wait for all units to have a specific extended status, except
for any defined as excluded. Unless specified via message, any for any defined as excluded. Unless specified via message, any
status containing any case of 'ready' will be considered a match. status containing any case of 'ready' will be considered a match.
@ -215,7 +216,10 @@ class OpenStackAmuletDeployment(AmuletDeployment):
:param timeout: Maximum time in seconds to wait for status match :param timeout: Maximum time in seconds to wait for status match
:returns: None. Raises if timeout is hit. :returns: None. Raises if timeout is hit.
""" """
self.log.info('Waiting for extended status on units...') if not timeout:
timeout = int(os.environ.get('AMULET_SETUP_TIMEOUT', 1800))
self.log.info('Waiting for extended status on units for {}s...'
''.format(timeout))
all_services = self.d.services.keys() all_services = self.d.services.keys()
@ -252,9 +256,9 @@ class OpenStackAmuletDeployment(AmuletDeployment):
service_messages = {service: message for service in services} service_messages = {service: message for service in services}
# Check for idleness # Check for idleness
self.d.sentry.wait() self.d.sentry.wait(timeout=timeout)
# Check for error states and bail early # Check for error states and bail early
self.d.sentry.wait_for_status(self.d.juju_env, services) self.d.sentry.wait_for_status(self.d.juju_env, services, timeout=timeout)
# Check for ready messages # Check for ready messages
self.d.sentry.wait_for_messages(service_messages, timeout=timeout) self.d.sentry.wait_for_messages(service_messages, timeout=timeout)

View File

@ -549,6 +549,8 @@ def write_file(path, content, owner='root', group='root', perms=0o444):
with open(path, 'wb') as target: with open(path, 'wb') as target:
os.fchown(target.fileno(), uid, gid) os.fchown(target.fileno(), uid, gid)
os.fchmod(target.fileno(), perms) os.fchmod(target.fileno(), perms)
if six.PY3 and isinstance(content, six.string_types):
content = content.encode('UTF-8')
target.write(content) target.write(content)
return return
# the contents were the same, but we might still need to change the # the contents were the same, but we might still need to change the

View File

@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import logging import logging
import os
import re import re
import sys import sys
import six import six
@ -185,7 +186,7 @@ class OpenStackAmuletDeployment(AmuletDeployment):
self.d.configure(service, config) self.d.configure(service, config)
def _auto_wait_for_status(self, message=None, exclude_services=None, def _auto_wait_for_status(self, message=None, exclude_services=None,
include_only=None, timeout=1800): include_only=None, timeout=None):
"""Wait for all units to have a specific extended status, except """Wait for all units to have a specific extended status, except
for any defined as excluded. Unless specified via message, any for any defined as excluded. Unless specified via message, any
status containing any case of 'ready' will be considered a match. status containing any case of 'ready' will be considered a match.
@ -215,7 +216,10 @@ class OpenStackAmuletDeployment(AmuletDeployment):
:param timeout: Maximum time in seconds to wait for status match :param timeout: Maximum time in seconds to wait for status match
:returns: None. Raises if timeout is hit. :returns: None. Raises if timeout is hit.
""" """
self.log.info('Waiting for extended status on units...') if not timeout:
timeout = int(os.environ.get('AMULET_SETUP_TIMEOUT', 1800))
self.log.info('Waiting for extended status on units for {}s...'
''.format(timeout))
all_services = self.d.services.keys() all_services = self.d.services.keys()
@ -252,9 +256,9 @@ class OpenStackAmuletDeployment(AmuletDeployment):
service_messages = {service: message for service in services} service_messages = {service: message for service in services}
# Check for idleness # Check for idleness
self.d.sentry.wait() self.d.sentry.wait(timeout=timeout)
# Check for error states and bail early # Check for error states and bail early
self.d.sentry.wait_for_status(self.d.juju_env, services) self.d.sentry.wait_for_status(self.d.juju_env, services, timeout=timeout)
# Check for ready messages # Check for ready messages
self.d.sentry.wait_for_messages(service_messages, timeout=timeout) self.d.sentry.wait_for_messages(service_messages, timeout=timeout)

View File

@ -549,6 +549,8 @@ def write_file(path, content, owner='root', group='root', perms=0o444):
with open(path, 'wb') as target: with open(path, 'wb') as target:
os.fchown(target.fileno(), uid, gid) os.fchown(target.fileno(), uid, gid)
os.fchmod(target.fileno(), perms) os.fchmod(target.fileno(), perms)
if six.PY3 and isinstance(content, six.string_types):
content = content.encode('UTF-8')
target.write(content) target.write(content)
return return
# the contents were the same, but we might still need to change the # the contents were the same, but we might still need to change the