Пример #1
0
 def setUp(self):
     super(TestTasksDeploymentOrder, self).setUp()
     self.cluster = mock.Mock()
     self.nodes = [{
         'id': 1,
         'role': 'controller'
     }, {
         'id': 2,
         'role': 'compute'
     }]
     self.hook = BasePluginDeploymentHooksSerializer(
         self.nodes, self.cluster)
Пример #2
0
 def setUp(self):
     super(TestBasePluginDeploymentHooksSerializer, self).setUp()
     cluster_mock = mock.Mock()
     self.cluster = cluster_mock
     self.nodes = [{
         'id': 1,
         'role': 'controller'
     }, {
         'id': 2,
         'role': 'compute'
     }]
     self.hook = BasePluginDeploymentHooksSerializer(
         self.nodes,
         self.cluster,
         role_resolver=NullResolver([x['id'] for x in self.nodes]))
Пример #3
0
class TestTasksDeploymentOrder(base.BaseTestCase):
    def setUp(self):
        super(TestTasksDeploymentOrder, self).setUp()
        self.cluster = mock.Mock()
        self.nodes = [{
            'id': 1,
            'role': 'controller'
        }, {
            'id': 2,
            'role': 'compute'
        }]
        self.hook = BasePluginDeploymentHooksSerializer(
            self.nodes, self.cluster)

    def make_plugin_mock_with_stages(self, plugin_name, stages):
        common_attrs = {
            'type': 'shell',
            'role': '*',
            'parameters': {
                'cmd': 'cmd',
                'timeout': 100
            }
        }

        tasks = []
        for stage in stages:
            task = copy.deepcopy(common_attrs)
            task['stage'] = stage
            task['parameters']['cmd'] = stage
            tasks.append(task)

        plugin = mock.Mock()
        plugin.tasks = tasks
        plugin.plugin.name = plugin_name

        return plugin

    def test_sorts_plugins_by_numerical_postfixes(self, _):
        plugin1 = self.make_plugin_mock_with_stages('name1', [
            'pre_deployment/-100', 'pre_deployment/100.0',
            'pre_deployment/+100', 'pre_deployment'
        ])
        plugin2 = self.make_plugin_mock_with_stages(
            'name2',
            ['pre_deployment/-99', 'pre_deployment/100', 'pre_deployment'])

        tasks = self.hook.deployment_tasks(
            # Pass plugins in reverse alphabetic order, to make
            # sure that plugin name sorting works
            [plugin2, plugin1],
            consts.STAGES.pre_deployment)

        commands = map(lambda t: t['parameters']['cmd'], tasks)

        self.assertEqual(commands, [
            'pre_deployment/-100', 'pre_deployment/-99', 'pre_deployment',
            'pre_deployment', 'pre_deployment/100.0', 'pre_deployment/+100',
            'pre_deployment/100'
        ])
class TestTasksDeploymentOrder(base.BaseTestCase):

    def setUp(self):
        super(TestTasksDeploymentOrder, self).setUp()
        self.cluster = mock.Mock()
        self.nodes = [
            {'id': 1, 'role': 'controller'},
            {'id': 2, 'role': 'compute'}]
        self.hook = BasePluginDeploymentHooksSerializer(
            self.nodes,
            self.cluster)

    def make_plugin_mock_with_stages(self, plugin_name, stages):
        common_attrs = {
            'type': 'shell',
            'role': '*',
            'parameters': {'cmd': 'cmd', 'timeout': 100}}

        tasks = []
        for stage in stages:
            task = copy.deepcopy(common_attrs)
            task['stage'] = stage
            task['parameters']['cmd'] = stage
            tasks.append(task)

        plugin = mock.Mock()
        plugin.tasks = tasks
        plugin.plugin.name = plugin_name

        return plugin

    def test_sorts_plugins_by_numerical_postfixes(self, _):
        plugin1 = self.make_plugin_mock_with_stages('name1', [
            'pre_deployment/-100',
            'pre_deployment/100.0',
            'pre_deployment/+100',
            'pre_deployment'])
        plugin2 = self.make_plugin_mock_with_stages('name2', [
            'pre_deployment/-99',
            'pre_deployment/100',
            'pre_deployment'])

        tasks = self.hook.deployment_tasks(
            # Pass plugins in reverse alphabetic order, to make
            # sure that plugin name sorting works
            [plugin2, plugin1],
            consts.STAGES.pre_deployment)

        commands = map(lambda t: t['parameters']['cmd'], tasks)

        self.assertEqual(
            commands,
            ['pre_deployment/-100',
             'pre_deployment/-99',
             'pre_deployment',
             'pre_deployment',
             'pre_deployment/100.0',
             'pre_deployment/+100',
             'pre_deployment/100'])
 def setUp(self):
     super(TestTasksDeploymentOrder, self).setUp()
     self.cluster = mock.Mock()
     self.nodes = [
         {'id': 1, 'role': 'controller'},
         {'id': 2, 'role': 'compute'}]
     self.hook = BasePluginDeploymentHooksSerializer(
         self.nodes,
         self.cluster)
