def test_get_blueprint_deployments(self):
        now = str(datetime.now())
        blueprint = models.BlueprintState(id='blueprint-id',
                                          created_at=now,
                                          updated_at=now,
                                          plan={'name': 'my-bp'},
                                          source='bp-source')
        storage_manager.instance().put_blueprint('blueprint-id', blueprint)

        deployment1 = models.Deployment(id='dep-1',
                                        created_at=now,
                                        updated_at=now,
                                        blueprint_id='blueprint-id',
                                        plan={'name': 'my-bp'},
                                        permalink=None,
                                        workflows={},
                                        inputs={},
                                        policy_types={},
                                        policy_triggers={},
                                        groups={},
                                        outputs={})
        storage_manager.instance().put_deployment('dep-1', deployment1)

        deployment2 = models.Deployment(id='dep-2',
                                        created_at=now,
                                        updated_at=now,
                                        blueprint_id='blueprint-id',
                                        plan={'name': 'my-bp'},
                                        permalink=None,
                                        workflows={},
                                        inputs={},
                                        policy_types={},
                                        policy_triggers={},
                                        groups={},
                                        outputs={})
        storage_manager.instance().put_deployment('dep-2', deployment2)

        deployment3 = models.Deployment(id='dep-3',
                                        created_at=now,
                                        updated_at=now,
                                        blueprint_id='another-blueprint-id',
                                        plan={'name': 'my-bp'},
                                        permalink=None,
                                        workflows={},
                                        inputs={},
                                        policy_types={},
                                        policy_triggers={},
                                        groups={},
                                        outputs={})
        storage_manager.instance().put_deployment('dep-3', deployment3)

        blueprint_deployments = storage_manager.instance()\
            .get_blueprint_deployments(
                'blueprint-id')

        self.assertEquals(2, len(blueprint_deployments))
        self.assertEquals(deployment1.__dict__,
                          blueprint_deployments[0].__dict__)
        self.assertEquals(deployment2.__dict__,
                          blueprint_deployments[1].__dict__)
 def put_node_instance(self, instance_id, deployment_id,
                       runtime_properties):
     from manager_rest.models import DeploymentNodeInstance
     node = DeploymentNodeInstance(id=instance_id,
                                   node_id=None,
                                   deployment_id=deployment_id,
                                   runtime_properties=runtime_properties,
                                   state=None,
                                   version=None,
                                   relationships=None,
                                   host_id=None)
     sm.instance().put_node_instance(node)
 def put_node_instance(self,
                       instance_id,
                       deployment_id,
                       runtime_properties):
     from manager_rest.models import DeploymentNodeInstance
     node = DeploymentNodeInstance(id=instance_id,
                                   node_id=None,
                                   deployment_id=deployment_id,
                                   runtime_properties=runtime_properties,
                                   state=None,
                                   version=None,
                                   relationships=None,
                                   host_id=None)
     sm.instance().put_node_instance(node)
    def test_fields_query(self):
        now = str(datetime.now())
        blueprint = models.BlueprintState(id='blueprint-id',
                                          created_at=now,
                                          updated_at=now,
                                          plan={'name': 'my-bp'},
                                          source='bp-source')
        storage_manager.instance().put_blueprint('blueprint-id', blueprint)

        blueprint_restored = \
            storage_manager.instance().get_blueprint('blueprint-id',
                                                     {'id', 'created_at'})
        self.assertEquals('blueprint-id', blueprint_restored.id)
        self.assertEquals(now, blueprint_restored.created_at)
        self.assertEquals(None, blueprint_restored.updated_at)
        self.assertEquals(None, blueprint_restored.plan)
 def test_patch_node_conflict(self):
     from manager_rest import manager_exceptions
     prev_update_node_func = sm.instance().update_node_instance
     try:
         def conflict_update_node_func(node):
             raise manager_exceptions.ConflictError()
         sm.instance().update_node_instance = conflict_update_node_func
         self.put_node_instance(
             instance_id='1234',
             deployment_id='111',
             runtime_properties={
                 'key': 'value'
             }
         )
         response = self.patch('/node-instances/1234',
                               {'runtime_properties': {'key': 'new_value'},
                                'version': 2})
         self.assertEqual(409, response.status_code)
     finally:
         sm.instance().update_node_instance = prev_update_node_func
