All of lore.kernel.org
 help / color / mirror / Atom feed
* [m-c-s][PATCH] python-*: fixup postinst scripts
@ 2017-11-15 17:59 Mark Asselstine
  2017-11-15 20:54 ` Bruce Ashfield
  2017-11-15 20:58 ` Richard Purdie
  0 siblings, 2 replies; 7+ messages in thread
From: Mark Asselstine @ 2017-11-15 17:59 UTC (permalink / raw)
  To: meta-virtualization, bruce.ashfield

Checking for "$D" and doing an "exit 1" now results in errors such as:

[log_check] warning: %post(keystone-cronjobs-...) scriptlet failed, exit status 2

during image creation. Instead of escaping the script for "level-1"
(image creation postinst) we wrap the "level-2" (first boot) postinst
in an if statement. This also ensure the scriptlet in
indentity.bbclass is less prone to behaving differently based on the
postinsts defined in the classes which inherit 'identity'.

Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
---
 meta-openstack/classes/identity.bbclass            | 11 +++--
 .../recipes-devtools/python/python-barbican_git.bb |  8 ++--
 .../python/python-ceilometer_git.bb                | 24 +++++------
 .../recipes-devtools/python/python-cinder_git.bb   | 48 ++++++++++-----------
 .../recipes-devtools/python/python-glance_git.bb   | 24 +++++------
 .../recipes-devtools/python/python-heat_git.bb     | 24 +++++------
 .../recipes-devtools/python/python-keystone_git.bb | 50 +++++++++++-----------
 .../recipes-devtools/python/python-neutron_git.bb  | 32 ++++++--------
 .../recipes-devtools/python/python-nova_git.bb     | 42 ++++++++----------
 .../recipes-devtools/python/python-rally_git.bb    | 28 ++++++------
 .../recipes-devtools/python/python-swift_git.bb    | 40 ++++++++---------
 .../recipes-devtools/python/python-trove_git.bb    | 45 ++++++++++---------
 .../postgresql/postgresql_9.%.bbappend             | 14 +++---
 13 files changed, 185 insertions(+), 205 deletions(-)

diff --git a/meta-openstack/classes/identity.bbclass b/meta-openstack/classes/identity.bbclass
index c4b1394..1f4f408 100644
--- a/meta-openstack/classes/identity.bbclass
+++ b/meta-openstack/classes/identity.bbclass
@@ -163,9 +163,11 @@ python populate_packages_append () {
 
         postinst = d.getVar('pkg_postinst_%s' % pkg, True) or d.getVar('pkg_postinst', True)
         if not postinst:
-            postinst = '    if [ "x$D" != "x" ]; then\n' + \
-                       '        exit 1\n' + \
-                       '    fi\n'
+            postinst = ''
+
+        # Only execute on target. Header.
+        postinst += '    if [ -z "$D" ]; then\n'
+
         postinst += servicecreate_postinst_common_copy
 
         if d.getVar('USERCREATE_PARAM_%s' % pkg, True):
@@ -176,6 +178,9 @@ python populate_packages_append () {
             servicecreate_postinst_service = servicecreate_postinst_service_copy.replace("SERVICECREATE_PARAM", servicecreate_param(d, pkg))
             postinst += servicecreate_postinst_service
 
+        # Footer.
+        postinst += '    fi\n'
+
         d.setVar('pkg_postinst_%s' % pkg, postinst)
         bb.debug(1, 'pkg_postinst_%s = %s' % (pkg, d.getVar('pkg_postinst_%s' % pkg, True)))
 }
diff --git a/meta-openstack/recipes-devtools/python/python-barbican_git.bb b/meta-openstack/recipes-devtools/python/python-barbican_git.bb
index 0b3d768..579413c 100644
--- a/meta-openstack/recipes-devtools/python/python-barbican_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-barbican_git.bb
@@ -85,12 +85,10 @@ FILES_${SRCNAME} = "${sysconfdir}/${SRCNAME}/* \
 
 ALLOW_EMPTY_${SRCNAME}-setup = "1"
 pkg_postinst_${SRCNAME}-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "$D" ]; then
+        chown -R barbican:barbican ${sysconfdir}/${SRCNAME}
+        chown -R barbican:barbican ${localstatedir}/lib/barbican
     fi
-
-    chown -R barbican:barbican ${sysconfdir}/${SRCNAME}
-    chown -R barbican:barbican ${localstatedir}/lib/barbican
 }
 
 DEPENDS += " \
diff --git a/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb b/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb
index 5645626..4b01022 100644
--- a/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb
@@ -108,20 +108,18 @@ do_install_append() {
 }
 
 pkg_postinst_${SRCNAME}-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "$D" ]; then
+        # This is to make sure postgres is configured and running
+        if ! pidof postmaster > /dev/null; then
+           /etc/init.d/postgresql-init
+           /etc/init.d/postgresql start
+           sleep 2
+        fi
+
+        mkdir /var/log/ceilometer
+        sudo -u postgres createdb ceilometer
+        ceilometer-dbsync
     fi
-
-    # This is to make sure postgres is configured and running
-    if ! pidof postmaster > /dev/null; then
-       /etc/init.d/postgresql-init
-       /etc/init.d/postgresql start
-       sleep 2
-    fi
-    
-    mkdir /var/log/ceilometer
-    sudo -u postgres createdb ceilometer
-    ceilometer-dbsync
 }
 
 inherit setuptools identity hosts update-rc.d default_configs monitor
diff --git a/meta-openstack/recipes-devtools/python/python-cinder_git.bb b/meta-openstack/recipes-devtools/python/python-cinder_git.bb
index e70a3aa..9f70beb 100644
--- a/meta-openstack/recipes-devtools/python/python-cinder_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-cinder_git.bb
@@ -124,31 +124,29 @@ do_install_append() {
 }
 
 pkg_postinst_${SRCNAME}-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
-    fi
-
-    # This is to make sure postgres is configured and running
-    if ! pidof postmaster > /dev/null; then
-       /etc/init.d/postgresql-init
-       /etc/init.d/postgresql start
-    fi
-
-    if [ ! -d /var/log/cinder ]; then
-       mkdir /var/log/cinder
-    fi
-
-    sudo -u postgres createdb cinder
-    cinder-manage db sync
-
-    # Create Cinder nfs_share config file with default nfs server
-    if [ ! -f /etc/cinder/nfs_shares ]; then
-        /bin/bash /etc/cinder/drivers/nfs_setup.sh
-    fi
-
-    # Create Cinder glusterfs_share config file with default glusterfs server
-    if [ ! -f /etc/cinder/glusterfs_shares ] && [ -f /usr/sbin/glusterfsd ]; then
-        /bin/bash /etc/cinder/drivers/glusterfs_setup.sh
+    if [ -z "$D" ]; then
+	 # This is to make sure postgres is configured and running
+	 if ! pidof postmaster > /dev/null; then
+	    /etc/init.d/postgresql-init
+	    /etc/init.d/postgresql start
+	 fi
+
+	 if [ ! -d /var/log/cinder ]; then
+	    mkdir /var/log/cinder
+	 fi
+
+	 sudo -u postgres createdb cinder
+	 cinder-manage db sync
+
+	 # Create Cinder nfs_share config file with default nfs server
+	 if [ ! -f /etc/cinder/nfs_shares ]; then
+	     /bin/bash /etc/cinder/drivers/nfs_setup.sh
+	 fi
+
+	 # Create Cinder glusterfs_share config file with default glusterfs server
+	 if [ ! -f /etc/cinder/glusterfs_shares ] && [ -f /usr/sbin/glusterfsd ]; then
+	     /bin/bash /etc/cinder/drivers/glusterfs_setup.sh
+	 fi
     fi
 }
 
diff --git a/meta-openstack/recipes-devtools/python/python-glance_git.bb b/meta-openstack/recipes-devtools/python/python-glance_git.bb
index 27c33b9..4042f1b 100644
--- a/meta-openstack/recipes-devtools/python/python-glance_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-glance_git.bb
@@ -122,20 +122,18 @@ do_install_append() {
 }
 
 pkg_postinst_${SRCNAME}-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "$D" ]; then
+	# This is to make sure postgres is configured and running
+	if ! pidof postmaster > /dev/null; then
+	   /etc/init.d/postgresql-init
+	   /etc/init.d/postgresql start
+	   sleep 5
+	fi
+
+	mkdir /var/log/glance
+	sudo -u postgres createdb glance
+	glance-manage db_sync
     fi
-    
-    # This is to make sure postgres is configured and running
-    if ! pidof postmaster > /dev/null; then
-       /etc/init.d/postgresql-init
-       /etc/init.d/postgresql start
-       sleep 5
-    fi
-    
-    mkdir /var/log/glance
-    sudo -u postgres createdb glance
-    glance-manage db_sync
 }
 
 PACKAGES += " ${SRCNAME}-tests ${SRCNAME} ${SRCNAME}-setup ${SRCNAME}-api ${SRCNAME}-registry"
diff --git a/meta-openstack/recipes-devtools/python/python-heat_git.bb b/meta-openstack/recipes-devtools/python/python-heat_git.bb
index cccaf0a..2cf7ce4 100644
--- a/meta-openstack/recipes-devtools/python/python-heat_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-heat_git.bb
@@ -107,20 +107,18 @@ do_install_append() {
 }
 
 pkg_postinst_${SRCNAME}-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "$D" ]; then
+	# This is to make sure postgres is configured and running
+	if ! pidof postmaster > /dev/null; then
+	   /etc/init.d/postgresql-init
+	   /etc/init.d/postgresql start
+	   sleep 2
+	fi
+
+	mkdir /var/log/heat
+	sudo -u postgres createdb heat
+	heat-manage db_sync
     fi
-    
-    # This is to make sure postgres is configured and running
-    if ! pidof postmaster > /dev/null; then
-       /etc/init.d/postgresql-init
-       /etc/init.d/postgresql start
-       sleep 2
-    fi
-    
-    mkdir /var/log/heat
-    sudo -u postgres createdb heat
-    heat-manage db_sync
 }
 
 inherit setuptools identity hosts update-rc.d default_configs monitor
