From 1758142b296021d775360aafc06ee85736d4a886 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Tue, 29 Sep 2020 12:46:06 +0200 Subject: [PATCH] Create devstack-tobiko Vagrantfile Change-Id: I59810fd352b196f3fb08b265cfb3962efb88f326 --- .gitignore | 1 + Vagrantfile | 126 ++++++++++++++++++ ansible.cfg | 12 ++ playbooks/vagrant/.gitignore | 1 + playbooks/vagrant/local.conf | 30 +++++ playbooks/vagrant/provision.yaml | 29 ++++ .../devstack-tobiko-common/defaults/main.yaml | 24 ++++ roles/devstack-tobiko-deploy/meta/main.yaml | 4 + .../tasks/deploy-local-conf.yaml | 9 ++ .../tasks/deploy-project.yaml | 54 ++++++++ .../tasks/deploy-projects.yaml | 21 +++ .../tasks/ensure-stack-user.yaml | 37 +++++ .../tasks/install-bindeps.yaml | 13 ++ roles/devstack-tobiko-deploy/tasks/main.yaml | 8 ++ .../tasks/run-stack.yaml | 19 +++ .../tasks/run-unstack.yaml | 26 ++++ .../devstack-tobiko-run-tests/meta/main.yaml | 4 + .../devstack-tobiko-run-tests/tasks/main.yaml | 3 + .../tasks/run-tests.yaml | 7 + 19 files changed, 428 insertions(+) create mode 100644 Vagrantfile create mode 100644 ansible.cfg create mode 100644 playbooks/vagrant/.gitignore create mode 100644 playbooks/vagrant/local.conf create mode 100644 playbooks/vagrant/provision.yaml create mode 100644 roles/devstack-tobiko-common/defaults/main.yaml create mode 100644 roles/devstack-tobiko-deploy/meta/main.yaml create mode 100644 roles/devstack-tobiko-deploy/tasks/deploy-local-conf.yaml create mode 100644 roles/devstack-tobiko-deploy/tasks/deploy-project.yaml create mode 100644 roles/devstack-tobiko-deploy/tasks/deploy-projects.yaml create mode 100644 roles/devstack-tobiko-deploy/tasks/ensure-stack-user.yaml create mode 100644 roles/devstack-tobiko-deploy/tasks/install-bindeps.yaml create mode 100644 roles/devstack-tobiko-deploy/tasks/main.yaml create mode 100644 roles/devstack-tobiko-deploy/tasks/run-stack.yaml create mode 100644 roles/devstack-tobiko-deploy/tasks/run-unstack.yaml create mode 100644 roles/devstack-tobiko-run-tests/meta/main.yaml create mode 100644 roles/devstack-tobiko-run-tests/tasks/main.yaml create mode 100644 roles/devstack-tobiko-run-tests/tasks/run-tests.yaml diff --git a/.gitignore b/.gitignore index 7625e80..d98ab23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # Tox files .tox +.vagrant diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..875a33a --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,126 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = "2" + +# Customize the count of CPU cores on the VM +CPUS = 4 + +# Customize the amount of memory on the VM +MEMORY = ENV.fetch("VM_SIZE", "4096").to_i + +# Every Vagrant development environment requires a box. You can search for +# boxes at https://vagrantcloud.com/search. +BOX = ENV.fetch("VM_BOX", "generic/centos8") + +# Machine host name +HOSTNAME = "tobiko" + +# Top vagrantfile dir +VAGRANTFILE_DIR = File.dirname(__FILE__) + +# Source provision playbook +PROVISION_PLAYBOOK = ENV.fetch( + "PROVISION_PLAYBOOK", "#{VAGRANTFILE_DIR}/playbooks/vagrant/provision.yaml") + +# Host IP address to be assigned to OpenStack in DevStack +HOST_IP = "192.168.33.10" + +# Local directory from where look for required projects files +PROJECTS_DIR = File.dirname(ENV.fetch('PROJECTS_DIR', VAGRANTFILE_DIR)) + +GIT_BASE = ENV.fetch('GIT_BASE', 'https://opendev.org') + +# Local project directories to be copied +DEVSTACK_PROJECTS = { + # Local directory from where look for devstack project files + 'devstack' => { + 'src_dir' => ENV.fetch("DEVSTACK_DIR", "#{PROJECTS_DIR}/devstack"), + }, + + # Local directory from where look for devstack tobiko plugin project files + 'devstack-plugin-tobiko' => { + 'src_dir' => ENV.fetch("DEVSTACK_PLUGIN_TOBIKO_SRC_DIR", VAGRANTFILE_DIR), + }, + + # Local directory from where looking for Tobiko project files + 'tobiko' => { + 'src_dir' => ENV.fetch("TOBIKO_SRC_DIR", "#{PROJECTS_DIR}/tobiko"), + }, +} + + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.box = BOX + # config.vm.box_version = "< 3.0" + config.vm.hostname = HOSTNAME + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + config.vm.network "private_network", ip: HOST_IP + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + config.vm.provider "virtualbox" do |vb| + # Display the VirtualBox GUI when booting the machine + vb.gui = false + + vb.cpus = CPUS + vb.memory = MEMORY + end + + config.vm.provider "libvirt" do |libvirt| + libvirt.cpus = CPUS + libvirt.memory = MEMORY + end + + # Run provision playbook + config.vm.provision "ansible" do |ansible| + ansible.limit = 'all' + ansible.playbook = PROVISION_PLAYBOOK + ansible.extra_vars = ansible.extra_vars = { + 'devstack_projects' => DEVSTACK_PROJECTS, + } + end + +end diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..495f6e0 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,12 @@ +[defaults] +host_key_checking = False +forks = 500 +timeout = 30 +force_color = 0 +interpreter_python = auto + +roles_path = roles/ + +[ssh_connection] +pipelining = True +ssh_args = -o ControlMaster=auto -o ControlPersist=60s diff --git a/playbooks/vagrant/.gitignore b/playbooks/vagrant/.gitignore new file mode 100644 index 0000000..755189b --- /dev/null +++ b/playbooks/vagrant/.gitignore @@ -0,0 +1 @@ +roles/ diff --git a/playbooks/vagrant/local.conf b/playbooks/vagrant/local.conf new file mode 100644 index 0000000..e3a5554 --- /dev/null +++ b/playbooks/vagrant/local.conf @@ -0,0 +1,30 @@ +[[local|localrc]] +ADMIN_PASSWORD=secret +DATABASE_PASSWORD=$ADMIN_PASSWORD +RABBIT_PASSWORD=$ADMIN_PASSWORD +SERVICE_PASSWORD=$ADMIN_PASSWORD + +LOGFILE=/opt/stack/devstack/stack.log +LOG_COLOR=False + + +# Disable unrequired services ------------------------------------------------- + +disable_service horizon +disable_service tempest + + +# Configure Neutron ----------------------------------------------------------- + +HOST_IP=192.168.33.10 +IP_VERSION=4 + + +# Configure Heat -------------------------------------------------------------- + +enable_plugin heat https://opendev.org/openstack/heat.git + + +# Configure Tobiko ------------------------------------------------------------ + +enable_plugin devstack-tobiko-plugin https://opendev.org/x/devstack-plugin-tobiko.git diff --git a/playbooks/vagrant/provision.yaml b/playbooks/vagrant/provision.yaml new file mode 100644 index 0000000..6997739 --- /dev/null +++ b/playbooks/vagrant/provision.yaml @@ -0,0 +1,29 @@ +--- + +- hosts: all + vars: + resolv_conf_file: /etc/resolv.conf + dest_dir: /opt/stack + + pre_tasks: + + - name: copy '{{ resolv_conf_file}}' file + become: yes + copy: + src: '{{ resolv_conf_file }}' + dest: /etc/resolv.conf + owner: root + group: root + mode: '0644' + + - name: update APT database + apt: + update_cache: yes + cache_valid_time: 3600 + become: yes + when: + - ansible_os_family == 'Debian' + + roles: + - devstack-tobiko-deploy + - devstack-tobiko-run-tests diff --git a/roles/devstack-tobiko-common/defaults/main.yaml b/roles/devstack-tobiko-common/defaults/main.yaml new file mode 100644 index 0000000..f3e9b1a --- /dev/null +++ b/roles/devstack-tobiko-common/defaults/main.yaml @@ -0,0 +1,24 @@ +--- + +devstack_restack: true + +devstack_dest_dir: /opt/stack +devstack_local_conf_file: '{{ playbook_dir }}/local.conf' + +devstack_projects_dir: '{{ playbook_dir | dirname }}' + +devstack_projects_base: + devstack: + git_repo: 'https://opendev.org/openstack/devstack.git' + devstack-plugin-tobiko: + git_repo: 'https://opendev.org/x/devstack-plugin-tobiko.git' + tobiko: + git_repo: 'https://opendev.org/x/tobiko.git' + +devstack_projects: {} + +devstack_dir: '{{ devstack_dest_dir }}/devstack' + +sudo_secure_path: '' + +tobiko_dir: '{{ devstack_dest_dir }}/tobiko' diff --git a/roles/devstack-tobiko-deploy/meta/main.yaml b/roles/devstack-tobiko-deploy/meta/main.yaml new file mode 100644 index 0000000..13a388c --- /dev/null +++ b/roles/devstack-tobiko-deploy/meta/main.yaml @@ -0,0 +1,4 @@ +--- + +dependencies: + - devstack-tobiko-common diff --git a/roles/devstack-tobiko-deploy/tasks/deploy-local-conf.yaml b/roles/devstack-tobiko-deploy/tasks/deploy-local-conf.yaml new file mode 100644 index 0000000..c943ba3 --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/deploy-local-conf.yaml @@ -0,0 +1,9 @@ +--- + +- name: copy local.conf file + become: yes + copy: + owner: stack + group: stack + src: '{{ devstack_local_conf_file }}' + dest: '{{ devstack_dir }}/local.conf' diff --git a/roles/devstack-tobiko-deploy/tasks/deploy-project.yaml b/roles/devstack-tobiko-deploy/tasks/deploy-project.yaml new file mode 100644 index 0000000..707259e --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/deploy-project.yaml @@ -0,0 +1,54 @@ +--- + +- name: "ensure '{{ project_dest_dir }}' exists" + become: yes + become_user: root + file: + path: '{{ project_dest_dir | realpath }}' + state: directory + mode: '0755' + owner: stack + group: stack + recurse: yes + when: >- + ( project_src_dir | length) > 0 or + ( project_git_repo | length) > 0 + + +- name: "check '{{ project_src_dir }}' exists" + stat: + path: '{{ project_src_dir }}' + delegate_to: localhost + register: check_project_src_dir_exists + when: ( project_src_dir | length) > 0 + failed_when: no + + +- become: yes + become_user: stack + block: + + - name: copy '{{ project_src_dir }}' to '{{ project_dest_dir }}' + synchronize: + group: no + owner: no + src: "{{ project_src_dir | realpath }}/." + dest: "{{ project_dest_dir | realpath }}" + use_ssh_args: yes + recursive: yes + rsync_opts: + - '--exclude-from={{ project_src_dir | realpath }}/.gitignore' + register: copy_project_src_dir + when: check_project_src_dir_exists.stat.isdir | default(False) + + - name: >- + fetch project sources from '{{ project_git_repo }}' to + '{{ project_dest_dir }}' + git: + repo: '{{ project_git_repo }}' + dest: '{{ project_dest_dir }}' + version: '{{ project_git_version }}' + force: true + when: + - copy_project_src_dir is skipped + - ( project_git_repo | length) > 0 diff --git a/roles/devstack-tobiko-deploy/tasks/deploy-projects.yaml b/roles/devstack-tobiko-deploy/tasks/deploy-projects.yaml new file mode 100644 index 0000000..a1aec7a --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/deploy-projects.yaml @@ -0,0 +1,21 @@ +--- + +- name: combine DevStack projects + set_fact: + devstack_projects_combined: >- + {{ [devstack_projects_base, devstack_projects] | + combine(recursive=True) }} + + +- name: show resulting DevStack projects + debug: var=devstack_projects_combined + + +- name: deploy projects + include_tasks: deploy-project.yaml + with_dict: '{{ devstack_projects_combined }}' + vars: + project_dest_dir: '{{ devstack_dest_dir }}/{{ item.key }}' + project_src_dir: '{{ item.value.src_dir | default("") }}' + project_git_repo: '{{ item.value.git_repo | default("") }}' + project_git_version: '{{ item.value.git_version | default("HEAD") }}' diff --git a/roles/devstack-tobiko-deploy/tasks/ensure-stack-user.yaml b/roles/devstack-tobiko-deploy/tasks/ensure-stack-user.yaml new file mode 100644 index 0000000..371a5ea --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/ensure-stack-user.yaml @@ -0,0 +1,37 @@ +--- + + +- name: ensure stack group exists + become: yes + group: + name: stack + state: present + + +- name: ensure stack user exists + become: yes + user: + name: stack + home: '{{ devstack_dest_dir }}' + comment: DevStack user + group: stack + shell: /bin/bash + + +- name: ensure stack user has sudo privileges + become: yes + copy: + dest: /etc/sudoers.d/stack + content: | + stack ALL=(ALL) NOPASSWD: ALL + + +- name: ensure stack user home exists + become: yes + become_user: root + file: + path: '{{ devstack_dest_dir | realpath }}' + state: directory + mode: '0755' + owner: stack + group: stack diff --git a/roles/devstack-tobiko-deploy/tasks/install-bindeps.yaml b/roles/devstack-tobiko-deploy/tasks/install-bindeps.yaml new file mode 100644 index 0000000..5e01808 --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/install-bindeps.yaml @@ -0,0 +1,13 @@ +--- + +- name: "ensure DevStack bindeps are installed" + become: true + package: + name: + - git + - iptables + - python3 + - python3-pip + - python3-systemd + - rsync + - sudo diff --git a/roles/devstack-tobiko-deploy/tasks/main.yaml b/roles/devstack-tobiko-deploy/tasks/main.yaml new file mode 100644 index 0000000..7edcebc --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/main.yaml @@ -0,0 +1,8 @@ +--- + +- include_tasks: install-bindeps.yaml +- include_tasks: ensure-stack-user.yaml +- include_tasks: run-unstack.yaml +- include_tasks: deploy-projects.yaml +- include_tasks: deploy-local-conf.yaml +- include_tasks: run-stack.yaml diff --git a/roles/devstack-tobiko-deploy/tasks/run-stack.yaml b/roles/devstack-tobiko-deploy/tasks/run-stack.yaml new file mode 100644 index 0000000..bedc211 --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/run-stack.yaml @@ -0,0 +1,19 @@ +--- + +- name: run stack.sh + become: true + become_user: stack + shell: + cmd: | + sudo su -l stack -c "cd '{{ devstack_dir }}' && ./stack.sh" 2>&1 + rc=$? + echo "*** FINISHED ***" + exit $rc + chdir: '{{ devstack_dir }}' + register: run_stack + ignore_errors: true + + +- name: show stack.sh output + debug: var=run_stack.stdout_lines + failed_when: run_stack is failed diff --git a/roles/devstack-tobiko-deploy/tasks/run-unstack.yaml b/roles/devstack-tobiko-deploy/tasks/run-unstack.yaml new file mode 100644 index 0000000..9a775a5 --- /dev/null +++ b/roles/devstack-tobiko-deploy/tasks/run-unstack.yaml @@ -0,0 +1,26 @@ +--- + +- name: check '{{ devstack_dir }}/local.conf' exists + stat: + path: '{{ devstack_dir }}/local.conf' + register: check_devstack_local_conf_file_exists + failed_when: no + + +- name: run unstack.sh + become: yes + become_user: stack + shell: + cmd: | + sudo su -l stack -c "cd '{{ devstack_dir }}' && ./unstack.sh" 2>&1 + rc=$? + echo "*** FINISHED ***" + exit $rc + register: run_unstack + ignore_errors: yes + when: + check_devstack_local_conf_file_exists.stat.exists | default(False) + + +- debug: var=run_unstack.stdout_lines + when: run_unstack is failed diff --git a/roles/devstack-tobiko-run-tests/meta/main.yaml b/roles/devstack-tobiko-run-tests/meta/main.yaml new file mode 100644 index 0000000..13a388c --- /dev/null +++ b/roles/devstack-tobiko-run-tests/meta/main.yaml @@ -0,0 +1,4 @@ +--- + +dependencies: + - devstack-tobiko-common diff --git a/roles/devstack-tobiko-run-tests/tasks/main.yaml b/roles/devstack-tobiko-run-tests/tasks/main.yaml new file mode 100644 index 0000000..9c717ec --- /dev/null +++ b/roles/devstack-tobiko-run-tests/tasks/main.yaml @@ -0,0 +1,3 @@ +--- + +- include_tasks: run-tests.yaml diff --git a/roles/devstack-tobiko-run-tests/tasks/run-tests.yaml b/roles/devstack-tobiko-run-tests/tasks/run-tests.yaml new file mode 100644 index 0000000..57fda0b --- /dev/null +++ b/roles/devstack-tobiko-run-tests/tasks/run-tests.yaml @@ -0,0 +1,7 @@ +--- + +- name: run tobiko test cases + command: + cmd: > + tox -e {{ tox_envlist }} + chdir: '{{ tobiko_dir }}'