コード例 #1
0
 def test_execute_operation_failure(self):
     from plugins.cloudmock.tasks import set_raise_exception_on_start
     send_task(set_raise_exception_on_start).get(timeout=10)
     dsl_path = resource("dsl/basic.yaml")
     try:
         deploy(dsl_path)
         self.fail('expected exception')
     except Exception:
         pass
コード例 #2
0
 def test_execute_operation_failure(self):
     from plugins.cloudmock.tasks import set_raise_exception_on_start
     send_task(set_raise_exception_on_start).get(timeout=10)
     dsl_path = resource("dsl/basic.yaml")
     try:
         deploy(dsl_path)
         self.fail('expected exception')
     except Exception:
         pass
コード例 #3
0
 def test_inject_properties_to_operation(self):
     dsl_path = resource("dsl/hardcoded_operation_properties.yaml")
     deploy(dsl_path)
     from plugins.testmockoperations.tasks import get_state as \
         testmock_get_state
     states = send_task(testmock_get_state).get(timeout=10)
     from plugins.testmockoperations.tasks import \
         get_mock_operation_invocations as testmock_get__invocations
     invocations = send_task(testmock_get__invocations).get(timeout=10)
     self.assertEqual(1, len(invocations))
     invocation = invocations[0]
     self.assertEqual('mockpropvalue', invocation['mockprop'])
     self.assertEqual(states[0]['id'], invocation['id'])
コード例 #4
0
 def test_inject_properties_to_operation(self):
     dsl_path = resource("dsl/hardcoded_operation_properties.yaml")
     deploy(dsl_path)
     from plugins.testmockoperations.tasks import get_state as \
         testmock_get_state
     states = send_task(testmock_get_state).get(timeout=10)
     from plugins.testmockoperations.tasks import \
         get_mock_operation_invocations as testmock_get__invocations
     invocations = send_task(testmock_get__invocations).get(timeout=10)
     self.assertEqual(1, len(invocations))
     invocation = invocations[0]
     self.assertEqual('mockpropvalue', invocation['mockprop'])
     self.assertEqual(states[0]['id'], invocation['id'])
コード例 #5
0
    def test_deploy_multi_instance_application(self):
        dsl_path = resource("dsl/multi_instance.yaml")
        deploy(dsl_path)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = set(result.get(timeout=10))
        self.assertEquals(2, len(machines))

        from plugins.testmockoperations.tasks import get_state as get_state
        apps_state = send_task(get_state).get(timeout=10)
        machines_with_apps = set([])
        for app_state in apps_state:
            host_id = app_state['capabilities'].keys()[0]
            machines_with_apps.add(host_id)
        self.assertEquals(machines, machines_with_apps)
コード例 #6
0
    def wait_for_invocations(self, expected_count):
        def assertion():
            invocations = send_task(testmock_get_invocations).get(timeout=10)
            self.assertEqual(expected_count, len(invocations))

        self.do_assertions(assertion)
        return send_task(testmock_get_invocations).get(timeout=10)
コード例 #7
0
    def wait_for_invocations(self, expected_count):
        def assertion():
            invocations = send_task(testmock_get_invocations).get(timeout=10)
            self.assertEqual(expected_count, len(invocations))

        self.do_assertions(assertion)
        return send_task(testmock_get_invocations).get(timeout=10)
コード例 #8
0
    def test_deploy_multi_instance_application(self):
        dsl_path = resource("dsl/multi_instance.yaml")
        deploy(dsl_path)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = set(result.get(timeout=10))
        self.assertEquals(2, len(machines))

        from plugins.testmockoperations.tasks import get_state as get_state
        apps_state = send_task(get_state).get(timeout=10)
        machines_with_apps = set([])
        for app_state in apps_state:
            host_id = app_state['capabilities'].keys()[0]
            machines_with_apps.add(host_id)
        self.assertEquals(machines, machines_with_apps)
コード例 #9
0
 def test_operation_mapping_override(self):
     dsl_path = resource("dsl/operation_mapping.yaml")
     deployment, _ = deploy(dsl_path, 'workflow2')
     invocations = send_task(get_mock_operation_invocations).get()
     self.assertEqual(3, len(invocations))
     for invocation in invocations:
         self.assertEqual(1, len(invocation))
         self.assertEqual(invocation['test_key'], 'overridden_test_value')