diff --git a/meta-openstack/recipes-devtools/python/python-keystone_git.bb b/meta-openstack/recipes-devtools/python/python-keystone_git.bb
index 79bd0c8..a26c9bf 100644
--- a/meta-openstack/recipes-devtools/python/python-keystone_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-keystone_git.bb
@@ -189,28 +189,26 @@ role_tree_dn = ou=Roles,${LDAP_DN} \
 
 pkg_postinst_${SRCNAME}-setup () {
     # python-keystone postinst start
-    if [ "x$D" != "x" ]; then
-        exit 1
-    fi
-
-    # This is to make sure postgres is configured and running
-    if ! pidof postmaster > /dev/null; then
-        /etc/init.d/postgresql-init
-        /etc/init.d/postgresql start
-        sleep 2
-    fi
-
-    # This is to make sure keystone is configured and running
-    PIDFILE="/var/run/keystone-all.pid"
-    if [ -z `cat $PIDFILE 2>/dev/null` ]; then
-        sudo -u postgres createdb keystone
-        keystone-manage db_sync
-        keystone-manage pki_setup --keystone-user=root --keystone-group=daemon
-
-        if ${@bb.utils.contains('DISTRO_FEATURES', 'OpenLDAP', 'true', 'false', d)}; then
-            /etc/init.d/openldap start
-        fi
-        /etc/init.d/keystone start
+    if [ -z "$D" ]; then
+	# This is to make sure postgres is configured and running
+	if ! pidof postmaster > /dev/null; then
+	    /etc/init.d/postgresql-init
+	    /etc/init.d/postgresql start
+	    sleep 2
+	fi
+
+	# This is to make sure keystone is configured and running
+	PIDFILE="/var/run/keystone-all.pid"
+	if [ -z `cat $PIDFILE 2>/dev/null` ]; then
+	    sudo -u postgres createdb keystone
+	    keystone-manage db_sync
+	    keystone-manage pki_setup --keystone-user=root --keystone-group=daemon
+
+	    if ${@bb.utils.contains('DISTRO_FEATURES', 'OpenLDAP', 'true', 'false', d)}; then
+		/etc/init.d/openldap start
+	    fi
+	    /etc/init.d/keystone start
+	fi
     fi
 }
 
@@ -219,9 +217,11 @@ pkg_postinst_${SRCNAME}-setup () {
 KEYSTONE_TOKEN_FLUSH_TIME ??= "0 0 */2 * *"
 
 pkg_postinst_${SRCNAME}-cronjobs () {
-    # By default keystone expired tokens are not automatic removed out of the
-    # database.  So we create a cronjob for cleaning these expired tokens.
-    echo "${KEYSTONE_TOKEN_FLUSH_TIME} root /usr/bin/keystone-manage token_flush" >> /etc/crontab
+    if [ -z "$D" ]; then
+	# By default keystone expired tokens are not automatic removed out of the
+	# database.  So we create a cronjob for cleaning these expired tokens.
+	echo "${KEYSTONE_TOKEN_FLUSH_TIME} root /usr/bin/keystone-manage token_flush" >> /etc/crontab
+    fi
 }
 
 PACKAGES += " ${SRCNAME}-tests ${SRCNAME} ${SRCNAME}-setup ${SRCNAME}-cronjobs"
diff --git a/meta-openstack/recipes-devtools/python/python-neutron_git.bb b/meta-openstack/recipes-devtools/python/python-neutron_git.bb
index 51c2ac4..c837401 100644
--- a/meta-openstack/recipes-devtools/python/python-neutron_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-neutron_git.bb
@@ -138,29 +138,25 @@ do_install_append() {
 }
 
 pkg_postinst_${SRCNAME}-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "$D" ]; then
+	# This is to make sure postgres is configured and running
+	if ! pidof postmaster > /dev/null; then
+	    /etc/init.d/postgresql-init
+	    /etc/init.d/postgresql start
+	    sleep 2
+	fi
+
+	sudo -u postgres createdb neutron
+	sudo neutron-db-manage --config-file /etc/neutron/neutron.conf  \
+			       --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head
     fi
-
-    # This is to make sure postgres is configured and running
-    if ! pidof postmaster > /dev/null; then
-        /etc/init.d/postgresql-init
-        /etc/init.d/postgresql start
-        sleep 2
-    fi
-
-    sudo -u postgres createdb neutron
-    sudo neutron-db-manage --config-file /etc/neutron/neutron.conf  \
-                           --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head
 }
 
 pkg_postinst_${SRCNAME}-plugin-openvswitch-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "$D" ]; then
+	/etc/init.d/openvswitch-switch start
+	ovs-vsctl --no-wait -- --may-exist add-br br-int
     fi
-   
-    /etc/init.d/openvswitch-switch start
-    ovs-vsctl --no-wait -- --may-exist add-br br-int
 }
 
 ALLOW_EMPTY_${SRCNAME}-setup = "1"
diff --git a/meta-openstack/recipes-devtools/python/python-nova_git.bb b/meta-openstack/recipes-devtools/python/python-nova_git.bb
index f3a6b86..7b560a7 100644
--- a/meta-openstack/recipes-devtools/python/python-nova_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-nova_git.bb
@@ -160,33 +160,29 @@ do_install_append() {
 }
 
 pkg_postinst_${SRCNAME}-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "$D" ]; then
+	# This is to make sure postgres is configured and running
+	if ! pidof postmaster > /dev/null; then
+	   /etc/init.d/postgresql-init
+	   /etc/init.d/postgresql start
+	   sleep 5
+	fi
+
+	sudo -u postgres createdb nova
+	sleep 2
+	nova-manage db sync
     fi
-
-    # This is to make sure postgres is configured and running
-    if ! pidof postmaster > /dev/null; then
-       /etc/init.d/postgresql-init
-       /etc/init.d/postgresql start
-       sleep 5
-    fi
-
-    sudo -u postgres createdb nova
-    sleep 2
-    nova-manage db sync
 }
 
 pkg_postinst_${SRCNAME}-common () {
-    if [ "x$D" != "x" ]; then
-        exit 1
-    fi
-
-    if [ -d  /home/root ]; then
-        echo "source /etc/nova/openrc" >> /home/root/.bashrc
-	echo "source /etc/nova/openrc" >> /home/root/.profile
-    else
-        echo "source /etc/nova/openrc" >> /root/.bashrc
-	echo "source /etc/nova/openrc" >> /root/.profile
+    if [ -z "$D" ]; then
+	if [ -d  /home/root ]; then
+	    echo "source /etc/nova/openrc" >> /home/root/.bashrc
+	    echo "source /etc/nova/openrc" >> /home/root/.profile
+	else
+	    echo "source /etc/nova/openrc" >> /root/.bashrc
+	    echo "source /etc/nova/openrc" >> /root/.profile
+	fi
     fi
 }
 
diff --git a/meta-openstack/recipes-devtools/python/python-rally_git.bb b/meta-openstack/recipes-devtools/python/python-rally_git.bb
index d29e7cb..31d4242 100644
--- a/meta-openstack/recipes-devtools/python/python-rally_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-rally_git.bb
@@ -63,22 +63,20 @@ do_install_append() {
 }
 
 pkg_postinst_${SRCNAME}-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "$D" ]; then
+	# This is to make sure postgres is configured and running
+	if ! pidof postmaster > /dev/null; then
+	   /etc/init.d/postgresql-init
+	   /etc/init.d/postgresql start
+	fi
+
+	if [ ! -d /var/log/rally ]; then
+	   mkdir /var/log/rally
+	fi
+
+	sudo -u postgres createdb rally
+	rally-manage db recreate
     fi
-
-    # This is to make sure postgres is configured and running
-    if ! pidof postmaster > /dev/null; then
-       /etc/init.d/postgresql-init
-       /etc/init.d/postgresql start
-    fi
-
-    if [ ! -d /var/log/rally ]; then
-       mkdir /var/log/rally
-    fi
-
-    sudo -u postgres createdb rally
-    rally-manage db recreate
 }
 
 PACKAGES += "${SRCNAME}-tests ${SRCNAME}-api ${SRCNAME} ${SRCNAME}-setup"
diff --git a/meta-openstack/recipes-devtools/python/python-swift_git.bb b/meta-openstack/recipes-devtools/python/python-swift_git.bb
index 8552ea7..fc7c258 100644
--- a/meta-openstack/recipes-devtools/python/python-swift_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-swift_git.bb
@@ -109,28 +109,26 @@ do_install_append() {
 }
 
 pkg_postinst_${SRCNAME}-setup () {
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "x$D" ]; then
+	CLUSTER_CONF=/etc/swift/cluster.conf
+	SWIFT_SETUP='/bin/bash /etc/swift/swift_setup.sh'
+
+	for i in `seq 1 3`; do
+	    BACKING_FILE=/etc/swift/swift_backing_$i
+	    if [ "x${SWIFT_BACKING_FILE_SIZE}" != "x0G" ]; then
+		truncate -s ${SWIFT_BACKING_FILE_SIZE} $BACKING_FILE
+		sed "s:%SWIFT_BACKING_FILE_${i}%:$BACKING_FILE:g" -i $CLUSTER_CONF
+	    else
+		sed "s:%SWIFT_BACKING_FILE_${i}%::g" -i $CLUSTER_CONF
+	    fi
+	done
+
+	$SWIFT_SETUP createrings
+	$SWIFT_SETUP formatdevs
+	$SWIFT_SETUP mountdevs
+	$SWIFT_SETUP -i "${CONTROLLER_IP}" adddevs
+	$SWIFT_SETUP unmountdevs
     fi
-
-    CLUSTER_CONF=/etc/swift/cluster.conf
-    SWIFT_SETUP='/bin/bash /etc/swift/swift_setup.sh'
-
-    for i in `seq 1 3`; do
-        BACKING_FILE=/etc/swift/swift_backing_$i
-        if [ "x${SWIFT_BACKING_FILE_SIZE}" != "x0G" ]; then
-            truncate -s ${SWIFT_BACKING_FILE_SIZE} $BACKING_FILE
-            sed "s:%SWIFT_BACKING_FILE_${i}%:$BACKING_FILE:g" -i $CLUSTER_CONF
-        else
-            sed "s:%SWIFT_BACKING_FILE_${i}%::g" -i $CLUSTER_CONF
-        fi
-    done
-
-    $SWIFT_SETUP createrings
-    $SWIFT_SETUP formatdevs
-    $SWIFT_SETUP mountdevs
-    $SWIFT_SETUP -i "${CONTROLLER_IP}" adddevs
-    $SWIFT_SETUP unmountdevs
 }
 
 PACKAGES += "${SRCNAME}-tests ${SRCNAME} ${SRCNAME}-setup"
