Esempio n. 1
0
 def test_fail_to_upload_plugin_while_creating_snapshot(self):
     # Create snapshot and make sure it's state remains 'started'
     self._create_snapshot_and_modify_execution_status(Execution.STARTED)
     with self.assertRaisesRegex(CloudifyClientError,
                                 '[Cc]annot start') as cm:
         upload_mock_plugin(self.client, 'cloudify-script-plugin', '1.2')
     self.assertEqual(cm.exception.status_code, 400)
Esempio n. 2
0
    def test_different_plugin_versions(self):
        new_config = """
    hooks:
      - event_type: workflow_started
        implementation: target_aware_mock.target_aware_mock.tasks.hook_task
        inputs:
          input1: input1_test
          input2: input2_test
        description: test hook
    """
        old_version = '1.0'
        new_version = '1.33'

        upload_mock_plugin(self.client, 'target-aware-mock-v1_33', new_version)

        self._update_hooks_config(new_config)
        self._start_a_workflow()
        event_type_msg = "workflow_started"
        workflow_id_msg = "create_deployment_environment"
        input1_msg = "input1_test"

        # Verify that the hook task calls the newest version of the plugin
        newest_version_msg = "version 1.33"
        messages = [
            event_type_msg, workflow_id_msg, input1_msg, newest_version_msg
        ]
        self._assert_messages_in_log(messages, log_path=self.PLUGIN_LOG_PATH)

        # Verify that both versions of the plugin are installed on manager
        versions = [
            plugin['package_version'] for plugin in self.client.plugins.list(
                package_name='target_aware_mock').items
        ]
        assert (old_version in versions) and (new_version in versions)
Esempio n. 3
0
    def test_install_uninstall_workflows_execution(self):
        test_utils.upload_mock_plugin(self.client, TEST_PACKAGE_NAME,
                                      TEST_PACKAGE_VERSION)

        plugin = self.client.plugins.list()[0]
        self.client.plugins.delete(plugin.id)
        plugins = self.client.plugins.list()
        self.assertEqual(len(plugins), 0)
 def test_fail_to_upload_plugin_while_creating_snapshot(self):
     # Create snapshot and make sure it's state remains 'started'
     self._create_snapshot_and_modify_execution_status(Execution.STARTED)
     try:
         upload_mock_plugin('cloudify-script-plugin', '1.2')
     except CloudifyClientError as e:
         self.assertIn('You cannot start an execution that modifies DB'
                       ' state while a `create_snapshot`', e.message)
         self.assertEquals(e.status_code, 400)
 def test_fail_to_upload_plugin_while_creating_snapshot(self):
     # Create snapshot and make sure it's state remains 'started'
     self._create_snapshot_and_modify_execution_status(Execution.STARTED)
     try:
         upload_mock_plugin('cloudify-script-plugin', '1.2')
     except CloudifyClientError as e:
         self.assertIn('You cannot start an execution that modifies DB'
                       ' state while a `create_snapshot`', e.message)
         self.assertEquals(e.status_code, 400)
    def test_fail_to_delete_plugin_while_creating_snapshot(self):
        # Upload plugin
        upload_mock_plugin('cloudify-script-plugin', '1.2')
        plugins_list = self.client.plugins.list()
        self.assertEqual(
            1, len(plugins_list), 'expecting 1 plugin result, '
            'got {0}'.format(len(plugins_list)))

        # Create snapshot and make sure it's state remains 'started'
        self._execute_unpermitted_operation_and_catch_exception(
            self._create_snapshot_and_modify_execution_status, 'started')
Esempio n. 7
0
    def test_plugins_list_no_filters(self):
        test_utils.upload_mock_plugin(
                TEST_PACKAGE_NAME,
                TEST_PACKAGE_VERSION)
        test_utils.upload_mock_plugin(
                TEST_PACKAGE_NAME,
                OLD_TEST_PACKAGE_VERSION)
        response = self.client.plugins.list()

        self.assertEqual(len(response), 2, 'expecting 2 plugin results, '
                                           'got {0}'.format(len(response)))
        self.assertNotEquals(response[0].id, response[1].id)
