Esempio n. 1
0
    def get_create_member_flow(self):
        """Create a flow to create a member

        :returns: The flow for creating a member
        """
        create_member_flow = linear_flow.Flow(constants.CREATE_MEMBER_FLOW)
        create_member_flow.add(
            lifecycle_tasks.MemberToErrorOnRevertTask(requires=[
                constants.MEMBER, constants.LISTENERS, constants.LOADBALANCER,
                constants.POOL
            ]))
        create_member_flow.add(
            database_tasks.MarkMemberPendingCreateInDB(
                requires=constants.MEMBER))
        create_member_flow.add(
            network_tasks.CalculateDelta(
                requires=(constants.LOADBALANCER, constants.AVAILABILITY_ZONE),
                provides=constants.DELTAS))
        create_member_flow.add(
            network_tasks.HandleNetworkDeltas(requires=constants.DELTAS,
                                              provides=constants.ADDED_PORTS))
        create_member_flow.add(
            amphora_driver_tasks.AmphoraePostNetworkPlug(
                requires=(constants.LOADBALANCER, constants.ADDED_PORTS)))
        create_member_flow.add(
            amphora_driver_tasks.ListenersUpdate(
                requires=constants.LOADBALANCER))
        create_member_flow.add(
            database_tasks.MarkMemberActiveInDB(requires=constants.MEMBER))
        create_member_flow.add(
            database_tasks.MarkPoolActiveInDB(requires=constants.POOL))
        create_member_flow.add(
            database_tasks.MarkLBAndListenersActiveInDB(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))

        return create_member_flow
Esempio n. 2
0
    def get_update_health_monitor_flow(self):
        """Create a flow to update a health monitor

        :returns: The flow for updating a health monitor
        """
        update_hm_flow = linear_flow.Flow(constants.UPDATE_HEALTH_MONITOR_FLOW)
        update_hm_flow.add(lifecycle_tasks.HealthMonitorToErrorOnRevertTask(
            requires=[constants.HEALTH_MON,
                      constants.LISTENERS,
                      constants.LOADBALANCER]))
        update_hm_flow.add(database_tasks.MarkHealthMonitorPendingUpdateInDB(
            requires=constants.HEALTH_MON))
        update_hm_flow.add(amphora_driver_tasks.ListenersUpdate(
            requires=constants.LOADBALANCER_ID))
        update_hm_flow.add(database_tasks.UpdateHealthMonInDB(
            requires=[constants.HEALTH_MON, constants.UPDATE_DICT]))
        update_hm_flow.add(database_tasks.MarkHealthMonitorActiveInDB(
            requires=constants.HEALTH_MON))
        update_hm_flow.add(database_tasks.MarkPoolActiveInDB(
            requires=constants.POOL_ID))
        update_hm_flow.add(database_tasks.MarkLBAndListenersActiveInDB(
            requires=(constants.LOADBALANCER_ID, constants.LISTENERS)))

        return update_hm_flow
Esempio n. 3
0
def create_mirror_view(mirror_view, mirror_name, primary_lun_id, pool_name,
                       lun_name, lun_size, provision, tier):
    flow_name = 'create_mirror_view'
    store_specs = {
        'mirror': mirror_view,
        'mirror_name': mirror_name,
        'primary_lun_id': primary_lun_id,
        'pool_name': pool_name,
        'lun_name': lun_name,
        'lun_size': lun_size,
        'provision': provision,
        'tier': tier,
        'ignore_thresholds': True
    }
    # NOTE: should create LUN on secondary device/array
    work_flow = linear_flow.Flow(flow_name)
    work_flow.add(
        CreateMirrorTask(),
        CreateLunTask(name='CreateSecondaryLunTask',
                      provides=('secondary_lun_id', 'secondary_lun_wwn'),
                      inject={'client': mirror_view.secondary_client}),
        AddMirrorImageTask())
    engine = taskflow.engines.load(work_flow, store=store_specs)
    engine.run()
Esempio n. 4
0
    def test_graph_nested_provides(self):
        a = test_utils.ProvidesRequiresTask('a', provides=[], requires=['x'])
        b = test_utils.ProvidesRequiresTask('b', provides=['x'], requires=[])
        c = test_utils.ProvidesRequiresTask('c', provides=[], requires=[])
        inner_flo = lf.Flow("test2").add(b, c)
        flo = gf.Flow("test").add(a, inner_flo)

        g = _replicate_graph_with_names(
            compiler.PatternCompiler(flo).compile())
        self.assertEqual(7, len(g))
        self.assertItemsEqual(
            g.edges(data=True),
            [
                ('test', 'test2', {
                    'invariant': True
                }),
                ('a', 'test[$]', {
                    'invariant': True
                }),

                # The 'x' requirement is produced out of test2...
                ('test2[$]', 'a', {
                    'reasons': set(['x'])
                }),
                ('test2', 'b', {
                    'invariant': True
                }),
                ('b', 'c', {
                    'invariant': True
                }),
                ('c', 'test2[$]', {
                    'invariant': True
                }),
            ])
        self.assertItemsEqual(['test'], g.no_predecessors_iter())
        self.assertItemsEqual(['test[$]'], g.no_successors_iter())