コード例 #10
0
    def test_failed_uninstall_task(self):
        dsl_path = resource("dsl/basic.yaml")
        self.logger.info('** install **')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id

        send_task(cloudmock.set_raise_exception_on_stop).get(timeout=10)

        self.logger.info('** uninstall **')
        time.sleep(5)  # give elasticsearch time to update execution status..
        undeploy(deployment_id)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)

        self.assertEquals(0, len(machines))
コード例 #11
0
    def test_failed_uninstall_task(self):
        dsl_path = resource("dsl/basic.yaml")
        self.logger.info('** install **')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id

        send_task(cloudmock.set_raise_exception_on_stop).get(timeout=10)

        self.logger.info('** uninstall **')
        time.sleep(5)  # give elasticsearch time to update execution status..
        undeploy(deployment_id)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)

        self.assertEquals(0, len(machines))
コード例 #12
0
    def _assert_execution_cancelled(self, execution):
        self.assertEquals(Execution.CANCELLED, execution.status)

        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], {'before-sleep': None})
コード例 #13
0
    def _assert_execution_cancelled(self, execution):
        self.assertEquals(Execution.CANCELLED, execution.status)

        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], {'before-sleep': None})
コード例 #14
0
    def test_fail_remote_task_eventual_success(self):
        deploy(resource('dsl/workflow_api.yaml'), self._testMethodName,
               parameters={'do_get': self.do_get})

        # testing workflow remote task
        invocations = send_task(get_fail_invocations).get()
        self.assertEqual(3, len(invocations))
        for i in range(len(invocations) - 1):
            self.assertLessEqual(1, invocations[i+1] - invocations[i])
コード例 #15
0
    def test_cancel_execution_before_it_started(self):
        execution = self._execute_and_cancel_execution(
            'sleep_with_cancel_support', False, True, False)
        self.assertEquals(Execution.CANCELLED, execution.status)

        from plugins.testmockoperations.tasks import \
            get_mock_operation_invocations

        invocations = send_task(get_mock_operation_invocations).get(timeout=10)
        self.assertEqual(0, len(invocations))
コード例 #16
0
 def test_start_monitor_node_operation(self):
     dsl_path = resource("dsl/hardcoded_operation_properties.yaml")
     deploy(dsl_path)
     from plugins.testmockoperations.tasks import \
         get_monitoring_operations_invocation
     invocations = send_task(get_monitoring_operations_invocation)\
         .get(timeout=10)
     self.assertEqual(1, len(invocations))
     invocation = invocations[0]
     self.assertEqual('start_monitor', invocation['operation'])
コード例 #17
0
 def assertion():
     executions = self.client.executions.list(deployment.id)
     self.assertEqual(3, len(executions))
     invocations = send_task(testmock_get_invocations).get(timeout=10)
     self.assertEqual(2, len(invocations))
     instances = self.client.node_instances.list(deployment.id)
     self.assertEqual(1, len(instances))
     instance = instances[0]
     self.assertEqual(instance.id, invocations[0]['node_id'])
     self.assertEqual(123, invocations[1]['metric'])
コード例 #18
0
    def test_fail_remote_task_eventual_success(self):
        deploy(resource('dsl/workflow_api.yaml'),
               self._testMethodName,
               parameters={'do_get': self.do_get})

        # testing workflow remote task
        invocations = send_task(get_fail_invocations).get()
        self.assertEqual(3, len(invocations))
        for i in range(len(invocations) - 1):
            self.assertLessEqual(1, invocations[i + 1] - invocations[i])
コード例 #19
0
 def test_start_monitor_node_operation(self):
     dsl_path = resource("dsl/hardcoded_operation_properties.yaml")
     deploy(dsl_path)
     from plugins.testmockoperations.tasks import \
         get_monitoring_operations_invocation
     invocations = send_task(get_monitoring_operations_invocation)\
         .get(timeout=10)
     self.assertEqual(1, len(invocations))
     invocation = invocations[0]
     self.assertEqual('start_monitor', invocation['operation'])
コード例 #20
0
    def test_cancel_execution_before_it_started(self):
        execution = self._execute_and_cancel_execution(
            'sleep_with_cancel_support', False, True, False)
        self.assertEquals(Execution.CANCELLED, execution.status)

        from plugins.testmockoperations.tasks import \
            get_mock_operation_invocations

        invocations = send_task(get_mock_operation_invocations).get(timeout=10)
        self.assertEqual(0, len(invocations))
コード例 #21
0
    def test_uninstall_with_dependency_order(self):
        dsl_path = resource(
            "dsl/uninstall_dependencies-order-with-three-nodes.yaml")
        print('starting deploy process')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id
        print('deploy completed')
        print('starting undeploy process')
        time.sleep(5)  # give elasticsearch time to update execution status..
        undeploy(deployment_id)
        print('undeploy completed')
        # Checking that uninstall wasn't called on the contained node
        from plugins.testmockoperations.tasks import \
            get_unreachable_call_order \
            as testmock_get_unreachable_call_order
        from plugins.testmockoperations.tasks import get_state \
            as testmock_get_state
        states = send_task(testmock_get_state).get(timeout=10)
        node1_id = states[0]['id']
        node2_id = states[1]['id']
        node3_id = states[2]['id']

        unreachable_call_order = send_task(
            testmock_get_unreachable_call_order).get(timeout=10)
        self.assertEquals(3, len(unreachable_call_order))
        self.assertEquals(node3_id, unreachable_call_order[0]['id'])
        self.assertEquals(node2_id, unreachable_call_order[1]['id'])
        self.assertEquals(node1_id, unreachable_call_order[2]['id'])

        from plugins.connection_configurer_mock.tasks import get_state \
            as config_get_state
        configurer_state = send_task(config_get_state).get(timeout=10)
        self.assertEquals(2, len(configurer_state))
        self.assertTrue(
            configurer_state[0]['id'].startswith('contained_in_node2'))
        self.assertTrue(
            configurer_state[0]['related_id'].startswith('contained_in_node1'))
        self.assertTrue(
            configurer_state[1]['id'].startswith('containing_node'))
        self.assertTrue(
            configurer_state[1]['related_id'].startswith('contained_in_node1'))
コード例 #22
0
    def test_uninstall_with_dependency_order(self):
        dsl_path = resource(
            "dsl/uninstall_dependencies-order-with-three-nodes.yaml")
        print('starting deploy process')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id
        print('deploy completed')
        print('starting undeploy process')
        time.sleep(5)  # give elasticsearch time to update execution status..
        undeploy(deployment_id)
        print('undeploy completed')
        # Checking that uninstall wasn't called on the contained node
        from plugins.testmockoperations.tasks import \
            get_unreachable_call_order \
            as testmock_get_unreachable_call_order
        from plugins.testmockoperations.tasks import get_state \
            as testmock_get_state
        states = send_task(testmock_get_state).get(timeout=10)
        node1_id = states[0]['id']
        node2_id = states[1]['id']
        node3_id = states[2]['id']

        unreachable_call_order = send_task(
            testmock_get_unreachable_call_order).get(timeout=10)
        self.assertEquals(3, len(unreachable_call_order))
        self.assertEquals(node3_id, unreachable_call_order[0]['id'])
        self.assertEquals(node2_id, unreachable_call_order[1]['id'])
        self.assertEquals(node1_id, unreachable_call_order[2]['id'])

        from plugins.connection_configurer_mock.tasks import get_state \
            as config_get_state
        configurer_state = send_task(config_get_state).get(timeout=10)
        self.assertEquals(2, len(configurer_state))
        self.assertTrue(
            configurer_state[0]['id'].startswith('contained_in_node2'))
        self.assertTrue(
            configurer_state[0]['related_id'].startswith('contained_in_node1'))
        self.assertTrue(
            configurer_state[1]['id'].startswith('containing_node'))
        self.assertTrue(
            configurer_state[1]['related_id'].startswith('contained_in_node1'))
コード例 #23
0
    def test_execute_operation(self):
        dsl_path = resource("dsl/basic.yaml")
        blueprint_id = self.id()
        deployment, _ = deploy(dsl_path, blueprint_id=blueprint_id)

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)

        self.assertEquals(1, len(machines))
コード例 #24
0
    def test_dependencies_order_with_two_nodes(self):
        dsl_path = resource("dsl/dependencies_order_with_two_nodes.yaml")
        blueprint_id = self.id()
        deployment, _ = deploy(dsl_path, blueprint_id=blueprint_id)

        self.assertEquals(blueprint_id, deployment.blueprint_id)

        from plugins.testmockoperations.tasks import get_state as \
            testmock_get_state
        states = send_task(testmock_get_state) \
            .get(timeout=10)
        self.assertEquals(2, len(states))
        self.assertTrue('host_node' in states[0]['id'])
        self.assertTrue('db_node' in states[1]['id'])
