Exemplo n.º 1
0
    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_workers_installation_complete, 30,
                   deployment_id=deployment_id)
        execution = self.client.deployments.execute(
            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
Exemplo n.º 2
0
    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)

        from plugins.testmockoperations.tasks import \
            get_mock_operation_invocations

        invocations = send_task(get_mock_operation_invocations).get(timeout=10)
        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_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_workers_installation_complete, 30,
                   deployment_id=deployment_id)
        execution = self.client.deployments.execute(deployment_id,
                                                    'execute_operation')
        wait_for_execution_to_end(execution)

        from plugins.testmockoperations.tasks import \
            get_mock_operation_invocations

        invocations = send_task(get_mock_operation_invocations).get(timeout=10)
        self.assertEqual(1, len(invocations))
        self.assertDictEqual(invocations[0], {'test_key': 'test_value'})
Exemplo n.º 4
0
    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_workers_installation_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.deployments.execute(
            deployment_id, 'another_execute_operation',
            parameters=execution_parameters,
            allow_custom_parameters=True)
        wait_for_execution_to_end(execution)

        from plugins.testmockoperations.tasks import \
            get_mock_operation_invocations

        invocations = send_task(get_mock_operation_invocations).get(timeout=10)
        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)
Exemplo n.º 5
0
    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)

        from plugins.testmockoperations.tasks import \
            get_mock_operation_invocations

        invocations = send_task(get_mock_operation_invocations).get(timeout=10)
        self.assertEqual(1, len(invocations))
        self.assertDictEqual(invocations[0], {'test_key': 'test_value'})