Esempio n. 8
0
 def test_install_uninstall_workflows_execution(self):
     self.clear_plugin_data('agent')
     test_utils.upload_mock_plugin(TEST_PACKAGE_NAME, TEST_PACKAGE_VERSION)
     plugins = self.get_plugin_data('agent',
                                    deployment_id='system')['local']
     self.assertEqual(plugins[TEST_PACKAGE_NAME], ['installed'])
     plugin = self.client.plugins.list()[0]
     self.client.plugins.delete(plugin.id)
     plugins = self.get_plugin_data('agent',
                                    deployment_id='system')['local']
     self.assertEqual(plugins[TEST_PACKAGE_NAME],
                      ['installed', 'uninstalled'])
    def test_fail_to_delete_plugin_while_creating_snapshot(self):
        # Upload plugin
        upload_mock_plugin('cloudify-script-plugin', '1.2')
        plugins_list = self.client.plugins.list()
        self.assertEqual(1, len(plugins_list),
                         'expecting 1 plugin result, '
                         'got {0}'.format(len(plugins_list)))

        # Create snapshot and make sure it's state remains 'started'
        self._execute_unpermitted_operation_and_catch_exception(
            self._create_snapshot_and_modify_execution_status,
            Execution.STARTED)
Esempio n. 10
0
    def test_install_uninstall_workflows_execution(self):
        test_utils.upload_mock_plugin(TEST_PACKAGE_NAME, TEST_PACKAGE_VERSION)

        execution = self._get_latest_execution('install_plugin')
        self.wait_for_execution_to_end(execution)

        plugin = self.client.plugins.list()[0]
        self.client.plugins.delete(plugin.id)

        execution = self._get_latest_execution('uninstall_plugin')
        self.wait_for_execution_to_end(execution)

        plugins = self.client.plugins.list()
        self.assertEqual(len(plugins), 0)
    def test_install_uninstall_workflows_execution(self):
        test_utils.upload_mock_plugin(TEST_PACKAGE_NAME, TEST_PACKAGE_VERSION)

        ex = self._get_execution('install_plugin')
        self.wait_for_execution_to_end(ex)

        plugin = self.client.plugins.list()[0]
        self.client.plugins.delete(plugin.id)

        ex = self._get_execution('uninstall_plugin')
        self.wait_for_execution_to_end(ex)

        plugins = self.client.plugins.list()
        self.assertEqual(len(plugins), 0)
Esempio n. 12
0
    def test_plugins_list_with_filters(self):
        test_utils.upload_mock_plugin(
                TEST_PACKAGE_NAME,
                TEST_PACKAGE_VERSION)
        sec_plugin_id = test_utils.upload_mock_plugin(
            TEST_PACKAGE_NAME,
            OLD_TEST_PACKAGE_VERSION)['id']
        filter_field = {'id': sec_plugin_id}
        response = self.client.plugins.list(**filter_field)

        self.assertEqual(len(response), 1, 'expecting 1 plugin result, '
                                           'got {0}'.format(len(response)))
        self.assertDictContainsSubset(filter_field, response[0],
                                      'expecting filtered results having '
                                      'filters {0}, got {1}'
                                      .format(filter_field, response[0]))
