def test_deployment_logs(self):
        message = 'TEST MESSAGE'
        inputs = {'message': message}

        dsl_path = resource("dsl/deployment_logs.yaml")
        deployment, _ = deploy(dsl_path, inputs=inputs)

        deployment_log_path = ('/var/log/cloudify/mgmtworker/logs/{0}.log'
                               .format(deployment.id))

        def read_deployment_logs():
            return self.read_manager_file(deployment_log_path, no_strip=True)

        def verify_logs_exist_with_content():
            self.assertIn(message, read_deployment_logs())

        verify_logs_exist_with_content()

        undeploy(deployment.id, is_delete_deployment=True)

        # Verify log file id truncated on deployment delete
        self.assertEqual('', read_deployment_logs())

        deployment, _ = deploy(dsl_path, inputs=inputs,
                               deployment_id=deployment.id)

        # Verify new deployment with the same deployment id
        # can write to the previous location.
        verify_logs_exist_with_content()
 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})
Beispiel #3
0
 def _verify_plugin_can_be_used_in_blueprint(self):
     blueprint_path = resource('dsl/managed_plugins.yaml')
     test_input_value = 'MY_TEST_INPUT'
     inputs = {'test_input': test_input_value}
     deployment, _ = deploy(blueprint_path, inputs=inputs)
     outputs = self.client.deployments.outputs.get(deployment.id)
     self.assertEqual(outputs.outputs['test_output'], test_input_value)
    def test_hello_world(self):
        blueprint_file = self._prepare_hello_world()
        deployment, _ = deploy(blueprint_file, timeout_seconds=120)

        self._assert_hello_world_events(deployment.id)
        self._assert_hello_world_metric(deployment.id)

        ip = self.test_case.get_host_ip(node_id='vm',
                                        deployment_id=deployment.id)
        url = 'http://{0}:8080'.format(ip)

        def _webserver_request():
            return requests.get(url, timeout=1)

        # assert webserver running
        response = utils.do_retries(
            _webserver_request,
            exception_class=requests.exceptions.ConnectionError)
        self.test_case.assertIn('http_web_server', response.text)

        if not self.skip_uninstall:
            utils.undeploy_application(deployment.id)

            # assert webserver not running
            self.test_case.assertRaises(requests.exceptions.ConnectionError,
                                        _webserver_request)

        return deployment
 def test_post_source_started_location_target(self):
     dsl_path = resource(
         "dsl/relationship_interface_post_source_location_target.yaml")
     deployment, _ = deploy(dsl_path)
     self.verify_assertions(deployment.id,
                            hook='post-init',
                            runs_on_source=False)
Beispiel #6
0
    def get_and_download_deployment_resource_test(self):
        blueprint_id = str(uuid.uuid4())
        deployment_id = blueprint_id
        blueprint_path = resource('dsl/deployment_resource.yaml')
        deployment_folder_on_manager = \
            '/opt/manager/resources/deployments/{0}'.format(deployment_id)
        full_resource_path = os.path.join(deployment_folder_on_manager,
                                          RESOURCE_PATH)
        self.execute_on_manager(
            'mkdir -p {0}/resources'.format(deployment_folder_on_manager))

        with tempfile.NamedTemporaryFile() as f:
            f.write(RESOURCE_CONTENT)
            f.flush()
            self.copy_file_to_manager(source=f.name, target=full_resource_path)
            self.execute_on_manager('chmod +r {0}'.format(full_resource_path))

        deployment, _ = deploy(blueprint_path,
                               blueprint_id=blueprint_id,
                               deployment_id=deployment_id,
                               inputs={'resource_path': RESOURCE_PATH})

        plugin_data = self.get_plugin_data(plugin_name='testmockoperations',
                                           deployment_id=deployment.id)

        get_resource_content = plugin_data['get_resource']
        download_resource_path = plugin_data['download_resource']

        self.assertEquals(RESOURCE_CONTENT, get_resource_content)
        self.assertEquals(RESOURCE_CONTENT,
                          self.read_manager_file(download_resource_path))

        self.client.deployments.delete(deployment_id, ignore_live_nodes=True)
        self.assertRaises(sh.ErrorReturnCode, self.execute_on_manager,
                          'test -d {0}'.format(deployment_folder_on_manager))
 def test_pre_source_started_location_source(self):
     dsl_path = resource(
         "dsl/relationship_interface_pre_source_location_source.yaml")
     deployment, _ = deploy(dsl_path)
     self.verify_assertions(deployment.id,
                            hook='pre-init',
                            runs_on_source=True)
Beispiel #8
0
    def test_events_timestamp_format(self):
        dsl_path = resource('dsl/empty_blueprint.yaml')
        deployment, _ = deploy(dsl_path)

        #  connect to Elastic search
        es = elasticsearch.Elasticsearch(hosts=[{
            'host': utils.get_manager_ip(),
            'port': 9200
        }])
        index = "cloudify_events" if es.indices.exists(
            index=["cloudify_events"]) else "logstash-*"

        def read_events():
            res = es.search(
                index=index,
                body={"query": {
                    "match": {
                        "deployment_id": deployment.id
                    }
                }})
            #  check if events were created
            self.assertNotEqual(
                0, res['hits']['total'], 'There are no events in for '
                'deployment ' + deployment.id)
            return res

        result = self.do_assertions(read_events, timeout=120)

        #  loop over all the events and compare timestamp to regular expression
        for hit in result['hits']['hits']:
            if not (re.match(TIMESTAMP_PATTERN, hit["_source"]['timestamp'])):
                self.fail('Got {0}. Does not match format '
                          'YYYY-MM-DDTHH:MM:SS.***Z'.format(
                              hit["_source"]['timestamp']))
 def test_policies_flow_with_diamond(self):
     dsl_path = resource('dsl/with_policies_and_diamond.yaml')
     self.deployment, _ = deploy(dsl_path)
     expected_metric_value = 42
     self.wait_for_executions(3)
     invocations = self.wait_for_invocations(self.deployment.id, 1)
     self.assertEqual(expected_metric_value, invocations[0]['metric'])
 def test_workflow_deployment_scaling_groups(self):
     deployment, _ = deploy(resource('dsl/store-scaling-groups.yaml'),
                            workflow_name='workflow')
     instance = self.client.node_instances.list(deployment.id)[0]
     self.assertEqual(
         ['node'],
         instance.runtime_properties['scaling_groups']['group1']['members'])
    def test_uninstall_with_dependency_order(self):
        dsl_path = resource(
            "dsl/uninstall_dependencies-order-with-three-nodes.yaml")
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id
        undeploy(deployment_id)
        # Checking that uninstall wasn't called on the contained node
        states = self.get_plugin_data(plugin_name='testmockoperations',
                                      deployment_id=deployment_id)['state']
        node1_id = states[0]['id']
        node2_id = states[1]['id']
        node3_id = states[2]['id']

        unreachable_call_order = self.get_plugin_data(
            plugin_name='testmockoperations',
            deployment_id=deployment_id)['unreachable_call_order']
        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'])

        configurer_state = self.get_plugin_data(
            plugin_name='connection_configurer_mock',
            deployment_id=deployment_id)['state']
        self.assertEquals(2, len(configurer_state))
        self.assertTrue(
            configurer_state[0]['source_id'].startswith('contained_in_node2'))
        self.assertTrue(
            configurer_state[0]['target_id'].startswith('contained_in_node1'))
        self.assertTrue(
            configurer_state[1]['target_id'].startswith('containing_node'))
        self.assertTrue(
            configurer_state[1]['source_id'].startswith('contained_in_node1'))
 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_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)
Beispiel #14
0
 def test_subgraph_retries_provider_config_config(self):
     context = {
         'cloudify': {
             'workflows': {
                 'task_retries': 0,
                 'task_retry_interval': 0,
                 'subgraph_retries': 2
             }
         }
     }
     deployment_id = str(uuid.uuid4())
     self.client.manager.create_context(self._testMethodName, context)
     deploy(resource('dsl/workflow_subgraph_retries.yaml'),
            deployment_id=deployment_id)
     invocations = self.get_plugin_data(
         plugin_name='testmockoperations',
         deployment_id=deployment_id)['failure_invocation']
     self.assertEqual(len(invocations), 3)
 def test_deployment_modifications_sort(self):
     deployment = deploy(resource('dsl/sort.yaml'))
     for i in range(2, 12):
         modification = self.client.deployment_modifications.start(
             deployment_id=deployment.id, nodes={'node': {
                 'instances': i
             }})
         self.client.deployment_modifications.finish(modification.id)
     self._test_sort('deployment_modifications', 'deployment_id')
    def test_script_mapping(self):
        dsl_path = resource('dsl/test_script_mapping.yaml')
        deployment, _ = deploy(dsl_path)
        execute_workflow('workflow', deployment.id)

        data = self.get_plugin_data(plugin_name='script',
                                    deployment_id=deployment.id)
        self.assertEqual(data['op1_called_with_property'], 'op2_called')
        self.assertEqual(data['op2_prop'], 'op2_value')
 def _test_custom_workflow(self, workflow, error_expected=False):
     deployment = deploy(resource("dsl/basic_task_not_exist.yaml"))
     try:
         execute_workflow(workflow, deployment.id)
         if error_expected:
             self.fail('RuntimeError expected')
     except RuntimeError as e:
         if not error_expected:
             self.fail('Success expected. error message: {0}'.format(e))
         self.assertIn(self.AGENT_ALIVE_FAIL, str(e))
Beispiel #18
0
    def test_operation_retry(self):
        self.configure(retries=5, retry_interval=5)
        deployment_id = str(uuid.uuid4())
        deploy(resource('dsl/test-operation-retry-blueprint.yaml'),
               deployment_id=deployment_id)
        invocations = self.get_plugin_data(
            plugin_name='testmockoperations',
            deployment_id=deployment_id)['retry_invocations']
        self.assertEqual(4, invocations)

        # 1 asserting event messages reflect that the task has been rescheduled
        # 2 asserting that task events contain current_retries/total_retries
        #   only asserting that the properties exists and nothing logical
        #   because this is already covered in the local workflow tests
        def assertion():
            events = self.client.events.list(deployment_id=deployment_id,
                                             include_logs=True)
            self.assertGreater(len(events), 0)
            for event in events:
                if 'Task rescheduled' in event['message']['text']:
                    break
            else:
                self.fail('could not find expected message')
            for event in events:
                if 'Retrying operation' in event['message']['text']:
                    break
            else:
                self.fail('could not find expected message')
            events = [
                e for e in events
                if e.get('event_type', '').startswith('task_')
                or e.get('event_type', '') == 'sending_task'
            ]
            seen_current_retries = set()
            for event in events:
                current_retries = event['context']['task_current_retries']
                seen_current_retries.add(current_retries)
                total_retries = event['context']['task_total_retries']
                self.assertEqual(total_retries, 5)
            self.assertSetEqual(seen_current_retries, {0, 1, 2, 3})

        # events are async so we may have to wait some
        self.do_assertions(assertion, timeout=120)
    def test_failed_uninstall_task(self):
        dsl_path = resource('dsl/basic_stop_error.yaml')
        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id
        undeploy(deployment_id, parameters={'ignore_failure': True})

        machines = self.get_plugin_data(
            plugin_name='cloudmock', deployment_id=deployment_id)['machines']

        self.assertEquals(0, len(machines))
Beispiel #20
0
 def launch_deployment(self, yaml_file, expected_num_of_node_instances=1):
     deployment, _ = deploy(resource(yaml_file))
     self.deployment = deployment
     self.node_instances = self.client.node_instances.list(deployment.id)
     self.assertEqual(
         expected_num_of_node_instances,
         len(self.node_instances)
     )
     self.wait_for_executions(self.NUM_OF_INITIAL_WORKFLOWS,
                              expect_exact_count=False)
 def test_operation_mapping_override(self):
     dsl_path = resource("dsl/operation_mapping.yaml")
     deployment, _ = deploy(dsl_path, 'workflow2')
     invocations = self.get_plugin_data(
         plugin_name='testmockoperations',
         deployment_id=deployment.id)['mock_operation_invocation']
     self.assertEqual(3, len(invocations))
     for invocation in invocations:
         self.assertEqual(1, len(invocation))
         self.assertEqual(invocation['test_key'], 'overridden_test_value')
