2016-12-27 11 views
0

私はファブリックから始めて、タスクが何度も実行されている問題に取り掛かります。私は、タスクを実行するつもりです。pythonファブリックのエラー重複した実行の実行

ここに私のfabfile(ノードとハブの両方がリストされている。ノード複数のホストを持っている。ハブ1つのホストのみを持っている)fabric.api輸入CD、ENV、実行し、役割、実行して、設定から インポート要求 輸入JSON は、ですタスクは、runs_once

buildconfig_location = 'http://10.102.0.69' 

def get_environment_configuration(environment_name): 
    request = requests.get("{}/api/v1/environments/{}".format(buildconfig_location, environment_name)) 
    environment_configuration = json.loads(request.text) 

    return environment_configuration 

def get_hub_servers(server_list): 
    hub = [ 
     server['ip_address'] 
     for server in server_list 
     if server['active'] and server['unit_tests']] 

    return hub 

def get_node_servers(server_list): 
    nodes = [ 
     server['ip_address'] 
     for server in server_list 
     if server['active'] and server['unit_tests'] is False] 

    return nodes 

def set_hosts(environment_configuration): 
    environment_configuration['servers'] 

    env.roledefs = { 
     'hub': [ 
      server['ip_address'] 
      for server in environment_configuration['servers'] 
      if server['active'] and server['unit_tests']], 
     'node': [ 
      server['ip_address'] 
      for server in environment_configuration['servers'] 
      if server['active'] and server['unit_tests'] is False], 
    } 

def start_node(): 
    with settings(user="automation1"): 
     with cd('/home/automation1/inventory.robot/grid'): 
      output = run('nohup ./start_node.sh > node_out 2>&1 &') 

def start_hub(): 
    with settings(user="automation1"): 
     with cd('/home/automation1/inventory.robot/grid'): 
      run('nohup ./start_hub.sh > hub_out 2>&1 &') 

def robot_test(): 
    with settings(user="automation1"): 
     with cd('/home/automation1/inventory.robot/grid'): 
      run('python grid.py') 

def kill_node(): 
    with settings(user="automation1"): 
     with cd('/home/automation1/inventory.robot/grid'): 
      run('./kill_node.pl') 

@task 
@runs_once 
def robot_test(): 
    environment_configuration = get_environment_configuration('Selenium') 
    #set_hosts(environment_configuration) 
    nodes = get_node_servers(environment_configuration['servers']) 
    hubs = get_hub_servers(environment_configuration['servers']) 

    execute(start_hub, hosts=hubs) 
    execute(start_node, hosts=nodes) 
    execute(robot_test, hosts=hubs) 

    all = hubs + nodes 
    execute(kill_node, hosts=(hubs + nodes)) 

は、ここで出力です:

[10.102.0.101] Executing task 'start_hub' 
[10.102.0.101] run: nohup ./start_hub.sh > hub_out 2>&1 & 
[10.102.0.102] Executing task 'start_node' 
[10.102.0.102] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.103] Executing task 'start_node' 
[10.102.0.103] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.104] Executing task 'start_node' 
[10.102.0.104] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.105] Executing task 'start_node' 
[10.102.0.105] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.106] Executing task 'start_node' 
[10.102.0.106] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.107] Executing task 'start_node' 
[10.102.0.107] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.108] Executing task 'start_node' 
[10.102.0.108] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.109] Executing task 'start_node' 
[10.102.0.109] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.110] Executing task 'start_node' 
[10.102.0.110] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.101] Executing task 'robot_test' 
[10.102.0.101] Executing task 'start_hub' 
[10.102.0.101] run: nohup ./start_hub.sh > hub_out 2>&1 & 
[10.102.0.102] Executing task 'start_node' 
[10.102.0.102] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.103] Executing task 'start_node' 
[10.102.0.103] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.104] Executing task 'start_node' 
[10.102.0.104] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.105] Executing task 'start_node' 
[10.102.0.105] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.106] Executing task 'start_node' 
[10.102.0.106] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.107] Executing task 'start_node' 
[10.102.0.107] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.108] Executing task 'start_node' 
[10.102.0.108] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.109] Executing task 'start_node' 
[10.102.0.109] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.110] Executing task 'start_node' 
[10.102.0.110] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.101] Executing task 'robot_test' 
[10.102.0.101] Executing task 'start_hub' 
[10.102.0.101] run: nohup ./start_hub.sh > hub_out 2>&1 & 
[10.102.0.102] Executing task 'start_node' 
[10.102.0.102] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.103] Executing task 'start_node' 
[10.102.0.103] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.104] Executing task 'start_node' 
[10.102.0.104] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.105] Executing task 'start_node' 
[10.102.0.105] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.106] Executing task 'start_node' 
[10.102.0.106] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.107] Executing task 'start_node' 
[10.102.0.107] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.108] Executing task 'start_node' 
[10.102.0.108] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.109] Executing task 'start_node' 
[10.102.0.109] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.110] Executing task 'start_node' 
[10.102.0.110] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.101] Executing task 'robot_test' 
[10.102.0.101] Executing task 'start_hub' 
[10.102.0.101] run: nohup ./start_hub.sh > hub_out 2>&1 & 
[10.102.0.102] Executing task 'start_node' 
[10.102.0.102] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.103] Executing task 'start_node' 
[10.102.0.103] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.104] Executing task 'start_node' 
[10.102.0.104] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.105] Executing task 'start_node' 
[10.102.0.105] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.106] Executing task 'start_node' 
[10.102.0.106] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.107] Executing task 'start_node' 
[10.102.0.107] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.108] Executing task 'start_node' 
[10.102.0.108] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.109] Executing task 'start_node' 
[10.102.0.109] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.110] Executing task 'start_node' 
[10.102.0.110] run: nohup ./start_node.sh > node_out 2>&1 & 
[10.102.0.101] Executing task 'robot_test' 
^C 
Stopped. 
Disconnecting from [email protected] done. 
Disconnecting from [email protected] done. 
Disconnecting from [email protected] done. 
Disconnecting from [email protected] done. 
Disconnecting from [email protected] done. 
Disconnecting from [email protected] done. 
Disconnecting from [email protected] done. 
Disconnecting from [email protected] done. 
Disconnecting from [email protected] done. 
Disconnecting from [email protected] done. 

私がコメントアウトした場合 '(robot_test、ホスト=ハブ)を実行し' 私は近い私が期待するものへの出力を取得します。私はこれがexecuteと関係があり、そのページの警告があることを認識していますが、ここで何が問題なのか分かりません。

答えて

0

robot_test()は再帰的である、それは無限ループに自分自身を呼び出している、あなたがキャンセルするまで、それは実行だ理由です。

robot_test()robot_test()のコールを削除します。あなたはその電話で何を得ようとしていますか?私はそれが目的を持っていると思うので、それは誤字ではありません。

@task 
@runs_once 
def robot_test(): 
    environment_configuration = get_environment_configuration('Selenium') 
    #set_hosts(environment_configuration) 
    nodes = get_node_servers(environment_configuration['servers']) 
    hubs = get_hub_servers(environment_configuration['servers']) 

    execute(start_hub, hosts=hubs) 
    execute(start_node, hosts=nodes) 

    all = hubs + nodes 
    execute(kill_node, hosts=(hubs + nodes)) 

実際に再帰的に実行したい場合は、再帰をいつ停止するかを知るためのパラメータが必要です。

+0

あなたはそれを釘付けにしました。私は何かの真ん中にいて、誤って2つの異なる方法のためにrobot_testという名前を使用しました。 – user7344353

0

一度だけ実行する必要がある関数のそれぞれに、runs_onceデコレータを追加してください。例えば:

@runs_once 
def start_node(): 
    with settings(user="automation1"): 
     with cd('/home/automation1/inventory.robot/grid'): 
      output = run('nohup ./start_node.sh > node_out 2>&1 &') 

@runs_once 
def start_hub(): 
    with settings(user="automation1"): 
     with cd('/home/automation1/inventory.robot/grid'): 
      run('nohup ./start_hub.sh > hub_out 2>&1 &') 

@runs_once 
def robot_test(): 
    with settings(user="automation1"): 
     with cd('/home/automation1/inventory.robot/grid'): 
      run('python grid.py') 

runs_onceデコレータがなければ、各機能は、一度ホストあたりの実行の代わりに、一度ホストごとに設定されます。


は一度ホストごとについて、あなたはこのような何かを行うことができます。

from fabric.context_managers import env 

env.hosts = hubs 
execute(start_hub) 
env.hosts = nodes 
execute(start_node) 
env.hosts = hubs 
execute(robot_test) 
+0

start_node、start_hub、robot_testおよびkill_nodeは、ホストごとに1回実行する必要があります。私の問題は、これらがホストごとに1回*複数回実行されないことです。 – user7344353

関連する問題