def test_invalid_dsl(self):
        # note: this actually tests the validation part of the "deploy" command
        dsl_path = resource("dsl/invalid-dsl.yaml")

        with self.assertRaises(Exception) as cm:
            deploy(dsl_path)
            self.assertTrue('invalid blueprint' in
                            cm.exception.message.lower(), cm.exception.message)
예제 #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_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])
예제 #4
0
    def test_execute_operation(self):
        dsl_path = resource("dsl/basic.yaml")
        deploy(dsl_path)

        from cosmo.cloudmock.tasks import get_machines
        result = get_machines.apply_async()
        machines = result.get(timeout=10)

        self.assertEquals(1, len(machines))
예제 #5
0
    def test_dependencies_order_with_two_nodes(self):
        dsl_path = resource("dsl/dependencies-order-with-two-nodes.yaml")
        deploy(dsl_path)

        from cosmo.testmockoperations.tasks import get_state as testmock_get_state
        states = testmock_get_state.apply_async().get(timeout=10)
        self.assertEquals(2, len(states))
        self.assertEquals('mock_app.containing_node', states[0]['id'])
        self.assertEquals('mock_app.contained_in_node', states[1]['id'])
예제 #6
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
예제 #7
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])
예제 #8
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'])
예제 #9
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'])
예제 #10
0
 def _local_task_fail_impl(self, wf_name):
     if self.do_get:
         deploy(resource('dsl/workflow_api.yaml'), wf_name,
                parameters={'do_get': self.do_get})
     else:
         self.assertRaises(RuntimeError,
                           deploy,
                           resource('dsl/workflow_api.yaml'),
                           wf_name,
                           parameters={'do_get': self.do_get})
예제 #11
0
    def test_cloudify_runtime_properties_injection(self):
        dsl_path = resource("dsl/dependencies-order-with-two-nodes.yaml")
        deploy(dsl_path)

        from cosmo.testmockoperations.tasks import get_state as testmock_get_state
        states = testmock_get_state.apply_async().get(timeout=10)
        node_runtime_props = states[1]['relationships'][
            'mock_app.containing_node']
        self.assertEquals('value1', node_runtime_props['property1'])
        self.assertEquals('true', node_runtime_props['reachable'])
        self.assertEquals(2, len(node_runtime_props))
예제 #12
0
 def _local_task_fail_impl(self, wf_name):
     if self.do_get:
         deploy(resource('dsl/workflow_api.yaml'),
                wf_name,
                parameters={'do_get': self.do_get})
     else:
         self.assertRaises(RuntimeError,
                           deploy,
                           resource('dsl/workflow_api.yaml'),
                           wf_name,
                           parameters={'do_get': self.do_get})
예제 #13
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'])
예제 #14
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'])
예제 #15
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)))
예제 #16
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)))
예제 #17
0
 def test_cancel_on_wait_for_task_termination(self):
     _, eid = deploy(
         resource('dsl/workflow_api.yaml'), self._testMethodName,
         parameters={'do_get': self.do_get}, wait_for_execution=False)
     self.wait_for_execution_status(eid, status=Execution.STARTED)
     self.client.executions.cancel(eid)
     self.wait_for_execution_status(eid, status=Execution.CANCELLED)
예제 #18
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)
예제 #19
0
    def test_threshold_policy(self):
        dsl_path = resource("dsl/with_policies2.yaml")
        deployment, _ = deploy(dsl_path)
        self.deployment_id = deployment.id
        self.instance_id = self.wait_for_node_instance().id

        class Tester(object):
            def __init__(self, test_case, threshold, current_executions,
                         current_invocations):
                self.test_case = test_case
                self.current_invocations = current_invocations
                self.current_executions = current_executions
                self.threshold = threshold

            def publish_above_threshold(self, do_assert):
                self.test_case.logger.info('Publish above threshold')
                self.test_case.publish(self.threshold + 1)
                if do_assert:
                    self.inc()
                    self.assertion(upper=True)

            def publish_below_threshold(self, do_assert):
                self.test_case.logger.info('Publish below threshold')
                self.test_case.publish(self.threshold - 1)
                if do_assert:
                    self.inc()
                    self.assertion(upper=False)

            def inc(self):
                self.current_executions += 1
                self.current_invocations += 1

            def assertion(self, upper):
                self.test_case.logger.info('waiting for {} executions'.format(
                    self.current_executions))
                self.test_case.wait_for_executions(self.current_executions)
                self.test_case.logger.info('waiting for {} invocations'.format(
                    self.current_invocations))
                invocations = self.test_case.wait_for_invocations(
                    self.current_invocations)
                if upper:
                    key = 'upper'
                    value = self.threshold + 1
                else:
                    key = 'lower'
                    value = self.threshold - 1
                self.test_case.assertEqual(
                    invocations[-1][key], value,
                    'key: {}, expected: {}'.format(key, value))

        tester = Tester(test_case=self,
                        threshold=100,
                        current_executions=2,
                        current_invocations=0)

        for _ in range(2):
            tester.publish_above_threshold(do_assert=True)
            tester.publish_above_threshold(do_assert=False)
            tester.publish_below_threshold(do_assert=True)
            tester.publish_below_threshold(do_assert=False)
