Exemplo n.º 1
0
def test_platform_from_job_info_two_spices(job, remote, returns):
    platforms = {
        'sugar': {
            'hosts': ['sugar', 'localhost'],
            'job runner': 'slurm',
        },
        'pepper': {
            'job runner': 'slurm',
            'hosts': 'pepper'
        },
    }
    assert platform_from_job_info(platforms, job, remote) == returns
Exemplo n.º 2
0
def test_platform_from_job_info_ordered_dict_comparison():
    """Check that we are only comparing set items in OrderedDictWithDefaults.
    """
    job = {'batch system': 'background', 'Made up key': 'Zaphod'}
    remote = {'host': 'hpc1', 'Made up key': 'Arthur'}
    # Set up a fake OrderedDictWith a fake unset default.
    platform = OrderedDictWithDefaults()
    platform.defaults_ = {k: None for k in PLATFORMS['hpc1-bg'].keys()}
    platform.defaults_['Made up key'] = {}
    platform.update(PLATFORMS['hpc1-bg'])
    platforms = {'hpc1-bg': platform, 'dobbie': PLATFORMS['sugar']}
    assert platform_from_job_info(platforms, job, remote) == 'hpc1-bg'
Exemplo n.º 3
0
def test_platform_from_job_info_similar_platforms(job, remote, returns):
    platforms = {
        'my-platform-with-bash': {
            'hosts': 'desktop01',
            'shell': '/bin/bash',
            'job runner': 'background'
        },
        # An extra platform to check that we only pick up the first match
        'my-platform-with-fish-not-this-one': {
            'hosts': 'desktop01',
            'shell': '/bin/fish',
            'job runner': 'background'
        },
        'my-platform-with-fish': {
            'hosts': 'desktop01',
            'shell': '/bin/fish',
            'job runner': 'background'
        },
    }
    assert platform_from_job_info(platforms, job, remote) == returns
Exemplo n.º 4
0
    def upgrade_to_platforms(self):
        """upgrade [job]batch system and [remote]host to platform

        * Add 'platform' and 'user' columns to table task_jobs.
        * Remove 'user_at_host' and 'batch_sys_name' columns


        Returns:
            bool - True if upgrade performed, False if upgrade skipped.
        """
        conn = self.connect()

        # check if upgrade required
        schema = conn.execute(rf'PRAGMA table_info({self.TABLE_TASK_JOBS})')
        for _, name, *_ in schema:
            if name == 'platform_name':
                LOG.debug('platform_name column present - skipping db upgrade')
                return False

        # Perform upgrade:
        table = self.TABLE_TASK_JOBS
        LOG.info('Upgrade to Cylc 8 platforms syntax')
        conn.execute(rf'''
                ALTER TABLE
                    {table}
                ADD COLUMN
                    user TEXT
            ''')
        conn.execute(rf'''
                ALTER TABLE
                    {table}
                ADD COLUMN
                    platform_name TEXT
            ''')
        job_platforms = glbl_cfg(cached=False).get(['platforms'])
        for cycle, name, user_at_host, batch_system in conn.execute(rf'''
                SELECT
                    cycle, name, user_at_host, batch_system
                FROM
                    {table}
        '''):
            match = re.match(r"(?P<user>\S+)@(?P<host>\S+)", user_at_host)
            if match:
                user = match.group('user')
                host = match.group('host')
            else:
                user = ''
                host = user_at_host
            platform = platform_from_job_info(job_platforms,
                                              {'batch system': batch_system},
                                              {'host': host})
            conn.execute(
                rf'''
                    UPDATE
                        {table}
                    SET
                        user=?,
                        platform_name=?
                    WHERE
                        cycle==?
                        AND name==?
                ''', (user, platform, cycle, name))
        conn.commit()
        return True
Exemplo n.º 5
0
def test_reverse_PlatformLookupError(job, remote):
    with pytest.raises(PlatformLookupError):
        platform_from_job_info(PLATFORMS, job, remote)
Exemplo n.º 6
0
def test_platform_from_job_info_basic(job, remote, returns):
    assert platform_from_job_info(PLATFORMS, job, remote) == returns