コード例 #25
0
    def test_uninstall_application_single_node_no_host(self):
        from testenv import logger
        dsl_path = resource("dsl/single_node_no_host.yaml")
        logger.info('starting deploy process')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id
        logger.info('deploy completed')
        logger.info('starting undeploy process')
        time.sleep(5)  # give elasticsearch time to update execution status..
        undeploy(deployment_id)
        logger.info('undeploy completed')

        from plugins.testmockoperations.tasks import get_state as \
            testmock_get_state
        from plugins.testmockoperations.tasks import is_unreachable_called
        states = send_task(testmock_get_state).get(timeout=10)
        node_id = states[0]['id']

        result = send_task(is_unreachable_called, [node_id])
        self.assertTrue(result.get(timeout=10))

        node_instance = self.client.node_instances.get(node_id)
        self.assertEqual('deleted', node_instance['state'])
コード例 #26
0
    def test_uninstall_application_single_node_no_host(self):
        from testenv import logger
        dsl_path = resource("dsl/single_node_no_host.yaml")
        logger.info('starting deploy process')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id
        logger.info('deploy completed')
        logger.info('starting undeploy process')
        time.sleep(5)  # give elasticsearch time to update execution status..
        undeploy(deployment_id)
        logger.info('undeploy completed')

        from plugins.testmockoperations.tasks import get_state as \
            testmock_get_state
        from plugins.testmockoperations.tasks import is_unreachable_called
        states = send_task(testmock_get_state).get(timeout=10)
        node_id = states[0]['id']

        result = send_task(is_unreachable_called, [node_id])
        self.assertTrue(result.get(timeout=10))

        node_instance = self.client.node_instances.get(node_id)
        self.assertEqual('deleted', node_instance['state'])
コード例 #27
0
    def test_dependencies_order_with_two_nodes(self):
        dsl_path = resource("dsl/dependencies_order_with_two_nodes.yaml")
        blueprint_id = self.id()
        deployment, _ = deploy(dsl_path, blueprint_id=blueprint_id)

        self.assertEquals(blueprint_id, deployment.blueprint_id)

        from plugins.testmockoperations.tasks import get_state as \
            testmock_get_state
        states = send_task(testmock_get_state) \
            .get(timeout=10)
        self.assertEquals(2, len(states))
        self.assertTrue('host_node' in states[0]['id'])
        self.assertTrue('db_node' in states[1]['id'])
コード例 #28
0
    def test_deploy_multi_instance_many_different_hosts(self):
        dsl_path = resource('dsl/multi_instance_many_different_hosts.yaml')
        deploy(dsl_path)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = set(result.get(timeout=10))
        self.assertEquals(15, len(machines))

        self.assertEquals(
            5, len(filter(lambda ma: ma.startswith('host1'), machines)))
        self.assertEquals(
            5, len(filter(lambda ma: ma.startswith('host2'), machines)))
        self.assertEquals(
            5, len(filter(lambda ma: ma.startswith('host3'), machines)))
コード例 #29
0
    def test_execute_operation(self):
        dsl_path = resource("dsl/basic.yaml")
        blueprint_id = self.id()
        deployment, _ = deploy(dsl_path, blueprint_id=blueprint_id)

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)
        self.assertEquals(1, len(machines))

        outputs = self.client.deployments.outputs.get(deployment.id).outputs
        # ip runtime property is not set in this case
        self.assertIsNone(outputs['ip_address'])
コード例 #30
0
    def test_deploy_multi_instance_many_different_hosts(self):
        dsl_path = resource('dsl/multi_instance_many_different_hosts.yaml')
        deploy(dsl_path)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = set(result.get(timeout=10))
        self.assertEquals(15, len(machines))

        self.assertEquals(5, len(filter(lambda ma: ma.startswith('host1'),
                                        machines)))
        self.assertEquals(5, len(filter(lambda ma: ma.startswith('host2'),
                                        machines)))
        self.assertEquals(5, len(filter(lambda ma: ma.startswith('host3'),
                                        machines)))
コード例 #31
0
    def test_execute_operation(self):
        dsl_path = resource("dsl/basic.yaml")
        blueprint_id = self.id()
        deployment, _ = deploy(dsl_path, blueprint_id=blueprint_id)

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)
        self.assertEquals(1, len(machines))

        outputs = self.client.deployments.outputs.get(deployment.id).outputs
        # ip runtime property is not set in this case
        self.assertIsNone(outputs['ip_address'])
コード例 #32
0
    def test_search(self):
        dsl_path = resource("dsl/basic.yaml")
        blueprint_id = 'my_new_blueprint'
        deployment, _ = deploy(dsl_path, blueprint_id=blueprint_id)

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)

        self.assertEquals(1, len(machines))
        result = self.client.search.run_query('')
        hits = map(lambda x: x['_source'], result['hits']['hits'])

        self.assertEquals(7, len(hits))
コード例 #33
0
    def test_search(self):
        dsl_path = resource("dsl/basic.yaml")
        blueprint_id = 'my_new_blueprint'
        deployment, _ = deploy(dsl_path, blueprint_id=blueprint_id)

        self.assertEqual(blueprint_id, deployment.blueprint_id)

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)

        self.assertEquals(1, len(machines))
        result = self.client.search.run_query('')
        hits = map(lambda x: x['_source'], result['hits']['hits'])

        self.assertEquals(7, len(hits))
コード例 #34
0
    def test_simple(self):
        parameters = {'do_get': self.do_get, 'key': 'key1', 'value': 'value1'}
        result_dict = {'key1': 'value1'}
        deployment, _ = deploy(resource('dsl/workflow_api.yaml'),
                               self._testMethodName,
                               parameters=parameters)

        # testing workflow remote task
        invocation = send_task(get_mock_operation_invocations).get()[0]
        self.assertDictEqual(result_dict, invocation)

        # testing workflow local task
        instance = self.client.node_instances.list(
            deployment_id=deployment.id)[0]
        # I am in love with eventual consistency
        instance = self.client.node_instances.get(instance.id)
        self.assertEqual('test_state', instance.state)
コード例 #35
0
    def test_cloudify_runtime_properties_injection(self):
        dsl_path = resource("dsl/dependencies_order_with_two_nodes.yaml")
        deploy(dsl_path)

        from plugins.testmockoperations.tasks import get_state as \
            testmock_get_state
        states = send_task(testmock_get_state).get(timeout=10)
        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))
コード例 #36
0
    def test_cloudify_runtime_properties_injection(self):
        dsl_path = resource("dsl/dependencies_order_with_two_nodes.yaml")
        deploy(dsl_path)

        from plugins.testmockoperations.tasks import get_state as \
            testmock_get_state
        states = send_task(testmock_get_state).get(timeout=10)
        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))
コード例 #37
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)
コード例 #38
0
    def test_uninstall_application_single_host_node(self):
        dsl_path = resource("dsl/basic.yaml")

        self.logger.info('starting deploy process')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id
        self.logger.info('deploy completed')

        self.logger.info('starting undeploy process')
        time.sleep(5)  # give elasticsearch time to update execution status..
        undeploy(deployment_id)
        self.logger.info('undeploy completed')

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)

        self.assertEquals(0, len(machines))
コード例 #39
0
 def _test_retries_and_retry_interval_impl(self,
                                           blueprint,
                                           retries,
                                           retry_interval,
                                           expected_interval,
                                           expected_retries,
                                           invocations_task,
                                           expect_failure=False):
     self.configure(retries=retries, retry_interval=retry_interval)
     if expect_failure:
         self.assertRaises(RuntimeError, deploy, resource(blueprint))
     else:
         deploy(resource(blueprint))
     invocations = send_task(invocations_task).get()
     self.assertEqual(expected_retries + 1, len(invocations))
     for i in range(len(invocations) - 1):
         self.assertLessEqual(expected_interval,
                              invocations[i + 1] - invocations[i])
コード例 #40
0
    def test_uninstall_application_single_host_node(self):
        dsl_path = resource("dsl/basic.yaml")

        self.logger.info('starting deploy process')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id
        self.logger.info('deploy completed')

        self.logger.info('starting undeploy process')
        time.sleep(5)  # give elasticsearch time to update execution status..
        undeploy(deployment_id)
        self.logger.info('undeploy completed')

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)

        self.assertEquals(0, len(machines))
