def test_delete_botched_deployment(self): from testenv import testenv_instance storage_file_path = os.path.join(testenv_instance.plugins_storage_dir, 'agent.json') dsl_path = resource('dsl/basic.yaml') _id = uuid.uuid1() blueprint_id = 'blueprint_{0}'.format(_id) deployment_id = 'deployment_{0}'.format(_id) data = {deployment_id: {'raise_exception_on_delete': True}} with open(storage_file_path, 'w') as f: json.dump(data, f) self.client.blueprints.upload(dsl_path, blueprint_id) self.client.deployments.create(blueprint_id, deployment_id) execution = \ self.client.executions.list(deployment_id, include_system_workflows=True)[0] wait_for_execution_to_end(execution) self.client.deployments.delete(deployment_id) try: self.client.deployments.get(deployment_id) self.fail("Expected deployment to be deleted") except CloudifyClientError as e: self.assertEquals(404, e.status_code)
def _execute_and_cancel_execution(self, workflow_id, force=False, wait_for_termination=True, is_wait_for_asleep_node=True): dsl_path = resource('dsl/sleep_workflows.yaml') _id = uuid.uuid1() blueprint_id = 'blueprint_{0}'.format(_id) deployment_id = 'deployment_{0}'.format(_id) self.client.blueprints.upload(dsl_path, blueprint_id) self.client.deployments.create(blueprint_id, deployment_id) do_retries(verify_deployment_environment_creation_complete, 30, deployment_id=deployment_id) execution = self.client.executions.start( deployment_id, workflow_id) node_inst_id = self.client.node_instances.list(deployment_id)[0].id if is_wait_for_asleep_node: for retry in range(30): if self.client.node_instances.get( node_inst_id).state == 'asleep': break time.sleep(1) else: raise RuntimeError("Execution was expected to go" " into 'sleeping' status") execution = self.client.executions.cancel(execution.id, force) expected_status = Execution.FORCE_CANCELLING if force else \ Execution.CANCELLING self.assertEquals(expected_status, execution.status) if wait_for_termination: wait_for_execution_to_end(execution) execution = self.client.executions.get(execution.id) return execution, deployment_id
def test_delete_botched_deployment(self): from testenv import testenv_instance storage_file_path = os.path.join( testenv_instance.plugins_storage_dir, 'agent.json' ) dsl_path = resource('dsl/basic.yaml') _id = uuid.uuid1() blueprint_id = 'blueprint_{0}'.format(_id) deployment_id = 'deployment_{0}'.format(_id) data = { deployment_id: {'raise_exception_on_delete': True} } with open(storage_file_path, 'w') as f: json.dump(data, f) self.client.blueprints.upload(dsl_path, blueprint_id) self.client.deployments.create(blueprint_id, deployment_id) execution = \ self.client.executions.list(deployment_id, include_system_workflows=True)[0] wait_for_execution_to_end(execution) self.client.deployments.delete(deployment_id) try: self.client.deployments.get(deployment_id) self.fail("Expected deployment to be deleted") except CloudifyClientError as e: self.assertEquals(404, e.status_code)
def test_cancel_execution_and_then_force_cancel(self): execution, deployment_id = self._execute_and_cancel_execution( 'sleep', False, False) # cancel didn't work (unsupported) - use force-cancel instead execution = self.client.executions.cancel(execution.id, True) self.assertEquals(Execution.FORCE_CANCELLING, execution.status) wait_for_execution_to_end(execution) execution = self.client.executions.get(execution.id) self._assert_execution_cancelled(execution, deployment_id)
def _test1(self): num_deps = 5 for i in range(num_deps): deploy(resource('dsl/basic.yaml'), deployment_id='d{0}'.format(i)) while True: for workflow in ['uninstall', 'install']: executions = [] for i in range(num_deps): execution = execute_workflow( workflow, deployment_id='d{0}'.format(i), wait_for_execution=False) executions.append(execution) for execution in executions: wait_for_execution_to_end(execution)
def test_workflow_parameters_pass_from_blueprint(self): dsl_path = resource('dsl/workflow_parameters.yaml') _id = uuid.uuid1() blueprint_id = 'blueprint_{0}'.format(_id) deployment_id = 'deployment_{0}'.format(_id) self.client.blueprints.upload(dsl_path, blueprint_id) self.client.deployments.create(blueprint_id, deployment_id) do_retries(verify_deployment_environment_creation_complete, 30, deployment_id=deployment_id) execution = self.client.executions.start(deployment_id, 'custom_execute_operation') wait_for_execution_to_end(execution) invocations = self.get_plugin_data( plugin_name='testmockoperations', deployment_id=deployment_id)['mock_operation_invocation'] self.assertEqual(1, len(invocations)) self.assertDictEqual(invocations[0], {'test_key': 'test_value'})
def test_workflow_parameters_pass_from_blueprint(self): dsl_path = resource('dsl/workflow_parameters.yaml') _id = uuid.uuid1() blueprint_id = 'blueprint_{0}'.format(_id) deployment_id = 'deployment_{0}'.format(_id) self.client.blueprints.upload(dsl_path, blueprint_id) self.client.deployments.create(blueprint_id, deployment_id) do_retries(verify_deployment_environment_creation_complete, 30, deployment_id=deployment_id) execution = self.client.executions.start(deployment_id, 'execute_operation') wait_for_execution_to_end(execution) invocations = self.get_plugin_data( plugin_name='testmockoperations', deployment_id=deployment_id )['mock_operation_invocation'] self.assertEqual(1, len(invocations)) self.assertDictEqual(invocations[0], {'test_key': 'test_value'})
def test_execution_parameters(self): dsl_path = resource('dsl/workflow_parameters.yaml') _id = uuid.uuid1() blueprint_id = 'blueprint_{0}'.format(_id) deployment_id = 'deployment_{0}'.format(_id) self.client.blueprints.upload(dsl_path, blueprint_id) self.client.deployments.create(blueprint_id, deployment_id) do_retries(verify_deployment_environment_creation_complete, 60, deployment_id=deployment_id) execution_parameters = { 'operation': 'test_interface.operation', 'properties': { 'key': 'different-key', 'value': 'different-value' }, 'custom-parameter': "doesn't matter" } execution = self.client.executions.start( deployment_id, 'another_execute_operation', parameters=execution_parameters, allow_custom_parameters=True) wait_for_execution_to_end(execution) invocations = self.get_plugin_data( plugin_name='testmockoperations', deployment_id=deployment_id)['mock_operation_invocation'] self.assertEqual(1, len(invocations)) self.assertDictEqual(invocations[0], {'different-key': 'different-value'}) # checking for execution parameters - expecting there to be a merge # with overrides with workflow parameters. expected_params = { 'node_id': 'test_node', 'operation': 'test_interface.operation', 'properties': { 'key': 'different-key', 'value': 'different-value' }, 'custom-parameter': "doesn't matter" } self.assertEqual(expected_params, execution.parameters)
def test_execution_parameters(self): dsl_path = resource('dsl/workflow_parameters.yaml') _id = uuid.uuid1() blueprint_id = 'blueprint_{0}'.format(_id) deployment_id = 'deployment_{0}'.format(_id) self.client.blueprints.upload(dsl_path, blueprint_id) self.client.deployments.create(blueprint_id, deployment_id) do_retries(verify_deployment_environment_creation_complete, 30, deployment_id=deployment_id) execution_parameters = { 'operation': 'test_interface.operation', 'properties': { 'key': 'different-key', 'value': 'different-value' }, 'custom-parameter': "doesn't matter" } execution = self.client.executions.start( deployment_id, 'another_execute_operation', parameters=execution_parameters, allow_custom_parameters=True) wait_for_execution_to_end(execution) invocations = self.get_plugin_data( plugin_name='testmockoperations', deployment_id=deployment_id )['mock_operation_invocation'] self.assertEqual(1, len(invocations)) self.assertDictEqual(invocations[0], {'different-key': 'different-value'}) # checking for execution parameters - expecting there to be a merge # with overrides with workflow parameters. expected_params = { 'node_id': 'test_node', 'operation': 'test_interface.operation', 'properties': { 'key': 'different-key', 'value': 'different-value' }, 'custom-parameter': "doesn't matter" } self.assertEqual(expected_params, execution.parameters)
def _wait_for_stop_dep_env_execution_to_end(self, deployment_id, timeout_seconds=240): executions = self.client.executions.list(deployment_id=deployment_id, include_system_workflows=True) running_stop_executions = [e for e in executions if e.workflow_id == '_stop_deployment_environment' and e.status not in Execution.END_STATES] if not running_stop_executions: return if len(running_stop_executions) > 1: raise RuntimeError('There is more than one running ' '"_stop_deployment_environment" execution: {0}' .format(running_stop_executions)) execution = running_stop_executions[0] return wait_for_execution_to_end(execution, timeout_seconds)