def test_upgrade(self):
        """Tests version verification."""
        zk_content = {
            'servers': {
                's1': {}
            },
            'version': {
                's1': {
                    'digest': '1234',
                },
                's2': {
                    'digest': '1234',
                },
            },
        }
        self.make_mock_zk(zk_content)

        # In 100% successful scenario, version nodes will be recreated by
        # version monitor.
        #
        # In the test, version for s1 will not be recreated, and s1 will be
        # reported as failure.
        self.assertEqual(['s1'],
                         versionmgr.upgrade(self.zkclient, '3456',
                                            ['s1', 's2'], 10, 1, False))
        self.assertNotIn('s1', zk_content['version'])
        self.assertNotIn('s2', zk_content['version'])
Beispiel #2
0
    def upgrade(cell, ldap, ldap_search_base, batch, timeout, treadmill_root,
                continue_on_error, dry_run, force, servers):
        """Upgrade the supplied cell"""
        context.GLOBAL.ldap.url = ldap
        context.GLOBAL.ldap.search_base = ldap_search_base

        servers = []
        for server_list in servers:
            servers.extend(server_list.split(','))

        if not treadmill_root:
            admin_cell = admin.Cell(context.GLOBAL.ldap.conn)
            cell_info = admin_cell.get(cell)
            treadmill_root = cell_info.get('treadmill_root')

        _LOGGER.info('Treadmill root: %s', treadmill_root)
        digest = versionmgr.checksum_dir(treadmill_root).hexdigest()
        _LOGGER.info('Checksum: %s', digest)

        context.GLOBAL.resolve(cell)
        zkclient = context.GLOBAL.zk.conn

        if not servers:
            # pylint: disable=R0204
            servers = zkutils.get(zkclient, zkutils.SERVERS)

        if dry_run:
            failed = versionmgr.verify(zkclient, digest, servers)
        else:
            failed = versionmgr.upgrade(
                zkclient,
                digest,
                servers,
                batch,
                timeout,
                stop_on_error=(not continue_on_error),
                force_upgrade=force,
            )

        if not failed:
            _LOGGER.info('All servers are up to date.')
        else:
            _LOGGER.error('Upgrade failed.')

        utils.print_yaml(failed)