コード例 #41
0
 def _test_retries_and_retry_interval_impl(self,
                                           blueprint,
                                           retries,
                                           retry_interval,
                                           expected_interval,
                                           expected_retries,
                                           invocations_task,
                                           expect_failure=False):
     self.configure(retries=retries, retry_interval=retry_interval)
     if expect_failure:
         self.assertRaises(RuntimeError, deploy, resource(blueprint))
     else:
         deploy(resource(blueprint))
     invocations = send_task(invocations_task).get()
     self.assertEqual(expected_retries + 1, len(invocations))
     for i in range(len(invocations) - 1):
         self.assertLessEqual(expected_interval,
                              invocations[i+1] - invocations[i])
コード例 #42
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_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'})
コード例 #43
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)
コード例 #44
0
    def test_plugin_get_resource(self):
        dsl_path = resource("dsl/get_resource_in_plugin.yaml")
        deploy(dsl_path)
        from plugins.testmockoperations.tasks import \
            get_resource_operation_invocations as testmock_get_invocations
        invocations = send_task(testmock_get_invocations).get(timeout=10)
        self.assertEquals(1, len(invocations))
        invocation = invocations[0]
        with open(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'])
コード例 #45
0
    def test_node_states(self):
        dsl_path = resource('dsl/node_states.yaml')
        _id = uuid.uuid1()
        blueprint_id = 'blueprint_{0}'.format(_id)
        deployment_id = 'deployment_{0}'.format(_id)
        deployment, _ = deploy(dsl_path,
                               blueprint_id=blueprint_id,
                               deployment_id=deployment_id)

        from plugins.testmockoperations.tasks import get_node_states
        node_states = send_task(get_node_states).get(timeout=10)

        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)
コード例 #46
0
    def test_plugin_get_resource(self):
        dsl_path = resource("dsl/get_resource_in_plugin.yaml")
        deploy(dsl_path)
        from plugins.testmockoperations.tasks import \
            get_resource_operation_invocations as testmock_get_invocations
        invocations = send_task(testmock_get_invocations).get(
            timeout=10)
        self.assertEquals(1, len(invocations))
        invocation = invocations[0]
        with open(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'])
コード例 #47
0
 def test_stop_monitor_node_operation(self):
     dsl_path = resource("dsl/hardcoded_operation_properties.yaml")
     print('starting deploy process')
     deployment, _ = deploy(dsl_path)
     deployment_id = deployment.id
     print('deploy completed')
     print('starting undeploy process')
     time.sleep(5)  # give elasticsearch time to update execution status..
     undeploy(deployment_id)
     print('undeploy completed')
     # test stop monitor invocations
     from plugins.testmockoperations.tasks import \
         get_monitoring_operations_invocation
     invocations = send_task(get_monitoring_operations_invocation) \
         .get(timeout=10)
     self.assertEqual(2, len(invocations))
     self.assertTrue('single_node' in invocations[0]['id'])
     self.assertEquals('start_monitor', invocations[0]['operation'])
     self.assertTrue('single_node' in invocations[1]['id'])
     self.assertEquals('stop_monitor', invocations[1]['operation'])
コード例 #48
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'})
コード例 #49
0
 def test_stop_monitor_node_operation(self):
     dsl_path = resource(
         "dsl/hardcoded_operation_properties.yaml")
     print('starting deploy process')
     deployment, _ = deploy(dsl_path)
     deployment_id = deployment.id
     print('deploy completed')
     print('starting undeploy process')
     time.sleep(5)  # give elasticsearch time to update execution status..
     undeploy(deployment_id)
     print('undeploy completed')
     # test stop monitor invocations
     from plugins.testmockoperations.tasks import \
         get_monitoring_operations_invocation
     invocations = send_task(get_monitoring_operations_invocation) \
         .get(timeout=10)
     self.assertEqual(2, len(invocations))
     self.assertTrue('single_node' in invocations[0]['id'])
     self.assertEquals('start_monitor', invocations[0]['operation'])
     self.assertTrue('single_node' in invocations[1]['id'])
     self.assertEquals('stop_monitor', invocations[1]['operation'])
コード例 #50
0
    def test_get_instance_ip(self):
        dsl_path = resource("dsl/get_instance_ip.yaml")
        deploy(dsl_path)

        invocations = send_task(get_mock_operation_invocations).get()
        mapping = {name: ip for name, ip in invocations}

        self.assertDictEqual({
            'host1_1': '1.1.1.1',
            'host1_2': '2.2.2.2',
            'contained1_in_host1_1': '1.1.1.1',
            'contained1_in_host1_2': '2.2.2.2',
            'host2_1': '3.3.3.3',
            'host2_2': '4.4.4.4',
            'contained2_in_host2_1': '3.3.3.3',
            'contained2_in_host2_2': '4.4.4.4',
            'host2_1_rel': '3.3.3.3',
            'host2_2_rel': '4.4.4.4',
            'contained2_in_host2_1_rel': '3.3.3.3',
            'contained2_in_host2_2_rel': '4.4.4.4'
        }, mapping)
コード例 #51
0
    def test_node_states(self):
        dsl_path = resource('dsl/node_states.yaml')
        _id = uuid.uuid1()
        blueprint_id = 'blueprint_{0}'.format(_id)
        deployment_id = 'deployment_{0}'.format(_id)
        deployment, _ = deploy(dsl_path,
                               blueprint_id=blueprint_id,
                               deployment_id=deployment_id)

        from plugins.testmockoperations.tasks import get_node_states
        node_states = send_task(get_node_states).get(timeout=10)

        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)