Beispiel #22
0
 def test_sort_executions(self):
     dsl_path = resource("dsl/basic.yaml")
     deployment, execution_id = deploy(dsl_path)
     wait_for_execution_to_end(self.client.executions.get(execution_id))
     deployment, execution_id = deploy(dsl_path)
     wait_for_execution_to_end(self.client.executions.get(execution_id))
     deployments_executions = self.client.executions.list(sort='created_at')
     for i in range(len(deployments_executions) - 1):
         self.assertTrue(
             deployments_executions[i]['created_at'] <
             deployments_executions[i + 1]['created_at'],
             'execution list not sorted correctly')
     deployments_executions = self.client.executions.list(
         sort='created_at', is_descending=True)
     for i in range(len(deployments_executions) - 1):
         self.assertTrue(
             deployments_executions[i]['created_at'] >
             deployments_executions[i + 1]['created_at'],
             'execution list not sorted correctly')
    def test_uninstall_application_single_host_node(self):
        dsl_path = resource("dsl/basic.yaml")

        deployment, _ = deploy(dsl_path)
        deployment_id = deployment.id

        undeploy(deployment_id)

        machines = self.get_plugin_data(
            plugin_name='cloudmock', deployment_id=deployment_id)['machines']

        self.assertEquals(0, len(machines))
    def test_fail_remote_task_eventual_success(self):
        deployment, _ = deploy(resource('dsl/workflow_api.yaml'),
                               self._testMethodName,
                               parameters={'do_get': self.do_get})

        # testing workflow remote task
        invocations = self.get_plugin_data(
            plugin_name='testmockoperations',
            deployment_id=deployment.id)['failure_invocation']
        self.assertEqual(3, len(invocations))
        for i in range(len(invocations) - 1):
            self.assertLessEqual(1, invocations[i + 1] - invocations[i])
 def test_deploy_multi_instance_many_different_hosts(self):
     dsl_path = resource('dsl/multi_instance_many_different_hosts.yaml')
     deployment, _ = deploy(dsl_path, timeout_seconds=60)
     machines = set(
         self.get_plugin_data(plugin_name='cloudmock',
                              deployment_id=deployment.id)['machines'])
     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_update_node_bad_version(self):
        deploy(resource("dsl/basic.yaml"))
        client = self.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)
 def test_stop_monitor_node_operation(self):
     dsl_path = resource("dsl/hardcoded_operation_properties.yaml")
     deployment, _ = deploy(dsl_path)
     deployment_id = deployment.id
     undeploy(deployment_id)
     # test stop monitor invocations
     invocations = self.get_plugin_data(
         plugin_name='testmockoperations',
         deployment_id=deployment_id)['monitoring_operations_invocation']
     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'])
 def test_deploy_multi_instance_application(self):
     dsl_path = resource("dsl/multi_instance.yaml")
     deployment, _ = deploy(dsl_path)
     machines = set(
         self.get_plugin_data(plugin_name='cloudmock',
                              deployment_id=deployment.id)['machines'])
     self.assertEquals(2, len(machines))
     apps_state = self.get_plugin_data(plugin_name='testmockoperations',
                                       deployment_id=deployment.id)['state']
     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)
Beispiel #29
0
 def _test_retries_and_retry_interval_impl(self,
                                           blueprint,
                                           retries,
                                           retry_interval,
                                           expected_interval,
                                           expected_retries,
                                           invocations_type,
                                           expect_failure=False):
     self.configure(retries=retries, retry_interval=retry_interval)
     deployment_id = str(uuid.uuid4())
     if expect_failure:
         self.assertRaises(RuntimeError,
                           deploy,
                           dsl_path=resource(blueprint),
                           deployment_id=deployment_id)
     else:
         deploy(resource(blueprint), deployment_id=deployment_id)
     invocations = self.get_plugin_data(
         plugin_name='testmockoperations',
         deployment_id=deployment_id)[invocations_type]
     self.assertEqual(expected_retries + 1, len(invocations))
     for i in range(len(invocations) - 1):
         self.assertLessEqual(expected_interval,
                              invocations[i + 1] - invocations[i])
 def _retrieve_resource_test(self, mode):
     blueprint_id = 'blueprint-' + str(uuid.uuid4())
     deployment, _ = deploy(self.dsl_path,
                            blueprint_id=blueprint_id,
                            timeout_seconds=15,
                            inputs={
                                'rendering_tests_demo_conf':
                                self.template_path,
                                'mode': mode
                            })
     rendered_resource = \
         self.get_plugin_data('testmockoperations',
                              deployment.id)['rendered_resource']
     expected = self._get_expected_template()
     return expected, rendered_resource