在yardstick的自动化脚本开发过程有一种重要场景,就是要登陆计算节点来读取计算节点的信息或者验证某些信息,一般来讲,假如源节点(要登陆计算节点的端点,譬如笔记本)在计算节点的云内,比如源节点就是计算节点上的虚拟机,这时直接就可以ssh登陆。但是,假如源节点在云外,只能通过openstack的API地址访问云,那这时候计算节点的管理IP是不对外的,我们只能通过先登陆控制节点,然后再登陆计算节点的方式来达到目的。
Openstack网络示意图
大多数的openstack的网络跟上面的示意图类似,基本分为四个网络,这里暂且不讨论存储网络,也就还剩三个网络:管理网络1(红色)、业务网络(蓝色)和管理网络2(紫色),红色网络是各个节点间进行通信的网络,蓝色网络是虚拟机的网络,紫色网络是openstack对外的网络,外部要访问openstack内部只能通过紫色网络。要申明一点,很多时候,openstack的控制节点和网络节点合一了,即只有控制节点和计算节点,这里把网络节点看成是控制节点就行了,然后多个控制节点通过一个公共的浮动IP对外提供服务。
由于上面的原因,当我们使用node类型的context也即ansible的方式来实现从docker节点(yardstick运行在docker上)跳转到计算节点并读取计算节点信息时就要用到跳板ansible的跳转机的方法(不用)。
说明:
1)用ansible的缺点是,当跳转到compute节点上时,compute包括的所有的host都会把compute的action执行一遍,这会耗用一定的资源,当host的数量很大时,下面介绍的方法不适用,但对于自动化验证来说,host的数量少,是可以用后面介绍的方法的。
2)除了使用完全都用node的context的方法外,还可以用context为heat,然后从虚拟机通过两次ssh的方式登陆计算节点(该方法正在调试,调试完成会共享出来);或者用混合的方式,即一个testcase的yaml文件既用node类型的context也用heat类型的context。
3)下面介绍的方法还用了ansible框架的功能,即通过ansible框架,在网络可达的基础上,源主机(ansible框架代码所在的主机)是可以ssh直接登录到inventory.ini文件中的各个host上去的,不需要跳板机。之所以用跳板机是由于上面图的openstack的网络架构的原因。
4)Ansible的一些说明:Ansible 可同时操作属于一个组的多台主机,组和主机之间的关系通过 inventory 文件配置. 默认的文件路径为 /etc/ansible/hosts
方法分为两大步骤:
1、 配置跳板机的方式
1)配置ssh的跳板机的方式。该配置文件(位于docker上)是说,去所有的host主机都会通过192.168.115.222进行跳转。
root@88050931d062:~# more ssh_config
GSSAPIAuthentication no
Host *
ProxyCommand ssh root@192.168.115.222 -W %h:%p
root@88050931d062:~# pwd
/root
2)在dorcker上的ansible.cfg文件配置SSH的相关选项,特别是ssh_connect
root@88050931d062:/home/opnfv/repos/yardstick/ansible# more ansible.cfg
[defaults]
host_key_checking = False
keep_remote_files = True
remote_tmp = /tmp/.ansible/tmp
[ssh_connection]
ssh_args = -o ControlPersist=15m -F /root/ssh_config -q
scp_if_ssh = True
2、 在compute的action部分增加when语句,我这个文档是把roles和action合一了。
具体如下(红色标注):
- hosts: compute tasks:
- name: get name of current host
shell:
source /etc/yardstick/openstack.creds;
echo $HOSTNAME
args:
executable: /bin/bash
register: computenode2
- debug: var=computenode2
- name: get host of VM created
shell:
source /etc/yardstick/openstack.creds;
nova show yardstick-vm | grep OS-EXT-SRV-ATTR:hypervisor_hostname | awk '{print $4}'
args:
executable: /bin/bash
register: computenode1
- debug: var=computenode1
- name: the node is not right
when: computenode1.stdout_lines[0]!=computenode2.stdout_lines[0]
shell: echo "The vm is not on the" {{item}}
with_items:
- '{{computenode2.stdout_lines[0]}}'
register: display
- debug: var=display
- name: show NUMA info
when: computenode1.stdout_lines[0]==computenode2.stdout_lines[0]
shell: sleep 10; numastat -p qemu
args:
executable: /bin/bash
register: cmd
- debug: var=cmd.stdout
附件:整个yaml文件的内容。
---
- hosts: localhost
tasks:
- name: create flavor yardstick-pinned-flavor
shell:
source /etc/yardstick/openstack.creds;
nova flavor-create 'yardstick-pinned-flavor' $(cat /proc/sys/kernel/random/uuid) 512 2 2;
nova flavor-list
args:
executable: /bin/bash
register: cmd
- debug: var=cmd.stdout_lines
- name: set yardstick-pinned-flavor property
shell:
source /etc/yardstick/openstack.creds;
openstack flavor set --property hw:cpu_policy=dedicated yardstick-pinned-flavor;
openstack flavor set --property hw:numa_nodes=1 yardstick-pinned-flavor;
openstack flavor show yardstick-pinned-flavor;
args:
executable: /bin/bash
register: cmd
- debug: var=cmd.stdout_lines
- name: create VM
shell:
source /etc/yardstick/openstack.creds;
openstack server create --flavor yardstick-pinned-flavor --image cirros-0.3.5 \
--network=ext-net yardstick-vm
args:
executable: /bin/bash
register: cmd
- debug: var=cmd.stdout_lines
- hosts: compute
tasks:
- name: get name of current host
shell:
source /etc/yardstick/openstack.creds;
echo $HOSTNAME
args:
executable: /bin/bash
register: computenode2
- debug: var=computenode2
- name: get host of VM created
shell:
source /etc/yardstick/openstack.creds;
nova show yardstick-vm | grep OS-EXT-SRV-ATTR:hypervisor_hostname | awk '{print $4}'
args:
executable: /bin/bash
register: computenode1
- debug: var=computenode1
- name: the node is not right
when: computenode1.stdout_lines[0]!=computenode2.stdout_lines[0]
shell: echo "The vm is not on the" {{item}}
with_items:
- '{{computenode2.stdout_lines[0]}}'
register: display
- debug: var=display
- name: show NUMA info
when: computenode1.stdout_lines[0]==computenode2.stdout_lines[0]
shell: sleep 10; numastat -p qemu
args:
executable: /bin/bash
register: cmd
- debug: var=cmd.stdout
- hosts: localhost
tasks:
- name: delete VM
shell:
source /etc/yardstick/openstack.creds;
openstack server delete yardstick-vm
args:
executable: /bin/bash
register: cmd
- debug: var=cmd.stdout_lines
- name: delete flavor yardstick-pinned-flavor
shell:
source /etc/yardstick/openstack.creds;
nova flavor-delete 'yardstick-pinned-flavor';
args:
executable: /bin/bash
register: cmd
- debug: var=cmd.stdout_lines
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com