Exemple #6
0
    def test_patch_node_conflict(self):
        from manager_rest import manager_exceptions
        prev_update_node_func = sm.instance().update_node_instance
        try:

            def conflict_update_node_func(node):
                raise manager_exceptions.ConflictError()

            sm.instance().update_node_instance = conflict_update_node_func
            self.put_node_instance(instance_id='1234',
                                   deployment_id='111',
                                   runtime_properties={'key': 'value'})
            response = self.patch('/node-instances/1234', {
                'runtime_properties': {
                    'key': 'new_value'
                },
                'version': 2
            })
            self.assertEqual(409, response.status_code)
        finally:
            sm.instance().update_node_instance = prev_update_node_func
    def test_list_system_executions(self):
        (blueprint_id, deployment_id, blueprint_response,
         deployment_response) = self.put_deployment(self.DEPLOYMENT_ID)

        # manually pushing a system workflow execution to the storage
        system_wf_execution_id = 'mock_execution_id'
        system_wf_id = 'mock_system_workflow_id'
        system_wf_execution = models.Execution(
            id=system_wf_execution_id,
            status=models.Execution.TERMINATED,
            deployment_id=deployment_id,
            workflow_id=system_wf_id,
            blueprint_id=blueprint_id,
            created_at=str(datetime.now()),
            error='',
            parameters=dict(),
            is_system_workflow=True)
        storage_manager.instance().put_execution(system_wf_execution_id,
                                                 system_wf_execution)

        # listing only non-system workflow executions
        executions = self.client.executions.list(deployment_id=deployment_id)

        # expecting 1 execution (create_deployment_environment)
        self.assertEquals(1, len(executions))
        self.assertEquals('create_deployment_environment',
                          executions[0]['workflow_id'])

        # listing all executions
        executions = self.client.executions.list(deployment_id=deployment_id,
                                                 include_system_workflows=True)
        executions.sort(key=lambda e: e.created_at)

        # expecting 2 executions
        self.assertEquals(2, len(executions))
        self.assertEquals('create_deployment_environment',
                          executions[0]['workflow_id'])
        self.assertEquals(system_wf_id, executions[1]['workflow_id'])

        return deployment_id, system_wf_id
 def test_store_load_delete_blueprint(self):
     now = str(datetime.now())
     blueprint = models.BlueprintState(id='blueprint-id',
                                       created_at=now,
                                       updated_at=now,
                                       plan={'name': 'my-bp'},
                                       source='bp-source')
     storage_manager.instance().put_blueprint('blueprint-id', blueprint)
     blueprint_from_list = storage_manager.instance().blueprints_list()[0]
     blueprint_restored = \
         storage_manager.instance().get_blueprint('blueprint-id')
     bp_from_delete = storage_manager.instance().delete_blueprint(
         'blueprint-id')
     self.assertEquals(blueprint.__dict__, blueprint_from_list.__dict__)
     self.assertEquals(blueprint.__dict__, blueprint_restored.__dict__)
     # in bp returned from delete operation only 'id' is guaranteed to
     # return
     self.assertEquals(blueprint.id, bp_from_delete.id)
     self.assertEquals(0,
                       len(storage_manager.instance().blueprints_list()))
from datetime import datetime
import uuid
import sys

from manager_rest.storage_manager import instance
from manager_rest import models

execution_id = str(uuid.uuid4())

blueprint_id = sys.argv[1]
deployment_id = sys.argv[2]
workflow_id = sys.argv[3]

new_execution = models.Execution(
    id=execution_id,
    status=models.Execution.PENDING,
    created_at=str(datetime.now()),
    blueprint_id=blueprint_id,
    workflow_id=workflow_id,
    deployment_id=deployment_id,
    error='',
    parameters=[]
)
sm = instance()
sm.put_execution(new_execution.id, new_execution)

print new_execution.id