Browse code

Merge "Fleetify nova conductor for N cells"

Jenkins authored on 2017/07/26 07:32:17
Showing 2 changed files
... ...
@@ -51,6 +51,7 @@ NOVA_AUTH_CACHE_DIR=${NOVA_AUTH_CACHE_DIR:-/var/cache/nova}
51 51
 NOVA_CONF_DIR=/etc/nova
52 52
 NOVA_CONF=$NOVA_CONF_DIR/nova.conf
53 53
 NOVA_CELLS_CONF=$NOVA_CONF_DIR/nova-cells.conf
54
+NOVA_CPU_CONF=$NOVA_CONF_DIR/nova-cpu.conf
54 55
 NOVA_FAKE_CONF=$NOVA_CONF_DIR/nova-fake.conf
55 56
 NOVA_CELLS_DB=${NOVA_CELLS_DB:-nova_cell}
56 57
 NOVA_API_DB=${NOVA_API_DB:-nova_api}
... ...
@@ -59,6 +60,13 @@ NOVA_METADATA_UWSGI=$NOVA_BIN_DIR/nova-metadata-wsgi
59 59
 NOVA_UWSGI_CONF=$NOVA_CONF_DIR/nova-api-uwsgi.ini
60 60
 NOVA_METADATA_UWSGI_CONF=$NOVA_CONF_DIR/nova-metadata-uwsgi.ini
61 61
 
62
+# The total number of cells we expect. Must be greater than one and doesn't
63
+# count cell0.
64
+NOVA_NUM_CELLS=${NOVA_NUM_CELLS:-1}
65
+# Our cell index, so we know what rabbit vhost to connect to.
66
+# This should be in the range of 1-$NOVA_NUM_CELLS
67
+NOVA_CPU_CELL=${NOVA_CPU_CELL:-1}
68
+
62 69
 NOVA_API_PASTE_INI=${NOVA_API_PASTE_INI:-$NOVA_CONF_DIR/api-paste.ini}
63 70
 
64 71
 # Toggle for deploying Nova-API under a wsgi server. We default to
