コード例 #1
0
 def test_execute_operation_failure(self):
     deployment_id = str(uuid.uuid4())
     dsl_path = get_resource("dsl/basic.yaml")
     try:
         deploy_application(dsl_path, deployment_id=deployment_id)
         self.fail('expected exception')
     except Exception as e:
         if e.message:
             self.logger.info(e.message)
         pass
コード例 #2
0
    def test_deploy_with_operation_executor_override(self):
        dsl_path = get_resource('dsl/operation_executor_override.yaml')
        deployment, _ = deploy_application(dsl_path)
        deployment_nodes = self.client.node_instances.list(
            deployment_id=deployment.id
        )

        webserver_nodes = filter(lambda node: 'host' not in node.node_id,
                                 deployment_nodes)
        self.assertEquals(1, len(webserver_nodes))
        webserver_node = webserver_nodes[0]
        start_invocation = self.get_plugin_data(
            plugin_name='target_aware_mock_plugin',
            deployment_id=deployment.id
        )[webserver_node.id]['start']

        expected_start_invocation = {'target': 'cloudify.management'}
        self.assertEqual(expected_start_invocation, start_invocation)

        agent_data = self.get_plugin_data(
            plugin_name='agent',
            deployment_id=deployment.id
        )

        # target_aware_mock_plugin should have been installed
        # on the management worker as well because 'start'
        # overrides the executor (with a local task)
        self.assertEqual(agent_data['local']['target_aware_mock_plugin'],
                         ['installed'])
        undeploy_application(deployment_id=deployment.id)
コード例 #3
0
    def test_basic_sanity(self):
        self.configure()
        dsl_path = get_resource('dsl/basic.yaml')
        blueprint_id = self.id()
        deployment, _ = deploy_application(
            dsl_path,
            blueprint_id=blueprint_id,
            timeout_seconds=30)

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        machines = self.get_plugin_data(
            plugin_name='cloudmock',
            deployment_id=deployment.id
        )['machines']
        self.assertEquals(1, len(machines))

        outputs = self.client.deployments.outputs.get(deployment.id).outputs
        # ip runtime property is not set in this case
        self.assertEquals(outputs['ip_address'], '')

        self._wait_for_stop_dep_env_execution_to_end(deployment.id)
        undeploy_application(deployment.id, delete_deployment=True)
        deployments = self.client.deployments.list()
        self.assertEqual(0, len(deployments))
コード例 #4
0
    def test_basic_sanity(self):
        # despite the module/class name, this test tests the opposite of the
        # default mode, i.e. if transient workers mode is enabled by default,
        # this will test sanity in non transient workers mode, and vice versa
        self.configure(transient_mode_enabled=not IS_TRANSIENT_WORKERS_MODE)
        dsl_path = get_resource('dsl/basic.yaml')
        blueprint_id = self.id()
        deployment, _ = deploy_application(
            dsl_path,
            blueprint_id=blueprint_id,
            timeout_seconds=30)

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        machines = self.get_plugin_data(
            plugin_name='cloudmock',
            deployment_id=deployment.id
        )['machines']
        self.assertEquals(1, len(machines))

        outputs = self.client.deployments.outputs.get(deployment.id).outputs
        # ip runtime property is not set in this case
        self.assertEquals(outputs['ip_address'], '')

        undeploy_application(deployment.id, is_delete_deployment=True)
        deployments = self.client.deployments.list()
        self.assertEqual(0, len(deployments))
コード例 #5
0
    def test_get_blueprint(self):
        dsl_path = get_resource("dsl/basic.yaml")
        blueprint_id = str(uuid.uuid4())
        deployment, _ = deploy_application(dsl_path, blueprint_id=blueprint_id)

        self.assertEqual(blueprint_id, deployment.blueprint_id)
        blueprint = self.client.blueprints.get(blueprint_id)
        self.assertEqual(blueprint_id, blueprint.id)
        self.assertTrue(len(blueprint['plan']) > 0)