Esempio n. 13
0
 def test_uploading_different_version_plugin_than_existing(self):
     mock_id = upload_mock_plugin(self.client, self.TEST_PACKAGE_NAME,
                                  self.TEST_PACKAGE_VERSION)['id']
     self.wait_for_all_executions_to_end()
     basic_blueprint_path = resource('dsl/empty_blueprint.yaml')
     self.client.blueprints.upload(basic_blueprint_path,
                                   entity_id=self.basic_blueprint_id)
     wait_for_blueprint_upload(self.basic_blueprint_id, self.client, True)
     deployment_id = 'd{0}'.format(uuid.uuid4())
     main_blueprint = self.test_blueprint.format(
         'https://cloudify-tests-files.s3-eu-west-1.amazonaws.com/plugins',
         'cloudify_script_plugin/2_0/'
         'cloudify_script_plugin-2.0-py27-none-any.wgn',
         'cloudify_script_plugin/2_0/plugin.yaml')
     blueprint_path = self.make_yaml_file(main_blueprint)
     self.deploy_application(blueprint_path, deployment_id=deployment_id)
     plugins_list = self.client.plugins.list()
     self.assertEqual(len(plugins_list), 2)
     self.assertTrue(plugins_list[0]['package_version'],
                     self.TEST_PACKAGE_NAME)
     self.assertTrue(plugins_list[1]['package_version'],
                     self.TEST_PACKAGE_NAME)
     self.undeploy_application(deployment_id)
     self.assertEqual(len(self.client.plugins.list()), 1)
     self.client.plugins.delete(mock_id)
    def test_implementation_plugin(self):
        new_config = """
hooks:
  - event_type: workflow_started
    implementation: target-aware-mock.target_aware_mock.tasks.hook_task
    inputs:
      input1: input1_test
      input2: input2_test
    description: test hook
"""
        upload_mock_plugin('target-aware-mock',
                           '1.0',)

        self._update_hooks_config(new_config)
        self._start_a_workflow()
        event_type_msg = "workflow_started"
        workflow_id_msg = "create_deployment_environment"
        input1_msg = "input1_test"
        messages = [event_type_msg, workflow_id_msg, input1_msg]
        self._assert_messages_in_log(messages, log_path=self.PLUGIN_LOG_PATH)
Esempio n. 15
0
    def test_implementation_plugin(self):
        new_config = """
hooks:
  - event_type: workflow_started
    implementation: target-aware-mock.target_aware_mock.tasks.hook_task
    inputs:
      input1: input1_test
      input2: input2_test
    description: test hook
"""
        upload_mock_plugin('target-aware-mock',
                           '1.0',)

        self._update_hooks_config(new_config)
        self._start_a_workflow()
        event_type_msg = "workflow_started"
        workflow_id_msg = "create_deployment_environment"
        input1_msg = "input1_test"
        messages = [event_type_msg, workflow_id_msg, input1_msg]
        self._assert_messages_in_log(messages, log_path=self.PLUGIN_LOG_PATH)
Esempio n. 16
0
 def test_get_plugin_by_id(self):
     plugin_id = None
     try:
         put_plugin_response = test_utils.upload_mock_plugin(
             self.client, TEST_PACKAGE_NAME, TEST_PACKAGE_VERSION)
         plugin_id = put_plugin_response.get('id')
         get_plugin_by_id_response = self.client.plugins.get(plugin_id)
         self.assertEqual(put_plugin_response, get_plugin_by_id_response)
     finally:
         if plugin_id:
             self.client.plugins.delete(plugin_id)
Esempio n. 17
0
    def test_get_plugin_by_id(self):
        put_plugin_response = test_utils.upload_mock_plugin(
            TEST_PACKAGE_NAME, TEST_PACKAGE_VERSION)
        plugin_id = put_plugin_response.get('id')
        self.assertIsNotNone(plugin_id)
        self.assertEquals(put_plugin_response.get('package_name'),
                          TEST_PACKAGE_NAME)
        self.assertEquals(put_plugin_response.get('package_version'),
                          TEST_PACKAGE_VERSION)
        get_plugin_by_id_response = self.client.plugins.get(plugin_id)

        self.assertEquals(put_plugin_response, get_plugin_by_id_response)