Esempio n. 5
0
    def test_suspend_and_resume_linear_flow_on_revert(self):
        flow = lf.Flow('linear').add(utils.ProgressingTask('a'),
                                     utils.ProgressingTask('b'),
                                     utils.FailingTask('c'))
        engine = self._make_engine(flow)
        with SuspendingListener(engine,
                                task_name='b',
                                task_state=states.REVERTED) as capturer:
            engine.run()
        expected = [
            'a.t RUNNING', 'a.t SUCCESS(5)', 'b.t RUNNING', 'b.t SUCCESS(5)',
            'c.t RUNNING', 'c.t FAILURE(Failure: RuntimeError: Woot!)',
            'c.t REVERTING', 'c.t REVERTED(None)', 'b.t REVERTING',
            'b.t REVERTED(None)'
        ]
        self.assertEqual(expected, capturer.values)

        # pretend we are resuming
        engine2 = self._make_engine(flow, engine.storage._flowdetail)
        with utils.CaptureListener(engine2, capture_flow=False) as capturer2:
            self.assertRaisesRegexp(RuntimeError, '^Woot', engine2.run)
        self.assertEqual(states.REVERTED, engine2.storage.get_flow_state())
        expected = ['a.t REVERTING', 'a.t REVERTED(None)']
        self.assertEqual(expected, capturer2.values)
Esempio n. 6
0
 def test_parallel_revert_exception_do_not_revert_linear_tasks(self):
     flow = lf.Flow('l-root').add(
         utils.SaveOrderTask(self.values, name='task1'),
         utils.SaveOrderTask(self.values, name='task2'),
         uf.Flow('p-inner').add(
             utils.SaveOrderTask(self.values, name='task3', sleep=0.1),
             utils.NastyTask(), utils.FailingTask(sleep=0.01)))
     engine = self._make_engine(flow)
     # Depending on when (and if failing task) is executed the exception
     # raised could be either woot or gotcha since the above unordered
     # sub-flow does not guarantee that the ordering will be maintained,
     # even with sleeping.
     was_nasty = False
     try:
         engine.run()
         self.assertTrue(False)
     except RuntimeError as e:
         self.assertRegexpMatches(str(e), '^Gotcha|^Woot')
         if 'Gotcha!' in str(e):
             was_nasty = True
     result = set(self.values)
     possible_result = set(['task1', 'task2', 'task3', 'task3 reverted(5)'])
     if not was_nasty:
         possible_result.update(['task1 reverted(5)', 'task2 reverted(5)'])
     self.assertIsSubset(possible_result, result)
     # If the nasty task killed reverting, then task1 and task2 should not
     # have reverted, but if the failing task stopped execution then task1
     # and task2 should have reverted.
     if was_nasty:
         must_not_have = ['task1 reverted(5)', 'task2 reverted(5)']
         for r in must_not_have:
             self.assertNotIn(r, result)
     else:
         must_have = ['task1 reverted(5)', 'task2 reverted(5)']
         for r in must_have:
             self.assertIn(r, result)
Esempio n. 7
0
    def test_linear_nested(self):
        a, b, c, d = test_utils.make_many(4)
        flo = lf.Flow("test")
        flo.add(a, b)
        inner_flo = uf.Flow("test2")
        inner_flo.add(c, d)
        flo.add(inner_flo)

        g = _replicate_graph_with_names(
            compiler.PatternCompiler(flo).compile())
        self.assertEqual(8, len(g))

        sub_g = g.subgraph(['a', 'b'])
        self.assertFalse(sub_g.has_edge('b', 'a'))
        self.assertTrue(sub_g.has_edge('a', 'b'))
        self.assertEqual({'invariant': True}, sub_g.get_edge_data("a", "b"))

        sub_g = g.subgraph(['c', 'd'])
        self.assertEqual(0, sub_g.number_of_edges())

        # This ensures that c and d do not start executing until after b.
        self.assertTrue(g.has_edge('b', 'test2'))
        self.assertTrue(g.has_edge('test2', 'c'))
        self.assertTrue(g.has_edge('test2', 'd'))
Esempio n. 8
0
def create_migration_flow(obj, config, migration):
    """
    Creates migration flow for object ``obj`` based on configuration ``config``
    migration ``migration``.
    :param obj: model.Model instance
    :param config: configuration
    :param migration: migration (part of configuration)
    :return: migration flow for an object
    """

    if obj.find_link(config.clouds[migration.destination]) is not None:
        return None
    cls = obj.get_class()
    flow_factories = migration.migration_flow_factories
    if cls not in flow_factories:
        raise RuntimeError('Failed to find migration flow factory for ' +
                           repr(cls))
    else:
        flow = linear_flow.Flow('top_level_' + taskflow_utils.object_name(obj),
                                retry=retry.AlwaysRevert())
        factory = flow_factories[cls]()
        migration_tasks = factory.create_flow(config, migration, obj)
        flow.add(InjectSourceObject(obj), *migration_tasks)
        return flow
