<s> import copy <EOL> from itertools import chain <EOL> from itertools import repeat <EOL> from random import randrange <EOL> import threading <EOL> import time <EOL> from fysom import Fysom <EOL> from kombu import Connection <EOL> from kombu import Exchange <EOL> from kombu import Queue <EOL> from nailgun import objects <EOL> from nailgun import consts <EOL> from nailgun . db import db <EOL> from nailgun . db . sqlalchemy . models import Node <EOL> from nailgun . rpc . receiver import NailgunReceiver <EOL> from nailgun . settings import settings <EOL> class FSMNodeFlow ( Fysom ) : <EOL> def __init__ ( self , data , initial = None ) : <EOL> super ( FSMNodeFlow , self ) . __init__ ( { <EOL> '<STR_LIT>' : initial or consts . NODE_STATUSES . discover , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:src>' : consts . NODE_STATUSES . discover , <EOL> '<STR_LIT>' : consts . NODE_STATUSES . provisioning } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:src>' : consts . NODE_STATUSES . provisioning , <EOL> '<STR_LIT>' : consts . NODE_STATUSES . provisioned } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:src>' : consts . NODE_STATUSES . provisioned , <EOL> '<STR_LIT>' : consts . NODE_STATUSES . deploying } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:src>' : consts . NODE_STATUSES . deploying , <EOL> '<STR_LIT>' : consts . NODE_STATUSES . ready } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:src>' : consts . NODE_STATUSES . error , <EOL> '<STR_LIT>' : consts . NODE_STATUSES . error } , <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT:error>' , <EOL> '<STR_LIT:src>' : [ <EOL> consts . NODE_STATUSES . discover , <EOL> consts . NODE_STATUSES . provisioning , <EOL> consts . NODE_STATUSES . provisioned , <EOL> consts . NODE_STATUSES . deploying , <EOL> consts . NODE_STATUSES . ready , <EOL> consts . NODE_STATUSES . error <EOL> ] , <EOL> '<STR_LIT>' : consts . NODE_STATUSES . error <EOL> } , <EOL> { <EOL> '<STR_LIT:name>' : consts . NODE_STATUSES . ready , <EOL> '<STR_LIT:src>' : [ <EOL> consts . NODE_STATUSES . discover , <EOL> consts . NODE_STATUSES . provisioning , <EOL> consts . NODE_STATUSES . provisioned , <EOL> consts . NODE_STATUSES . deploying , <EOL> consts . NODE_STATUSES . ready , <EOL> consts . NODE_STATUSES . error <EOL> ] , <EOL> '<STR_LIT>' : consts . NODE_STATUSES . ready <EOL> } , <EOL> ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . on_next , <EOL> '<STR_LIT>' : self . on_error , <EOL> '<STR_LIT>' : self . on_ready <EOL> } <EOL> } ) <EOL> self . data = data <EOL> self . data . setdefault ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> if data . get ( '<STR_LIT:status>' ) == consts . NODE_STATUSES . error : <EOL> self . error ( ) <EOL> else : <EOL> self . next ( ) <EOL> def on_ready ( self , e ) : <EOL> self . data [ '<STR_LIT:status>' ] = consts . NODE_STATUSES . ready <EOL> self . data [ '<STR_LIT>' ] = <NUM_LIT:100> <EOL> def on_error ( self , e ) : <EOL> self . data [ '<STR_LIT:status>' ] = consts . NODE_STATUSES . error <EOL> if e . src in [ <EOL> consts . NODE_STATUSES . discover , consts . NODE_STATUSES . provisioning <EOL> ] : <EOL> if not self . data . get ( '<STR_LIT>' ) : <EOL> self . data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> elif e . src in [ consts . NODE_STATUSES . provisioned , <EOL> consts . NODE_STATUSES . deploying , <EOL> consts . NODE_STATUSES . ready ] : <EOL> if not self . data . get ( '<STR_LIT>' ) : <EOL> self . data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . data [ '<STR_LIT>' ] = <NUM_LIT:100> <EOL> def on_next ( self , e ) : <EOL> if e . dst in [ <EOL> consts . NODE_STATUSES . provisioning , consts . NODE_STATUSES . deploying <EOL> ] : <EOL> self . data [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> self . data [ '<STR_LIT:status>' ] = e . dst <EOL> def update_progress ( self , value ) : <EOL> self . data [ '<STR_LIT>' ] += value <EOL> if self . data [ '<STR_LIT>' ] >= <NUM_LIT:100> : <EOL> self . data [ '<STR_LIT>' ] = <NUM_LIT:100> <EOL> self . next ( ) <EOL> class FakeThread ( threading . Thread ) : <EOL> NODE_FIELDS = ( '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> Receiver = NailgunReceiver <EOL> def __init__ ( self , data = None , params = None , group = None , target = None , <EOL> name = None , verbose = None , join_to = None ) : <EOL> threading . Thread . __init__ ( self , group = group , target = target , name = name , <EOL> verbose = verbose ) <EOL> self . data = data <EOL> self . params = params <EOL> self . join_to = join_to <EOL> self . tick_count = int ( settings . FAKE_TASKS_TICK_COUNT ) <EOL> self . low_tick_count = self . tick_count - <NUM_LIT:10> <EOL> if self . low_tick_count < <NUM_LIT:0> : <EOL> self . low_tick_count = <NUM_LIT:0> <EOL> self . tick_interval = int ( settings . FAKE_TASKS_TICK_INTERVAL ) <EOL> self . task_uuid = data [ '<STR_LIT:args>' ] . get ( <EOL> '<STR_LIT>' <EOL> ) <EOL> self . respond_to = data [ '<STR_LIT>' ] <EOL> self . stoprequest = threading . Event ( ) <EOL> self . error = None <EOL> def run ( self ) : <EOL> if self . join_to : <EOL> self . join_to . join ( ) <EOL> if self . join_to . error : <EOL> self . error = "<STR_LIT>" <EOL> self . message_gen = self . error_message_gen <EOL> def error_message_gen ( self ) : <EOL> return [ { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT:status>' : '<STR_LIT:error>' , <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> '<STR_LIT:error>' : self . error <EOL> } ] <EOL> def rude_join ( self , timeout = None ) : <EOL> self . stoprequest . set ( ) <EOL> super ( FakeThread , self ) . join ( timeout ) <EOL> def sleep ( self , timeout ) : <EOL> if timeout == <NUM_LIT:0> : <EOL> return <EOL> step = <NUM_LIT> <EOL> for r in repeat ( step , int ( float ( timeout ) / step ) ) : <EOL> if not self . stoprequest . isSet ( ) : <EOL> time . sleep ( r ) <EOL> def refresh_nodes ( self , nodes ) : <EOL> nodes_map = { str ( n [ '<STR_LIT>' ] ) : n for n in nodes } <EOL> nodes_db = db ( ) . query ( Node ) . filter ( <EOL> Node . id . in_ ( nodes_map ) <EOL> ) <EOL> for node_db in nodes_db : <EOL> node = nodes_map [ node_db . uid ] <EOL> for field in self . NODE_FIELDS : <EOL> v = getattr ( node_db , field ) <EOL> if v is not None : <EOL> node [ field ] = v <EOL> def notify ( self , kwargs ) : <EOL> resp_method = getattr ( self . Receiver , self . respond_to ) <EOL> try : <EOL> resp_method ( ** kwargs ) <EOL> db ( ) . commit ( ) <EOL> except Exception : <EOL> db ( ) . rollback ( ) <EOL> raise <EOL> def run_until_status ( self , smart_nodes , status , <EOL> role = None , random_error = False , <EOL> instant = False ) : <EOL> ready = False <EOL> if random_error : <EOL> smart_nodes [ randrange ( <NUM_LIT:0> , len ( smart_nodes ) ) ] . error ( ) <EOL> while not ready and not self . stoprequest . isSet ( ) : <EOL> for sn in smart_nodes : <EOL> continue_cases = ( <EOL> sn . current in ( status , consts . NODE_STATUSES . error ) , <EOL> role and <EOL> ( ( '<STR_LIT>' in sn . data and sn . data [ '<STR_LIT>' ] != role ) or <EOL> ( '<STR_LIT>' in sn . data and role not in sn . data [ '<STR_LIT>' ] ) ) <EOL> ) <EOL> if any ( continue_cases ) : <EOL> continue <EOL> if instant : <EOL> sn . ready ( ) <EOL> else : <EOL> sn . update_progress ( <EOL> randrange ( <EOL> self . low_tick_count , <EOL> self . tick_count <EOL> ) <EOL> ) <EOL> if role : <EOL> test_nodes = [ <EOL> sn for sn in smart_nodes <EOL> if ( ( '<STR_LIT>' in sn . data and sn . data [ '<STR_LIT>' ] ) or <EOL> ( '<STR_LIT>' in sn . data and role in sn . data [ '<STR_LIT>' ] ) ) <EOL> ] <EOL> else : <EOL> test_nodes = smart_nodes <EOL> node_ready_status = ( <EOL> ( tn . current in ( status , '<STR_LIT:error>' ) ) <EOL> for tn in test_nodes <EOL> ) <EOL> if all ( node_ready_status ) : <EOL> ready = True <EOL> yield [ sn . data for sn in smart_nodes ] <EOL> class FakeAmpqThread ( FakeThread ) : <EOL> def run ( self ) : <EOL> super ( FakeAmpqThread , self ) . run ( ) <EOL> if settings . FAKE_TASKS_AMQP : <EOL> nailgun_exchange = Exchange ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> durable = True <EOL> ) <EOL> nailgun_queue = Queue ( <EOL> '<STR_LIT>' , <EOL> exchange = nailgun_exchange , <EOL> routing_key = '<STR_LIT>' <EOL> ) <EOL> with Connection ( '<STR_LIT>' ) as conn : <EOL> with conn . Producer ( serializer = '<STR_LIT>' ) as producer : <EOL> for msg in self . message_gen ( ) : <EOL> producer . publish ( <EOL> { <EOL> "<STR_LIT>" : self . respond_to , <EOL> "<STR_LIT:args>" : msg <EOL> } , <EOL> exchange = nailgun_exchange , <EOL> routing_key = '<STR_LIT>' , <EOL> declare = [ nailgun_queue ] <EOL> ) <EOL> else : <EOL> for msg in self . message_gen ( ) : <EOL> self . notify ( msg ) <EOL> class FakeDeploymentThread ( FakeAmpqThread ) : <EOL> def message_gen ( self ) : <EOL> error = self . params . get ( "<STR_LIT:error>" ) <EOL> if error != '<STR_LIT>' : <EOL> error = None <EOL> error_msg = self . params . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> task_ready = self . params . get ( "<STR_LIT>" ) <EOL> if '<STR_LIT>' in self . params : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> override_state = self . params . get ( "<STR_LIT>" , False ) <EOL> if '<STR_LIT>' in self . data [ '<STR_LIT:args>' ] : <EOL> nodes = [ <EOL> { '<STR_LIT>' : uid } <EOL> for uid in self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] <EOL> if uid and uid != consts . MASTER_NODE_UID <EOL> ] <EOL> else : <EOL> nodes = self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] <EOL> self . refresh_nodes ( nodes ) <EOL> kwargs = { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT>' : nodes , <EOL> '<STR_LIT:status>' : '<STR_LIT>' <EOL> } <EOL> if override_state : <EOL> progress = override_state . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> status = override_state . get ( "<STR_LIT:status>" , "<STR_LIT>" ) <EOL> for n in kwargs [ "<STR_LIT>" ] : <EOL> n [ "<STR_LIT:status>" ] = status <EOL> n [ "<STR_LIT>" ] = progress <EOL> kwargs [ "<STR_LIT:status>" ] = status <EOL> yield kwargs <EOL> raise StopIteration <EOL> smart_nodes = [ <EOL> FSMNodeFlow ( n , consts . NODE_STATUSES . provisioned ) <EOL> for n in kwargs [ '<STR_LIT>' ] <EOL> ] <EOL> stages_errors = { <EOL> None : chain ( <EOL> self . run_until_status ( <EOL> smart_nodes , consts . NODE_STATUSES . deploying <EOL> ) , <EOL> self . run_until_status ( <EOL> smart_nodes , consts . NODE_STATUSES . ready , '<STR_LIT>' <EOL> ) , <EOL> self . run_until_status ( <EOL> smart_nodes , consts . NODE_STATUSES . ready <EOL> ) <EOL> ) , <EOL> '<STR_LIT>' : chain ( <EOL> self . run_until_status ( <EOL> smart_nodes , consts . NODE_STATUSES . deploying <EOL> ) , <EOL> self . run_until_status ( <EOL> smart_nodes , consts . NODE_STATUSES . ready , <EOL> '<STR_LIT>' , random_error = True <EOL> ) <EOL> ) <EOL> } <EOL> mode = stages_errors [ error ] <EOL> for nodes_status in mode : <EOL> kwargs [ '<STR_LIT>' ] = nodes_status <EOL> yield kwargs <EOL> self . sleep ( self . tick_interval ) <EOL> if not error or task_ready : <EOL> kwargs [ '<STR_LIT:status>' ] = consts . TASK_STATUSES . ready <EOL> else : <EOL> kwargs [ '<STR_LIT:status>' ] = consts . TASK_STATUSES . error <EOL> if error_msg : <EOL> kwargs [ '<STR_LIT:error>' ] = error_msg <EOL> yield kwargs <EOL> class FakeProvisionThread ( FakeThread ) : <EOL> def run ( self ) : <EOL> super ( FakeProvisionThread , self ) . run ( ) <EOL> error = self . params . get ( "<STR_LIT:error>" ) <EOL> error_msg = self . params . get ( '<STR_LIT>' ) <EOL> if error != "<STR_LIT>" : <EOL> error = None <EOL> kwargs = { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT:status>' : consts . TASK_STATUSES . running , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } <EOL> smart_nodes = [ <EOL> FSMNodeFlow ( n , consts . NODE_STATUSES . discover ) <EOL> for n in self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> ] <EOL> for nodes in self . run_until_status ( <EOL> smart_nodes , consts . NODE_STATUSES . provisioned , <EOL> random_error = error is not None <EOL> ) : <EOL> kwargs [ '<STR_LIT>' ] = nodes <EOL> for n in nodes : <EOL> if n [ '<STR_LIT:status>' ] in ( <EOL> consts . NODE_STATUSES . provisioned , <EOL> consts . NODE_STATUSES . error <EOL> ) : <EOL> continue <EOL> kwargs [ '<STR_LIT>' ] = n [ '<STR_LIT>' ] <EOL> kwargs [ '<STR_LIT:status>' ] = consts . TASK_STATUSES . running <EOL> break <EOL> else : <EOL> kwargs [ '<STR_LIT>' ] = <NUM_LIT:100> <EOL> if error is None : <EOL> kwargs [ '<STR_LIT:status>' ] = consts . TASK_STATUSES . ready <EOL> else : <EOL> kwargs [ '<STR_LIT:status>' ] = consts . TASK_STATUSES . error <EOL> if error_msg : <EOL> kwargs [ '<STR_LIT>' ] = error_msg <EOL> self . notify ( kwargs ) <EOL> self . sleep ( self . tick_interval ) <EOL> class FakeDeletionThread ( FakeThread ) : <EOL> def run ( self ) : <EOL> super ( FakeDeletionThread , self ) . run ( ) <EOL> receiver = NailgunReceiver <EOL> kwargs = { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT>' : self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT:status>' : '<STR_LIT>' <EOL> } <EOL> nodes_to_restore = copy . deepcopy ( <EOL> self . data [ '<STR_LIT:args>' ] . get ( '<STR_LIT>' , [ ] ) ) <EOL> resp_method = getattr ( receiver , self . respond_to ) <EOL> try : <EOL> resp_method ( ** kwargs ) <EOL> db ( ) . commit ( ) <EOL> except Exception : <EOL> db ( ) . rollback ( ) <EOL> raise <EOL> recover_nodes = self . params . get ( "<STR_LIT>" , True ) <EOL> recover_offline_nodes = self . params . get ( "<STR_LIT>" , True ) <EOL> if not recover_nodes : <EOL> db ( ) . commit ( ) <EOL> return <EOL> for node_data in nodes_to_restore : <EOL> is_offline = "<STR_LIT>" in node_data and not node_data [ "<STR_LIT>" ] <EOL> if is_offline and not recover_offline_nodes : <EOL> continue <EOL> node_data [ "<STR_LIT:status>" ] = "<STR_LIT>" <EOL> objects . Node . create ( node_data ) <EOL> db ( ) . commit ( ) <EOL> class FakeStopDeploymentThread ( FakeThread ) : <EOL> def run ( self ) : <EOL> super ( FakeStopDeploymentThread , self ) . run ( ) <EOL> receiver = NailgunReceiver <EOL> recover_nodes = self . params . get ( "<STR_LIT>" , True ) <EOL> ia_nodes_count = self . params . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> nodes = self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] <EOL> ia_nodes = [ ] <EOL> if ia_nodes_count : <EOL> ia_nodes = nodes [ <NUM_LIT:0> : ia_nodes_count ] <EOL> nodes = nodes [ ia_nodes_count : ] <EOL> self . sleep ( self . tick_interval ) <EOL> kwargs = { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT>' : self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : nodes , <EOL> '<STR_LIT>' : ia_nodes , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:100> <EOL> } <EOL> resp_method = getattr ( receiver , self . respond_to ) <EOL> try : <EOL> resp_method ( ** kwargs ) <EOL> db ( ) . commit ( ) <EOL> except Exception : <EOL> db ( ) . rollback ( ) <EOL> raise <EOL> if not recover_nodes : <EOL> db ( ) . commit ( ) <EOL> return <EOL> nodes_db = db ( ) . query ( Node ) . filter ( <EOL> Node . id . in_ ( [ <EOL> n [ '<STR_LIT>' ] for n in self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] <EOL> ] ) <EOL> ) . all ( ) <EOL> for n in nodes_db : <EOL> self . sleep ( self . tick_interval ) <EOL> n . online = True <EOL> n . status = "<STR_LIT>" <EOL> db ( ) . add ( n ) <EOL> db ( ) . commit ( ) <EOL> class FakeResetEnvironmentThread ( FakeThread ) : <EOL> def run ( self ) : <EOL> super ( FakeResetEnvironmentThread , self ) . run ( ) <EOL> receiver = NailgunReceiver <EOL> recover_nodes = self . params . get ( "<STR_LIT>" , True ) <EOL> ia_nodes_count = self . params . get ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> nodes = self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] <EOL> ia_nodes = [ ] <EOL> if ia_nodes_count : <EOL> ia_nodes = nodes [ <NUM_LIT:0> : ia_nodes_count ] <EOL> nodes = nodes [ ia_nodes_count : ] <EOL> self . sleep ( self . tick_interval ) <EOL> kwargs = { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT>' : nodes , <EOL> '<STR_LIT>' : ia_nodes , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:100> <EOL> } <EOL> resp_method = getattr ( receiver , self . respond_to ) <EOL> try : <EOL> resp_method ( ** kwargs ) <EOL> db ( ) . commit ( ) <EOL> except Exception : <EOL> db ( ) . rollback ( ) <EOL> raise <EOL> if not recover_nodes : <EOL> db ( ) . commit ( ) <EOL> return <EOL> nodes_db = db ( ) . query ( Node ) . filter ( <EOL> Node . id . in_ ( [ <EOL> n [ '<STR_LIT>' ] for n in self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] <EOL> ] ) <EOL> ) . all ( ) <EOL> for n in nodes_db : <EOL> self . sleep ( self . tick_interval ) <EOL> n . online = True <EOL> n . status = "<STR_LIT>" <EOL> db ( ) . add ( n ) <EOL> db ( ) . commit ( ) <EOL> class FakeVerificationThread ( FakeThread ) : <EOL> def run ( self ) : <EOL> super ( FakeVerificationThread , self ) . run ( ) <EOL> for n in self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] : <EOL> for iface in n [ '<STR_LIT>' ] : <EOL> if <NUM_LIT> in iface [ '<STR_LIT>' ] : <EOL> iface [ '<STR_LIT>' ] = list ( set ( iface [ '<STR_LIT>' ] ) ^ set ( [ <NUM_LIT> ] ) ) <EOL> for subtask in self . data . get ( '<STR_LIT>' , [ ] ) : <EOL> func = FAKE_THREADS [ subtask [ '<STR_LIT>' ] ] ( subtask , self . params ) <EOL> func . run ( ) <EOL> resp_method = getattr ( NailgunReceiver , self . respond_to ) <EOL> try : <EOL> resp_method ( <EOL> task_uuid = self . task_uuid , <EOL> progress = <NUM_LIT:100> , <EOL> status = '<STR_LIT>' , <EOL> nodes = self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] , <EOL> ) <EOL> db ( ) . commit ( ) <EOL> except Exception : <EOL> db ( ) . rollback ( ) <EOL> raise <EOL> class FakeMulticastVerifications ( FakeAmpqThread ) : <EOL> """<STR_LIT>""" <EOL> def ready_multicast ( self ) : <EOL> response = { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } <EOL> response [ '<STR_LIT>' ] = <NUM_LIT:30> <EOL> yield response <EOL> nodes = self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] <EOL> nodes_uid = [ node [ '<STR_LIT>' ] for node in nodes ] <EOL> response [ '<STR_LIT:status>' ] = '<STR_LIT>' <EOL> response [ '<STR_LIT>' ] = <NUM_LIT:100> <EOL> response [ '<STR_LIT>' ] = dict ( ( node_uid , nodes_uid ) <EOL> for node_uid in nodes_uid ) <EOL> yield response <EOL> def error1_multicast ( self ) : <EOL> response = { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } <EOL> response [ '<STR_LIT>' ] = <NUM_LIT:30> <EOL> yield response <EOL> nodes = self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] <EOL> nodes_uid = [ node [ '<STR_LIT>' ] for node in nodes ] [ : len ( nodes ) - <NUM_LIT:1> ] <EOL> response [ '<STR_LIT:status>' ] = '<STR_LIT>' <EOL> response [ '<STR_LIT>' ] = <NUM_LIT:100> <EOL> response [ '<STR_LIT>' ] = dict ( ( node_uid , nodes_uid ) <EOL> for node_uid in nodes_uid ) <EOL> yield response <EOL> def error2_multicast ( self ) : <EOL> response = { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT>' : <NUM_LIT:0> <EOL> } <EOL> response [ '<STR_LIT>' ] = <NUM_LIT:30> <EOL> yield response <EOL> nodes = self . data [ '<STR_LIT:args>' ] [ '<STR_LIT>' ] <EOL> nodes_uid = [ node [ '<STR_LIT>' ] for node in nodes ] <EOL> response [ '<STR_LIT:status>' ] = '<STR_LIT>' <EOL> response [ '<STR_LIT>' ] = <NUM_LIT:100> <EOL> response [ '<STR_LIT>' ] = dict ( ( node_uid , nodes_uid ) <EOL> for node_uid in nodes_uid ) <EOL> response [ '<STR_LIT>' ] [ nodes_uid [ - <NUM_LIT:1> ] ] = [ ] <EOL> yield response <EOL> def message_gen ( self ) : <EOL> task_name = '<STR_LIT>' . format ( self . params . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> return getattr ( self , task_name ) ( ) <EOL> class FakeCheckingDhcpThread ( FakeAmpqThread ) : <EOL> """<STR_LIT>""" <EOL> def _get_message ( self , mac ) : <EOL> """<STR_LIT>""" <EOL> nodes = [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:data>' : [ { '<STR_LIT>' : mac , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:data>' : [ { '<STR_LIT>' : mac , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ] } ] <EOL> return { '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT:error>' : '<STR_LIT>' , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> '<STR_LIT>' : nodes } <EOL> def message_gen ( self ) : <EOL> self . sleep ( self . tick_interval ) <EOL> if self . params . get ( "<STR_LIT>" ) : <EOL> return self . error_message_gen ( ) <EOL> elif '<STR_LIT>' in self . params : <EOL> return ( self . _get_message ( self . params [ '<STR_LIT>' ] ) , ) <EOL> else : <EOL> return ( self . _get_message ( settings . ADMIN_NETWORK [ '<STR_LIT>' ] ) , ) <EOL> class FakeDumpEnvironment ( FakeAmpqThread ) : <EOL> def message_gen ( self ) : <EOL> self . sleep ( self . tick_interval ) <EOL> return [ { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> class FakeCapacityLog ( FakeAmpqThread ) : <EOL> def message_gen ( self ) : <EOL> self . sleep ( self . tick_interval ) <EOL> return [ { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ] <EOL> class FakeExecuteTasksThread ( FakeAmpqThread ) : <EOL> def message_gen ( self ) : <EOL> self . sleep ( self . tick_interval ) <EOL> return [ { <EOL> '<STR_LIT>' : self . task_uuid , <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:100> <EOL> } ] <EOL> class FakeCheckRepositories ( FakeAmpqThread ) : <EOL> def message_gen ( self ) : <EOL> self . sleep ( self . tick_interval ) <EOL> return [ { <EOL> "<STR_LIT>" : self . task_uuid , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:100> , <EOL> "<STR_LIT>" : [ { "<STR_LIT>" : "<STR_LIT:1>" , "<STR_LIT:status>" : <NUM_LIT:0> , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } ] <EOL> } ] <EOL> class FakeTaskInOrchestrator ( FakeAmpqThread ) : <EOL> def message_gen ( self ) : <EOL> self . sleep ( self . tick_interval ) <EOL> return [ { '<STR_LIT>' : self . task_uuid } ] <EOL> FAKE_THREADS = { <EOL> '<STR_LIT>' : FakeProvisionThread , <EOL> '<STR_LIT>' : FakeProvisionThread , <EOL> '<STR_LIT>' : FakeDeploymentThread , <EOL> '<STR_LIT>' : FakeDeploymentThread , <EOL> '<STR_LIT>' : FakeDeploymentThread , <EOL> '<STR_LIT>' : FakeDeletionThread , <EOL> '<STR_LIT>' : FakeStopDeploymentThread , <EOL> '<STR_LIT>' : FakeResetEnvironmentThread , <EOL> '<STR_LIT>' : FakeVerificationThread , <EOL> '<STR_LIT>' : FakeCheckingDhcpThread , <EOL> '<STR_LIT>' : FakeDumpEnvironment , <EOL> '<STR_LIT>' : FakeCapacityLog , <EOL> '<STR_LIT>' : FakeMulticastVerifications , <EOL> '<STR_LIT>' : FakeExecuteTasksThread , <EOL> '<STR_LIT>' : FakeCheckRepositories , <EOL> '<STR_LIT>' : FakeCheckRepositories , <EOL> '<STR_LIT>' : FakeTaskInOrchestrator <EOL> } </s>