コード例 #6
0
 def test_start_monitor_node_operation(self):
     dsl_path = get_resource("dsl/hardcoded_operation_properties.yaml")
     deployment, _ = deploy_application(dsl_path)
     invocations = self.get_plugin_data(
         plugin_name='testmockoperations',
         deployment_id=deployment.id
     )['monitoring_operations_invocation']
     self.assertEqual(1, len(invocations))
     invocation = invocations[0]
     self.assertEqual('start_monitor', invocation['operation'])
コード例 #7
0
    def test_riemann_core_not_started_without_policies(self):
        """A riemann core isn't started if there's no policies defined
        """
        dsl_path = get_resource('dsl/without_policies.yaml')
        deployment, _ = deploy_application(dsl_path)

        self.assertFalse(self._is_riemann_core_up(deployment.id))

        undeploy_application(deployment.id, is_delete_deployment=True)

        self.assertFalse(self._is_riemann_core_up(deployment.id))
コード例 #8
0
    def test_riemann_core_started_with_policies(self):
        """A riemann core is started if the blueprint defines policies
        """
        dsl_path = get_resource('dsl/with_policies1.yaml')
        deployment, _ = deploy_application(dsl_path)

        self.assertTrue(self._is_riemann_core_up(deployment.id))

        undeploy_application(deployment.id, is_delete_deployment=True)

        self.assertFalse(self._is_riemann_core_up(deployment.id))
コード例 #9
0
    def test_deploy_with_agent_worker(self):
        dsl_path = get_resource('dsl/with_agent_worker.yaml')
        deployment, _ = deploy_application(dsl_path)
        deployment_nodes = self.client.node_instances.list(
            deployment_id=deployment.id
        )

        webserver_nodes = filter(lambda node: 'host' not in node.node_id,
                                 deployment_nodes)
        self.assertEquals(1, len(webserver_nodes))
        webserver_node = webserver_nodes[0]
        invocations = self.get_plugin_data(
            plugin_name='mock_agent_plugin',
            deployment_id=deployment.id
        )[webserver_node.id]

        agent_data = self.get_plugin_data(
            plugin_name='agent',
            deployment_id=deployment.id
        )

        # agent on host should have been started and restarted
        self.assertEqual(
            agent_data[webserver_node.host_id]['states'],
            ['created', 'configured', 'started'])

        self.assertEqual(
            agent_data[
                webserver_node.host_id
            ]['mock_agent_plugin'],
            ['installed'])

        expected_invocations = ['create', 'start']
        self.assertListEqual(invocations, expected_invocations)

        undeploy_application(deployment_id=deployment.id)
        invocations = self.get_plugin_data(
            plugin_name='mock_agent_plugin',
            deployment_id=deployment.id
        )[webserver_node.id]

        expected_invocations = ['create', 'start', 'stop', 'delete']
        self.assertListEqual(invocations, expected_invocations)

        # agent on host should have also
        # been stopped and uninstalled
        agent_data = self.get_plugin_data(
            plugin_name='agent',
            deployment_id=deployment.id
        )
        self.assertEqual(
            agent_data[webserver_node.host_id]['states'],
            ['created', 'configured', 'started',
             'stopped', 'deleted'])
コード例 #10
0
 def test_get_attribute(self):
     # assertion happens in operation get_attribute.tasks.assertion
     dsl_path = get_resource('dsl/get_attributes.yaml')
     deployment, _ = deploy_application(dsl_path)
     data = self.get_plugin_data(plugin_name='get_attribute',
                                 deployment_id=deployment.id)
     invocations = data['invocations']
     self.assertEqual(2, len([
         i for i in invocations
         if i == context.RELATIONSHIP_INSTANCE]))
     self.assertEqual(1, len([
         i for i in invocations
         if i == context.NODE_INSTANCE]))
コード例 #11
0
    def test_dependencies_order_with_two_nodes(self):
        dsl_path = get_resource("dsl/dependencies_order_with_two_nodes.yaml")
        blueprint_id = self.id()
        deployment, _ = deploy_application(dsl_path, blueprint_id=blueprint_id)

        self.assertEquals(blueprint_id, deployment.blueprint_id)

        states = self.get_plugin_data(
            plugin_name='testmockoperations',
            deployment_id=deployment.id
        )['state']
        self.assertEquals(2, len(states))
        self.assertTrue('host_node' in states[0]['id'])
        self.assertTrue('db_node' in states[1]['id'])