Esempio n. 9
0
        def _setup_flow_and_run():
            # Define the flow
            flow = tf_lf.Flow("destroy")

            # Power Off the LPAR. If its disks are about to be deleted, issue a
            # hard shutdown.
            flow.add(tf_vm.PowerOff(self.adapter, instance,
                                    force_immediate=destroy_disks))
            # TODO(thorst, efried) Add unplug vifs task
            # TODO(thorst, efried) Add config drive tasks
            # TODO(thorst, efried) Add volume disconnect tasks

            # Detach the disk storage adapters
            flow.add(tf_stg.DetachDisk(self.disk_dvr, instance))

            # Delete the storage disks
            if destroy_disks:
                flow.add(tf_stg.DeleteDisk(self.disk_dvr))

            # TODO(thorst, efried) Add LPAR id based scsi map clean up task
            flow.add(tf_vm.Delete(self.adapter, instance))

            # Build the engine & run!
            tf_base.run(flow, instance=instance)
Esempio n. 10
0
    def get_delete_listener_internal_flow(self, listener_name):
        """Create a flow to delete a listener and l7policies internally

           (will skip deletion on the amp and marking LB active)

        :returns: The flow for deleting a listener
        """
        delete_listener_flow = linear_flow.Flow(constants.DELETE_LISTENER_FLOW)
        # Should cascade delete all L7 policies
        delete_listener_flow.add(
            network_tasks.UpdateVIP(name='delete_update_vip_' + listener_name,
                                    requires=constants.LOADBALANCER))
        delete_listener_flow.add(
            database_tasks.DeleteListenerInDB(
                name='delete_listener_in_db_' + listener_name,
                requires=constants.LISTENER,
                rebind={constants.LISTENER: listener_name}))
        delete_listener_flow.add(
            database_tasks.DecrementListenerQuota(
                name='decrement_listener_quota_' + listener_name,
                requires=constants.LISTENER,
                rebind={constants.LISTENER: listener_name}))

        return delete_listener_flow
Esempio n. 11
0
    def test_linear_nested(self):
        a, b, c, d = test_utils.make_many(4)
        flo = lf.Flow("test")
        flo.add(a, b)
        inner_flo = uf.Flow("test2")
        inner_flo.add(c, d)
        flo.add(inner_flo)

        compilation = compiler.PatternCompiler(flo).compile()
        graph = compilation.execution_graph
        self.assertEqual(6, len(graph))

        lb = graph.subgraph([a, b])
        self.assertFalse(lb.has_edge(b, a))
        self.assertTrue(lb.has_edge(a, b))
        self.assertEqual({'invariant': True}, graph.get_edge_data(a, b))

        ub = graph.subgraph([c, d])
        self.assertEqual(0, ub.number_of_edges())

        # This ensures that c and d do not start executing until after b.
        self.assertTrue(graph.has_edge(b, inner_flo))
        self.assertTrue(graph.has_edge(inner_flo, c))
        self.assertTrue(graph.has_edge(inner_flo, d))
Esempio n. 12
0
    def get_update_listener_flow(self):
        """Create a flow to update a listener

        :returns: The flow for updating a listener
        """
        update_listener_flow = linear_flow.Flow(constants.UPDATE_LISTENER_FLOW)
        update_listener_flow.add(
            lifecycle_tasks.ListenersToErrorOnRevertTask(
                requires=[constants.LOADBALANCER, constants.LISTENERS]))
        update_listener_flow.add(
            model_tasks.UpdateAttributes(
                rebind={constants.OBJECT: constants.LISTENER},
                requires=[constants.UPDATE_DICT]))
        update_listener_flow.add(
            amphora_driver_tasks.ListenersUpdate(
                requires=[constants.LOADBALANCER, constants.LISTENERS]))
        update_listener_flow.add(
            database_tasks.UpdateListenerInDB(
                requires=[constants.LISTENER, constants.UPDATE_DICT]))
        update_listener_flow.add(
            database_tasks.MarkLBAndListenersActiveInDB(
                requires=[constants.LOADBALANCER, constants.LISTENERS]))

        return update_listener_flow
    def get_create_listener_flow(self):
        """Create a flow to create a listener

        :returns: The flow for creating a listener
        """
        create_listener_flow = linear_flow.Flow(constants.CREATE_LISTENER_FLOW)
        create_listener_flow.add(
            lifecycle_tasks.ListenersToErrorOnRevertTask(
                requires=[constants.LOADBALANCER, constants.LISTENERS]))
        create_listener_flow.add(
            a10_database_tasks.GetVThunderByLoadBalancer(
                requires=constants.LOADBALANCER,
                provides=a10constants.VTHUNDER))
        create_listener_flow.add(
            virtual_port_tasks.ListenersCreate(requires=[
                constants.LOADBALANCER, constants.LISTENERS,
                a10constants.VTHUNDER
            ]))
        create_listener_flow.add(
            a10_network_tasks.UpdateVIP(requires=constants.LOADBALANCER))
        create_listener_flow.add(
            database_tasks.MarkLBAndListenersActiveInDB(
                requires=[constants.LOADBALANCER, constants.LISTENERS]))
        return create_listener_flow
