ansible命令模块:JMeter msg:[Errno 2]没有这样的文件或目录

时间:2015-10-02 21:52:05

标签: jmeter performance-testing ansible ansible-playbook file-not-found

Ansible 1.9.2 / latest。 操作系统:CentOS 6.7 /更高版本 JAVA_HOME,PATH变量和所有其他东西都设置正确。

我在perf_tests / tasks / main.yml中运行了以下playbook。要仅运行此剧本,我使用Ansible标签。

# Run JMeter tests
- name: Run JMeter test(s)
#  command: "export PATH={{ jdk_install_dir }}/bin:$PATH && export JAVA_HOME={{ jdk_install_dir }} && {{ jmeter_install_dir }}/bin/jmeter -n -t {{ common_download_dir}}/perf_tests/ProjectTest1.jmx -l {{ common_download_dir}}/perf_tests/log_jmeter_ProjectTest1.jtl"
  command: export PATH={{ jdk_install_dir }}/bin:$PATH && export JAVA_HOME={{ jdk_install_dir }} && /apps/jmeter/apache-jmeter-2.13/bin/jmeter -n -t /tmp/perf_tests/ProjectTest1.jmx -l /tmp/perf_tests/log_jmeter_ProjectTest1.jtl
  become_user: "{{ common_user }}"
  tags:
     - giga

JMeter可执行文件所需的文件存在于目标计算机上,我使用"命令"在ansible模块中启动JMeter。

[appuser@jmeter01 ~]$ ls -l /apps/jmeter/apache-jmeter-2.13/bin/jmeter /tmp/perf_tests/ProjectTest1.jmx
-rwxr-xr-x. 1 appuser appgroup  5589 Mar  8  2015 /apps/jmeter/apache-jmeter-2.13/bin/jmeter
-rw-r--r--. 1 appuser appgroup 50194 Oct  2 12:19 /tmp/perf_tests/ProjectTest1.jmx
[appuser@jmeter01 ~]$

[appuser@jmeter01 ~]$ which java
/apps/jdk/jdk1.7.0_67/bin/java

当我运行上面的playbook时,在.jmx文件上运行jmeter来生成一个结果.jtl文件(使用ANSIBLE),它的错误输出错误代码为2(如下所示): msg:[Errno 2]没有这样的文件或目录

ANSIBLE输出:

TASK: [perf_tests | Run JMeter test(s)] ***************************************
<jmeter01.perf.jenkins> ESTABLISH CONNECTION FOR USER: confman on PORT 22 TO jmeter01.perf.jenkins
<jmeter01.perf.jenkins> REMOTE_MODULE command export PATH=/apps/jdk/jdk1.7.0_67/bin:$PATH && export JAVA_HOME=/apps/jdk/jdk1.7.0_67 && /apps/jmeter/apache-jmeter-2.13/bin/jmeter -n -t /tmp/perf_tests/ProjectTest1.jmx -l /tmp/perf_tests/log_jmeter_ProjectTest1.jtl
<jmeter01.perf.jenkins> EXEC /bin/sh -c 'mkdir -p /tmp/ansible-tmp-1443821195.89-232957509929426 && chmod a+rx /tmp/ansible-tmp-1443821195.89-232957509929426 && echo /tmp/ansible-tmp-1443821195.89-232957509929426'
<jmeter01.perf.jenkins> PUT /tmp/tmp6fAr1W TO /tmp/ansible-tmp-1443821195.89-232957509929426/command
<jmeter01.perf.jenkins> EXEC /bin/sh -c 'chmod a+r /tmp/ansible-tmp-1443821195.89-232957509929426/command'
<jmeter01.perf.jenkins> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=pkivlaidiolrcxvyxxixeysvrfkpvroy] password: " -u appuser /bin/sh -c '"'"'echo BECOME-SUCCESS-pkivlaidiolrcxvyxxixeysvrfkpvroy; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1443821195.89-232957509929426/command'"'"''
<jmeter01.perf.jenkins> EXEC /bin/sh -c 'rm -rf /tmp/ansible-tmp-1443821195.89-232957509929426/ >/dev/null 2>&1'
failed: [jmeter01.perf.jenkins] => {"cmd": "export PATH=/apps/jdk/jdk1.7.0_67/bin:/sbin:/bin:/usr/sbin:/usr/bin '&&' export JAVA_HOME=/apps/jdk/jdk1.7.0_67 '&&' /apps/jmeter/apache-jmeter-2.13/bin/jmeter -n -t /tmp/perf_tests/ProjectTest1.jmx -l /tmp/perf_tests/log_jmeter_ProjectTest1.jtl", "failed": true, "rc": 2}
msg: [Errno 2] No such file or directory

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************