コード例 #12
0
 def test_inject_properties_to_operation(self):
     dsl_path = get_resource("dsl/hardcoded_operation_properties.yaml")
     deployment, _ = deploy_application(dsl_path)
     states = self.get_plugin_data(
         plugin_name='testmockoperations',
         deployment_id=deployment.id
     )['state']
     invocations = self.get_plugin_data(
         plugin_name='testmockoperations',
         deployment_id=deployment.id
     )['mock_operation_invocation']
     self.assertEqual(1, len(invocations))
     invocation = invocations[0]
     self.assertEqual('mockpropvalue', invocation['mockprop'])
     self.assertEqual(states[0]['id'], invocation['id'])
コード例 #13
0
    def test_system_workflows_execution(self):
        self.configure()
        dsl_path = get_resource('dsl/basic.yaml')
        bp_and_dep_id = self.id()
        deployment, _ = deploy_application(
            dsl_path,
            blueprint_id=bp_and_dep_id,
            deployment_id=bp_and_dep_id,
            timeout_seconds=30)

        executions = self.client.executions.list(include_system_workflows=True)
        executions.sort(key=lambda e: e.created_at)

        # expecting 4 executions: deployment environment creation,
        # deployment environment start, install workflow, and
        # deployment environment stop
        self.assertEquals(4, len(executions))
        self.assertEquals('create_deployment_environment',
                          executions[0].workflow_id)
        self.assertEquals('_start_deployment_environment',
                          executions[1].workflow_id)
        self.assertEquals('install',
                          executions[2].workflow_id)
        self.assertEquals('_stop_deployment_environment',
                          executions[3].workflow_id)
        self.assertEqual([executions[1], executions[3]],
                         [e for e in executions if e.is_system_workflow])

        self._wait_for_stop_dep_env_execution_to_end(deployment.id)
        undeploy_application(bp_and_dep_id)

        executions = self.client.executions.list(include_system_workflows=True)
        executions.sort(key=lambda e: e.created_at)

        # expecting 7 executions, the last 3 being deployment environment
        # start, uninstall workflow, and deployment environment stop
        self.assertEquals(7, len(executions))
        self.assertEquals('_start_deployment_environment',
                          executions[4].workflow_id)
        self.assertEquals('uninstall',
                          executions[5].workflow_id)
        self.assertEquals('_stop_deployment_environment',
                          executions[6].workflow_id)
        self.assertEqual([executions[1], executions[3], executions[4],
                          executions[6]],
                         [e for e in executions if e.is_system_workflow])
コード例 #14
0
 def test_cloudify_runtime_properties_injection(self):
     dsl_path = get_resource("dsl/dependencies_order_with_two_nodes.yaml")
     deployment, _ = deploy_application(dsl_path)
     states = self.get_plugin_data(
         plugin_name='testmockoperations',
         deployment_id=deployment.id
     )['state']
     node_runtime_props = None
     for k, v in states[1]['capabilities'].iteritems():
         if 'host_node' in k:
             node_runtime_props = v
             break
     self.assertEquals('value1', node_runtime_props['property1'])
     self.assertEquals(1,
                       len(node_runtime_props),
                       msg='Expected 2 but contains: {0}'.format(
                           node_runtime_props))
コード例 #15
0
    def test_search(self):
        dsl_path = get_resource("dsl/basic.yaml")
        blueprint_id = 'my_new_blueprint'
        deployment, _ = deploy_application(dsl_path, blueprint_id=blueprint_id)

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        machines = self.get_plugin_data(
            plugin_name='cloudmock',
            deployment_id=deployment.id
        )['machines']
        self.assertEquals(1, len(machines))
        result = self.client.search.run_query({})
        hits = map(lambda x: x['_source'], result['hits']['hits'])

        expected_num_of_hits = 7
        self.assertEquals(expected_num_of_hits, len(hits))