diff --git a/meta-openstack/recipes-devtools/python/python-trove_git.bb b/meta-openstack/recipes-devtools/python/python-trove_git.bb
index 830da92..b90e552 100755
--- a/meta-openstack/recipes-devtools/python/python-trove_git.bb
+++ b/meta-openstack/recipes-devtools/python/python-trove_git.bb
@@ -146,30 +146,29 @@ do_install_append() {
 
 pkg_postinst_${SRCNAME}-setup () {
     # python-trove-setup postinst start
-    if [ "x$D" != "x" ]; then
-        exit 1
+    if [ -z "$D" ]; then
+	source /etc/nova/openrc
+
+	# This is to make sure postgres is configured and running
+	if ! pidof postmaster > /dev/null; then
+	   /etc/init.d/postgresql-init
+	   /etc/init.d/postgresql start
+	   sleep 5
+	fi
+
+	mkdir /var/log/trove
+	# Create database for trove.
+	sudo -u postgres createdb trove
+
+	# Create default trove database.
+	trove-manage db_sync
+	# Create new datastore.
+	trove-manage datastore_update "postgresql" ""
+	# Set up new version
+	trove-manage datastore_version_update "postgresql" "9.1" "postgresql" 1 "postgresql-server-9.1" 1
+	# Set new default version.
+	trove-manage datastore_update "postgresql" "9.1"
     fi
-    source /etc/nova/openrc
-
-    # This is to make sure postgres is configured and running
-    if ! pidof postmaster > /dev/null; then
-       /etc/init.d/postgresql-init
-       /etc/init.d/postgresql start
-       sleep 5
-    fi
-
-    mkdir /var/log/trove
-    # Create database for trove.
-    sudo -u postgres createdb trove
-
-    # Create default trove database.
-    trove-manage db_sync
-    # Create new datastore.
-    trove-manage datastore_update "postgresql" ""
-    # Set up new version
-    trove-manage datastore_version_update "postgresql" "9.1" "postgresql" 1 "postgresql-server-9.1" 1
-    # Set new default version.
-    trove-manage datastore_update "postgresql" "9.1"
 }
 
 
diff --git a/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend b/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
index 22dae71..b26054e 100644
--- a/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
+++ b/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
@@ -41,14 +41,12 @@ ALLOW_EMPTY_${PN}-setup = "1"
 
 pkg_postinst_${PN}-setup () {
     # postgres 9.2.4 postinst
-    if [ "x$D" != "x" ]; then
-        exit 1
-    fi
-      
-    /etc/init.d/postgresql-init
-    if [ $? -ne 0 ]; then
-        echo "[ERROR] postgres: unable to create admin account"
-        exit 1
+    if [ -z "$D" ]; then
+	/etc/init.d/postgresql-init
+	if [ $? -ne 0 ]; then
+	    echo "[ERROR] postgres: unable to create admin account"
+	    exit 1
+	fi
     fi
 }
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [m-c-s][PATCH] python-*: fixup postinst scripts
  2017-11-15 17:59 [m-c-s][PATCH] python-*: fixup postinst scripts Mark Asselstine
@ 2017-11-15 20:54 ` Bruce Ashfield
  2017-11-15 21:10   ` Mark Asselstine
  2017-11-15 20:58 ` Richard Purdie
  1 sibling, 1 reply; 7+ messages in thread
From: Bruce Ashfield @ 2017-11-15 20:54 UTC (permalink / raw)
  To: Mark Asselstine, meta-virtualization

On 2017-11-15 12:59 PM, Mark Asselstine wrote:
> Checking for "$D" and doing an "exit 1" now results in errors such as:
> 
> [log_check] warning: %post(keystone-cronjobs-...) scriptlet failed, exit status 2
> 
> during image creation. Instead of escaping the script for "level-1"
> (image creation postinst) we wrap the "level-2" (first boot) postinst
> in an if statement. This also ensure the scriptlet in
> indentity.bbclass is less prone to behaving differently based on the
> postinsts defined in the classes which inherit 'identity'.

merged.

Bruce

> 
> Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
> ---
>   meta-openstack/classes/identity.bbclass            | 11 +++--
>   .../recipes-devtools/python/python-barbican_git.bb |  8 ++--
>   .../python/python-ceilometer_git.bb                | 24 +++++------
>   .../recipes-devtools/python/python-cinder_git.bb   | 48 ++++++++++-----------
>   .../recipes-devtools/python/python-glance_git.bb   | 24 +++++------
>   .../recipes-devtools/python/python-heat_git.bb     | 24 +++++------
>   .../recipes-devtools/python/python-keystone_git.bb | 50 +++++++++++-----------
>   .../recipes-devtools/python/python-neutron_git.bb  | 32 ++++++--------
>   .../recipes-devtools/python/python-nova_git.bb     | 42 ++++++++----------
>   .../recipes-devtools/python/python-rally_git.bb    | 28 ++++++------
>   .../recipes-devtools/python/python-swift_git.bb    | 40 ++++++++---------
>   .../recipes-devtools/python/python-trove_git.bb    | 45 ++++++++++---------
>   .../postgresql/postgresql_9.%.bbappend             | 14 +++---
>   13 files changed, 185 insertions(+), 205 deletions(-)
> 
> diff --git a/meta-openstack/classes/identity.bbclass b/meta-openstack/classes/identity.bbclass
> index c4b1394..1f4f408 100644
> --- a/meta-openstack/classes/identity.bbclass
> +++ b/meta-openstack/classes/identity.bbclass
> @@ -163,9 +163,11 @@ python populate_packages_append () {
>   
>           postinst = d.getVar('pkg_postinst_%s' % pkg, True) or d.getVar('pkg_postinst', True)
>           if not postinst:
> -            postinst = '    if [ "x$D" != "x" ]; then\n' + \
> -                       '        exit 1\n' + \
> -                       '    fi\n'
> +            postinst = ''
> +
> +        # Only execute on target. Header.
> +        postinst += '    if [ -z "$D" ]; then\n'
> +
>           postinst += servicecreate_postinst_common_copy
>   
>           if d.getVar('USERCREATE_PARAM_%s' % pkg, True):
> @@ -176,6 +178,9 @@ python populate_packages_append () {
>               servicecreate_postinst_service = servicecreate_postinst_service_copy.replace("SERVICECREATE_PARAM", servicecreate_param(d, pkg))
>               postinst += servicecreate_postinst_service
>   
> +        # Footer.
> +        postinst += '    fi\n'
> +
>           d.setVar('pkg_postinst_%s' % pkg, postinst)
>           bb.debug(1, 'pkg_postinst_%s = %s' % (pkg, d.getVar('pkg_postinst_%s' % pkg, True)))
>   }
> diff --git a/meta-openstack/recipes-devtools/python/python-barbican_git.bb b/meta-openstack/recipes-devtools/python/python-barbican_git.bb
> index 0b3d768..579413c 100644
> --- a/meta-openstack/recipes-devtools/python/python-barbican_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-barbican_git.bb
> @@ -85,12 +85,10 @@ FILES_${SRCNAME} = "${sysconfdir}/${SRCNAME}/* \
>   
>   ALLOW_EMPTY_${SRCNAME}-setup = "1"
>   pkg_postinst_${SRCNAME}-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "$D" ]; then
> +        chown -R barbican:barbican ${sysconfdir}/${SRCNAME}
> +        chown -R barbican:barbican ${localstatedir}/lib/barbican
>       fi
> -
> -    chown -R barbican:barbican ${sysconfdir}/${SRCNAME}
> -    chown -R barbican:barbican ${localstatedir}/lib/barbican
>   }
>   
>   DEPENDS += " \
> diff --git a/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb b/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb
> index 5645626..4b01022 100644
> --- a/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb
> @@ -108,20 +108,18 @@ do_install_append() {
>   }
>   
>   pkg_postinst_${SRCNAME}-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "$D" ]; then
> +        # This is to make sure postgres is configured and running
> +        if ! pidof postmaster > /dev/null; then
> +           /etc/init.d/postgresql-init
> +           /etc/init.d/postgresql start
> +           sleep 2
> +        fi
> +
> +        mkdir /var/log/ceilometer
> +        sudo -u postgres createdb ceilometer
> +        ceilometer-dbsync
>       fi
> -
> -    # This is to make sure postgres is configured and running
> -    if ! pidof postmaster > /dev/null; then
> -       /etc/init.d/postgresql-init
> -       /etc/init.d/postgresql start
> -       sleep 2
> -    fi
> -
> -    mkdir /var/log/ceilometer
> -    sudo -u postgres createdb ceilometer
> -    ceilometer-dbsync
>   }
>   
>   inherit setuptools identity hosts update-rc.d default_configs monitor
> diff --git a/meta-openstack/recipes-devtools/python/python-cinder_git.bb b/meta-openstack/recipes-devtools/python/python-cinder_git.bb
> index e70a3aa..9f70beb 100644
> --- a/meta-openstack/recipes-devtools/python/python-cinder_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-cinder_git.bb
> @@ -124,31 +124,29 @@ do_install_append() {
>   }
>   
>   pkg_postinst_${SRCNAME}-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> -    fi
> -
> -    # This is to make sure postgres is configured and running
> -    if ! pidof postmaster > /dev/null; then
> -       /etc/init.d/postgresql-init
> -       /etc/init.d/postgresql start
> -    fi
> -
> -    if [ ! -d /var/log/cinder ]; then
> -       mkdir /var/log/cinder
> -    fi
> -
> -    sudo -u postgres createdb cinder
> -    cinder-manage db sync
> -
> -    # Create Cinder nfs_share config file with default nfs server
> -    if [ ! -f /etc/cinder/nfs_shares ]; then
> -        /bin/bash /etc/cinder/drivers/nfs_setup.sh
> -    fi
> -
> -    # Create Cinder glusterfs_share config file with default glusterfs server
> -    if [ ! -f /etc/cinder/glusterfs_shares ] && [ -f /usr/sbin/glusterfsd ]; then
> -        /bin/bash /etc/cinder/drivers/glusterfs_setup.sh
> +    if [ -z "$D" ]; then
> +	 # This is to make sure postgres is configured and running
> +	 if ! pidof postmaster > /dev/null; then
> +	    /etc/init.d/postgresql-init
> +	    /etc/init.d/postgresql start
> +	 fi
> +
> +	 if [ ! -d /var/log/cinder ]; then
> +	    mkdir /var/log/cinder
> +	 fi
> +
> +	 sudo -u postgres createdb cinder
> +	 cinder-manage db sync
> +
> +	 # Create Cinder nfs_share config file with default nfs server
> +	 if [ ! -f /etc/cinder/nfs_shares ]; then
> +	     /bin/bash /etc/cinder/drivers/nfs_setup.sh
> +	 fi
> +
> +	 # Create Cinder glusterfs_share config file with default glusterfs server
> +	 if [ ! -f /etc/cinder/glusterfs_shares ] && [ -f /usr/sbin/glusterfsd ]; then
> +	     /bin/bash /etc/cinder/drivers/glusterfs_setup.sh
> +	 fi
>       fi
>   }
>   
> diff --git a/meta-openstack/recipes-devtools/python/python-glance_git.bb b/meta-openstack/recipes-devtools/python/python-glance_git.bb
> index 27c33b9..4042f1b 100644
> --- a/meta-openstack/recipes-devtools/python/python-glance_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-glance_git.bb
> @@ -122,20 +122,18 @@ do_install_append() {
>   }
>   
>   pkg_postinst_${SRCNAME}-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "$D" ]; then
> +	# This is to make sure postgres is configured and running
> +	if ! pidof postmaster > /dev/null; then
> +	   /etc/init.d/postgresql-init
> +	   /etc/init.d/postgresql start
> +	   sleep 5
> +	fi
> +
> +	mkdir /var/log/glance
> +	sudo -u postgres createdb glance
> +	glance-manage db_sync
>       fi
> -
> -    # This is to make sure postgres is configured and running
> -    if ! pidof postmaster > /dev/null; then
> -       /etc/init.d/postgresql-init
> -       /etc/init.d/postgresql start
> -       sleep 5
> -    fi
> -
> -    mkdir /var/log/glance
> -    sudo -u postgres createdb glance
> -    glance-manage db_sync
>   }
>   
>   PACKAGES += " ${SRCNAME}-tests ${SRCNAME} ${SRCNAME}-setup ${SRCNAME}-api ${SRCNAME}-registry"
> diff --git a/meta-openstack/recipes-devtools/python/python-heat_git.bb b/meta-openstack/recipes-devtools/python/python-heat_git.bb
> index cccaf0a..2cf7ce4 100644
> --- a/meta-openstack/recipes-devtools/python/python-heat_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-heat_git.bb
> @@ -107,20 +107,18 @@ do_install_append() {
>   }
>   
>   pkg_postinst_${SRCNAME}-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "$D" ]; then
> +	# This is to make sure postgres is configured and running
> +	if ! pidof postmaster > /dev/null; then
> +	   /etc/init.d/postgresql-init
> +	   /etc/init.d/postgresql start
> +	   sleep 2
> +	fi
> +
> +	mkdir /var/log/heat
> +	sudo -u postgres createdb heat
> +	heat-manage db_sync
>       fi
> -
> -    # This is to make sure postgres is configured and running
> -    if ! pidof postmaster > /dev/null; then
> -       /etc/init.d/postgresql-init
> -       /etc/init.d/postgresql start
> -       sleep 2
> -    fi
> -
> -    mkdir /var/log/heat
> -    sudo -u postgres createdb heat
> -    heat-manage db_sync
>   }
>   
>   inherit setuptools identity hosts update-rc.d default_configs monitor
> diff --git a/meta-openstack/recipes-devtools/python/python-keystone_git.bb b/meta-openstack/recipes-devtools/python/python-keystone_git.bb
> index 79bd0c8..a26c9bf 100644
> --- a/meta-openstack/recipes-devtools/python/python-keystone_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-keystone_git.bb
> @@ -189,28 +189,26 @@ role_tree_dn = ou=Roles,${LDAP_DN} \
>   
>   pkg_postinst_${SRCNAME}-setup () {
>       # python-keystone postinst start
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> -    fi
> -
> -    # This is to make sure postgres is configured and running
> -    if ! pidof postmaster > /dev/null; then
> -        /etc/init.d/postgresql-init
> -        /etc/init.d/postgresql start
> -        sleep 2
> -    fi
> -
> -    # This is to make sure keystone is configured and running
> -    PIDFILE="/var/run/keystone-all.pid"
> -    if [ -z `cat $PIDFILE 2>/dev/null` ]; then
> -        sudo -u postgres createdb keystone
> -        keystone-manage db_sync
> -        keystone-manage pki_setup --keystone-user=root --keystone-group=daemon
> -
> -        if ${@bb.utils.contains('DISTRO_FEATURES', 'OpenLDAP', 'true', 'false', d)}; then
> -            /etc/init.d/openldap start
> -        fi
> -        /etc/init.d/keystone start
> +    if [ -z "$D" ]; then
> +	# This is to make sure postgres is configured and running
> +	if ! pidof postmaster > /dev/null; then
> +	    /etc/init.d/postgresql-init
> +	    /etc/init.d/postgresql start
> +	    sleep 2
> +	fi
> +
> +	# This is to make sure keystone is configured and running
> +	PIDFILE="/var/run/keystone-all.pid"
> +	if [ -z `cat $PIDFILE 2>/dev/null` ]; then
> +	    sudo -u postgres createdb keystone
> +	    keystone-manage db_sync
> +	    keystone-manage pki_setup --keystone-user=root --keystone-group=daemon
> +
> +	    if ${@bb.utils.contains('DISTRO_FEATURES', 'OpenLDAP', 'true', 'false', d)}; then
> +		/etc/init.d/openldap start
> +	    fi
> +	    /etc/init.d/keystone start
> +	fi
>       fi
>   }
>   
> @@ -219,9 +217,11 @@ pkg_postinst_${SRCNAME}-setup () {
>   KEYSTONE_TOKEN_FLUSH_TIME ??= "0 0 */2 * *"
>   
>   pkg_postinst_${SRCNAME}-cronjobs () {
> -    # By default keystone expired tokens are not automatic removed out of the
> -    # database.  So we create a cronjob for cleaning these expired tokens.
> -    echo "${KEYSTONE_TOKEN_FLUSH_TIME} root /usr/bin/keystone-manage token_flush" >> /etc/crontab
> +    if [ -z "$D" ]; then
> +	# By default keystone expired tokens are not automatic removed out of the
> +	# database.  So we create a cronjob for cleaning these expired tokens.
> +	echo "${KEYSTONE_TOKEN_FLUSH_TIME} root /usr/bin/keystone-manage token_flush" >> /etc/crontab
> +    fi
>   }
>   
>   PACKAGES += " ${SRCNAME}-tests ${SRCNAME} ${SRCNAME}-setup ${SRCNAME}-cronjobs"
> diff --git a/meta-openstack/recipes-devtools/python/python-neutron_git.bb b/meta-openstack/recipes-devtools/python/python-neutron_git.bb
> index 51c2ac4..c837401 100644
> --- a/meta-openstack/recipes-devtools/python/python-neutron_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-neutron_git.bb
> @@ -138,29 +138,25 @@ do_install_append() {
>   }
>   
>   pkg_postinst_${SRCNAME}-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "$D" ]; then
> +	# This is to make sure postgres is configured and running
> +	if ! pidof postmaster > /dev/null; then
> +	    /etc/init.d/postgresql-init
> +	    /etc/init.d/postgresql start
> +	    sleep 2
> +	fi
> +
> +	sudo -u postgres createdb neutron
> +	sudo neutron-db-manage --config-file /etc/neutron/neutron.conf  \
> +			       --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head
>       fi
> -
> -    # This is to make sure postgres is configured and running
> -    if ! pidof postmaster > /dev/null; then
> -        /etc/init.d/postgresql-init
> -        /etc/init.d/postgresql start
> -        sleep 2
> -    fi
> -
> -    sudo -u postgres createdb neutron
> -    sudo neutron-db-manage --config-file /etc/neutron/neutron.conf  \
> -                           --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head
>   }
>   
>   pkg_postinst_${SRCNAME}-plugin-openvswitch-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "$D" ]; then
> +	/etc/init.d/openvswitch-switch start
> +	ovs-vsctl --no-wait -- --may-exist add-br br-int
>       fi
> -
> -    /etc/init.d/openvswitch-switch start
> -    ovs-vsctl --no-wait -- --may-exist add-br br-int
>   }
>   
>   ALLOW_EMPTY_${SRCNAME}-setup = "1"
> diff --git a/meta-openstack/recipes-devtools/python/python-nova_git.bb b/meta-openstack/recipes-devtools/python/python-nova_git.bb
> index f3a6b86..7b560a7 100644
> --- a/meta-openstack/recipes-devtools/python/python-nova_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-nova_git.bb
> @@ -160,33 +160,29 @@ do_install_append() {
>   }
>   
>   pkg_postinst_${SRCNAME}-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "$D" ]; then
> +	# This is to make sure postgres is configured and running
> +	if ! pidof postmaster > /dev/null; then
> +	   /etc/init.d/postgresql-init
> +	   /etc/init.d/postgresql start
> +	   sleep 5
> +	fi
> +
> +	sudo -u postgres createdb nova
> +	sleep 2
> +	nova-manage db sync
>       fi
> -
> -    # This is to make sure postgres is configured and running
> -    if ! pidof postmaster > /dev/null; then
> -       /etc/init.d/postgresql-init
> -       /etc/init.d/postgresql start
> -       sleep 5
> -    fi
> -
> -    sudo -u postgres createdb nova
> -    sleep 2
> -    nova-manage db sync
>   }
>   
>   pkg_postinst_${SRCNAME}-common () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> -    fi
> -
> -    if [ -d  /home/root ]; then
> -        echo "source /etc/nova/openrc" >> /home/root/.bashrc
> -	echo "source /etc/nova/openrc" >> /home/root/.profile
> -    else
> -        echo "source /etc/nova/openrc" >> /root/.bashrc
> -	echo "source /etc/nova/openrc" >> /root/.profile
> +    if [ -z "$D" ]; then
> +	if [ -d  /home/root ]; then
> +	    echo "source /etc/nova/openrc" >> /home/root/.bashrc
> +	    echo "source /etc/nova/openrc" >> /home/root/.profile
> +	else
> +	    echo "source /etc/nova/openrc" >> /root/.bashrc
> +	    echo "source /etc/nova/openrc" >> /root/.profile
> +	fi
>       fi
>   }
>   
> diff --git a/meta-openstack/recipes-devtools/python/python-rally_git.bb b/meta-openstack/recipes-devtools/python/python-rally_git.bb
> index d29e7cb..31d4242 100644
> --- a/meta-openstack/recipes-devtools/python/python-rally_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-rally_git.bb
> @@ -63,22 +63,20 @@ do_install_append() {
>   }
>   
>   pkg_postinst_${SRCNAME}-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "$D" ]; then
> +	# This is to make sure postgres is configured and running
> +	if ! pidof postmaster > /dev/null; then
> +	   /etc/init.d/postgresql-init
> +	   /etc/init.d/postgresql start
> +	fi
> +
> +	if [ ! -d /var/log/rally ]; then
> +	   mkdir /var/log/rally
> +	fi
> +
> +	sudo -u postgres createdb rally
> +	rally-manage db recreate
>       fi
> -
> -    # This is to make sure postgres is configured and running
> -    if ! pidof postmaster > /dev/null; then
> -       /etc/init.d/postgresql-init
> -       /etc/init.d/postgresql start
> -    fi
> -
> -    if [ ! -d /var/log/rally ]; then
> -       mkdir /var/log/rally
> -    fi
> -
> -    sudo -u postgres createdb rally
> -    rally-manage db recreate
>   }
>   
>   PACKAGES += "${SRCNAME}-tests ${SRCNAME}-api ${SRCNAME} ${SRCNAME}-setup"
> diff --git a/meta-openstack/recipes-devtools/python/python-swift_git.bb b/meta-openstack/recipes-devtools/python/python-swift_git.bb
> index 8552ea7..fc7c258 100644
> --- a/meta-openstack/recipes-devtools/python/python-swift_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-swift_git.bb
> @@ -109,28 +109,26 @@ do_install_append() {
>   }
>   
>   pkg_postinst_${SRCNAME}-setup () {
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "x$D" ]; then
> +	CLUSTER_CONF=/etc/swift/cluster.conf
> +	SWIFT_SETUP='/bin/bash /etc/swift/swift_setup.sh'
> +
> +	for i in `seq 1 3`; do
> +	    BACKING_FILE=/etc/swift/swift_backing_$i
> +	    if [ "x${SWIFT_BACKING_FILE_SIZE}" != "x0G" ]; then
> +		truncate -s ${SWIFT_BACKING_FILE_SIZE} $BACKING_FILE
> +		sed "s:%SWIFT_BACKING_FILE_${i}%:$BACKING_FILE:g" -i $CLUSTER_CONF
> +	    else
> +		sed "s:%SWIFT_BACKING_FILE_${i}%::g" -i $CLUSTER_CONF
> +	    fi
> +	done
> +
> +	$SWIFT_SETUP createrings
> +	$SWIFT_SETUP formatdevs
> +	$SWIFT_SETUP mountdevs
> +	$SWIFT_SETUP -i "${CONTROLLER_IP}" adddevs
> +	$SWIFT_SETUP unmountdevs
>       fi
> -
> -    CLUSTER_CONF=/etc/swift/cluster.conf
> -    SWIFT_SETUP='/bin/bash /etc/swift/swift_setup.sh'
> -
> -    for i in `seq 1 3`; do
> -        BACKING_FILE=/etc/swift/swift_backing_$i
> -        if [ "x${SWIFT_BACKING_FILE_SIZE}" != "x0G" ]; then
> -            truncate -s ${SWIFT_BACKING_FILE_SIZE} $BACKING_FILE
> -            sed "s:%SWIFT_BACKING_FILE_${i}%:$BACKING_FILE:g" -i $CLUSTER_CONF
> -        else
> -            sed "s:%SWIFT_BACKING_FILE_${i}%::g" -i $CLUSTER_CONF
> -        fi
> -    done
> -
> -    $SWIFT_SETUP createrings
> -    $SWIFT_SETUP formatdevs
> -    $SWIFT_SETUP mountdevs
> -    $SWIFT_SETUP -i "${CONTROLLER_IP}" adddevs
> -    $SWIFT_SETUP unmountdevs
>   }
>   
>   PACKAGES += "${SRCNAME}-tests ${SRCNAME} ${SRCNAME}-setup"
> diff --git a/meta-openstack/recipes-devtools/python/python-trove_git.bb b/meta-openstack/recipes-devtools/python/python-trove_git.bb
> index 830da92..b90e552 100755
> --- a/meta-openstack/recipes-devtools/python/python-trove_git.bb
> +++ b/meta-openstack/recipes-devtools/python/python-trove_git.bb
> @@ -146,30 +146,29 @@ do_install_append() {
>   
>   pkg_postinst_${SRCNAME}-setup () {
>       # python-trove-setup postinst start
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> +    if [ -z "$D" ]; then
> +	source /etc/nova/openrc
> +
> +	# This is to make sure postgres is configured and running
> +	if ! pidof postmaster > /dev/null; then
> +	   /etc/init.d/postgresql-init
> +	   /etc/init.d/postgresql start
> +	   sleep 5
> +	fi
> +
> +	mkdir /var/log/trove
> +	# Create database for trove.
> +	sudo -u postgres createdb trove
> +
> +	# Create default trove database.
> +	trove-manage db_sync
> +	# Create new datastore.
> +	trove-manage datastore_update "postgresql" ""
> +	# Set up new version
> +	trove-manage datastore_version_update "postgresql" "9.1" "postgresql" 1 "postgresql-server-9.1" 1
> +	# Set new default version.
> +	trove-manage datastore_update "postgresql" "9.1"
>       fi
> -    source /etc/nova/openrc
> -
> -    # This is to make sure postgres is configured and running
> -    if ! pidof postmaster > /dev/null; then
> -       /etc/init.d/postgresql-init
> -       /etc/init.d/postgresql start
> -       sleep 5
> -    fi
> -
> -    mkdir /var/log/trove
> -    # Create database for trove.
> -    sudo -u postgres createdb trove
> -
> -    # Create default trove database.
> -    trove-manage db_sync
> -    # Create new datastore.
> -    trove-manage datastore_update "postgresql" ""
> -    # Set up new version
> -    trove-manage datastore_version_update "postgresql" "9.1" "postgresql" 1 "postgresql-server-9.1" 1
> -    # Set new default version.
> -    trove-manage datastore_update "postgresql" "9.1"
>   }
>   
>   
> diff --git a/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend b/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
> index 22dae71..b26054e 100644
> --- a/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
> +++ b/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
> @@ -41,14 +41,12 @@ ALLOW_EMPTY_${PN}-setup = "1"
>   
>   pkg_postinst_${PN}-setup () {
>       # postgres 9.2.4 postinst
> -    if [ "x$D" != "x" ]; then
> -        exit 1
> -    fi
> -
> -    /etc/init.d/postgresql-init
> -    if [ $? -ne 0 ]; then
> -        echo "[ERROR] postgres: unable to create admin account"
> -        exit 1
> +    if [ -z "$D" ]; then
> +	/etc/init.d/postgresql-init
> +	if [ $? -ne 0 ]; then
> +	    echo "[ERROR] postgres: unable to create admin account"
> +	    exit 1
> +	fi
>       fi
>   }
>   
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m-c-s][PATCH] python-*: fixup postinst scripts
  2017-11-15 17:59 [m-c-s][PATCH] python-*: fixup postinst scripts Mark Asselstine
  2017-11-15 20:54 ` Bruce Ashfield
@ 2017-11-15 20:58 ` Richard Purdie
  2017-11-15 21:08   ` Mark Asselstine
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Purdie @ 2017-11-15 20:58 UTC (permalink / raw)
  To: Mark Asselstine, meta-virtualization, bruce.ashfield

On Wed, 2017-11-15 at 12:59 -0500, Mark Asselstine wrote:
> Checking for "$D" and doing an "exit 1" now results in errors such
> as:
> 
> [log_check] warning: %post(keystone-cronjobs-...) scriptlet failed,
> exit status 2
> 
> during image creation. Instead of escaping the script for "level-1"
> (image creation postinst) we wrap the "level-2" (first boot) postinst
> in an if statement. This also ensure the scriptlet in
> indentity.bbclass is less prone to behaving differently based on the
> postinsts defined in the classes which inherit 'identity'.

I think this could mean the postinst doesn't get executed at all if
there isn't an exit 1, else how would it know to defer to first boot?

Cheers,

Richard


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m-c-s][PATCH] python-*: fixup postinst scripts
  2017-11-15 20:58 ` Richard Purdie
@ 2017-11-15 21:08   ` Mark Asselstine
  2017-11-15 21:09     ` Bruce Ashfield
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Asselstine @ 2017-11-15 21:08 UTC (permalink / raw)
  To: Richard Purdie; +Cc: bruce.ashfield, meta-virtualization

On Wednesday, November 15, 2017 8:58:36 PM EST Richard Purdie wrote:
> On Wed, 2017-11-15 at 12:59 -0500, Mark Asselstine wrote:
> > Checking for "$D" and doing an "exit 1" now results in errors such
> > as:
> > 
> > [log_check] warning: %post(keystone-cronjobs-...) scriptlet failed,
> > exit status 2
> > 
> > during image creation. Instead of escaping the script for "level-1"
> > (image creation postinst) we wrap the "level-2" (first boot) postinst
> > in an if statement. This also ensure the scriptlet in
> > indentity.bbclass is less prone to behaving differently based on the
> > postinsts defined in the classes which inherit 'identity'.
> 
> I think this could mean the postinst doesn't get executed at all if
> there isn't an exit 1, else how would it know to defer to first boot?

Every time I touch the postinst I admittedly end up in a knot. I was 
inspecting the rpm scripts and all seemed well but I will take another look to 
ensure I am not being a dolt.

Either way thanks for the nudge Richard. Bruce hold off on this one for now. I 
have so many little and big changes to get m-c-s back up to snuff I am better 
off taking the time to ensure I am not messing something up.

Mark

> 
> Cheers,
> 
> Richard




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m-c-s][PATCH] python-*: fixup postinst scripts
  2017-11-15 21:08   ` Mark Asselstine
