From 79731f43c074d742a3d90b02684bf48d4bf3b3c1 Mon Sep 17 00:00:00 2001 From: Michael Marchetti Date: Tue, 10 Jul 2018 18:07:12 +0200 Subject: [PATCH] Add support for vim emu installation * add auto push to vagrant cloud Signed-off-by: Michael Marchetti --- packer/.gitignore | 2 ++ packer/scripts/get-install-osm.sh | 12 ++++++-- packer/scripts/juju-setup.sh | 1 + packer/scripts/vimemu.sh | 49 +++++++++++++++++++++++++++++++ packer/ubuntu1604-juju.json | 24 +++++++++++++-- packer/ubuntu1604-ovf-osm.json | 29 +++++++++++++----- 6 files changed, 104 insertions(+), 13 deletions(-) create mode 100755 packer/scripts/vimemu.sh diff --git a/packer/.gitignore b/packer/.gitignore index 7979d3aa..bf86b4f3 100644 --- a/packer/.gitignore +++ b/packer/.gitignore @@ -1,3 +1,5 @@ output-virtualbox-iso/ packer_cache/ builds/ +jujubase*/ +osm-*/ diff --git a/packer/scripts/get-install-osm.sh b/packer/scripts/get-install-osm.sh index 534799bb..e04b96ac 100755 --- a/packer/scripts/get-install-osm.sh +++ b/packer/scripts/get-install-osm.sh @@ -3,6 +3,12 @@ export PATH=$PATH:/snap/bin echo "PATH=$PATH" juju status -wget "$1" -chmod +x install_osm.sh -./install_osm.sh --nolxd -y --vimemu +git clone https://osm.etsi.org/gerrit/osm/vim-emu.git +git clone https://osm.etsi.org/gerrit/osm/devops.git +eval devops/installers/full_install_osm.sh --nolxd -y "$1" + +cat >> ~/.bashrc <<-EOF +export OSM_HOSTNAME=127.0.0.1 +export OSM_SOL005=True + +EOF diff --git a/packer/scripts/juju-setup.sh b/packer/scripts/juju-setup.sh index 55752e56..8685b48f 100755 --- a/packer/scripts/juju-setup.sh +++ b/packer/scripts/juju-setup.sh @@ -1,2 +1,3 @@ #!/bin/sh sudo snap install juju --classic +/snap/bin/juju bootstrap --bootstrap-series=xenial localhost osm diff --git a/packer/scripts/vimemu.sh b/packer/scripts/vimemu.sh new file mode 100755 index 00000000..6beb79b8 --- /dev/null +++ b/packer/scripts/vimemu.sh @@ -0,0 +1,49 @@ +#!/bin/sh +mkdir -p /etc/systemd/system/scripts +cat > /etc/systemd/system/scripts/osm-vimemu-startup.sh <<-'EOF' +#!/bin/sh + +export OSM_HOSTNAME=127.0.0.1 +export OSM_SOL005=True + +echo "Waiting for OSM startup" +while true; do + # wait for startup of osm + RC=$(osm vim-list) + if [ "$?" -eq 0 ]; then + break + fi + sleep 2 +done +echo "OSM is up" +sleep 10 +export VIMEMU_HOSTNAME=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu) +osm vim-create --name vim-emulator --user username --password password --auth_url http://$VIMEMU_HOSTNAME:6001/v2.0 --tenant tenantName --account_type openstack +osm vnfd-create /home/vagrant/vim-emu/examples/vnfs/ping.tar.gz +osm vnfd-create /home/vagrant/vim-emu/examples/vnfs/pong.tar.gz +osm nsd-create /home/vagrant/vim-emu/examples/services/pingpong_nsd.tar.gz +osm ns-create --nsd_name pingpong --ns_name test --vim_account vim-emulator + +echo "VIM emulator created" +systemctl disable osm-vimemu-setup.service +EOF +chmod +x /etc/systemd/system/scripts/osm-vimemu-startup.sh + +cat > /etc/systemd/system/osm-vimemu-setup.service <<-'EOF' +[Unit] +Description=OSM VIM emulator setup + +[Service] +Type=oneshot +ExecStart=/etc/systemd/system/scripts/osm-vimemu-startup.sh +RemainAfterExit=yes +TimeoutSec=120 + +# Output needs to appear in instance console output +StandardOutput=journal+console + +[Install] +WantedBy=multi-user.target +EOF + +#systemctl enable osm-vimemu-setup.service diff --git a/packer/ubuntu1604-juju.json b/packer/ubuntu1604-juju.json index 79b49eda..15db3121 100644 --- a/packer/ubuntu1604-juju.json +++ b/packer/ubuntu1604-juju.json @@ -21,7 +21,17 @@ }, { "type": "shell", - "script": "scripts/juju-setup.sh" + "inline": ["echo 'vagrant' | sudo shutdown -r now"], + "expect_disconnect": "true" + }, + { + "type": "shell", + "script": "scripts/juju-setup.sh", + "pause_before": "10s" + }, + { + "type": "shell", + "script": "scripts/cleanup.sh" } ], "builders": [ @@ -54,7 +64,7 @@ "" ], "boot_wait": "10s", - "disk_size": 15360, + "disk_size": 20480, "guest_os_type": "Ubuntu_64", "headless": true, "http_directory": "http", @@ -71,7 +81,8 @@ "shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now", "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", "virtualbox_version_file": ".vbox_version", - "vm_name": "packer-ubuntu-16.04-amd64-juju", + "output_directory": "jujubase-{{timestamp}}", + "vm_name": "xenial-jujubase", "vboxmanage": [ [ "modifyvm", @@ -87,5 +98,12 @@ ] ] } + ], + "post-processors": [ + { + "output": "jujubase-{{timestamp}}/{{.Provider}}-jujubase.box", + "type": "vagrant", + "keep_input_artifact": true + } ] } diff --git a/packer/ubuntu1604-ovf-osm.json b/packer/ubuntu1604-ovf-osm.json index 08221bd2..d4a2c776 100644 --- a/packer/ubuntu1604-ovf-osm.json +++ b/packer/ubuntu1604-ovf-osm.json @@ -3,7 +3,12 @@ { "type": "shell", "script": "scripts/get-install-osm.sh", - "execute_command": "{{.Path}} {{user `osm_installer`}}" + "execute_command": "{{.Path}} {{user `osm_install_options`}}" + }, + { + "type": "shell", + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", + "script": "scripts/vimemu.sh" }, { "type": "shell", @@ -12,9 +17,9 @@ } ], "variables": { - "osm_installer": "https://osm-download.etsi.org/ftp/osm-4.0-four/install_osm.sh", + "osm_install_options": "--vimemu", "input_ovf": "output-virtualbox-iso/packer-ubuntu-16.04-amd64-juju.ovf", - "vm_name": "packer-ubuntu-16.04-ovf-amd64" + "vm_name": "xenial-osm" }, "builders": [ { @@ -28,6 +33,7 @@ "shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now", "virtualbox_version_file": ".vbox_version", "vm_name": "{{user `vm_name`}}", + "output_directory": "osm-{{timestamp}}", "vboxmanage": [ [ "modifyvm", @@ -45,9 +51,18 @@ } ], "post-processors": [ - { - "output": "builds/{{.Provider}}-osm.box", - "type": "vagrant" - } + [ + { + "output": "osm-{{timestamp}}/{{.Provider}}-osm.box", + "type": "vagrant", + "keep_input_artifact": true + }, + { + "type": "vagrant-cloud", + "box_tag": "osm/{{user `release`}}", + "access_token": "{{user `cloud_token`}}", + "version": "{{user `version`}}" + } + ] ] } -- 2.25.1