From 8af5bfcebcd3ab60374192c826858efc011efb61 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Thu, 13 Oct 2016 15:46:45 -0500 Subject: [PATCH] Create minor playbook to sync TZ data on upgrade Keeping the timezone data in sync between containers and the host machine should be done by default. This addition ensures that all containers inherit the TZ data from the host they're running on. Change-Id: I2803b4b6814680af39594e205fcf7be338a70091 Signed-off-by: Kevin Carter --- doc/source/upgrade-guide/manual-upgrade.rst | 11 +++++ .../reference-upgrade-playbooks.rst | 8 ++++ ...xc-container-sync-tz-b75cb628972c795b.yaml | 7 +++ scripts/run-upgrade.sh | 1 + .../playbooks/lxc-container-tz-sync.yml | 44 +++++++++++++++++++ 5 files changed, 71 insertions(+) create mode 100644 releasenotes/notes/lxc-container-sync-tz-b75cb628972c795b.yaml create mode 100644 scripts/upgrade-utilities/playbooks/lxc-container-tz-sync.yml diff --git a/doc/source/upgrade-guide/manual-upgrade.rst b/doc/source/upgrade-guide/manual-upgrade.rst index f22ea658bf..cc53b7ed3b 100644 --- a/doc/source/upgrade-guide/manual-upgrade.rst +++ b/doc/source/upgrade-guide/manual-upgrade.rst @@ -221,6 +221,17 @@ See :ref:`old-hostname-compatibility` for details. # openstack-ansible "${UPGRADE_PLAYBOOKS}/old-hostname-compatibility.yml" +Ensure TZ data is sync'd between hosts and containers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Ensure all containers have the same TZ and the physical hosts. + +See :ref:`lxc-container-tz-sync` for details. + +.. code-block:: console + + # openstack-ansible "${UPGRADE_PLAYBOOKS}/lxc-container-tz-sync.yml" + Perform a mariadb version upgrade ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/source/upgrade-guide/reference-upgrade-playbooks.rst b/doc/source/upgrade-guide/reference-upgrade-playbooks.rst index 345ca05fa2..d444081f6c 100644 --- a/doc/source/upgrade-guide/reference-upgrade-playbooks.rst +++ b/doc/source/upgrade-guide/reference-upgrade-playbooks.rst @@ -74,6 +74,14 @@ playbook is only needed for upgrades of in-place upgrades of existing nodes or if a node is replaced or rebuilt it will be brought into the cluster using a compliant hostname. +.. _lxc-container-tz-sync: + +lxc-container-tz-sync.yml +~~~~~~~~~~~~~~~~~~~~~~~~~ + +This playbook ensures that all containers are running on the same TZ settings +as the physical host. + .. _setup-infra-playbook: setup-infrastructure.yml diff --git a/releasenotes/notes/lxc-container-sync-tz-b75cb628972c795b.yaml b/releasenotes/notes/lxc-container-sync-tz-b75cb628972c795b.yaml new file mode 100644 index 0000000000..e5c0cd9ebc --- /dev/null +++ b/releasenotes/notes/lxc-container-sync-tz-b75cb628972c795b.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - LXC containers will have their TZ data sync with their physical host + machines. This is being done because containers have been assumed to + use UTC while a host could be using something else. This causes issues + in some services like celiometer and can result in general time + differences in logging. diff --git a/scripts/run-upgrade.sh b/scripts/run-upgrade.sh index 1bb91d6d41..277814fd56 100755 --- a/scripts/run-upgrade.sh +++ b/scripts/run-upgrade.sh @@ -180,6 +180,7 @@ function main { # rebuild the repo servers RUN_TASKS+=("repo-install.yml") RUN_TASKS+=("${UPGRADE_PLAYBOOKS}/old-hostname-compatibility.yml") + RUN_TASKS+=("${UPGRADE_PLAYBOOKS}/lxc-container-tz-sync.yml") # explicitly perform mariadb upgrade RUN_TASKS+=("galera-install.yml -e 'galera_upgrade=true'") # explicitly perform controlled galera cluster restart diff --git a/scripts/upgrade-utilities/playbooks/lxc-container-tz-sync.yml b/scripts/upgrade-utilities/playbooks/lxc-container-tz-sync.yml new file mode 100644 index 0000000000..ae81c8e9ee --- /dev/null +++ b/scripts/upgrade-utilities/playbooks/lxc-container-tz-sync.yml @@ -0,0 +1,44 @@ +--- +# Copyright 2016, Rackspace US, 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. + +- name: Container time sync + hosts: "{{ lxc_host_group | default('lxc_hosts')}}" + gather_facts: false + max_fail_percentage: 20 + user: root + tasks: + - name: Ensure localtime is in sync + shell: | + EXIT_CODE=0 + for i in $(lxc-ls --running); do + CONTAINER_ROOT="/proc/$(lxc-info -n $i -p | awk '{print $2}')/root" + DATE_BEFORE="$(chroot ${CONTAINER_ROOT} date +%Z)" + rm "${CONTAINER_ROOT}/etc/localtime" + cp -fP /etc/localtime "${CONTAINER_ROOT}/etc/localtime" + DATE_AFTER="$(chroot ${CONTAINER_ROOT} date +%Z)" + echo $DATE_AFTER $DATE_BEFORE + if [ "${DATE_BEFORE}" != "${DATE_AFTER}" ]; then + export EXIT_CODE=3 + fi + done + exit ${EXIT_CODE} + args: + executable: /bin/bash + register: tz_data + failed_when: tz_data.rc == 1 + changed_when: tz_data.rc == 3 + tags: + - lxc-containers-create +