原文:https://github.com/Azure/sonic-mgmt/blob/master/docs/testbed/README.testbed.VsSetup.md
KVM Testbed Setup
本文描述了设置基于虚拟交换机的测试台、向其部署T0拓扑以及运行快速测试以验证其是否按预期工作的步骤。
Prepare testbed host
首先,我们需要准备主机,在那里我们将配置虚拟测试台并运行测试。
-
Install Ubuntu 20.04 AMD64 on your host or VM
- To setup a T0 topology, the server needs to have at least 10GB of memory free
- 如果测试台主机是VM,那么它必须支持嵌套虚拟化
- 运行主机安装脚本以安装所需的包并初始化管理网桥网络
git clone https://github.com/Azure/sonic-mgmt
cd sonic-mgmt/ansible
sudo ./setup-management-network.sh
- 安装Docker CE。一定要遵循安装后的说明,这样就不需要sudo权限来运行docker命令。
Download an VM image
我们目前支持基于EOS或SONiC VMs来模拟虚拟试验台中的相邻设备,就像我们对物理试验台所做的那样。为此,我们需要将映像下载到我们的测试台主机。
Option 1: vEOS (KVM-based) image
- Download the vEOS image from Arista
- 将以下镜像文件复制到测试台主机上的~/veos vm/images:
Aboot-veos-serial-8.0.0.iso
vEOS-lab-4.20.15M.vmdk
Option 2: cEOS (container-based) image (experimental)
Option 2.1: Download and import cEOS image manually
- Download the cEOS image from Arista
- Import the cEOS image (导入需要几分钟,请耐心等待!)
$ docker import cEOS64-lab-4.23.2F.tar.xz ceosimage:4.23.2F
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ceosimage 4.23.2F d53c28e38448 2 hours ago 1.82GB
Option 2.2: Pull cEOS image automatically
-
Alternatively, you can host the cEOS image on a http server. Specify
vm_images_url
for downloading the image here. -
如果下载CEO映像需要SAS密钥,请在sonic mgmt/ansible/vars/azure_storage.yml中指定ceosimage_saskey.
If you want to skip downloading the image when the cEOS image is not imported locally, set skip_ceos_image_downloading
to true
in sonic-mgmt/ansible/group_vars/all/ceos.yml
. Then, when the cEOS image is not locally available, the scripts will not try to download it and will fail with an error message. Please use option 1 to download and import the cEOS image manually.
Option 3: Use SONiC image as neighboring devices
You need to prepare a sound SONiC image sonic-vs.img
in ~/veos-vm/images/
. We don't support to download sound sonic image right now, but for testing, you can also follow the section Download the sonic-vs image to download an available image and put it into the directory ~/veos-vm/images
Download the sonic-vs image
To run the tests with a virtual SONiC device, we need a virtual SONiC image. The simplest way to do so is to download a public build from Jenkins.
- Download the sonic-vs image from here
wget https://sonic-jenkins.westus2.cloudapp.azure.com/job/vs/job/buildimage-vs-image/lastSuccessfulBuild/artifact/target/sonic-vs.img.gz
- Unzip the image and move it into
~/sonic-vm/images/
$ gzip -d sonic-vs.img.gz
$ mkdir -p ~/sonic-vm/images
$ mv sonic-vs.img ~/sonic-vm/images
Setup sonic-mgmt docker
所有测试台配置步骤和测试都是从sonic mgmt docker容器运行的。这个容器有所有必要的软件包和工具,以便在不同的开发人员和实验室设置之间测试行为是一致的。
- Run the
setup-container.sh
in the root directory of the sonic-mgmt repository:
$ cd sonic-mgmt
$ ./setup-container.sh -n <container name> -d /data
- 从现在起,所有步骤都在sonic mgmt docker中运行,除非另有说明。
您可以使用以下命令输入sonic mgmt容器:
$ docker exec -it <container name> bash
You will find your sonic-mgmt directory mounted at /data/sonic-mgmt
:
$ ls /data/sonic-mgmt/
LICENSE README.md __pycache__ ansible docs lgtm.yml setup-container.sh spytest test_reporting tests
Setup host public key in sonic-mgmt docker
为了在您的主机上自动配置测试床,Ansible需要能够在没有密码提示的情况下SSH到其中。上一步中的setup container脚本将为您设置所有必需的SSH密钥,但要使Ansible正常工作,还需要进行一些修改:
- 修改veos_vtb以使用您要用于登录主机的用户名(例如foo)(这可以是您在主机上的用户名)
foo@sonic:/data/sonic-mgmt/ansible$ git diff
diff --git a/ansible/veos_vtb b/ansible/veos_vtb
index 3e7b3c4e..edabfc40 100644
--- a/ansible/veos_vtb
+++ b/ansible/veos_vtb
@@ -73,7 +73,7 @@ vm_host_1:
hosts:
STR-ACS-VSERV-01:
ansible_host: 172.17.0.1
- ansible_user: use_own_value
+ ansible_user: foo
vms_1:
hosts:
- Create a dummy
password.txt
file under/data/sonic-mgmt/ansible
Note: Here, password.txt
is the Ansible Vault password file. Ansible allows users to use Ansible Vault to encrypt password files.
By default, the testbed scripts require a password file. If you are not using Ansible Vault, you can create a file with a dummy password (e.g. abc
) and pass the filename to the command line. The file name and location is created and maintained by the user.
-
在主机上,运行sudo visudo并在末尾添加以下行:
foo ALL=(ALL) NOPASSWD:ALL
-
Verify that you can login into the host (e.g.
ssh [email protected]
) from thesonic-mgmt
container without any password prompt. -
Verify that you can use
sudo
without a password prompt inside the host (e.g.sudo bash
).
Setup VMs on the server
(如果您使用的是cEOS,请跳过此步骤-容器将在稍后的步骤中自动设置。)
现在我们需要在主机上启动一些虚拟机,作为virtual SONiC switch.的相邻设备。
- Start the VMs:
$ ./testbed-cli.sh -m veos_vtb -n 4 start-vms server_1 password.txt
如果您使用SONiC image作为VMs,则需要添加extract参数-k SONiC,命令:
./testbed-cli.sh -m veos_vtb -n 4 -k sonic start-vms server_1 password.txt.
当然,如果要停止VMs,还需要在原始命令之后附加这些参数。
提醒:默认情况下,此shell脚本需要密码文件。如果不使用Ansible Vault,只需使用伪密码创建一个文件,并将文件名传递到命令行。
- 检查所有虚拟机是否已启动并正在运行。对于基于EOS的VMs,请注意:passwd是123456。
$ ansible -m ping -i veos_vtb server_1 -u root -k
VM0102 | SUCCESS => {
"changed": false,
"ping": "pong"
}
VM0101 | SUCCESS => {
"changed": false,
"ping": "pong"
}
STR-ACS-VSERV-01 | SUCCESS => {
"changed": false,
"ping": "pong"
}
VM0103 | SUCCESS => {
"changed": false,
"ping": "pong"
}
VM0100 | SUCCESS => {
"changed": false,
"ping": "pong"
}
对于SONiC VMs注意:passwd是password。
$ ansible -m ping -i veos_vtb server_1 -u admin -k
VM0102 | SUCCESS => {
"changed": false,
"ping": "pong"
}
VM0101 | SUCCESS => {
"changed": false,
"ping": "pong"
}
STR-ACS-VSERV-01 | SUCCESS => {
"changed": false,
"ping": "pong"
}
VM0103 | SUCCESS => {
"changed": false,
"ping": "pong"
}
VM0100 | SUCCESS => {
"changed": false,
"ping": "pong"
}
部署T0拓扑
现在我们终于可以为我们的测试平台部署拓扑了!运行以下命令,具体取决于用于安装的EOS图像类型:
vEOS
$ cd /data/sonic-mgmt/ansible
$ ./testbed-cli.sh -t vtestbed.csv -m veos_vtb add-topo vms-kvm-t0 password.txt
cEOS
$ cd /data/sonic-mgmt/ansible
$ ./testbed-cli.sh -t vtestbed.csv -m veos_vtb -k ceos add-topo vms-kvm-t0 password.txt
验证是否正确创建了cEOS邻居:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
575064498cbc ceosimage:4.23.2F "/sbin/init systemd.…" About a minute ago Up About a minute ceos_vms6-1_VM0103
d71b8970bcbb debian:jessie "bash" About a minute ago Up About a minute net_vms6-1_VM0103
3d2e5ecdd472 ceosimage:4.23.2F "/sbin/init systemd.…" About a minute ago Up About a minute ceos_vms6-1_VM0102
28d64c74fa54 debian:jessie "bash" About a minute ago Up About a minute net_vms6-1_VM0102
0fa067a47c7f ceosimage:4.23.2F "/sbin/init systemd.…" About a minute ago Up About a minute ceos_vms6-1_VM0101
47066451fa4c debian:jessie "bash" About a minute ago Up About a minute net_vms6-1_VM0101
e07bd0245bd9 ceosimage:4.23.2F "/sbin/init systemd.…" About a minute ago Up About a minute ceos_vms6-1_VM0100
4584820bf368 debian:jessie "bash" 7 minutes ago Up 7 minutes net_vms6-1_VM0100
c929c622232a sonicdev-microsoft.azurecr.io:443/docker-ptf:latest "/usr/local/bin/supe…" 7 minutes ago Up 7 minutes ptf_vms6-1
Deploy minigraph on the DUT
一旦创建了拓扑,我们就需要给DUT一个初始配置。
- Deploy the
minigraph.xml
to the DUT and save the configuration:
$ ./testbed-cli.sh -t vtestbed.csv -m veos_vtb deploy-mg vms-kvm-t0 lab password.txt
-
Verify that you can login to the SONiC KVM using Mgmt IP = 10.250.0.101 and admin:password.
-
You should see BGP sessions up in SONiC:
admin@vlab-01:~$ show ip bgp sum
BGP router identifier 10.1.0.32, local AS number 65100
RIB entries 12807, using 1401 KiB of memory
Peers 8, using 36 KiB of memory
Peer groups 2, using 112 bytes of memory
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
10.0.0.57 4 64600 3208 12 0 0 0 00:00:22 1
10.0.0.59 4 64600 3208 593 0 0 0 00:00:22 1
10.0.0.61 4 64600 3205 950 0 0 0 00:00:21 1
10.0.0.63 4 64600 3204 950 0 0 0 00:00:21 1
Run a Pytest
Now that the testbed has been fully setup and configured, let's run a simple test to make sure everything is functioning as expected.
- Switch over to the
tests
directory:
cd sonic-mgmt/tests
- Run the following command to execute the
bgp_fact
test (including the pre/post setup steps):
./run_tests.sh -n vms-kvm-t0 -d vlab01 -c bgp/test_bgp_fact.py -f vtestbed.csv -i veos_vtb
You should see three sets of tests run and pass. You're now set up and ready to use the KVM testbed!