Esempio n. 18
0
    def test_fail_to_delete_plugin_while_creating_snapshot(self):
        # Upload plugin
        plugin = upload_mock_plugin(self.client, 'cloudify-script-plugin',
                                    '1.2')
        plugins_list = self.client.plugins.list()
        # 3 plugins were uploaded with the test class
        self.assertEqual(
            4, len(plugins_list), 'expecting 4 plugin results, '
            'got {0}'.format(len(plugins_list)))

        # Create snapshot and make sure it's state remains 'started'
        self._create_snapshot_and_modify_execution_status(Execution.STARTED)
        self._execute_unpermitted_operation_and_catch_exception(
            self.client.plugins.delete, plugin.id)
    def test_different_plugin_versions(self):
        new_config = """
    hooks:
      - event_type: workflow_started
        implementation: target-aware-mock.target_aware_mock.tasks.hook_task
        inputs:
          input1: input1_test
          input2: input2_test
        description: test hook
    """
        old_version = '1.0'
        new_version = '1.33'

        # Upload the new one before the old, on purpose
        upload_mock_plugin('target-aware-mock-v1_33', new_version)
        upload_mock_plugin('target-aware-mock', old_version)

        self._update_hooks_config(new_config)
        self._start_a_workflow()
        event_type_msg = "workflow_started"
        workflow_id_msg = "create_deployment_environment"
        input1_msg = "input1_test"

        # Verify that the hook task calls the newest version of the plugin
        newest_version_msg = "version 1.33"
        messages = [event_type_msg,
                    workflow_id_msg,
                    input1_msg,
                    newest_version_msg]
        self._assert_messages_in_log(messages,
                                     log_path=self.PLUGIN_LOG_PATH)

        # Verify that both versions of the plugin are installed on manager
        versions = [plugin['package_version'] for plugin in
                    self.client.plugins.list(
                    package_name='target-aware-mock').items]
        assert (old_version in versions) and (new_version in versions)
Esempio n. 20
0
    def test_delete_plugin(self):
        put_response = test_utils.upload_mock_plugin(self.client,
                                                     TEST_PACKAGE_NAME,
                                                     TEST_PACKAGE_VERSION)

        plugins_list = self.client.plugins.list()
        self.assertEqual(
            1, len(plugins_list), 'expecting 1 plugin result, '
            'got {0}'.format(len(plugins_list)))

        self.client.plugins.delete(put_response['id'])
        plugins_list = self.client.plugins.list()
        self.assertEqual(
            0, len(plugins_list), 'expecting 0 plugin result, '
            'got {0}'.format(len(plugins_list)))
Esempio n. 21
0
    def test_delete_plugin(self):
        put_response = test_utils.upload_mock_plugin(TEST_PACKAGE_NAME,
                                                     TEST_PACKAGE_VERSION)

        plugins_list = self.client.plugins.list()
        self.assertEqual(
            1, len(plugins_list), 'expecting 1 plugin result, '
            'got {0}'.format(len(plugins_list)))

        delete_response = self.client.plugins.delete(put_response['id'])
        # in delete response, yaml_url_path should be empty
        put_response['yaml_url_path'] = ''
        self.assertEquals(put_response, delete_response)

        plugins_list = self.client.plugins.list()
        self.assertEqual(
            0, len(plugins_list), 'expecting 0 plugin result, '
            'got {0}'.format(len(plugins_list)))
    def test_get_plugin_by_id(self):
        plugin_id = None
        try:
            put_plugin_response = test_utils.upload_mock_plugin(
                    TEST_PACKAGE_NAME,
                    TEST_PACKAGE_VERSION)
            plugin_id = put_plugin_response.get('id')
            self.assertIsNotNone(plugin_id)
            self.assertEquals(put_plugin_response.get('package_name'),
                              TEST_PACKAGE_NAME)
            self.assertEquals(put_plugin_response.get('package_version'),
                              TEST_PACKAGE_VERSION)
            get_plugin_by_id_response = self.client.plugins.get(plugin_id)

            self.assertEquals(put_plugin_response, get_plugin_by_id_response)
        finally:
            if plugin_id:
                self.client.plugins.delete(plugin_id)
    def test_delete_plugin(self):
        put_response = test_utils.upload_mock_plugin(
                TEST_PACKAGE_NAME,
                TEST_PACKAGE_VERSION)

        plugins_list = self.client.plugins.list()
        self.assertEqual(1, len(plugins_list),
                         'expecting 1 plugin result, '
                         'got {0}'.format(len(plugins_list)))

        delete_response = self.client.plugins.delete(put_response['id'])
        # in delete response, yaml_url_path should be empty
        put_response['yaml_url_path'] = ''
        self.assertEquals(put_response, delete_response)

        plugins_list = self.client.plugins.list()
        self.assertEqual(0, len(plugins_list),
                         'expecting 0 plugin result, '
                         'got {0}'.format(len(plugins_list)))
