使用fabric测试服务器环境。
envassert的Python项目详细描述
使用fabric测试服务器环境。
要求
- python 2.6或更高版本
- 面料
如何使用
安装
% pip install envassert
写fabfile.py。
from fabric.api import env, task from envassert import file, process, package, user, group, port, cron, detect env.use_ssh_config = True @task def check(): env.platform_family = detect.detect() assert file.exists("/etc/hosts") assert file.is_file("/etc/hosts") assert file.is_dir("/tmp/") assert file.dir_exists("/tmp/") assert file.has_line("/etc/passwd", "sshd") assert file.owner_is("/bin/sh", "root") assert file.group_is("/bin/sh", "root") assert file.mode_is("/bin/sh", "777") if env.platform_family == "freebsd": assert file.is_link("/compat") else: assert file.is_link("/usr/tmp") assert package.installed("wget.x86_64") assert user.exists("sshd") assert user.is_belonging_group("shirou", "users") assert group.exists("wheel") assert port.is_listening(22) assert port.is_listening(80, "tcp") assert process.is_up("http") is False assert service.is_enabled("httpd") assert cron.has_entry('shirou', 'python') assert filesystem.is_type('ext4', '/')
运行fab
% fab -H somehost check [somehost] Executing task 'check' Done. Disconnecting from root@192.168.22.98... done.
您可以使用任何其他fabric参数,如hosts或parallel。
检测操作系统
detect.detect()函数可以检测目标操作系统和 分配。将此变量设置为env.platform_family, 函数可以根据该值进行调度。
此函数是Ohai的最小端口。
目前,可以检测到这些平台。(但尚未测试)
- RHEL(Redhat、CentOS、Oracle、Scientific、EnterpriseeEnterprise、Amazon)
- debian(debian,ubuntu,linuxmint,raspbian)
- 软呢帽
- 苏西
- 格图
- 拱门
- FreeBSD
- 上网本
- openbsd
- 达尔文
但是,并不是所有的功能都可以实现 站台。欢迎拉取请求。
这项工作所依靠的巨人们
许可证
麻省理工学院许可证
仅供参考
- 美食:BSD
- 服务器规格:MIT
- Ohai:Apache2