From a79a2caaffb2ba2706066344550b134746398c01 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 27 Mar 2015 15:22:25 +0000 Subject: openvswitch: Move setup scripts to Ansible. Also change systemd units and configure extension to match this change --- .../system/openvswitch-initialize-db.service | 10 ----- .../lib/systemd/system/openvswitch-setup.service | 6 +-- openstack/usr/share/openstack/openvswitch-setup | 44 ---------------------- openstack/usr/share/openstack/openvswitch.yml | 40 ++++++++++++++++++++ openvswitch.configure | 13 ++----- 5 files changed, 45 insertions(+), 68 deletions(-) delete mode 100644 openstack/usr/lib/systemd/system/openvswitch-initialize-db.service delete mode 100644 openstack/usr/share/openstack/openvswitch-setup create mode 100644 openstack/usr/share/openstack/openvswitch.yml diff --git a/openstack/usr/lib/systemd/system/openvswitch-initialize-db.service b/openstack/usr/lib/systemd/system/openvswitch-initialize-db.service deleted file mode 100644 index 3c564c5a..00000000 --- a/openstack/usr/lib/systemd/system/openvswitch-initialize-db.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Run openvswitch-initialize-db (once) -After=local-fs.target openvswitch-db-server.service - -ConditionPathExists=!/usr/local/var/run/openvswitch/openvswitch-initialize-db-flag - -[Service] -Type=oneshot -ExecStart=/usr/bin/ovs-vsctl --no-wait init -ExecStart=/bin/touch /usr/local/var/run/openvswitch/openvswitch-initialize-db-flag diff --git a/openstack/usr/lib/systemd/system/openvswitch-setup.service b/openstack/usr/lib/systemd/system/openvswitch-setup.service index bfe67002..1dbda6d8 100644 --- a/openstack/usr/lib/systemd/system/openvswitch-setup.service +++ b/openstack/usr/lib/systemd/system/openvswitch-setup.service @@ -1,11 +1,9 @@ [Unit] -Description=Run openvswitch-setup (once) +Description=Run openvswitch-setup Ansible scripts After=local-fs.target [Service] -Type=oneshot -ExecStart=/usr/share/openstack/openvswitch-setup -Restart=no +ExecStart=/usr/bin/ansible-playbook -v -i /usr/share/openstack/hosts /usr/share/openstack/openvswitch.yml [Install] WantedBy=multi-user.target diff --git a/openstack/usr/share/openstack/openvswitch-setup b/openstack/usr/share/openstack/openvswitch-setup deleted file mode 100644 index a5db7d21..00000000 --- a/openstack/usr/share/openstack/openvswitch-setup +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2014 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -set -e - -if [ -f /var/openstack/openvswitch-setup ]; then - exit 0 -fi - -# Create the openvswitch required folders -mkdir -p /usr/local/etc/openvswitch -mkdir -p /usr/local/var/run/openvswitch - -# Define openvswitch files -# Example (default values) -#openvswitch_database=/usr/local/etc/openvswitch/conf.db -#openvswitch_pidfile=/usr/local/var/run/openvswitch/ovsdb-server.pid -#openvswitch_logfile=/usr/local/var/run/openvswitch/ovsdb-server.log -openvswitch_database=/usr/local/etc/openvswitch/conf.db -openvswitch_pidfile=/usr/local/var/run/openvswitch/ovsdb-server.pid -openvswitch_logfile=/usr/local/var/run/openvswitch/ovsdb-server.log - -# Create openvswitch database -ovsdb-tool create $openvswitch_database /usr/share/openvswitch/vswitch.ovsschema - -install -D -m 644 /proc/self/fd/0 <<'EOF' /var/openstack/openvswitch-setup -Openvswitch setup: success -EOF - -exit 0 diff --git a/openstack/usr/share/openstack/openvswitch.yml b/openstack/usr/share/openstack/openvswitch.yml new file mode 100644 index 00000000..dd6eeac0 --- /dev/null +++ b/openstack/usr/share/openstack/openvswitch.yml @@ -0,0 +1,40 @@ +#!/bin/sh +--- +- hosts: localhost + tasks: + + - name: Create openvswitch directories + file: path={{ item }} state=directory + with_items: + - /usr/local/etc/openvswitch + - /usr/local/var/run/openvswitch + + - shell: > + ovsdb-tool create /usr/local/etc/openvswitch/conf.db /usr/share/openvswitch/vswitch.ovsschema + creates=/usr/local/etc/openvswitch/conf.db + + # We enable the openvswitch-db-server in a different task to identify + # the first time we run this script by identifying when we enable the + # unit. + # + # We need to identify this to initialise the database. + - name: Enable openvswitch database service + service: name={{ item }} enabled=yes + with_items: + - openvswitch-db-server.service + register: openvswitch_db_enable + + - name: Start openvswitch database service + service: name={{ item }} state=started + with_items: + - openvswitch-db-server.service + + - name: initialise openvswitch-db + shell: ovs-vsctl --no-wait init + when: openvswitch_db_enable|changed + + - name: Enable and start openstack-keystone service + service: name={{ item }} enabled=yes state=started + with_items: + - openvswitch.service + - openstack-neutron-setup.service diff --git a/openvswitch.configure b/openvswitch.configure index be4eb6d3..7e64de69 100644 --- a/openvswitch.configure +++ b/openvswitch.configure @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Copyright (C) 2015 Codethink Limited # @@ -19,12 +19,5 @@ set -e ROOT="$1" -services=("openvswitch-setup.service" \ - "openvswitch-db-server.service" \ - "openvswitch-initialize-db.service" \ - "openvswitch.service") - -for service in ${services[@]}; do - ln -sf "/etc/systemd/system/$service" \ - "$ROOT/etc/systemd/system/multi-user.target.wants/$service" -done +ln -sf "/usr/lib/systemd/system/openvswitch-setup.service" \ + "$ROOT/etc/systemd/system/multi-user.target.wants/openvswitch-setup.service" -- cgit v1.2.1