コード例 #16
0
    def test_execute_operation(self):
        dsl_path = get_resource('dsl/basic.yaml')
        blueprint_id = self.id()
        deployment, _ = deploy_application(
            dsl_path,
            blueprint_id=blueprint_id,
            timeout_seconds=15
        )

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        machines = self.get_plugin_data(
            plugin_name='cloudmock',
            deployment_id=deployment.id
        )['machines']
        self.assertEquals(1, len(machines))

        outputs = self.client.deployments.outputs.get(deployment.id).outputs
        self.assertEquals(outputs['ip_address'], '')
コード例 #17
0
    def test_system_workflows_execution(self):
        self.configure()
        dsl_path = get_resource('dsl/basic.yaml')
        bp_and_dep_id = self.id()
        deployment, _ = deploy_application(dsl_path,
                                           blueprint_id=bp_and_dep_id,
                                           deployment_id=bp_and_dep_id,
                                           timeout_seconds=30)

        executions = self.client.executions.list(include_system_workflows=True)
        executions.sort(key=lambda e: e.created_at)

        # expecting 4 executions: deployment environment creation,
        # deployment environment start, install workflow, and
        # deployment environment stop
        self.assertEquals(4, len(executions))
        self.assertEquals('create_deployment_environment',
                          executions[0].workflow_id)
        self.assertEquals('_start_deployment_environment',
                          executions[1].workflow_id)
        self.assertEquals('install', executions[2].workflow_id)
        self.assertEquals('_stop_deployment_environment',
                          executions[3].workflow_id)
        self.assertEqual([executions[1], executions[3]],
                         [e for e in executions if e.is_system_workflow])

        undeploy_application(bp_and_dep_id)

        executions = self.client.executions.list(include_system_workflows=True)
        executions.sort(key=lambda e: e.created_at)

        # expecting 7 executions, the last 3 being deployment environment
        # start, uninstall workflow, and deployment environment stop
        self.assertEquals(7, len(executions))
        self.assertEquals('_start_deployment_environment',
                          executions[4].workflow_id)
        self.assertEquals('uninstall', executions[5].workflow_id)
        self.assertEquals('_stop_deployment_environment',
                          executions[6].workflow_id)
        self.assertEqual(
            [executions[1], executions[3], executions[4], executions[6]],
            [e for e in executions if e.is_system_workflow])
コード例 #18
0
    def test_plugin_get_resource(self):
        dsl_path = get_resource("dsl/get_resource_in_plugin.yaml")
        deployment, _ = deploy_application(dsl_path)
        invocations = self.get_plugin_data(
            plugin_name='testmockoperations',
            deployment_id=deployment.id
        )['get_resource_operation_invocation']
        self.assertEquals(1, len(invocations))
        invocation = invocations[0]
        with open(get_resource("dsl/basic.yaml")) as f:
            basic_data = f.read()

        # checking the resources are the correct data
        self.assertEquals(basic_data, invocation['res1_data'])
        self.assertEquals(basic_data, invocation['res2_data'])

        # checking the custom filepath provided is indeed where the second
        # resource was saved
        self.assertEquals(invocation['custom_filepath'],
                          invocation['res2_path'])
コード例 #19
0
    def test_deployment_creation_workflow(self):

        dsl_path = get_resource(
            'dsl/basic_with_deployment_plugin_and_workflow_plugin.yaml'
        )
        deployment, _ = deploy_application(dsl_path)

        from testenv import testenv_instance
        deployment_dir_path = os.path.join(
                testenv_instance.test_working_dir, 'cloudify.management',
                'work', 'deployments', deployment.id)

        def _is_riemann_core_up():
            try:
                with open(os.path.join(
                        self.riemann_workdir, deployment.id, 'ok')) as f:
                    return f.read().strip() == 'ok'
            except IOError, e:
                if e.errno == errno.ENOENT:
                    return False
                raise
