Example #1
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})
Example #2
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})
Example #3
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)
    def _execute_and_cancel_execution(self, workflow_id, force=False,
                                      wait_for_termination=True,
                                      is_wait_for_asleep_node=True):
        dsl_path = resource('dsl/sleep_workflows.yaml')
        _id = uuid.uuid1()
        blueprint_id = 'blueprint_{0}'.format(_id)
        deployment_id = 'deployment_{0}'.format(_id)
        self.client.blueprints.upload(dsl_path, blueprint_id)
        self.client.deployments.create(blueprint_id, deployment_id)
        do_retries(verify_workers_installation_complete, 30,
                   deployment_id=deployment_id)
        execution = self.client.deployments.execute(
            deployment_id, workflow_id)

        node_inst_id = self.client.node_instances.list(deployment_id)[0].id

        if is_wait_for_asleep_node:
            for retry in range(30):
                if self.client.node_instances.get(
                        node_inst_id).state == 'asleep':
                    break
                time.sleep(1)
            else:
                raise RuntimeError("Execution was expected to go"
                                   " into 'sleeping' status")

        execution = self.client.executions.cancel(execution.id, force)
        expected_status = Execution.FORCE_CANCELLING if force else \
            Execution.CANCELLING
        self.assertEquals(expected_status, execution.status)
        if wait_for_termination:
            wait_for_execution_to_end(execution)
            execution = self.client.executions.get(execution.id)
        return execution
Example #5
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)
Example #6
0
 def test_illegal_non_graph_to_graph_mode(self):
     if not self.do_get:
         # no need to run twice
         return
     self.assertRaises(RuntimeError, deploy,
                       resource('dsl/workflow_api.yaml'),
                       self._testMethodName)
Example #7
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)
Example #8
0
 def test_illegal_non_graph_to_graph_mode(self):
     if not self.do_get:
         # no need to run twice
         return
     self.assertRaises(RuntimeError, deploy,
                       resource('dsl/workflow_api.yaml'),
                       self._testMethodName)
Example #9
0
 def setUp(self):
     super(RestAPITest, self).setUp()
     dsl_path = resource('dsl/basic.yaml')
     self.node_id = 'webserver_host'
     self.blueprint_id = 'blueprint-' + str(uuid.uuid4())
     self.deployment_id = 'deployment-' + str(uuid.uuid4())
     self.client.blueprints.upload(dsl_path, self.blueprint_id)
     self.client.deployments.create(self.blueprint_id, self.deployment_id)
Example #10
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)
    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)
 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')
Example #13
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)
Example #14
0
 def setUp(self):
     super(RestAPITest, self).setUp()
     dsl_path = resource('dsl/basic.yaml')
     self.node_id = 'webserver_host'
     self.blueprint_id = 'blueprint-' + str(uuid.uuid4())
     self.deployment_id = 'deployment-' + str(uuid.uuid4())
     self.client.blueprints.upload(dsl_path, self.blueprint_id)
     self.client.deployments.create(self.blueprint_id, self.deployment_id)
Example #15
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])
Example #16
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)
Example #17
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
 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])
Example #19
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])
Example #20
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))
Example #21
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'])
Example #22
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)
Example #23
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)
Example #24
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
 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)
Example #26
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)
Example #27
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'])
Example #28
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'])
Example #29
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])
Example #30
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'])
Example #31
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))
Example #32
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'])
Example #33
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))
Example #34
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'])
Example #35
0
 def test_deployment_inputs(self):
     blueprint_id = str(uuid.uuid4())
     blueprint = self.client.blueprints.upload(resource("dsl/basic.yaml"), blueprint_id)
     inputs = blueprint.plan["inputs"]
     self.assertEqual(1, len(inputs))
     self.assertTrue("install_agent" in inputs)
     self.assertFalse(inputs["install_agent"]["default"])
     self.assertTrue(len(inputs["install_agent"]["description"]) > 0)
     deployment_id = str(uuid.uuid4())
     deployment = self.client.deployments.create(blueprint.id, deployment_id)
     self.assertEqual(1, len(deployment.inputs))
     self.assertTrue("install_agent" in deployment.inputs)
     self.assertFalse(deployment.inputs["install_agent"])
Example #36
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'])
Example #37
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)
Example #38
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'])
Example #39
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'])
    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)))
Example #41
0
 def test_deployment_inputs(self):
     blueprint_id = str(uuid.uuid4())
     blueprint = self.client.blueprints.upload(resource("dsl/basic.yaml"),
                                               blueprint_id)
     inputs = blueprint.plan['inputs']
     self.assertEqual(1, len(inputs))
     self.assertTrue('install_agent' in inputs)
     self.assertFalse(inputs['install_agent']['default'])
     self.assertTrue(len(inputs['install_agent']['description']) > 0)
     deployment_id = str(uuid.uuid4())
     deployment = self.client.deployments.create(blueprint.id,
                                                 deployment_id)
     self.assertEqual(1, len(deployment.inputs))
     self.assertTrue('install_agent' in deployment.inputs)
     self.assertFalse(deployment.inputs['install_agent'])
Example #42
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'])
Example #43
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'])
Example #44
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)))
    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')
Example #46
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))
Example #47
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)
Example #48
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_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_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)
Example #53
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_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))
Example #55
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)
Example #56
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'])
Example #57
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))
Example #59
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))