*** Settings *** Library SSHLibrary Library Selenium2Library Resource ElementPath.robot #Library ../../Script/SC0_Common/00_Initial/Vsphere.py Library DatabaseLibrary #Library AutoItLibrary Library Process *** Keywords *** 登录黑方 [Arguments] ${IPaddress} ${login_name} ${login_pwd} # 黑方服务器IP地址 \| 登录名称 \| 登录密码 Open Browser ${IPaddress} ff Sleep 2s Set Window Size 1920 1080 Log 切换浏览器窗口 1920*1080 Wait Until Element Is Visible ${Bc_Logo} 60s 浏览器打开失败 Sleep 5s 元素输入 ${Input_UserName} ${login_name} 定位用户名输入框失败 元素输入 ${Input_UserPWD} ${login_pwd} 定位用户密码输入框失败 元素点击 ${Button_Login} 点击登录按钮 定位登录按钮失败 Wait Until Page Contains Element xpath=//span[text()="${login_name}"] 60s 用户登录失败 Log ${login_name}登录成功 Sleep 5s 元素点击 [Arguments] ${location} ${log_localsuccess} ${log_localfail} ${sleeptime}=30s [Documentation] 元素点击: ... 点击页面上某个元素 ... ... 用法: ... 元素点击 \ \ 元素路径 \ \ 元素点击成功输出的日志 \ \ \ 元素点击失败输出的日志 \ \ \ 等待N秒直到元素出现 Wait Until Page Contains Element ${location} ${sleeptime} ${log_localfail} Set Focus To Element ${location} Click Element ${location} Log ${log_localsuccess} Sleep 5s 元素输入 [Arguments] ${location} ${input_content} ${log_localfail} ${sleeptime}=30s Wait Until Element Is Visible ${location} ${sleeptime} ${log_localfail} Set Focus To Element ${location} Input Text ${location} ${input_content} Log 输入内容为${input_content} Sleep 2s 关闭浏览器 Close Browser Log 浏览器关闭成功 关闭全部浏览器 Close All Browsers Log 全部浏览器关闭成功 系统初始化 [Arguments] ${ip} ${username} ${password} ${path} ${snapname} ${bc_ip} ${bc_root} ${bc_pwd} # esxi IP地址|登录账号|登录密码|虚拟机文件|快照名称|黑方ip|黑方用户|黑方密码 Sphere Login ${ip} ${username} ${password} Log 登录esxi成功 Vm Revert Snapshot ${path} ${snapname} Log 恢复指定虚拟机快照 Vm Poweron ${path} Log 开启虚拟机 Sleep 240s Open Connection ${bc_ip} SSHLibrary.Login ${bc_root} ${bc_pwd} Log 黑方连接成功 FOR ${n} IN RANGE 10 Execute Command systemctl status unabackup > /bc_status.txt ${bc_status} Execute Command grep "unabackup start success" /bc_status.txt ${bc_status_length} Get Length ${bc_status} Run Keyword If ${bc_status_length}>0 Exit For Loop ... ELSE Log 黑方服务还未启动 Sleep 30s END Run Keyword If ${bc_status_length}==0 Fail ... ELSE Log 黑方服务已启动 Close Connection 密码初始化 [Arguments] ${new_pwd} 登录黑方 ${Plantform_BC_Url} ${Sys_Admin} ${DefaultPWD} ${change_pwd_window}= Run Keyword And Return Status Wait Until Element Is Visible ${Change_Pwd} Run Keyword If '${change_pwd_window}'=='True' 修改密码 ${DefaultPWD} ${new_pwd} ... ELSE Close Browser Sleep 2s Log ${Sys_Admin}密码初始化完毕 Close Browser 登录黑方 ${Plantform_BC_Url} ${Sec_Admin} ${DefaultPWD} ${change_pwd_window}= Run Keyword And Return Status Wait Until Element Is Visible ${Change_Pwd} Run Keyword If '${change_pwd_window}'=='True' 修改密码 ${DefaultPWD} ${new_pwd} ... ELSE Close Browser Sleep 2s Log ${Sec_Admin}密码初始化完毕 Close Browser 登录黑方 ${Plantform_BC_Url} ${Aud_Admin} ${DefaultPWD} ${change_pwd_window}= Run Keyword And Return Status Wait Until Element Is Visible ${Change_Pwd} Run Keyword If '${change_pwd_window}'=='True' 修改密码 ${DefaultPWD} ${new_pwd} ... ELSE Close Browser Sleep 2s Log ${Aud_Admin}密码初始化完毕 Close Browser 修改密码 [Arguments] ${old_pwd} ${new_pwd} # 旧密码|新密码 Wait Until Element Is Visible ${Change_Pwd} 30s 定位修改密码窗口失败 Sleep 2s Wait Until Element Is Visible ${Input_Email} 10s 定位邮箱输入框失败 Set Focus To Element ${Input_Email} Input Text ${Input_Email} ${Email} Sleep 2s Wait Until Element Is Visible ${Input_old_pwd} 10s 定位旧密码输入框失败 Set Focus To Element ${Input_old_pwd} Input Text ${Input_old_pwd} ${old_pwd} Sleep 2s Wait Until Element Is Visible ${Input_new_pwd} 10s 定位新密码输入框失败 Set Focus To Element ${Input_new_pwd} Input Text ${Input_new_pwd} ${new_pwd} Sleep 2s Wait Until Element Is Visible ${Input_verify_pwd} 10s 定位新密码确认输入框失败 Set Focus To Element ${Input_verify_pwd} Input Text ${Input_verify_pwd} ${new_pwd} Sleep 5s Wait Until Element Is Visible ${Change_success_confirm} 10s 定位确定按钮失败 Set Focus To Element ${Change_success_confirm} Click Element ${Change_success_confirm} Sleep 2s 试用授权 登录黑方 ${Plantform_BC_Url} ${Sys_Admin} ${WebPWD} Wait Until Element Is Visible ${System_Config} 30s 定位系统设置栏失败 Set Focus To Element ${System_Config} Click Element ${System_Config} Log 进入系统设置栏 Sleep 2s Wait Until Element Is Visible ${Bc_Auth} 30s 定位产品授权栏失败 Set Focus To Element ${Bc_Auth} Click Element ${Bc_Auth} Log 进入产品授权管理栏 Sleep 2s Wait Until Element Is Visible ${Temp_Auth} 30s 定位产品试用授权失败 Set Focus To Element ${Temp_Auth} Click Element ${Temp_Auth} Log 点击试用 Sleep 2s Wait Until Element Is Visible ${Bc_Auth_confirm} 30s 定位确认试用按钮失败 Set Focus To Element ${Bc_Auth_confirm} Click Element ${Bc_Auth_confirm} Log 点击确认试用 Sleep 2s Close Browser 关闭页面锁定 登录黑方 ${Plantform_BC_Url} ${Sys_Admin} ${WebPWD} Wait Until Element Is Visible ${System_Config} 30s 定位系统设置栏失败 Set Focus To Element ${System_Config} Click Element ${System_Config} Log 进入系统设置栏 Sleep 2s Wait Until Element Is Visible ${Button_ChangeLockTime} 30s 定位更改锁定时间按钮失败 Set Focus To Element ${Button_ChangeLockTime} Click Element ${Button_ChangeLockTime} Log 点击锁定时间更改按钮 Sleep 2s Wait Until Element Is Visible ${Input_SessionLock} 30s 定位会话锁定时间输入框失败 Set Focus To Element ${Input_SessionLock} Input Text ${Input_SessionLock} 60 Log 设置会话锁定时间为60 Sleep 2s Wait Until Element Is Visible ${SessionLock_confirm} 30s 定位确认更改会话锁定失败 Set Focus To Element ${SessionLock_confirm} Click Element ${SessionLock_confirm} Log 设置会话锁定成功 Wait Until Element Is Visible ${Change_Locktime_Success} 30s 锁定时间设置失败 Click Element ${Success_Confirm} 打开黑方登录页面 [Arguments] ${IPaddress} # 黑方地址 Open Browser ${IPaddress} ff \ \ \ \ \ \ C:/Python38/geckodriver.exe Sleep 2s Set Window Size 1920 1080 Log 切换浏览器窗口 1920*1080 Wait Until Element Is Visible ${Bc_Logo} 60s 浏览器打开失败 Sleep 5s 黑方服务重启 [Arguments] ${ip} ${user} ${pwd} # 黑方ip|ssh用户名|ssh密码 Open Connection ${ip} SSHLibrary.Login ${user} ${pwd} Log 黑方连接成功 Execute Command service unabackup restart Sleep 300s Close Connection 黑方Mysql解限 ${ip} ${user} ${pwd} 循环点击 [Arguments] ${locator1} ${locator2} ${sleep_time}=5s # 需要点击的元素|预计应该看到的元素|默认等待时间 FOR ${n} IN RANGE 10 Sleep ${sleep_time} Set Focus To Element ${locator1} Click Element ${locator1} Sleep ${sleep_time} ${status}= Run Keyword And Return Status Wait Until Element Is Visible ${locator2} Run Keyword If ${status} Exit For Loop ... ELSE Log 点击${n}次 END 生成策略名 [Arguments] ${program} # 项目名(比如DPM,定时,CDM,副本) ${date} Evaluate time.strftime('%Y%m%d%H%M%S',time.localtime()) time ${taskname}= Catenate SEPARATOR=_ ${program} ${date} Set Suite Variable ${taskname} Log 设置策略名称为全局变量 清理历史作业 [Arguments] ${ip} ${user} ${pwd} # 黑方地址|用户名称|密码 [Documentation] 清理黑方页面历史作业信息 黑方Mysql解限 ${ip} ${user} ${pwd} Connect To Database Using Custom Params pymysql host='${ip}', port=${BCPort}, user='${BCUser}', passwd='${BCPwd}', db='unary', charset= 'utf8' Execute Sql String use unary; Execute Sql String delete from tbl_jobhistory; Execute Sql String delete from tbl_jobhistory_info; Disconnect From Database Log 断开数据库连接 黑方网速监控_RX [Arguments] ${ip} ${user} ${pwd} ${check_speed} # 黑方ip|ssh用户名|ssh密码|实际校验网速 Open Connection ${ip} SSHLibrary.Login ${user} ${pwd} Log 黑方连接成功 Execute Command sar -n DEV 5 10|grep eth0 > /net.txt ${TX_KB}= Execute Command cat /net.txt|awk NR==11|awk '{print $5}' ${TX_MB}= Evaluate ${TX_KB}/1024 ${check_speed}= Evaluate ${check_speed}+0.5 Run Keyword If ${TX_MB}>${check_speed} Fail 超速了 ... ELSE log 网速正常 Sleep 60s 代理初始化 [Arguments] ${ip} ${user} ${pwd} ${path} ${name} # esxi_ip地址|用户名|密码|虚拟机路径|快照名称 sphere_login ${ip} ${user} ${pwd} sleep 2S log 恢复到指定快照 vm_revert_snapshot ${path} ${name} sleep 20s sphere_logoff 代理开机 [Arguments] ${ip} ${user} ${pwd} ${agent_name} # ip地址|用户名|密码|生产机名称 log 生产机开机(esxi中操作) sphere_login ${ip} ${user} ${pwd} sleep 2s vm_poweron_name ${agent_name} sleep 5s sphere_logoff sleep 200s 代理下载_Win [Arguments] ${ip} ${user} ${pwd} ${agent_zip} ${ip_win} ${user_win} ${pwd_win} # 黑方IP | 黑方用户名 | 黑方密码|黑方后台代理路径|win代理ip|win用户名|win密码 Open Connection ${ip} 22 SSHLibrary.Login ${user} ${pwd} Log 进入服务器 sleep 5s log 黑方解压安装包 Write rm -rf /opt/agentsetup Write unzip ${agent_zip} -d /opt sleep 30s Write scp -r /opt/agentsetup ${user_win}@${ip_win}:C:/ Sleep 3s Write yes Sleep 3s Write ${pwd_win} Sleep 60s Close Connection 代理下载_Lin [Arguments] ${ip} ${user} ${pwd} ${agent_zip} ${ip_lin} ${user_lin} ${pwd_lin} # 黑方IP | 黑方用户名 | 黑方密码|黑方后台代理路径|lin代理ip|lin用户名|lin密码 Open Connection ${ip} 22 SSHLibrary.Login ${user} ${pwd} Log 进入服务器 sleep 5s Write scp ${agent_zip} ${user_lin}@${ip_lin}:/opt Sleep 15s Write yes Sleep 15s Write ${pwd_lin} Sleep 60s Close Connection 代理安装_Win [Arguments] ${ip_win} ${user_win} ${pwd_win} ${module} ${bc_url} # 代理ip|代理登录名称|代理密码|安装的组件模块(以@间隔,如@file@mysql)|黑方url Open Connection ${ip_win} 22 SSHLibrary.Login ${user_win} ${pwd_win} Log 进入生产机 sleep 5s Start Command C:\\agentsetup\\install.bat C:\\Agent uagent${module} ${bc_url}:443 \ ${ip_win} C:\\agentsetup Sleep 360s Close Connection 代理安装_Lin [Arguments] ${ip_lin} ${user_lin} ${pwd_lin} ${agent_tar} ${module} ${bc_url} # 代理ip|代理用户名|代理密码|代理压缩包名称|要安装的组件|黑方url Open Connection ${ip_lin} 22 SSHLibrary.Login ${user_lin} ${pwd_lin} Log 进入生产机 sleep 5s Write cd /opt Sleep 3s Write tar -xvf ${agent_tar} Sleep 20s Write cd agentsetup Sleep 3s Write ./install.sh /opt/agent uagent${module} ${bc_url}:443 ${ip_lin} /opt/agentsetup Sleep 300s Close Connection 启用恢复模式 [Arguments] ${agent_name} # 代理名称 元素点击 ${Timed_DataProtect} 点击进入定时数据管理 定位副本数据栏失败 元素输入 ${Input_Agent_Name} ${agent_name} 定位代理名称输入框失败 Right Click Element xpath=//span[text()="${agent_name}"] Sleep 5s 元素点击 ${Active_Recover} 启用代理恢复模式 定位启用恢复模式失败 元素点击 ${Success_Confirm} 确定代理启用成功 定位启用成功弹窗失败 Sleep 5s 代理卸载_Lin [Arguments] ${Agent_IP} ${Agent_User} ${Agent_Passwd} Open Connection ${Agent_IP} 22 log 用户登录远程测试机器 SSHLibrary.Login ${Agent_User} ${Agent_Passwd} log 卸载代理开始 ${out}= Execute Command sh /opt/agent/ubackup/uagent/bin/uninstall.sh Should Contain ${out} Welcome to use it next time Execute Command rm -rf /opt/agent* log 卸载代理结束 Close Connection 黑方网速监控_TX [Arguments] ${ip} ${user} ${pwd} ${check_speed} # 黑方ip|ssh用户名|ssh密码|实际校验网速 Open Connection ${ip} SSHLibrary.Login ${user} ${pwd} Log 黑方连接成功 Execute Command sar -n DEV 5 10|grep eth0 > /net.txt ${TX_KB}= Execute Command cat /net.txt|awk NR==11|awk '{print $6}' ${TX_MB}= Evaluate ${TX_KB}/1024 ${check_speed}= Evaluate ${check_speed}+0.5 Run Keyword If ${TX_MB}>${check_speed} Fail 超速了 ... ELSE log 网速正常 升级黑方版本 [Arguments] ${udb_path} ${bc_ip} ${login_name} ${password} # 218UDB包归档路径|升级黑方IP|SSH登录名|SSH密码 Open Connection ${bc_ip} SSHLibrary.Login ${login_name} ${password} Sleep 5s Execute Command rm -rf /opt/udb/* Log 清空黑方后台UDB包路径 Sleep 5s Execute Command mount -t cifs -o username=tester,password=Unary@2022 "${udb_path}" /mnt/ Log 执行udb目录挂载到黑方/mnt目录 ${UDB}= Execute Command find /mnt/*.udb | wc -l log 计算UDB包数量 Execute Command cp \ /mnt/* \ /opt/udb/ Log 将udb包拷贝至黑方目录/opt/udb/ Execute Command umount /mnt/ Log 卸载挂载目录 Log 上传安装脚本 Put File ${Scripts_Path}${/}..${/}Script${/}SC0_Common${/}01_Update${/}updateUDB.sh /opt/udb/ mode=7777 Log 上传升级脚本完毕 Start Command /opt/udb/updateUDB.sh Log 开始升级 FOR ${n} IN RANGE 60 ${out}= Execute Command ps -ef | grep -c \ updateUDB.sh Run Keyword If ${out}==2 Exit For Loop ... ELSE Log 升级未完成 Sleep 30s END Log 黑方升级完毕 ${success}= Execute Command cat /opt/udb/outfile.txt | grep -c success Should Be Equal ${UDB} ${success} Log 校验所有UDB包升级成功 黑方Mysql解限 [Arguments] ${ip} ${root} ${root_pwd} Open Connection ${ip} SSHLibrary.Login ${root} ${root_pwd} Execute Command touch /mysql.sh Execute Command echo '#!/bin/bash' >>/mysql.sh Execute Command echo "sed -i 's/bind/#bind/g' /etc/my.cnf" >>/mysql.sh Execute Command echo 'service mysql restart' >>/mysql.sh Execute Command echo 'service iptables stop' >>/mysql.sh Execute Command echo 'chkconfig iptables off' >>/mysql.sh Execute Command chmod -R 777 /mysql.sh Execute Command /mysql.sh Execute Command mysql -uunadba -p1223Bc@2008 -e "GRANT ALL PRIVILEGES ON *.* TO unadba@'%' IDENTIFIED BY '1223Bc@2008';FLUSH PRIVILEGES;" Log 黑方mysql解除限制完毕 循环点击_JS [Arguments] ${noxpath} ${local} # 需要循环点击的xpath路径|点击后出现的响应元素 FOR ${n} IN RANGE 10 Sleep 5s Execute Javascript document.evaluate('${noxpath}',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(0).click() Log 执行js点击元素${n}次 Sleep 5s ${status}= Run Keyword And Return Status Wait Until Element Is Visible ${local} Run Keyword If ${status} Exit For Loop ... ELSE Log 点击${n}次 END