Пример #6
0
 def setUp(self):
     super(TestBasePluginDeploymentHooksSerializer, self).setUp()
     cluster_mock = mock.Mock()
     self.cluster = cluster_mock
     self.nodes = [
         {'id': 1, 'role': 'controller'},
         {'id': 2, 'role': 'compute'}
     ]
     self.hook = BasePluginDeploymentHooksSerializer(
         self.nodes,
         self.cluster,
         role_resolver=NullResolver([x['id'] for x in self.nodes])
     )
Пример #7
0
class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
    def setUp(self):
        super(TestBasePluginDeploymentHooksSerializer, self).setUp()
        cluster_mock = mock.Mock()
        self.cluster = cluster_mock
        self.nodes = [{
            'id': 1,
            'role': 'controller'
        }, {
            'id': 2,
            'role': 'compute'
        }]
        self.hook = BasePluginDeploymentHooksSerializer(
            self.nodes, self.cluster)

    @mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles')
    def test_original_order_of_deployment_tasks(self, get_uids_for_roles_mock):
        stage = 'pre_deployment'
        role = 'controller'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.tasks = [{
            'type': 'shell',
            'role': role,
            'id': '1',
            'stage': stage,
            'parameters': {
                'cmd': 'test1',
                'cwd': '/',
                'timeout': 15
            }
        }, {
            'type': 'puppet',
            'role': role,
            'id': '2',
            'stage': stage,
            'parameters': {
                'puppet_manifest': 'manifests/site.pp',
                'puppet_modules': 'modules',
                'cwd': '/etc/puppet/plugins/plugin_name',
                'timeout': 150
            }
        }, {
            'type': 'shell',
            'role': role,
            'id': '3',
            'stage': stage,
            'parameters': {
                'cmd': 'test2',
                'cwd': '/',
                'timeout': 15
            }
        }]

        get_uids_for_roles_mock.return_value = [1, 2]

        raw_result = self.hook.deployment_tasks([plugin], stage)
        result = [r['type'] for r in raw_result]
        self.assertEqual(result, ['shell', 'puppet', 'shell'])
        self.assertEqual(raw_result[0]['parameters']['cmd'], 'test1')
        self.assertEqual(raw_result[1]['parameters']['puppet_modules'],
                         'modules')
        self.assertEqual(raw_result[2]['parameters']['cmd'], 'test2')

    @mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles')
    def test_support_reboot_type_task(self, get_uids_for_roles_mock):
        stage = 'pre_deployment'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.slaves_scripts_path = 'plugin_path'

        plugin.tasks = [{
            'type': 'reboot',
            'role': 'controller',
            'stage': stage,
            'parameters': {
                'timeout': 15
            }
        }]

        get_uids_for_roles_mock.return_value = [1, 2]

        result = self.hook.deployment_tasks([plugin], stage)
        expecting_format = {
            'diagnostic_name': 'plugin_name',
            'fail_on_error': True,
            'parameters': {
                'timeout': 15
            },
            'type': 'reboot',
            'uids': [1, 2]
        }

        self.assertEqual(result, [expecting_format])

    @mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles',
                return_value=[1, 2])
    def test_generates_scripts_path_in_case_of_several_plugins(self, _):
        stage = 'pre_deployment'
        plugins = []
        names = ['plugin_name1', 'plugin_name2']

        for name in names:
            plugin = mock.Mock()
            plugin.full_name = name
            plugin.slaves_scripts_path = name

            plugin.tasks = [{
                'type': 'shell',
                'role': 'controller',
                'stage': stage,
                'parameters': {
                    'timeout': 15,
                    'cmd': 'cmd'
                }
            }]
            plugins.append(plugin)

        result = self.hook.deployment_tasks(plugins, stage)
        script_paths = sorted(map(lambda p: p['parameters']['cwd'], result))
        self.assertEqual(script_paths, names)