コード例 #52
0
    def test_get_instance_ip(self):
        dsl_path = resource("dsl/get_instance_ip.yaml")
        deploy(dsl_path)

        invocations = send_task(get_mock_operation_invocations).get()
        mapping = {name: ip for name, ip in invocations}

        self.assertDictEqual(
            {
                'host1_1': '1.1.1.1',
                'host1_2': '2.2.2.2',
                'contained1_in_host1_1': '1.1.1.1',
                'contained1_in_host1_2': '2.2.2.2',
                'host2_1': '3.3.3.3',
                'host2_2': '4.4.4.4',
                'contained2_in_host2_1': '3.3.3.3',
                'contained2_in_host2_2': '4.4.4.4',
                'host2_1_rel': '3.3.3.3',
                'host2_2_rel': '4.4.4.4',
                'contained2_in_host2_1_rel': '3.3.3.3',
                'contained2_in_host2_2_rel': '4.4.4.4'
            }, mapping)
コード例 #53
0
    def test_simple(self):
        parameters = {
            'do_get': self.do_get,
            'key': 'key1',
            'value': 'value1'
        }
        result_dict = {
            'key1': 'value1'
        }
        deployment, _ = deploy(resource('dsl/workflow_api.yaml'),
                               self._testMethodName,
                               parameters=parameters)

        # testing workflow remote task
        invocation = send_task(get_mock_operation_invocations).get()[0]
        self.assertDictEqual(result_dict, invocation)

        # testing workflow local task
        instance = self.client.node_instances.list(
            deployment_id=deployment.id)[0]
        # I am in love with eventual consistency
        instance = self.client.node_instances.get(instance.id)
        self.assertEqual('test_state', instance.state)
コード例 #54
0
    def verify_assertions(self, hook, runs_on_source):

        if runs_on_source:
            node_id_id_prefix = 'mock_node_that_connects_to_host'
            related_id_prefix = 'host'
        else:
            node_id_id_prefix = 'host'
            related_id_prefix = 'mock_node_that_connects_to_host'

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)
        self.assertEquals(1, len(machines))

        from plugins.connection_configurer_mock.tasks import get_state \
            as config_get_state
        result = send_task(config_get_state)

        state = result.get(timeout=10)[0]

        node_id = state['id']
        related_id = state['related_id']

        self.assertTrue(node_id.startswith(node_id_id_prefix))
        self.assertTrue(related_id.startswith(related_id_prefix))

        from testenv import is_node_started
        self.assertTrue(is_node_started(related_id))

        if runs_on_source:
            self.assertEquals('source_property_value',
                              state['properties']['source_property_key'])
            self.assertEquals(
                'target_property_value',
                state['related_properties']['target_property_key'])
            self.assertEquals(
                'source_runtime_property_value',
                state['runtime_properties']['source_runtime_property_key'])
            self.assertEquals(
                'target_runtime_property_value',
                state['related_runtime_properties']
                ['target_runtime_property_key'])
        else:
            self.assertEquals(
                'source_property_value',
                state['related_properties']['source_property_key'])
            self.assertEquals('target_property_value',
                              state['properties']['target_property_key'])
            self.assertEquals(
                'source_runtime_property_value',
                state['related_runtime_properties']
                ['source_runtime_property_key'])
            self.assertEquals(
                'target_runtime_property_value',
                state['runtime_properties']['target_runtime_property_key'])

        if hook == 'pre-init':
            self.assertTrue(node_id not in state['capabilities'])
        elif hook == 'post-init':
            self.assertTrue(is_node_started(node_id))
        else:
            self.fail('unhandled state')

        connector_timestamp = state['time']

        from plugins.testmockoperations.tasks import get_state \
            as testmock_get_state
        from plugins.testmockoperations.tasks import get_touched_time \
            as testmock_get_touch_time
        state = send_task(testmock_get_state).get(timeout=10)[0]
        touched_timestamp = send_task(testmock_get_touch_time)\
            .get(timeout=10)

        reachable_timestamp = state['time']
        if hook == 'pre-init':
            self.assertLess(touched_timestamp, connector_timestamp)
            self.assertGreater(reachable_timestamp, connector_timestamp)
        elif hook == 'post-init':
            self.assertLess(reachable_timestamp, connector_timestamp)
        else:
            self.fail('unhandled state')