コード例 #20
0
    def test_deployment_creation_workflow(self):
        dsl_path = get_resource(
            'dsl/basic_with_deployment_plugin_and_workflow_plugin.yaml'
        )
        deployment, _ = deploy_application(dsl_path)

        from testenv import testenv_instance
        deployment_dir_path = os.path.join(
                testenv_instance.test_working_dir, 'cloudify.management',
                'work', 'deployments', deployment.id)

        self.assertTrue(os.path.isdir(deployment_dir_path))

        # assert plugin installer installed
        # the necessary plugins.
        agent_data = self.get_plugin_data(
            plugin_name='agent',
            deployment_id=deployment.id)

        # cloudmock and mock_workflows should have been installed
        # on the management worker as local tasks
        installed = ['installed']
        self.assertEqual(agent_data['local']['cloudmock'], installed)
        self.assertEqual(agent_data['local']['mock_workflows'], installed)

        undeploy_application(deployment.id, is_delete_deployment=True)

        # assert plugin installer uninstalled
        # the necessary plugins.
        agent_data = self.get_plugin_data(
            plugin_name='agent',
            deployment_id=deployment.id)

        uninstalled = ['installed', 'uninstalled']
        self.assertEqual(agent_data['local']['cloudmock'], uninstalled)
        self.assertEqual(agent_data['local']['mock_workflows'], uninstalled)

        self.assertFalse(os.path.isdir(deployment_dir_path))
コード例 #21
0
    def test_node_states(self):
        dsl_path = get_resource('dsl/node_states.yaml')
        _id = uuid.uuid1()
        blueprint_id = 'blueprint_{0}'.format(_id)
        deployment_id = 'deployment_{0}'.format(_id)
        deployment, _ = deploy_application(
            dsl_path,
            blueprint_id=blueprint_id,
            deployment_id=deployment_id)
        node_states = self.get_plugin_data(
            plugin_name='testmockoperations',
            deployment_id=deployment.id
        )['node_states']
        self.assertEquals(node_states, [
            'creating', 'configuring', 'starting'
        ])

        deployment_nodes = self.client.node_instances.list(
            deployment_id=deployment_id)
        self.assertEqual(1, len(deployment_nodes))
        node_id = deployment_nodes[0].id
        node_instance = self.client.node_instances.get(node_id)
        self.assertEqual('started', node_instance.state)
コード例 #22
0
    def test_basic_sanity(self):
        # despite the module/class name, this test tests the opposite of the
        # default mode, i.e. if transient workers mode is enabled by default,
        # this will test sanity in non transient workers mode, and vice versa
        self.configure(transient_mode_enabled=not IS_TRANSIENT_WORKERS_MODE)
        dsl_path = get_resource('dsl/basic.yaml')
        blueprint_id = self.id()
        deployment, _ = deploy_application(dsl_path,
                                           blueprint_id=blueprint_id,
                                           timeout_seconds=30)

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        machines = self.get_plugin_data(
            plugin_name='cloudmock', deployment_id=deployment.id)['machines']
        self.assertEquals(1, len(machines))

        outputs = self.client.deployments.outputs.get(deployment.id).outputs
        # ip runtime property is not set in this case
        self.assertEquals(outputs['ip_address'], '')

        undeploy_application(deployment.id, is_delete_deployment=True)
        deployments = self.client.deployments.list()
        self.assertEqual(0, len(deployments))
コード例 #23
0
 def _deploy_basic_blueprint(self):
     deploy_application(self.dsl_path,
                        blueprint_id=self.blueprint_id,
                        deployment_id=self.deployment_id)
コード例 #24
0
 def _deploy_basic_blueprint(self):
     deploy_application(self.dsl_path,
                        blueprint_id=self.blueprint_id,
                        deployment_id=self.deployment_id)