Esempio n. 14
0
    def get_update_l7rule_flow(self):
        """Create a flow to update an L7 rule

        :returns: The flow for updating an L7 rule
        """
        update_l7rule_flow = linear_flow.Flow(constants.UPDATE_L7RULE_FLOW)
        update_l7rule_flow.add(lifecycle_tasks.L7RuleToErrorOnRevertTask(
            requires=[constants.L7RULE,
                      constants.LISTENERS,
                      constants.LOADBALANCER]))
        update_l7rule_flow.add(database_tasks.MarkL7RulePendingUpdateInDB(
            requires=constants.L7RULE))
        update_l7rule_flow.add(amphora_driver_tasks.ListenersUpdate(
            requires=[constants.LOADBALANCER, constants.LISTENERS]))
        update_l7rule_flow.add(database_tasks.UpdateL7RuleInDB(
            requires=[constants.L7RULE, constants.UPDATE_DICT]))
        update_l7rule_flow.add(database_tasks.MarkL7RuleActiveInDB(
            requires=constants.L7RULE))
        update_l7rule_flow.add(database_tasks.MarkL7PolicyActiveInDB(
            requires=constants.L7POLICY))
        update_l7rule_flow.add(database_tasks.MarkLBAndListenersActiveInDB(
            requires=[constants.LOADBALANCER, constants.LISTENERS]))

        return update_l7rule_flow
Esempio n. 15
0
    def setUp(self):
        super(GetVmInterfacesTests, self).setUp()

        flavor_name = "m1.tiny"

        self.nova_client = client.nova_client()
        self.neutron_client = client.neutron_client()

        self.valid_vm_name = str(uuid.uuid4())

        image_list = self.nova_client.images.list()
        for image in image_list:
            if (image.name.startswith("cirros")) and (
                    image.name.endswith("kernel")):
                break
        valid_image = image

        valid_flavor = self.nova_client.flavors.find(name=flavor_name)

        network_name = "private"
        networks = self.neutron_client.list_networks(name=network_name)
        network = networks['networks'][0]
        self.valid_net_id = network['id']
        nics = [{'net-id': self.valid_net_id}]

        new_vm = self.nova_client.servers.create(name=self.valid_vm_name,
                                                 image=valid_image,
                                                 flavor=valid_flavor,
                                                 nics=nics)
        self.valid_vm_id = new_vm.id

        self.flow = linear_flow.Flow("create vm flow")
        self.flow.add(
            list_vm_interfaces.ListVmInterfaces(os_client=self.nova_client,
                                                requires=('server', ),
                                                provides=('interface_list')))
Esempio n. 16
0
def get_flow(context, db_api, driver_api, request_spec=None,
             filter_properties=None,
             volume=None, snapshot_id=None, image_id=None):

    """Constructs and returns the scheduler entrypoint flow.

    This flow will do the following:

    1. Inject keys & values for dependent tasks.
    2. Extract a scheduler specification from the provided inputs.
    3. Use provided scheduler driver to select host and pass volume creation
       request further.
    """
    create_what = {
        'context': context,
        'raw_request_spec': request_spec,
        'filter_properties': filter_properties,
        'volume': volume,
        'snapshot_id': snapshot_id,
        'image_id': image_id,
    }

    flow_name = ACTION.replace(":", "_") + "_scheduler"
    scheduler_flow = linear_flow.Flow(flow_name)

    # This will extract and clean the spec from the starting values.
    scheduler_flow.add(ExtractSchedulerSpecTask(
        db_api,
        rebind={'request_spec': 'raw_request_spec'}))

    # This will activate the desired scheduler driver (and handle any
    # driver related failures appropriately).
    scheduler_flow.add(ScheduleCreateVolumeTask(db_api, driver_api))

    # Now load (but do not run) the flow using the provided initial data.
    return taskflow.engines.load(scheduler_flow, store=create_what)
