From e3ea28a0cd05c8d0b3e5f28aaf8e7b71a9863b69 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Tue, 9 Feb 2021 21:48:31 +0530 Subject: [PATCH] mbx: update tool Signed-off-by: Rohit Yadav --- .gitignore | 1 + README.md | 40 ++++++---------------- mbx | 87 +++++++++++++++++++++++++++++++++++------------ packages/.gitkeep | 0 4 files changed, 78 insertions(+), 50 deletions(-) create mode 100644 packages/.gitkeep diff --git a/.gitignore b/.gitignore index dc1f2e9..dca8823 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ boxes/boxes.list boxes/** +templates/*.qcow2 diff --git a/README.md b/README.md index 561e929..0983845 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ NFS server and KVM are prerequisites to using `mbx`. ### Install and setup NFS - apt-get install nfs-kernel-server quota + apt-get install nfs-kernel-server quota sshpass wget echo "/export *(rw,async,no_root_squash,no_subtree_check)" > /etc/exports mkdir -p /export/testing exportfs -a @@ -54,33 +54,26 @@ on your machine: ![VM Manager](doc/images/virt-manager.png) -Install docker for packaging: https://docs.docker.com/engine/install/ubuntu/ +Install docker for packaging, follow: https://docs.docker.com/engine/install/ubuntu/ ### Install `mbx` git clone https://github.com/shapeblue/mbx /export/monkeybox - cd /export/monkeybox/templates - # Download pre-built mbx templates - wget http://download.cloudstack.org/templates/mbx/kvm-centos7.qcow2 - wget http://download.cloudstack.org/templates/mbx/vmware67u3.qcow2 - wget http://download.cloudstack.org/templates/mbx/xcpng76.qcow2 - wget http://download.cloudstack.org/templates/mbx/xenserver71.qcow2 - wget http://download.cloudstack.org/templates/mbx/md5sum.txt - # After downloading run the md5sum check again the md5sum.txt - md5sum --check md5sum.txt - # Next setup mbx tool: - cd /export/monkeybox - sudo cp files/sudoer.mbx /etc/sudoers.d/mbx # Enable mbx under $PATH, for bash: echo export PATH="/export/monkeybox:$PATH" >> ~/.bashrc # Enable mbx under $PATH, for zsh: echo export PATH="/export/monkeybox:$PATH" >> ~/.zshrc + # Initialise `mbx` by opening in another shell: + mbx init + +The `mbx init` is idempotent and can be used to update templates and domain xml +definitions. ### Setup `mbx` Network For our local dev-qa environment, we'll create a 172.20.0.0/16 virtual network with NAT so VMs on this network are only accessible from the host/laptop but -not by the outside network. +not by the outside network. The `mbx init` command will initialise this network. External Network . +-----------------+ @@ -103,17 +96,6 @@ used as a single physical network in CloudStack that has the public, private, management/control and storage networks. A complex setup is possible by adding multiple virtual networks and nics on them. -To setup the network run: - - $ mbx install - -This essentially runs: - - virsh net-define monkeynet.xml - virsh net-autostart monkeynet - virsh net-start monkeynet - # finally loops through templates/xmls and defines the templates - The default network xml definition assumes `virbr1` is not already assigned, in case you get an error change the bridge name to something other than `virbr1`. @@ -163,7 +145,7 @@ run in management VMs and their IPs will be dynamically allocated. To ssh into deployed VMs (with NSS configured), you can login simply using: - $ ssh root@ + $ ssh root@ ### Storage Setup @@ -202,7 +184,7 @@ environments, run smoketests on them and destroy environments. Usage: $ mbx MonkeyBox 🐵 1.0 Available commands are: - install: setup monkeynet and mbx templates + init: initialises monkeynet and mbx templates build: build packages from git repo and sha/tag/branch list: list available environments deploy: deploy monkeybox VMs using mbx templates, setup storage @@ -316,7 +298,7 @@ Fork the repository at: github.com/apache/cloudstack, or get the code: Noredist CloudStack builds requires additional jars that may be installed from: - https://github.com/rhtyd/cloudstack-nonoss + https://github.com/shapeblue/cloudstack-nonoss Clone the above repository and run the install.sh script, you'll need to do this only once or whenver the noredist jar dependencies are updated in above diff --git a/mbx b/mbx index f071cef..828eef2 100755 --- a/mbx +++ b/mbx @@ -1,40 +1,57 @@ #!/bin/bash - set -e -ROOT=/export/monkeybox +ROOT="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" mkdir -p $ROOT/boxes touch $ROOT/boxes/boxes.list export LIBVIRT_DEFAULT_URI="qemu:///system" - echo MonkeyBox 🐵 1.0 usage() { echo "Available commands are:" - echo " install: setup monkeynet and mbx templates" + echo " init: initialises monkeynet and mbx templates" echo " build: build packages from git repo and sha/tag/branch" echo " list: list available environments" echo " deploy: deploy monkeybox VMs using mbx templates, setup storage" echo " launch: creates marvin config file and launches a zone" echo " test: start marvin tests" + echo " stop: stop all env VMs" + echo " start: start all env VMs" echo " destroy: destroy environment" } -install() { - virsh net-define $ROOT/monkeynet.xml - virsh net-autostart monkeynet - virsh net-start monkeynet - echo $pwd - echo "Setting up mbx templates, we assumes the templates are already downloaded in templates directory" - for xml in $(ls $ROOT/templates/xmls/*xml); do virsh define $xml; done - sudo cp $ROOT/files/sudoer.mbx /etc/sudoers.d/mbx -} - build() { echo "Build Packages, please input git repo URL and git/sha/branch" + echo "Pulling docker build container images" + docker pull bhaisaab/centos8-cloudstack-slave + docker pull bhaisaab/centos7-cloudstack-slave + docker pull bhaisaab/centos6-cloudstack-slave + docker pull bhaisaab/ubuntu-cloudstack-slave echo "TODO" } +init() { + if virsh net-list --all --name | grep -q monkeynet; + then + echo "'monkeynet' network is already defined, skipped re-initialisation"; + else + virsh net-define $ROOT/monkeynet.xml + virsh net-autostart monkeynet + virsh net-start monkeynet + fi + echo "Setting up mbx sudoers file. Please enter sudoer password if you're prompted." + sudo cp $ROOT/files/sudoer.mbx /etc/sudoers.d/mbx + echo "Updating templates" + for template in $(cat $ROOT/templates/md5sum.txt | awk '{print $2}' | sed 's/.qcow2//g'); do + virsh undefine mbxt-$template >/dev/null 2>/dev/null || true + echo "Updating template: $template" + wget --show-progress -nc https://download.cloudstack.org/templates/mbx/$template.qcow2 -O $ROOT/templates/$template.qcow2 || true + virsh define $ROOT/templates/xmls/mbxt-$template.xml >/dev/null + done + echo "Running md5 checksum checks on templates (this may take some time...)" + (cd $ROOT/templates && md5sum --check md5sum.txt) +} + list() { echo for env in $(cat $ROOT/boxes/boxes.list); do @@ -48,7 +65,7 @@ list() { echo -e "$vm\t$ip\t$url" if [[ $vm == *vmw-host1* ]]; then vcip=$(sshpass -p 'P@ssword123' ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" root@$vm vim-cmd "vmsvc/get.guest 1 | grep ipAddress | head -1 | sed 's/.*ipAddress = \"//g' | sed 's/\".*//g'" 2> /dev/null) || true - echo -e "VC (photon-machine)\t$vcip\thttps://$vcip/" + echo -e "VC (photon-machine)\t\t$vcip\thttps://$vcip/" fi done echo @@ -79,7 +96,7 @@ deploy() { id= for idx in {1..9}; do - if ! grep -q qa-$idx- $ROOT/boxes/boxes.list; then + if ! grep -q qa$idx- $ROOT/boxes/boxes.list; then id=$idx break fi @@ -99,7 +116,7 @@ deploy() { hypervisor=$(echo $hyt | awk '{print substr($0,6,3)}') repo=${4:-"http://packages.shapeblue.com/cloudstack/upstream/centos7/4.15"} storage=${5:-"/export/testing/4.15"} - env="qa-$id-$name-$hypervisor" + env="qa$id-$name-$hypervisor" echo -e "Building env with name: \033[4m$env\033[0m" echo "Management server template: $mst" @@ -261,7 +278,7 @@ launch() { echo "Please provide a valid env name, run 'mbx list' to find name of environments" exit 1 fi - id=$(echo $env | sed 's/qa-//g' | sed 's/-.*//g') + id=$(echo $env | sed 's/^qa//g' | sed 's/-.*$//g') echo "Generating marvin config for env ID $id" msip=$(getent hosts $env-mgmt1 | awk '{ print $1 }') @@ -278,7 +295,7 @@ launch() { test() { set +x - echo "Please ssh into the env; cd /marvin; bash -x smoketests.sh:" + echo "Please ssh into the env and run: cd /marvin; bash -x smoketests.sh" for env in $(cat $ROOT/boxes/boxes.list); do for vm in $(cat $ROOT/boxes/$env/list| grep mgmt1); do echo "$env: ssh root@$vm" @@ -286,6 +303,31 @@ test() { done } +stop() { + env=$1 + if [ -z "$env" ]; then + echo "Usage: mbx stop . Please pass a name, run 'mbx list' for list of available envs." + return + fi + sync + for vm in $(cat $ROOT/boxes/$env/list); do + sync + virsh destroy $vm 2>/dev/null || true + done +} + + +start() { + env=$1 + if [ -z "$env" ]; then + echo "Usage: mbx start . Please pass a name, run 'mbx list' for list of available envs." + return + fi + for vm in $(cat $ROOT/boxes/$env/list); do + virsh start $vm 2>/dev/null || true; + done +} + destroy() { env=$1 if [ -z "$env" ]; then @@ -299,18 +341,21 @@ destroy() { sed -i "/$env/d" $ROOT/boxes/boxes.list rm -frv $ROOT/boxes/$env echo "Removed environment VMs and config" - echo "To remove storage run: sudo rm -frv /export/testing/$env" + echo "To remove storage run:" + echo " sudo rm -frv /export/testing/$env" } case "$1" in help) usage;; -h) usage;; - install) install;; + init) init;; list) list;; build) build;; deploy) deploy ${@:2};; launch) launch $2;; test) test;; + start) start $2;; + stop) stop $2;; destroy) destroy $2;; *) usage;; esac diff --git a/packages/.gitkeep b/packages/.gitkeep new file mode 100644 index 0000000..e69de29