@ 2017-11-15 21:09     ` Bruce Ashfield
  2017-11-15 22:01       ` Mark Asselstine
  0 siblings, 1 reply; 7+ messages in thread
From: Bruce Ashfield @ 2017-11-15 21:09 UTC (permalink / raw)
  To: Mark Asselstine, Richard Purdie; +Cc: meta-virtualization

On 2017-11-15 4:08 PM, Mark Asselstine wrote:
> On Wednesday, November 15, 2017 8:58:36 PM EST Richard Purdie wrote:
>> On Wed, 2017-11-15 at 12:59 -0500, Mark Asselstine wrote:
>>> Checking for "$D" and doing an "exit 1" now results in errors such
>>> as:
>>>
>>> [log_check] warning: %post(keystone-cronjobs-...) scriptlet failed,
>>> exit status 2
>>>
>>> during image creation. Instead of escaping the script for "level-1"
>>> (image creation postinst) we wrap the "level-2" (first boot) postinst
>>> in an if statement. This also ensure the scriptlet in
>>> indentity.bbclass is less prone to behaving differently based on the
>>> postinsts defined in the classes which inherit 'identity'.
>>
>> I think this could mean the postinst doesn't get executed at all if
>> there isn't an exit 1, else how would it know to defer to first boot?
> 
> Every time I touch the postinst I admittedly end up in a knot. I was
> inspecting the rpm scripts and all seemed well but I will take another look to
> ensure I am not being a dolt.
> 
> Either way thanks for the nudge Richard. Bruce hold off on this one for now. I
> have so many little and big changes to get m-c-s back up to snuff I am better
> off taking the time to ensure I am not messing something up.

