From 15af69c32d0338d7a659ddcf23cfb339973d18e2 Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Thu, 30 Jul 2020 17:56:36 -0400 Subject: Implement linting process This commit pretends to make changes required by yamllint and shellcheck tools. Signed-off-by: Victor Morales Change-Id: I73b0a3b54f89b2692c1c3af7940a3acf1124fadb --- .gitignore | 1 + .yamllint | 17 ++++++ create_vm.sh | 17 +++--- deploy.sh | 8 +-- functions.sh | 114 ++++++++++++++++++++------------------- hw_config/intel/idf.yaml | 2 + hw_config/intel/pdf.yaml | 5 +- hw_config/intel/setup_network.sh | 15 ++++-- sw_config/bmra/all.yml | 20 +++---- sw_config/bmra/node1.yml | 2 +- tox.ini | 17 ++++++ 11 files changed, 132 insertions(+), 86 deletions(-) create mode 100644 .yamllint create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index d05a783..17c225e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ meta-data user-data +*.swp diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..c30d2b5 --- /dev/null +++ b/.yamllint @@ -0,0 +1,17 @@ +--- +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2020 Samsung Electronics +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +extends: default + +ignore: | + deployment.yaml + +rules: + line-length: disable diff --git a/create_vm.sh b/create_vm.sh index 39bc38f..74435f2 100755 --- a/create_vm.sh +++ b/create_vm.sh @@ -10,10 +10,10 @@ # TODO This will be merged in main functions.sh -sudo mkdir -p /var/lib/libvirt/images/$1 +sudo mkdir -p "/var/lib/libvirt/images/$1" sudo qemu-img create -f qcow2 \ -o backing_file=/var/lib/libvirt/images/ubuntu-18.04.qcow2 \ - /var/lib/libvirt/images/$1/"$1".qcow2 10G + "/var/lib/libvirt/images/$1/${1}.qcow2" 10G # Create cloud-init configuration files cat < user-data @@ -21,7 +21,7 @@ cat < user-data users: - name: ubuntu ssh-authorized-keys: - - $(cat $HOME/.ssh/id_rsa.pub) + - $(cat "$HOME/.ssh/id_rsa.pub") sudo: ['ALL=(ALL) NOPASSWD:ALL'] groups: sudo shell: /bin/bash @@ -30,11 +30,12 @@ cat < meta-data local-hostname: $VM_NAME EOL -sudo genisoimage -output /var/lib/libvirt/images/$1/"$1"-cidata.iso \ +sudo genisoimage -output "/var/lib/libvirt/images/$1/$1-cidata.iso" \ -volid cidata -joliet -rock user-data meta-data -sudo virt-install --connect qemu:///system --name $VM_NAME \ +sudo virt-install --connect qemu:///system --name "$VM_NAME" \ --ram 4096 --vcpus=4 --os-type linux --os-variant ubuntu16.04 \ - --disk path=/var/lib/libvirt/images/$1/"$1".qcow2,format=qcow2 \ - --disk /var/lib/libvirt/images/$1/"$1"-cidata.iso,device=cdrom \ - --import --network network=default --network bridge=$BRIDGE,model=rtl8139 --noautoconsole + --disk path="/var/lib/libvirt/images/$1/${1}.qcow2",format=qcow2 \ + --disk "/var/lib/libvirt/images/$1/${1}-cidata.iso",device=cdrom \ + --import --network network=default \ + --network bridge="$BRIDGE",model=rtl8139 --noautoconsole diff --git a/deploy.sh b/deploy.sh index 631f580..ff5797e 100755 --- a/deploy.sh +++ b/deploy.sh @@ -16,12 +16,12 @@ set -o nounset # Please refer to README for detailed information. # Get path information -DIRECTORY=$(readlink -f $0) -CURRENTPATH=$(dirname $DIRECTORY) +DIRECTORY=$(readlink -f "$0") +CURRENTPATH=$(dirname "$DIRECTORY") # Source env variables & functions -source $CURRENTPATH/deploy.env -source $CURRENTPATH/functions.sh +source "$CURRENTPATH/deploy.env" +source "$CURRENTPATH/functions.sh" # Clean up leftovers clean_up diff --git a/functions.sh b/functions.sh index 32f3c9a..5f7c0db 100755 --- a/functions.sh +++ b/functions.sh @@ -9,99 +9,101 @@ ############################################################################## # Clean up - clean_up() { if sudo virsh list --all | grep "${VM_NAME}.*running" ; then - sudo virsh destroy $VM_NAME + sudo virsh destroy "$VM_NAME" fi if sudo virsh list --all | grep "${VM_NAME}" ; then - sudo virsh undefine $VM_NAME + sudo virsh undefine "$VM_NAME" fi - sudo rm -rf /var/lib/libvirt/images/$VM_NAME - sleep 5 + sudo rm -rf "/var/lib/libvirt/images/$VM_NAME" + sleep 5 } # Create jumphost VM - create_jump() { - ./create_vm.sh $VM_NAME + ./create_vm.sh "$VM_NAME" sleep 30 } # Get jumphost VM IP - get_vm_ip() { - sudo virsh domifaddr ${VM_NAME} | awk 'FNR == 3 {gsub(/\/.*/, ""); print $4}' + sudo virsh domifaddr "$VM_NAME" | awk 'FNR == 3 {gsub(/\/.*/, ""); print $4}' } # Setup PXE network - setup_PXE_network() { - ssh -o StrictHostKeyChecking=no -tT $USERNAME@$(get_vm_ip) << EOF - sudo ifconfig $PXE_IF up - sudo ifconfig $PXE_IF $PXE_IF_IP netmask $NETMASK - sudo ifconfig $PXE_IF hw ether $PXE_IF_MAC + ssh -o StrictHostKeyChecking=no -tT "$USERNAME"@"$(get_vm_ip)" << "EOF" +sudo ifconfig $PXE_IF up +sudo ifconfig $PXE_IF $PXE_IF_IP netmask $NETMASK +sudo ifconfig $PXE_IF hw ether $PXE_IF_MAC EOF } # Copy files needed by Infra engine & BMRA in the jumphost VM - copy_files_jump() { - scp -r -o StrictHostKeyChecking=no $CURRENTPATH/{hw_config/$VENDOR/,sw_config/$INSTALLER/} \ - $USERNAME@$(get_vm_ip):$PROJECT_ROOT + scp -r -o StrictHostKeyChecking=no \ + "$CURRENTPATH/{hw_config/$VENDOR/,sw_config/$INSTALLER/}" \ + "$USERNAME@$(get_vm_ip):$PROJECT_ROOT" } # Host Provisioning - provision_hosts() { -# SSH to jumphost - ssh -tT $USERNAME@$(get_vm_ip) << EOF + ssh -tT "$USERNAME"@"$(get_vm_ip)" << "EOF" # Install and run cloud-infra - if [ ! -d "${PROJECT_ROOT}/engine" ]; then - ssh-keygen -t rsa -N "" -f ${PROJECT_ROOT}/.ssh/id_rsa - git clone https://gerrit.nordix.org/infra/engine.git - cp $PROJECT_ROOT/$VENDOR/{pdf.yaml,idf.yaml} ${PROJECT_ROOT}/engine/engine -# sudo mkdir /httpboot && sudo cp -r ${PROJECT_ROOT}/deployment_image.qcow2 /httpboot #will be removed when centos image path will be added in infra-engine - fi - cd ${PROJECT_ROOT}/engine/engine && ./deploy.sh -s ironic -d centos7 \ - -p file:///${PROJECT_ROOT}/engine/engine/pdf.yaml -i file:///${PROJECT_ROOT}/engine/engine/idf.yaml +if [ ! -d "${PROJECT_ROOT}/engine" ]; then + ssh-keygen -t rsa -N "" -f ${PROJECT_ROOT}/.ssh/id_rsa + git clone https://gerrit.nordix.org/infra/engine.git + cp $PROJECT_ROOT/$VENDOR/{pdf.yaml,idf.yaml} \ + ${PROJECT_ROOT}/engine/engine +# NOTE: will be removed when centos image path will be added in infra-engine +sudo mkdir /httpboot +# sudo cp -r ${PROJECT_ROOT}/deployment_image.qcow2 /httpboot +fi +cd ${PROJECT_ROOT}/engine/engine +./deploy.sh -s ironic -d centos7 \ +-p file:///${PROJECT_ROOT}/engine/engine/pdf.yaml \ +-i file:///${PROJECT_ROOT}/engine/engine/idf.yaml EOF } -# Setup networking on provisioned hosts (Adapt setup_network.sh according to your network setup) - +# Setup networking on provisioned hosts (Adapt setup_network.sh according to your network setup) setup_network() { -# SSH to jumphost - ssh -tT $USERNAME@$(get_vm_ip) << EOF - ssh -o StrictHostKeyChecking=no root@$MASTER_IP 'bash -s' < ${PROJECT_ROOT}/${VENDOR}/setup_network.sh - ssh -o StrictHostKeyChecking=no root@$WORKER_IP 'bash -s' < ${PROJECT_ROOT}/${VENDOR}/setup_network.sh + ssh -tT "$USERNAME"@"$(get_vm_ip)" << "EOF" +ssh -o StrictHostKeyChecking=no root@$MASTER_IP \ + 'bash -s' < ${PROJECT_ROOT}/${VENDOR}/setup_network.sh +ssh -o StrictHostKeyChecking=no root@$WORKER_IP \ + 'bash -s' < ${PROJECT_ROOT}/${VENDOR}/setup_network.sh EOF } # k8s Provisioning (currently BMRA) - provision_k8s() { -# SSH to jumphost - ssh -tT $USERNAME@$(get_vm_ip) << EOF + ssh -tT "$USERNAME"@"$(get_vm_ip)" << "EOF" # Install BMRA - if [ ! -d "${PROJECT_ROOT}/container-experience-kits" ]; then - curl -fsSL https://get.docker.com/ | sh - printf "Waiting for docker service..." - until sudo docker info; do - printf "." - sleep 2 - done - git clone https://github.com/intel/container-experience-kits.git - cd ${PROJECT_ROOT}/container-experience-kits - git checkout v1.4.1 - git submodule update --init - cp -r examples/group_vars examples/host_vars . - cp ${PROJECT_ROOT}/${INSTALLER}/inventory.ini ${PROJECT_ROOT}/container-experience-kits/ - cp ${PROJECT_ROOT}/${INSTALLER}/all.yml ${PROJECT_ROOT}/container-experience-kits/group_vars/ - cp ${PROJECT_ROOT}/${INSTALLER}/node1.yml ${PROJECT_ROOT}/container-experience-kits/host_vars/ - fi - sudo service docker start - sudo docker run --rm -v ${PROJECT_ROOT}/container-experience-kits:/bmra -v ~/.ssh/:/root/.ssh/ \ - rihabbanday/bmra-install:centos ansible-playbook -i /bmra/inventory.ini /bmra/playbooks/cluster.yml +if [ ! -d "${PROJECT_ROOT}/container-experience-kits" ]; then + curl -fsSL https://get.docker.com/ | sh + printf "Waiting for docker service..." + until sudo docker info; do + printf "." + sleep 2 + done + git clone https://github.com/intel/container-experience-kits.git + cd ${PROJECT_ROOT}/container-experience-kits + git checkout v1.4.1 + git submodule update --init + cp -r examples/group_vars examples/host_vars . + cp ${PROJECT_ROOT}/${INSTALLER}/inventory.ini \ + ${PROJECT_ROOT}/container-experience-kits/ + cp ${PROJECT_ROOT}/${INSTALLER}/all.yml \ + ${PROJECT_ROOT}/container-experience-kits/group_vars/ + cp ${PROJECT_ROOT}/${INSTALLER}/node1.yml \ + ${PROJECT_ROOT}/container-experience-kits/host_vars/ +fi +sudo service docker start +sudo docker run --rm \ +-v ${PROJECT_ROOT}/container-experience-kits:/bmra \ +-v ~/.ssh/:/root/.ssh/ rihabbanday/bmra-install:centos \ +ansible-playbook -i /bmra/inventory.ini /bmra/playbooks/cluster.yml EOF } diff --git a/hw_config/intel/idf.yaml b/hw_config/intel/idf.yaml index d9127ff..a5f9455 100644 --- a/hw_config/intel/idf.yaml +++ b/hw_config/intel/idf.yaml @@ -1,3 +1,4 @@ +--- # SPDX-license-identifier: Apache-2.0 ############################################################################## # Copyright (c) 2020 @@ -6,6 +7,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## + idf: version: 0.1 net_config: &net_config diff --git a/hw_config/intel/pdf.yaml b/hw_config/intel/pdf.yaml index c97f29a..4b7862d 100644 --- a/hw_config/intel/pdf.yaml +++ b/hw_config/intel/pdf.yaml @@ -1,3 +1,4 @@ +--- # SPDX-license-identifier: Apache-2.0 ############################################################################## # Copyright (c) 2020 @@ -6,7 +7,6 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -### POD descriptor file ### version: 1.0 details: @@ -16,7 +16,6 @@ details: location: somewhere type: baremetal link: http://wiki.opnfv.org/display/pharos/Intel+Hosting -############################################################################## jumphost: name: pod19-jump node: &nodeparas @@ -56,7 +55,6 @@ jumphost: address: 10.10.192.1 mac_address: "3c:fd:fe:aa:be:24" vlan: native -############################################################################## nodes: - name: node1 node: *nodeparas @@ -96,7 +94,6 @@ nodes: address: 10.10.195.2 mac_address: "00:00:00:00:00:00" vlan: native -######################################################################## - name: node2 node: *nodeparas disks: *disks diff --git a/hw_config/intel/setup_network.sh b/hw_config/intel/setup_network.sh index a6ff6df..4035b7a 100755 --- a/hw_config/intel/setup_network.sh +++ b/hw_config/intel/setup_network.sh @@ -1,11 +1,20 @@ +#!/bin/bash +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + # Adapt this script according to your network setup # TODO Get networking info from PDF & IDF # TODO Add support in infra engine to update nameserver, etc # files with correct info -#!/bin/bash echo nameserver 8.8.8.8 > /etc/resolv.conf -sed -i 's/NM_CONTROLLED=yes/NM_CONTROLLED=no/g' /etc/sysconfig/network-scripts/ifcfg-eth2 +sed -i 's/NM_CONTROLLED=yes/NM_CONTROLLED=no/g' \ +/etc/sysconfig/network-scripts/ifcfg-eth2 echo GATEWAY=10.10.190.1 >> /etc/sysconfig/network-scripts/ifcfg-eth2 ifup eth2 - diff --git a/sw_config/bmra/all.yml b/sw_config/bmra/all.yml index a1140d3..45300e3 100644 --- a/sw_config/bmra/all.yml +++ b/sw_config/bmra/all.yml @@ -10,12 +10,12 @@ nfd_sleep_interval: 30s # Intel CPU Manager for Kubernetes cmk_enabled: false cmk_namespace: kube-system -cmk_use_all_hosts: false # 'true' will deploy CMK on the master nodes too -cmk_hosts_list: node1,node2 # allows to control where CMK nodes will run, leave this option commented out to deploy on all K8s nodes -cmk_shared_num_cores: 2 # number of CPU cores to be assigned to the "shared" pool on each of the nodes -cmk_exclusive_num_cores: 2 # number of CPU cores to be assigned to the "exclusive" pool on each of the nodes -#cmk_shared_mode: packed # choose between: packed, spread, default: packed -#cmk_exclusive_mode: packed # choose between: packed, spread, default: packed +cmk_use_all_hosts: false # 'true' will deploy CMK on the master nodes too +cmk_hosts_list: node1,node2 # allows to control where CMK nodes will run, leave this option commented out to deploy on all K8s nodes +cmk_shared_num_cores: 2 # number of CPU cores to be assigned to the "shared" pool on each of the nodes +cmk_exclusive_num_cores: 2 # number of CPU cores to be assigned to the "exclusive" pool on each of the nodes +# cmk_shared_mode: packed # choose between: packed, spread, default: packed +# cmk_exclusive_mode: packed # choose between: packed, spread, default: packed # Intel SRIOV Network Device Plugin sriov_net_dp_enabled: false @@ -65,11 +65,11 @@ example_net_attach_defs: sriov_net_dp: false ## Proxy configuration ## -#http_proxy: "http://proxy.example.com:1080" -#https_proxy: "http://proxy.example.com:1080" -#additional_no_proxy: ".example.com" +# http_proxy: "http://proxy.example.com:1080" +# https_proxy: "http://proxy.example.com:1080" +# additional_no_proxy: ".example.com" -#Topology Manager flags +# Topology Manager flags kubelet_node_custom_flags: - "--feature-gates=TopologyManager=true" - "--topology-manager-policy=none" diff --git a/sw_config/bmra/node1.yml b/sw_config/bmra/node1.yml index 3e4f634..e103673 100644 --- a/sw_config/bmra/node1.yml +++ b/sw_config/bmra/node1.yml @@ -17,7 +17,7 @@ sriov_nics: sriov_cni_enabled: false # install DPDK -install_dpdk: false # DPDK installation is required for sriov_enabled:true; default to false +install_dpdk: false # DPDK installation is required for sriov_enabled:true; default to false userspace_cni_enabled: false diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..4c9b4bd --- /dev/null +++ b/tox.ini @@ -0,0 +1,17 @@ +[tox] +minversion = 3.15 +skipsdist = True +envlist = lint,docs + +[testenv] +passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY + +[testenv:lint] +deps = + {env:BASHATE_INSTALL_PATH:bashate} + yamllint +whitelist_externals = bash +commands = bash -c "find {toxinidir} \ + -not -path {toxinidir}/.tox/\* \ + -name \*.sh | xargs bashate -v" + bash -c "yamllint {toxinidir}" -- cgit 1.2.3-korg