예제 #20
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)
예제 #21
0
    def test_policies(self):
        dsl_path = resource("dsl/with_policies.yaml")
        deployment, _ = deploy(dsl_path)

        def assertion():
            instances = self.client.node_instances.list(deployment.id)
            self.assertEqual(1, len(instances))
        self.do_assertions(assertion)

        instance = self.client.node_instances.list(deployment.id)[0]
        self.publish_riemann_event(deployment.id,
                                   node_name='node',
                                   node_id=instance.id,
                                   metric=123)

        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'])
        self.do_assertions(assertion)
예제 #22
0
 def test_cancel_on_wait_for_task_termination(self):
     _, eid = deploy(resource('dsl/workflow_api.yaml'),
                     self._testMethodName,
                     parameters={'do_get': self.do_get},
                     wait_for_execution=False)
     self.wait_for_execution_status(eid, status=Execution.STARTED)
     self.client.executions.cancel(eid)
     self.wait_for_execution_status(eid, status=Execution.CANCELLED)
예제 #23
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))
 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')
예제 #25
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))
예제 #26
0
    def test_update_node_bad_version(self):
        deploy(resource("dsl/basic.yaml"))
        client = create_rest_client()
        instance = client.node_instances.list()[0]
        instance = client.node_instances.get(instance.id)  # need the version

        props = {"key": "value"}
        result = client.node_instances.update(
            instance.id, state="started", runtime_properties=props, version=instance.version
        )
        self.assertEquals(instance.version + 1, result.version)
        self.assertEquals(instance.id, result.id)
        self.assertDictContainsSubset(props, result.runtime_properties)
        self.assertEquals("started", result.state)

        # making another call with a bad version
        self.assertRaises(CloudifyClientError, client.node_instances.update, instance.id, version=1)
예제 #27
0
 def test_cancel_on_task_retry_interval(self):
     self.configure(retries=2, interval=1000000)
     _, eid = deploy(
         resource('dsl/workflow_api.yaml'), self._testMethodName,
         parameters={'do_get': self.do_get}, wait_for_execution=False)
     self.wait_for_execution_status(eid, status=Execution.STARTED)
     self.client.executions.cancel(eid)
     self.wait_for_execution_status(eid, status=Execution.CANCELLED)
예제 #28
0
 def test_cancel_on_task_retry_interval(self):
     self.configure(retries=2, interval=1000000)
     _, eid = deploy(resource('dsl/workflow_api.yaml'),
                     self._testMethodName,
                     parameters={'do_get': self.do_get},
                     wait_for_execution=False)
     self.wait_for_execution_status(eid, status=Execution.STARTED)
     self.client.executions.cancel(eid)
     self.wait_for_execution_status(eid, status=Execution.CANCELLED)
예제 #29
0
    def test_get_blueprint(self):
        dsl_path = resource("dsl/basic.yaml")
        blueprint_id = str(uuid.uuid4())
        deployment, _ = deploy(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)
예제 #30
0
    def test_deploy_multi_instance_application(self):
        dsl_path = resource("dsl/multi_instance.yaml")
        deploy(dsl_path)

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

        from cosmo.testmockoperations.tasks import get_state as get_state
        apps_state = get_state.apply_async().get(timeout=10)
        machines_with_apps = set([])
        for app_state in apps_state:
            host_id = app_state['relationships'].keys()[0]
            machines_with_apps.add(host_id)
        self.assertEquals(machines, machines_with_apps)

        pass
예제 #31
0
    def test_get_blueprint(self):
        dsl_path = resource("dsl/basic.yaml")
        blueprint_id = str(uuid.uuid4())
        deployment, _ = deploy(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)
