Browse code

Fleetify nova conductor for N cells

This makes us start two levels of nova-conductor processes, and one per cell.

Change-Id: Ice4aceac5dc44954db3661480b9365f54e47a4c9

Dan Smith authored on 2017/06/08 21:22:38
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
... ...
@@ -692,8 +719,6 @@ function init_nova {
692 692
         recreate_database $NOVA_API_DB
693 693
         $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF api_db sync
694 694
 
695
-        # (Re)create nova databases
696
-        recreate_database nova
697 695
         recreate_database nova_cell0
698 696
 
699 697
         # map_cell0 will create the cell mapping record in the nova_api DB so
... ...
@@ -705,6 +730,12 @@ function init_nova {
705 705
         # Migrate nova and nova_cell0 databases.
706 706
         $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF db sync
707 707
 
708
+        # (Re)create nova databases
709
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
710
+            recreate_database nova_cell${i}
711
+            $NOVA_BIN_DIR/nova-manage --config-file $(conductor_conf $i) db sync
712
+        done
713
+
708 714
         if is_service_enabled n-cell; then
709 715
             recreate_database $NOVA_CELLS_DB
710 716
         fi
... ...
@@ -713,9 +744,13 @@ function init_nova {
713 713
         # Needed for flavor conversion
714 714
         $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF db online_data_migrations
715 715
 
716
+        # FIXME(danms): Should this be configurable?
717
+        iniset $NOVA_CONF workarounds disable_group_policy_check_upcall True
718
+
716 719
         # create the cell1 cell for the main nova db where the hosts live
717
-        nova-manage cell_v2 create_cell --transport-url $(get_transport_url) \
718
-            --name 'cell1'
720
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
721
+            nova-manage --config-file $NOVA_CONF --config-file $(conductor_conf $i) cell_v2 create_cell --name "cell$i"
722
+        done
719 723
     fi
720 724
 
721 725
     create_nova_cache_dir
... ...
@@ -823,25 +858,38 @@ function start_nova_api {
823 823
 
824 824
 # start_nova_compute() - Start the compute process
825 825
 function start_nova_compute {
826
+    local nomulticellflag="$1"
826 827
     # Hack to set the path for rootwrap
827 828
     local old_path=$PATH
828 829
     export PATH=$NOVA_BIN_DIR:$PATH
829 830
 
830 831
     if is_service_enabled n-cell; then
831 832
         local compute_cell_conf=$NOVA_CELLS_CONF
833
+        # NOTE(danms): Don't setup conductor fleet for cellsv1
834
+        nomulticellflag='nomulticell'
832 835
     else
833 836
         local compute_cell_conf=$NOVA_CONF
834 837
     fi
835 838
 
839
+    if [ "$nomulticellflag" = 'nomulticell' ]; then
840
+        # NOTE(danms): Grenade doesn't setup multi-cell rabbit, so
841
+        # skip these bits and use the normal config.
842
+        NOVA_CPU_CONF=$compute_cell_conf
843
+        echo "Skipping multi-cell conductor fleet setup"
844
+    else
845
+        cp $compute_cell_conf $NOVA_CPU_CONF
846
+        iniset_rpc_backend nova $NOVA_CPU_CONF DEFAULT "nova_cell${NOVA_CPU_CELL}"
847
+    fi
848
+
836 849
     if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
837 850
         # The group **$LIBVIRT_GROUP** is added to the current user in this script.
838 851
         # ``sg`` is used in run_process to execute nova-compute as a member of the
839 852
         # **$LIBVIRT_GROUP** group.
840
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $LIBVIRT_GROUP
853
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $LIBVIRT_GROUP
841 854
     elif [[ "$VIRT_DRIVER" = 'lxd' ]]; then
842
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $LXD_GROUP
855
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $LXD_GROUP
843 856
     elif [[ "$VIRT_DRIVER" = 'docker' || "$VIRT_DRIVER" = 'zun' ]]; then
844
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $DOCKER_GROUP
857
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $DOCKER_GROUP
845 858
     elif [[ "$VIRT_DRIVER" = 'fake' ]]; then
846 859
         local i
847 860
         for i in `seq 1 $NUMBER_FAKE_NOVA_COMPUTE`; do
... ...
@@ -850,13 +898,13 @@ function start_nova_compute {
850 850
             # gets its own configuration and own log file.
851 851
             local fake_conf="${NOVA_FAKE_CONF}-${i}"
852 852
             iniset $fake_conf DEFAULT nhost "${HOSTNAME}${i}"
853
-            run_process "n-cpu-${i}" "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf --config-file $fake_conf"
853
+            run_process "n-cpu-${i}" "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF --config-file $fake_conf"
854 854
         done
855 855
     else
856 856
         if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
857 857
             start_nova_hypervisor
858 858
         fi
859
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf"
859
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF"
860 860
     fi
861 861
 
862 862
     export PATH=$old_path
... ...
@@ -876,7 +924,6 @@ function start_nova_rest {
876 876
     fi
877 877
 
878 878
     # ``run_process`` checks ``is_service_enabled``, it is not needed here
879
-    run_process n-cond "$NOVA_BIN_DIR/nova-conductor --config-file $compute_cell_conf"
880 879
     run_process n-cell-region "$NOVA_BIN_DIR/nova-cells --config-file $api_cell_conf"
881 880
     run_process n-cell-child "$NOVA_BIN_DIR/nova-cells --config-file $compute_cell_conf"
882 881
 
... ...
@@ -899,8 +946,38 @@ function start_nova_rest {
899 899
     export PATH=$old_path
900 900
 }
901 901
 
902
+function enable_nova_fleet {
903
+    if is_service_enabled n-cond; then
904
+        enable_service n-super-cond
905
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
906
+            enable_service n-cond-cell${i}
907
+        done
908
+    fi
909
+}
910
+
911
+function start_nova_conductor {
912
+    if is_service_enabled n-cell; then
913
+        echo "Starting nova-conductor in a cellsv1-compatible way"
914
+        run_process n-cond "$NOVA_BIN_DIR/nova-conductor --config-file $NOVA_CELLS_CONF"
915
+        return
916
+    fi
917
+
918
+    enable_nova_fleet
919
+    if is_service_enabled n-super-cond; then
920
+        run_process n-super-cond "$NOVA_BIN_DIR/nova-conductor --config-file $NOVA_CONF"
921
+    fi
922
+    for i in $(seq 1 $NOVA_NUM_CELLS); do
923
+        if is_service_enabled n-cond-cell${i}; then
924
+            local conf
925
+            conf=$(conductor_conf $i)
926
+            run_process n-cond-cell${i} "$NOVA_BIN_DIR/nova-conductor --config-file $conf"
927
+        fi
928
+    done
929
+}
930
+
902 931
 function start_nova {
903 932
     start_nova_rest
933
+    start_nova_conductor
904 934
     start_nova_compute
905 935
 }
906 936
 
... ...
@@ -929,14 +1006,24 @@ function stop_nova_rest {
929 929
     # Kill the nova screen windows
930 930
     # Some services are listed here twice since more than one instance
931 931
     # of a service may be running in certain configs.
932
-    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
932
+    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
933 933
         stop_process $serv
934 934
     done
935 935
 }
936 936
 
937
+function stop_nova_conductor {
938
+    enable_nova_fleet
939
+    for srv in n-super-cond $(seq -f n-cond-cell%0.f 1 $NOVA_NUM_CELLS); do
940
+        if is_service_enabled $srv; then
941
+            stop_process $srv
942
+        fi
943
+    done
944
+}
945
+
937 946
 # stop_nova() - Stop running processes (non-screen)
938 947
 function stop_nova {
939 948
     stop_nova_rest
949
+    stop_nova_conductor
940 950
     stop_nova_compute
941 951
 }
942 952
 
... ...
@@ -1268,7 +1268,9 @@ fi
1268 1268
 # Unable to use LUKS passphrase that is exactly 16 bytes long
1269 1269
 # https://bugzilla.redhat.com/show_bug.cgi?id=1447297
1270 1270
 if is_service_enabled nova; then
1271
-    iniset $NOVA_CONF key_manager fixed_key $(generate_hex_string 36)
1271
+    key=$(generate_hex_string 36)
1272
+    iniset $NOVA_CONF key_manager fixed_key "$key"
1273
+    iniset $NOVA_CPU_CONF key_manager fixed_key "$key"
1272 1274
 fi
1273 1275
 
1274 1276
 # Launch the nova-api and wait for it to answer before continuing