上面的ansible&#t; svvv详细输出中的&#34; cmd&#34; 显示,Ansible成功通过/扩展了所有内容,用于调用jmeter命令,但它&#39失败了。

IF 我转到远程机器(jmeter01)和&#34; appuser&#34;并运行该命令,它工作正常,并成功创建提供.jtl结果文件的-l选项。

[appuser@jmeter01 ~]$ /apps/jmeter/apache-jmeter-2.13/bin/jmeter -n -t /tmp/perf_tests/ProjectTest1.jmx -l /tmp/perf_tests/log_jmeter_ProjectTest1.jtl
Creating summariser <summary>
Created the tree successfully using /tmp/perf_tests/ProjectTest1.jmx
Starting the test @ Fri Oct 02 17:23:50 EDT 2015 (1443821030343)
Waiting for possible shutdown message on port 4445
summary =    240 in   4.4s =   54.0/s Avg:    82 Min:     2 Max:  1113 Err:     0 (0.00%)
Tidying up ...    @ Fri Oct 02 17:23:55 EDT 2015 (1443821035009)
... end of run
[appuser@jmeter01 ~]$ ls -l /tmp/perf_tests
total 80
-rw-r--r--. 1 appuser appgroup 50194 Oct  2 12:19 ProjectTest1.jmx
-rw-r--r--. 1 appuser appgroup 22412 Oct  2 17:23 log_jmeter_ProjectTest1.jtl
drwxr-xr-x. 3 appuser appgroup  4096 Oct  2 12:19 META-INF
[appuser@jmeter01 ~]$

我难以理解为什么JMeter在使用Ansible运行时出错了这个错误! ?

2 个答案:

答案 0 :(得分:4)

您不能将export&&command模块一起使用,因为它直接执行命令,而不是通过shell,而export是一个shell内置。

您需要shell模块。

比较输出:

ansible myserver -m command -a "echo Hello && echo Goodbye"
ansible myserver -m command -a "export GREET=Hello && echo '$GREET'"

ansible myserver -m shell -a "echo Hello && echo Goodbye"
ansible myserver -m shell -a "export GREET=Hello && echo '$GREET'"

你可以清楚地看到这一点。

答案 1 :(得分:1)

Seumasmac是对的。我无法找到任何地方&#34;命令&#34;模块能够运行jmeter来运行测试(我甚至尝试硬编码值并将其传递给命令:xxx xxx xxx)。

使用以下&#34; shell &#34;模块我能够运行多个.jmx(如果项目有)并且还获取(将结果.jtl文件返回到运行ansible的源服务器)。

使用&#34; with_items&#34;,我可以传递jmxfile值并获得多个jmeter运行。脚本:run_jmeter_test.sh捆绑在一个ZIP文件中,我在{{common_download_dir}} == / tmp中首先(使用复制模块)推送到目标/远程jmeter01服务器并且我能够创建perf_tests文件夹并在那里解压缩ZIP以在运行playbook之前完成所有设置以运行JMeter可执行文件/命令。

# Run JMeter tests using Ansible shell module on remote Jmeter node
- name: Run JMeter tests using Ansible shell module on remote Jmeter node and pass parameters
  shell: "sudo {{ common_download_dir }}/perf_tests/run_jmeter_test.sh {{ jdk_install_dir }} {{ jmeter_install_dir }}/bin/jmeter {{ common_download_dir }}/perf_tests/{{ item.jmxfile }}.jmx {{ common_download_dir }}/perf_tests/log_jmeter_{{ item.jmxfile }}.jtl"
  become_user: "{{ common_user }}"
  with_items:
    - { jmxfile: 'ProjectTest1' }
#    - { jmxfile: 'ProjectTest101' }
#    - { jmxfile: 'ProjectTest102' }

# Fetch JMeter test(s) result .jtl file(s) from remote server and put it in local workspace.
- name: Fetch JMeter test(s) result .jtl file(s)
  fetch: src="{{ common_download_dir}}/perf_tests/log_jmeter_{{ item.jmxfile }}.jtl" dest="perf_tests/{{ item.jmxfile}}.jtl" flat=yes fail_on_missing=yes
  with_items:
    - { jmxfile: 'ProjectTest1' }
#    - { jmxfile: 'ProjectTest101' }
#    - { jmxfile: 'ProjectTest102' }

run_jmeter_test.sh 看起来像(非常简单/简单版本):

#!/bin/sh

javaHome=$1
jmExec=$2
jmxFile=$3
jtlFile=$4

export PATH=$javaHome/bin:$PATH

$jmExec -n -t $jmxFile -l $jtlFile

我的其他帖子还展示了我如何获得JMeter可执行文件以及它的Extra / Standard / WebDriver插件。