hah. I already merged this one, so rebase and send any fixups.

Bruce

> 
> Mark
> 
>>
>> Cheers,
>>
>> Richard
> 
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m-c-s][PATCH] python-*: fixup postinst scripts
  2017-11-15 20:54 ` Bruce Ashfield
@ 2017-11-15 21:10   ` Mark Asselstine
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Asselstine @ 2017-11-15 21:10 UTC (permalink / raw)
  To: Bruce Ashfield; +Cc: meta-virtualization

On Wednesday, November 15, 2017 3:54:01 PM EST Bruce Ashfield wrote:
> On 2017-11-15 12:59 PM, Mark Asselstine wrote:
> > Checking for "$D" and doing an "exit 1" now results in errors such as:
> > 
> > [log_check] warning: %post(keystone-cronjobs-...) scriptlet failed, exit
> > status 2
> > 
> > during image creation. Instead of escaping the script for "level-1"
> > (image creation postinst) we wrap the "level-2" (first boot) postinst
> > in an if statement. This also ensure the scriptlet in
> > indentity.bbclass is less prone to behaving differently based on the
> > postinsts defined in the classes which inherit 'identity'.
> 
> merged.

I am reading my email in reverse. So you will see my note about not merging 
this one after the nudge from Richard. No matter I will use this as the new 
baseline. Nobody can use this stuff currently so no harm in this merge.

