Shared filesystem management project for OpenStack.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin.sh 50KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. #!/bin/bash
  2. # Plugin file for enabling manila services
  3. # ----------------------------------------
  4. # Save trace setting
  5. XTRACE=$(set +o | grep xtrace)
  6. set -o xtrace
  7. # Entry Points
  8. # ------------
  9. function _clean_share_group {
  10. local vg=$1
  11. local vg_prefix=$2
  12. # Clean out existing shares
  13. for lv in `sudo lvs --noheadings -o lv_name $vg`; do
  14. # vg_prefix prefixes the LVs we want
  15. if [[ "${lv#$vg_prefix}" != "$lv" ]]; then
  16. sudo umount -f $MANILA_MNT_DIR/$lv
  17. sudo lvremove -f $vg/$lv
  18. sudo rm -rf $MANILA_MNT_DIR/$lv
  19. fi
  20. done
  21. }
  22. function _clean_manila_lvm_backing_file {
  23. local vg=$1
  24. # if there is no logical volume left, it's safe to attempt a cleanup
  25. # of the backing file
  26. if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then
  27. # if the backing physical device is a loop device, it was probably setup by devstack
  28. VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1
  29. }')
  30. if [[ -n "$VG_DEV" ]]; then
  31. sudo losetup -d $VG_DEV
  32. rm -f $DATA_DIR/${vg}-backing-file
  33. fi
  34. fi
  35. }
  36. function _clean_zfsonlinux_data {
  37. for filename in "$MANILA_ZFSONLINUX_BACKEND_FILES_CONTAINER_DIR"/*; do
  38. if [[ $(sudo zpool list | grep $filename) ]]; then
  39. echo "Destroying zpool named $filename"
  40. sudo zpool destroy -f $filename
  41. file="$MANILA_ZFSONLINUX_BACKEND_FILES_CONTAINER_DIR$filename"
  42. echo "Destroying file named $file"
  43. rm -f $file
  44. fi
  45. done
  46. }
  47. # cleanup_manila - Remove residual data files, anything left over from previous
  48. # runs that a clean run would need to clean up
  49. function cleanup_manila {
  50. # All stuff, that are created by share drivers will be cleaned up by other services.
  51. _clean_share_group $SHARE_GROUP $SHARE_NAME_PREFIX
  52. _clean_manila_lvm_backing_file $SHARE_GROUP
  53. _clean_zfsonlinux_data
  54. }
  55. # _config_manila_apache_wsgi() - Configure manila-api wsgi application.
  56. function _config_manila_apache_wsgi {
  57. local manila_api_apache_conf
  58. local venv_path=""
  59. manila_api_apache_conf=$(apache_site_config_for manila-api)
  60. sudo cp $MANILA_DIR/devstack/apache-manila.template $manila_api_apache_conf
  61. sudo sed -e "
  62. s|%APACHE_NAME%|$APACHE_NAME|g;
  63. s|%MANILA_BIN_DIR%|$MANILA_BIN_DIR|g;
  64. s|%PORT%|$MANILA_SERVICE_PORT|g;
  65. s|%APIWORKERS%|$API_WORKERS|g;
  66. s|%USER%|$STACK_USER|g;
  67. " -i $manila_api_apache_conf
  68. }
  69. # configure_default_backends - configures default Manila backends with generic driver.
  70. function configure_default_backends {
  71. # Configure two default backends with generic drivers onboard
  72. for group_name in $MANILA_BACKEND1_CONFIG_GROUP_NAME $MANILA_BACKEND2_CONFIG_GROUP_NAME; do
  73. iniset $MANILA_CONF $group_name share_driver $SHARE_DRIVER
  74. if [ "$MANILA_BACKEND1_CONFIG_GROUP_NAME" == "$group_name" ]; then
  75. iniset $MANILA_CONF $group_name share_backend_name $MANILA_SHARE_BACKEND1_NAME
  76. else
  77. iniset $MANILA_CONF $group_name share_backend_name $MANILA_SHARE_BACKEND2_NAME
  78. fi
  79. iniset $MANILA_CONF $group_name path_to_public_key $MANILA_PATH_TO_PUBLIC_KEY
  80. iniset $MANILA_CONF $group_name path_to_private_key $MANILA_PATH_TO_PRIVATE_KEY
  81. iniset $MANILA_CONF $group_name service_image_name $MANILA_SERVICE_IMAGE_NAME
  82. iniset $MANILA_CONF $group_name service_instance_user $MANILA_SERVICE_INSTANCE_USER
  83. iniset $MANILA_CONF $group_name driver_handles_share_servers True
  84. if [ "$SHARE_DRIVER" == $MANILA_CONTAINER_DRIVER ]; then
  85. iniset $MANILA_CONF $group_name network_api_class $MANILA_NETWORK_API_CLASS
  86. iniset $MANILA_CONF $group_name neutron_host_id $(hostname)
  87. iniset $MANILA_CONF $group_name neutron_vnic_type $MANILA_NEUTRON_VNIC_TYPE
  88. fi
  89. if [ $(trueorfalse False MANILA_USE_SERVICE_INSTANCE_PASSWORD) == True ]; then
  90. iniset $MANILA_CONF $group_name service_instance_password $MANILA_SERVICE_INSTANCE_PASSWORD
  91. fi
  92. done
  93. }
  94. # set_config_opts - this allows to set any config opt to any config group,
  95. # parsing env vars by prefix special 'MANILA_OPTGROUP_'.
  96. function set_config_opts {
  97. # expects only one param - name of config group(s) as list separated by commas
  98. GROUP_NAMES=$1
  99. if [[ -n "$GROUP_NAMES" ]]; then
  100. for be in ${GROUP_NAMES//,/ }; do
  101. # get backend_specific opt values
  102. prefix=MANILA_OPTGROUP_$be\_
  103. ( set -o posix ; set ) | grep ^$prefix | while read -r line ; do
  104. # parse it to opt names and values
  105. opt=${line#$prefix}
  106. opt_name=${opt%%=*}
  107. opt_value=${opt##*=}
  108. iniset $MANILA_CONF $be $opt_name $opt_value
  109. done
  110. done
  111. fi
  112. }
  113. # set_cinder_quotas - Sets Cinder quotas, that is useful for generic driver,
  114. # which uses Cinder volumes and snapshots.
  115. function set_cinder_quotas {
  116. # Update Cinder configuration to make sure default quotas are enough
  117. # for Manila using Generic driver with parallel testing.
  118. if is_service_enabled cinder; then
  119. if [[ ! "$CINDER_CONF" ]]; then
  120. CINDER_CONF=/etc/cinder/cinder.conf
  121. fi
  122. iniset $CINDER_CONF DEFAULT quota_volumes 50
  123. iniset $CINDER_CONF DEFAULT quota_snapshots 50
  124. iniset $CINDER_CONF DEFAULT quota_gigabytes 1000
  125. fi
  126. }
  127. # configure_manila - Set config files, create data dirs, etc
  128. function configure_manila {
  129. if [[ ! -d $MANILA_CONF_DIR ]]; then
  130. sudo mkdir -p $MANILA_CONF_DIR
  131. fi
  132. sudo chown $STACK_USER $MANILA_CONF_DIR
  133. if [[ -f $MANILA_DIR/etc/manila/policy.json ]]; then
  134. cp -p $MANILA_DIR/etc/manila/policy.json $MANILA_CONF_DIR
  135. fi
  136. # Set the paths of certain binaries
  137. MANILA_ROOTWRAP=$(get_rootwrap_location manila)
  138. # If Manila ships the new rootwrap filters files, deploy them
  139. # (owned by root) and add a parameter to $MANILA_ROOTWRAP
  140. ROOTWRAP_MANILA_SUDOER_CMD="$MANILA_ROOTWRAP"
  141. if [[ -d $MANILA_DIR/etc/manila/rootwrap.d ]]; then
  142. # Wipe any existing rootwrap.d files first
  143. if [[ -d $MANILA_CONF_DIR/rootwrap.d ]]; then
  144. sudo rm -rf $MANILA_CONF_DIR/rootwrap.d
  145. fi
  146. # Deploy filters to /etc/manila/rootwrap.d
  147. sudo mkdir -m 755 $MANILA_CONF_DIR/rootwrap.d
  148. sudo cp $MANILA_DIR/etc/manila/rootwrap.d/*.filters $MANILA_CONF_DIR/rootwrap.d
  149. sudo chown -R root:root $MANILA_CONF_DIR/rootwrap.d
  150. sudo chmod 644 $MANILA_CONF_DIR/rootwrap.d/*
  151. # Set up rootwrap.conf, pointing to /etc/manila/rootwrap.d
  152. sudo cp $MANILA_DIR/etc/manila/rootwrap.conf $MANILA_CONF_DIR/
  153. sudo sed -e "s:^filters_path=.*$:filters_path=$MANILA_CONF_DIR/rootwrap.d:" -i $MANILA_CONF_DIR/rootwrap.conf
  154. sudo chown root:root $MANILA_CONF_DIR/rootwrap.conf
  155. sudo chmod 0644 $MANILA_CONF_DIR/rootwrap.conf
  156. # Specify rootwrap.conf as first parameter to manila-rootwrap
  157. MANILA_ROOTWRAP="$MANILA_ROOTWRAP $MANILA_CONF_DIR/rootwrap.conf"
  158. ROOTWRAP_MANILA_SUDOER_CMD="$MANILA_ROOTWRAP *"
  159. fi
  160. TEMPFILE=`mktemp`
  161. echo "$USER ALL=(root) NOPASSWD: $ROOTWRAP_MANILA_SUDOER_CMD" >$TEMPFILE
  162. chmod 0440 $TEMPFILE
  163. sudo chown root:root $TEMPFILE
  164. sudo mv $TEMPFILE /etc/sudoers.d/manila-rootwrap
  165. cp $MANILA_DIR/etc/manila/api-paste.ini $MANILA_API_PASTE_INI
  166. # Remove old conf file if exists
  167. rm -f $MANILA_CONF
  168. configure_auth_token_middleware $MANILA_CONF manila $MANILA_AUTH_CACHE_DIR
  169. iniset $MANILA_CONF DEFAULT auth_strategy keystone
  170. iniset $MANILA_CONF DEFAULT debug True
  171. iniset $MANILA_CONF DEFAULT scheduler_driver $MANILA_SCHEDULER_DRIVER
  172. iniset $MANILA_CONF DEFAULT share_name_template ${SHARE_NAME_PREFIX}%s
  173. iniset $MANILA_CONF DATABASE connection `database_connection_url manila`
  174. iniset $MANILA_CONF DATABASE max_pool_size 40
  175. iniset $MANILA_CONF DEFAULT api_paste_config $MANILA_API_PASTE_INI
  176. iniset $MANILA_CONF DEFAULT rootwrap_config $MANILA_CONF_DIR/rootwrap.conf
  177. iniset $MANILA_CONF DEFAULT osapi_share_extension manila.api.contrib.standard_extensions
  178. iniset $MANILA_CONF DEFAULT state_path $MANILA_STATE_PATH
  179. # Note: Sample share types will still be created if the below is False
  180. if [ $(trueorfalse False MANILA_CONFIGURE_DEFAULT_TYPES) == True ]; then
  181. iniset $MANILA_CONF DEFAULT default_share_type $MANILA_DEFAULT_SHARE_TYPE
  182. iniset $MANILA_CONF DEFAULT default_share_group_type $MANILA_DEFAULT_SHARE_GROUP_TYPE
  183. fi
  184. if ! [[ -z $MANILA_SHARE_MIGRATION_PERIOD_TASK_INTERVAL ]]; then
  185. iniset $MANILA_CONF DEFAULT migration_driver_continue_update_interval $MANILA_SHARE_MIGRATION_PERIOD_TASK_INTERVAL
  186. fi
  187. if ! [[ -z $MANILA_DATA_COPY_CHECK_HASH ]]; then
  188. iniset $MANILA_CONF DEFAULT check_hash $MANILA_DATA_COPY_CHECK_HASH
  189. fi
  190. iniset $MANILA_CONF DEFAULT enabled_share_protocols $MANILA_ENABLED_SHARE_PROTOCOLS
  191. iniset $MANILA_CONF oslo_concurrency lock_path $MANILA_LOCK_PATH
  192. iniset $MANILA_CONF DEFAULT wsgi_keep_alive False
  193. iniset $MANILA_CONF DEFAULT lvm_share_volume_group $SHARE_GROUP
  194. # Set the replica_state_update_interval
  195. iniset $MANILA_CONF DEFAULT replica_state_update_interval $MANILA_REPLICA_STATE_UPDATE_INTERVAL
  196. if is_service_enabled neutron; then
  197. configure_auth_token_middleware $MANILA_CONF neutron $MANILA_AUTH_CACHE_DIR neutron
  198. fi
  199. if is_service_enabled nova; then
  200. configure_auth_token_middleware $MANILA_CONF nova $MANILA_AUTH_CACHE_DIR nova
  201. fi
  202. if is_service_enabled cinder; then
  203. configure_auth_token_middleware $MANILA_CONF cinder $MANILA_AUTH_CACHE_DIR cinder
  204. fi
  205. # Note: set up config group does not mean that this backend will be enabled.
  206. # To enable it, specify its name explicitly using "enabled_share_backends" opt.
  207. configure_default_backends
  208. default_backends=$MANILA_BACKEND1_CONFIG_GROUP_NAME
  209. if [ "$MANILA_MULTI_BACKEND" = "True" ]; then
  210. default_backends+=,$MANILA_BACKEND2_CONFIG_GROUP_NAME
  211. fi
  212. if [ ! $MANILA_ENABLED_BACKENDS ]; then
  213. # If $MANILA_ENABLED_BACKENDS is not set, use configured backends by default
  214. export MANILA_ENABLED_BACKENDS=$default_backends
  215. fi
  216. iniset $MANILA_CONF DEFAULT enabled_share_backends $MANILA_ENABLED_BACKENDS
  217. if [ ! -f $MANILA_PATH_TO_PRIVATE_KEY ]; then
  218. ssh-keygen -N "" -t rsa -f $MANILA_PATH_TO_PRIVATE_KEY;
  219. fi
  220. iniset $MANILA_CONF DEFAULT manila_service_keypair_name $MANILA_SERVICE_KEYPAIR_NAME
  221. if is_service_enabled tls-proxy; then
  222. # Set the service port for a proxy to take the original
  223. iniset $MANILA_CONF DEFAULT osapi_share_listen_port $MANILA_SERVICE_PORT_INT
  224. fi
  225. iniset_rpc_backend manila $MANILA_CONF DEFAULT
  226. setup_logging $MANILA_CONF
  227. MANILA_CONFIGURE_GROUPS=${MANILA_CONFIGURE_GROUPS:-"$MANILA_ENABLED_BACKENDS"}
  228. set_config_opts $MANILA_CONFIGURE_GROUPS
  229. set_config_opts DEFAULT
  230. if [ $(trueorfalse False MANILA_USE_MOD_WSGI) == True ]; then
  231. _config_manila_apache_wsgi
  232. fi
  233. }
  234. function create_manila_service_keypair {
  235. if is_service_enabled nova; then
  236. local keypair_exists=$( openstack keypair list | grep " $MANILA_SERVICE_KEYPAIR_NAME " )
  237. if [[ -z $keypair_exists ]]; then
  238. openstack keypair create $MANILA_SERVICE_KEYPAIR_NAME --public-key $MANILA_PATH_TO_PUBLIC_KEY
  239. fi
  240. fi
  241. }
  242. function is_driver_enabled {
  243. driver_name=$1
  244. for BE in ${MANILA_ENABLED_BACKENDS//,/ }; do
  245. share_driver=$(iniget $MANILA_CONF $BE share_driver)
  246. if [ "$share_driver" == "$driver_name" ]; then
  247. return 0
  248. fi
  249. done
  250. return 1
  251. }
  252. # create_service_share_servers - creates service Nova VMs, one per generic
  253. # driver, and only if it is configured to mode without handling of share servers.
  254. function create_service_share_servers {
  255. created_admin_network=false
  256. for BE in ${MANILA_ENABLED_BACKENDS//,/ }; do
  257. driver_handles_share_servers=$(iniget $MANILA_CONF $BE driver_handles_share_servers)
  258. share_driver=$(iniget $MANILA_CONF $BE share_driver)
  259. generic_driver='manila.share.drivers.generic.GenericShareDriver'
  260. if [[ $share_driver == $generic_driver ]]; then
  261. if [[ $(trueorfalse False driver_handles_share_servers) == False ]]; then
  262. vm_name='manila_service_share_server_'$BE
  263. local vm_exists=$( openstack server list --all-projects | grep " $vm_name " )
  264. if [[ -z $vm_exists ]]; then
  265. private_net_id=$(openstack network show $PRIVATE_NETWORK_NAME -f value -c id)
  266. vm_id=$(openstack server create $vm_name \
  267. --flavor $MANILA_SERVICE_VM_FLAVOR_NAME \
  268. --image $MANILA_SERVICE_IMAGE_NAME \
  269. --nic net-id=$private_net_id \
  270. --security-group $MANILA_SERVICE_SECGROUP \
  271. --key-name $MANILA_SERVICE_KEYPAIR_NAME \
  272. | grep ' id ' | get_field 2)
  273. else
  274. vm_id=$(openstack server show $vm_name -f value -c id)
  275. fi
  276. floating_ip=$(openstack floating ip create $PUBLIC_NETWORK_NAME --subnet $PUBLIC_SUBNET_NAME | grep 'floating_ip_address' | get_field 2)
  277. # TODO(rishabh-d-dave): For time being circumvent the bug -
  278. # https://bugs.launchpad.net/python-openstackclient/+bug/1747721
  279. # Once fixed, replace the following 3 lines by -
  280. # openstack server add floating ip $vm_id $floating_ip
  281. vm_port_id=$(openstack port list --server $vm_id -c ID -f \
  282. value)
  283. openstack floating ip set --port $vm_port_id $floating_ip
  284. iniset $MANILA_CONF $BE service_instance_name_or_id $vm_id
  285. iniset $MANILA_CONF $BE service_net_name_or_ip $floating_ip
  286. iniset $MANILA_CONF $BE tenant_net_name_or_ip $PRIVATE_NETWORK_NAME
  287. else
  288. if is_service_enabled neutron; then
  289. if ! [[ -z $MANILA_ADMIN_NET_RANGE ]]; then
  290. if [ $created_admin_network == false ]; then
  291. project_id=$(openstack project show $SERVICE_PROJECT_NAME -c id -f value)
  292. local admin_net_id=$( openstack network show admin_net -f value -c id )
  293. if [[ -z $admin_net_id ]]; then
  294. openstack network create admin_net --project $project_id
  295. admin_net_id=$(openstack network show admin_net -f value -c id)
  296. fi
  297. local admin_subnet_id=$( openstack subnet show admin_subnet -f value -c id )
  298. if [[ -z $admin_subnet_id ]]; then
  299. openstack subnet create admin_subnet --project $project_id --ip-version 4 --network $admin_net_id --gateway None --subnet-range $MANILA_ADMIN_NET_RANGE
  300. admin_subnet_id=$(openstack subnet show admin_subnet -f value -c id)
  301. fi
  302. created_admin_network=true
  303. fi
  304. iniset $MANILA_CONF $BE admin_network_id $admin_net_id
  305. iniset $MANILA_CONF $BE admin_subnet_id $admin_subnet_id
  306. fi
  307. fi
  308. fi
  309. fi
  310. done
  311. configure_data_service_generic_driver
  312. }
  313. function configure_data_service_generic_driver {
  314. enabled_backends=(${MANILA_ENABLED_BACKENDS//,/ })
  315. share_driver=$(iniget $MANILA_CONF ${enabled_backends[0]} share_driver)
  316. generic_driver='manila.share.drivers.generic.GenericShareDriver'
  317. if [[ $share_driver == $generic_driver ]]; then
  318. driver_handles_share_servers=$(iniget $MANILA_CONF ${enabled_backends[0]} driver_handles_share_servers)
  319. if [[ $(trueorfalse False driver_handles_share_servers) == False ]]; then
  320. iniset $MANILA_CONF DEFAULT data_node_access_ip $PUBLIC_NETWORK_GATEWAY
  321. else
  322. if ! [[ -z $MANILA_DATA_NODE_IP ]]; then
  323. iniset $MANILA_CONF DEFAULT data_node_access_ip $MANILA_DATA_NODE_IP
  324. fi
  325. fi
  326. fi
  327. }
  328. # create_manila_service_flavor - creates flavor, that will be used by backends
  329. # with configured generic driver to boot Nova VMs with.
  330. function create_manila_service_flavor {
  331. if is_service_enabled nova; then
  332. local flavor_exists=$( openstack flavor list | grep " $MANILA_SERVICE_VM_FLAVOR_NAME " )
  333. if [[ -z $flavor_exists ]]; then
  334. # Create flavor for Manila's service VM
  335. openstack flavor create \
  336. $MANILA_SERVICE_VM_FLAVOR_NAME \
  337. --id $MANILA_SERVICE_VM_FLAVOR_REF \
  338. --ram $MANILA_SERVICE_VM_FLAVOR_RAM \
  339. --disk $MANILA_SERVICE_VM_FLAVOR_DISK \
  340. --vcpus $MANILA_SERVICE_VM_FLAVOR_VCPUS
  341. fi
  342. fi
  343. }
  344. # create_manila_service_image - creates image, that will be used by backends
  345. # with configured generic driver to boot Nova VMs from.
  346. function create_manila_service_image {
  347. if is_service_enabled nova; then
  348. TOKEN=$(openstack token issue -c id -f value)
  349. local image_exists=$( openstack image list | grep " $MANILA_SERVICE_IMAGE_NAME " )
  350. if [[ -z $image_exists ]]; then
  351. # Download Manila's image
  352. if is_service_enabled g-reg; then
  353. upload_image $MANILA_SERVICE_IMAGE_URL $TOKEN
  354. fi
  355. fi
  356. fi
  357. }
  358. # create_manila_service_secgroup - creates security group that is used by
  359. # Nova VMs when generic driver is configured.
  360. function create_manila_service_secgroup {
  361. # Create a secgroup
  362. if ! openstack security group list | grep -q $MANILA_SERVICE_SECGROUP; then
  363. openstack security group create $MANILA_SERVICE_SECGROUP --description "$MANILA_SERVICE_SECGROUP description"
  364. if ! timeout 30 sh -c "while ! openstack security group list | grep -q $MANILA_SERVICE_SECGROUP; do sleep 1; done"; then
  365. echo "Security group not created"
  366. exit 1
  367. fi
  368. fi
  369. # Configure Security Group Rules
  370. if ! openstack security group rule list $MANILA_SERVICE_SECGROUP | grep -q icmp; then
  371. openstack security group rule create $MANILA_SERVICE_SECGROUP --protocol icmp
  372. fi
  373. if ! openstack security group rule list $MANILA_SERVICE_SECGROUP | grep -q " tcp .* 22 "; then
  374. openstack security group rule create $MANILA_SERVICE_SECGROUP --protocol tcp --dst-port 22
  375. fi
  376. if ! openstack security group rule list $MANILA_SERVICE_SECGROUP | grep -q " tcp .* 2049 "; then
  377. openstack security group rule create $MANILA_SERVICE_SECGROUP --protocol tcp --dst-port 2049
  378. fi
  379. if ! openstack security group rule list $MANILA_SERVICE_SECGROUP | grep -q " udp .* 2049 "; then
  380. openstack security group rule create $MANILA_SERVICE_SECGROUP --protocol udp --dst-port 2049
  381. fi
  382. if ! openstack security group rule list $MANILA_SERVICE_SECGROUP | grep -q " udp .* 445 "; then
  383. openstack security group rule create $MANILA_SERVICE_SECGROUP --protocol udp --dst-port 445
  384. fi
  385. if ! openstack security group rule list $MANILA_SERVICE_SECGROUP | grep -q " tcp .* 445 "; then
  386. openstack security group rule create $MANILA_SERVICE_SECGROUP --protocol tcp --dst-port 445
  387. fi
  388. if ! openstack security group rule list $MANILA_SERVICE_SECGROUP | grep -q " tcp .* 139 "; then
  389. openstack security group rule create $MANILA_SERVICE_SECGROUP --protocol tcp --dst-port 137:139
  390. fi
  391. if ! openstack security group rule list $MANILA_SERVICE_SECGROUP | grep -q " udp .* 139 "; then
  392. openstack security group rule create $MANILA_SERVICE_SECGROUP --protocol udp --dst-port 137:139
  393. fi
  394. # List secgroup rules
  395. openstack security group rule list $MANILA_SERVICE_SECGROUP
  396. }
  397. # create_manila_accounts - Set up common required manila accounts
  398. function create_manila_accounts {
  399. create_service_user "manila"
  400. # Set up Manila v1 service and endpoint
  401. get_or_create_service "manila" "share" "Manila Shared Filesystem Service"
  402. get_or_create_endpoint "share" "$REGION_NAME" \
  403. "$MANILA_SERVICE_PROTOCOL://$MANILA_SERVICE_HOST:$MANILA_SERVICE_PORT/v1/\$(tenant_id)s" \
  404. "$MANILA_SERVICE_PROTOCOL://$MANILA_SERVICE_HOST:$MANILA_SERVICE_PORT/v1/\$(tenant_id)s" \
  405. "$MANILA_SERVICE_PROTOCOL://$MANILA_SERVICE_HOST:$MANILA_SERVICE_PORT/v1/\$(tenant_id)s"
  406. # Set up Manila v2 service and endpoint
  407. get_or_create_service "manilav2" "sharev2" "Manila Shared Filesystem Service V2"
  408. get_or_create_endpoint "sharev2" "$REGION_NAME" \
  409. "$MANILA_SERVICE_PROTOCOL://$MANILA_SERVICE_HOST:$MANILA_SERVICE_PORT/v2/\$(tenant_id)s" \
  410. "$MANILA_SERVICE_PROTOCOL://$MANILA_SERVICE_HOST:$MANILA_SERVICE_PORT/v2/\$(tenant_id)s" \
  411. "$MANILA_SERVICE_PROTOCOL://$MANILA_SERVICE_HOST:$MANILA_SERVICE_PORT/v2/\$(tenant_id)s"
  412. }
  413. # create_default_share_group_type - create share group type that will be set as default.
  414. function create_default_share_group_type {
  415. local type_exists=$( manila share-group-type-list | grep " $MANILA_DEFAULT_SHARE_GROUP_TYPE " )
  416. if [[ -z $type_exists ]]; then
  417. manila share-group-type-create $MANILA_DEFAULT_SHARE_GROUP_TYPE $MANILA_DEFAULT_SHARE_TYPE
  418. fi
  419. if [[ $MANILA_DEFAULT_SHARE_GROUP_TYPE_SPECS ]]; then
  420. manila share-group-type-key $MANILA_DEFAULT_SHARE_GROUP_TYPE set $MANILA_DEFAULT_SHARE_GROUP_TYPE_SPECS
  421. fi
  422. }
  423. # create_default_share_type - create share type that will be set as default
  424. # if $MANILA_CONFIGURE_DEFAULT_TYPES is set to True, if set to False, the share
  425. # type identified by $MANILA_DEFAULT_SHARE_TYPE is still created, but not
  426. # configured as default.
  427. function create_default_share_type {
  428. echo "Waiting for Manila API to start..."
  429. if ! wait_for_service 60 $MANILA_SERVICE_PROTOCOL://$MANILA_SERVICE_HOST:$MANILA_SERVICE_PORT; then
  430. die $LINENO "Manila did not start"
  431. fi
  432. enabled_backends=(${MANILA_ENABLED_BACKENDS//,/ })
  433. driver_handles_share_servers=$(iniget $MANILA_CONF ${enabled_backends[0]} driver_handles_share_servers)
  434. local type_exists=$( manila type-list | grep " $MANILA_DEFAULT_SHARE_TYPE " )
  435. if [[ -z $type_exists ]]; then
  436. local command_args="$MANILA_DEFAULT_SHARE_TYPE $driver_handles_share_servers"
  437. #if is_driver_enabled $MANILA_CONTAINER_DRIVER; then
  438. # # TODO(aovchinnikov): Remove this condition when Container driver supports
  439. # # snapshots
  440. # command_args="$command_args --snapshot_support false"
  441. #fi
  442. manila type-create $command_args
  443. fi
  444. if [[ $MANILA_DEFAULT_SHARE_TYPE_EXTRA_SPECS ]]; then
  445. manila type-key $MANILA_DEFAULT_SHARE_TYPE set $MANILA_DEFAULT_SHARE_TYPE_EXTRA_SPECS
  446. fi
  447. }
  448. # create_custom_share_types - create share types suitable for both possible
  449. # driver modes with names "dhss_true" and "dhss_false".
  450. function create_custom_share_types {
  451. manila type-create dhss_true True
  452. if [[ $MANILA_DHSS_TRUE_SHARE_TYPE_EXTRA_SPECS ]]; then
  453. manila type-key dhss_true set $MANILA_DHSS_TRUE_SHARE_TYPE_EXTRA_SPECS
  454. fi
  455. manila type-create dhss_false False
  456. if [[ $MANILA_DHSS_FALSE_SHARE_TYPE_EXTRA_SPECS ]]; then
  457. manila type-key dhss_false set $MANILA_DHSS_FALSE_SHARE_TYPE_EXTRA_SPECS
  458. fi
  459. }
  460. # configure_backing_file - Set up backing file for LVM
  461. function configure_backing_file {
  462. if ! sudo vgs $SHARE_GROUP; then
  463. if [ "$CONFIGURE_BACKING_FILE" = "True" ]; then
  464. SHARE_BACKING_FILE=${SHARE_BACKING_FILE:-$DATA_DIR/${SHARE_GROUP}-backing-file}
  465. # Only create if the file doesn't already exists
  466. [[ -f $SHARE_BACKING_FILE ]] || truncate -s $SHARE_BACKING_FILE_SIZE $SHARE_BACKING_FILE
  467. DEV=`sudo losetup -f --show $SHARE_BACKING_FILE`
  468. else
  469. DEV=$SHARE_BACKING_FILE
  470. fi
  471. # Only create if the loopback device doesn't contain $SHARE_GROUP
  472. if ! sudo vgs $SHARE_GROUP; then sudo vgcreate $SHARE_GROUP $DEV; fi
  473. fi
  474. mkdir -p $MANILA_STATE_PATH/shares
  475. mkdir -p /tmp/shares
  476. }
  477. # init_manila - Initializes database and creates manila dir if absent
  478. function init_manila {
  479. if is_service_enabled $DATABASE_BACKENDS; then
  480. # (re)create manila database
  481. recreate_database manila
  482. $MANILA_BIN_DIR/manila-manage db sync
  483. if [[ $(trueorfalse False MANILA_USE_DOWNGRADE_MIGRATIONS) == True ]]; then
  484. # Use both - upgrade and downgrade migrations to verify that
  485. # downgrade migrations do not break structure of Manila database.
  486. $MANILA_BIN_DIR/manila-manage db downgrade
  487. $MANILA_BIN_DIR/manila-manage db sync
  488. fi
  489. # Display version as debug-action (see bug/1473400)
  490. $MANILA_BIN_DIR/manila-manage db version
  491. fi
  492. if [ "$SHARE_DRIVER" == "manila.share.drivers.lvm.LVMShareDriver" ]; then
  493. if is_service_enabled m-shr; then
  494. # Configure a default volume group called '`lvm-shares`' for the share
  495. # service if it does not yet exist. If you don't wish to use a file backed
  496. # volume group, create your own volume group called ``stack-volumes`` before
  497. # invoking ``stack.sh``.
  498. #
  499. # By default, the backing file is 8G in size, and is stored in ``/opt/stack/data``.
  500. configure_backing_file
  501. fi
  502. elif [ "$SHARE_DRIVER" == $MANILA_CONTAINER_DRIVER ]; then
  503. if is_service_enabled m-shr; then
  504. SHARE_GROUP=$MANILA_CONTAINER_VOLUME_GROUP_NAME
  505. configure_backing_file
  506. fi
  507. elif [ "$SHARE_DRIVER" == "manila.share.drivers.zfsonlinux.driver.ZFSonLinuxShareDriver" ]; then
  508. if is_service_enabled m-shr; then
  509. mkdir -p $MANILA_ZFSONLINUX_BACKEND_FILES_CONTAINER_DIR
  510. file_counter=0
  511. MANILA_ZFSONLINUX_SERVICE_IP=${MANILA_ZFSONLINUX_SERVICE_IP:-"127.0.0.1"}
  512. for BE in ${MANILA_ENABLED_BACKENDS//,/ }; do
  513. if [[ $file_counter == 0 ]]; then
  514. # NOTE(vponomaryov): create two pools for first ZFS backend
  515. # to cover different use cases that are supported by driver:
  516. # - Support of more than one zpool for share backend.
  517. # - Support of nested datasets.
  518. local first_file="$MANILA_ZFSONLINUX_BACKEND_FILES_CONTAINER_DIR"/alpha
  519. local second_file="$MANILA_ZFSONLINUX_BACKEND_FILES_CONTAINER_DIR"/betta
  520. truncate -s $MANILA_ZFSONLINUX_ZPOOL_SIZE $first_file
  521. truncate -s $MANILA_ZFSONLINUX_ZPOOL_SIZE $second_file
  522. sudo zpool create alpha $first_file
  523. sudo zpool create betta $second_file
  524. # Create subdir (nested dataset) for second pool
  525. sudo zfs create betta/subdir
  526. iniset $MANILA_CONF $BE zfs_zpool_list alpha,betta/subdir
  527. elif [[ $file_counter == 1 ]]; then
  528. local file="$MANILA_ZFSONLINUX_BACKEND_FILES_CONTAINER_DIR"/gamma
  529. truncate -s $MANILA_ZFSONLINUX_ZPOOL_SIZE $file
  530. sudo zpool create gamma $file
  531. iniset $MANILA_CONF $BE zfs_zpool_list gamma
  532. else
  533. local filename=file"$file_counter"
  534. local file="$MANILA_ZFSONLINUX_BACKEND_FILES_CONTAINER_DIR"/"$filename"
  535. truncate -s $MANILA_ZFSONLINUX_ZPOOL_SIZE $file
  536. sudo zpool create $filename $file
  537. iniset $MANILA_CONF $BE zfs_zpool_list $filename
  538. fi
  539. iniset $MANILA_CONF $BE zfs_share_export_ip $MANILA_ZFSONLINUX_SHARE_EXPORT_IP
  540. iniset $MANILA_CONF $BE zfs_service_ip $MANILA_ZFSONLINUX_SERVICE_IP
  541. iniset $MANILA_CONF $BE zfs_dataset_creation_options $MANILA_ZFSONLINUX_DATASET_CREATION_OPTIONS
  542. iniset $MANILA_CONF $BE zfs_use_ssh $MANILA_ZFSONLINUX_USE_SSH
  543. iniset $MANILA_CONF $BE zfs_ssh_username $MANILA_ZFSONLINUX_SSH_USERNAME
  544. iniset $MANILA_CONF $BE replication_domain $MANILA_ZFSONLINUX_REPLICATION_DOMAIN
  545. iniset $MANILA_CONF $BE driver_handles_share_servers False
  546. let "file_counter=file_counter+1"
  547. done
  548. # Install the server's SSH key in our known_hosts file
  549. eval STACK_HOME=~$STACK_USER
  550. ssh-keyscan ${MANILA_ZFSONLINUX_SERVICE_IP} >> $STACK_HOME/.ssh/known_hosts
  551. # If the server is this machine, setup trust for ourselves (otherwise you're on your own)
  552. if [ "$MANILA_ZFSONLINUX_SERVICE_IP" = "127.0.0.1" ] || [ "$MANILA_ZFSONLINUX_SERVICE_IP" = "localhost" ] ; then
  553. # Trust our own SSH keys
  554. eval SSH_USER_HOME=~$MANILA_ZFSONLINUX_SSH_USERNAME
  555. cat $STACK_HOME/.ssh/*.pub >> $SSH_USER_HOME/.ssh/authorized_keys
  556. # Give ssh user sudo access
  557. echo "$MANILA_ZFSONLINUX_SSH_USERNAME ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers > /dev/null
  558. iniset $MANILA_CONF DEFAULT data_node_access_ip $MANILA_ZFSONLINUX_SERVICE_IP
  559. fi
  560. fi
  561. fi
  562. # Create cache dir
  563. sudo mkdir -p $MANILA_AUTH_CACHE_DIR
  564. sudo chown $STACK_USER $MANILA_AUTH_CACHE_DIR
  565. rm -f $MANILA_AUTH_CACHE_DIR/*
  566. }
  567. # check_nfs_kernel_service_state_ubuntu- Make sure nfsd is running
  568. function check_nfs_kernel_service_state_ubuntu {
  569. # (aovchinnikov): Workaround for nfs-utils bug 1052264
  570. if [[ $(sudo service nfs-kernel-server status &> /dev/null || echo 'fail') == 'fail' ]]; then
  571. echo "Apparently nfsd is not running. Trying to fix that."
  572. sudo mkdir -p "/media/nfsdonubuntuhelper"
  573. # (aovchinnikov): shell wrapping is needed for cases when a file to be written
  574. # is owned by root.
  575. sudo sh -c "echo '/media/nfsdonubuntuhelper 127.0.0.1(ro)' >> /etc/exports"
  576. sudo service nfs-kernel-server start
  577. fi
  578. if [[ $(sudo service nfs-kernel-server status &> /dev/null || echo 'fail') == 'fail' ]]; then
  579. echo "Failed to start nfsd. Exiting."
  580. exit 1
  581. fi
  582. }
  583. function _install_nfs_and_samba {
  584. if is_ubuntu; then
  585. install_package nfs-kernel-server nfs-common samba
  586. check_nfs_kernel_service_state_ubuntu
  587. elif is_fedora; then
  588. install_package nfs-utils samba
  589. sudo systemctl enable smb.service
  590. sudo systemctl start smb.service
  591. sudo systemctl enable nfs-server.service
  592. sudo systemctl start nfs-server.service
  593. elif is_suse; then
  594. install_package nfs-kernel-server nfs-utils samba
  595. else
  596. echo "This distro is not supported. Skipping step of NFS and Samba installation."
  597. fi
  598. }
  599. # install_manilaclient - Collect source and prepare
  600. # In order to install from git, add LIBS_FROM_GIT="python-manilaclient"
  601. # to local.conf
  602. function install_manilaclient {
  603. if use_library_from_git "python-manilaclient"; then
  604. git_clone $MANILACLIENT_REPO $MANILACLIENT_DIR $MANILACLIENT_BRANCH
  605. setup_develop $MANILACLIENT_DIR
  606. else
  607. pip_install python-manilaclient
  608. fi
  609. }
  610. # install_manila - Collect source and prepare
  611. function install_manila {
  612. setup_develop $MANILA_DIR
  613. if is_service_enabled m-shr; then
  614. if [[ ! $(systemctl is-active nfs-ganesha.service) == 'active' ]]; then
  615. _install_nfs_and_samba
  616. fi
  617. if [ "$SHARE_DRIVER" == "manila.share.drivers.zfsonlinux.driver.ZFSonLinuxShareDriver" ]; then
  618. if [[ $(sudo zfs list &> /dev/null && sudo zpool list &> /dev/null || echo 'absent') == 'absent' ]]; then
  619. # ZFS not found, try to install it
  620. if is_ubuntu; then
  621. if [[ $(lsb_release -s -d) == *"14.04"* ]]; then
  622. # Trusty
  623. sudo apt-get install -y software-properties-common
  624. sudo apt-add-repository --yes ppa:zfs-native/stable
  625. # Workaround for bug #1609696
  626. sudo apt-mark hold grub*
  627. sudo apt-get -y -q update && sudo apt-get -y -q upgrade
  628. # Workaround for bug #1609696
  629. sudo apt-mark unhold grub*
  630. sudo apt-get install -y linux-headers-generic
  631. sudo apt-get install -y build-essential
  632. sudo apt-get install -y ubuntu-zfs
  633. elif [[ $(echo $(lsb_release -rs) '>=' 16.04 | bc -l) == 1 ]]; then
  634. # Xenial and beyond
  635. sudo apt-get install -y zfsutils-linux
  636. else
  637. echo "Only 'Trusty', 'Xenial' and newer releases of Ubuntu are supported."
  638. exit 1
  639. fi
  640. else
  641. echo "Manila Devstack plugin supports installation "\
  642. "of ZFS packages only for 'Ubuntu' distros. "\
  643. "Please, install it first by other means or add its support "\
  644. "for your distro."
  645. exit 1
  646. fi
  647. sudo modprobe zfs
  648. sudo modprobe zpool
  649. fi
  650. check_nfs_kernel_service_state_ubuntu
  651. elif [ "$SHARE_DRIVER" == $MANILA_CONTAINER_DRIVER ]; then
  652. if is_ubuntu; then
  653. echo "Installing docker...."
  654. install_docker_ubuntu
  655. echo "Importing docker image"
  656. import_docker_service_image_ubuntu
  657. elif is_fedora; then
  658. echo "Installing docker...."
  659. install_docker_fedora
  660. echo "Importing docker image"
  661. # TODO(tbarron): See if using a fedora container image
  662. # is faster/smaller because of fewer extra dependencies.
  663. import_docker_service_image_ubuntu
  664. else
  665. echo "Manila Devstack plugin does not support Container Driver on"\
  666. " distros other than Ubuntu or Fedora."
  667. exit 1
  668. fi
  669. fi
  670. fi
  671. }
  672. #configure_samba - Configure node as Samba server
  673. function configure_samba {
  674. if [ "$SHARE_DRIVER" == "manila.share.drivers.lvm.LVMShareDriver" ]; then
  675. # TODO(vponomaryov): add here condition for ZFSonLinux driver too
  676. # when it starts to support SAMBA
  677. samba_daemon_name=smbd
  678. if is_service_enabled m-shr; then
  679. if is_fedora; then
  680. samba_daemon_name=smb
  681. fi
  682. sudo service $samba_daemon_name restart || echo "Couldn't restart '$samba_daemon_name' service"
  683. fi
  684. if [[ -e /usr/share/samba/smb.conf ]]; then
  685. sudo cp /usr/share/samba/smb.conf $SMB_CONF
  686. fi
  687. sudo chown $STACK_USER -R /etc/samba
  688. iniset $SMB_CONF global include registry
  689. iniset $SMB_CONF global security user
  690. if [ ! -d "$SMB_PRIVATE_DIR" ]; then
  691. sudo mkdir $SMB_PRIVATE_DIR
  692. sudo touch $SMB_PRIVATE_DIR/secrets.tdb
  693. fi
  694. for backend_name in ${MANILA_ENABLED_BACKENDS//,/ }; do
  695. iniset $MANILA_CONF $backend_name driver_handles_share_servers False
  696. iniset $MANILA_CONF $backend_name lvm_share_export_ips $MANILA_LVM_SHARE_EXPORT_IPS
  697. done
  698. iniset $MANILA_CONF DEFAULT data_node_access_ip $HOST_IP
  699. fi
  700. }
  701. # start_manila_api - starts manila API services and checks its availability
  702. function start_manila_api {
  703. if [ $(trueorfalse False MANILA_USE_MOD_WSGI) == True ]; then
  704. install_apache_wsgi
  705. enable_apache_site manila-api
  706. restart_apache_server
  707. tail_log m-api /var/log/$APACHE_NAME/manila_api.log
  708. else
  709. run_process m-api "$MANILA_BIN_DIR/manila-api --config-file $MANILA_CONF"
  710. fi
  711. echo "Waiting for Manila API to start..."
  712. if ! wait_for_service $SERVICE_TIMEOUT $MANILA_SERVICE_PROTOCOL://$MANILA_SERVICE_HOST:$MANILA_SERVICE_PORT; then
  713. die $LINENO "Manila API did not start"
  714. fi
  715. # Start proxies if enabled
  716. if is_service_enabled tls-proxy; then
  717. start_tls_proxy '*' $MANILA_SERVICE_PORT $MANILA_SERVICE_HOST $MANILA_SERVICE_PORT_INT &
  718. fi
  719. }
  720. # start_rest_of_manila - starts non-api manila services
  721. function start_rest_of_manila {
  722. run_process m-shr "$MANILA_BIN_DIR/manila-share --config-file $MANILA_CONF"
  723. run_process m-sch "$MANILA_BIN_DIR/manila-scheduler --config-file $MANILA_CONF"
  724. run_process m-dat "$MANILA_BIN_DIR/manila-data --config-file $MANILA_CONF"
  725. }
  726. # start_manila - start all manila services. This function is kept for compatibility
  727. # reasons with old approach.
  728. function start_manila {
  729. start_manila_api
  730. start_rest_of_manila
  731. }
  732. # stop_manila - Stop running processes
  733. function stop_manila {
  734. # Disable manila api service
  735. if [ $(trueorfalse False MANILA_USE_MOD_WSGI) == True ]; then
  736. disable_apache_site manila-api
  737. restart_apache_server
  738. else
  739. stop_process m-api
  740. fi
  741. # Kill all other manila processes
  742. for serv in m-sch m-shr m-dat; do
  743. stop_process $serv
  744. done
  745. }
  746. function install_manila_tempest_plugin {
  747. MANILA_TEMPEST_PLUGIN_REPO=${MANILA_TEMPEST_PLUGIN_REPO:-${GIT_BASE}/openstack/manila-tempest-plugin.git}
  748. MANILA_TEMPEST_PLUGIN_BRANCH=${MANILA_TEMPEST_PLUGIN_BRANCH:-master}
  749. MANILA_TEMPEST_PLUGIN_DIR=$DEST/manila-tempest-plugin
  750. git_clone $MANILA_TEMPEST_PLUGIN_REPO $MANILA_TEMPEST_PLUGIN_DIR $MANILA_TEMPEST_PLUGIN_BRANCH
  751. setup_develop $MANILA_TEMPEST_PLUGIN_DIR
  752. }
  753. # update_tempest - Function used for updating Tempest config if Tempest service enabled
  754. function update_tempest {
  755. if is_service_enabled tempest; then
  756. TEMPEST_CONFIG=${TEMPEST_CONFIG:-$TEMPEST_DIR/etc/tempest.conf}
  757. ADMIN_TENANT_NAME=${ADMIN_TENANT_NAME:-"admin"}
  758. ADMIN_DOMAIN_NAME=${ADMIN_DOMAIN_NAME:-"Default"}
  759. ADMIN_PASSWORD=${ADMIN_PASSWORD:-"secretadmin"}
  760. if [ $(trueorfalse False MANILA_USE_SERVICE_INSTANCE_PASSWORD) == True ]; then
  761. iniset $TEMPEST_CONFIG share image_password $MANILA_SERVICE_INSTANCE_PASSWORD
  762. fi
  763. iniset $TEMPEST_CONFIG share image_with_share_tools $MANILA_SERVICE_IMAGE_NAME
  764. iniset $TEMPEST_CONFIG auth admin_username ${ADMIN_USERNAME:-"admin"}
  765. iniset $TEMPEST_CONFIG auth admin_password ${ADMIN_PASSWORD:-"secretadmin"}
  766. iniset $TEMPEST_CONFIG auth admin_tenant_name $ADMIN_TENANT_NAME
  767. iniset $TEMPEST_CONFIG auth admin_domain_name $ADMIN_DOMAIN_NAME
  768. iniset $TEMPEST_CONFIG identity username ${TEMPEST_USERNAME:-"demo"}
  769. iniset $TEMPEST_CONFIG identity password $ADMIN_PASSWORD
  770. iniset $TEMPEST_CONFIG identity tenant_name ${TEMPEST_TENANT_NAME:-"demo"}
  771. iniset $TEMPEST_CONFIG identity domain_name $ADMIN_DOMAIN_NAME
  772. iniset $TEMPEST_CONFIG identity alt_username ${ALT_USERNAME:-"alt_demo"}
  773. iniset $TEMPEST_CONFIG identity alt_password $ADMIN_PASSWORD
  774. iniset $TEMPEST_CONFIG identity alt_tenant_name ${ALT_TENANT_NAME:-"alt_demo"}
  775. iniset $TEMPEST_CONFIG identity alt_domain_name $ADMIN_DOMAIN_NAME
  776. fi
  777. }
  778. function install_docker_ubuntu {
  779. sudo apt-get update
  780. install_package apparmor
  781. install_package docker.io
  782. }
  783. function install_docker_fedora {
  784. sudo yum install -y docker
  785. sudo systemctl enable docker
  786. sudo systemctl start docker
  787. }
  788. function download_image {
  789. local image_url=$1
  790. local image image_fname
  791. image_fname=`basename "$image_url"`
  792. if [[ $image_url != file* ]]; then
  793. # Downloads the image (uec ami+akistyle), then extracts it.
  794. if [[ ! -f $FILES/$image_fname || "$(stat -c "%s" $FILES/$image_fname)" = "0" ]]; then
  795. wget --progress=dot:giga -c $image_url -O $FILES/$image_fname
  796. if [[ $? -ne 0 ]]; then
  797. echo "Not found: $image_url"
  798. return
  799. fi
  800. fi
  801. image="$FILES/${image_fname}"
  802. else
  803. # File based URL (RFC 1738): ``file://host/path``
  804. # Remote files are not considered here.
  805. # unix: ``file:///home/user/path/file``
  806. # windows: ``file:///C:/Documents%20and%20Settings/user/path/file``
  807. image=$(echo $image_url | sed "s/^file:\/\///g")
  808. if [[ ! -f $image || "$(stat -c "%s" $image)" == "0" ]]; then
  809. echo "Not found: $image_url"
  810. return
  811. fi
  812. fi
  813. }
  814. function import_docker_service_image_ubuntu {
  815. GZIPPED_IMG_NAME=`basename "$MANILA_DOCKER_IMAGE_URL"`
  816. IMG_NAME_LOAD=${GZIPPED_IMG_NAME%.*}
  817. LOCAL_IMG_NAME=${IMG_NAME_LOAD%.*}
  818. if [[ "$(sudo docker images -q $LOCAL_IMG_NAME)" == "" ]]; then
  819. download_image $MANILA_DOCKER_IMAGE_URL
  820. # Import image in Docker
  821. gzip -d $FILES/$GZIPPED_IMG_NAME
  822. sudo docker load --input $FILES/$IMG_NAME_LOAD
  823. fi
  824. }
  825. function remove_docker_service_image {
  826. sudo docker rmi $MANILA_DOCKER_IMAGE_ALIAS
  827. }
  828. function install_libraries {
  829. if [ $(trueorfalse False MANILA_MULTI_BACKEND) == True ]; then
  830. if [ $(trueorfalse True RUN_MANILA_HOST_ASSISTED_MIGRATION_TESTS) == True ]; then
  831. if is_ubuntu; then
  832. install_package nfs-common
  833. else
  834. install_package nfs-utils
  835. fi
  836. fi
  837. fi
  838. }
  839. function setup_ipv6 {
  840. # save IPv6 default route to add back later after enabling forwarding
  841. local default_route=$(ip -6 route | grep default | cut -d ' ' -f1,2,3,4,5)
  842. # make sure those system values are set
  843. sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0
  844. sudo sysctl -w net.ipv6.conf.all.accept_ra=2
  845. sudo sysctl -w net.ipv6.conf.all.forwarding=1
  846. # Disable in-band as our communication is only internal
  847. sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE other_config:disable-in-band=true
  848. # Create address scopes and subnet pools
  849. openstack address scope create --share --ip-version 4 scope-v4
  850. openstack address scope create --share --ip-version 6 scope-v6
  851. openstack subnet pool create $SUBNETPOOL_NAME_V4 --default-prefix-length $SUBNETPOOL_SIZE_V4 --pool-prefix $SUBNETPOOL_PREFIX_V4 --address-scope scope-v4 --default --share
  852. openstack subnet pool create $SUBNETPOOL_NAME_V6 --default-prefix-length $SUBNETPOOL_SIZE_V6 --pool-prefix $SUBNETPOOL_PREFIX_V6 --address-scope scope-v6 --default --share
  853. # Create example private network and router
  854. openstack router create $Q_ROUTER_NAME
  855. openstack network create $PRIVATE_NETWORK_NAME
  856. openstack subnet create --ip-version 6 --use-default-subnet-pool --ipv6-address-mode $IPV6_ADDRESS_MODE --ipv6-ra-mode $IPV6_RA_MODE --network $PRIVATE_NETWORK_NAME $IPV6_PRIVATE_SUBNET_NAME
  857. openstack subnet create --ip-version 4 --use-default-subnet-pool --network $PRIVATE_NETWORK_NAME $PRIVATE_SUBNET_NAME
  858. openstack router add subnet $Q_ROUTER_NAME $IPV6_PRIVATE_SUBNET_NAME
  859. openstack router add subnet $Q_ROUTER_NAME $PRIVATE_SUBNET_NAME
  860. # Create public network
  861. openstack network create $PUBLIC_NETWORK_NAME --external --default --provider-network-type flat --provider-physical-network $PUBLIC_PHYSICAL_NETWORK
  862. local public_gateway_ipv6=$(openstack subnet create $IPV6_PUBLIC_SUBNET_NAME --ip-version 6 --network $PUBLIC_NETWORK_NAME --subnet-pool $SUBNETPOOL_NAME_V6 --no-dhcp -c gateway_ip -f value)
  863. local public_gateway_ipv4=$(openstack subnet create $PUBLIC_SUBNET_NAME --ip-version 4 --network $PUBLIC_NETWORK_NAME --subnet-range $FLOATING_RANGE --no-dhcp -c gateway_ip -f value)
  864. # Set router to use public network
  865. openstack router set --external-gateway $PUBLIC_NETWORK_NAME $Q_ROUTER_NAME
  866. # Configure interfaces due to NEUTRON_CREATE_INITIAL_NETWORKS=False
  867. local ipv4_cidr_len=${FLOATING_RANGE#*/}
  868. sudo ip -6 addr add "$public_gateway_ipv6"/$SUBNETPOOL_SIZE_V6 dev $PUBLIC_BRIDGE
  869. sudo ip addr add $PUBLIC_NETWORK_GATEWAY/"$ipv4_cidr_len" dev $PUBLIC_BRIDGE
  870. # Enabling interface is needed due to NEUTRON_CREATE_INITIAL_NETWORKS=False
  871. sudo ip link set $PUBLIC_BRIDGE up
  872. if [ "$SHARE_DRIVER" == "manila.share.drivers.lvm.LVMShareDriver" ]; then
  873. for backend_name in ${MANILA_ENABLED_BACKENDS//,/ }; do
  874. iniset $MANILA_CONF $backend_name lvm_share_export_ips $public_gateway_ipv4,$public_gateway_ipv6
  875. done
  876. iniset $MANILA_CONF DEFAULT data_node_access_ip $public_gateway_ipv4
  877. fi
  878. # install Quagga for setting up the host routes dynamically
  879. install_package quagga
  880. # set Quagga daemons
  881. (
  882. echo "zebra=yes"
  883. echo "bgpd=yes"
  884. echo "ospfd=no"
  885. echo "ospf6d=no"
  886. echo "ripd=no"
  887. echo "ripngd=no"
  888. echo "isisd=no"
  889. echo "babeld=no"
  890. ) | sudo tee /etc/quagga/daemons > /dev/null
  891. # set Quagga zebra.conf
  892. (
  893. echo "hostname dsvm"
  894. echo "password openstack"
  895. echo "log file /var/log/quagga/zebra.log"
  896. ) | sudo tee /etc/quagga/zebra.conf > /dev/null
  897. # set Quagga vtysh.conf
  898. (
  899. echo "service integrated-vtysh-config"
  900. echo "username quagga nopassword"
  901. ) | sudo tee /etc/quagga/vtysh.conf > /dev/null
  902. # set Quagga bgpd.conf
  903. (
  904. echo "log file /var/log/quagga/bgpd.log"
  905. echo "bgp multiple-instance"
  906. echo "router bgp 200"
  907. echo " bgp router-id 1.2.3.4"
  908. echo " neighbor $public_gateway_ipv6 remote-as 100"
  909. echo " neighbor $public_gateway_ipv6 passive"
  910. echo " address-family ipv6"
  911. echo " neighbor $public_gateway_ipv6 activate"
  912. echo "line vty"
  913. echo "debug bgp events"
  914. echo "debug bgp filters"
  915. echo "debug bgp fsm"
  916. echo "debug bgp keepalives"
  917. echo "debug bgp updates"
  918. ) | sudo tee /etc/quagga/bgpd.conf > /dev/null
  919. # Quagga logging
  920. sudo mkdir -p /var/log/quagga
  921. sudo touch /var/log/quagga/zebra.log
  922. sudo touch /var/log/quagga/bgpd.log
  923. sudo chown -R quagga:quagga /var/log/quagga
  924. GetOSVersion
  925. QUAGGA_SERVICES="zebra bgpd"
  926. if [[ is_ubuntu && "$os_CODENAME" == "xenial" ]]; then
  927. # In Ubuntu Xenial, the services bgpd and zebra are under
  928. # one systemd unit: quagga
  929. QUAGGA_SERVICES="quagga"
  930. elif is_fedora; then
  931. # Disable SELinux rule that conflicts with Zebra
  932. sudo setsebool -P zebra_write_config 1
  933. fi
  934. sudo systemctl enable $QUAGGA_SERVICES
  935. sudo systemctl restart $QUAGGA_SERVICES
  936. # log the systemd status
  937. sudo systemctl status $QUAGGA_SERVICES
  938. # add default IPv6 route back
  939. if ! [[ -z $default_route ]]; then
  940. # "replace" should ignore "RTNETLINK answers: File exists"
  941. # error if the route wasn't flushed by the bgp setup we did earlier.
  942. sudo ip -6 route replace $default_route
  943. fi
  944. }
  945. # Main dispatcher
  946. if [[ "$1" == "stack" && "$2" == "install" ]]; then
  947. echo_summary "Installing Manila Client"
  948. install_manilaclient
  949. echo_summary "Installing Manila"
  950. install_manila
  951. set_cinder_quotas
  952. elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
  953. echo_summary "Configuring Manila"
  954. configure_manila
  955. echo_summary "Initializing Manila"
  956. init_manila
  957. echo_summary "Installing extra libraries"
  958. install_libraries
  959. echo_summary "Creating Manila entities for auth service"
  960. create_manila_accounts
  961. # Cinder config update
  962. if is_service_enabled cinder && [[ -n "$CINDER_OVERSUBSCRIPTION_RATIO" ]]; then
  963. CINDER_CONF=${CINDER_CONF:-/etc/cinder/cinder.conf}
  964. CINDER_ENABLED_BACKENDS=$(iniget $CINDER_CONF DEFAULT enabled_backends)
  965. for BN in ${CINDER_ENABLED_BACKENDS//,/ }; do
  966. iniset $CINDER_CONF $BN lvm_max_over_subscription_ratio $CINDER_OVERSUBSCRIPTION_RATIO
  967. done
  968. iniset $CINDER_CONF DEFAULT max_over_subscription_ratio $CINDER_OVERSUBSCRIPTION_RATIO
  969. fi
  970. elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
  971. if is_service_enabled nova; then
  972. echo_summary "Creating Manila service flavor"
  973. create_manila_service_flavor
  974. echo_summary "Creating Manila service security group"
  975. create_manila_service_secgroup
  976. fi
  977. # Skip image downloads when disabled.
  978. # This way vendor Manila driver CI tests can skip
  979. # this potentially long and unnecessary download.
  980. if [ "$MANILA_SERVICE_IMAGE_ENABLED" = "True" ]; then
  981. echo_summary "Creating Manila service image"
  982. create_manila_service_image
  983. else
  984. echo_summary "Skipping download of Manila service image"
  985. fi
  986. if is_service_enabled nova; then
  987. echo_summary "Creating Manila service keypair"
  988. create_manila_service_keypair
  989. fi
  990. echo_summary "Configure Samba server"
  991. configure_samba
  992. echo_summary "Configuring IPv6"
  993. if [ $(trueorfalse False MANILA_SETUP_IPV6) == True ]; then
  994. setup_ipv6
  995. fi
  996. echo_summary "Starting Manila API"
  997. start_manila_api
  998. # Workaround for bug #1660304
  999. if [ "$SHARE_DRIVER" != "manila.share.drivers.generic.GenericShareDriver" ]; then
  1000. echo_summary "Starting rest of Manila services - scheduler, share and data"
  1001. start_rest_of_manila
  1002. fi
  1003. echo_summary "Creating Manila default share type"
  1004. create_default_share_type
  1005. echo_summary "Creating Manila default share group type"
  1006. create_default_share_group_type
  1007. echo_summary "Creating Manila custom share types"
  1008. create_custom_share_types
  1009. echo_summary "Manila UI is no longer enabled by default. \
  1010. Add enable_plugin manila-ui github.com/openstack/manila-ui \
  1011. to your local.conf file to enable Manila UI"
  1012. elif [[ "$1" == "stack" && "$2" == "test-config" ]]; then
  1013. ###########################################################################
  1014. # NOTE(vponomaryov): Workaround for bug #1660304
  1015. # We are able to create Nova VMs now only when last Nova step is performed
  1016. # which is registration of cell0. It is registered as last action in
  1017. # "post-extra" section.
  1018. if is_service_enabled nova; then
  1019. echo_summary "Creating Manila service VMs for generic driver \
  1020. backends for which handlng of share servers is disabled."
  1021. create_service_share_servers
  1022. fi
  1023. if [ "$SHARE_DRIVER" == "manila.share.drivers.generic.GenericShareDriver" ]; then
  1024. echo_summary "Starting rest of Manila services - scheduler, share and data"
  1025. start_rest_of_manila
  1026. fi
  1027. ###########################################################################
  1028. echo_summary "Fetching and installing manila-tempest-plugin system-wide"
  1029. install_manila_tempest_plugin
  1030. echo_summary "Update Tempest config"
  1031. update_tempest
  1032. fi
  1033. if [[ "$1" == "unstack" ]]; then
  1034. cleanup_manila
  1035. fi
  1036. if [[ "$1" == "clean" ]]; then
  1037. cleanup_manila
  1038. sudo rm -rf /etc/manila
  1039. fi
  1040. # Restore xtrace
  1041. $XTRACE