diff --git a/tools/dev/vagrant/Vagrantfile b/tools/dev/vagrant/Vagrantfile new file mode 100644 index 0000000000..1e952d41c6 --- /dev/null +++ b/tools/dev/vagrant/Vagrantfile @@ -0,0 +1,24 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + + if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil + config.vm.synced_folder ".", "/vagrant", mount_options: ["dmode=700,fmode=600"] + else + config.vm.synced_folder ".", "/vagrant" + end + + config.vm.define "onosdev" do |d| + d.vm.box = "ubuntu/trusty64" + d.vm.hostname = "onosdev" + d.vm.network "private_network", ip: "10.100.198.200" + d.vm.provision :shell, path: "scripts/bootstrap_ansible.sh" + d.vm.provision :shell, inline: "PYTHONUNBUFFERED=1 ansible-playbook /vagrant/ansible/onosdev.yml -c local" + d.vm.provider "virtualbox" do |v| + v.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"] + v.memory = 8192 + v.cpus = 2 + end + end +end diff --git a/tools/dev/vagrant/ansible/ansible.cfg b/tools/dev/vagrant/ansible/ansible.cfg new file mode 100644 index 0000000000..bd331b24a7 --- /dev/null +++ b/tools/dev/vagrant/ansible/ansible.cfg @@ -0,0 +1,9 @@ +[defaults] +callback_plugins=/etc/ansible/callback_plugins/ +host_key_checking=False +deprecation_warnings=False + +[privilege_escalation] +become=True +become_method=sudo +become_user=root diff --git a/tools/dev/vagrant/ansible/onosdev.retry b/tools/dev/vagrant/ansible/onosdev.retry new file mode 100644 index 0000000000..2fbb50c4a8 --- /dev/null +++ b/tools/dev/vagrant/ansible/onosdev.retry @@ -0,0 +1 @@ +localhost diff --git a/tools/dev/vagrant/ansible/onosdev.yml b/tools/dev/vagrant/ansible/onosdev.yml new file mode 100644 index 0000000000..cd7a5a50a3 --- /dev/null +++ b/tools/dev/vagrant/ansible/onosdev.yml @@ -0,0 +1,8 @@ +- hosts: localhost + remote_user: vagrant + serial: 1 + roles: + - common + - brctl + - java8-oracle + - lxc diff --git a/tools/dev/vagrant/ansible/roles/brctl/tasks/main.yml b/tools/dev/vagrant/ansible/roles/brctl/tasks/main.yml new file mode 100644 index 0000000000..002509a5fc --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/brctl/tasks/main.yml @@ -0,0 +1,37 @@ +- name: Bridge onosbr0 is present + become: yes + template: + src: templates/create_bridge.j2 + dest: /etc/network/if-pre-up.d/create_bridge_{{ networks.bridge_name }} + owner: root + group: root + mode: 0755 + +- name: eth1 is in onosbr0 + become: yes + template: + src: templates/add_iface.j2 + dest: /etc/network/if-pre-up.d/add_iface_{{ interfaces.hostonly }} + owner: root + group: root + mode: 0755 + +- name: Activate onos bridge + become: yes + command: /etc/network/if-pre-up.d/create_bridge_{{ networks.bridge_name }} report-changed + register: bridge_changed + changed_when: bridge_changed.stdout == 'true' + +- name: Activate eth1 in bridge + become: yes + command: /etc/network/if-pre-up.d/add_iface_{{ interfaces.hostonly }} report-changed + register: bridge_iface_changed + changed_when: bridge_iface_changed == 'true' + +- name: Flush ip of eth1 + become: yes + command: /sbin/ip addr flush {{ interfaces.hostonly }} + +- name: bring onosbr0 up + become: yes + command: /sbin/ifconfig onosbr0 up diff --git a/tools/dev/vagrant/ansible/roles/brctl/templates/add_iface.j2 b/tools/dev/vagrant/ansible/roles/brctl/templates/add_iface.j2 new file mode 100644 index 0000000000..f09bd50544 --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/brctl/templates/add_iface.j2 @@ -0,0 +1,17 @@ +#!/bin/bash + +REPORT_CHANGED=0 +if [ $# -gt 0 ]; then + REPORT_CHANGED=1 +fi +CHANGED='false' + +FOUND=$(brctl show | grep "^{{ interfaces.hostonly }}" | wc -l) +if [ $FOUND -eq 0 ]; then + CHANGED='true' + brctl addif {{ networks.bridge_name }} {{ interfaces.hostonly }} +fi + +if [ $REPORT_CHANGED -ne 0 ]; then + echo -n $CHANGED +fi diff --git a/tools/dev/vagrant/ansible/roles/brctl/templates/create_bridge.j2 b/tools/dev/vagrant/ansible/roles/brctl/templates/create_bridge.j2 new file mode 100644 index 0000000000..5f12261a68 --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/brctl/templates/create_bridge.j2 @@ -0,0 +1,17 @@ +#!/bin/bash + +REPORT_CHANGED=0 +if [ $# -gt 0 ]; then + REPORT_CHANGED=1 +fi +CHANGED='false' + +FOUND=$(brctl show | grep "^{{ networks.bridge_name }}" | wc -l) +if [ $FOUND -eq 0 ]; then + CHANGED='true' + brctl addbr {{ networks.bridge_name }} +fi + +if [ $REPORT_CHANGED -ne 0 ]; then + echo -n $CHANGED +fi diff --git a/tools/dev/vagrant/ansible/roles/brctl/vars/main.yml b/tools/dev/vagrant/ansible/roles/brctl/vars/main.yml new file mode 100644 index 0000000000..5c705ac1b8 --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/brctl/vars/main.yml @@ -0,0 +1,9 @@ +interfaces: + hostonly: "{{ hostonly_iface | default('eth1') }}" + +networks: + # CHANGE: + # 'bridge' name of the bridge to create that is used when connecting + # the LXC containers + bridge_name: "{{ bridge_name | default('onosbr0') }}" + bridge: "{{ bridge_network | default('10.100.198.200/24') }}" diff --git a/tools/dev/vagrant/ansible/roles/common/defaults/main.yml b/tools/dev/vagrant/ansible/roles/common/defaults/main.yml new file mode 100644 index 0000000000..cd8a8e3a35 --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/common/defaults/main.yml @@ -0,0 +1,6 @@ +hosts: [ + { host_ip: "10.100.198.200", host_name: "onosdev"}, + { host_ip: "10.100.198.201", host_name: "onos1"}, + { host_ip: "10.100.198.202", host_name: "onos2"}, + { host_ip: "10.100.198.203", host_name: "onos3"}, +] diff --git a/tools/dev/vagrant/ansible/roles/common/tasks/main.yml b/tools/dev/vagrant/ansible/roles/common/tasks/main.yml new file mode 100644 index 0000000000..d03f8ecacd --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/common/tasks/main.yml @@ -0,0 +1,42 @@ +- name: bridge-utils is present + apt: + name: bridge-utils + force: yes + tags: [common] + +- name: lxc is present + apt: + name: lxc + force: yes + tags: [common] + +- name: python-dev is present + apt: + name: python-dev + force: yes + tags: [common] + +- name: lxc-dev is present + apt: + name: lxc-dev + force: yes + tags: [common] + +- name: python-pip is present + apt: + name: python-pip + force: yes + tags: [common] + +- name: python3-lxc is present + pip: + name: lxc-python2 + state: present + tags: [common] +- name: Host is present + lineinfile: + dest: /etc/hosts + regexp: "^{{ item.host_ip }}" + line: "{{ item.host_ip }} {{ item.host_name }}" + with_items: hosts + tags: [common] diff --git a/tools/dev/vagrant/ansible/roles/java8-oracle/meta/main.yml b/tools/dev/vagrant/ansible/roles/java8-oracle/meta/main.yml new file mode 100644 index 0000000000..a51875be9b --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/java8-oracle/meta/main.yml @@ -0,0 +1,15 @@ +--- +galaxy_info: + author: Ciena Blueplanet + description: Java 8 from Oracle + company: Ciena Blueplanet + license: Apache 2.0 + min_ansible_version: 2.0 + platforms: + - name: Ubuntu + versions: + - trusty + galaxy_tags: + - development + - system +dependencies: [] diff --git a/tools/dev/vagrant/ansible/roles/java8-oracle/tasks/main.yml b/tools/dev/vagrant/ansible/roles/java8-oracle/tasks/main.yml new file mode 100644 index 0000000000..46deb760f3 --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/java8-oracle/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- name: Install add-apt-repostory + become: yes + apt: name=software-properties-common state=latest update_cache=yes + +- name: Add Oracle Java Repository + become: yes + apt_repository: repo='ppa:webupd8team/java' + +- name: Accept Java 8 License + become: yes + debconf: name='oracle-java8-installer' question='shared/accepted-oracle-license-v1-1' value='true' vtype='select' + +- name: Install Oracle Java 8 + become: yes + apt: name={{item}} state=latest + with_items: + - oracle-java8-installer + - ca-certificates + - oracle-java8-set-default diff --git a/tools/dev/vagrant/ansible/roles/lxc/files/99-onos-sudoers b/tools/dev/vagrant/ansible/roles/lxc/files/99-onos-sudoers new file mode 100644 index 0000000000..2a00beea80 --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/lxc/files/99-onos-sudoers @@ -0,0 +1 @@ +ubuntu ALL=(ALL:ALL) NOPASSWD:ALL diff --git a/tools/dev/vagrant/ansible/roles/lxc/files/default.conf b/tools/dev/vagrant/ansible/roles/lxc/files/default.conf new file mode 100644 index 0000000000..b496600259 --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/lxc/files/default.conf @@ -0,0 +1,11 @@ +lxc.mount.entry = /usr/lib/jvm/java-8-oracle usr/lib/jvm/java none bind,create=dir 0 0 + +lxc.network.type = veth +lxc.network.link = lxcbr0 +lxc.network.flags = up +lxc.network.name = eth0 + +lxc.network.type = veth +lxc.network.link = onosbr0 +lxc.network.flags = up +lxc.network.name = eth1 diff --git a/tools/dev/vagrant/ansible/roles/lxc/tasks/main.yml b/tools/dev/vagrant/ansible/roles/lxc/tasks/main.yml new file mode 100644 index 0000000000..ab4fbd4c83 --- /dev/null +++ b/tools/dev/vagrant/ansible/roles/lxc/tasks/main.yml @@ -0,0 +1,55 @@ +- name: Remove lxc default config + become: yes + file: path=/etc/lxc/default.conf state=absent + +- name: Copy default lxc file + become: yes + copy: + src: files/default.conf + dest: /etc/lxc/default.conf + mode: 644 + +- name: Create onos1 container + lxc_container: + name: onos1 + container_log: true + template: ubuntu + state: started + template_options: --release trusty + container_config: + - "lxc.network.ipv4=10.100.198.201/24" + container_command: | + ln -s /usr/lib/jvm/java/bin/java /usr/bin/java + apt-get update + apt-get install -y openssh-server + echo "ubuntu ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-onos-sudoers + +- name: Create onos2 container + lxc_container: + name: onos2 + container_log: true + template: ubuntu + state: started + template_options: --release trusty + container_config: + - "lxc.network.ipv4=10.100.198.202/24" + container_command: | + ln -s /usr/lib/jvm/java/bin/java /usr/bin/java + apt-get update + apt-get install -y openssh-server + echo "ubuntu ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-onos-sudoers + +- name: Create onos3 container + lxc_container: + name: onos3 + container_log: true + template: ubuntu + state: started + template_options: --release trusty + container_config: + - "lxc.network.ipv4=10.100.198.203/24" + container_command: | + ln -s /usr/lib/jvm/java/bin/java /usr/bin/java + apt-get update + apt-get install -y openssh-server + echo "ubuntu ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/99-onos-sudoers diff --git a/tools/dev/vagrant/scripts/bootstrap_ansible.sh b/tools/dev/vagrant/scripts/bootstrap_ansible.sh new file mode 100644 index 0000000000..cbd390515b --- /dev/null +++ b/tools/dev/vagrant/scripts/bootstrap_ansible.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Copyright 2012 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -e + +echo "Installing Ansible..." +apt-get install -y software-properties-common ca-certificates +apt-add-repository ppa:ansible/ansible +apt-get update +apt-get install -y ansible +cp /vagrant/ansible/ansible.cfg /etc/ansible/ansible.cfg diff --git a/tools/test/cells/lxc b/tools/test/cells/lxc new file mode 100644 index 0000000000..e04b8993c5 --- /dev/null +++ b/tools/test/cells/lxc @@ -0,0 +1,11 @@ +export OCI=10.100.198.201 +export OC1=10.100.198.201 +export OC2=10.100.198.202 +export OC3=10.100.198.203 +export ONOS_APPS=drivers,openflow,proxyarp +export ONOS_NIC=10.100.198.* +export ONOS_SCENARIOS=$HOME/work/onos-next/tools/test/scenarios +export ONOS_USER=ubuntu +export ONOS_GROUP=ubuntu +export ONOS_WEB_PASS=rocks +export ONOS_WEB_USER=onos