Esempio n. 17
0
 def test_default_times_retry(self):
     flow = lf.Flow('flow-1',
                    retry.Times(3, 'r1')).add(utils.ProgressingTask('t1'),
                                              utils.FailingTask('t2'))
     engine = self._make_engine(flow)
     with utils.CaptureListener(engine) as capturer:
         self.assertRaisesRegexp(RuntimeError, '^Woot', engine.run)
     expected = [
         'flow-1.f RUNNING', 'r1.r RUNNING', 'r1.r SUCCESS(1)',
         't1.t RUNNING', 't1.t SUCCESS(5)', 't2.t RUNNING',
         't2.t FAILURE(Failure: RuntimeError: Woot!)', 't2.t REVERTING',
         't2.t REVERTED', 't1.t REVERTING', 't1.t REVERTED',
         'r1.r RETRYING', 't1.t PENDING', 't2.t PENDING', 'r1.r RUNNING',
         'r1.r SUCCESS(2)', 't1.t RUNNING', 't1.t SUCCESS(5)',
         't2.t RUNNING', 't2.t FAILURE(Failure: RuntimeError: Woot!)',
         't2.t REVERTING', 't2.t REVERTED', 't1.t REVERTING',
         't1.t REVERTED', 'r1.r RETRYING', 't1.t PENDING', 't2.t PENDING',
         'r1.r RUNNING', 'r1.r SUCCESS(3)', 't1.t RUNNING',
         't1.t SUCCESS(5)', 't2.t RUNNING',
         't2.t FAILURE(Failure: RuntimeError: Woot!)', 't2.t REVERTING',
         't2.t REVERTED', 't1.t REVERTING', 't1.t REVERTED',
         'r1.r REVERTING', 'r1.r REVERTED', 'flow-1.f REVERTED'
     ]
     self.assertEqual(expected, capturer.values)
Esempio n. 18
0
 def runner(my_name, poison):
     while not poison.isSet():
         my_jobs = []
         job_board. await (0.05)
         job_search_from = None
         for j in job_board.posted_after(job_search_from):
             if j.owner is not None:
                 continue
             try:
                 j.claim(my_name)
                 my_jobs.append(j)
             except exc.UnclaimableJobException:
                 pass
         if not my_jobs:
             # No jobs were claimed, lets not search the past again
             # then, since *likely* those jobs will remain claimed...
             job_search_from = datetime.utcnow()
         if my_jobs and poison.isSet():
             # Oh crap, we need to unclaim and repost the jobs.
             for j in my_jobs:
                 j.unclaim()
                 job_board.repost(j)
         else:
             # Set all jobs to pending before starting them
             for j in my_jobs:
                 j.state = states.PENDING
             for j in my_jobs:
                 # Create some dummy flow for the job
                 wf = lw.Flow('dummy')
                 for _i in range(0, 5):
                     wf.add(utils.null_functor)
                 j.associate(wf)
                 j.state = states.RUNNING
                 wf.run(j.context)
                 j.state = states.SUCCESS
                 j.erase()
Esempio n. 19
0
    def get_create_health_monitor_flow(self):
        """Create a flow to create a health monitor

        :returns: The flow for creating a health monitor
        """
        create_hm_flow = linear_flow.Flow(constants.CREATE_HEALTH_MONITOR_FLOW)
        create_hm_flow.add(lifecycle_tasks.HealthMonitorToErrorOnRevertTask(
            requires=[constants.HEALTH_MON,
                      constants.LISTENERS,
                      constants.LOADBALANCER]))
        create_hm_flow.add(database_tasks.MarkHealthMonitorPendingCreateInDB(
            requires=constants.HEALTH_MON))
        create_hm_flow.add(a10_database_tasks.GetVThunderByLoadBalancer(
            requires=constants.LOADBALANCER,
            provides=a10constants.VTHUNDER))
        create_hm_flow.add(a10_database_tasks.GetFlavorData(
            rebind={a10constants.LB_RESOURCE: constants.LOADBALANCER},
            provides=constants.FLAVOR))
        create_hm_flow.add(health_monitor_tasks.CreateAndAssociateHealthMonitor(
            requires=[constants.LISTENERS, constants.HEALTH_MON, a10constants.VTHUNDER,
                      constants.FLAVOR]))
        create_hm_flow.add(database_tasks.MarkHealthMonitorActiveInDB(
            requires=constants.HEALTH_MON))
        create_hm_flow.add(database_tasks.MarkPoolActiveInDB(
            requires=constants.POOL))
        create_hm_flow.add(database_tasks.MarkLBAndListenersActiveInDB(
            requires=[constants.LOADBALANCER, constants.LISTENERS]))
        create_hm_flow.add(vthunder_tasks.WriteMemory(
            name=a10constants.WRITE_MEM_FOR_LOCAL_PARTITION,
            requires=(a10constants.VTHUNDER)))
        create_hm_flow.add(vthunder_tasks.WriteMemory(
            name=a10constants.WRITE_MEM_FOR_SHARED_PARTITION,
            requires=(a10constants.VTHUNDER, a10constants.WRITE_MEM_SHARED_PART)))
        create_hm_flow.add(a10_database_tasks.SetThunderUpdatedAt(
            requires=(a10constants.VTHUNDER)))
        return create_hm_flow