Mark

> 
> Bruce
> 
> > Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com>
> > ---
> > 
> >   meta-openstack/classes/identity.bbclass            | 11 +++--
> >   .../recipes-devtools/python/python-barbican_git.bb |  8 ++--
> >   .../python/python-ceilometer_git.bb                | 24 +++++------
> >   .../recipes-devtools/python/python-cinder_git.bb   | 48
> >   ++++++++++----------- .../recipes-devtools/python/python-glance_git.bb 
> >    | 24 +++++------ .../recipes-devtools/python/python-heat_git.bb     |
> >   24 +++++------ .../recipes-devtools/python/python-keystone_git.bb | 50
> >   +++++++++++-----------
> >   .../recipes-devtools/python/python-neutron_git.bb  | 32 ++++++--------
> >   .../recipes-devtools/python/python-nova_git.bb     | 42
> >   ++++++++---------- .../recipes-devtools/python/python-rally_git.bb    |
> >   28 ++++++------ .../recipes-devtools/python/python-swift_git.bb    | 40
> >   ++++++++--------- .../recipes-devtools/python/python-trove_git.bb    |
> >   45 ++++++++++--------- .../postgresql/postgresql_9.%.bbappend          
> >     | 14 +++---
> >   13 files changed, 185 insertions(+), 205 deletions(-)
> > 
> > diff --git a/meta-openstack/classes/identity.bbclass
> > b/meta-openstack/classes/identity.bbclass index c4b1394..1f4f408 100644
> > --- a/meta-openstack/classes/identity.bbclass
> > +++ b/meta-openstack/classes/identity.bbclass
> > @@ -163,9 +163,11 @@ python populate_packages_append () {
> > 
> >           postinst = d.getVar('pkg_postinst_%s' % pkg, True) or
> >           d.getVar('pkg_postinst', True)> 
> >           if not postinst:
> > -            postinst = '    if [ "x$D" != "x" ]; then\n' + \
> > -                       '        exit 1\n' + \
> > -                       '    fi\n'
> > +            postinst = ''
> > +
> > +        # Only execute on target. Header.
> > +        postinst += '    if [ -z "$D" ]; then\n'
> > +
> > 
> >           postinst += servicecreate_postinst_common_copy
> > 
> >           if d.getVar('USERCREATE_PARAM_%s' % pkg, True):
> > @@ -176,6 +178,9 @@ python populate_packages_append () {
> > 
> >               servicecreate_postinst_service =
> >               servicecreate_postinst_service_copy.replace("SERVICECREATE_
> >               PARAM", servicecreate_param(d, pkg)) postinst +=
> >               servicecreate_postinst_service
> > 
> > +        # Footer.
> > +        postinst += '    fi\n'
> > +
> > 
> >           d.setVar('pkg_postinst_%s' % pkg, postinst)
> >           bb.debug(1, 'pkg_postinst_%s = %s' % (pkg,
> >           d.getVar('pkg_postinst_%s' % pkg, True)))>   
> >   }
> > 
> > diff --git a/meta-openstack/recipes-devtools/python/python-barbican_git.bb
> > b/meta-openstack/recipes-devtools/python/python-barbican_git.bb index
> > 0b3d768..579413c 100644
> > --- a/meta-openstack/recipes-devtools/python/python-barbican_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-barbican_git.bb
> > @@ -85,12 +85,10 @@ FILES_${SRCNAME} = "${sysconfdir}/${SRCNAME}/* \
> > 
> >   ALLOW_EMPTY_${SRCNAME}-setup = "1"
> >   pkg_postinst_${SRCNAME}-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +        chown -R barbican:barbican ${sysconfdir}/${SRCNAME}
> > +        chown -R barbican:barbican ${localstatedir}/lib/barbican
> > 
> >       fi
> > 
> > -
> > -    chown -R barbican:barbican ${sysconfdir}/${SRCNAME}
> > -    chown -R barbican:barbican ${localstatedir}/lib/barbican
> > 
> >   }
> >   
> >   DEPENDS += " \
> > 
> > diff --git
> > a/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb
> > b/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb index
> > 5645626..4b01022 100644
> > --- a/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-ceilometer_git.bb
> > @@ -108,20 +108,18 @@ do_install_append() {
> > 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +        # This is to make sure postgres is configured and running
> > +        if ! pidof postmaster > /dev/null; then
> > +           /etc/init.d/postgresql-init
> > +           /etc/init.d/postgresql start
> > +           sleep 2
> > +        fi
> > +
> > +        mkdir /var/log/ceilometer
> > +        sudo -u postgres createdb ceilometer
> > +        ceilometer-dbsync
> > 
> >       fi
> > 
> > -
> > -    # This is to make sure postgres is configured and running
> > -    if ! pidof postmaster > /dev/null; then
> > -       /etc/init.d/postgresql-init
> > -       /etc/init.d/postgresql start
> > -       sleep 2
> > -    fi
> > -
> > -    mkdir /var/log/ceilometer
> > -    sudo -u postgres createdb ceilometer
> > -    ceilometer-dbsync
> > 
> >   }
> >   
> >   inherit setuptools identity hosts update-rc.d default_configs monitor
> > 
> > diff --git a/meta-openstack/recipes-devtools/python/python-cinder_git.bb
> > b/meta-openstack/recipes-devtools/python/python-cinder_git.bb index
> > e70a3aa..9f70beb 100644
> > --- a/meta-openstack/recipes-devtools/python/python-cinder_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-cinder_git.bb
> > @@ -124,31 +124,29 @@ do_install_append() {
> > 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > -    fi
> > -
> > -    # This is to make sure postgres is configured and running
> > -    if ! pidof postmaster > /dev/null; then
> > -       /etc/init.d/postgresql-init
> > -       /etc/init.d/postgresql start
> > -    fi
> > -
> > -    if [ ! -d /var/log/cinder ]; then
> > -       mkdir /var/log/cinder
> > -    fi
> > -
> > -    sudo -u postgres createdb cinder
> > -    cinder-manage db sync
> > -
> > -    # Create Cinder nfs_share config file with default nfs server
> > -    if [ ! -f /etc/cinder/nfs_shares ]; then
> > -        /bin/bash /etc/cinder/drivers/nfs_setup.sh
> > -    fi
> > -
> > -    # Create Cinder glusterfs_share config file with default glusterfs
> > server -    if [ ! -f /etc/cinder/glusterfs_shares ] && [ -f
> > /usr/sbin/glusterfsd ]; then -        /bin/bash
> > /etc/cinder/drivers/glusterfs_setup.sh
> > +    if [ -z "$D" ]; then
> > +	 # This is to make sure postgres is configured and running
> > +	 if ! pidof postmaster > /dev/null; then
> > +	    /etc/init.d/postgresql-init
> > +	    /etc/init.d/postgresql start
> > +	 fi
> > +
> > +	 if [ ! -d /var/log/cinder ]; then
> > +	    mkdir /var/log/cinder
> > +	 fi
> > +
> > +	 sudo -u postgres createdb cinder
> > +	 cinder-manage db sync
> > +
> > +	 # Create Cinder nfs_share config file with default nfs server
> > +	 if [ ! -f /etc/cinder/nfs_shares ]; then
> > +	     /bin/bash /etc/cinder/drivers/nfs_setup.sh
> > +	 fi
> > +
> > +	 # Create Cinder glusterfs_share config file with default glusterfs
> > server +	 if [ ! -f /etc/cinder/glusterfs_shares ] && [ -f
> > /usr/sbin/glusterfsd ]; then +	     /bin/bash
> > /etc/cinder/drivers/glusterfs_setup.sh
> > +	 fi
> > 
> >       fi
> >   
> >   }
> > 
> > diff --git a/meta-openstack/recipes-devtools/python/python-glance_git.bb
> > b/meta-openstack/recipes-devtools/python/python-glance_git.bb index
> > 27c33b9..4042f1b 100644
> > --- a/meta-openstack/recipes-devtools/python/python-glance_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-glance_git.bb
> > @@ -122,20 +122,18 @@ do_install_append() {
> > 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +	# This is to make sure postgres is configured and running
> > +	if ! pidof postmaster > /dev/null; then
> > +	   /etc/init.d/postgresql-init
> > +	   /etc/init.d/postgresql start
> > +	   sleep 5
> > +	fi
> > +
> > +	mkdir /var/log/glance
> > +	sudo -u postgres createdb glance
> > +	glance-manage db_sync
> > 
> >       fi
> > 
> > -
> > -    # This is to make sure postgres is configured and running
> > -    if ! pidof postmaster > /dev/null; then
> > -       /etc/init.d/postgresql-init
> > -       /etc/init.d/postgresql start
> > -       sleep 5
> > -    fi
> > -
> > -    mkdir /var/log/glance
> > -    sudo -u postgres createdb glance
> > -    glance-manage db_sync
> > 
> >   }
> >   
> >   PACKAGES += " ${SRCNAME}-tests ${SRCNAME} ${SRCNAME}-setup
> >   ${SRCNAME}-api ${SRCNAME}-registry"> 
> > diff --git a/meta-openstack/recipes-devtools/python/python-heat_git.bb
> > b/meta-openstack/recipes-devtools/python/python-heat_git.bb index
> > cccaf0a..2cf7ce4 100644
> > --- a/meta-openstack/recipes-devtools/python/python-heat_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-heat_git.bb
> > @@ -107,20 +107,18 @@ do_install_append() {
> > 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +	# This is to make sure postgres is configured and running
> > +	if ! pidof postmaster > /dev/null; then
> > +	   /etc/init.d/postgresql-init
> > +	   /etc/init.d/postgresql start
> > +	   sleep 2
> > +	fi
> > +
> > +	mkdir /var/log/heat
> > +	sudo -u postgres createdb heat
> > +	heat-manage db_sync
> > 
> >       fi
> > 
> > -
> > -    # This is to make sure postgres is configured and running
> > -    if ! pidof postmaster > /dev/null; then
> > -       /etc/init.d/postgresql-init
> > -       /etc/init.d/postgresql start
> > -       sleep 2
> > -    fi
> > -
> > -    mkdir /var/log/heat
> > -    sudo -u postgres createdb heat
> > -    heat-manage db_sync
> > 
> >   }
> >   
> >   inherit setuptools identity hosts update-rc.d default_configs monitor
> > 
> > diff --git a/meta-openstack/recipes-devtools/python/python-keystone_git.bb
> > b/meta-openstack/recipes-devtools/python/python-keystone_git.bb index
> > 79bd0c8..a26c9bf 100644
> > --- a/meta-openstack/recipes-devtools/python/python-keystone_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-keystone_git.bb
> > @@ -189,28 +189,26 @@ role_tree_dn = ou=Roles,${LDAP_DN} \
> > 
> >   pkg_postinst_${SRCNAME}-setup () {
> >   
> >       # python-keystone postinst start
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > -    fi
> > -
> > -    # This is to make sure postgres is configured and running
> > -    if ! pidof postmaster > /dev/null; then
> > -        /etc/init.d/postgresql-init
> > -        /etc/init.d/postgresql start
> > -        sleep 2
> > -    fi
> > -
> > -    # This is to make sure keystone is configured and running
> > -    PIDFILE="/var/run/keystone-all.pid"
> > -    if [ -z `cat $PIDFILE 2>/dev/null` ]; then
> > -        sudo -u postgres createdb keystone
> > -        keystone-manage db_sync
> > -        keystone-manage pki_setup --keystone-user=root
> > --keystone-group=daemon -
> > -        if ${@bb.utils.contains('DISTRO_FEATURES', 'OpenLDAP', 'true',
> > 'false', d)}; then -            /etc/init.d/openldap start
> > -        fi
> > -        /etc/init.d/keystone start
> > +    if [ -z "$D" ]; then
> > +	# This is to make sure postgres is configured and running
> > +	if ! pidof postmaster > /dev/null; then
> > +	    /etc/init.d/postgresql-init
> > +	    /etc/init.d/postgresql start
> > +	    sleep 2
> > +	fi
> > +
> > +	# This is to make sure keystone is configured and running
> > +	PIDFILE="/var/run/keystone-all.pid"
> > +	if [ -z `cat $PIDFILE 2>/dev/null` ]; then
> > +	    sudo -u postgres createdb keystone
> > +	    keystone-manage db_sync
> > +	    keystone-manage pki_setup --keystone-user=root
> > --keystone-group=daemon +
> > +	    if ${@bb.utils.contains('DISTRO_FEATURES', 'OpenLDAP', 'true',
> > 'false', d)}; then +		/etc/init.d/openldap start
> > +	    fi
> > +	    /etc/init.d/keystone start
> > +	fi
> > 
> >       fi
> >   
> >   }
> > 
> > @@ -219,9 +217,11 @@ pkg_postinst_${SRCNAME}-setup () {
> > 
> >   KEYSTONE_TOKEN_FLUSH_TIME ??= "0 0 */2 * *"
> >   
> >   pkg_postinst_${SRCNAME}-cronjobs () {
> > 
> > -    # By default keystone expired tokens are not automatic removed out of
> > the -    # database.  So we create a cronjob for cleaning these expired
> > tokens. -    echo "${KEYSTONE_TOKEN_FLUSH_TIME} root
> > /usr/bin/keystone-manage token_flush" >> /etc/crontab +    if [ -z "$D"
> > ]; then
> > +	# By default keystone expired tokens are not automatic removed out of
> > the
> > +	# database.  So we create a cronjob for cleaning these expired 
tokens.
> > +	echo "${KEYSTONE_TOKEN_FLUSH_TIME} root /usr/bin/keystone-manage
> > token_flush" >> /etc/crontab +    fi
> > 
> >   }
> >   
> >   PACKAGES += " ${SRCNAME}-tests ${SRCNAME} ${SRCNAME}-setup
> >   ${SRCNAME}-cronjobs"> 
> > diff --git a/meta-openstack/recipes-devtools/python/python-neutron_git.bb
> > b/meta-openstack/recipes-devtools/python/python-neutron_git.bb index
> > 51c2ac4..c837401 100644
> > --- a/meta-openstack/recipes-devtools/python/python-neutron_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-neutron_git.bb
> > @@ -138,29 +138,25 @@ do_install_append() {
> > 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +	# This is to make sure postgres is configured and running
> > +	if ! pidof postmaster > /dev/null; then
> > +	    /etc/init.d/postgresql-init
> > +	    /etc/init.d/postgresql start
> > +	    sleep 2
> > +	fi
> > +
> > +	sudo -u postgres createdb neutron
> > +	sudo neutron-db-manage --config-file /etc/neutron/neutron.conf  \
> > +			       --config-file /etc/neutron/plugins/ml2/ml2_conf.ini 
upgrade
> > head
> > 
> >       fi
> > 
> > -
> > -    # This is to make sure postgres is configured and running
> > -    if ! pidof postmaster > /dev/null; then
> > -        /etc/init.d/postgresql-init
> > -        /etc/init.d/postgresql start
> > -        sleep 2
> > -    fi
> > -
> > -    sudo -u postgres createdb neutron
> > -    sudo neutron-db-manage --config-file /etc/neutron/neutron.conf  \
> > -                           --config-file
> > /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head> 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-plugin-openvswitch-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +	/etc/init.d/openvswitch-switch start
> > +	ovs-vsctl --no-wait -- --may-exist add-br br-int
> > 
> >       fi
> > 
> > -
> > -    /etc/init.d/openvswitch-switch start
> > -    ovs-vsctl --no-wait -- --may-exist add-br br-int
> > 
> >   }
> >   
> >   ALLOW_EMPTY_${SRCNAME}-setup = "1"
> > 
> > diff --git a/meta-openstack/recipes-devtools/python/python-nova_git.bb
> > b/meta-openstack/recipes-devtools/python/python-nova_git.bb index
> > f3a6b86..7b560a7 100644
> > --- a/meta-openstack/recipes-devtools/python/python-nova_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-nova_git.bb
> > @@ -160,33 +160,29 @@ do_install_append() {
> > 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +	# This is to make sure postgres is configured and running
> > +	if ! pidof postmaster > /dev/null; then
> > +	   /etc/init.d/postgresql-init
> > +	   /etc/init.d/postgresql start
> > +	   sleep 5
> > +	fi
> > +
> > +	sudo -u postgres createdb nova
> > +	sleep 2
> > +	nova-manage db sync
> > 
> >       fi
> > 
> > -
> > -    # This is to make sure postgres is configured and running
> > -    if ! pidof postmaster > /dev/null; then
> > -       /etc/init.d/postgresql-init
> > -       /etc/init.d/postgresql start
> > -       sleep 5
> > -    fi
> > -
> > -    sudo -u postgres createdb nova
> > -    sleep 2
> > -    nova-manage db sync
> > 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-common () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > -    fi
> > -
> > -    if [ -d  /home/root ]; then
> > -        echo "source /etc/nova/openrc" >> /home/root/.bashrc
> > -	echo "source /etc/nova/openrc" >> /home/root/.profile
> > -    else
> > -        echo "source /etc/nova/openrc" >> /root/.bashrc
> > -	echo "source /etc/nova/openrc" >> /root/.profile
> > +    if [ -z "$D" ]; then
> > +	if [ -d  /home/root ]; then
> > +	    echo "source /etc/nova/openrc" >> /home/root/.bashrc
> > +	    echo "source /etc/nova/openrc" >> /home/root/.profile
> > +	else
> > +	    echo "source /etc/nova/openrc" >> /root/.bashrc
> > +	    echo "source /etc/nova/openrc" >> /root/.profile
> > +	fi
> > 
> >       fi
> >   
> >   }
> > 
> > diff --git a/meta-openstack/recipes-devtools/python/python-rally_git.bb
> > b/meta-openstack/recipes-devtools/python/python-rally_git.bb index
> > d29e7cb..31d4242 100644
> > --- a/meta-openstack/recipes-devtools/python/python-rally_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-rally_git.bb
> > @@ -63,22 +63,20 @@ do_install_append() {
> > 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +	# This is to make sure postgres is configured and running
> > +	if ! pidof postmaster > /dev/null; then
> > +	   /etc/init.d/postgresql-init
> > +	   /etc/init.d/postgresql start
> > +	fi
> > +
> > +	if [ ! -d /var/log/rally ]; then
> > +	   mkdir /var/log/rally
> > +	fi
> > +
> > +	sudo -u postgres createdb rally
> > +	rally-manage db recreate
> > 
> >       fi
> > 
> > -
> > -    # This is to make sure postgres is configured and running
> > -    if ! pidof postmaster > /dev/null; then
> > -       /etc/init.d/postgresql-init
> > -       /etc/init.d/postgresql start
> > -    fi
> > -
> > -    if [ ! -d /var/log/rally ]; then
> > -       mkdir /var/log/rally
> > -    fi
> > -
> > -    sudo -u postgres createdb rally
> > -    rally-manage db recreate
> > 
> >   }
> >   
> >   PACKAGES += "${SRCNAME}-tests ${SRCNAME}-api ${SRCNAME}
> >   ${SRCNAME}-setup"
> > 
> > diff --git a/meta-openstack/recipes-devtools/python/python-swift_git.bb
> > b/meta-openstack/recipes-devtools/python/python-swift_git.bb index
> > 8552ea7..fc7c258 100644
> > --- a/meta-openstack/recipes-devtools/python/python-swift_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-swift_git.bb
> > @@ -109,28 +109,26 @@ do_install_append() {
> > 
> >   }
> >   
> >   pkg_postinst_${SRCNAME}-setup () {
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "x$D" ]; then
> > +	CLUSTER_CONF=/etc/swift/cluster.conf
> > +	SWIFT_SETUP='/bin/bash /etc/swift/swift_setup.sh'
> > +
> > +	for i in `seq 1 3`; do
> > +	    BACKING_FILE=/etc/swift/swift_backing_$i
> > +	    if [ "x${SWIFT_BACKING_FILE_SIZE}" != "x0G" ]; then
> > +		truncate -s ${SWIFT_BACKING_FILE_SIZE} $BACKING_FILE
> > +		sed "s:%SWIFT_BACKING_FILE_${i}%:$BACKING_FILE:g" -i 
$CLUSTER_CONF
> > +	    else
> > +		sed "s:%SWIFT_BACKING_FILE_${i}%::g" -i $CLUSTER_CONF
> > +	    fi
> > +	done
> > +
> > +	$SWIFT_SETUP createrings
> > +	$SWIFT_SETUP formatdevs
> > +	$SWIFT_SETUP mountdevs
> > +	$SWIFT_SETUP -i "${CONTROLLER_IP}" adddevs
> > +	$SWIFT_SETUP unmountdevs
> > 
> >       fi
> > 
> > -
> > -    CLUSTER_CONF=/etc/swift/cluster.conf
> > -    SWIFT_SETUP='/bin/bash /etc/swift/swift_setup.sh'
> > -
> > -    for i in `seq 1 3`; do
> > -        BACKING_FILE=/etc/swift/swift_backing_$i
> > -        if [ "x${SWIFT_BACKING_FILE_SIZE}" != "x0G" ]; then
> > -            truncate -s ${SWIFT_BACKING_FILE_SIZE} $BACKING_FILE
> > -            sed "s:%SWIFT_BACKING_FILE_${i}%:$BACKING_FILE:g" -i
> > $CLUSTER_CONF -        else
> > -            sed "s:%SWIFT_BACKING_FILE_${i}%::g" -i $CLUSTER_CONF
> > -        fi
> > -    done
> > -
> > -    $SWIFT_SETUP createrings
> > -    $SWIFT_SETUP formatdevs
> > -    $SWIFT_SETUP mountdevs
> > -    $SWIFT_SETUP -i "${CONTROLLER_IP}" adddevs
> > -    $SWIFT_SETUP unmountdevs
> > 
> >   }
> >   
> >   PACKAGES += "${SRCNAME}-tests ${SRCNAME} ${SRCNAME}-setup"
> > 
> > diff --git a/meta-openstack/recipes-devtools/python/python-trove_git.bb
> > b/meta-openstack/recipes-devtools/python/python-trove_git.bb index
> > 830da92..b90e552 100755
> > --- a/meta-openstack/recipes-devtools/python/python-trove_git.bb
> > +++ b/meta-openstack/recipes-devtools/python/python-trove_git.bb
> > @@ -146,30 +146,29 @@ do_install_append() {
> > 
> >   pkg_postinst_${SRCNAME}-setup () {
> >   
> >       # python-trove-setup postinst start
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +	source /etc/nova/openrc
> > +
> > +	# This is to make sure postgres is configured and running
> > +	if ! pidof postmaster > /dev/null; then
> > +	   /etc/init.d/postgresql-init
> > +	   /etc/init.d/postgresql start
> > +	   sleep 5
> > +	fi
> > +
> > +	mkdir /var/log/trove
> > +	# Create database for trove.
> > +	sudo -u postgres createdb trove
> > +
> > +	# Create default trove database.
> > +	trove-manage db_sync
> > +	# Create new datastore.
> > +	trove-manage datastore_update "postgresql" ""
> > +	# Set up new version
> > +	trove-manage datastore_version_update "postgresql" "9.1" "postgresql" 
1
> > "postgresql-server-9.1" 1 +	# Set new default version.
> > +	trove-manage datastore_update "postgresql" "9.1"
> > 
> >       fi
> > 
> > -    source /etc/nova/openrc
> > -
> > -    # This is to make sure postgres is configured and running
> > -    if ! pidof postmaster > /dev/null; then
> > -       /etc/init.d/postgresql-init
> > -       /etc/init.d/postgresql start
> > -       sleep 5
> > -    fi
> > -
> > -    mkdir /var/log/trove
> > -    # Create database for trove.
> > -    sudo -u postgres createdb trove
> > -
> > -    # Create default trove database.
> > -    trove-manage db_sync
> > -    # Create new datastore.
> > -    trove-manage datastore_update "postgresql" ""
> > -    # Set up new version
> > -    trove-manage datastore_version_update "postgresql" "9.1" "postgresql"
> > 1 "postgresql-server-9.1" 1 -    # Set new default version.
> > -    trove-manage datastore_update "postgresql" "9.1"
> > 
> >   }
> > 
> > diff --git
> > a/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
> > b/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend index
> > 22dae71..b26054e 100644
> > --- a/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
> > +++ b/meta-openstack/recipes-support/postgresql/postgresql_9.%.bbappend
> > @@ -41,14 +41,12 @@ ALLOW_EMPTY_${PN}-setup = "1"
> > 
> >   pkg_postinst_${PN}-setup () {
> >   
> >       # postgres 9.2.4 postinst
> > 
> > -    if [ "x$D" != "x" ]; then
> > -        exit 1
> > -    fi
> > -
> > -    /etc/init.d/postgresql-init
> > -    if [ $? -ne 0 ]; then
> > -        echo "[ERROR] postgres: unable to create admin account"
> > -        exit 1
> > +    if [ -z "$D" ]; then
> > +	/etc/init.d/postgresql-init
> > +	if [ $? -ne 0 ]; then
> > +	    echo "[ERROR] postgres: unable to create admin account"
> > +	    exit 1
> > +	fi
> > 
> >       fi
> >   
> >   }




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [m-c-s][PATCH] python-*: fixup postinst scripts
  2017-11-15 21:09     ` Bruce Ashfield
@ 2017-11-15 22:01       ` Mark Asselstine
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Asselstine @ 2017-11-15 22:01 UTC (permalink / raw)
  To: Bruce Ashfield; +Cc: meta-virtualization

On Wednesday, November 15, 2017 4:09:01 PM EST Bruce Ashfield wrote:
> On 2017-11-15 4:08 PM, Mark Asselstine wrote:
> > On Wednesday, November 15, 2017 8:58:36 PM EST Richard Purdie wrote:
> >> On Wed, 2017-11-15 at 12:59 -0500, Mark Asselstine wrote:
> >>> Checking for "$D" and doing an "exit 1" now results in errors such
> >>> as:
> >>> 
> >>> [log_check] warning: %post(keystone-cronjobs-...) scriptlet failed,
> >>> exit status 2
> >>> 
> >>> during image creation. Instead of escaping the script for "level-1"
> >>> (image creation postinst) we wrap the "level-2" (first boot) postinst
> >>> in an if statement. This also ensure the scriptlet in
> >>> indentity.bbclass is less prone to behaving differently based on the
> >>> postinsts defined in the classes which inherit 'identity'.
> >> 
> >> I think this could mean the postinst doesn't get executed at all if
> >> there isn't an exit 1, else how would it know to defer to first boot?
> > 
> > Every time I touch the postinst I admittedly end up in a knot. I was
> > inspecting the rpm scripts and all seemed well but I will take another
> > look to ensure I am not being a dolt.
> > 
> > Either way thanks for the nudge Richard. Bruce hold off on this one for
> > now. I have so many little and big changes to get m-c-s back up to snuff
> > I am better off taking the time to ensure I am not messing something up.
> 
> hah. I already merged this one, so rebase and send any fixups.

No problem. Seems Richard was correct. I saw the scripts in the RPM and see 
them logged on first boot but they are in fact ineffective. Adding the exit 1, 
however, marks a return of the log_check warning, so I will have to look at 
what is going on there.

At any rate I need to go through each of these postinst scripts one by one as 
they are all out of date, so overall this will not be a cause off any 
additional noise.

Mark

> 
> Bruce
> 
> > Mark
> > 
> >> Cheers,
> >> 
> >> Richard




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-11-15 22:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-15 17:59 [m-c-s][PATCH] python-*: fixup postinst scripts Mark Asselstine
2017-11-15 20:54 ` Bruce Ashfield
2017-11-15 21:10   ` Mark Asselstine
2017-11-15 20:58 ` Richard Purdie
2017-11-15 21:08   ` Mark Asselstine
2017-11-15 21:09     ` Bruce Ashfield
2017-11-15 22:01       ` Mark Asselstine

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.