Browse code

Merge "Fleetify nova conductor for N cells"

Jenkins authored on 2017/06/23 20:36:35
Showing 2 changed files
... ...
@@ -53,10 +53,18 @@ NOVA_AUTH_CACHE_DIR=${NOVA_AUTH_CACHE_DIR:-/var/cache/nova}
53 53
 NOVA_CONF_DIR=/etc/nova
54 54
 NOVA_CONF=$NOVA_CONF_DIR/nova.conf
55 55
 NOVA_CELLS_CONF=$NOVA_CONF_DIR/nova-cells.conf
56
+NOVA_CPU_CONF=$NOVA_CONF_DIR/nova-cpu.conf
56 57
 NOVA_FAKE_CONF=$NOVA_CONF_DIR/nova-fake.conf
57 58
 NOVA_CELLS_DB=${NOVA_CELLS_DB:-nova_cell}
58 59
 NOVA_API_DB=${NOVA_API_DB:-nova_api}
59 60
 
61
+# The total number of cells we expect. Must be greater than one and doesn't
62
+# count cell0.
63
+NOVA_NUM_CELLS=${NOVA_NUM_CELLS:-1}
64
+# Our cell index, so we know what rabbit vhost to connect to.
65
+# This should be in the range of 1-$NOVA_NUM_CELLS
66
+NOVA_CPU_CELL=${NOVA_CPU_CELL:-1}
67
+
60 68
 NOVA_API_PASTE_INI=${NOVA_API_PASTE_INI:-$NOVA_CONF_DIR/api-paste.ini}
61 69
 
62 70
 if is_suse; then