Exemplo n.º 6
0
    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
    def test_dsl_with_agent_plugin_and_manager_plugin(self):
        # start deployment workers
        deployment_worker = TestEnvironment.create_celery_worker(
            DEPLOYMENT_ID)
        self.addCleanup(deployment_worker.close)
        deployment_worker.start()

        deployment_workflows_worker = TestEnvironment.create_celery_worker(
            DEPLOYMENT_WORKFLOWS_QUEUE)
        self.addCleanup(deployment_workflows_worker.close)
        deployment_workflows_worker.start()

        # upload blueprint
        blueprint_id = self.client.blueprints.upload(
            resource('dsl/with_plugin.yaml'), BLUEPRINT_ID).id

        # create deployment
        self.client.deployments.create(blueprint_id, DEPLOYMENT_ID)

        # waiting for the deployment workers installation to complete
        do_retries(verify_workers_installation_complete, 15,
                   deployment_id=DEPLOYMENT_ID)

        # test plugin installed in deployment operations worker
        deployment_plugins = self._get(get_installed_plugins,
                                       queue=DEPLOYMENT_ID)

        self.assertIn('test_management_plugin', deployment_plugins)

        # test plugin installed in deployment workflows worker
        workflow_plugin = self._get(get_installed_plugins,
                                    queue=DEPLOYMENT_WORKFLOWS_QUEUE)
        self.assertIn('workflows', workflow_plugin)

        # test valid deployment worker installation order
        state = self._get(get_worker_state, queue=MANAGEMENT,
                          args=[DEPLOYMENT_ID])
        self.assertEquals(state, AFTER_INSTALL_STAGES)

        # test valid workflows worker installation order
        state = self._get(get_worker_state, queue=MANAGEMENT,
                          args=[DEPLOYMENT_WORKFLOWS_QUEUE])
        self.assertEquals(state, AFTER_INSTALL_STAGES)

        # test riemann core started successfully
        self.assertTrue(self._is_riemann_core_up())

        # start agent worker
        node_id = self._list_nodes()[0].id
        agent_worker = TestEnvironment.create_celery_worker(node_id)
        self.addCleanup(agent_worker.close)
        agent_worker.start()

        # install
        self._execute('install')

        # test plugins installed in agent worker
        agent_plugins = self._get(get_installed_plugins, queue=node_id)
        self.assertIn('test_plugin', agent_plugins)

        # test valid agent worker installation order
        state = self._get(get_worker_state, queue=DEPLOYMENT_ID,
                          args=[node_id])
        self.assertEquals(state, AFTER_INSTALL_STAGES)

        # uninstall
        self._execute('uninstall')

        # delete deployment
        self.client.deployments.delete(DEPLOYMENT_ID)

        # test valid deployment worker un-installation order
        state = self._get(get_worker_state, queue=MANAGEMENT,
                          args=[DEPLOYMENT_ID])
        self.assertEquals(state, AFTER_UNINSTALL_STAGES)

        # test valid workflows worker un-installation order
        state = self._get(get_worker_state, queue=MANAGEMENT,
                          args=[DEPLOYMENT_WORKFLOWS_QUEUE])
        self.assertEquals(state, AFTER_UNINSTALL_STAGES)

        # test valid agent worker un-installation order
        state = self._get(get_worker_state, queue=DEPLOYMENT_ID,
                          args=[node_id])
        self.assertEquals(state, AFTER_UNINSTALL_STAGES)

        # validate riemann core is no longer running
        self.assertFalse(self._is_riemann_core_up())
    def test_dsl_with_agent_plugin_and_manager_plugin(self):
        # start deployment workers
        deployment_worker = TestEnvironment.create_celery_worker(DEPLOYMENT_ID)
        self.addCleanup(deployment_worker.close)
        deployment_worker.start()

        deployment_workflows_worker = TestEnvironment.create_celery_worker(
            DEPLOYMENT_WORKFLOWS_QUEUE)
        self.addCleanup(deployment_workflows_worker.close)
        deployment_workflows_worker.start()

        # upload blueprint
        blueprint_id = self.client.blueprints.upload(
            resource('dsl/with_plugin.yaml'), BLUEPRINT_ID).id

        # create deployment
        self.client.deployments.create(blueprint_id, DEPLOYMENT_ID)

        # waiting for the deployment environment creation to complete
        do_retries(verify_deployment_environment_creation_complete,
                   15,
                   deployment_id=DEPLOYMENT_ID)

        # test plugin installed in deployment operations worker
        deployment_plugins = self._get(get_installed_plugins,
                                       queue=DEPLOYMENT_ID)

        self.assertIn('test_management', deployment_plugins)

        # test plugin installed in deployment workflows worker
        workflow_plugin = self._get(get_installed_plugins,
                                    queue=DEPLOYMENT_WORKFLOWS_QUEUE)
        self.assertIn('default_workflows', workflow_plugin)

        # test valid deployment worker installation order
        state = self._get(get_worker_state,
                          queue=MANAGEMENT,
                          args=[DEPLOYMENT_ID])
        self.assertEquals(state, AFTER_INSTALL_STAGES)

        # test valid workflows worker installation order
        state = self._get(get_worker_state,
                          queue=MANAGEMENT,
                          args=[DEPLOYMENT_WORKFLOWS_QUEUE])
        self.assertEquals(state, AFTER_INSTALL_STAGES)

        # test riemann core started successfully
        self.assertTrue(self._is_riemann_core_up())

        # start agent worker
        node_id = self._list_nodes()[0].id
        agent_worker = TestEnvironment.create_celery_worker(node_id)
        self.addCleanup(agent_worker.close)
        agent_worker.start()

        # install
        self._execute('install')

        # test plugins installed in agent worker
        agent_plugins = self._get(get_installed_plugins, queue=node_id)
        self.assertIn('test', agent_plugins)

        # test valid agent worker installation order
        state = self._get(get_worker_state,
                          queue=DEPLOYMENT_ID,
                          args=[node_id])
        self.assertEquals(state, AFTER_INSTALL_STAGES)

        # uninstall
        self._execute('uninstall')

        # delete deployment
        self.client.deployments.delete(DEPLOYMENT_ID)

        # test valid deployment worker un-installation order
        state = self._get(get_worker_state,
                          queue=MANAGEMENT,
                          args=[DEPLOYMENT_ID])
        self.assertEquals(state, AFTER_UNINSTALL_STAGES)

        # test valid workflows worker un-installation order
        state = self._get(get_worker_state,
                          queue=MANAGEMENT,
                          args=[DEPLOYMENT_WORKFLOWS_QUEUE])
        self.assertEquals(state, AFTER_UNINSTALL_STAGES)

        # test valid agent worker un-installation order
        state = self._get(get_worker_state,
                          queue=DEPLOYMENT_ID,
                          args=[node_id])
        self.assertEquals(state, AFTER_UNINSTALL_STAGES)

        # validate riemann core is no longer running
        self.assertFalse(self._is_riemann_core_up())