... ...
@@ -424,7 +432,7 @@ function create_nova_conf {
424 424
     # require them running on the host. The ensures that n-cpu doesn't
425 425
     # leak a need to use the db in a multinode scenario.
426 426
     if is_service_enabled n-api n-cond n-sched; then
427
-        iniset $NOVA_CONF database connection `database_connection_url nova`
427
+        iniset $NOVA_CONF database connection `database_connection_url nova_cell0`
428 428
         iniset $NOVA_CONF api_database connection `database_connection_url nova_api`
429 429
     fi
430 430
 
... ...
@@ -518,6 +526,7 @@ function create_nova_conf {
518 518
     # Set the oslo messaging driver to the typical default. This does not
519 519
     # enable notifications, but it will allow them to function when enabled.
520 520
     iniset $NOVA_CONF oslo_messaging_notifications driver "messagingv2"
521
+    iniset $NOVA_CONF oslo_messaging_notifications transport_url $(get_transport_url)
521 522
     iniset_rpc_backend nova $NOVA_CONF
522 523
     iniset $NOVA_CONF glance api_servers "$GLANCE_URL"
523 524
 
... ...
@@ -560,6 +569,20 @@ function create_nova_conf {
560 560
     if [ "$NOVA_USE_SERVICE_TOKEN" == "True" ]; then
561 561
         init_nova_service_user_conf
562 562
     fi
563
+
564
+    if is_service_enabled n-cond; then
565
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
566
+            local conf
567
+            local vhost
568
+            conf=$(conductor_conf $i)
569
+            vhost="nova_cell${i}"
570
+            iniset $conf database connection `database_connection_url nova_cell${i}`
571
+            iniset $conf conductor workers "$API_WORKERS"
572
+            iniset $conf DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
573
+            rpc_backend_add_vhost $vhost
574
+            iniset_rpc_backend nova $conf DEFAULT $vhost
575
+        done
576
+    fi
563 577
 }
564 578
 
565 579
 function init_nova_service_user_conf {
... ...
@@ -574,6 +597,11 @@ function init_nova_service_user_conf {
574 574
     iniset $NOVA_CONF service_user auth_strategy keystone
575 575
 }
576 576
 
577
+function conductor_conf {
578
+    local cell="$1"
579
+    echo "${NOVA_CONF_DIR}/nova_cell${cell}.conf"
580
+}
581
+
577 582
 function init_nova_cells {
578 583
     if is_service_enabled n-cell; then
579 584
         cp $NOVA_CONF $NOVA_CELLS_CONF
... ...
@@ -640,8 +668,6 @@ function init_nova {
640 640
         recreate_database $NOVA_API_DB
641 641
         $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF api_db sync
642 642
 
643
-        # (Re)create nova databases
644
-        recreate_database nova
645 643
         recreate_database nova_cell0
646 644
 
647 645
         # map_cell0 will create the cell mapping record in the nova_api DB so
... ...
@@ -653,6 +679,12 @@ function init_nova {
653 653
         # Migrate nova and nova_cell0 databases.
654 654
         $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF db sync
655 655
 
656
+        # (Re)create nova databases
657
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
658
+            recreate_database nova_cell${i}
659
+            $NOVA_BIN_DIR/nova-manage --config-file $(conductor_conf $i) db sync
660
+        done
661
+
656 662
         if is_service_enabled n-cell; then
657 663
             recreate_database $NOVA_CELLS_DB
658 664
         fi
... ...
@@ -662,8 +694,9 @@ function init_nova {
662 662
         $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF db online_data_migrations
663 663
 
664 664
         # create the cell1 cell for the main nova db where the hosts live
665
-        nova-manage cell_v2 create_cell --transport-url $(get_transport_url) \
666
-            --name 'cell1'
665
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
666
+            nova-manage --config-file $NOVA_CONF --config-file $(conductor_conf $i) cell_v2 create_cell --name "cell$i"
667
+        done
667 668
     fi
668 669
 
669 670
     create_nova_cache_dir
... ...
@@ -762,25 +795,40 @@ function start_nova_api {
762 762
 
763 763
 # start_nova_compute() - Start the compute process
764 764
 function start_nova_compute {
765
+    local nomulticellflag="$1"
765 766
     # Hack to set the path for rootwrap
766 767
     local old_path=$PATH
767 768
     export PATH=$NOVA_BIN_DIR:$PATH
768 769
 
769 770
     if is_service_enabled n-cell; then
770 771
         local compute_cell_conf=$NOVA_CELLS_CONF
772
+        # NOTE(danms): Don't setup conductor fleet for cellsv1
773
+        nomulticellflag='nomulticell'
771 774
     else
772 775
         local compute_cell_conf=$NOVA_CONF
773 776
     fi
774 777
 
778
+    if [ "$nomulticellflag" = 'nomulticell' ]; then
779
+        # NOTE(danms): Grenade doesn't setup multi-cell rabbit, so
780
+        # skip these bits and use the normal config.
781
+        NOVA_CPU_CONF=$compute_cell_conf
782
+        echo "Skipping multi-cell conductor fleet setup"
783
+    else
784
+        cp $compute_cell_conf $NOVA_CPU_CONF
785
+        # FIXME(danms): Should this be configurable?
786
+        iniset $NOVA_CPU_CONF workarounds disable_group_policy_check_upcall True
787
+        iniset_rpc_backend nova $NOVA_CPU_CONF DEFAULT "nova_cell${NOVA_CPU_CELL}"
788
+    fi
789
+
775 790
     if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
776 791
         # The group **$LIBVIRT_GROUP** is added to the current user in this script.
777 792
         # ``sg`` is used in run_process to execute nova-compute as a member of the
778 793
         # **$LIBVIRT_GROUP** group.
779
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $LIBVIRT_GROUP
794
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $LIBVIRT_GROUP
780 795
     elif [[ "$VIRT_DRIVER" = 'lxd' ]]; then
781
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $LXD_GROUP
796
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $LXD_GROUP
782 797
     elif [[ "$VIRT_DRIVER" = 'docker' || "$VIRT_DRIVER" = 'zun' ]]; then
783
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf" $DOCKER_GROUP
798
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF" $DOCKER_GROUP
784 799
     elif [[ "$VIRT_DRIVER" = 'fake' ]]; then
785 800
         local i
786 801
         for i in `seq 1 $NUMBER_FAKE_NOVA_COMPUTE`; do
... ...
@@ -789,13 +837,13 @@ function start_nova_compute {
789 789
             # gets its own configuration and own log file.
790 790
             local fake_conf="${NOVA_FAKE_CONF}-${i}"
791 791
             iniset $fake_conf DEFAULT nhost "${HOSTNAME}${i}"
792
-            run_process "n-cpu-${i}" "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf --config-file $fake_conf"
792
+            run_process "n-cpu-${i}" "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF --config-file $fake_conf"
793 793
         done
794 794
     else
795 795
         if is_service_enabled n-cpu && [[ -r $NOVA_PLUGINS/hypervisor-$VIRT_DRIVER ]]; then
796 796
             start_nova_hypervisor
797 797
         fi
798
-        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $compute_cell_conf"
798
+        run_process n-cpu "$NOVA_BIN_DIR/nova-compute --config-file $NOVA_CPU_CONF"
799 799
     fi
800 800
 
801 801
     export PATH=$old_path
... ...
@@ -815,7 +863,6 @@ function start_nova_rest {
815 815
     fi
816 816
 
817 817
     # ``run_process`` checks ``is_service_enabled``, it is not needed here
818
-    run_process n-cond "$NOVA_BIN_DIR/nova-conductor --config-file $compute_cell_conf"
819 818
     run_process n-cell-region "$NOVA_BIN_DIR/nova-cells --config-file $api_cell_conf"
820 819
     run_process n-cell-child "$NOVA_BIN_DIR/nova-cells --config-file $compute_cell_conf"
821 820
 
... ...
@@ -842,8 +889,38 @@ function start_nova_rest {
842 842
     export PATH=$old_path
843 843
 }
844 844
 
845
+function enable_nova_fleet {
846
+    if is_service_enabled n-cond; then
847
+        enable_service n-super-cond
848
+        for i in $(seq 1 $NOVA_NUM_CELLS); do
849
+            enable_service n-cond-cell${i}
850
+        done
851
+    fi
852
+}
853
+
854
+function start_nova_conductor {
855
+    if is_service_enabled n-cell; then
856
+        echo "Starting nova-conductor in a cellsv1-compatible way"
857
+        run_process n-cond "$NOVA_BIN_DIR/nova-conductor --config-file $NOVA_CELLS_CONF"
858
+        return
859
+    fi
860
+
861
+    enable_nova_fleet
862
+    if is_service_enabled n-super-cond; then
863
+        run_process n-super-cond "$NOVA_BIN_DIR/nova-conductor --config-file $NOVA_CONF"
864
+    fi
865
+    for i in $(seq 1 $NOVA_NUM_CELLS); do
866
+        if is_service_enabled n-cond-cell${i}; then
867
+            local conf
868
+            conf=$(conductor_conf $i)
869
+            run_process n-cond-cell${i} "$NOVA_BIN_DIR/nova-conductor --config-file $conf"
870
+        fi
871
+    done
872
+}
873
+
845 874
 function start_nova {
846 875
     start_nova_rest
876
+    start_nova_conductor
847 877
     start_nova_compute
848 878
 }
849 879
 
... ...
@@ -863,14 +940,24 @@ function stop_nova_compute {
863 863
 
864 864
 function stop_nova_rest {
865 865
     # Kill the non-compute nova processes
866
-    for serv in n-api n-api-meta n-net n-sch n-novnc n-xvnc n-cauth n-spice n-cond n-cell n-cell n-sproxy; do
866
+    for serv in n-api n-api-meta n-net n-sch n-novnc n-xvnc n-cauth n-spice n-cell n-cell n-sproxy; do
867 867
         stop_process $serv
868 868
     done
869 869
 }
870 870
 
871
+function stop_nova_conductor {
872
+    enable_nova_fleet
873
+    for srv in n-super-cond $(seq -f n-cond-cell%0.f 1 $NOVA_NUM_CELLS); do
874
+        if is_service_enabled $srv; then
875
+            stop_process $srv
876
+        fi
877
+    done
878
+}
879
+
871 880
 # stop_nova() - Stop running processes (non-screen)
872 881
 function stop_nova {
873 882
     stop_nova_rest
883
+    stop_nova_conductor
874 884
     stop_nova_compute
875 885
 }
876 886
 
... ...
@@ -1304,7 +1304,9 @@ fi
1304 1304
 # Unable to use LUKS passphrase that is exactly 16 bytes long
1305 1305
 # https://bugzilla.redhat.com/show_bug.cgi?id=1447297
1306 1306
 if is_service_enabled nova; then
1307
-    iniset $NOVA_CONF key_manager fixed_key $(generate_hex_string 36)
1307
+    key=$(generate_hex_string 36)
1308
+    iniset $NOVA_CONF key_manager fixed_key "$key"
1309
+    iniset $NOVA_CPU_CONF key_manager fixed_key "$key"
1308 1310
 fi
1309 1311
 
1310 1312
 # Launch the nova-api and wait for it to answer before continuing