Пример #8
0
class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):

    def setUp(self):
        super(TestBasePluginDeploymentHooksSerializer, self).setUp()
        cluster_mock = mock.Mock()
        self.cluster = cluster_mock
        self.nodes = [
            {'id': 1, 'role': 'controller'},
            {'id': 2, 'role': 'compute'}
        ]
        self.hook = BasePluginDeploymentHooksSerializer(
            self.nodes,
            self.cluster,
            role_resolver=NullResolver([x['id'] for x in self.nodes])
        )

    def test_original_order_of_deployment_tasks(self):
        stage = 'pre_deployment'
        role = 'controller'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.tasks = [
            {'type': 'shell', 'role': role, 'id': '1', 'stage': stage,
             'parameters': {'cmd': 'test1', 'cwd': '/', 'timeout': 15}},
            {'type': 'puppet', 'role': role, 'id': '2', 'stage': stage,
             'parameters': {
                 'puppet_manifest': 'manifests/site.pp',
                 'puppet_modules': 'modules',
                 'cwd': '/etc/puppet/plugins/plugin_name',
                 'timeout': 150}},
            {'type': 'shell', 'role': role, 'id': '3', 'stage': stage,
             'parameters': {'cmd': 'test2', 'cwd': '/', 'timeout': 15}}
        ]

        raw_result = list(self.hook.deployment_tasks([plugin], stage))
        result = [r['type'] for r in raw_result]
        self.assertEqual(result, ['shell', 'puppet', 'shell'])
        self.assertEqual(raw_result[0]['parameters']['cmd'], 'test1')
        self.assertEqual(
            raw_result[1]['parameters']['puppet_modules'],
            'modules')
        self.assertEqual(raw_result[2]['parameters']['cmd'], 'test2')

    @mock.patch('nailgun.logger.logger.warn')
    def test_ignoring_unsupported_deployment_tasks(self, m_warn):
        stage = 'pre_deployment'
        role = 'controller'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.tasks = [
            {'type': 'unsupported', 'role': role, 'id': '1', 'stage': stage,
             'parameters': {'cmd': 'test1', 'cwd': '/', 'timeout': 15}}]

        self.assertItemsEqual(
            self.hook.deployment_tasks([plugin], stage), list())
        m_warn.assert_called_once_with(
            'Task is skipped %s, because its type '
            'is not supported', plugin.tasks[0])

    def test_support_reboot_type_task(self):
        stage = 'pre_deployment'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.slaves_scripts_path = 'plugin_path'

        plugin.tasks = [{
            'type': 'reboot',
            'role': 'controller',
            'stage': stage,
            'parameters': {'timeout': 15}}]

        result = self.hook.deployment_tasks([plugin], stage)
        expecting_format = {
            'id': None,
            'diagnostic_name': 'plugin_name',
            'fail_on_error': True,
            'parameters': {'timeout': 15},
            'type': 'reboot',
            'uids': [1, 2]}

        self.assertItemsEqual([expecting_format], result)

    def test_generates_scripts_path_in_case_of_several_plugins(self):
        stage = 'pre_deployment'
        plugins = []
        names = ['plugin_name1', 'plugin_name2']

        for name in names:
            plugin = mock.Mock()
            plugin.full_name = name
            plugin.slaves_scripts_path = name

            plugin.tasks = [{
                'type': 'shell',
                'role': 'controller',
                'stage': stage,
                'parameters': {'timeout': 15, 'cmd': 'cmd'}}]
            plugins.append(plugin)

        result = self.hook.deployment_tasks(plugins, stage)
        script_paths = sorted(map(lambda p: p['parameters']['cwd'], result))
        self.assertEqual(script_paths, names)
