Skip to content

Instantly share code, notes, and snippets.

@tai271828
Last active June 20, 2018 09:00
Show Gist options
  • Save tai271828/8fa918b85b769e7b592ef294a102e26e to your computer and use it in GitHub Desktop.
Save tai271828/8fa918b85b769e7b592ef294a102e26e to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Use the existing testflinger-agent production folder
# to duplicate one more testflinger-agent for desktop SRU
#
set +x
# target CID
target_cid=$1
# remove dash from the CID
# juju does not accept dash as a agent name
target_agent_name=sru${target_cid/-}
# target IP
target_ip=$2
src_dir=$3
template_deploy=${src_dir}/deploy.yaml
target_data_dir=${src_dir}/data/${target_agent_name}
target_agent_conf=${target_data_dir}/testflinger-agent.conf
# used by snappy-device-agents
target_provision_conf=${target_data_dir}/default.yaml
# an existing folder to be used as a template
# it is the root folder of production
# oem recovery provision: use 201606-22528
#template_cid=${4:-201606-22528}
# regular maas2 provision: use 201711-25923
template_cid=$4
template_agent_name=sru${template_cid/-}
template_data_dir=${src_dir}/data/${template_agent_name}
template_provision_conf=${template_data_dir}/default.yaml
template_ip=`grep device_ip ${template_provision_conf} | awk -F: {'print $2'} | sed "s/^ //"`
template_maas_node_name=`grep node_name ${template_provision_conf} | awk {'print $2'}`
target_maas_node_name=$5
template_maas_node_id=`grep node_id ${template_provision_conf} | awk {'print $2'}`
target_maas_node_id=$6
template_secure_id=`grep secure_id ${template_provision_conf} | awk {'print $2'}`
target_secure_id=$7
echo $1 $2 $3 $4 $5 $6 $7
Usage() {
cat << EOF
Usage: ${0##*/} target-CID target-IP src-path template-CID maas-node-name maas-node-id secure-id
EOF
}
flush_template() {
local target_file=$1
local template_string=$2
local target_string=$3
echo ${target_file} : Now replace ${template_string} with ${target_string}
sed -i "s/${template_string}/${target_string}/g" ${target_file}
}
# Add testflinger-agent conf to deploy.yaml
cat << EOF >> ${template_deploy}
@@agent-name-pattern@@:
series: xenial
charm: testflinger-agent
branch: git://git.launchpad.net/~canonical-hw-cert/testflinger-agent/+git/testflinger-agent-charm
to: agent-host
resources:
testflinger_agent_configfile: data/@@agent-name-pattern@@/testflinger-agent.conf
device_configfile: data/@@agent-name-pattern@@/default.yaml
EOF
flush_template ${template_deploy} @@agent-name-pattern@@ ${target_agent_name}
cp -r ${template_data_dir} ${target_data_dir}
# regular maas provision required only
flush_template ${target_provision_conf} ${template_maas_node_name} ${target_maas_node_name}
flush_template ${target_provision_conf} ${template_maas_node_id} ${target_maas_node_id}
flush_template ${target_provision_conf} ${template_secure_id} ${target_secure_id}
flush_template ${target_agent_conf} ${template_maas_node_name} ${target_maas_node_name}
flush_template ${target_agent_conf} ${template_maas_node_id} ${target_maas_node_id}
flush_template ${target_agent_conf} ${template_secure_id} ${target_secure_id}
flush_template ${target_provision_conf} ${template_agent_name} ${target_agent_name}
flush_template ${target_provision_conf} ${template_ip} ${target_ip}
flush_template ${target_agent_conf} ${template_agent_name} ${target_agent_name}
flush_template ${target_agent_conf} ${template_cid} ${target_cid}
echo "Now check ${src_dir} to make sure you have added ${target_cid} with ${target_ip}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment