diff --git a/ansible/config_sonic_basedon_testbed.yml b/ansible/config_sonic_basedon_testbed.yml index 13618e16301..195132e1d97 100644 --- a/ansible/config_sonic_basedon_testbed.yml +++ b/ansible/config_sonic_basedon_testbed.yml @@ -153,6 +153,12 @@ delegate_to: localhost when: local_minigraph is defined and local_minigraph|bool == true + - name: copy existing minigraph file for SONiC device + copy: src=minigraph/{{ inventory_hostname }}.{{ topo }}.xml + dest=/etc/sonic/minigraph.xml + become: true + when: copy is defined and copy|bool == true + - block: - name: Init telemetry keys set_fact: @@ -225,11 +231,13 @@ shell: mv /etc/sonic/minigraph.xml /etc/sonic/minigraph.xml.orig become: true ignore_errors: true + when: copy is not defined or copy is defined and copy|bool == false - name: create new minigraph file for SONiC device template: src=templates/minigraph_template.j2 dest=/etc/sonic/minigraph.xml become: true + when: copy is not defined or copy is defined and copy|bool == false - name: Test if configlet script exist stat: diff --git a/ansible/testbed-cli.sh b/ansible/testbed-cli.sh index 361120c4d65..4faedc1c67a 100755 --- a/ansible/testbed-cli.sh +++ b/ansible/testbed-cli.sh @@ -12,7 +12,7 @@ function usage echo " $0 [options] refresh-dut " echo " $0 [options] (connect-vms | disconnect-vms) " echo " $0 [options] config-vm " - echo " $0 [options] (gen-mg | deploy-mg | test-mg) " + echo " $0 [options] (gen-mg | deploy-mg | test-mg | copy-mg) " echo " $0 [options] (create-master | destroy-master) " echo echo "Options:" @@ -52,6 +52,7 @@ function usage echo "To configure a VM on a server: $0 config-vm 'topo-name' 'vm-name' ~/.password" echo "To generate minigraph for DUT in a topology: $0 gen-mg 'topo-name' 'inventory' ~/.password" echo "To deploy minigraph to DUT in a topology: $0 deploy-mg 'topo-name' 'inventory' ~/.password" + echo "To copy and load generated minigraph to DUT in a topology: $0 copy-mg 'topo-name' 'inventory' ~/.password" echo " gen-mg, deploy-mg, test-mg supports enabling/disabling data ACL with parameter" echo " -e enable_data_plane_acl=true" echo " -e enable_data_plane_acl=false" @@ -393,6 +394,24 @@ function test_minigraph echo Done } +function copy_minigraph +{ + topology=$1 + inventory=$2 + passfile=$3 + shift + shift + shift + + echo "Copying minigraph '$topology'" + + read_file $topology + + ansible-playbook -i "$inventory" config_sonic_basedon_testbed.yml --vault-password-file="$passfile" -l "$duts" -e testbed_name="$topology" -e testbed_file=$tbfile -e vm_file=$vmfile -e copy=true $@ + + echo Done +} + function config_vm { echo "Configure VM $2" @@ -513,6 +532,8 @@ case "${subcmd}" in ;; test-mg) test_minigraph $@ ;; + copy-mg) copy_minigraph $@ + ;; create-master) start_k8s_vms $@ setup_k8s_vms $@ ;;