Пример #9
0
class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
    def setUp(self):
        super(TestBasePluginDeploymentHooksSerializer, self).setUp()
        cluster_mock = mock.Mock()
        self.cluster = cluster_mock
        self.nodes = [{
            'id': 1,
            'role': 'controller'
        }, {
            'id': 2,
            'role': 'compute'
        }]
        self.hook = BasePluginDeploymentHooksSerializer(
            self.nodes, self.cluster)

    @mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles')
    def test_original_order_of_deployment_tasks(self, get_uids_for_roles_mock):
        stage = 'pre_deployment'
        role = 'controller'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.tasks = [{
            'type': 'shell',
            'role': role,
            'id': '1',
            'stage': stage,
            'parameters': {
                'cmd': 'test1',
                'cwd': '/',
                'timeout': 15
            }
        }, {
            'type': 'puppet',
            'role': role,
            'id': '2',
            'stage': stage,
            'parameters': {
                'puppet_manifest': 'manifests/site.pp',
                'puppet_modules': 'modules',
                'cwd': '/etc/puppet/plugins/plugin_name',
                'timeout': 150
            }
        }, {
            'type': 'shell',
            'role': role,
            'id': '3',
            'stage': stage,
            'parameters': {
                'cmd': 'test2',
                'cwd': '/',
                'timeout': 15
            }
        }]

        get_uids_for_roles_mock.return_value = [1, 2]

        raw_result = self.hook.deployment_tasks([plugin], stage)
        result = [r['type'] for r in raw_result]
        self.assertEqual(result, ['shell', 'puppet', 'shell'])
        self.assertEqual(raw_result[0]['parameters']['cmd'], 'test1')
        self.assertEqual(raw_result[1]['parameters']['puppet_modules'],
                         'modules')
        self.assertEqual(raw_result[2]['parameters']['cmd'], 'test2')
class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):

    def setUp(self):
        super(TestBasePluginDeploymentHooksSerializer, self).setUp()
        cluster_mock = mock.Mock()
        self.cluster = cluster_mock
        self.nodes = [
            {'id': 1, 'role': 'controller'},
            {'id': 2, 'role': 'compute'}
        ]
        self.hook = BasePluginDeploymentHooksSerializer(
            self.nodes,
            self.cluster)

    @mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles')
    def test_original_order_of_deployment_tasks(self, get_uids_for_roles_mock):
        stage = 'pre_deployment'
        role = 'controller'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.tasks = [
            {'type': 'shell', 'role': role, 'id': '1', 'stage': stage,
             'parameters': {'cmd': 'test1', 'cwd': '/', 'timeout': 15}},
            {'type': 'puppet', 'role': role, 'id': '2', 'stage': stage,
             'parameters': {
                 'puppet_manifest': 'manifests/site.pp',
                 'puppet_modules': 'modules',
                 'cwd': '/etc/puppet/plugins/plugin_name',
                 'timeout': 150}},
            {'type': 'shell', 'role': role, 'id': '3', 'stage': stage,
             'parameters': {'cmd': 'test2', 'cwd': '/', 'timeout': 15}}
        ]

        get_uids_for_roles_mock.return_value = [1, 2]

        raw_result = self.hook.deployment_tasks([plugin], stage)
        result = [r['type'] for r in raw_result]
        self.assertEqual(result, ['shell', 'puppet', 'shell'])
        self.assertEqual(raw_result[0]['parameters']['cmd'], 'test1')
        self.assertEqual(
            raw_result[1]['parameters']['puppet_modules'],
            'modules')
        self.assertEqual(raw_result[2]['parameters']['cmd'], 'test2')

    @mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles')
    def test_support_reboot_type_task(self, get_uids_for_roles_mock):
        stage = 'pre_deployment'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.slaves_scripts_path = 'plugin_path'

        plugin.tasks = [{
            'type': 'reboot',
            'role': 'controller',
            'stage': stage,
            'parameters': {'timeout': 15}}]

        get_uids_for_roles_mock.return_value = [1, 2]

        result = self.hook.deployment_tasks([plugin], stage)
        expecting_format = {
            'diagnostic_name': 'plugin_name',
            'fail_on_error': True,
            'parameters': {'timeout': 15},
            'type': 'reboot',
            'uids': [1, 2]}

        self.assertEqual(result, [expecting_format])

    @mock.patch('nailgun.orchestrator.plugins_serializers.get_uids_for_roles',
                return_value=[1, 2])
    def test_generates_scripts_path_in_case_of_several_plugins(self, _):
        stage = 'pre_deployment'
        plugins = []
        names = ['plugin_name1', 'plugin_name2']

        for name in names:
            plugin = mock.Mock()
            plugin.full_name = name
            plugin.slaves_scripts_path = name

            plugin.tasks = [{
                'type': 'shell',
                'role': 'controller',
                'stage': stage,
                'parameters': {'timeout': 15, 'cmd': 'cmd'}}]
            plugins.append(plugin)

        result = self.hook.deployment_tasks(plugins, stage)
        script_paths = sorted(map(lambda p: p['parameters']['cwd'], result))
        self.assertEqual(script_paths, names)
Пример #11
0
class TestBasePluginDeploymentHooksSerializer(base.BaseTestCase):
    def setUp(self):
        super(TestBasePluginDeploymentHooksSerializer, self).setUp()
        cluster_mock = mock.Mock()
        self.cluster = cluster_mock
        self.nodes = [{
            'id': 1,
            'role': 'controller'
        }, {
            'id': 2,
            'role': 'compute'
        }]
        self.hook = BasePluginDeploymentHooksSerializer(
            self.nodes,
            self.cluster,
            role_resolver=NullResolver([x['id'] for x in self.nodes]))

    def test_original_order_of_deployment_tasks(self):
        stage = 'pre_deployment'
        role = 'controller'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.tasks = [{
            'type': 'shell',
            'role': role,
            'id': '1',
            'stage': stage,
            'parameters': {
                'cmd': 'test1',
                'cwd': '/',
                'timeout': 15
            }
        }, {
            'type': 'puppet',
            'role': role,
            'id': '2',
            'stage': stage,
            'parameters': {
                'puppet_manifest': 'manifests/site.pp',
                'puppet_modules': 'modules',
                'cwd': '/etc/puppet/plugins/plugin_name',
                'timeout': 150
            }
        }, {
            'type': 'shell',
            'role': role,
            'id': '3',
            'stage': stage,
            'parameters': {
                'cmd': 'test2',
                'cwd': '/',
                'timeout': 15
            }
        }]

        raw_result = list(self.hook.deployment_tasks([plugin], stage))
        result = [r['type'] for r in raw_result]
        self.assertEqual(result, ['shell', 'puppet', 'shell'])
        self.assertEqual(raw_result[0]['parameters']['cmd'], 'test1')
        self.assertEqual(raw_result[1]['parameters']['puppet_modules'],
                         'modules')
        self.assertEqual(raw_result[2]['parameters']['cmd'], 'test2')

    @mock.patch('nailgun.logger.logger.warn')
    def test_ignoring_unsupported_deployment_tasks(self, m_warn):
        stage = 'pre_deployment'
        role = 'controller'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.tasks = [{
            'type': 'unsupported',
            'role': role,
            'id': '1',
            'stage': stage,
            'parameters': {
                'cmd': 'test1',
                'cwd': '/',
                'timeout': 15
            }
        }]

        self.assertItemsEqual(self.hook.deployment_tasks([plugin], stage),
                              list())
        m_warn.assert_called_once_with(
            'Task is skipped %s, because its type '
            'is not supported', plugin.tasks[0])

    def test_support_reboot_type_task(self):
        stage = 'pre_deployment'

        plugin = mock.Mock()
        plugin.full_name = 'plugin_name'
        plugin.slaves_scripts_path = 'plugin_path'

        plugin.tasks = [{
            'type': 'reboot',
            'role': 'controller',
            'stage': stage,
            'parameters': {
                'timeout': 15
            }
        }]

        result = self.hook.deployment_tasks([plugin], stage)
        expecting_format = {
            'id': None,
            'diagnostic_name': 'plugin_name',
            'fail_on_error': True,
            'parameters': {
                'timeout': 15
            },
            'type': 'reboot',
            'uids': [1, 2]
        }

        self.assertItemsEqual([expecting_format], result)

    def test_generates_scripts_path_in_case_of_several_plugins(self):
        stage = 'pre_deployment'
        plugins = []
        names = ['plugin_name1', 'plugin_name2']

        for name in names:
            plugin = mock.Mock()
            plugin.full_name = name
            plugin.slaves_scripts_path = name

            plugin.tasks = [{
                'type': 'shell',
                'role': 'controller',
                'stage': stage,
                'parameters': {
                    'timeout': 15,
                    'cmd': 'cmd'
                }
            }]
            plugins.append(plugin)

        result = self.hook.deployment_tasks(plugins, stage)
        script_paths = sorted(map(lambda p: p['parameters']['cwd'], result))
        self.assertEqual(script_paths, names)