Browse code

Merge "Allow devstack plugins to specify prereq packages"

Jenkins authored on 2015/03/19 09:35:34
Showing 3 changed files
... ...
@@ -179,3 +179,24 @@ functions:
179 179
 -  ``start_nova_hypervisor`` - start any external services
180 180
 -  ``stop_nova_hypervisor`` - stop any external services
181 181
 -  ``cleanup_nova_hypervisor`` - remove transient data and cache
182
+
183
+System Packages
184
+===============
185
+
186
+Devstack provides a framework for getting packages installed at an early
187
+phase of its execution. This packages may be defined in a plugin as files
188
+that contain new-line separated lists of packages required by the plugin
189
+
190
+Supported packaging systems include apt and yum across multiple distributions.
191
+To enable a plugin to hook into this and install package dependencies, packages
192
+may be listed at the following locations in the top-level of the plugin
193
+repository:
194
+
195
+- ``./devstack/files/debs/$plugin_name`` - Packages to install when running
196
+  on Ubuntu, Debian or Linux Mint.
197
+
198
+- ``./devstack/files/rpms/$plugin_name`` - Packages to install when running
199
+  on Red Hat, Fedora, CentOS or XenServer.
200
+
201
+- ``./devstack/files/rpms-suse/$plugin_name`` - Packages to install when
202
+  running on SUSE Linux or openSUSE.
... ...
@@ -774,13 +774,18 @@ function get_or_create_endpoint {
774 774
 
775 775
 # _get_package_dir
776 776
 function _get_package_dir {
777
+    local base_dir=$1
777 778
     local pkg_dir
779
+
780
+    if [[ -z "$base_dir" ]]; then
781
+        base_dir=$FILES
782
+    fi
778 783
     if is_ubuntu; then
779
-        pkg_dir=$FILES/debs
784
+        pkg_dir=$base_dir/debs
780 785
     elif is_fedora; then
781
-        pkg_dir=$FILES/rpms
786
+        pkg_dir=$base_dir/rpms
782 787
     elif is_suse; then
783
-        pkg_dir=$FILES/rpms-suse
788
+        pkg_dir=$base_dir/rpms-suse
784 789
     else
785 790
         exit_distro_not_supported "list of packages"
786 791
     fi
... ...
@@ -806,6 +811,59 @@ function apt_get {
806 806
         apt-get --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
807 807
 }
808 808
 
809
+function _parse_package_files {
810
+    local files_to_parse=$@
811
+
812
+    if [[ -z "$DISTRO" ]]; then
813
+        GetDistro
814
+    fi
815
+
816
+    for fname in ${files_to_parse}; do
817
+        local OIFS line package distros distro
818
+        [[ -e $fname ]] || continue
819
+
820
+        OIFS=$IFS
821
+        IFS=$'\n'
822
+        for line in $(<${fname}); do
823
+            if [[ $line =~ "NOPRIME" ]]; then
824
+                continue
825
+            fi
826
+
827
+            # Assume we want this package
828
+            package=${line%#*}
829
+            inst_pkg=1
830
+
831
+            # Look for # dist:xxx in comment
832
+            if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then
833
+                # We are using BASH regexp matching feature.
834
+                package=${BASH_REMATCH[1]}
835
+                distros=${BASH_REMATCH[2]}
836
+                # In bash ${VAR,,} will lowecase VAR
837
+                # Look for a match in the distro list
838
+                if [[ ! ${distros,,} =~ ${DISTRO,,} ]]; then
839
+                    # If no match then skip this package
840
+                    inst_pkg=0
841
+                fi
842
+            fi
843
+
844
+            # Look for # testonly in comment
845
+            if [[ $line =~ (.*)#.*testonly.* ]]; then
846
+                package=${BASH_REMATCH[1]}
847
+                # Are we installing test packages? (test for the default value)
848
+                if [[ $INSTALL_TESTONLY_PACKAGES = "False" ]]; then
849
+                    # If not installing test packages the skip this package
850
+                    inst_pkg=0
851
+                fi
852
+            fi
853
+
854
+            if [[ $inst_pkg = 1 ]]; then
855
+                echo $package
856
+            fi
857
+        done
858
+        IFS=$OIFS
859
+    done
860
+}
861
+
809 862
 # get_packages() collects a list of package names of any type from the
810 863
 # prerequisite files in ``files/{debs|rpms}``.  The list is intended
811 864
 # to be passed to a package installer such as apt or yum.
... ...
@@ -830,103 +888,76 @@ function get_packages {
830 830
         echo "No package directory supplied"
831 831
         return 1
832 832
     fi
833
-    if [[ -z "$DISTRO" ]]; then
834
-        GetDistro
835
-    fi
836 833
     for service in ${services//,/ }; do
837 834
         # Allow individual services to specify dependencies
838 835
         if [[ -e ${package_dir}/${service} ]]; then
839
-            file_to_parse="${file_to_parse} $service"
836
+            file_to_parse="${file_to_parse} ${package_dir}/${service}"
840 837
         fi
841 838
         # NOTE(sdague) n-api needs glance for now because that's where
842 839
         # glance client is
843 840
         if [[ $service == n-api ]]; then
844 841
             if [[ ! $file_to_parse =~ nova ]]; then
845
-                file_to_parse="${file_to_parse} nova"
842
+                file_to_parse="${file_to_parse} ${package_dir}/nova"
846 843
             fi
847 844
             if [[ ! $file_to_parse =~ glance ]]; then
848
-                file_to_parse="${file_to_parse} glance"
845
+                file_to_parse="${file_to_parse} ${package_dir}/glance"
849 846
             fi
850 847
         elif [[ $service == c-* ]]; then
851 848
             if [[ ! $file_to_parse =~ cinder ]]; then
852
-                file_to_parse="${file_to_parse} cinder"
849
+                file_to_parse="${file_to_parse} ${package_dir}/cinder"
853 850
             fi
854 851
         elif [[ $service == ceilometer-* ]]; then
855 852
             if [[ ! $file_to_parse =~ ceilometer ]]; then
856
-                file_to_parse="${file_to_parse} ceilometer"
853
+                file_to_parse="${file_to_parse} ${package_dir}/ceilometer"
857 854
             fi
858 855
         elif [[ $service == s-* ]]; then
859 856
             if [[ ! $file_to_parse =~ swift ]]; then
860
-                file_to_parse="${file_to_parse} swift"
857
+                file_to_parse="${file_to_parse} ${package_dir}/swift"
861 858
             fi
862 859
         elif [[ $service == n-* ]]; then
863 860
             if [[ ! $file_to_parse =~ nova ]]; then
864
-                file_to_parse="${file_to_parse} nova"
861
+                file_to_parse="${file_to_parse} ${package_dir}/nova"
865 862
             fi
866 863
         elif [[ $service == g-* ]]; then
867 864
             if [[ ! $file_to_parse =~ glance ]]; then
868
-                file_to_parse="${file_to_parse} glance"
865
+                file_to_parse="${file_to_parse} ${package_dir}/glance"
869 866
             fi
870 867
         elif [[ $service == key* ]]; then
871 868
             if [[ ! $file_to_parse =~ keystone ]]; then
872
-                file_to_parse="${file_to_parse} keystone"
869
+                file_to_parse="${file_to_parse} ${package_dir}/keystone"
873 870
             fi
874 871
         elif [[ $service == q-* ]]; then
875 872
             if [[ ! $file_to_parse =~ neutron ]]; then
876
-                file_to_parse="${file_to_parse} neutron"
873
+                file_to_parse="${file_to_parse} ${package_dir}/neutron"
877 874
             fi
878 875
         elif [[ $service == ir-* ]]; then
879 876
             if [[ ! $file_to_parse =~ ironic ]]; then
880
-                file_to_parse="${file_to_parse} ironic"
877
+                file_to_parse="${file_to_parse} ${package_dir}/ironic"
881 878
             fi
882 879
         fi
883 880
     done
881
+    echo "$(_parse_package_files $file_to_parse)"
882
+    $xtrace
883
+}
884 884
 
885
-    for file in ${file_to_parse}; do
886
-        local fname=${package_dir}/${file}
887
-        local OIFS line package distros distro
888
-        [[ -e $fname ]] || continue
889
-
890
-        OIFS=$IFS
891
-        IFS=$'\n'
892
-        for line in $(<${fname}); do
893
-            if [[ $line =~ "NOPRIME" ]]; then
894
-                continue
895
-            fi
896
-
897
-            # Assume we want this package
898
-            package=${line%#*}
899
-            inst_pkg=1
900
-
901
-            # Look for # dist:xxx in comment
902
-            if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then
903
-                # We are using BASH regexp matching feature.
904
-                package=${BASH_REMATCH[1]}
905
-                distros=${BASH_REMATCH[2]}
906
-                # In bash ${VAR,,} will lowecase VAR
907
-                # Look for a match in the distro list
908
-                if [[ ! ${distros,,} =~ ${DISTRO,,} ]]; then
909
-                    # If no match then skip this package
910
-                    inst_pkg=0
911
-                fi
912
-            fi
913
-
914
-            # Look for # testonly in comment
915
-            if [[ $line =~ (.*)#.*testonly.* ]]; then
916
-                package=${BASH_REMATCH[1]}
917
-                # Are we installing test packages? (test for the default value)
918
-                if [[ $INSTALL_TESTONLY_PACKAGES = "False" ]]; then
919
-                    # If not installing test packages the skip this package
920
-                    inst_pkg=0
921
-                fi
922
-            fi
923
-
924
-            if [[ $inst_pkg = 1 ]]; then
925
-                echo $package
926
-            fi
927
-        done
928
-        IFS=$OIFS
885
+# get_plugin_packages() collects a list of package names of any type from a
886
+# plugin's prerequisite files in ``$PLUGIN/devstack/files/{debs|rpms}``.  The
887
+# list is intended to be passed to a package installer such as apt or yum.
888
+#
889
+# Only packages required for enabled and collected plugins will included.
890
+#
891
+# The same metadata used in the main devstack prerequisite files may be used
892
+# in these prerequisite files, see get_packages() for more info.
893
+function get_plugin_packages {
894
+    local xtrace=$(set +o | grep xtrace)
895
+    set +o xtrace
896
+    local files_to_parse=""
897
+    local package_dir=""
898
+    for plugin in ${DEVSTACK_PLUGINS//,/ }; do
899
+        local package_dir="$(_get_package_dir ${GITDIR[$plugin]}/devstack/files)"
900
+        files_to_parse+="$package_dir/$plugin"
929 901
     done
902
+    echo "$(_parse_package_files $files_to_parse)"
930 903
     $xtrace
931 904
 }
932 905
 
... ...
@@ -62,6 +62,8 @@ export_proxy_variables
62 62
 
63 63
 # Install package requirements
64 64
 PACKAGES=$(get_packages general $ENABLED_SERVICES)
65
+PACKAGES="$PACKAGES $(get_plugin_packages)"
66
+
65 67
 if is_ubuntu && echo $PACKAGES | grep -q dkms ; then
66 68
     # ensure headers for the running kernel are installed for any DKMS builds
67 69
     PACKAGES="$PACKAGES linux-headers-$(uname -r)"