Monday, August 21, 2017

Openstack-Vagrant - Bringing Vagrant, Ansible, and Devstack together to deploy for developers

Introduction

OpenStack developers in general, and Dragonflow developers in particular, find themselves in need of setting up many OpenStack deployments (for testing, troubleshooting, developing, and what not). Every change requires testing on a 'real' environment.

Doing this manually is impossible. This is a task that must be automated. If a patch is ready, setting up a server to test it should take seconds.

This is where Openstack-Vagrant comes in.

More Details

In essence, Openstack-Vagrant (https://github.com/omeranson/openstack-vagrant) is a Vagrantfile (read: Vagrant configuration file) that sets up a virtual machine, configures it and installs all the necessary dependencies (using Ansible), and then runs devstack.

In effect, Openstack-Vagrant allows you to create a new OpenStack deployment by simply updating a configuration file, and running vagrant up.

Vagrant

Vagrant (https://www.vagrantup.com/) allows you to easily manage your virtual machines. They can be deployed on many hosts (e.g. your personal PC, or several lab servers), with many backends (e.g. libvirt, or virtual box), with many distributions (e.g. Ubuntu, Fedora). I am sticking to Linux here, because that's what's relevant to our deployment.

Vagrant also let's you automatically provision your virtual machines, using e.g. shell or Ansible.

Ansible

Ansible (https://www.ansible.com/) allows you to easily provision your remote devices. It was selected for OpenStack-Vagrant for two main reasons:
  1. It is agent-less. No prior installation is needed.
  2. It works over SSH - out of the box for Linux cloud images.
Like many provisioning tools, Ansible is idempotent - you state the outcome (e.g. file exists, package installed) rather than the action. This way the same playbook (Ansible's list of tasks) can be replayed safely in case of errors along the way.

Devstack

Every developer in OpenStack should know devstack (https://docs.openstack.org/devstack/latest/). That's how testing setups are deployed.

Really In-Depth

Let's review how to set-up an OpenStack and Dragonflow deployment on a single server using Openstack-Vagrant.

  1. Grab a local.conf file. The Dragonflow project has some with healthy defaults (https://github.com/openstack/dragonflow/tree/master/doc/source/single-node-conf). At the time of writing, redis and etcd are gated. I recommend etcd, since it's now an Openstack base service (https://github.com/openstack/dragonflow/blob/master/doc/source/single-node-conf/etcd_local_controller.conf)
    • wget https://raw.githubusercontent.com/openstack/dragonflow/master/doc/source/single-node-conf/etcd_local_controller.conf
  2. Create a configuration for your new virtual machine. A basic example exists in the project's repository (https://github.com/omeranson/openstack-vagrant/blob/master/directory.conf.yml).
    • machines: 
        - name: one
          hypervisor:
            name: localhost
            username: root
          memory: 8192
          vcpus: 1
          box: "fedora/25-cloud-base"
          local_conf_file: etcd_local_controller.conf
      
  3. Run vagrant up <machine name>
    • vagrant up one
  4. Go drink coffee. You have an hour. 
  5. Once Ansible finishes its thing, you can log into the virtual machine with vagrant ssh or vagrant ssh -p -- -l stack (to log in directly to the stack user). Once as the stack user, devstack progress is available in a tmux session.
    • vagrant ssh -p -- -l stack
    • tmux attach

How Can It Be Better? 

 There are many ways we can still improve Openstack-Vagrant. Here are some thoughts that come to mind:
  1. A simple CLI interface that creates the configuration file and fires up the virtual machine.
  2. Use templates to make the local.conf file more customisable.

Conclusion

With Openstack-Vagrant, it is much easier to create new devstack deployments. A deployment can be fired in under a minute, and it will automatically boot the virtual machine, update it, install any necessary software, and run devstack

No comments:

Post a Comment