Esempio n. 24
0
    def _upload_plugin_and_assert_values(self,
                                         package_name,
                                         package_version,
                                         plugins_count,
                                         corrupt_plugin=False):
        plugin = test_utils.upload_mock_plugin(self.client,
                                               package_name,
                                               package_version,
                                               corrupt_plugin=corrupt_plugin)

        self.client.plugins.install(
            plugin.id,
            managers=[m.hostname for m in self.client.manager.get_managers()])

        time.sleep(2)  # give time for log to refresh and plugin to install
        plugin_retrieved = self.client.plugins.get(plugin.id)
        assert 'installation_state' in plugin_retrieved

        if corrupt_plugin:
            log_path = '/var/log/cloudify/mgmtworker/mgmtworker.log'
            tmp_log_path = str(self.workdir / 'test_log')
            self.copy_file_from_manager(log_path, tmp_log_path)
            with open(tmp_log_path) as f:
                data = f.readlines()
            last_log_lines = str(data[-20:])
            message = 'Failed installing managed plugin: {0}'.format(plugin.id)
            assert message in last_log_lines
            assert all(
                s.get('state') == 'error'
                for s in plugin_retrieved['installation_state'])
            self.client.plugins.delete(plugin.id)
        else:
            assert all(
                s.get('state') == 'installed'
                for s in plugin_retrieved['installation_state'])
        plugins = self.client.plugins.list()
        assert len(plugins) == plugins_count
        return plugin
Esempio n. 25
0
    def _upload_plugin_and_assert_values(self,
                                         package_name,
                                         package_version,
                                         plugins_count,
                                         wagon_files_count,
                                         corrupt_plugin=False):
        plugin = test_utils.upload_mock_plugin(package_name,
                                               package_version,
                                               corrupt_plugin=corrupt_plugin)
        wagon_file = plugin.archive_name[len(INSTALLING_PREFIX):]

        execution = self._get_latest_execution('install_plugin')
        if corrupt_plugin:
            with self.assertRaisesRegexp(RuntimeError,
                                         'Workflow execution failed: .*'):
                self.wait_for_execution_to_end(execution)
            execution = self._get_latest_execution('uninstall_plugin')
        self.wait_for_execution_to_end(execution)

        find_output = self._find_file_on_manager(wagon_file)
        self.assertEqual(len(find_output), wagon_files_count)
        plugins = self.client.plugins.list()
        self.assertEqual(len(plugins), plugins_count)
        return plugin
Esempio n. 26
0
    def test_get_plugin_by_id(self):
        plugin_id = None
        try:
            put_plugin_response = test_utils.upload_mock_plugin(
                TEST_PACKAGE_NAME, TEST_PACKAGE_VERSION)
            execution = self._get_latest_execution('install_plugin')
            self.wait_for_execution_to_end(execution)
            put_plugin_response['archive_name'] = \
                put_plugin_response['archive_name'][len(INSTALLING_PREFIX):]

            self.logger.info('Plugin test execution ID is '
                             '{0}.'.format(execution.id))
            plugin_id = put_plugin_response.get('id')
            self.assertIsNotNone(plugin_id)
            self.assertEquals(put_plugin_response.get('package_name'),
                              TEST_PACKAGE_NAME)
            self.assertEquals(put_plugin_response.get('package_version'),
                              TEST_PACKAGE_VERSION)
            get_plugin_by_id_response = self.client.plugins.get(plugin_id)

            self.assertEquals(put_plugin_response, get_plugin_by_id_response)
        finally:
            if plugin_id:
                self.client.plugins.delete(plugin_id)