def serialize(self):
        uids = self.get_uids()
        operating_system = self.cluster.release.operating_system
        repos = objects.Attributes.merged_attrs_values(
            self.cluster.attributes)['repo_setup']['repos']

        if operating_system == consts.RELEASE_OS.centos:
            for repo in repos:
                yield templates.make_centos_repo_task(uids, repo)
            yield templates.make_yum_clean(uids)
        elif operating_system == consts.RELEASE_OS.ubuntu:
            # NOTE(ikalnitsky):
            # We have to clear /etc/apt/sources.list, because it
            # has a lot of invalid repos right after provisioning
            # and that lead us to deployment failures.
            yield templates.make_shell_task(uids, {
                'parameters': {
                    'cmd': '> /etc/apt/sources.list',
                    'timeout': 60
                }})
            yield templates.make_ubuntu_apt_disable_ipv6(uids)
            # NOTE(kozhukalov):
            # This task is to allow installing packages from
            # unauthenticated repositories.
            yield templates.make_ubuntu_unauth_repos_task(uids)
            for repo in repos:
                yield templates.make_ubuntu_sources_task(uids, repo)

                if repo.get('priority'):
                    # do not add preferences task to task list if we can't
                    # complete it (e.g. can't retrieve or parse Release file)
                    task = templates.make_ubuntu_preferences_task(uids, repo)
                    if task is not None:
                        yield task
            yield templates.make_apt_update_task(uids)
Example #2
0
    def serialize(self):
        uids = self.get_uids()
        operating_system = self.cluster.release.operating_system
        repos = objects.Attributes.merged_attrs_values(
            self.cluster.attributes)['repo_setup']['repos']

        if operating_system == consts.RELEASE_OS.centos:
            for repo in repos:
                yield templates.make_centos_repo_task(uids, repo)
            yield templates.make_yum_clean(uids)
        elif operating_system == consts.RELEASE_OS.ubuntu:
            # NOTE(ikalnitsky):
            # We have to clear /etc/apt/sources.list, because it
            # has a lot of invalid repos right after provisioning
            # and that lead us to deployment failures.
            yield templates.make_shell_task(uids, {
                'parameters': {
                    'cmd': '> /etc/apt/sources.list',
                    'timeout': 10
                }})
            yield templates.make_ubuntu_apt_disable_ipv6(uids)
            # NOTE(kozhukalov):
            # This task is to allow installing packages from
            # unauthenticated repositories.
            yield templates.make_ubuntu_unauth_repos_task(uids)
            for repo in repos:
                yield templates.make_ubuntu_sources_task(uids, repo)

                if repo.get('priority'):
                    # do not add preferences task to task list if we can't
                    # complete it (e.g. can't retrieve or parse Release file)
                    task = templates.make_ubuntu_preferences_task(uids, repo)
                    if task is not None:
                        yield task
            yield templates.make_apt_update_task(uids)
Example #3
0
    def create_repositories(self, plugins):
        operating_system = self.cluster.release.operating_system

        for plugin in plugins:
            uids = self._get_node_uids_for_plugin_tasks(plugin)

            # If there are no nodes for tasks execution
            # or if there are no files in repository
            if not uids or not plugin.repo_files(self.cluster):
                continue

            if operating_system == consts.RELEASE_OS.centos:
                repo = self.get_centos_repo(plugin)
                yield self.serialize_task(
                    plugin, templates.make_centos_repo_task(uids, repo))

            elif operating_system == consts.RELEASE_OS.ubuntu:
                repo = self.get_ubuntu_repo(plugin)

                yield self.serialize_task(
                    plugin, templates.make_ubuntu_sources_task(uids, repo))

                # do not add preferences task to task list if we can't
                # complete it (e.g. can't retrieve or parse Release file)
                task = templates.make_ubuntu_preferences_task(uids, repo)
                if task is not None:
                    yield self.serialize_task(plugin, task)

                # apt-get update executed after every additional source.list
                # to be able understand what plugin source.list caused error
                yield self.serialize_task(plugin,
                                          templates.make_apt_update_task(uids))
            else:
                raise errors.InvalidOperatingSystem(
                    'Operating system {0} is invalid'.format(operating_system))
    def test_make_ubuntu_preferences_task(self):
        result = tasks_templates.make_ubuntu_preferences_task(
            [1, 2, 3],
            {
                'name': 'plugin_name',
                'type': 'deb',
                'uri': 'http://url',
                'suite': '/',
                'section': '',
                'priority': 1001
            })
        self.assertEqual(
            result,
            {'parameters': {
                'data': 'Package: *\nPin: release a=/\nPin-Priority: 1001',
                'path': '/etc/apt/preferences.d/plugin_name'},
             'type': 'upload_file',
             'uids': [1, 2, 3]})

        result = tasks_templates.make_ubuntu_preferences_task(
            [1, 2, 3],
            {
                'name': 'plugin_name',
                'type': 'deb',
                'uri': 'http://url',
                'suite': 'jessie',
                'section': 'main universe',
                'priority': 1004
            })
        self.assertEqual(
            result,
            {'parameters': {
                'data': ('Package: *\n'
                         'Pin: release a=jessie,c=main\n'
                         'Pin-Priority: 1004\n\n'
                         'Package: *\n'
                         'Pin: release a=jessie,c=universe\n'
                         'Pin-Priority: 1004'),
                'path': '/etc/apt/preferences.d/plugin_name'},
             'type': 'upload_file',
             'uids': [1, 2, 3]})