コード例 #55
0
 def _get(self, task, queue, args=None):
     return send_task(task, queue=queue, args=args).get(timeout=10)
コード例 #56
0
 def assertion():
     invocations = send_task(testmock_get_invocations).get(timeout=10)
     self.assertEqual(expected_count, len(invocations))
コード例 #57
0
 def _get(self, task, queue, args=None):
     return send_task(task, queue=queue, args=args).get(timeout=10)
コード例 #58
0
    def verify_assertions(self, hook, runs_on_source):

        if runs_on_source:
            node_id_id_prefix = 'mock_node_that_connects_to_host'
            related_id_prefix = 'host'
        else:
            node_id_id_prefix = 'host'
            related_id_prefix = 'mock_node_that_connects_to_host'

        from plugins.cloudmock.tasks import get_machines
        result = send_task(get_machines)
        machines = result.get(timeout=10)
        self.assertEquals(1, len(machines))

        from plugins.connection_configurer_mock.tasks import get_state \
            as config_get_state
        result = send_task(config_get_state)

        state = result.get(timeout=10)[0]

        node_id = state['id']
        related_id = state['related_id']

        self.assertTrue(node_id.startswith(node_id_id_prefix))
        self.assertTrue(related_id.startswith(related_id_prefix))

        from testenv import is_node_started
        self.assertTrue(is_node_started(related_id))

        if runs_on_source:
            self.assertEquals('source_property_value',
                              state['properties']['source_property_key'])
            self.assertEquals(
                'target_property_value',
                state['related_properties']['target_property_key'])
            self.assertEquals(
                'source_runtime_property_value',
                state['runtime_properties']['source_runtime_property_key']
            )
            self.assertEquals(
                'target_runtime_property_value',
                state['related_runtime_properties']
                     ['target_runtime_property_key']
            )
        else:
            self.assertEquals('source_property_value',
                              state['related_properties']
                              ['source_property_key'])
            self.assertEquals(
                'target_property_value',
                state['properties']['target_property_key'])
            self.assertEquals(
                'source_runtime_property_value',
                state['related_runtime_properties']
                     ['source_runtime_property_key']
            )
            self.assertEquals(
                'target_runtime_property_value',
                state['runtime_properties']
                     ['target_runtime_property_key']
            )

        if hook == 'pre-init':
            self.assertTrue(node_id not in
                            state['capabilities'])
        elif hook == 'post-init':
            self.assertTrue(is_node_started(node_id))
        else:
            self.fail('unhandled state')

        connector_timestamp = state['time']

        from plugins.testmockoperations.tasks import get_state \
            as testmock_get_state
        from plugins.testmockoperations.tasks import get_touched_time \
            as testmock_get_touch_time
        state = send_task(testmock_get_state).get(timeout=10)[0]
        touched_timestamp = send_task(testmock_get_touch_time)\
            .get(timeout=10)

        reachable_timestamp = state['time']
        if hook == 'pre-init':
            self.assertLess(touched_timestamp, connector_timestamp)
            self.assertGreater(reachable_timestamp, connector_timestamp)
        elif hook == 'post-init':
            self.assertLess(reachable_timestamp, connector_timestamp)
        else:
            self.fail('unhandled state')