... ...
@@ -479,7 +487,7 @@ function create_nova_conf {
479 479
     # require them running on the host. The ensures that n-cpu doesn't
480 480
     # leak a need to use the db in a multinode scenario.
481 481
     if is_service_enabled n-api n-cond n-sched; then
482
-        iniset $NOVA_CONF database connection `database_connection_url nova`
482
+        iniset $NOVA_CONF database connection `database_connection_url nova_cell0`
483 483
         iniset $NOVA_CONF api_database connection `database_connection_url nova_api`
484 484
     fi
485 485
 
... ...
@@ -614,6 +622,20 @@ function create_nova_conf {
614 614
     if [ "$NOVA_USE_SERVICE_TOKEN" == "True" ]; then
615 615
         init_nova_service_user_conf
616 616
     fi
617
+
618
+    if is_service_enabled n-cond; then
619
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
620
+            local conf
621
+            local vhost
622
+            conf=$(conductor_conf $i)
623
+            vhost="nova_cell${i}"
624
+            iniset $conf database connection `database_connection_url nova_cell${i}`
625
+            iniset $conf conductor workers "$API_WORKERS"
626
+            iniset $conf DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
627
+            rpc_backend_add_vhost $vhost
628
+            iniset_rpc_backend nova $conf DEFAULT $vhost
629
+        done
630
+    fi
617 631
 }
618 632
 
619 633
 function init_nova_service_user_conf {
... ...
@@ -628,6 +650,11 @@ function init_nova_service_user_conf {
628 628
     iniset $NOVA_CONF service_user auth_strategy keystone
629 629
 }
630 630
 
631
+function conductor_conf {
632
+    local cell="$1"
633
+    echo "${NOVA_CONF_DIR}/nova_cell${cell}.conf"
634
+}
635
+
631 636
 function init_nova_cells {
632 637
     if is_service_enabled n-cell; then
633 638
         cp $NOVA_CONF $NOVA_CELLS_CONF
... ...
@@ -694,8 +721,6 @@ function init_nova {
694 694
         recreate_database $NOVA_API_DB
695 695
         $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF api_db sync
696 696
 
697
-        # (Re)create nova databases
698
-        recreate_database nova
699 697
         recreate_database nova_cell0
700 698
 
701 699
         # map_cell0 will create the cell mapping record in the nova_api DB so
... ...
@@ -707,6 +732,12 @@ function init_nova {
707 707
         # Migrate nova and nova_cell0 databases.
708 708
         $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF db sync
709 709
 
710
+        # (Re)create nova databases
711
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
712
+            recreate_database nova_cell${i}
713
+            $NOVA_BIN_DIR/nova-manage --config-file $(conductor_conf $i) db sync
714
+        done
715
+
710 716
         if is_service_enabled n-cell; then
711 717
             recreate_database $NOVA_CELLS_DB
712 718
         fi
... ...
@@ -715,9 +746,13 @@ function init_nova {
715 715
         # Needed for flavor conversion
716 716
         $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF db online_data_migrations
717 717
 
718
+        # FIXME(danms): Should this be configurable?
719
+        iniset $NOVA_CONF workarounds disable_group_policy_check_upcall True
720
+
718 721
         # create the cell1 cell for the main nova db where the hosts live
719
-        nova-manage cell_v2 create_cell --transport-url $(get_transport_url) \
720
-            --name 'cell1'
722
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
723
+            nova-manage --config-file $NOVA_CONF --config-file $(conductor_conf $i) cell_v2 create_cell --name "cell$i"
724
+        done
721 725
     fi
722 726
 
723 727
     create_nova_cache_dir
... ...
@@ -825,25 +860,38 @@ function start_nova_api {
825 825
 
826 826
 # start_nova_compute() - Start the compute process
827 827
 function start_nova_compute {
828
+    local nomulticellflag="$1"
828 829
     # Hack to set the path for rootwrap
829 830
     local old_path=$PATH
830 831
     export PATH=$NOVA_BIN_DIR:$PATH
831 832
 
832 833
     if is_service_enabled n-cell; then
833 834
         local compute_cell_conf=$NOVA_CELLS_CONF
835
+        # NOTE(danms): Don't setup conductor fleet for cellsv1
836
+        nomulticellflag='nomulticell'
834 837
     else
835 838
         local compute_cell_conf=$NOVA_CONF
836 839
     fi
837 840
 
841
+    if [ "$nomulticellflag" = 'nomulticell' ]; then
842
+        # NOTE(danms): Grenade doesn't setup multi-cell rabbit, so
843
+        # skip these bits and use the normal config.
844
+        NOVA_CPU_CONF=$compute_cell_conf
845
+        echo "Skipping multi-cell conductor fleet setup"
846
+    else
847
+        cp $compute_cell_conf $NOVA_CPU_CONF
848
+        iniset_rpc_backend nova $NOVA_CPU_CONF DEFAULT "nova_cell${NOVA_CPU_CELL}"
849
+    fi
850
+
838 851
     if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
839 852
         # The group **$LIBVIRT_GROUP** is added to the current user in this script.
840 853
         # ``sg`` is used in run_process to execute nova-compute as a member of the
841 854
         # **$LIBVIRT_GROUP** group.
842
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $LIBVIRT_GROUP
855
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $LIBVIRT_GROUP
843 856
     elif [[ "$VIRT_DRIVER" = 'lxd' ]]; then
844
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $LXD_GROUP
857
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $LXD_GROUP
845 858
     elif [[ "$VIRT_DRIVER" = 'docker' || "$VIRT_DRIVER" = 'zun' ]]; then
846
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $DOCKER_GROUP
859
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $DOCKER_GROUP
847 860
     elif [[ "$VIRT_DRIVER" = 'fake' ]]; then
848 861
         local i
849 862
         for i in `seq 1 $NUMBER_FAKE_NOVA_COMPUTE`; do
... ...
@@ -852,13 +900,13 @@ function start_nova_compute {
852 852
             # gets its own configuration and own log file.
853 853
             local fake_conf="${NOVA_FAKE_CONF}-${i}"
854 854
             iniset $fake_conf DEFAULT nhost "${HOSTNAME}${i}"
855
-            run_process "n-cpu-${i}" "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf --config-file $fake_conf"
855
+            run_process "n-cpu-${i}" "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF --config-file $fake_conf"
856 856
         done
857 857
     else
858 858
         if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
859 859
             start_nova_hypervisor
860 860
         fi
861
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf"
861
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF"
862 862
     fi
863 863
 
864 864
     export PATH=$old_path
... ...
@@ -878,7 +926,6 @@ function start_nova_rest {
878 878
     fi
879 879
 
880 880
     # ``run_process`` checks ``is_service_enabled``, it is not needed here
881
-    run_process n-cond "$NOVA_BIN_DIR/nova-conductor --config-file $compute_cell_conf"
882 881
     run_process n-cell-region "$NOVA_BIN_DIR/nova-cells --config-file $api_cell_conf"
883 882
     run_process n-cell-child "$NOVA_BIN_DIR/nova-cells --config-file $compute_cell_conf"
884 883
 
... ...
@@ -901,8 +948,38 @@ function start_nova_rest {
901 901
     export PATH=$old_path
902 902
 }
903 903
 
904
+function enable_nova_fleet {
905
+    if is_service_enabled n-cond; then
906
+        enable_service n-super-cond
907
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
908
+            enable_service n-cond-cell${i}
909
+        done
910
+    fi
911
+}
912
+
913
+function start_nova_conductor {
914
+    if is_service_enabled n-cell; then
915
+        echo "Starting nova-conductor in a cellsv1-compatible way"
916
+        run_process n-cond "$NOVA_BIN_DIR/nova-conductor --config-file $NOVA_CELLS_CONF"
917
+        return
918
+    fi
919
+
920
+    enable_nova_fleet
921
+    if is_service_enabled n-super-cond; then
922
+        run_process n-super-cond "$NOVA_BIN_DIR/nova-conductor --config-file $NOVA_CONF"
923
+    fi
924
+    for i in $(seq 1 $NOVA_NUM_CELLS); do
925
+        if is_service_enabled n-cond-cell${i}; then
926
+            local conf
927
+            conf=$(conductor_conf $i)
928
+            run_process n-cond-cell${i} "$NOVA_BIN_DIR/nova-conductor --config-file $conf"
929
+        fi
930
+    done
931
+}
932
+
904 933
 function start_nova {
905 934
     start_nova_rest
935
+    start_nova_conductor
906 936
     start_nova_compute
907 937
 }
908 938
 
... ...
@@ -931,14 +1008,24 @@ function stop_nova_rest {
931 931
     # Kill the nova screen windows
932 932
     # Some services are listed here twice since more than one instance
933 933
     # of a service may be running in certain configs.
934
-    for serv in n-api n-net n-sch n-novnc n-xvnc n-cauth n-spice n-cond n-cell n-cell n-api-meta n-sproxy; do
934
+    for serv in n-api n-net n-sch n-novnc n-xvnc n-cauth n-spice n-cell n-cell n-api-meta n-sproxy; do
935 935
         stop_process $serv
936 936
     done
937 937
 }
938 938
 
939
+function stop_nova_conductor {
940
+    enable_nova_fleet
941
+    for srv in n-super-cond $(seq -f n-cond-cell%0.f 1 $NOVA_NUM_CELLS); do
942
+        if is_service_enabled $srv; then
943
+            stop_process $srv
944
+        fi
945
+    done
946
+}
947
+
939 948
 # stop_nova() - Stop running processes (non-screen)
940 949
 function stop_nova {
941 950
     stop_nova_rest
951
+    stop_nova_conductor
942 952
     stop_nova_compute
943 953
 }
944 954
 
... ...
@@ -1301,7 +1301,9 @@ fi
1301 1301
 # Unable to use LUKS passphrase that is exactly 16 bytes long
1302 1302
 # https://bugzilla.redhat.com/show_bug.cgi?id=1447297
1303 1303
 if is_service_enabled nova; then
1304
-    iniset $NOVA_CONF key_manager fixed_key $(generate_hex_string 36)
1304
+    key=$(generate_hex_string 36)
1305
+    iniset $NOVA_CONF key_manager fixed_key "$key"
1306
+    iniset $NOVA_CPU_CONF key_manager fixed_key "$key"
1305 1307
 fi
1306 1308
 
1307 1309
 # Launch the nova-api and wait for it to answer before continuing