Example #5
0
    def test_make_ubuntu_preferences_task_returns_none_if_errors(self, m_get):
        r = requests.Response()
        r.status_code = 404
        m_get.return_value = r

        result = tasks_templates.make_ubuntu_preferences_task(
            [1, 2, 3], {
                'name': 'plugin_name',
                'type': 'deb',
                'uri': 'http://url',
                'suite': 'test-archive',
                'section': 'main universe',
                'priority': 1004
            })

        self.assertIsNone(result)
Example #6
0
    def test_make_ubuntu_preferences_task_flat(self, _):
        result = tasks_templates.make_ubuntu_preferences_task(
            [1, 2, 3],
            {"name": "plugin_name", "type": "deb", "uri": "http://url", "suite": "/", "section": "", "priority": 1004},
        )

        data = result["parameters"].pop("data")
        self.assertEqual(
            result,
            {
                "parameters": {"path": "/etc/apt/preferences.d/plugin_name.pref"},
                "type": "upload_file",
                "uids": [1, 2, 3],
            },
        )

        self._check_apt_preferences(data, [], 1004)
    def test_make_ubuntu_preferences_task_returns_none_if_errors(self, m_get):
        r = requests.Response()
        r.status_code = 404
        m_get.return_value = r

        result = tasks_templates.make_ubuntu_preferences_task(
            [1, 2, 3],
            {
                'name': 'plugin_name',
                'type': 'deb',
                'uri': 'http://url',
                'suite': 'test-archive',
                'section': 'main universe',
                'priority': 1004
            })

        self.assertIsNone(result)
    def create_repositories(self, plugins):
        operating_system = self.cluster.release.operating_system

        repo_tasks = []
        for plugin in plugins:
            uids = get_uids_for_tasks(self.nodes, plugin.tasks)

            # If there are no nodes for tasks execution
            # or if there are no files in repository
            if not uids or not plugin.repo_files(self.cluster):
                continue

            if operating_system == consts.RELEASE_OS.centos:
                repo = self.get_centos_repo(plugin)
                repo_tasks.append(
                    self.serialize_task(
                        plugin,
                        templates.make_centos_repo_task(uids, repo)))

            elif operating_system == consts.RELEASE_OS.ubuntu:
                repo = self.get_ubuntu_repo(plugin)

                repo_tasks.append(
                    self.serialize_task(
                        plugin,
                        templates.make_ubuntu_sources_task(uids, repo)))

                # do not add preferences task to task list if we can't
                # complete it (e.g. can't retrieve or parse Release file)
                task = self.serialize_task(
                    plugin, templates.make_ubuntu_preferences_task(uids, repo))
                if task is not None:
                    repo_tasks.append(task)

                # apt-get update executed after every additional source.list
                # to be able understand what plugin source.list caused error
                repo_tasks.append(
                    self.serialize_task(
                        plugin,
                        templates.make_apt_update_task(uids)))
            else:
                raise errors.InvalidOperatingSystem(
                    'Operating system {0} is invalid'.format(operating_system))

        return repo_tasks
Example #9
0
    def test_make_ubuntu_preferences_task_returns_none_if_errors(self, m_get):
        r = requests.Response()
        r.status_code = 404
        m_get.return_value = r

        result = tasks_templates.make_ubuntu_preferences_task(
            [1, 2, 3],
            {
                "name": "plugin_name",
                "type": "deb",
                "uri": "http://url",
                "suite": "test-archive",
                "section": "main universe",
                "priority": 1004,
            },
        )

        self.assertIsNone(result)
Example #10
0
    def test_make_ubuntu_preferences_task_flat(self, _):
        result = tasks_templates.make_ubuntu_preferences_task(
            [1, 2, 3],
            {
                'name': 'plugin_name',
                'type': 'deb',
                'uri': 'http://url',
                'suite': '/',
                'section': '',
                'priority': 1004
            })

        data = result['parameters'].pop('data')
        self.assertEqual(
            result,
            {'parameters': {'path': '/etc/apt/preferences.d/plugin_name.pref'},
             'type': 'upload_file',
             'uids': [1, 2, 3]})

        self._check_apt_preferences(data, [], 1004)
Example #11
0
    def test_make_ubuntu_preferences_task_flat(self, _):
        result = tasks_templates.make_ubuntu_preferences_task(
            [1, 2, 3],
            {
                'name': 'plugin_name',
                'type': 'deb',
                'uri': 'http://url',
                'suite': '/',
                'section': '',
                'priority': 1004
            })

        data = result['parameters'].pop('data')
        self.assertEqual(
            result,
            {'parameters': {'path': '/etc/apt/preferences.d/plugin_name.pref'},
             'type': 'upload_file',
             'uids': [1, 2, 3]})

        self._check_apt_preferences(data, [], 1004)