예제 #32
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])
예제 #33
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])
예제 #34
0
    def test_deploy_multi_instance_application(self):
        dsl_path = resource("dsl/multi_instance.yaml")
        deploy(dsl_path)

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

        from cosmo.testmockoperations.tasks import get_state as get_state
        apps_state = get_state.apply_async().get(timeout=10)
        machines_with_apps = set([])
        for app_state in apps_state:
            host_id = app_state['relationships'].keys()[0]
            machines_with_apps.add(host_id)
        self.assertEquals(machines, machines_with_apps)

        pass
예제 #35
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'])
 def test_deployment_workflows(self):
     dsl_path = resource("dsl/custom_workflow_mapping.yaml")
     deployment, _ = deploy(dsl_path)
     deployment_id = deployment.id
     workflows = self.client.deployments.get(deployment_id).workflows
     self.assertEqual(3, len(workflows))
     wf_ids = [x.name for x in workflows]
     self.assertTrue('uninstall' in wf_ids)
     self.assertTrue('install' in wf_ids)
     self.assertTrue('custom' in wf_ids)
예제 #37
0
 def test_deployment_workflows(self):
     dsl_path = resource("dsl/custom_workflow_mapping.yaml")
     deployment, _ = deploy(dsl_path)
     deployment_id = deployment.id
     workflows = self.client.deployments.get(deployment_id).workflows
     self.assertEqual(3, len(workflows))
     wf_ids = [x.name for x in workflows]
     self.assertTrue('uninstall' in wf_ids)
     self.assertTrue('install' in wf_ids)
     self.assertTrue('custom' in wf_ids)
예제 #38
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'])
예제 #39
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))
    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)
예제 #41
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)
예제 #42
0
    def test_threshold_policy(self):
        dsl_path = resource("dsl/with_policies2.yaml")
        deployment, _ = deploy(dsl_path)
        self.deployment_id = deployment.id
        self.instance_id = self.wait_for_node_instance().id

        class Tester(object):
            def __init__(self, test_case, threshold, current_executions, current_invocations):
                self.test_case = test_case
                self.current_invocations = current_invocations
                self.current_executions = current_executions
                self.threshold = threshold

            def publish_above_threshold(self, do_assert):
                self.test_case.logger.info("Publish above threshold")
                self.test_case.publish(self.threshold + 1)
                if do_assert:
                    self.inc()
                    self.assertion(upper=True)

            def publish_below_threshold(self, do_assert):
                self.test_case.logger.info("Publish below threshold")
                self.test_case.publish(self.threshold - 1)
                if do_assert:
                    self.inc()
                    self.assertion(upper=False)

            def inc(self):
                self.current_executions += 1
                self.current_invocations += 1

            def assertion(self, upper):
                self.test_case.logger.info("waiting for {} executions".format(self.current_executions))
                self.test_case.wait_for_executions(self.current_executions)
                self.test_case.logger.info("waiting for {} invocations".format(self.current_invocations))
                invocations = self.test_case.wait_for_invocations(self.current_invocations)
                if upper:
                    key = "upper"
                    value = self.threshold + 1
                else:
                    key = "lower"
                    value = self.threshold - 1
                self.test_case.assertEqual(invocations[-1][key], value, "key: {}, expected: {}".format(key, value))

        tester = Tester(test_case=self, threshold=100, current_executions=2, current_invocations=0)

        for _ in range(2):
            tester.publish_above_threshold(do_assert=True)
            tester.publish_above_threshold(do_assert=False)
            tester.publish_below_threshold(do_assert=True)
            tester.publish_below_threshold(do_assert=False)
예제 #43
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'])
예제 #44
0
    def test_update_node_bad_version(self):
        deploy(resource("dsl/basic.yaml"))
        client = create_rest_client()
        instance = client.node_instances.list()[0]
        instance = client.node_instances.get(instance.id)  # need the version

        props = {'key': 'value'}
        result = client.node_instances.update(
            instance.id,
            state='started',
            runtime_properties=props,
            version=instance.version,
        )
        self.assertEquals(instance.version + 1, result.version)
        self.assertEquals(instance.id, result.id)
        self.assertDictContainsSubset(props, result.runtime_properties)
        self.assertEquals('started', result.state)

        # making another call with a bad version
        self.assertRaises(CloudifyClientError,
                          client.node_instances.update,
                          instance.id,
                          version=1)