コード例 #25
0
    def test_delete_deployment(self):
        dsl_path = get_resource("dsl/basic.yaml")
        blueprint_id = self.id()
        deployment_id = str(uuid.uuid4())

        def change_execution_status(execution_id, status):
            self.client.executions.update(execution_id, status)
            updated_execution = self.client.executions.get(deployment_id)
            self.assertEqual(status, updated_execution.status)

        @contextmanager
        def client_error_check(expect_in_error_message, failer_message):
            try:
                yield
                self.fail(failer_message)
            except CloudifyClientError as exc:
                self.assertTrue(expect_in_error_message in str(exc))

        # verifying a deletion of a new deployment, i.e. one which hasn't
        # been installed yet, and therefore all its nodes are still in
        # 'uninitialized' state.
        self.client.blueprints.upload(dsl_path, blueprint_id)
        self.client.deployments.create(blueprint_id, deployment_id)
        do_retries(verify_deployment_environment_creation_complete,
                   timeout_seconds=30,
                   deployment_id=deployment_id)

        delete_deployment(deployment_id, ignore_live_nodes=False)
        self.client.blueprints.delete(blueprint_id)

        # recreating the deployment, this time actually deploying it too
        _, execution_id = deploy_application(
            dsl_path,
            blueprint_id=blueprint_id,
            deployment_id=deployment_id,
            wait_for_execution=True)

        execution = self.client.executions.get(execution_id)
        self.assertEqual(Execution.TERMINATED, execution.status)

        # verifying deployment exists
        deployment = self.client.deployments.get(deployment_id)
        self.assertEqual(deployment_id, deployment.id)

        # retrieving deployment nodes
        nodes = self.client.node_instances.list(deployment_id=deployment_id)
        self.assertTrue(len(nodes) > 0)

        # setting one node's state to 'started' (making it a 'live' node)
        # node must be read using get in order for it to have a version.
        node = self.client.node_instances.get(nodes[0].id)
        self.client.node_instances.update(
            node.id, state='started', version=node.version)

        modification = self.client.deployment_modifications.start(
            deployment_id,
            nodes={'webserver_host': {'instances': 2}})
        self.client.deployment_modifications.finish(modification.id)

        # get updated node instances list
        nodes = self.client.node_instances.list(deployment_id=deployment_id)
        self.assertTrue(len(nodes) > 0)
        nodes_ids = [_node.id for _node in nodes]

        # attempting to delete deployment - should fail because there are
        # live nodes for this deployment
        with client_error_check(
                failer_message='Deleted deployment {0} successfully even '
                               'though it should have had live nodes and the '
                               'ignore_live_nodes flag was set to False'
                               .format(deployment_id),
                expect_in_error_message='live nodes'):
            delete_deployment(deployment_id)

        # deleting deployment - this time there's no execution running,
        # and using the ignore_live_nodes parameter to force deletion
        deleted_deployment_id = delete_deployment(deployment_id, True).id
        self.assertEqual(deployment_id, deleted_deployment_id)

        # verifying deployment does no longer exist
        with client_error_check(
                failer_message="Got deployment {0} successfully even though "
                               "it wasn't expected to exist"
                               .format(deployment_id),
                expect_in_error_message='not found'):
            self.client.deployments.get(deployment_id)

        # verifying deployment's execution does no longer exist
        with client_error_check(
                failer_message='execution {0} still exists even though it '
                               'should have been deleted when its deployment '
                               'was deleted'.format(execution_id),
                expect_in_error_message='not found'):
            self.client.executions.get(execution_id)

        # verifying deployment modification no longer exists
        with client_error_check(
                failer_message='deployment modification {0} still exists even '
                               'though it should have been deleted when its '
                               'deployment was deleted',
                expect_in_error_message='not found'):
            self.client.deployment_modifications.get(modification.id)

        # verifying deployment's nodes do no longer exist
        for node_id in nodes_ids:
            with client_error_check(
                    failer_message='node {0} still exists even though it '
                                   'should have been deleted when its '
                                   'deployment was deleted'.format(node_id),
                    expect_in_error_message='not found'):
                self.client.node_instances.get(node_id)

        # trying to delete a nonexistent deployment
        with client_error_check(
                failer_message="Deleted deployment {0} successfully even "
                               "though it wasn't expected to exist"
                               .format(deployment_id),
                expect_in_error_message='not found'):
            delete_deployment(deployment_id)
コード例 #26
0
 def test_install(self):
     with self.assertRaisesRegexp(RuntimeError, self.AGENT_ALIVE_FAIL):
         deploy_application(resource("dsl/basic_start_not_exists.yaml"))