def test_one_active_update_per_dep_force_flag_real_active_executions(self): deployment_id = 'dep' self._deploy_base(deployment_id, 'no_output.yaml') response = self._update(deployment_id, 'one_output.yaml') first_update_id = response.json['id'] first_execution_id = response.json['execution_id'] # updating the execution's status to started to make the first update # really be active storage_manager._get_instance().update_execution_status( first_execution_id, models.Execution.STARTED, error='') self.client.executions.get(execution_id=first_execution_id) response = self._update(deployment_id, blueprint_name='one_output.yaml', force=True) # force flag is expected not to work because the first update is # still really running self.assertEquals(response.json['error_code'], 'conflict_error') self.assertIn('there are deployment updates still active', response.json['message']) self.assertIn('the "force" flag was used', response.json['message']) # verifying the first update wasn't set with a failed state by the # force flag call first_update = self.client.deployment_updates.get(first_update_id) self.assertEquals(STATES.EXECUTING_WORKFLOW, first_update.state)
def _modify_execution_status_in_database( self, execution, new_status): try: execution_id = execution['id'] except TypeError: execution_id = execution.id storage_manager._get_instance().update_execution_status( execution_id, new_status, error='') updated_execution = self.client.executions.get( execution_id=execution_id) self.assertEqual(new_status, updated_execution['status'])
def _modify_execution_status_in_database(self, execution, new_status): try: execution_id = execution['id'] except TypeError: execution_id = execution.id storage_manager._get_instance().update_execution_status(execution_id, new_status, error='') updated_execution = self.client.executions.get( execution_id=execution_id) self.assertEqual(new_status, updated_execution['status'])
def _start_maintenance_transition_mode(self): (blueprint_id, deployment_id, blueprint_response, deployment_response) = self.put_deployment('d1') execution = self.client.executions.start(deployment_id, 'install') execution = self.client.executions.get(execution.id) self.assertEquals('terminated', execution.status) storage_manager._get_instance().update_execution_status( execution.id, models.Execution.STARTED, error='') self.client.maintenance_mode.activate() response = self.client.maintenance_mode.status() self.assertEqual(ACTIVATING_MAINTENANCE_MODE, response.status)
def test_storage_serialization_and_response(self): now = str(datetime.now()) sm = storage_manager._get_instance() deployment_update = models.DeploymentUpdate( deployment_id='deployment-id', deployment_plan={'name': 'my-bp'}, state='staged', id='depup-id', steps=(), deployment_update_nodes=None, deployment_update_node_instances=None, deployment_update_deployment=None, modified_entity_ids=None, execution_id='execution-id', created_at=now) sm.put_deployment_update(deployment_update) depup_from_client = self.client.deployment_updates.get('depup-id') depup_response_attributes = { 'id', 'state', 'deployment_id', 'steps', 'execution_id', 'created_at' } for att in depup_response_attributes: self.assertEqual(getattr(depup_from_client, att), getattr(deployment_update, att))
def test_patch_node_conflict(self): """A conflict inside the storage manager propagates to the client.""" # patch the storage manager .update_node_instance method to throw an # error - remember to revert it after the test sm = storage_manager._get_instance() def _revert_update_node_func(sm, func): sm.update_node_instance = func def conflict_update_node_func(node): raise manager_exceptions.ConflictError() self.addCleanup(_revert_update_node_func, sm, sm.update_node_instance) sm.update_node_instance = conflict_update_node_func node_instance_id = '1234' self.put_node_instance(instance_id=node_instance_id, deployment_id='111', runtime_properties={'key': 'value'}) with self.assertRaises(CloudifyClientError) as cm: self.client.node_instances.update( node_instance_id, runtime_properties={'key': 'new_value'}, version=2) self.assertEqual(cm.exception.status_code, 409)
def test_patch_node_conflict(self): """A conflict inside the storage manager propagates to the client.""" # patch the storage manager .update_node_instance method to throw an # error - remember to revert it after the test sm = storage_manager._get_instance() def _revert_update_node_func(sm, func): sm.update_node_instance = func def conflict_update_node_func(node): raise manager_exceptions.ConflictError() self.addCleanup(_revert_update_node_func, sm, sm.update_node_instance) sm.update_node_instance = conflict_update_node_func node_instance_id = '1234' self.put_node_instance( instance_id=node_instance_id, deployment_id='111', runtime_properties={ 'key': 'value' } ) with self.assertRaises(CloudifyClientError) as cm: self.client.node_instances.update( node_instance_id, runtime_properties={'key': 'new_value'}, version=2) self.assertEqual(cm.exception.status_code, 409)
def put_node_instance(self, instance_id, deployment_id, runtime_properties=None, node_id=None): runtime_properties = runtime_properties or {} from manager_rest.models import DeploymentNodeInstance node = DeploymentNodeInstance(id=instance_id, node_id=node_id, deployment_id=deployment_id, runtime_properties=runtime_properties, state=None, version=None, relationships=None, host_id=None) storage_manager._get_instance().put_node_instance(node)
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._get_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_sort_list(self): execution1 = models.Execution( id='0', status=models.Execution.TERMINATED, deployment_id='', workflow_id='', blueprint_id='', created_at=datetime.now().isoformat(), error='', parameters=dict(), is_system_workflow=False ) execution2 = models.Execution( id='1', status=models.Execution.TERMINATED, deployment_id='', workflow_id='', blueprint_id='', created_at=datetime.now().isoformat(), error='', parameters=dict(), is_system_workflow=False ) storage_manager._get_instance().put_execution('0', execution1) storage_manager._get_instance().put_execution('1', execution2) executions = self.client.executions.list(sort='created_at') self.assertEqual(2, len(executions)) self.assertEqual('0', executions[0].id) self.assertEqual('1', executions[1].id) executions = self.client.executions.list( sort='created_at', is_descending=True) self.assertEqual(2, len(executions)) self.assertEqual('1', executions[0].id) self.assertEqual('0', executions[1].id)
def test_fields_query(self): now = str(datetime.now()) blueprint = models.BlueprintState(id='blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, source='bp-source', main_file_name='aaa') sm = storage_manager._get_instance() sm.put_blueprint('blueprint-id', blueprint) blueprint_restored = sm.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) self.assertEquals(None, blueprint_restored.main_file_name)
def test_store_load_delete_blueprint(self): now = str(datetime.now()) sm = storage_manager._get_instance() blueprint = models.BlueprintState(id='blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, source='bp-source', main_file_name='aaa') sm.put_blueprint('blueprint-id', blueprint) blueprint_from_list = sm.blueprints_list().items[0] blueprint_restored = sm.get_blueprint('blueprint-id') bp_from_delete = sm.delete_blueprint('blueprint-id') self.assertEquals(blueprint.to_dict(), blueprint_from_list.to_dict()) self.assertEquals(blueprint.to_dict(), blueprint_restored.to_dict()) # in bp returned from delete operation only 'id' is guaranteed to # return self.assertEquals(blueprint.id, bp_from_delete.id) blueprints_list = sm.blueprints_list().items self.assertEquals(0, len(blueprints_list))
def test_patch_node_conflict(self): sm = storage_manager._get_instance() from manager_rest import manager_exceptions prev_update_node_func = sm.update_node_instance try: def conflict_update_node_func(node): raise manager_exceptions.ConflictError() sm.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.update_node_instance = prev_update_node_func
def test_patch_node_conflict(self): sm = storage_manager._get_instance() from manager_rest import manager_exceptions prev_update_node_func = sm.update_node_instance try: def conflict_update_node_func(node): raise manager_exceptions.ConflictError() sm.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.update_node_instance = prev_update_node_func
def _reset_execution_status_in_db(self, execution_id): storage_manager._get_instance().update_execution_status( execution_id, models.Execution.STARTED, error='') updated_execution = self.admin_client.executions.get( execution_id=execution_id) self.assertEqual(models.Execution.STARTED, updated_execution['status'])
def _terminate_execution(self, execution_id): storage_manager._get_instance().update_execution_status( execution_id, models.Execution.TERMINATED, error='')
def test_get_blueprint_deployments(self): now = str(datetime.now()) sm = storage_manager._get_instance() blueprint = models.BlueprintState(id='blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, source='bp-source', main_file_name='aaa') sm.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={}) sm.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={}) sm.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={}) sm.put_deployment('dep-3', deployment3) blueprint_deployments = sm.get_blueprint_deployments('blueprint-id') blueprint_deployments = sm.get_blueprint_deployments( 'blueprint-id').items self.assertEquals(2, len(blueprint_deployments)) if blueprint_deployments[0].id != deployment1.id: blueprint_deployments[0], blueprint_deployments[1] =\ blueprint_deployments[1], blueprint_deployments[0] self.assertEquals(deployment1.to_dict(), blueprint_deployments[0].to_dict()) self.assertEquals(deployment2.to_dict(), blueprint_deployments[1].to_dict())
def test_get_blueprint_deployments(self): now = str(datetime.now()) sm = storage_manager._get_instance() blueprint = models.BlueprintState(id='blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, source='bp-source', main_file_name='aaa') sm.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, description=None, workflows={}, inputs={}, policy_types={}, policy_triggers={}, groups={}, scaling_groups={}, outputs={}) sm.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, description=None, workflows={}, inputs={}, policy_types={}, policy_triggers={}, groups={}, scaling_groups={}, outputs={}) sm.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'}, description=None, permalink=None, workflows={}, inputs={}, policy_types={}, policy_triggers={}, groups={}, scaling_groups={}, outputs={}) sm.put_deployment('dep-3', deployment3) blueprint_deployments = \ sm.get_blueprint_deployments('blueprint-id').items self.assertEquals(2, len(blueprint_deployments)) if blueprint_deployments[0].id != deployment1.id: blueprint_deployments[0], blueprint_deployments[1] =\ blueprint_deployments[1], blueprint_deployments[0] self.assertEquals(deployment1.to_dict(), blueprint_deployments[0].to_dict()) self.assertEquals(deployment2.to_dict(), blueprint_deployments[1].to_dict())