예제 #45
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'])
예제 #46
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'])
예제 #47
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'])
    def test_update_runtime_properties(self):
        dsl_path = resource("dsl/set-property.yaml")

        # testing set property
        deployment, _ = deploy(dsl_path)
        node_id = self.client.node_instances.list(
            deployment_id=deployment.id)[0].id
        node_runtime_props = self.client.node_instances.get(
            node_id).runtime_properties
        self.assertEqual('property_value', node_runtime_props['property_name'])

        # testing delete property
        undeploy(deployment.id)
        node_runtime_props = self.client.node_instances.get(
            node_id).runtime_properties
        self.assertNotIn('property_name', node_runtime_props)
예제 #49
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))
    def test_get_deployment_nodes(self):
        dsl_path = resource("dsl/deployment-nodes-three-nodes.yaml")
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id
        nodes = get_deployment_nodes(deployment_id, get_state=True)
        self.assertEqual(deployment_id, nodes.deploymentId)
        self.assertEqual(3, len(nodes.nodes))

        def assert_node_state(node_id_infix):
            self.assertTrue(any(map(
                lambda n: node_id_infix in n.id and n.reachable, nodes.nodes
            )), 'Failed finding node {0} state'.format(node_id_infix))

        assert_node_state('containing_node')
        assert_node_state('contained_in_node1')
        assert_node_state('contained_in_node2')
예제 #51
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))
    def test_update_runtime_properties(self):
        dsl_path = resource("dsl/set_property.yaml")

        # testing set property
        deployment, _ = deploy(dsl_path)
        node_id = self.client.node_instances.list(
            deployment_id=deployment.id)[0].id
        node_runtime_props = self.client.node_instances.get(
            node_id).runtime_properties
        self.assertEqual('property_value', node_runtime_props['property_name'])

        # testing delete property
        undeploy(deployment.id)
        node_runtime_props = self.client.node_instances.get(
            node_id).runtime_properties
        self.assertNotIn('property_name', node_runtime_props)
    def test_failed_uninstall_task(self):
        dsl_path = resource("dsl/basic.yaml")
        self.logger.info('** install **')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id

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

        self.logger.info('** uninstall **')
        undeploy(deployment_id)

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

        self.assertEquals(0, len(machines))
    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')
        undeploy(deployment_id)
        self.logger.info('undeploy completed')

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

        self.assertEquals(0, len(machines))
예제 #55
0
    def test_policies_flow(self):
        """
        Tests policy/trigger/group creation and processing flow
        """
        dsl_path = resource("dsl/with_policies1.yaml")
        deployment, _ = deploy(dsl_path)
        self.deployment_id = deployment.id
        self.instance_id = self.wait_for_node_instance().id

        metric_value = 123

        self.publish(metric=metric_value)

        self.wait_for_executions(3)
        invocations = self.wait_for_invocations(2)
        self.assertEqual(self.instance_id, invocations[0]["node_id"])
        self.assertEqual(123, invocations[1]["metric"])
예제 #56
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)
예제 #57
0
    def test_policies_flow(self):
        """
        Tests policy/trigger/group creation and processing flow
        """
        dsl_path = resource("dsl/with_policies1.yaml")
        deployment, _ = deploy(dsl_path)
        self.deployment_id = deployment.id
        self.instance_id = self.wait_for_node_instance().id

        metric_value = 123

        self.publish(metric=metric_value)

        self.wait_for_executions(3)
        invocations = self.wait_for_invocations(2)
        self.assertEqual(self.instance_id, invocations[0]['node_id'])
        self.assertEqual(123, invocations[1]['metric'])
예제 #58
0
 def test_update_execution_status(self):
     dsl_path = resource("dsl/basic.yaml")
     _, execution_id = deploy(dsl_path, wait_for_execution=True)
     execution = self.client.executions.get(execution_id)
     self.assertEquals(Execution.TERMINATED, execution.status)
     execution = self.client.executions.update(execution_id, 'new-status')
     self.assertEquals('new-status', execution.status)
     execution = self.client.executions.update(execution_id,
                                               'another-new-status',
                                               'some-error')
     self.assertEquals('another-new-status', execution.status)
     self.assertEquals('some-error', execution.error)
     # verifying that updating only the status field also resets the
     # error field to an empty string
     execution = self.client.executions.update(execution_id, 'final-status')
     self.assertEquals('final-status', execution.status)
     self.assertEquals('', execution.error)
    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))