Esempio n. 20
0
def delete_service():
    flow = linear_flow.Flow('Deleting poppy-service').add(
        linear_flow.Flow('Update Oslo Context').add(
            common.ContextUpdateTask()),
        linear_flow.Flow('Delete Provider Services').add(
            delete_service_tasks.DeleteProviderServicesTask()),
        linear_flow.Flow(
            'Delete Service DNS Mapping flow',
            retry=retry.ParameterizedForEach(
                rebind=['time_seconds'], provides='retry_sleep_time')).add(
                    delete_service_tasks.DeleteServiceDNSMappingTask()),
        delete_service_tasks.GatherProviderDetailsTask(
            rebind=['responders', 'dns_responder']),
        linear_flow.Flow('Delete san certificates for service').add(
            delete_service_tasks.DeleteCertificatesForService()),
        linear_flow.Flow('Delete service storage operation').add(
            common.UpdateProviderDetailIfNotEmptyTask(
                rebind=['provider_details_dict']),
            delete_service_tasks.DeleteStorageServiceTask()))
    return flow
Esempio n. 21
0
import sys

logging.basicConfig(level=logging.ERROR)

my_dir_path = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(os.path.join(my_dir_path, os.pardir),
                                os.pardir))

from taskflow.patterns import linear_flow as lf


def call_jim(context):
    print("Calling jim.")
    print("Context = %s" % (context))


def call_joe(context):
    print("Calling joe.")
    print("Context = %s" % (context))


flow = lf.Flow("call-them")
flow.add(call_jim)
flow.add(call_joe)

context = {
    "joe_number": 444,
    "jim_number": 555,
}
flow.run(context)
Esempio n. 22
0
        print("Done!")
        print("All data processed and sent to %s" % (sent_to))


class DummyUser(object):
    def __init__(self, user, id_):
        self.user = user
        self.id = id_


# Resources (db handles and similar) of course can *not* be persisted so we
# need to make sure that we pass this resource fetcher to the tasks constructor
# so that the tasks have access to any needed resources (the resources are
# lazily loaded so that they are only created when they are used).
resources = ResourceFetcher()
flow = lf.Flow("initialize-me")

# 1. First we extract the api request into a usable format.
# 2. Then we go ahead and make a database entry for our request.
flow.add(ExtractInputRequest(resources), MakeDBEntry(resources))

# 3. Then we activate our payment method and finally declare success.
sub_flow = gf.Flow("after-initialize")
sub_flow.add(ActivateDriver(resources), DeclareSuccess())
flow.add(sub_flow)

# Initially populate the storage with the following request object,
# prepopulating this allows the tasks that dependent on the 'request' variable
# to start processing (in this case this is the ExtractInputRequest task).
store = {
    'request': DummyUser(user="******", id_="1.35"),
Esempio n. 23
0
 def test_revert_exception_is_reraised(self):
     flow = lf.Flow('revert-1').add(NastyTask(), FailingTask(name='fail'))
     engine = self._make_engine(flow)
     with self.assertRaisesRegexp(RuntimeError, '^Gotcha'):
         engine.run()
Esempio n. 24
0
 def test_sequential_flow_nested_blocks(self):
     flow = lf.Flow('nested-1').add(
         TestTask(self.values, 'task1'),
         lf.Flow('inner-1').add(TestTask(self.values, 'task2')))
     self._make_engine(flow).run()
     self.assertEquals(self.values, ['task1', 'task2'])
Esempio n. 25
0
 def test_sequential_flow_two_tasks(self):
     flow = lf.Flow('flow-2').add(TestTask(self.values, name='task1'),
                                  TestTask(self.values, name='task2'))
     self._make_engine(flow).run()
     self.assertEquals(self.values, ['task1', 'task2'])
Esempio n. 26
0
    def execute(self, z):
        return z * self._multiplier


# Note here that the ordering is established so that the correct sequences
# of operations occurs where the adding and multiplying is done according
# to the expected and typical mathematical model. A graph_flow could also be
# used here to automatically ensure the correct ordering.
flow = lf.Flow('root').add(
    # Provide the initial values for other tasks to depend on.
    #
    # x = 2, y = 3, d = 5
    Provider("provide-adder", 2, 3, 5, provides=('x', 'y', 'd')),
    # z = x+y = 5
    Adder("add-1", provides='z'),
    # a = z+d = 10
    Adder("add-2", provides='a', rebind=['z', 'd']),
    # Calculate 'r = a*3 = 30'
    #
    # Note here that the 'z' argument of the execute() function will not be
    # bound to the 'z' variable provided from the above 'provider' object but
    # instead the 'z' argument will be taken from the 'a' variable provided
    # by the second add-2 listed above.
    Multiplier("multi", 3, provides='r', rebind={'z': 'a'}))

# The result here will be all results (from all tasks) which is stored in an
# in-memory storage location that backs this engine since it is not configured
# with persistance storage.
results = taskflow.engines.run(flow)
print(results)
Esempio n. 27
0
def revert_tt():
    flow = linear_flow.Flow('f1')
    flow.add(RevertingTask())
    engines.run(flow)
Esempio n. 28
0
def check_cert_status_and_update_flow():
    flow = linear_flow.Flow('Update Akamai Property').add(
        check_cert_status_and_update_tasks.CheckCertStatusTask(),
        check_cert_status_and_update_tasks.UpdateCertStatusTask())
    return flow
Esempio n. 29
0
    def get_write_memory_flow(self, vthunder, store, deleteCompute):
        """Perform write memory for thunder """
        sf_name = 'a10-house-keeper' + '-' + a10constants.WRITE_MEMORY_THUNDER_FLOW

        write_memory_flow = linear_flow.Flow(sf_name)
        vthunder_store = {}
        vthunder_store[vthunder.vthunder_id] = vthunder
        write_memory_flow.add(
            a10_database_tasks.GetActiveLoadBalancersByThunder(
                requires=a10constants.VTHUNDER,
                rebind={a10constants.VTHUNDER: vthunder.vthunder_id},
                name='{flow}-{id}'.format(
                    id=vthunder.vthunder_id,
                    flow='GetActiveLoadBalancersByThunder'),
                provides=a10constants.LOADBALANCERS_LIST))
        write_memory_flow.add(
            a10_database_tasks.MarkLoadBalancersPendingUpdateInDB(
                name='{flow}-{id}'.format(
                    id=vthunder.vthunder_id,
                    flow='MarkLoadBalancersPendingUpdateInDB'),
                requires=a10constants.LOADBALANCERS_LIST))
        if not deleteCompute:
            write_memory_flow.add(
                vthunder_tasks.WriteMemoryHouseKeeper(
                    requires=(a10constants.VTHUNDER,
                              a10constants.LOADBALANCERS_LIST,
                              a10constants.WRITE_MEM_SHARED_PART),
                    rebind={a10constants.VTHUNDER: vthunder.vthunder_id},
                    name='{flow}-{partition}-{id}'.format(
                        id=vthunder.vthunder_id,
                        flow='WriteMemory-' +
                        a10constants.WRITE_MEMORY_THUNDER_FLOW,
                        partition=a10constants.WRITE_MEM_FOR_SHARED_PARTITION),
                    provides=a10constants.WRITE_MEM_SHARED))
            write_memory_flow.add(
                vthunder_tasks.WriteMemoryHouseKeeper(
                    requires=(a10constants.VTHUNDER,
                              a10constants.LOADBALANCERS_LIST),
                    rebind={a10constants.VTHUNDER: vthunder.vthunder_id},
                    name='{flow}-{partition}-{id}'.format(
                        id=vthunder.vthunder_id,
                        flow='WriteMemory-' +
                        a10constants.WRITE_MEMORY_THUNDER_FLOW,
                        partition=a10constants.WRITE_MEM_FOR_LOCAL_PARTITION),
                    provides=a10constants.WRITE_MEM_PRIVATE))
            write_memory_flow.add(
                a10_database_tasks.SetThunderLastWriteMem(
                    requires=(a10constants.VTHUNDER,
                              a10constants.WRITE_MEM_SHARED,
                              a10constants.WRITE_MEM_PRIVATE),
                    rebind={a10constants.VTHUNDER: vthunder.vthunder_id},
                    name='{flow}-{id}'.format(id=vthunder.vthunder_id,
                                              flow='SetThunderLastWriteMem')))
        else:
            write_memory_flow.add(
                a10_database_tasks.SetThunderLastWriteMem(
                    requires=(a10constants.VTHUNDER),
                    inject={
                        a10constants.WRITE_MEM_SHARED: True,
                        a10constants.WRITE_MEM_PRIVATE: True
                    },
                    rebind={a10constants.VTHUNDER: vthunder.vthunder_id},
                    name='{flow}-{id}'.format(id=vthunder.vthunder_id,
                                              flow='SetThunderLastWriteMem')))
        write_memory_flow.add(
            a10_database_tasks.MarkLoadBalancersActiveInDB(
                name='{flow}-{id}'.format(id=vthunder.vthunder_id,
                                          flow='MarkLoadBalancersActiveInDB'),
                requires=a10constants.LOADBALANCERS_LIST))

        store.update(vthunder_store)
        return write_memory_flow
Esempio n. 30
0
    def _get_vthunder_for_amphora_subflow(self, prefix, role):
        """Subflow to create lb in existing vThunder."""

        sf_name = prefix + '-' + a10constants.LB_TO_VTHUNDER_SUBFLOW
        vthunder_for_amphora_subflow = linear_flow.Flow(sf_name)
        vthunder_for_amphora_subflow.add(
            database_tasks.CreateAmphoraInDB(name=sf_name + '-' +
                                             constants.CREATE_AMPHORA_INDB,
                                             provides=constants.AMPHORA_ID))
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.ValidateComputeForProject(
                name=sf_name + '-' + a10constants.VALIDATE_COMPUTE_FOR_PROJECT,
                requires=constants.LOADBALANCER,
                inject={"role": role},
                provides=constants.COMPUTE_ID))
        vthunder_for_amphora_subflow.add(
            database_tasks.UpdateAmphoraComputeId(
                name=sf_name + '-' + constants.UPDATE_AMPHORA_COMPUTEID,
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        vthunder_for_amphora_subflow.add(
            compute_tasks.ComputeActiveWait(
                name=sf_name + '-' + constants.COMPUTE_WAIT,
                requires=(constants.COMPUTE_ID, constants.AMPHORA_ID),
                provides=constants.COMPUTE_OBJ))
        vthunder_for_amphora_subflow.add(
            database_tasks.UpdateAmphoraInfo(
                name=sf_name + '-' + constants.UPDATE_AMPHORA_INFO,
                requires=(constants.AMPHORA_ID, constants.COMPUTE_OBJ),
                provides=constants.AMPHORA))
        # create vThunder entry in custom DB
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.CreateVThunderEntry(
                name=sf_name + '-' + a10constants.CREATE_VTHUNDER_ENTRY,
                requires=(constants.AMPHORA, constants.LOADBALANCER),
                inject={
                    "role": role,
                    "status": constants.PENDING_CREATE
                }))
        # Get VThunder details from database
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.GetVThunderByLoadBalancer(
                name=sf_name + '-' + a10constants.VTHUNDER_BY_LB,
                requires=constants.LOADBALANCER,
                provides=a10constants.VTHUNDER))
        vthunder_for_amphora_subflow.add(
            database_tasks.ReloadLoadBalancer(
                name=sf_name + '-' + constants.RELOADLOAD_BALANCER,
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))
        vthunder_for_amphora_subflow.add(
            a10_network_tasks.GetLBResourceSubnet(
                name=sf_name + '-' + a10constants.GET_LB_RESOURCE,
                rebind={a10constants.LB_RESOURCE: constants.LOADBALANCER},
                provides=constants.SUBNET))
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.GetChildProjectsOfParentPartition(
                name=sf_name + '-' + a10constants.GET_PROJECT_COUNT,
                requires=[a10constants.VTHUNDER],
                rebind={a10constants.LB_RESOURCE: constants.LOADBALANCER},
                provides=a10constants.PARTITION_PROJECT_LIST))
        vthunder_for_amphora_subflow.add(
            a10_database_tasks.CountLoadbalancersInProjectBySubnet(
                name=sf_name + '-' + a10constants.GET_LB_COUNT_SUBNET,
                requires=[
                    constants.SUBNET, a10constants.PARTITION_PROJECT_LIST
                ],
                provides=a10constants.LB_COUNT_SUBNET))
        vthunder_for_amphora_subflow.add(
            a10_network_tasks.AllocateVIP(
                name=sf_name + '-' + a10constants.ALLOCATE_VIP,
                requires=[
                    constants.LOADBALANCER, a10constants.LB_COUNT_SUBNET
                ],
                provides=constants.VIP))
        vthunder_for_amphora_subflow.add(
            database_tasks.UpdateVIPAfterAllocation(
                name=sf_name + '-' + a10constants.UPDATE_VIP_AFTER_ALLOCATION,
                requires=(constants.LOADBALANCER_ID, constants.VIP),
                provides=constants.LOADBALANCER))
        vthunder_for_amphora_subflow.add(
            database_tasks.MarkAmphoraAllocatedInDB(
                name=sf_name + '-' + constants.MARK_AMPHORA_ALLOCATED_INDB,
                requires=(constants.AMPHORA, constants.LOADBALANCER_ID)))
        vthunder_for_amphora_subflow.add(
            database_tasks.ReloadAmphora(name=sf_name + '-' +
                                         constants.RELOAD_AMPHORA,
                                         requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))
        vthunder_for_amphora_subflow.add(
            vthunder_tasks.AllowL2DSR(
                name=sf_name + '-' + a10constants.ALLOW_L2DSR,
                requires=(constants.SUBNET, constants.AMPHORA)))
        if role == constants.ROLE_MASTER:
            vthunder_for_amphora_subflow.add(
                database_tasks.MarkAmphoraMasterInDB(
                    name=sf_name + '-' + constants.MARK_AMP_MASTER_INDB,
                    requires=constants.AMPHORA))
        elif role == constants.ROLE_BACKUP:
            vthunder_for_amphora_subflow.add(
                database_tasks.MarkAmphoraBackupInDB(
                    name=sf_name + '-' + constants.MARK_AMP_BACKUP_INDB,
                    requires=constants.AMPHORA))
        elif role == constants.ROLE_STANDALONE:
            vthunder_for_amphora_subflow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=sf_name + '-' + constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))
        return vthunder_for_amphora_subflow